Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maven-plugin-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
<postBuildHookScript>verify</postBuildHookScript>
<localRepositoryPath>${project.build.directory}/local-repo</localRepositoryPath>
<settingsFile>src/it/settings.xml</settingsFile>
<streamLogsOnFailures>true</streamLogsOnFailures>
<filterProperties>
<sitePluginVersion>3.3</sitePluginVersion>
<antVersion>${antVersion}</antVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

invoker.goals = process-classes
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mplugin-382</groupId>
<artifactId>mplugin-382-exclude-provided-dependency</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Maven Integration Test :: mplugin-382-empty-dependency</name>
<description>
Test plugin-plugin, plugin.xml descriptor - shouldn't contain dependencies in provided scope
</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>@mavenVersion@</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>@project.version@</version>
<scope>provided</scope>
</dependency>

<!-- dependency in compile scope -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>

<!-- dependency in runtime scope -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-rng-client-api</artifactId>
<version>1.4</version>
<scope>runtime</scope>
</dependency>

</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>@project.version@</version>
</plugin>
</plugins>

</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.apache.maven.plugin.coreit;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

/**
* Touches a test file.
*
* @since 1.2
*/
@Mojo( name = "first", requiresDependencyResolution = ResolutionScope.TEST, defaultPhase = LifecyclePhase.INTEGRATION_TEST )
public class FirstMojo
extends AbstractMojo
{

/**
* @since 0.1
* @deprecated As of 0.2
*/
@Parameter( alias = "alias" )
private String aliasedParam;

public void execute()
throws MojoExecutionException
{
// nothing
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

File descriptorFile = new File( basedir, "target/classes/META-INF/maven/plugin.xml" );
assert descriptorFile.isFile()

def pluginDescriptor = new XmlParser().parse( descriptorFile );

// one mojo with one parameter
assert pluginDescriptor.mojos.mojo.size() == 1
assert pluginDescriptor.mojos.mojo.parameters.parameter.size() == 1

// dependencies without provided
assert pluginDescriptor.dependencies.dependency.size() == 2

// expected dependencies on list
assert pluginDescriptor.dependencies.dependency.find{ it.artifactId.text() == "commons-math3" } != null
assert pluginDescriptor.dependencies.dependency.find{ it.artifactId.text() == "commons-rng-client-api" } != null

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
* under the License.
*/

import static java.nio.charset.StandardCharsets.UTF_8;
import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -40,11 +43,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.text.MutableAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.parser.ParserDelegator;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
Expand All @@ -56,6 +54,8 @@
import org.codehaus.plexus.util.xml.XMLWriter;
import org.w3c.tidy.Tidy;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* Convenience methods to play with Maven plugins.
*
Expand Down Expand Up @@ -122,14 +122,19 @@ public static void element( XMLWriter w, String name, String value, boolean asTe

/**
* @param artifacts not null collection of <code>Artifact</code>
* @return list of component dependencies
* @return list of component dependencies, without in provided scope
*/
public static List<ComponentDependency> toComponentDependencies( Collection<Artifact> artifacts )
{
List<ComponentDependency> componentDeps = new LinkedList<>();

for ( Artifact artifact : artifacts )
{
if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
{
continue;
}

ComponentDependency cd = new ComponentDependency();

cd.setArtifactId( artifact.getArtifactId() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@
* under the License.
*/

import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.testing.stubs.MavenProjectStub;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.xml.CompactXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import org.junit.Test;

import java.io.StringWriter;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -210,4 +214,30 @@ public void testIsMavenReport()
assertFalse( GeneratorUtils.isMavenReport( impl, stub ) );
}

@Test
public void testExcludeProvidedScopeFormComponentDependencies()
{

Artifact a1 = new DefaultArtifact( "g", "a1", "1.0", Artifact.SCOPE_COMPILE, "jar", "", null );
Artifact a2 = new DefaultArtifact( "g", "a2", "2.0", Artifact.SCOPE_PROVIDED, "jar", "", null );
Artifact a3 = new DefaultArtifact( "g", "a3", "3.0", Artifact.SCOPE_RUNTIME, "jar", "", null );
List<Artifact> depList = Arrays.asList( a1, a2, a3 );

List<ComponentDependency> componentDependencies = GeneratorUtils.toComponentDependencies( depList );

assertEquals( 2, componentDependencies.size() );

ComponentDependency componentDependency1 = componentDependencies.get( 0 );
assertEquals( a1.getGroupId(), componentDependency1.getGroupId() );
assertEquals( a1.getArtifactId(), componentDependency1.getArtifactId() );
assertEquals( a1.getVersion(), componentDependency1.getVersion() );
assertEquals( a1.getType(), componentDependency1.getType() );

ComponentDependency componentDependency2 = componentDependencies.get( 1 );
assertEquals( a3.getGroupId(), componentDependency2.getGroupId() );
assertEquals( a3.getArtifactId(), componentDependency2.getArtifactId() );
assertEquals( a3.getVersion(), componentDependency2.getVersion() );
assertEquals( a3.getType(), componentDependency2.getType() );
}

}