diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven')
12 files changed, 2530 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java new file mode 100644 index 00000000..9ef31b3d --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/ComplexActivationTest.java @@ -0,0 +1,60 @@ +package org.apache.maven.model.building; + + /* + * 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 junit.framework.TestCase; + +import java.io.File; +import java.util.Properties; + +/** + * @author Konstantin Perikov + */ +public class ComplexActivationTest + extends TestCase +{ + + private File getPom( String name ) + { + return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile(); + } + + public void testAndConditionInActivation() + throws Exception + { + Properties sysProperties = new Properties(); + sysProperties.setProperty( "myproperty", "test" ); + + ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); + assertNotNull( builder ); + + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setProcessPlugins( true ); + request.setPomFile( getPom( "complex" ) ); + request.setSystemProperties( sysProperties ); + + ModelBuildingResult result = builder.build( request ); + assertNotNull( result ); + assertNotNull( result.getEffectiveModel() ); + assertEquals( "activated-1", result.getEffectiveModel().getProperties().get( "profile.file" ) ); + assertNull( result.getEffectiveModel().getProperties().get( "profile.miss" ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java new file mode 100644 index 00000000..90b65a4c --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/DefaultModelBuilderFactoryTest.java @@ -0,0 +1,59 @@ +package org.apache.maven.model.building; + +/* + * 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.codehaus.plexus.util.xml.Xpp3Dom; + +import junit.framework.TestCase; + +/** + * @author Benjamin Bentmann + */ +public class DefaultModelBuilderFactoryTest + extends TestCase +{ + + private File getPom( String name ) + { + return new File( "src/test/resources/poms/factory/" + name + ".xml" ).getAbsoluteFile(); + } + + public void testCompleteWiring() + throws Exception + { + ModelBuilder builder = new DefaultModelBuilderFactory().newInstance(); + assertNotNull( builder ); + + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setProcessPlugins( true ); + request.setPomFile( getPom( "simple" ) ); + + ModelBuildingResult result = builder.build( request ); + assertNotNull( result ); + assertNotNull( result.getEffectiveModel() ); + assertEquals( "activated", result.getEffectiveModel().getProperties().get( "profile.file" ) ); + Xpp3Dom conf = (Xpp3Dom) result.getEffectiveModel().getBuild().getPlugins().get( 0 ).getConfiguration(); + assertEquals( "1.5", conf.getChild( "source" ).getValue() ); + assertEquals( " 1.5 ", conf.getChild( "target" ).getValue() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java new file mode 100644 index 00000000..bb0ccff9 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/building/SimpleProblemCollector.java @@ -0,0 +1,89 @@ +package org.apache.maven.model.building; + +/* + * 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.ArrayList; +import java.util.List; + +import org.apache.maven.model.Model; + + +/** + * A simple model problem collector for testing the model building components. + * + * @author Benjamin Bentmann + */ +public class SimpleProblemCollector + implements ModelProblemCollector +{ + private Model model; + + private List<String> warnings = new ArrayList<String>(); + + private List<String> errors = new ArrayList<String>(); + + private List<String> fatals = new ArrayList<String>(); + + public SimpleProblemCollector() + { + } + + public SimpleProblemCollector( Model model ) + { + this.model = model; + } + + public Model getModel() + { + return model; + } + + public List<String> getWarnings() + { + return warnings; + } + + public List<String> getErrors() + { + return errors; + } + + public List<String> getFatals() + { + return fatals; + } + + public void add( ModelProblemCollectorRequest req ) + { + switch ( req.getSeverity() ) + { + case FATAL: + fatals.add( req.getMessage() ); + break; + case ERROR: + errors.add( req.getMessage() ); + break; + case WARNING: + warnings.add( req.getMessage() ); + break; + } + + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java new file mode 100644 index 00000000..1aef12ec --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/inheritance/DefaultInheritanceAssemblerTest.java @@ -0,0 +1,108 @@ +package org.apache.maven.model.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 java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; + +import org.apache.maven.model.Model; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.io.ModelParseException; +import org.apache.maven.model.io.ModelReader; +import org.apache.maven.model.io.ModelWriter; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.util.IOUtil; +import org.custommonkey.xmlunit.XMLAssert; +import org.custommonkey.xmlunit.XMLUnit; + +/** + * @author HervĂ© Boutemy + */ +public class DefaultInheritanceAssemblerTest + extends PlexusTestCase +{ + private ModelReader reader; + + private ModelWriter writer; + + private InheritanceAssembler assembler; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + reader = lookup( ModelReader.class ); + writer = lookup( ModelWriter.class ); + assembler = lookup( InheritanceAssembler.class ); + } + + private File getPom( String name ) + { + return getTestFile( "src/test/resources/poms/inheritance/" + name + ".xml" ); + } + + private Model getModel( String name ) + throws ModelParseException, IOException + { + return reader.read( getPom( name ), null ); + } + + public void testPluginConfiguration() + throws Exception + { + Model parent = getModel( "plugin-configuration-parent" ); + + Model child = getModel( "plugin-configuration-child" ); + + SimpleProblemCollector problems = new SimpleProblemCollector(); + + assembler.assembleModelInheritance( child, parent, null, problems ); + + File actual = getTestFile( "target/test-classes/poms/inheritance/plugin-configuration-actual.xml" ); + + writer.write( actual, null, child ); + + // check with getPom( "plugin-configuration-effective" ) + Reader control = null; + Reader test = null; + try + { + File expected = getPom( "plugin-configuration-expected" ); + control = new InputStreamReader( new FileInputStream( expected ), "UTF-8" ); + + test = new InputStreamReader( new FileInputStream( actual ), "UTF-8" ); + + XMLUnit.setIgnoreComments( true ); + XMLUnit.setIgnoreWhitespace( true ); + XMLAssert.assertXMLEqual( control, test ); + } + catch ( IOException ioe ) + { + IOUtil.close( control ); + IOUtil.close( test ); + } + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java new file mode 100644 index 00000000..99842dfe --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/AbstractModelInterpolatorTest.java @@ -0,0 +1,494 @@ +package org.apache.maven.model.interpolation; + +/* + * 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.Build; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Organization; +import org.apache.maven.model.Repository; +import org.apache.maven.model.Resource; +import org.apache.maven.model.Scm; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.path.PathTranslator; +import org.codehaus.plexus.PlexusTestCase; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.TimeZone; + +/** + * @author jdcasey + */ +public abstract class AbstractModelInterpolatorTest + extends PlexusTestCase +{ + private Properties context; + + protected void setUp() + throws Exception + { + super.setUp(); + + context = new Properties(); + context.put( "basedir", "myBasedir" ); + context.put( "project.baseUri", "myBaseUri" ); + } + + + protected void assertProblemFree( SimpleProblemCollector collector ) + { + assertEquals( "Expected no errors", 0, collector.getErrors().size() ); + assertEquals( "Expected no warnings", 0, collector.getWarnings().size() ); + assertEquals( "Expected no fatals", 0, collector.getFatals().size() ); + } + + protected void assertColllectorState( int numFatals, int numErrors, int numWarnings, + SimpleProblemCollector collector ) + { + assertEquals( "Errors", numErrors, collector.getErrors().size() ); + assertEquals( "Warnings", numWarnings, collector.getWarnings().size() ); + assertEquals( "Fatals", numFatals, collector.getFatals().size() ); + } + + private ModelBuildingRequest createModelBuildingRequest( Properties p ) + { + ModelBuildingRequest config = new DefaultModelBuildingRequest(); + if ( p != null ) + { + config.setSystemProperties( p ); + } + return config; + } + + public void testDefaultBuildTimestampFormatShouldFormatTimeIn24HourFormat() + { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("UTC")); + cal.set( Calendar.HOUR, 12 ); + cal.set( Calendar.AM_PM, Calendar.AM ); + + // just to make sure all the bases are covered... + cal.set( Calendar.HOUR_OF_DAY, 0 ); + cal.set( Calendar.MINUTE, 16 ); + cal.set( Calendar.SECOND, 0 ); + cal.set( Calendar.YEAR, 1976 ); + cal.set( Calendar.MONTH, Calendar.NOVEMBER ); + cal.set( Calendar.DATE, 11 ); + + Date firstTestDate = cal.getTime(); + + cal.set( Calendar.HOUR, 11 ); + cal.set( Calendar.AM_PM, Calendar.PM ); + + // just to make sure all the bases are covered... + cal.set( Calendar.HOUR_OF_DAY, 23 ); + + Date secondTestDate = cal.getTime(); + + SimpleDateFormat format = + new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT ); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + assertEquals( "1976-11-11T00:16:00Z", format.format( firstTestDate ) ); + assertEquals( "1976-11-11T23:16:00Z", format.format( secondTestDate ) ); + } + + public void testDefaultBuildTimestampFormatWithLocalTimeZoneMidnightRollover() + { + Calendar cal = Calendar.getInstance(); + cal.setTimeZone(TimeZone.getTimeZone("Europe/Berlin")); + + cal.set( Calendar.HOUR_OF_DAY, 1 ); + cal.set( Calendar.MINUTE, 16 ); + cal.set( Calendar.SECOND, 0 ); + cal.set( Calendar.YEAR, 2014 ); + cal.set( Calendar.MONTH, Calendar.JUNE ); + cal.set( Calendar.DATE, 16 ); + + Date firstTestDate = cal.getTime(); + + cal.set( Calendar.MONTH, Calendar.NOVEMBER ); + + Date secondTestDate = cal.getTime(); + + SimpleDateFormat format = + new SimpleDateFormat( MavenBuildTimestamp.DEFAULT_BUILD_TIMESTAMP_FORMAT ); + format.setTimeZone(TimeZone.getTimeZone("UTC")); + assertEquals( "2014-06-15T23:16:00Z", format.format( firstTestDate ) ); + assertEquals( "2014-11-16T00:16:00Z", format.format( secondTestDate ) ); + } + + public void testShouldNotThrowExceptionOnReferenceToNonExistentValue() + throws Exception + { + Model model = new Model(); + + Scm scm = new Scm(); + scm.setConnection( "${test}/somepath" ); + + model.setScm( scm ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + + assertProblemFree( collector ); + assertEquals( "${test}/somepath", out.getScm().getConnection() ); + } + + public void testShouldThrowExceptionOnRecursiveScmConnectionReference() + throws Exception + { + Model model = new Model(); + + Scm scm = new Scm(); + scm.setConnection( "${project.scm.connection}/somepath" ); + + model.setScm( scm ); + + try + { + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector ); + assertColllectorState( 0, 1, 0, collector ); + } + catch ( Exception e ) + { + + } + } + + public void testShouldNotThrowExceptionOnReferenceToValueContainingNakedExpression() + throws Exception + { + Model model = new Model(); + + Scm scm = new Scm(); + scm.setConnection( "${test}/somepath" ); + + model.setScm( scm ); + + model.addProperty( "test", "test" ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + + assertProblemFree( collector ); + + assertEquals( "test/somepath", out.getScm().getConnection() ); + } + + public void testShouldInterpolateOrganizationNameCorrectly() + throws Exception + { + String orgName = "MyCo"; + + Model model = new Model(); + model.setName( "${pom.organization.name} Tools" ); + + Organization org = new Organization(); + org.setName( orgName ); + + model.setOrganization( org ); + + ModelInterpolator interpolator = createInterpolator(); + + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), + new SimpleProblemCollector() ); + + assertEquals( orgName + " Tools", out.getName() ); + } + + public void testShouldInterpolateDependencyVersionToSetSameAsProjectVersion() + throws Exception + { + Model model = new Model(); + model.setVersion( "3.8.1" ); + + Dependency dep = new Dependency(); + dep.setVersion( "${version}" ); + + model.addDependency( dep ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertColllectorState(0, 0, 1, collector ); + + assertEquals( "3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() ); + } + + public void testShouldNotInterpolateDependencyVersionWithInvalidReference() + throws Exception + { + Model model = new Model(); + model.setVersion( "3.8.1" ); + + Dependency dep = new Dependency(); + dep.setVersion( "${something}" ); + + model.addDependency( dep ); + + /* + // This is the desired behaviour, however there are too many crappy poms in the repo and an issue with the + // timing of executing the interpolation + + try + { + new RegexBasedModelInterpolator().interpolate( model, context ); + fail( "Should have failed to interpolate with invalid reference" ); + } + catch ( ModelInterpolationException expected ) + { + assertTrue( true ); + } + */ + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( "${something}", ( out.getDependencies().get( 0 ) ).getVersion() ); + } + + public void testTwoReferences() + throws Exception + { + Model model = new Model(); + model.setVersion( "3.8.1" ); + model.setArtifactId( "foo" ); + + Dependency dep = new Dependency(); + dep.setVersion( "${artifactId}-${version}" ); + + model.addDependency( dep ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertColllectorState( 0, 0, 2, collector ); + + assertEquals( "foo-3.8.1", ( out.getDependencies().get( 0 ) ).getVersion() ); + } + + public void testBasedir() + throws Exception + { + Model model = new Model(); + model.setVersion( "3.8.1" ); + model.setArtifactId( "foo" ); + + Repository repository = new Repository(); + + repository.setUrl( "file://localhost/${basedir}/temp-repo" ); + + model.addRepository( repository ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( "file://localhost/myBasedir/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() ); + } + + public void testBaseUri() + throws Exception + { + Model model = new Model(); + model.setVersion( "3.8.1" ); + model.setArtifactId( "foo" ); + + Repository repository = new Repository(); + + repository.setUrl( "${project.baseUri}/temp-repo" ); + + model.addRepository( repository ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( "myBaseUri/temp-repo", ( out.getRepositories().get( 0 ) ).getUrl() ); + } + + public void testEnvars() + throws Exception + { + Properties context = new Properties(); + + context.put( "env.HOME", "/path/to/home" ); + + Model model = new Model(); + + Properties modelProperties = new Properties(); + + modelProperties.setProperty( "outputDirectory", "${env.HOME}" ); + + model.setProperties( modelProperties ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( "/path/to/home", out.getProperties().getProperty( "outputDirectory" ) ); + } + + public void testEnvarExpressionThatEvaluatesToNullReturnsTheLiteralString() + throws Exception + { + Model model = new Model(); + + Properties modelProperties = new Properties(); + + modelProperties.setProperty( "outputDirectory", "${env.DOES_NOT_EXIST}" ); + + model.setProperties( modelProperties ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${env.DOES_NOT_EXIST}" ); + } + + public void testExpressionThatEvaluatesToNullReturnsTheLiteralString() + throws Exception + { + Model model = new Model(); + + Properties modelProperties = new Properties(); + + modelProperties.setProperty( "outputDirectory", "${DOES_NOT_EXIST}" ); + + model.setProperties( modelProperties ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = + interpolator.interpolateModel( model, new File( "." ), createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + assertEquals( out.getProperties().getProperty( "outputDirectory" ), "${DOES_NOT_EXIST}" ); + } + + public void testShouldInterpolateSourceDirectoryReferencedFromResourceDirectoryCorrectly() + throws Exception + { + Model model = new Model(); + + Build build = new Build(); + build.setSourceDirectory( "correct" ); + + Resource res = new Resource(); + res.setDirectory( "${project.build.sourceDirectory}" ); + + build.addResource( res ); + + Resource res2 = new Resource(); + res2.setDirectory( "${pom.build.sourceDirectory}" ); + + build.addResource( res2 ); + + Resource res3 = new Resource(); + res3.setDirectory( "${build.sourceDirectory}" ); + + build.addResource( res3 ); + + model.setBuild( build ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model out = interpolator.interpolateModel( model, null, createModelBuildingRequest( context ), collector ); + assertColllectorState( 0, 0, 2, collector ); + + + List<Resource> outResources = out.getBuild().getResources(); + Iterator<Resource> resIt = outResources.iterator(); + + assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() ); + assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() ); + assertEquals( build.getSourceDirectory(), resIt.next().getDirectory() ); + } + + public void testShouldInterpolateUnprefixedBasedirExpression() + throws Exception + { + File basedir = new File( "/test/path" ); + Model model = new Model(); + Dependency dep = new Dependency(); + dep.setSystemPath( "${basedir}/artifact.jar" ); + + model.addDependency( dep ); + + ModelInterpolator interpolator = createInterpolator(); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + Model result = interpolator.interpolateModel( model, basedir, createModelBuildingRequest( context ), collector ); + assertProblemFree( collector ); + + + List<Dependency> rDeps = result.getDependencies(); + assertNotNull( rDeps ); + assertEquals( 1, rDeps.size() ); + assertEquals( new File( basedir, "artifact.jar" ).getAbsolutePath(), + new File( rDeps.get( 0 ).getSystemPath() ).getAbsolutePath() ); + } + + protected abstract ModelInterpolator createInterpolator( PathTranslator translator ) + throws Exception; + + protected abstract ModelInterpolator createInterpolator() + throws Exception; + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java new file mode 100644 index 00000000..8af32fc5 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/MavenBuildTimestampTest.java @@ -0,0 +1,38 @@ +package org.apache.maven.model.interpolation; + +/* + * 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.Date; +import java.util.Properties; + +import junit.framework.TestCase; + +public class MavenBuildTimestampTest + extends TestCase +{ + public void testMavenBuildTimestampUsesUTC() + { + Properties interpolationProperties = new Properties(); + interpolationProperties.setProperty( "maven.build.timestamp.format", "yyyyMMdd'T'HHmm'Z'" ); + MavenBuildTimestamp timestamp = new MavenBuildTimestamp( new Date(), interpolationProperties ); + String formattedTimestamp = timestamp.formattedTimestamp(); + assertTrue( "We expect the UTC marker at the end of the timestamp.", formattedTimestamp.endsWith( "Z" ) ); + } +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java new file mode 100644 index 00000000..c4cae3d4 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java @@ -0,0 +1,505 @@ +package org.apache.maven.model.interpolation; + +/* + * 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.InputLocation; +import org.apache.maven.model.InputSource; +import org.apache.maven.model.Model; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.model.building.SimpleProblemCollector; + +import java.io.File; +import java.util.*; +import java.util.concurrent.Callable; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Future; +import java.util.concurrent.FutureTask; + +/** + * @author jdcasey + * @author Benjamin Bentmann + */ +public class StringSearchModelInterpolatorTest + extends AbstractModelInterpolatorTest +{ + + protected ModelInterpolator interpolator; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + interpolator = lookup( ModelInterpolator.class ); + } + + + protected ModelInterpolator createInterpolator( org.apache.maven.model.path.PathTranslator translator ) + throws Exception + { + return this.interpolator; + } + + protected ModelInterpolator createInterpolator() + throws Exception + { + return this.interpolator; + } + + public void testInterpolateStringArray() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + String[] values = { "${key}", "${key2}" }; + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest(p); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( values, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", values[0] ); + assertEquals( "value2", values[1] ); + } + + private ModelBuildingRequest createModelBuildingRequest( Properties p ) + { + ModelBuildingRequest config = new DefaultModelBuildingRequest(); + config.setSystemProperties( p ); + return config; + } + + public void testInterpolateObjectWithStringArrayField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + String[] values = { "${key}", "${key2}" }; + + ObjectWithStringArrayField obj = new ObjectWithStringArrayField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", obj.values[0] ); + assertEquals( "value2", obj.values[1] ); + } + + public void testInterpolateObjectWithStringListField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + List<String> values = new ArrayList<String>(); + values.add( "${key}" ); + values.add( "${key2}" ); + + ObjectWithListField obj = new ObjectWithListField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", obj.values.get( 0 ) ); + assertEquals( "value2", obj.values.get( 1 ) ); + } + + public void testInterpolateObjectWithStringListFieldAndOneLiteralValue() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + List<String> values = new ArrayList<String>(); + values.add( "key" ); + values.add( "${key2}" ); + + ObjectWithListField obj = new ObjectWithListField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "key", obj.values.get( 0 ) ); + assertEquals( "value2", obj.values.get( 1 ) ); + } + + public void testInterpolateObjectWithUnmodifiableStringListField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + List<String> values = Collections.unmodifiableList( Collections.singletonList( "${key}" ) ); + + ObjectWithListField obj = new ObjectWithListField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "${key}", obj.values.get( 0 ) ); + } + + public void testInterpolateObjectWithStringArrayListField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + p.setProperty( "key3", "value3" ); + p.setProperty( "key4", "value4" ); + + List<String[]> values = new ArrayList<String[]>(); + values.add( new String[] { "${key}", "${key2}" } ); + values.add( new String[] { "${key3}", "${key4}" } ); + + ObjectWithListField obj = new ObjectWithListField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", ( (String[]) obj.values.get( 0 ) )[0] ); + assertEquals( "value2", ( (String[]) obj.values.get( 0 ) )[1] ); + assertEquals( "value3", ( (String[]) obj.values.get( 1 ) )[0] ); + assertEquals( "value4", ( (String[]) obj.values.get( 1 ) )[1] ); + } + + public void testInterpolateObjectWithStringToStringMapField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + Map<String, String> values = new HashMap<String, String>(); + values.put( "key", "${key}" ); + values.put( "key2", "${key2}" ); + + ObjectWithMapField obj = new ObjectWithMapField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", obj.values.get( "key" ) ); + assertEquals( "value2", obj.values.get( "key2" ) ); + } + + public void testInterpolateObjectWithStringToStringMapFieldAndOneLiteralValue() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + Map<String, String> values = new HashMap<String, String>(); + values.put( "key", "val" ); + values.put( "key2", "${key2}" ); + + ObjectWithMapField obj = new ObjectWithMapField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "val", obj.values.get( "key" ) ); + assertEquals( "value2", obj.values.get( "key2" ) ); + } + + public void testInterpolateObjectWithUnmodifiableStringToStringMapField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + + Map<String, String> values = Collections.unmodifiableMap( Collections.singletonMap( "key", "${key}" ) ); + + ObjectWithMapField obj = new ObjectWithMapField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "${key}", obj.values.get( "key" ) ); + } + + public void testInterpolateObjectWithStringToStringArrayMapField() + throws Exception + { + Model model = new Model(); + + Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + p.setProperty( "key3", "value3" ); + p.setProperty( "key4", "value4" ); + + Map<String, String[]> values = new HashMap<String, String[]>(); + values.put( "key", new String[] { "${key}", "${key2}" } ); + values.put( "key2", new String[] { "${key3}", "${key4}" } ); + + ObjectWithMapField obj = new ObjectWithMapField( values ); + + StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + ModelBuildingRequest config = createModelBuildingRequest( p ); + + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + assertProblemFree( collector ); + + assertEquals( "value", ( (String[]) obj.values.get( "key" ) )[0] ); + assertEquals( "value2", ( (String[]) obj.values.get( "key" ) )[1] ); + assertEquals( "value3", ( (String[]) obj.values.get( "key2" ) )[0] ); + assertEquals( "value4", ( (String[]) obj.values.get( "key2" ) )[1] ); + } + + + public void testConcurrentInterpolation() + throws Exception + { + final Model model = new Model(); + + final Properties p = new Properties(); + p.setProperty( "key", "value" ); + p.setProperty( "key2", "value2" ); + p.setProperty( "key3", "value3" ); + p.setProperty( "key4", "value4" ); + p.setProperty( "key5", "value5" ); + + final StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator(); + + + int numItems = 100; + final CountDownLatch countDownLatch = new CountDownLatch(1); + + List<Future<SimpleProblemCollector>> futures = new ArrayList<Future<SimpleProblemCollector>>(); + for ( int i = 0; i < numItems; i++ ) + { + Callable<SimpleProblemCollector> future = new Callable<SimpleProblemCollector>() + { + public SimpleProblemCollector call() + throws Exception + { + final ObjectWithMixedProtection obj = getValueList(); + final ModelBuildingRequest config = createModelBuildingRequest( p ); + + countDownLatch.await(); + final SimpleProblemCollector collector = new SimpleProblemCollector(); + interpolator.interpolateObject( obj, model, new File( "." ), config, collector ); + return collector; + } + }; + FutureTask<SimpleProblemCollector> task = new FutureTask<SimpleProblemCollector>( future ); + futures.add( task ); + new Thread( task ).start(); + } + countDownLatch.countDown(); // Start all the threads + for ( Future<SimpleProblemCollector> result : futures ) + { + SimpleProblemCollector problemCollector = result.get(); // ArrayIndexOutOfBoundsException are typical indication of threading issues + assertProblemFree( problemCollector ); + } + } + + private ObjectWithMixedProtection getValueList() + { + List<String[]> values = new ArrayList<String[]>(); + + values.add( new String[] { "${key}", "${key2}" } ); + values.add( new String[] { "${key3}", "${key4}" } ); + List<String> values2 = new ArrayList<String>(); + values.add( new String[] { "${key}", "${key2}" } ); + values.add( new String[] { "${key3}", "${key4}" } ); + List<String> values3 = new ArrayList<String>(); + values.add( new String[] { "${key}", "${key2}" } ); + values.add( new String[] { "${key3}", "${key4}" } ); + + return new ObjectWithMixedProtection( values, values2, values3, "${key5}" ); + } + + + private static final class ObjectWithStringArrayField + { + private final String[] values; + + public ObjectWithStringArrayField( String[] values ) + { + this.values = values; + } + } + + private static final class ObjectWithListField + { + private final List<?> values; + + public ObjectWithListField( List<?> values ) + { + this.values = values; + } + } + + private static final class ObjectWithMapField + { + private final Map<?, ?> values; + + public ObjectWithMapField( Map<?, ?> values ) + { + this.values = values; + } + } + + @SuppressWarnings( "unused" ) + private static final class ObjectWithMixedProtection + { + private List<?> values1; + protected List<?> values2; + List<?> values3; + private String fooBar; + + private ObjectWithMixedProtection( List<?> values1, List<?> values2, List<?> values3 ) + { + this.values1 = values1; + this.values2 = values2; + this.values3 = values3; + } + + private ObjectWithMixedProtection( List<?> values1, List<?> values2, List<?> values3, String fooBar ) + { + this.values1 = values1; + this.values2 = values2; + this.values3 = values3; + this.fooBar = fooBar; + } + + public String getFooBar() + { + return fooBar; + } + } + + public void testFinalFieldsExcludedFromInterpolation() + { + Properties props = new Properties(); + props.setProperty( "expression", "value" ); + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setUserProperties( props ); + + SimpleProblemCollector problems = new SimpleProblemCollector(); + StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator(); + interpolator.interpolateObject( new ClassWithFinalField(), new Model(), null, request, problems ); + + assertProblemFree( problems ); + } + + static class ClassWithFinalField + { + public static final String CONSTANT = "${expression}"; + } + + public void testLocationTrackerShouldBeExcludedFromInterpolation() + { + Properties props = new Properties(); + props.setProperty( "expression", "value" ); + DefaultModelBuildingRequest request = new DefaultModelBuildingRequest(); + request.setUserProperties( props ); + + InputSource source = new InputSource(); + source.setLocation( "${expression}" ); + source.setModelId( "${expression}" ); + Model model = new Model(); + model.setLocation( "", new InputLocation( 1, 1, source ) ); + + SimpleProblemCollector problems = new SimpleProblemCollector(); + StringSearchModelInterpolator interpolator = new StringSearchModelInterpolator(); + interpolator.interpolateObject( model, model, null, request, problems ); + + assertProblemFree( problems ); + assertEquals( "${expression}", source.getLocation() ); + assertEquals( "${expression}", source.getModelId() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java new file mode 100644 index 00000000..88fdc9cf --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java @@ -0,0 +1,85 @@ +package org.apache.maven.model.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 junit.framework.TestCase; + +/** + * @author Benjamin Bentmann + */ +public class DefaultUrlNormalizerTest + extends TestCase +{ + + private UrlNormalizer normalizer; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + normalizer = new DefaultUrlNormalizer(); + } + + @Override + protected void tearDown() + throws Exception + { + normalizer = null; + + super.tearDown(); + } + + private String normalize( String url ) + { + return normalizer.normalize( url ); + } + + public void testNullSafe() + { + assertNull( normalize( null ) ); + } + + public void testTrailingSlash() + { + assertEquals( "", normalize( "" ) ); + assertEquals( "http://server.org/dir", normalize( "http://server.org/dir" ) ); + assertEquals( "http://server.org/dir/", normalize( "http://server.org/dir/" ) ); + } + + public void testRemovalOfParentRefs() + { + assertEquals( "http://server.org/child", normalize( "http://server.org/parent/../child" ) ); + assertEquals( "http://server.org/child", normalize( "http://server.org/grand/parent/../../child" ) ); + + assertEquals( "http://server.org//child", normalize( "http://server.org/parent/..//child" ) ); + assertEquals( "http://server.org/child", normalize( "http://server.org/parent//../child" ) ); + } + + public void testPreservationOfDoubleSlashes() + { + assertEquals( "scm:hg:ssh://localhost//home/user", normalize( "scm:hg:ssh://localhost//home/user" ) ); + assertEquals( "file:////UNC/server", normalize( "file:////UNC/server" ) ); + assertEquals( "[fetch=]http://server.org/[push=]ssh://server.org/", + normalize( "[fetch=]http://server.org/[push=]ssh://server.org/" ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java new file mode 100644 index 00000000..0ec3b326 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -0,0 +1,92 @@ +package org.apache.maven.model.profile.activation; + +/* + * 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.Properties; + +import org.apache.maven.model.Profile; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.profile.DefaultProfileActivationContext; +import org.apache.maven.model.profile.ProfileActivationContext; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Provides common services to test {@link ProfileActivator} implementations. + * + * @author Benjamin Bentmann + */ +public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> + extends PlexusTestCase +{ + + private Class<T> activatorClass; + + private String roleHint; + + protected T activator; + + public AbstractProfileActivatorTest( Class<T> activatorClass ) + { + if ( activatorClass == null ) + { + throw new IllegalArgumentException( "class of profile activator to test is not specified" ); + } + + this.activatorClass = activatorClass; + + roleHint = activatorClass.getAnnotation( Component.class ).hint(); + } + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + activator = activatorClass.cast( lookup( ProfileActivator.class, roleHint ) ); + } + + @Override + protected void tearDown() + throws Exception + { + activator = null; + + super.tearDown(); + } + + protected ProfileActivationContext newContext( final Properties userProperties, final Properties systemProperties ) + { + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); + return context.setUserProperties( userProperties ).setSystemProperties( systemProperties ); + } + + protected void assertActivation( boolean active, Profile profile, ProfileActivationContext context ) + { + SimpleProblemCollector problems = new SimpleProblemCollector(); + + assertEquals( active, activator.isActive( profile, context, problems ) ); + + assertEquals( problems.getErrors().toString(), 0, problems.getErrors().size() ); + assertEquals( problems.getWarnings().toString(), 0, problems.getWarnings().size() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java new file mode 100644 index 00000000..440f120b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -0,0 +1,185 @@ +package org.apache.maven.model.profile.activation; + +/* + * 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.Properties; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.Profile; + +/** + * Tests {@link JdkVersionProfileActivator}. + * + * @author Benjamin Bentmann + */ +public class JdkVersionProfileActivatorTest + extends AbstractProfileActivatorTest<JdkVersionProfileActivator> +{ + + public JdkVersionProfileActivatorTest() + { + super( JdkVersionProfileActivator.class ); + } + + private Profile newProfile( String jdkVersion ) + { + Activation a = new Activation(); + a.setJdk( jdkVersion ); + + Profile p = new Profile(); + p.setActivation( a ); + + return p; + } + + private Properties newProperties( String javaVersion ) + { + Properties props = new Properties(); + props.setProperty( "java.version", javaVersion ); + return props; + } + + public void testNullSafe() + throws Exception + { + Profile p = new Profile(); + + assertActivation( false, p, newContext( null, null ) ); + + p.setActivation( new Activation() ); + + assertActivation( false, p, newContext( null, null ) ); + } + + public void testPrefix() + throws Exception + { + Profile profile = newProfile( "1.4" ); + + assertActivation( true, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.5" ) ) ); + } + + public void testPrefixNegated() + throws Exception + { + Profile profile = newProfile( "!1.4" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.3" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + } + + public void testVersionRangeInclusiveBounds() + throws Exception + { + Profile profile = newProfile( "[1.5,1.6]" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + + public void testVersionRangeExclusiveBounds() + throws Exception + { + Profile profile = newProfile( "(1.3,1.6)" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.3.1" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) ); + } + + public void testVersionRangeInclusiveLowerBound() + throws Exception + { + Profile profile = newProfile( "[1.5,)" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + + public void testVersionRangeExclusiveUpperBound() + throws Exception + { + Profile profile = newProfile( "(,1.6)" ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java new file mode 100644 index 00000000..73ab967e --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java @@ -0,0 +1,185 @@ +package org.apache.maven.model.profile.activation; + +/* + * 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.Properties; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Profile; + +/** + * Tests {@link PropertyProfileActivator}. + * + * @author Benjamin Bentmann + */ +public class PropertyProfileActivatorTest + extends AbstractProfileActivatorTest<PropertyProfileActivator> +{ + + public PropertyProfileActivatorTest() + { + super( PropertyProfileActivator.class ); + } + + private Profile newProfile( String key, String value ) + { + ActivationProperty ap = new ActivationProperty(); + ap.setName( key ); + ap.setValue( value ); + + Activation a = new Activation(); + a.setProperty( ap ); + + Profile p = new Profile(); + p.setActivation( a ); + + return p; + } + + private Properties newProperties( String key, String value ) + { + Properties props = new Properties(); + props.setProperty( key, value ); + return props; + } + + public void testNullSafe() + throws Exception + { + Profile p = new Profile(); + + assertActivation( false, p, newContext( null, null ) ); + + p.setActivation( new Activation() ); + + assertActivation( false, p, newContext( null, null ) ); + } + + public void testWithNameOnly_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", null ); + + assertActivation( true, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "other", "value" ), null ) ); + } + + public void testWithNameOnly_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", null ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "other", "value" ) ) ); + } + + public void testWithNegatedNameOnly_UserProperty() + throws Exception + { + Profile profile = newProfile( "!prop", null ); + + assertActivation( false, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "other", "value" ), null ) ); + } + + public void testWithNegatedNameOnly_SystemProperty() + throws Exception + { + Profile profile = newProfile( "!prop", null ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "other", "value" ) ) ); + } + + public void testWithValue_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + assertActivation( true, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "other" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "" ), null ) ); + } + + public void testWithValue_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "other" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "other", "" ) ) ); + } + + public void testWithNegatedValue_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", "!value" ); + + assertActivation( false, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "other" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "" ), null ) ); + } + + public void testWithNegatedValue_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "!value" ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "other" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "other", "" ) ) ); + } + + public void testWithValue_UserPropertyDominantOverSystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + Properties props1 = newProperties( "prop", "value" ); + Properties props2 = newProperties( "prop", "other" ); + + assertActivation( true, profile, newContext( props1, props2 ) ); + + assertActivation( false, profile, newContext( props2, props1 ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java new file mode 100644 index 00000000..dde532d8 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java @@ -0,0 +1,630 @@ +package org.apache.maven.model.validation; + +/* + * 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.InputStream; +import java.util.List; + +import org.apache.maven.model.Model; +import org.apache.maven.model.building.DefaultModelBuildingRequest; +import org.apache.maven.model.building.ModelBuildingRequest; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.PlexusTestCase; + +/** + * @author <a href="mailto:trygvis@inamo.no">Trygve Laugstøl</a> + */ +public class DefaultModelValidatorTest + extends PlexusTestCase +{ + + private ModelValidator validator; + + private Model read( String pom ) + throws Exception + { + String resource = "/poms/validation/" + pom; + InputStream is = getClass().getResourceAsStream( resource ); + assertNotNull( "missing resource: " + resource, is ); + return new MavenXpp3Reader().read( is ); + } + + private SimpleProblemCollector validate( String pom ) + throws Exception + { + return validateEffective( pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + } + + private SimpleProblemCollector validateRaw( String pom ) + throws Exception + { + return validateRaw( pom, ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + } + + private SimpleProblemCollector validateEffective( String pom, int level ) + throws Exception + { + ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level ); + + SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) ); + + validator.validateEffectiveModel( problems.getModel(), request, problems ); + + return problems; + } + + private SimpleProblemCollector validateRaw( String pom, int level ) + throws Exception + { + ModelBuildingRequest request = new DefaultModelBuildingRequest().setValidationLevel( level ); + + SimpleProblemCollector problems = new SimpleProblemCollector( read( pom ) ); + + validator.validateRawModel( problems.getModel(), request, problems ); + + return problems; + } + + private void assertContains( String msg, String substring ) + { + assertTrue( "\"" + substring + "\" was not found in: " + msg, msg.contains( substring ) ); + } + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + validator = lookup( ModelValidator.class ); + } + + @Override + protected void tearDown() + throws Exception + { + this.validator = null; + + super.tearDown(); + } + + private void assertViolations( SimpleProblemCollector result, int fatals, int errors, int warnings ) + { + assertEquals( String.valueOf( result.getFatals() ), fatals, result.getFatals().size() ); + assertEquals( String.valueOf( result.getErrors() ), errors, result.getErrors().size() ); + assertEquals( String.valueOf( result.getWarnings() ), warnings, result.getWarnings().size() ); + } + + public void testMissingModelVersion() + throws Exception + { + SimpleProblemCollector result = validate( "missing-modelVersion-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'modelVersion' is missing.", result.getErrors().get( 0 ) ); + } + + public void testBadModelVersion() + throws Exception + { + SimpleProblemCollector result = + validateRaw( "bad-modelVersion.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "modelVersion" ) ); + } + + public void testMissingArtifactId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-artifactId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'artifactId' is missing.", result.getErrors().get( 0 ) ); + } + + public void testMissingGroupId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-groupId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'groupId' is missing.", result.getErrors().get( 0 ) ); + } + + public void testInvalidIds() + throws Exception + { + SimpleProblemCollector result = validate( "invalid-ids-pom.xml" ); + + assertViolations( result, 0, 2, 0 ); + + assertEquals( "'groupId' with value 'o/a/m' does not match a valid id pattern.", result.getErrors().get( 0 ) ); + + assertEquals( "'artifactId' with value 'm$-do$' does not match a valid id pattern.", result.getErrors().get( 1 ) ); + } + + public void testMissingType() + throws Exception + { + SimpleProblemCollector result = validate( "missing-type-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'packaging' is missing.", result.getErrors().get( 0 ) ); + } + + public void testMissingVersion() + throws Exception + { + SimpleProblemCollector result = validate( "missing-version-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'version' is missing.", result.getErrors().get( 0 ) ); + } + + public void testInvalidAggregatorPackaging() + throws Exception + { + SimpleProblemCollector result = validate( "invalid-aggregator-packaging-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "Aggregator projects require 'pom' as packaging." ) ); + } + + public void testMissingDependencyArtifactId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-artifactId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); + } + + public void testMissingDependencyGroupId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-groupId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); + } + + public void testMissingDependencyVersion() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-version-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencies.dependency.version' for groupId:artifactId:jar is missing" ) ); + } + + public void testMissingDependencyManagementArtifactId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-mgmt-artifactId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencyManagement.dependencies.dependency.artifactId' for groupId:null:jar is missing" ) ); + } + + public void testMissingDependencyManagementGroupId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-mgmt-groupId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( + "'dependencyManagement.dependencies.dependency.groupId' for null:artifactId:jar is missing" ) ); + } + + public void testMissingAll() + throws Exception + { + SimpleProblemCollector result = validate( "missing-1-pom.xml" ); + + assertViolations( result, 0, 4, 0 ); + + List<String> messages = result.getErrors(); + + assertTrue( messages.contains( "\'modelVersion\' is missing." ) ); + assertTrue( messages.contains( "\'groupId\' is missing." ) ); + assertTrue( messages.contains( "\'artifactId\' is missing." ) ); + assertTrue( messages.contains( "\'version\' is missing." ) ); + // type is inherited from the super pom + } + + public void testMissingPluginArtifactId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-plugin-artifactId-pom.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'build.plugins.plugin.artifactId' is missing.", result.getErrors().get( 0 ) ); + } + + public void testEmptyPluginVersion() + throws Exception + { + SimpleProblemCollector result = validate( "empty-plugin-version.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertEquals( "'build.plugins.plugin.version' for org.apache.maven.plugins:maven-it-plugin" + + " must be a valid version but is ''.", result.getErrors().get( 0 ) ); + } + + public void testMissingRepositoryId() + throws Exception + { + SimpleProblemCollector result = + validateRaw( "missing-repository-id-pom.xml", ModelBuildingRequest.VALIDATION_LEVEL_STRICT ); + + assertViolations( result, 0, 4, 0 ); + + assertEquals( "'repositories.repository.id' is missing.", result.getErrors().get( 0 ) ); + + assertEquals( "'repositories.repository[null].url' is missing.", result.getErrors().get( 1 ) ); + + assertEquals( "'pluginRepositories.pluginRepository.id' is missing.", result.getErrors().get( 2 ) ); + + assertEquals( "'pluginRepositories.pluginRepository[null].url' is missing.", result.getErrors().get( 3 ) ); + } + + public void testMissingResourceDirectory() + throws Exception + { + SimpleProblemCollector result = validate( "missing-resource-directory-pom.xml" ); + + assertViolations( result, 0, 2, 0 ); + + assertEquals( "'build.resources.resource.directory' is missing.", result.getErrors().get( 0 ) ); + + assertEquals( "'build.testResources.testResource.directory' is missing.", result.getErrors().get( 1 ) ); + } + + public void testBadPluginDependencyScope() + throws Exception + { + SimpleProblemCollector result = validate( "bad-plugin-dependency-scope.xml" ); + + assertViolations( result, 0, 3, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:d" ) ); + + assertTrue( result.getErrors().get( 1 ).contains( "test:e" ) ); + + assertTrue( result.getErrors().get( 2 ).contains( "test:f" ) ); + } + + public void testBadDependencyScope() + throws Exception + { + SimpleProblemCollector result = validate( "bad-dependency-scope.xml" ); + + assertViolations( result, 0, 0, 2 ); + + assertTrue( result.getWarnings().get( 0 ).contains( "test:f" ) ); + + assertTrue( result.getWarnings().get( 1 ).contains( "test:g" ) ); + } + + public void testBadDependencyVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-dependency-version.xml" ); + + assertViolations( result, 0, 2, 0 ); + + assertContains( result.getErrors().get( 0 ), + "'dependencies.dependency.version' for test:b:jar must be a valid version" ); + assertContains( result.getErrors().get( 1 ), + "'dependencies.dependency.version' for test:c:jar must not contain any of these characters" ); + } + + public void testDuplicateModule() + throws Exception + { + SimpleProblemCollector result = validate( "duplicate-module.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "child" ) ); + } + + public void testDuplicateProfileId() + throws Exception + { + SimpleProblemCollector result = validateRaw( "duplicate-profile-id.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "non-unique-id" ) ); + } + + public void testBadPluginVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-plugin-version.xml" ); + + assertViolations( result, 0, 4, 0 ); + + assertContains( result.getErrors().get( 0 ), + "'build.plugins.plugin.version' for test:mip must be a valid version" ); + assertContains( result.getErrors().get( 1 ), + "'build.plugins.plugin.version' for test:rmv must be a valid version" ); + assertContains( result.getErrors().get( 2 ), + "'build.plugins.plugin.version' for test:lmv must be a valid version" ); + assertContains( result.getErrors().get( 3 ), + "'build.plugins.plugin.version' for test:ifsc must not contain any of these characters" ); + } + + public void testDistributionManagementStatus() + throws Exception + { + SimpleProblemCollector result = validate( "distribution-management-status.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "distributionManagement.status" ) ); + } + + public void testIncompleteParent() + throws Exception + { + SimpleProblemCollector result = validateRaw( "incomplete-parent.xml" ); + + assertViolations( result, 3, 0, 0 ); + + assertTrue( result.getFatals().get( 0 ).contains( "parent.groupId" ) ); + assertTrue( result.getFatals().get( 1 ).contains( "parent.artifactId" ) ); + assertTrue( result.getFatals().get( 2 ).contains( "parent.version" ) ); + } + + public void testHardCodedSystemPath() + throws Exception + { + SimpleProblemCollector result = validateRaw( "hard-coded-system-path.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertTrue( result.getWarnings().get( 0 ).contains( "test:a:jar" ) ); + } + + public void testEmptyModule() + throws Exception + { + SimpleProblemCollector result = validate( "empty-module.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "'modules.module[0]' has been specified without a path" ) ); + } + + public void testDuplicatePlugin() + throws Exception + { + SimpleProblemCollector result = validateRaw( "duplicate-plugin.xml" ); + + assertViolations( result, 0, 0, 4 ); + + assertTrue( result.getWarnings().get( 0 ).contains( "duplicate declaration of plugin test:duplicate" ) ); + assertTrue( result.getWarnings().get( 1 ).contains( "duplicate declaration of plugin test:managed-duplicate" ) ); + assertTrue( result.getWarnings().get( 2 ).contains( "duplicate declaration of plugin profile:duplicate" ) ); + assertTrue( result.getWarnings().get( 3 ).contains( "duplicate declaration of plugin profile:managed-duplicate" ) ); + } + + public void testDuplicatePluginExecution() + throws Exception + { + SimpleProblemCollector result = validateRaw( "duplicate-plugin-execution.xml" ); + + assertViolations( result, 0, 4, 0 ); + + assertContains( result.getErrors().get( 0 ), "duplicate execution with id a" ); + assertContains( result.getErrors().get( 1 ), "duplicate execution with id default" ); + assertContains( result.getErrors().get( 2 ), "duplicate execution with id c" ); + assertContains( result.getErrors().get( 3 ), "duplicate execution with id b" ); + } + + public void testReservedRepositoryId() + throws Exception + { + SimpleProblemCollector result = validate( "reserved-repository-id.xml" ); + + assertViolations( result, 0, 0, 4 ); + + assertContains( result.getWarnings().get( 0 ), "'repositories.repository.id'" + " must not be 'local'" ); + assertContains( result.getWarnings().get( 1 ), "'pluginRepositories.pluginRepository.id' must not be 'local'" ); + assertContains( result.getWarnings().get( 2 ), "'distributionManagement.repository.id' must not be 'local'" ); + assertContains( result.getWarnings().get( 3 ), + "'distributionManagement.snapshotRepository.id' must not be 'local'" ); + } + + public void testMissingPluginDependencyGroupId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-plugin-dependency-groupId.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( ":a:" ) ); + } + + public void testMissingPluginDependencyArtifactId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-plugin-dependency-artifactId.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:" ) ); + } + + public void testMissingPluginDependencyVersion() + throws Exception + { + SimpleProblemCollector result = validate( "missing-plugin-dependency-version.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:a" ) ); + } + + public void testBadPluginDependencyVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-plugin-dependency-version.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertTrue( result.getErrors().get( 0 ).contains( "test:b" ) ); + } + + public void testBadVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-version.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertContains( result.getWarnings().get( 0 ), "'version' must not contain any of these characters" ); + } + + public void testBadSnapshotVersion() + throws Exception + { + SimpleProblemCollector result = validate( "bad-snapshot-version.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertContains( result.getWarnings().get( 0 ), "'version' uses an unsupported snapshot version format" ); + } + + public void testBadRepositoryId() + throws Exception + { + SimpleProblemCollector result = validate( "bad-repository-id.xml" ); + + assertViolations( result, 0, 0, 4 ); + + assertContains( result.getWarnings().get( 0 ), + "'repositories.repository.id' must not contain any of these characters" ); + assertContains( result.getWarnings().get( 1 ), + "'pluginRepositories.pluginRepository.id' must not contain any of these characters" ); + assertContains( result.getWarnings().get( 2 ), + "'distributionManagement.repository.id' must not contain any of these characters" ); + assertContains( result.getWarnings().get( 3 ), + "'distributionManagement.snapshotRepository.id' must not contain any of these characters" ); + } + + public void testBadDependencyExclusionId() + throws Exception + { + SimpleProblemCollector result = validateEffective( "bad-dependency-exclusion-id.xml", ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0 ); + + assertViolations( result, 0, 0, 2 ); + + assertContains( result.getWarnings().get( 0 ), + "'dependencies.dependency.exclusions.exclusion.groupId' for gid:aid:jar" ); + assertContains( result.getWarnings().get( 1 ), + "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar" ); + + // MNG-3832: Aether (part of M3+) supports wildcard expressions for exclusions + + SimpleProblemCollector result_30 = validate( "bad-dependency-exclusion-id.xml" ); + + assertViolations( result_30, 0, 0, 0 ); + + } + + public void testMissingDependencyExclusionId() + throws Exception + { + SimpleProblemCollector result = validate( "missing-dependency-exclusion-id.xml" ); + + assertViolations( result, 0, 0, 2 ); + + assertContains( result.getWarnings().get( 0 ), + "'dependencies.dependency.exclusions.exclusion.groupId' for gid:aid:jar is missing" ); + assertContains( result.getWarnings().get( 1 ), + "'dependencies.dependency.exclusions.exclusion.artifactId' for gid:aid:jar is missing" ); + } + + public void testBadImportScopeType() + throws Exception + { + SimpleProblemCollector result = validateRaw( "bad-import-scope-type.xml" ); + + assertViolations( result, 0, 0, 1 ); + + assertContains( result.getWarnings().get( 0 ), + "'dependencyManagement.dependencies.dependency.type' for test:a:jar must be 'pom'" ); + } + + public void testBadImportScopeClassifier() + throws Exception + { + SimpleProblemCollector result = validateRaw( "bad-import-scope-classifier.xml" ); + + assertViolations( result, 0, 1, 0 ); + + assertContains( result.getErrors().get( 0 ), + "'dependencyManagement.dependencies.dependency.classifier' for test:a:pom:cls must be empty" ); + } + + public void testSystemPathRefersToProjectBasedir() + throws Exception + { + SimpleProblemCollector result = validateRaw( "basedir-system-path.xml" ); + + assertViolations( result, 0, 0, 2 ); + + assertContains( result.getWarnings().get( 0 ), "'dependencies.dependency.systemPath' for test:a:jar " + + "should not point at files within the project directory" ); + assertContains( result.getWarnings().get( 1 ), "'dependencies.dependency.systemPath' for test:b:jar " + + "should not point at files within the project directory" ); + } + + public void testMissingReportPluginVersion() + throws Exception + { + SimpleProblemCollector result = validate( "missing-report-version-pom.xml" ); + + assertViolations( result, 0, 0, 0 ); + } +} |