diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project')
26 files changed, 2959 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java new file mode 100644 index 00000000..7e3f7e6b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/AbstractMavenProjectTestCase.java @@ -0,0 +1,185 @@ +package org.apache.maven.project; + +/* + * 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 java.io.File; +import java.io.FileNotFoundException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.Arrays; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; +import org.apache.maven.model.building.ModelBuildingException; +import org.apache.maven.model.building.ModelProblem; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.repository.internal.MavenRepositorySystemUtils; +import org.codehaus.plexus.ContainerConfiguration; +import org.codehaus.plexus.PlexusConstants; +import org.codehaus.plexus.PlexusTestCase; +import org.eclipse.aether.DefaultRepositorySystemSession; + +/** + * @author Jason van Zyl + */ +public abstract class AbstractMavenProjectTestCase + extends PlexusTestCase +{ + protected ProjectBuilder projectBuilder; + + protected RepositorySystem repositorySystem; + + @Override + protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration ) + { + super.customizeContainerConfiguration( containerConfiguration ); + containerConfiguration.setAutoWiring( true ); + containerConfiguration.setClassPathScanning( PlexusConstants.SCANNING_INDEX ); + } + + protected void setUp() + throws Exception + { + super.setUp(); + + if ( getContainer().hasComponent( ProjectBuilder.class, "test" ) ) + { + projectBuilder = lookup( ProjectBuilder.class, "test" ); + } + else + { + // default over to the main project builder... + projectBuilder = lookup( ProjectBuilder.class ); + } + + repositorySystem = lookup( RepositorySystem.class ); + } + + @Override + protected void tearDown() + throws Exception + { + projectBuilder = null; + + super.tearDown(); + } + + protected ProjectBuilder getProjectBuilder() + { + return projectBuilder; + } + + @Override + protected String getCustomConfigurationName() + { + String name = AbstractMavenProjectTestCase.class.getName().replace( '.', '/' ) + ".xml"; + System.out.println( name ); + return name; + } + + // ---------------------------------------------------------------------- + // Local repository + // ---------------------------------------------------------------------- + + protected File getLocalRepositoryPath() + throws FileNotFoundException, URISyntaxException + { + File markerFile = getFileForClasspathResource( "local-repo/marker.txt" ); + + return markerFile.getAbsoluteFile().getParentFile(); + } + + protected static File getFileForClasspathResource( String resource ) + throws FileNotFoundException + { + ClassLoader cloader = Thread.currentThread().getContextClassLoader(); + + URL resourceUrl = cloader.getResource( resource ); + + if ( resourceUrl == null ) + { + throw new FileNotFoundException( "Unable to find: " + resource ); + } + + return new File( URI.create( resourceUrl.toString().replaceAll( " ", "%20" ) ) ); + } + + protected ArtifactRepository getLocalRepository() + throws Exception + { + ArtifactRepositoryLayout repoLayout = lookup( ArtifactRepositoryLayout.class, "legacy" ); + + ArtifactRepository r = repositorySystem.createArtifactRepository( "local", "file://" + getLocalRepositoryPath().getAbsolutePath(), repoLayout, null, null ); + + return r; + } + + // ---------------------------------------------------------------------- + // Project building + // ---------------------------------------------------------------------- + + protected MavenProject getProjectWithDependencies( File pom ) + throws Exception + { + ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); + configuration.setLocalRepository( getLocalRepository() ); + configuration.setRemoteRepositories( Arrays.asList( new ArtifactRepository[] {} ) ); + configuration.setProcessPlugins( false ); + configuration.setResolveDependencies( true ); + initRepoSession( configuration ); + + try + { + return projectBuilder.build( pom, configuration ).getProject(); + } + catch ( Exception e ) + { + Throwable cause = e.getCause(); + if ( cause instanceof ModelBuildingException ) + { + String message = "In: " + pom + "\n\n"; + for ( ModelProblem problem : ( (ModelBuildingException) cause ).getProblems() ) + { + message += problem + "\n"; + } + System.out.println( message ); + fail( message ); + } + + throw e; + } + } + + protected MavenProject getProject( File pom ) + throws Exception + { + ProjectBuildingRequest configuration = new DefaultProjectBuildingRequest(); + configuration.setLocalRepository( getLocalRepository() ); + initRepoSession( configuration ); + + return projectBuilder.build( pom, configuration ).getProject(); + } + + protected void initRepoSession( ProjectBuildingRequest request ) + { + File localRepo = new File( request.getLocalRepository().getBasedir() ); + DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession(); + session.setLocalRepositoryManager( new LegacyLocalRepositoryManager( localRepo ) ); + request.setRepositorySession( session ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ClasspathArtifactResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ClasspathArtifactResolver.java new file mode 100644 index 00000000..36eaee8f --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ClasspathArtifactResolver.java @@ -0,0 +1,89 @@ +package org.apache.maven.project; + +/* + * 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 java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import org.codehaus.plexus.component.annotations.Component; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.impl.ArtifactResolver; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.transfer.ArtifactNotFoundException; + +/** + * @author Benjamin Bentmann + */ +@Component( role = ArtifactResolver.class, hint = "classpath" ) +public class ClasspathArtifactResolver + implements ArtifactResolver +{ + + public List<ArtifactResult> resolveArtifacts( RepositorySystemSession session, + Collection<? extends ArtifactRequest> requests ) + throws ArtifactResolutionException + { + List<ArtifactResult> results = new ArrayList<ArtifactResult>(); + + for ( ArtifactRequest request : requests ) + { + ArtifactResult result = new ArtifactResult( request ); + results.add( result ); + + Artifact artifact = request.getArtifact(); + if ( "maven-test".equals( artifact.getGroupId() ) ) + { + String scope = artifact.getArtifactId().substring( "scope-".length() ); + + try + { + artifact = + artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + + "transitive-" + scope + "-dep.xml" ) ); + result.setArtifact( artifact ); + } + catch ( FileNotFoundException e ) + { + throw new IllegalStateException( "Missing test POM for " + artifact ); + } + } + else + { + result.addException( new ArtifactNotFoundException( artifact, null ) ); + throw new ArtifactResolutionException( results ); + } + } + + return results; + } + + public ArtifactResult resolveArtifact( RepositorySystemSession session, ArtifactRequest request ) + throws ArtifactResolutionException + { + return resolveArtifacts( session, Collections.singleton( request ) ).get( 0 ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java new file mode 100644 index 00000000..024917de --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecycleExecutor.java @@ -0,0 +1,110 @@ +package org.apache.maven.project; + +/* + * 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 java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.DefaultLifecycles; +import org.apache.maven.lifecycle.LifecycleExecutor; +import org.apache.maven.lifecycle.MavenExecutionPlan; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; +import org.apache.maven.plugin.MojoExecution; + +/** + * A stub implementation that assumes an empty lifecycle to bypass interaction with the plugin manager and to avoid + * plugin artifact resolution from repositories. + * + * @author Benjamin Bentmann + */ +public class EmptyLifecycleExecutor + implements LifecycleExecutor +{ + + public MavenExecutionPlan calculateExecutionPlan( MavenSession session, String... tasks ) + { + return new MavenExecutionPlan( null, new DefaultLifecycles() ); + } + + public MavenExecutionPlan calculateExecutionPlan( MavenSession session, boolean setup, String... tasks ) + { + return new MavenExecutionPlan( null, new DefaultLifecycles() ); + } + + public void execute( MavenSession session ) + { + } + + public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + { + Set<Plugin> plugins; + + // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests + if ( "JAR".equals( packaging ) ) + { + plugins = new LinkedHashSet<Plugin>(); + + plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) ); + plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) ); + plugins.add( newPlugin( "maven-surefire-plugin", "test" ) ); + plugins.add( newPlugin( "maven-jar-plugin", "jar" ) ); + plugins.add( newPlugin( "maven-install-plugin", "install" ) ); + plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) ); + } + else + { + plugins = Collections.emptySet(); + } + + return plugins; + } + + private Plugin newPlugin( String artifactId, String... goals ) + { + Plugin plugin = new Plugin(); + + plugin.setGroupId( "org.apache.maven.plugins" ); + plugin.setArtifactId( artifactId ); + + for ( String goal : goals ) + { + PluginExecution pluginExecution = new PluginExecution(); + pluginExecution.setId( "default-" + goal ); + pluginExecution.addGoal( goal ); + plugin.addExecution( pluginExecution ); + } + + return plugin; + } + + public void calculateForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + { + } + + public List<MavenProject> executeForkedExecutions( MojoExecution mojoExecution, MavenSession session ) + { + return Collections.emptyList(); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecyclePluginAnalyzer.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecyclePluginAnalyzer.java new file mode 100644 index 00000000..5a78a7e5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/EmptyLifecyclePluginAnalyzer.java @@ -0,0 +1,78 @@ +package org.apache.maven.project; + +/* + * 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 java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Set; + +import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; + +/** + * @author Benjamin Bentmann + */ +public class EmptyLifecyclePluginAnalyzer + implements LifeCyclePluginAnalyzer +{ + public Set<Plugin> getPluginsBoundByDefaultToAllLifecycles( String packaging ) + { + Set<Plugin> plugins; + + // NOTE: The upper-case packaging name is intentional, that's a special hinting mode used for certain tests + if ( "JAR".equals( packaging ) ) + { + plugins = new LinkedHashSet<Plugin>(); + + plugins.add( newPlugin( "maven-compiler-plugin", "compile", "testCompile" ) ); + plugins.add( newPlugin( "maven-resources-plugin", "resources", "testResources" ) ); + plugins.add( newPlugin( "maven-surefire-plugin", "test" ) ); + plugins.add( newPlugin( "maven-jar-plugin", "jar" ) ); + plugins.add( newPlugin( "maven-install-plugin", "install" ) ); + plugins.add( newPlugin( "maven-deploy-plugin", "deploy" ) ); + } + else + { + plugins = Collections.emptySet(); + } + + return plugins; + } + + private Plugin newPlugin( String artifactId, String... goals ) + { + Plugin plugin = new Plugin(); + + plugin.setGroupId( "org.apache.maven.plugins" ); + plugin.setArtifactId( artifactId ); + + for ( String goal : goals ) + { + PluginExecution pluginExecution = new PluginExecution(); + pluginExecution.setId( "default-" + goal ); + pluginExecution.addGoal( goal ); + plugin.addExecution( pluginExecution ); + } + + return plugin; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/LegacyLocalRepositoryManager.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/LegacyLocalRepositoryManager.java new file mode 100644 index 00000000..52fdd804 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/LegacyLocalRepositoryManager.java @@ -0,0 +1,192 @@ +package org.apache.maven.project; + +/* + * 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 java.io.File; + +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.metadata.Metadata; +import org.eclipse.aether.repository.LocalArtifactRegistration; +import org.eclipse.aether.repository.LocalArtifactRequest; +import org.eclipse.aether.repository.LocalArtifactResult; +import org.eclipse.aether.repository.LocalMetadataRegistration; +import org.eclipse.aether.repository.LocalMetadataRequest; +import org.eclipse.aether.repository.LocalMetadataResult; +import org.eclipse.aether.repository.LocalRepository; +import org.eclipse.aether.repository.LocalRepositoryManager; +import org.eclipse.aether.repository.RemoteRepository; + +/** + * @author Benjamin Bentmann + */ +public class LegacyLocalRepositoryManager + implements LocalRepositoryManager +{ + + private final LocalRepository repository; + + public LegacyLocalRepositoryManager( File basedir ) + { + this.repository = new LocalRepository( basedir.getAbsoluteFile(), "legacy" ); + } + + public LocalRepository getRepository() + { + return repository; + } + + public String getPathForLocalArtifact( Artifact artifact ) + { + StringBuilder path = new StringBuilder( 128 ); + + path.append( artifact.getGroupId() ).append( '/' ); + + path.append( artifact.getExtension() ).append( 's' ).append( '/' ); + + path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() ); + + if ( artifact.getClassifier().length() > 0 ) + { + path.append( '-' ).append( artifact.getClassifier() ); + } + + path.append( '.' ).append( artifact.getExtension() ); + + return path.toString(); + } + + public String getPathForRemoteArtifact( Artifact artifact, RemoteRepository repository, String context ) + { + return getPathForLocalArtifact( artifact ); + } + + public String getPathForLocalMetadata( Metadata metadata ) + { + return getPath( metadata, "local" ); + } + + public String getPathForRemoteMetadata( Metadata metadata, RemoteRepository repository, String context ) + { + return getPath( metadata, getRepositoryKey( repository, context ) ); + } + + String getRepositoryKey( RemoteRepository repository, String context ) + { + return repository.getId(); + } + + private String getPath( Metadata metadata, String repositoryKey ) + { + StringBuilder path = new StringBuilder( 128 ); + + if ( metadata.getGroupId().length() > 0 ) + { + path.append( metadata.getGroupId().replace( '.', '/' ) ).append( '/' ); + + if ( metadata.getArtifactId().length() > 0 ) + { + path.append( metadata.getArtifactId() ).append( '/' ); + + if ( metadata.getVersion().length() > 0 ) + { + path.append( metadata.getVersion() ).append( '/' ); + } + } + } + + path.append( insertRepositoryKey( metadata.getType(), repositoryKey ) ); + + return path.toString(); + } + + private String insertRepositoryKey( String filename, String repositoryKey ) + { + String result; + int idx = filename.indexOf( '.' ); + if ( idx < 0 ) + { + result = filename + '-' + repositoryKey; + } + else + { + result = filename.substring( 0, idx ) + '-' + repositoryKey + filename.substring( idx ); + } + return result; + } + + public LocalArtifactResult find( RepositorySystemSession session, LocalArtifactRequest request ) + { + String path = getPathForLocalArtifact( request.getArtifact() ); + File file = new File( getRepository().getBasedir(), path ); + + LocalArtifactResult result = new LocalArtifactResult( request ); + if ( file.isFile() ) + { + result.setFile( file ); + result.setAvailable( true ); + } + + return result; + } + + public void add( RepositorySystemSession session, LocalArtifactRegistration request ) + { + // noop + } + + public LocalMetadataResult find( RepositorySystemSession session, LocalMetadataRequest request ) + { + LocalMetadataResult result = new LocalMetadataResult( request ); + + String path; + + Metadata metadata = request.getMetadata(); + String context = request.getContext(); + RemoteRepository remote = request.getRepository(); + + if ( remote != null ) + { + path = getPathForRemoteMetadata( metadata, remote, context ); + } + else + { + path = getPathForLocalMetadata( metadata ); + } + + File file = new File( getRepository().getBasedir(), path ); + if ( file.isFile() ) + { + result.setFile( file ); + } + + return result; + } + + public void add( RepositorySystemSession session, LocalMetadataRegistration request ) + { + // noop + } + + public String toString() + { + return String.valueOf( getRepository() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java new file mode 100644 index 00000000..6c3df9a0 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ModelUtilsTest.java @@ -0,0 +1,616 @@ +package org.apache.maven.project; + +/* + * 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 java.io.IOException; +import java.io.StringReader; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import junit.framework.TestCase; + +import org.apache.maven.model.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginContainer; +import org.apache.maven.model.PluginExecution; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.Xpp3DomBuilder; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +public class ModelUtilsTest + extends TestCase +{ + + public void testShouldUseMainPluginDependencyVersionOverManagedDepVersion() + { + Plugin mgtPlugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP ); + Dependency mgtDep = createDependency( "g", "a", "2" ); + mgtPlugin.addDependency( mgtDep ); + + Plugin plugin = createPlugin( "group", "artifact", "1", Collections.EMPTY_MAP ); + Dependency dep = createDependency( "g", "a", "1" ); + plugin.addDependency( dep ); + + ModelUtils.mergePluginDefinitions( plugin, mgtPlugin, false ); + + assertEquals( dep.getVersion(), plugin.getDependencies().get( 0 ).getVersion() ); + } + + private Dependency createDependency( String gid, + String aid, + String ver ) + { + Dependency dep = new Dependency(); + dep.setGroupId( gid ); + dep.setArtifactId( aid ); + dep.setVersion( ver ); + + return dep; + } + + public void testShouldNotInheritPluginWithInheritanceSetToFalse() + { + PluginContainer parent = new PluginContainer(); + + Plugin parentPlugin = createPlugin( "group", "artifact", "1.0", Collections.EMPTY_MAP ); + parentPlugin.setInherited( "false" ); + + parent.addPlugin( parentPlugin ); + + PluginContainer child = new PluginContainer(); + + child.addPlugin( createPlugin( "group3", "artifact3", "1.0", Collections.EMPTY_MAP ) ); + + ModelUtils.mergePluginLists( child, parent, true ); + + List results = child.getPlugins(); + + assertEquals( 1, results.size() ); + + Plugin result1 = (Plugin) results.get( 0 ); + assertEquals( "group3", result1.getGroupId() ); + assertEquals( "artifact3", result1.getArtifactId() ); + } + + /** + * Test that this is the resulting ordering of plugins after merging: + * + * Given: + * + * parent: X -> A -> B -> D -> E + * child: Y -> A -> C -> D -> F + * + * Result: + * + * X -> Y -> A -> B -> C -> D -> E -> F + */ + public void testShouldPreserveChildOrderingOfPluginsAfterParentMerge() + { + PluginContainer parent = new PluginContainer(); + + parent.addPlugin( createPlugin( "group", "artifact", "1.0", Collections.EMPTY_MAP ) ); + parent.addPlugin( createPlugin( "group2", "artifact2", "1.0", Collections.singletonMap( "key", "value" ) ) ); + + PluginContainer child = new PluginContainer(); + + child.addPlugin( createPlugin( "group3", "artifact3", "1.0", Collections.EMPTY_MAP ) ); + child.addPlugin( createPlugin( "group2", "artifact2", "1.0", Collections.singletonMap( "key2", "value2" ) ) ); + + ModelUtils.mergePluginLists( child, parent, true ); + + List results = child.getPlugins(); + + assertEquals( 3, results.size() ); + + Plugin result1 = (Plugin) results.get( 0 ); + + assertEquals( "group", result1.getGroupId() ); + assertEquals( "artifact", result1.getArtifactId() ); + + Plugin result2 = (Plugin) results.get( 1 ); + + assertEquals( "group3", result2.getGroupId() ); + assertEquals( "artifact3", result2.getArtifactId() ); + + Plugin result3 = (Plugin) results.get( 2 ); + + assertEquals( "group2", result3.getGroupId() ); + assertEquals( "artifact2", result3.getArtifactId() ); + + Xpp3Dom result3Config = (Xpp3Dom) result3.getConfiguration(); + + assertNotNull( result3Config ); + + assertEquals( "value", result3Config.getChild( "key" ).getValue() ); + assertEquals( "value2", result3Config.getChild( "key2" ).getValue() ); + } + + private Plugin createPlugin( String groupId, String artifactId, String version, Map configuration ) + { + Plugin plugin = new Plugin(); + plugin.setGroupId( groupId ); + plugin.setArtifactId( artifactId ); + plugin.setVersion( version ); + + Xpp3Dom config = new Xpp3Dom( "configuration" ); + + if( configuration != null ) + { + for ( Object o : configuration.entrySet() ) + { + Map.Entry entry = (Map.Entry) o; + + Xpp3Dom param = new Xpp3Dom( String.valueOf( entry.getKey() ) ); + param.setValue( String.valueOf( entry.getValue() ) ); + + config.addChild( param ); + } + } + + plugin.setConfiguration( config ); + + return plugin; + } + + public void testShouldInheritOnePluginWithExecution() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + + PluginExecution parentExecution = new PluginExecution(); + parentExecution.setId( "testExecution" ); + + parent.addExecution( parentExecution ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + ModelUtils.mergePluginDefinitions( child, parent, false ); + + assertEquals( 1, child.getExecutions().size() ); + } + + public void testShouldMergeInheritedPluginHavingExecutionWithLocalPlugin() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + + PluginExecution parentExecution = new PluginExecution(); + parentExecution.setId( "testExecution" ); + + parent.addExecution( parentExecution ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + PluginExecution childExecution = new PluginExecution(); + childExecution.setId( "testExecution2" ); + + child.addExecution( childExecution ); + + ModelUtils.mergePluginDefinitions( child, parent, false ); + + assertEquals( 2, child.getExecutions().size() ); + } + + public void testShouldMergeOnePluginWithInheritExecutionWithoutDuplicatingPluginInList() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + + PluginExecution parentExecution = new PluginExecution(); + parentExecution.setId( "testExecution" ); + + parent.addExecution( parentExecution ); + + Build parentContainer = new Build(); + parentContainer.addPlugin( parent ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + Build childContainer = new Build(); + childContainer.addPlugin( child ); + + ModelUtils.mergePluginLists( childContainer, parentContainer, true ); + + List plugins = childContainer.getPlugins(); + + assertEquals( 1, plugins.size() ); + + Plugin plugin = (Plugin) plugins.get( 0 ); + + assertEquals( 1, plugin.getExecutions().size() ); + } + + public void testShouldMergePluginWithDifferentExecutionFromParentWithoutDuplicatingPluginInList() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + + PluginExecution parentExecution = new PluginExecution(); + parentExecution.setId( "testExecution" ); + + parent.addExecution( parentExecution ); + + Build parentContainer = new Build(); + parentContainer.addPlugin( parent ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + PluginExecution childExecution = new PluginExecution(); + childExecution.setId( "testExecution2" ); + + child.addExecution( childExecution ); + + + Build childContainer = new Build(); + childContainer.addPlugin( child ); + + ModelUtils.mergePluginLists( childContainer, parentContainer, true ); + + List plugins = childContainer.getPlugins(); + + assertEquals( 1, plugins.size() ); + + Plugin plugin = (Plugin) plugins.get( 0 ); + + assertEquals( 2, plugin.getExecutions().size() ); + } + + public void testShouldNOTMergeInheritedPluginHavingInheritEqualFalse() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + parent.setInherited( "false" ); + + PluginExecution parentExecution = new PluginExecution(); + parentExecution.setId( "testExecution" ); + + parent.addExecution( parentExecution ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + ModelUtils.mergePluginDefinitions( child, parent, true ); + + assertEquals( 0, child.getExecutions().size() ); + } + + /** + * Verifies MNG-1499: The order of the merged list should be the plugins specified by the parent followed by the + * child list. + */ + public void testShouldKeepOriginalPluginOrdering() + { + Plugin parentPlugin1 = new Plugin(); + parentPlugin1.setArtifactId( "testArtifact" ); + parentPlugin1.setGroupId( "zzz" ); // This will put this plugin last in the sorted map + parentPlugin1.setVersion( "1.0" ); + + PluginExecution parentExecution1 = new PluginExecution(); + parentExecution1.setId( "testExecution" ); + + parentPlugin1.addExecution( parentExecution1 ); + + Plugin parentPlugin2 = new Plugin(); + parentPlugin2.setArtifactId( "testArtifact" ); + parentPlugin2.setGroupId( "yyy" ); + parentPlugin2.setVersion( "1.0" ); + + PluginExecution parentExecution2 = new PluginExecution(); + parentExecution2.setId( "testExecution" ); + + parentPlugin2.addExecution( parentExecution2 ); + + PluginContainer parentContainer = new PluginContainer(); + parentContainer.addPlugin(parentPlugin1); + parentContainer.addPlugin(parentPlugin2); + + + Plugin childPlugin1 = new Plugin(); + childPlugin1.setArtifactId( "testArtifact" ); + childPlugin1.setGroupId( "bbb" ); + childPlugin1.setVersion( "1.0" ); + + PluginExecution childExecution1 = new PluginExecution(); + childExecution1.setId( "testExecution" ); + + childPlugin1.addExecution( childExecution1 ); + + Plugin childPlugin2 = new Plugin(); + childPlugin2.setArtifactId( "testArtifact" ); + childPlugin2.setGroupId( "aaa" ); + childPlugin2.setVersion( "1.0" ); + + PluginExecution childExecution2 = new PluginExecution(); + childExecution2.setId( "testExecution" ); + + childPlugin2.addExecution( childExecution2 ); + + PluginContainer childContainer = new PluginContainer(); + childContainer.addPlugin(childPlugin1); + childContainer.addPlugin(childPlugin2); + + + ModelUtils.mergePluginLists(childContainer, parentContainer, true); + + assertEquals( 4, childContainer.getPlugins().size() ); + assertSame(parentPlugin1, childContainer.getPlugins().get(0)); + assertSame(parentPlugin2, childContainer.getPlugins().get(1)); + assertSame(childPlugin1, childContainer.getPlugins().get(2)); + assertSame(childPlugin2, childContainer.getPlugins().get(3)); + } + + /** + * Verifies MNG-1499: The ordering of plugin executions should also be in the specified order. + */ + public void testShouldKeepOriginalPluginExecutionOrdering() + { + Plugin parent = new Plugin(); + parent.setArtifactId( "testArtifact" ); + parent.setGroupId( "testGroup" ); + parent.setVersion( "1.0" ); + + PluginExecution parentExecution1 = new PluginExecution(); + parentExecution1.setId( "zzz" ); // Will show up last in the sorted map + PluginExecution parentExecution2 = new PluginExecution(); + parentExecution2.setId( "yyy" ); // Will show up last in the sorted map + + parent.addExecution( parentExecution1 ); + parent.addExecution( parentExecution2 ); + + // this block verifies MNG-1703 + Dependency dep = new Dependency(); + dep.setGroupId( "depGroupId" ); + dep.setArtifactId( "depArtifactId" ); + dep.setVersion( "depVersion" ); + parent.setDependencies( Collections.singletonList( dep ) ); + + Plugin child = new Plugin(); + child.setArtifactId( "testArtifact" ); + child.setGroupId( "testGroup" ); + child.setVersion( "1.0" ); + + PluginExecution childExecution1 = new PluginExecution(); + childExecution1.setId( "bbb" ); + PluginExecution childExecution2 = new PluginExecution(); + childExecution2.setId( "aaa" ); + + child.addExecution( childExecution1 ); + child.addExecution( childExecution2 ); + + ModelUtils.mergePluginDefinitions( child, parent, false ); + + assertEquals( 4, child.getExecutions().size() ); + assertSame(parentExecution1, child.getExecutions().get(0)); + assertSame(parentExecution2, child.getExecutions().get(1)); + assertSame(childExecution1, child.getExecutions().get(2)); + assertSame(childExecution2, child.getExecutions().get(3)); + + // this block prevents MNG-1703 + assertEquals( 1, child.getDependencies().size() ); + Dependency dep2 = child.getDependencies().get( 0 ); + assertEquals( dep.getManagementKey(), dep2.getManagementKey() ); + } + + public void testShouldOverwritePluginConfigurationSubItemsByDefault() + throws XmlPullParserException, IOException + { + String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>"; + Xpp3Dom parentConfig = Xpp3DomBuilder.build( new StringReader( parentConfigStr ) ); + + Plugin parentPlugin = createPlugin( "group", "artifact", "1", null ); + parentPlugin.setConfiguration( parentConfig ); + + String childConfigStr = "<configuration><items><item>three</item></items></configuration>"; + Xpp3Dom childConfig = Xpp3DomBuilder.build( new StringReader( childConfigStr ) ); + + Plugin childPlugin = createPlugin( "group", "artifact", "1", null ); + childPlugin.setConfiguration( childConfig ); + + ModelUtils.mergePluginDefinitions( childPlugin, parentPlugin, true ); + + Xpp3Dom result = (Xpp3Dom) childPlugin.getConfiguration(); + Xpp3Dom items = result.getChild( "items" ); + + assertEquals( 1, items.getChildCount() ); + + Xpp3Dom item = items.getChild( 0 ); + assertEquals( "three", item.getValue() ); + } + + public void testShouldMergePluginConfigurationSubItemsWithMergeAttributeSet() + throws XmlPullParserException, IOException + { + String parentConfigStr = "<configuration><items><item>one</item><item>two</item></items></configuration>"; + Xpp3Dom parentConfig = Xpp3DomBuilder.build( new StringReader( parentConfigStr ) ); + + Plugin parentPlugin = createPlugin( "group", "artifact", "1", null ); + parentPlugin.setConfiguration( parentConfig ); + + String childConfigStr = "<configuration><items combine.children=\"append\"><item>three</item></items></configuration>"; + Xpp3Dom childConfig = Xpp3DomBuilder.build( new StringReader( childConfigStr ) ); + + Plugin childPlugin = createPlugin( "group", "artifact", "1", null ); + childPlugin.setConfiguration( childConfig ); + + ModelUtils.mergePluginDefinitions( childPlugin, parentPlugin, true ); + + Xpp3Dom result = (Xpp3Dom) childPlugin.getConfiguration(); + Xpp3Dom items = result.getChild( "items" ); + + assertEquals( 3, items.getChildCount() ); + + Xpp3Dom[] item = items.getChildren(); + + List<String> actual = Arrays.asList( item[0].getValue(), item[1].getValue(), item[2].getValue() ); + List<String> expected = Arrays.asList( "one", "two", "three" ); + Collections.sort( actual ); + Collections.sort( expected ); + assertEquals( expected, actual ); + } + + public void testShouldNotMergePluginExecutionWhenExecInheritedIsFalseAndTreatAsInheritanceIsTrue() + { + String gid = "group"; + String aid = "artifact"; + String ver = "1"; + + PluginContainer parent = new PluginContainer(); + Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + + pParent.setInherited( Boolean.toString( true ) ); + + PluginExecution eParent = new PluginExecution(); + + String testId = "test"; + + eParent.setId( testId ); + eParent.addGoal( "run" ); + eParent.setPhase( "initialize" ); + eParent.setInherited( Boolean.toString( false ) ); + + pParent.addExecution( eParent ); + parent.addPlugin( pParent ); + + PluginContainer child = new PluginContainer(); + Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + PluginExecution eChild = new PluginExecution(); + + eChild.setId( "child-specified" ); + eChild.addGoal( "child" ); + eChild.setPhase( "compile" ); + + pChild.addExecution( eChild ); + child.addPlugin( pChild ); + + ModelUtils.mergePluginDefinitions( pChild, pParent, true ); + + Map executionMap = pChild.getExecutionsAsMap(); + assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) ); + } + + public void testShouldNotMergePluginExecutionWhenPluginInheritedIsFalseAndTreatAsInheritanceIsTrue() + { + String gid = "group"; + String aid = "artifact"; + String ver = "1"; + + PluginContainer parent = new PluginContainer(); + Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + + pParent.setInherited( Boolean.toString( false ) ); + + PluginExecution eParent = new PluginExecution(); + + String testId = "test"; + + eParent.setId( testId ); + eParent.addGoal( "run" ); + eParent.setPhase( "initialize" ); + eParent.setInherited( Boolean.toString( true ) ); + + pParent.addExecution( eParent ); + parent.addPlugin( pParent ); + + PluginContainer child = new PluginContainer(); + Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + PluginExecution eChild = new PluginExecution(); + + eChild.setId( "child-specified" ); + eChild.addGoal( "child" ); + eChild.setPhase( "compile" ); + + pChild.addExecution( eChild ); + child.addPlugin( pChild ); + + ModelUtils.mergePluginDefinitions( pChild, pParent, true ); + + Map executionMap = pChild.getExecutionsAsMap(); + assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) ); + } + + public void testShouldMergePluginExecutionWhenExecInheritedIsTrueAndTreatAsInheritanceIsTrue() + { + String gid = "group"; + String aid = "artifact"; + String ver = "1"; + + PluginContainer parent = new PluginContainer(); + Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + + pParent.setInherited( Boolean.toString( true ) ); + + PluginExecution eParent = new PluginExecution(); + + String testId = "test"; + + eParent.setId( testId ); + eParent.addGoal( "run" ); + eParent.setPhase( "initialize" ); + eParent.setInherited( Boolean.toString( true ) ); + + pParent.addExecution( eParent ); + parent.addPlugin( pParent ); + + PluginContainer child = new PluginContainer(); + Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP ); + PluginExecution eChild = new PluginExecution(); + + eChild.setId( "child-specified" ); + eChild.addGoal( "child" ); + eChild.setPhase( "compile" ); + + pChild.addExecution( eChild ); + child.addPlugin( pChild ); + + ModelUtils.mergePluginDefinitions( pChild, pParent, true ); + + Map executionMap = pChild.getExecutionsAsMap(); + assertNotNull( "test execution should be inherited from parent.", executionMap.get( testId ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java new file mode 100644 index 00000000..d9e7beb2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -0,0 +1,149 @@ +package org.apache.maven.project; + +/* + * 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 java.io.File; +import java.util.Iterator; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.repository.internal.DefaultArtifactDescriptorReader; +import org.eclipse.aether.impl.ArtifactDescriptorReader; +import org.eclipse.aether.impl.ArtifactResolver; + +public class ProjectClasspathTest + extends AbstractMavenProjectTestCase +{ + static final String dir = "projects/scope/"; + + public void setUp() + throws Exception + { + ArtifactResolver resolver = lookup( ArtifactResolver.class, "classpath" ); + DefaultArtifactDescriptorReader pomReader = (DefaultArtifactDescriptorReader)lookup(ArtifactDescriptorReader.class); + pomReader.setArtifactResolver( resolver ); + + projectBuilder = lookup( ProjectBuilder.class, "classpath" ); + + // the metadata source looks up the default impl, so we have to trick it + getContainer().addComponent( projectBuilder, ProjectBuilder.class, "default" ); + + repositorySystem = lookup( RepositorySystem.class ); + } + + @Override + protected String getCustomConfigurationName() + { + return null; + } + + public void testProjectClasspath() + throws Exception + { + File f = getFileForClasspathResource( dir + "project-with-scoped-dependencies.xml" ); + + MavenProject project = getProjectWithDependencies( f ); + + Artifact artifact; + + assertNotNull( "Test project can't be null!", project ); + + checkArtifactIdScope( project, "provided", "provided" ); + checkArtifactIdScope( project, "test", "test" ); + checkArtifactIdScope( project, "compile", "compile" ); + checkArtifactIdScope( project, "runtime", "runtime" ); + checkArtifactIdScope( project, "default", "compile" ); + + // check all transitive deps of a test dependency are test, except test and provided which is skipped + artifact = getArtifact( project, "maven-test-test", "scope-provided" ); + assertNull( "Check no provided dependencies are transitive", artifact ); + artifact = getArtifact( project, "maven-test-test", "scope-test" ); + assertNull( "Check no test dependencies are transitive", artifact ); + + artifact = getArtifact( project, "maven-test-test", "scope-compile" ); + assertNotNull( artifact ); + + System.out.println( "a = " + artifact ); + System.out.println( "b = " + artifact.getScope() ); + assertEquals( "Check scope", "test", artifact.getScope() ); + artifact = getArtifact( project, "maven-test-test", "scope-default" ); + assertEquals( "Check scope", "test", artifact.getScope() ); + artifact = getArtifact( project, "maven-test-test", "scope-runtime" ); + assertEquals( "Check scope", "test", artifact.getScope() ); + + // check all transitive deps of a provided dependency are provided scope, except for test + checkGroupIdScope( project, "provided", "maven-test-provided" ); + artifact = getArtifact( project, "maven-test-provided", "scope-runtime" ); + assertEquals( "Check scope", "provided", artifact.getScope() ); + + // check all transitive deps of a runtime dependency are runtime scope, except for test + checkGroupIdScope( project, "runtime", "maven-test-runtime" ); + artifact = getArtifact( project, "maven-test-runtime", "scope-runtime" ); + assertEquals( "Check scope", "runtime", artifact.getScope() ); + + // check all transitive deps of a compile dependency are compile scope, except for runtime and test + checkGroupIdScope( project, "compile", "maven-test-compile" ); + artifact = getArtifact( project, "maven-test-compile", "scope-runtime" ); + assertEquals( "Check scope", "runtime", artifact.getScope() ); + + // check all transitive deps of a default dependency are compile scope, except for runtime and test + checkGroupIdScope( project, "compile", "maven-test-default" ); + artifact = getArtifact( project, "maven-test-default", "scope-runtime" ); + assertEquals( "Check scope", "runtime", artifact.getScope() ); + } + + private void checkGroupIdScope( MavenProject project, String scopeValue, String groupId ) + { + Artifact artifact; + artifact = getArtifact( project, groupId, "scope-compile" ); + assertEquals( "Check scope", scopeValue, artifact.getScope() ); + artifact = getArtifact( project, groupId, "scope-test" ); + assertNull( "Check test dependency is not transitive", artifact ); + artifact = getArtifact( project, groupId, "scope-provided" ); + assertNull( "Check provided dependency is not transitive", artifact ); + artifact = getArtifact( project, groupId, "scope-default" ); + assertEquals( "Check scope", scopeValue, artifact.getScope() ); + } + + private void checkArtifactIdScope( MavenProject project, String scope, String scopeValue ) + { + String artifactId = "scope-" + scope; + Artifact artifact = getArtifact( project, "maven-test", artifactId ); + assertNotNull( artifact ); + assertEquals( "Check scope", scopeValue, artifact.getScope() ); + } + + private Artifact getArtifact( MavenProject project, String groupId, String artifactId ) + { + System.out.println( "[ Looking for " + groupId + ":" + artifactId + " ]" ); + for ( Artifact a : project.getArtifacts() ) + { + System.out.println( a.toString() ); + if ( artifactId.equals( a.getArtifactId() ) && a.getGroupId().equals( groupId ) ) + { + System.out.println( "RETURN" ); + return a; + } + } + System.out.println( "Return null" ); + return null; + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestArtifactResolver.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestArtifactResolver.java new file mode 100644 index 00000000..9f389d6d --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestArtifactResolver.java @@ -0,0 +1,30 @@ +package org.apache.maven.project; + +/* + * 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.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.resolver.DefaultArtifactResolver; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +@Component(role=ArtifactResolver.class,hint="classpath") +public class TestArtifactResolver + extends DefaultArtifactResolver +{ + @Requirement(hint="classpath") + private ArtifactMetadataSource source; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java new file mode 100644 index 00000000..2818df06 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java @@ -0,0 +1,30 @@ +package org.apache.maven.project; + +/* + * 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.artifact.resolver.ArtifactResolver; +import org.apache.maven.repository.RepositorySystem; +import org.apache.maven.repository.legacy.LegacyRepositorySystem; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; + +@Component(role = RepositorySystem.class, hint = "classpath") +public class TestMavenRepositorySystem + extends LegacyRepositorySystem +{ + @Requirement(hint="classpath") + private ArtifactResolver artifactResolver; +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java new file mode 100644 index 00000000..754487f4 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -0,0 +1,68 @@ +package org.apache.maven.project; + +/* + * 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 java.io.File; +import java.io.FileNotFoundException; +import java.util.Collections; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.codehaus.plexus.component.annotations.Component; + +@Component(role=ProjectBuilder.class,hint="classpath") +public class TestProjectBuilder + extends DefaultProjectBuilder +{ + + @Override + public ProjectBuildingResult build( Artifact artifact, ProjectBuildingRequest request ) + throws ProjectBuildingException + { + if ( "maven-test".equals( artifact.getGroupId() ) ) + { + String scope = artifact.getArtifactId().substring( "scope-".length() ); + + try + { + artifact.setFile( ProjectClasspathTest.getFileForClasspathResource( ProjectClasspathTest.dir + "transitive-" + scope + "-dep.xml" ) ); + } + catch ( FileNotFoundException e ) + { + throw new IllegalStateException( "Missing test POM for " + artifact ); + } + } + if ( artifact.getFile() == null ) + { + MavenProject project = new MavenProject(); + project.setArtifact( artifact ); + return new DefaultProjectBuildingResult( project, null, null ); + } + return build( artifact.getFile(), request ); + } + + @Override + public ProjectBuildingResult build( File pomFile, ProjectBuildingRequest configuration ) + throws ProjectBuildingException + { + ProjectBuildingResult result = super.build( pomFile, configuration ); + + result.getProject().setRemoteArtifactRepositories( Collections.<ArtifactRepository> emptyList() ); + + return result; + } + +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java new file mode 100644 index 00000000..413d6fea --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/AbstractProjectInheritanceTestCase.java @@ -0,0 +1,57 @@ +package org.apache.maven.project.inheritance; + +/* + * 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 java.io.File; + +import org.apache.maven.project.AbstractMavenProjectTestCase; + +/** + * @author Jason van Zyl + */ +public abstract class AbstractProjectInheritanceTestCase + extends AbstractMavenProjectTestCase +{ + protected String getTestSeries() + { + String className = getClass().getPackage().getName(); + + return className.substring( className.lastIndexOf( "." ) + 1 ); + } + + protected File projectFile( String name ) + { + return projectFile( "maven", name ); + } + + protected File projectFile( String groupId, String artifactId ) + { + return new File( getLocalRepositoryPath(), "/" + groupId + "/poms/" + artifactId + "-1.0.pom" ); + } + + // ---------------------------------------------------------------------- + // The local repository for this category of tests + // ---------------------------------------------------------------------- + + protected File getLocalRepositoryPath() + { + return getTestFile("src/test/resources/inheritance-repo/" + getTestSeries() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java new file mode 100644 index 00000000..0ee79807 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t00/ProjectInheritanceTest.java @@ -0,0 +1,93 @@ +package org.apache.maven.project.inheritance.t00; + +/* + * 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.model.MailingList; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's recursive inheritance where + * a distinct value is taken from each parent contributing to the + * the final model of the project being assembled. There is no + * overriding going on amongst the models being used in this test: + * each model in the lineage is providing a value that is not present + * anywhere else in the lineage. We are just making sure that values + * down in the lineage are bubbling up where they should. + * + * @author Jason van Zyl + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p4 inherits from p3 + // p3 inherits from p2 + // p2 inherits from p1 + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p4 ---> p3 ---> p2 ---> p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testProjectInheritance() + throws Exception + { + MavenProject p4 = getProject( projectFile( "p4" ) ); + + assertEquals( "p4", p4.getName() ); + + // ---------------------------------------------------------------------- + // Value inherited from p3 + // ---------------------------------------------------------------------- + + assertEquals( "2000", p4.getInceptionYear() ); + + // ---------------------------------------------------------------------- + // Value taken from p2 + // ---------------------------------------------------------------------- + + assertEquals( "mailing-list", p4.getMailingLists().get( 0 ).getName() ); + + // ---------------------------------------------------------------------- + // Value taken from p1 + // ---------------------------------------------------------------------- + + assertEquals( "scm-url/p2/p3/p4", p4.getScm().getUrl() ); + + // ---------------------------------------------------------------------- + // Value taken from p4 + // ---------------------------------------------------------------------- + + assertEquals( "Codehaus", p4.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Value taken from super model + // ---------------------------------------------------------------------- + + assertEquals( "4.0.0", p4.getModelVersion() ); + + assertEquals( "4.0.0", p4.getModelVersion() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java new file mode 100644 index 00000000..e6efcc4d --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t01/ProjectInheritanceTest.java @@ -0,0 +1,92 @@ +package org.apache.maven.project.inheritance.t01; + +/* + * 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.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's recursive inheritance where + * we are testing to make sure that elements stated in a model are + * not clobbered by the same elements elsewhere in the lineage. + * + * @author Jason van Zyl + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p4 inherits from p3 + // p3 inherits from p2 + // p2 inherits from p1 + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p4 ---> p3 ---> p2 ---> p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testProjectInheritance() + throws Exception + { + // ---------------------------------------------------------------------- + // Check p0 value for org name + // ---------------------------------------------------------------------- + + MavenProject p0 = getProject( projectFile( "maven.t01", "p0" ) ); + + assertEquals( "p0-org", p0.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Check p1 value for org name + // ---------------------------------------------------------------------- + + MavenProject p1 = getProject( projectFile( "maven.t01", "p1" ) ); + + assertEquals( "p1-org", p1.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Check p2 value for org name + // ---------------------------------------------------------------------- + + MavenProject p2 = getProject( projectFile( "maven.t01", "p2" ) ); + + assertEquals( "p2-org", p2.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Check p2 value for org name + // ---------------------------------------------------------------------- + + MavenProject p3 = getProject( projectFile( "maven.t01", "p3" ) ); + + assertEquals( "p3-org", p3.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Check p4 value for org name + // ---------------------------------------------------------------------- + + MavenProject p4 = getProject( projectFile( "maven.t01", "p4" ) ); + + assertEquals( "p4-org", p4.getOrganization().getName() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java new file mode 100644 index 00000000..339c81ff --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t02/ProjectInheritanceTest.java @@ -0,0 +1,169 @@ +package org.apache.maven.project.inheritance.t02; + +/* + * 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 java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.maven.model.Build; +import org.apache.maven.model.MailingList; +import org.apache.maven.model.Plugin; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's recursive inheritance where + * a distinct value is taken from each parent contributing to the + * the final model of the project being assembled. There is no + * overriding going on amongst the models being used in this test: + * each model in the lineage is providing a value that is not present + * anywhere else in the lineage. We are just making sure that values + * down in the lineage are bubbling up where they should. + * + * @author Jason van Zyl + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p4 inherits from p3 + // p3 inherits from p2 + // p2 inherits from p1 + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p4 ---> p3 ---> p2 ---> p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testProjectInheritance() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + System.out.println( "Local repository is at: " + localRepo.getAbsolutePath() ); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom1 = new File( pom0.getParentFile(), "p1/pom.xml" ); + File pom2 = new File( pom1.getParentFile(), "p2/pom.xml" ); + File pom3 = new File( pom2.getParentFile(), "p3/pom.xml" ); + File pom4 = new File( pom3.getParentFile(), "p4/pom.xml" ); + File pom5 = new File( pom4.getParentFile(), "p5/pom.xml" ); + + System.out.println( "Location of project-4's POM: " + pom4.getPath() ); + + // load everything... + MavenProject project0 = getProject( pom0 ); + MavenProject project1 = getProject( pom1 ); + MavenProject project2 = getProject( pom2 ); + MavenProject project3 = getProject( pom3 ); + MavenProject project4 = getProject( pom4 ); + MavenProject project5 = getProject( pom5 ); + + assertEquals( "p4", project4.getName() ); + + // ---------------------------------------------------------------------- + // Value inherited from p3 + // ---------------------------------------------------------------------- + + assertEquals( "2000", project4.getInceptionYear() ); + + // ---------------------------------------------------------------------- + // Value taken from p2 + // ---------------------------------------------------------------------- + + assertEquals( "mailing-list", project4.getMailingLists().get( 0 ).getName() ); + + // ---------------------------------------------------------------------- + // Value taken from p1 + // ---------------------------------------------------------------------- + + assertEquals( "scm-url/p2/p3/p4", project4.getScm().getUrl() ); + + // ---------------------------------------------------------------------- + // Value taken from p4 + // ---------------------------------------------------------------------- + + assertEquals( "Codehaus", project4.getOrganization().getName() ); + + // ---------------------------------------------------------------------- + // Value taken from super model + // ---------------------------------------------------------------------- + + assertEquals( "4.0.0", project4.getModelVersion() ); + + Build build = project4.getBuild(); + List<Plugin> plugins = build.getPlugins(); + + Map validPluginCounts = new HashMap(); + + String testPluginArtifactId = "maven-compiler-plugin"; + + // this is the plugin we're looking for. + validPluginCounts.put( testPluginArtifactId, 0 ); + + // these are injected if -DperformRelease=true + validPluginCounts.put( "maven-deploy-plugin", 0 ); + validPluginCounts.put( "maven-javadoc-plugin", 0 ); + validPluginCounts.put( "maven-source-plugin", 0 ); + + Plugin testPlugin = null; + + for ( Plugin plugin : plugins ) + { + String pluginArtifactId = plugin.getArtifactId(); + + if ( !validPluginCounts.containsKey( pluginArtifactId ) ) + { + fail( "Illegal plugin found: " + pluginArtifactId ); + } + else + { + if ( pluginArtifactId.equals( testPluginArtifactId ) ) + { + testPlugin = plugin; + } + + Integer count = (Integer) validPluginCounts.get( pluginArtifactId ); + + if ( count > 0 ) + { + fail( "Multiple copies of plugin: " + pluginArtifactId + " found in POM." ); + } + else + { + count = count + 1; + + validPluginCounts.put( pluginArtifactId, count ); + } + } + } + + List executions = testPlugin.getExecutions(); + + assertEquals( 1, executions.size() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java new file mode 100644 index 00000000..73f518e4 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t03/ProjectInheritanceTest.java @@ -0,0 +1,68 @@ +package org.apache.maven.project.inheritance.t03; + +/* + * 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 java.io.File; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's recursive inheritance where + * a distinct value is taken from each parent contributing to the + * the final model of the project being assembled. There is no + * overriding going on amongst the models being used in this test: + * each model in the lineage is providing a value that is not present + * anywhere else in the lineage. We are just making sure that values + * down in the lineage are bubbling up where they should. + * + * @author Jason van Zyl + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testProjectInheritance() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + + File pom0Basedir = pom0.getParentFile(); + + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load everything... + MavenProject project0 = getProject( pom0 ); + MavenProject project1 = getProject( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java new file mode 100644 index 00000000..e24262f1 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t04/ProjectInheritanceTest.java @@ -0,0 +1,86 @@ +package org.apache.maven.project.inheritance.t04; + +/* + * 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 java.io.File; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies the version of a dependency listed in a parent's + * dependencyManagement section is chosen over another version of the same + * dependency, listed transitively. + * + * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // p1 has a depMgmt section that specifies versions 1.0 of jars "a" & "b" + // jar "a" has a transitive dependency on 2.0 of jar "b", but maven should + // prefer to use version 1.0. + // + // ---------------------------------------------------------------------- + + public void testDependencyManagementOverridesTransitiveDependencyVersion() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + Set set = project1.getArtifacts(); + assertNotNull( "No artifacts", set ); + assertTrue( "No Artifacts", set.size() > 0 ); + assertTrue( "Set size should be 3, is " + set.size(), set.size() == 3 ); + + for ( Object aSet : set ) + { + Artifact artifact = (Artifact) aSet; + System.out.println( + "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + ( + artifact.isOptional() + ? "true" + : "false" ) ); + assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), + artifact.getVersion().equals( "1.0" ) ); + } + + } +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java new file mode 100644 index 00000000..1d2bd182 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t05/ProjectInheritanceTest.java @@ -0,0 +1,79 @@ +package org.apache.maven.project.inheritance.t05; + +/* + * 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 java.io.File; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's dependency management + * + * @author <a href="rgoers@apache.org">Ralph Goers</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagement() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + + File pom0Basedir = pom0.getParentFile(); + + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load everything... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + Set set = project1.getArtifacts(); + assertNotNull( "No artifacts", set ); + assertTrue( "No Artifacts", set.size() > 0 ); + + for ( Object aSet : set ) + { + Artifact artifact = (Artifact) aSet; + System.out.println( + "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Scope: " + + artifact.getScope() ); + assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), + artifact.getVersion().equals( "1.0" ) ); + } + + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java new file mode 100644 index 00000000..1b80dfeb --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t06/ProjectInheritanceTest.java @@ -0,0 +1,80 @@ +package org.apache.maven.project.inheritance.t06; + +/* + * 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 java.io.File; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's dependency management + * + * @author <a href="rgoers@apache.org">Ralph Goers</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagement() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + + File pom0Basedir = pom0.getParentFile(); + + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load everything... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + Set set = project1.getArtifacts(); + assertNotNull( "No artifacts", set ); + assertTrue( "No Artifacts", set.size() > 0 ); + Iterator iter = set.iterator(); + assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 ); + + while ( iter.hasNext() ) + { + Artifact artifact = (Artifact) iter.next(); + System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + + " Optional=" + ( artifact.isOptional() ? "true" : "false" ) ); + assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), + artifact.getVersion().equals( "1.0" ) ); + } + + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java new file mode 100644 index 00000000..68586aaf --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t07/ProjectInheritanceTest.java @@ -0,0 +1,82 @@ +package org.apache.maven.project.inheritance.t07; + +/* + * 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 java.io.File; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's dependency management + * + * @author Jason van Zyl + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagement() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + + File pom0Basedir = pom0.getParentFile(); + + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load everything... + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + System.out.println("Project " + project1.getId() + " " + project1); + Set set = project1.getArtifacts(); + assertNotNull("No artifacts", set); + assertTrue("No Artifacts", set.size() > 0); + assertTrue("Set size should be 3, is " + set.size(), set.size() == 3 ); + + for ( Object aSet : set ) + { + Artifact artifact = (Artifact) aSet; + assertFalse( "", artifact.getArtifactId().equals( "t07-d" ) ); + System.out.println( + "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + " Optional=" + ( + artifact.isOptional() + ? "true" + : "false" ) ); + assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), + artifact.getVersion().equals( "1.0" ) ); + } + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java new file mode 100644 index 00000000..1afb8e8e --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t08/ProjectInheritanceTest.java @@ -0,0 +1,81 @@ +package org.apache.maven.project.inheritance.t08; + +/* + * 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 java.io.File; +import java.util.Iterator; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * A test which demonstrates maven's dependency management + * + * @author <a href="rgoers@apache.org">Ralph Goers</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagement() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + File pom0 = new File( localRepo, "p0/pom.xml" ); + + File pom0Basedir = pom0.getParentFile(); + + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load everything... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + System.out.println( "Project " + project1.getId() + " " + project1 ); + Set set = project1.getArtifacts(); + assertNotNull( "No artifacts", set ); + assertTrue( "No Artifacts", set.size() > 0 ); + Iterator iter = set.iterator(); + assertTrue( "Set size should be 4, is " + set.size(), set.size() == 4 ); + + while ( iter.hasNext() ) + { + Artifact artifact = (Artifact) iter.next(); + System.out.println( "Artifact: " + artifact.getDependencyConflictId() + " " + artifact.getVersion() + + " Optional=" + ( artifact.isOptional() ? "true" : "false" ) ); + assertTrue( "Incorrect version for " + artifact.getDependencyConflictId(), + artifact.getVersion().equals( "1.0" ) ); + } + + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java new file mode 100644 index 00000000..6a29b732 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t09/ProjectInheritanceTest.java @@ -0,0 +1,119 @@ +package org.apache.maven.project.inheritance.t09; + +/* + * 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 java.io.File; +import java.util.Map; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies exclusions listed in dependencyManagement are valid for + * transitive dependencies. + * + * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + /** + * How the test project is set up: + * + * 1. dependencyManagement lists dependencies on a & b, + * with an exclusion on c in b. + * 2. the child project lists a dependency on project a only + * 3. a depends on b (which is transitive to the child project), + * and b depends on c. + * + * We should see that the resulting size of collected artifacts is two: + * a & b only. + */ + public void testDependencyManagementExclusionsExcludeTransitively() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertNotNull("Parent is null", project1.getParent()); + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + Map map = project1.getArtifactMap(); + + assertNotNull("No artifacts", map); + assertTrue("No Artifacts", map.size() > 0); + assertTrue("Set size should be 2, is " + map.size(), map.size() == 2); + + assertTrue("maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" )); + assertTrue("maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" )); + assertFalse("maven-test:t09-c is in the project", map.containsKey( "maven-test:t09-c" )); + } + + /** + * Setup exactly the same as the above test, except that the child project + * now depends upon d, which has a transitive dependency on c. Even though + * we did list an exclusion on c, it was only from within the context of + * project b. We will pick up project c in this case because no + * restrictions were placed on d. This demonstrates that a, b, c, & d will + * all be collected. + * + * @throws Exception + */ + public void testDependencyManagementExclusionDoesNotOverrideGloballyForTransitives() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom2 = new File( pom0Basedir, "p2/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project2 = getProjectWithDependencies( pom2 ); + + assertEquals( pom0Basedir, project2.getParent().getBasedir() ); + Map map = project2.getArtifactMap(); + assertNotNull( "No artifacts", map ); + assertTrue( "No Artifacts", map.size() > 0 ); + assertTrue( "Set size should be 4, is " + map.size(), map.size() == 4 ); + + assertTrue( "maven-test:t09-a is not in the project", map.containsKey( "maven-test:t09-a" ) ); + assertTrue( "maven-test:t09-b is not in the project", map.containsKey( "maven-test:t09-b" ) ); + assertTrue( "maven-test:t09-c is not in the project", map.containsKey( "maven-test:t09-c" ) ); + assertTrue( "maven-test:t09-d is not in the project", map.containsKey( "maven-test:t09-d" ) ); + } +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java new file mode 100644 index 00000000..9e5137f2 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t10/ProjectInheritanceTest.java @@ -0,0 +1,94 @@ +package org.apache.maven.project.inheritance.t10; + +/* + * 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 java.io.File; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies scope inheritence of direct and transitive dependencies. + * + * Should show three behaviors: + * + * 1. dependencyManagement should override the scope of transitive dependencies. + * 2. Direct dependencies should override the scope of dependencyManagement. + * 3. Direct dependencies should inherit scope from dependencyManagement when + * they do not explicitly state a scope. + * + * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagementOverridesTransitiveDependencyVersion() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + System.out.println("Project " + project1.getId() + " " + project1); + Map map = project1.getArtifactMap(); + assertNotNull("No artifacts", map); + assertTrue("No Artifacts", map.size() > 0); + assertTrue("Set size should be 3, is " + map.size(), map.size() == 3); + + Artifact a = (Artifact) map.get("maven-test:t10-a"); + Artifact b = (Artifact) map.get("maven-test:t10-b"); + Artifact c = (Artifact) map.get("maven-test:t10-c"); + + assertNotNull( a ); + assertNotNull( b ); + assertNotNull( c ); + + // inherited from depMgmt + System.out.println(a.getScope()); + assertTrue("Incorrect scope for " + a.getDependencyConflictId(), a.getScope().equals("test")); + + // transitive dep, overridden b depMgmt + assertTrue("Incorrect scope for " + b.getDependencyConflictId(), b.getScope().equals("runtime")); + + // direct dep, overrides depMgmt + assertTrue("Incorrect scope for " + c.getDependencyConflictId(), c.getScope().equals("runtime")); + + } +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java new file mode 100644 index 00000000..bbdecd7a --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t11/ProjectInheritanceTest.java @@ -0,0 +1,64 @@ +package org.apache.maven.project.inheritance.t11; + +/* + * 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 java.io.File; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies scope of root project is preserved regardless of parent depenedency management. + * + * @author <a href="mailto:pschneider@gmail.com">Patrick Schneider</a> + * @see <a href="http://jira.codehaus.org/browse/MNG-2919">MNG-2919</a> + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testDependencyManagementDoesNotOverrideScopeOfCurrentArtifact() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + assertEquals( pom0Basedir, project1.getParent().getBasedir() ); + assertNull( "dependencyManagement has overwritten the scope of the currently building child project", + project1.getArtifact().getScope() ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java new file mode 100644 index 00000000..814e4871 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12/ProjectInheritanceTest.java @@ -0,0 +1,65 @@ +package org.apache.maven.project.inheritance.t12; + +/* + * 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 java.io.File; +import java.util.Map; + +import org.apache.maven.model.Plugin; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies that plugin execution sections in the parent POM that have + * inherit == false are not inherited to the child POM. + */ +public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inherits from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testFalsePluginExecutionInheritValue() throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "p1/pom.xml" ); + + getProjectWithDependencies( pom0 ); + MavenProject project1 = getProjectWithDependencies( pom1 ); + + Map pluginMap = project1.getBuild().getPluginsAsMap(); + Plugin compilerPlugin = (Plugin) pluginMap.get( "org.apache.maven.plugins:maven-compiler-plugin" ); + + assertNotNull( compilerPlugin ); + + Map executionMap = compilerPlugin.getExecutionsAsMap(); + assertNull( "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!", executionMap.get( "test" ) ); + } +}
\ No newline at end of file diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java new file mode 100644 index 00000000..3b086624 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/inheritance/t12scm/ProjectInheritanceTest.java @@ -0,0 +1,125 @@ +package org.apache.maven.project.inheritance.t12scm; + +/* + * 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 java.io.File; + +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase; + +/** + * Verifies SCM inheritance uses modules statement from parent. + * + * @author jdcasey + */ +public class ProjectInheritanceTest + extends AbstractProjectInheritanceTestCase +{ + // ---------------------------------------------------------------------- + // + // p1 inherits from p0 + // p0 inhertis from super model + // + // or we can show it graphically as: + // + // p1 ---> p0 --> super model + // + // ---------------------------------------------------------------------- + + public void testScmInfoCalculatedCorrectlyOnParentAndChildRead() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom0 = new File( localRepo, "p0/pom.xml" ); + File pom0Basedir = pom0.getParentFile(); + File pom1 = new File( pom0Basedir, "modules/p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project0 = getProject( pom0 ); + MavenProject project1 = getProject( pom1 ); + + System.out.println( "\n\n" ); + System.out.println( "Parent SCM URL is: " + project0.getScm().getUrl() ); + System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() ); + System.out.println(); + System.out.println( "Parent SCM connection is: " + project0.getScm().getConnection() ); + System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() ); + System.out.println(); + System.out.println( "Parent SCM developer connection is: " + + project0.getScm().getDeveloperConnection() ); + System.out.println( "Child SCM developer connection is: " + + project1.getScm().getDeveloperConnection() ); + + assertEquals( project1.getScm().getUrl(), project0.getScm().getUrl() + "/modules/p1" ); + assertEquals( project1.getScm().getConnection(), project0.getScm().getConnection() + + "/modules/p1" ); + assertEquals( project1.getScm().getDeveloperConnection(), project0.getScm() + .getDeveloperConnection() + + "/modules/p1" ); + } + + public void testScmInfoCalculatedCorrectlyOnChildOnlyRead() + throws Exception + { + File localRepo = getLocalRepositoryPath(); + + File pom1 = new File( localRepo, "p0/modules/p1/pom.xml" ); + + // load the child project, which inherits from p0... + MavenProject project1 = getProject( pom1 ); + + System.out.println( "\n\n" ); + System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() ); + System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() ); + System.out.println( "Child SCM developer connection is: " + + project1.getScm().getDeveloperConnection() ); + + assertEquals( "http://host/viewer?path=/p0/modules/p1", project1.getScm().getUrl() ); + assertEquals( "scm:svn:http://host/p0/modules/p1", project1.getScm().getConnection() ); + assertEquals( "scm:svn:https://host/p0/modules/p1", project1.getScm().getDeveloperConnection() ); + } + +// public void testScmInfoCalculatedCorrectlyOnChildReadFromLocalRepository() +// throws Exception +// { +// File localRepo = getLocalRepositoryPath(); +// +// ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.class ); +// Artifact artifact = factory.createProjectArtifact( "maven", "p1", "1.0" ); +// +// ArtifactRepositoryFactory repoFactory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.class ); +// ArtifactRepository localArtifactRepo = repoFactory.createLocalRepository( localRepo ); +// +// MavenProject project1 = getProjectBuilder().buildFromRepository( artifact, Collections.EMPTY_LIST, localArtifactRepo ); +// +// System.out.println( "\n\n" ); +// System.out.println( "Child SCM URL is: " + project1.getScm().getUrl() ); +// System.out.println( "Child SCM connection is: " + project1.getScm().getConnection() ); +// System.out.println( "Child SCM developer connection is: " +// + project1.getScm().getDeveloperConnection() ); +// +// assertEquals( project1.getScm().getUrl(), "http://host/viewer?path=/p0/modules/p1" ); +// assertEquals( project1.getScm().getConnection(), "scm:svn:http://host/p0/modules/p1" ); +// assertEquals( project1.getScm().getDeveloperConnection(), +// "scm:svn:https://host/p0/modules/p1" ); +// } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java new file mode 100644 index 00000000..b19ef996 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-compat/src/test/java/org/apache/maven/project/path/DefaultPathTranslatorTest.java @@ -0,0 +1,58 @@ +package org.apache.maven.project.path; + +/* + * 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 java.io.File; + +import junit.framework.TestCase; + +@SuppressWarnings( "deprecation" ) +public class DefaultPathTranslatorTest + extends TestCase +{ + + public void testAlignToBasedirWhereBasedirExpressionIsTheCompleteValue() + { + File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); + + String aligned = new DefaultPathTranslator().alignToBaseDirectory( "${basedir}", basedir ); + + assertEquals( basedir.getAbsolutePath(), aligned ); + } + + public void testAlignToBasedirWhereBasedirExpressionIsTheValuePrefix() + { + File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); + + String aligned = new DefaultPathTranslator().alignToBaseDirectory( "${basedir}/dir", basedir ); + + assertEquals( new File( basedir, "dir" ).getAbsolutePath(), aligned ); + } + + public void testUnalignToBasedirWherePathEqualsBasedir() + { + File basedir = new File( System.getProperty( "java.io.tmpdir" ), "test" ).getAbsoluteFile(); + + String unaligned = new DefaultPathTranslator().unalignFromBaseDirectory( basedir.getAbsolutePath(), basedir ); + + assertEquals( ".", unaligned ); + } + +} |