aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin')
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java342
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java164
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java447
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java74
4 files changed, 1027 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java
new file mode 100644
index 00000000..025e7725
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginManagerTest.java
@@ -0,0 +1,342 @@
+package org.apache.maven.plugin;
+
+/*
+ * 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.List;
+
+import org.apache.maven.AbstractCoreMavenComponentTestCase;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.DefaultRepositoryRequest;
+import org.apache.maven.artifact.repository.RepositoryRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.classworlds.realm.ClassRealm;
+import org.codehaus.plexus.component.annotations.Requirement;
+import org.codehaus.plexus.component.repository.ComponentDescriptor;
+
+public class PluginManagerTest
+ extends AbstractCoreMavenComponentTestCase
+{
+ @Requirement
+ private DefaultBuildPluginManager pluginManager;
+
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+ pluginManager = (DefaultBuildPluginManager) lookup( BuildPluginManager.class );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ pluginManager = null;
+ super.tearDown();
+ }
+
+ protected String getProjectsDirectory()
+ {
+ return "src/test/projects/plugin-manager";
+ }
+
+ public void testPluginLoading()
+ throws Exception
+ {
+ MavenSession session = createMavenSession( null );
+ Plugin plugin = new Plugin();
+ plugin.setGroupId( "org.apache.maven.its.plugins" );
+ plugin.setArtifactId( "maven-it-plugin" );
+ plugin.setVersion( "0.1" );
+ PluginDescriptor pluginDescriptor =
+ pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ assertNotNull( pluginDescriptor );
+ }
+
+ public void testMojoDescriptorRetrieval()
+ throws Exception
+ {
+ MavenSession session = createMavenSession( null );
+ String goal = "it";
+ Plugin plugin = new Plugin();
+ plugin.setGroupId( "org.apache.maven.its.plugins" );
+ plugin.setArtifactId( "maven-it-plugin" );
+ plugin.setVersion( "0.1" );
+
+ MojoDescriptor mojoDescriptor =
+ pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ assertNotNull( mojoDescriptor );
+ assertEquals( goal, mojoDescriptor.getGoal() );
+ // igorf: plugin realm comes later
+ // assertNotNull( mojoDescriptor.getRealm() );
+
+ PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor();
+ assertNotNull( pluginDescriptor );
+ assertEquals( "org.apache.maven.its.plugins", pluginDescriptor.getGroupId() );
+ assertEquals( "maven-it-plugin", pluginDescriptor.getArtifactId() );
+ assertEquals( "0.1", pluginDescriptor.getVersion() );
+ }
+
+ // -----------------------------------------------------------------------------------------------
+ // Tests which exercise the lifecycle executor when it is dealing with individual goals.
+ // -----------------------------------------------------------------------------------------------
+
+ //TODO: These two tests display a lack of symmetry with respect to the input which is a free form string and the
+ // mojo descriptor which comes back. All the free form parsing needs to be done somewhere else, this is
+ // really the function of the CLI, and then the pre-processing of that output still needs to be fed into
+ // a hinting process which helps flesh out the full specification of the plugin. The plugin manager should
+ // only deal in concrete terms -- all version finding mumbo jumbo is a customization to base functionality
+ // the plugin manager provides.
+
+ public void testRemoteResourcesPlugin()
+ throws Exception
+ {
+ //TODO: turn an equivalent back on when the RR plugin is released.
+
+ /*
+
+ This will not work until the RR plugin is released to get rid of the binding to the reporting exception which is a mistake.
+
+ This happpens after removing the reporting API from the core:
+
+ java.lang.NoClassDefFoundError: org/apache/maven/reporting/MavenReportException
+
+ MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
+ String goal = "process";
+
+ Plugin plugin = new Plugin();
+ plugin.setGroupId( "org.apache.maven.plugins" );
+ plugin.setArtifactId( "maven-remote-resources-plugin" );
+ plugin.setVersion( "1.0-beta-2" );
+
+ MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getCurrentProject(), session.getLocalRepository() );
+ assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-remote-resources-plugin", "1.0-beta-2" );
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
+ pluginManager.executeMojo( session, mojoExecution );
+ */
+ }
+
+ //TODO: this will be the basis of the customizable lifecycle execution so need to figure this out quickly.
+ public void testSurefirePlugin()
+ throws Exception
+ {
+ /*
+ MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
+ String goal = "test";
+
+ Plugin plugin = new Plugin();
+ plugin.setGroupId( "org.apache.maven.plugins" );
+ plugin.setArtifactId( "maven-surefire-plugin" );
+ plugin.setVersion( "2.4.2" );
+
+ // The project has already been fully interpolated so getting the raw mojoDescriptor is not going to have the processes configuration.
+ MojoDescriptor mojoDescriptor = pluginManager.getMojoDescriptor( plugin, goal, session.getLocalRepository(), session.getCurrentProject().getPluginArtifactRepositories() );
+ assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" );
+
+ System.out.println( session.getCurrentProject().getBuild().getPluginsAsMap() );
+
+ Xpp3Dom configuration = (Xpp3Dom) session.getCurrentProject().getBuild().getPluginsAsMap().get( plugin.getKey() ).getExecutions().get( 0 ).getConfiguration();
+ MojoExecution mojoExecution = new MojoExecution( mojoDescriptor, configuration );
+ pluginManager.executeMojo( session, mojoExecution );
+ */
+ }
+
+ public void testMojoConfigurationIsMergedCorrectly()
+ throws Exception
+ {
+ }
+
+ /**
+ * The case where the user wants to specify an alternate version of the underlying tool. Common case
+ * is in the Antlr plugin which comes bundled with a version of Antlr but the user often times needs
+ * to use a specific version. We need to make sure the version that they specify takes precedence.
+ */
+ public void testMojoWhereInternallyStatedDependencyIsOverriddenByProject()
+ throws Exception
+ {
+ }
+
+ /**
+ * The case where you have a plugin in the current build that you want to be used on projects in
+ * the current build.
+ */
+ public void testMojoThatIsPresentInTheCurrentBuild()
+ throws Exception
+ {
+ }
+
+ /**
+ * This is the case where the Mojo wants to execute on every project and then do something at the end
+ * with the results of each project.
+ */
+ public void testAggregatorMojo()
+ throws Exception
+ {
+ }
+
+ /**
+ * This is the case where a Mojo needs the lifecycle run to a certain phase before it can do
+ * anything useful.
+ */
+ public void testMojoThatRequiresExecutionToAGivenPhaseBeforeExecutingItself()
+ throws Exception
+ {
+ }
+
+ // test that mojo which does not require dependency resolution trigger no downloading of dependencies
+
+ // test interpolation of basedir values in mojo configuration
+
+ // test a build where projects use different versions of the same plugin
+
+ public void testThatPluginDependencyThatHasSystemScopeIsResolved()
+ throws Exception
+ {
+ /*
+ File systemPath = new File( getBasedir(), "pom.xml" );
+
+ Plugin plugin = new PluginBuilder( "org.apache.maven", "project-test", "1.0" )
+ .addDependency( "org.apache.maven", "system-dependency", "1.0", Artifact.SCOPE_SYSTEM, systemPath.getAbsolutePath() )
+ .get();
+
+ MavenProject pluginProject = new ProjectBuilder( "org.apache.maven", "project-test", "1.0" )
+ .addPlugin( plugin )
+ .addDependency( "junit", "junit", "3.8.1", Artifact.SCOPE_COMPILE )
+ .get();
+
+ // i'm making this artifact which is assumed to come from a pom in the metadata processor, then it tries to create a POM artifact
+ // and parse it for the dependencies and it blows up.
+ //
+ // we need to pass this through as is so it doesn't get parsed again.
+ Artifact pluginArtifact = new ProjectArtifact( pluginProject );
+
+ Set<Artifact> artifacts = pluginManager.getPluginArtifacts( pluginArtifact, plugin, getLocalRepository(), getPluginArtifactRepositories() );
+ System.out.println( artifacts );
+ */
+
+ MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
+ MavenProject project = session.getCurrentProject();
+ Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
+
+ RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
+ repositoryRequest.setLocalRepository( getLocalRepository() );
+ repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
+
+ PluginDescriptor pluginDescriptor =
+ pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ pluginManager.getPluginRealm( session, pluginDescriptor );
+ List<Artifact> artifacts = pluginDescriptor.getArtifacts();
+
+ for ( Artifact a : artifacts )
+ {
+ if ( a.getGroupId().equals( "org.apache.maven.its.mng3586" ) && a.getArtifactId().equals( "tools" ) )
+ {
+ // The system scoped dependencies will be present in the classloader for the plugin
+ return;
+ }
+ }
+
+ fail( "Can't find the system scoped dependency in the plugin artifacts." );
+ }
+
+ // -----------------------------------------------------------------------------------------------
+ // Testing help
+ // -----------------------------------------------------------------------------------------------
+
+ protected void assertPluginDescriptor( MojoDescriptor mojoDescriptor, String groupId, String artifactId, String version )
+ {
+ assertNotNull( mojoDescriptor );
+ PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
+ assertNotNull( pd );
+ assertEquals( groupId, pd.getGroupId() );
+ assertEquals( artifactId, pd.getArtifactId() );
+ assertEquals( version, pd.getVersion() );
+ }
+
+ public void testPluginRealmCache()
+ throws Exception
+ {
+ RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
+ repositoryRequest.setLocalRepository( getLocalRepository() );
+ repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
+
+ // prime realm cache
+ MavenSession session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
+ MavenProject project = session.getCurrentProject();
+ Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
+
+ PluginDescriptor pluginDescriptor =
+ pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ pluginManager.getPluginRealm( session, pluginDescriptor );
+
+ assertEquals( 1, pluginDescriptor.getDependencies().size() );
+
+ for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
+ {
+ assertNotNull( descriptor.getRealm() );
+ assertNotNull( descriptor.getImplementationClass() );
+ }
+
+ // reload plugin realm from cache
+ session = createMavenSession( getProject( "project-contributing-system-scope-plugin-dep" ) );
+ project = session.getCurrentProject();
+ plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
+
+ pluginDescriptor =
+ pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ pluginManager.getPluginRealm( session, pluginDescriptor );
+
+ assertEquals( 1, pluginDescriptor.getDependencies().size() );
+
+ for ( ComponentDescriptor<?> descriptor : pluginDescriptor.getComponents() )
+ {
+ assertNotNull( descriptor.getRealm() );
+ assertNotNull( descriptor.getImplementationClass() );
+ }
+ }
+
+ public void testBuildExtensionsPluginLoading()
+ throws Exception
+ {
+ RepositoryRequest repositoryRequest = new DefaultRepositoryRequest();
+ repositoryRequest.setLocalRepository( getLocalRepository() );
+ repositoryRequest.setRemoteRepositories( getPluginArtifactRepositories() );
+
+ // prime realm cache
+ MavenSession session = createMavenSession( getProject( "project-with-build-extensions-plugin" ) );
+ MavenProject project = session.getCurrentProject();
+ Plugin plugin = project.getPlugin( "org.apache.maven.its.plugins:maven-it-plugin" );
+
+ PluginDescriptor pluginDescriptor =
+ pluginManager.loadPlugin( plugin, session.getCurrentProject().getRemotePluginRepositories(),
+ session.getRepositorySession() );
+ ClassRealm pluginRealm = pluginManager.getPluginRealm( session, pluginDescriptor );
+
+ assertEquals(pluginRealm, pluginDescriptor.getComponents().get(0).getRealm());
+ }
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java
new file mode 100644
index 00000000..ead7ae2e
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExceptionTest.java
@@ -0,0 +1,164 @@
+package org.apache.maven.plugin;
+
+/*
+ * 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 org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.Parameter;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+
+import junit.framework.TestCase;
+
+/**
+ * MNG-3131
+ *
+ * @author Robert Scholte
+ *
+ */
+public class PluginParameterExceptionTest
+ extends TestCase
+{
+
+ public void testMissingRequiredStringArrayTypeParameter()
+ {
+ MojoDescriptor mojoDescriptor = new MojoDescriptor();
+ mojoDescriptor.setGoal( "goal" );
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setGoalPrefix( "goalPrefix" );
+ pluginDescriptor.setArtifactId( "artifactId" );
+ mojoDescriptor.setPluginDescriptor( pluginDescriptor );
+
+ Parameter parameter = new Parameter();
+ parameter.setType( "java.lang.String[]" );
+ parameter.setName( "toAddresses" );
+
+ parameter.setRequired( true );
+
+ PluginParameterException exception =
+ new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
+
+ assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
+ "\n" +
+ "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
+ "\n" +
+ "<configuration>\n" +
+ " ...\n" +
+ " <toAddresses>\n" +
+ " <item>VALUE</item>\n" +
+ " </toAddresses>\n" +
+ "</configuration>.\n", exception.buildDiagnosticMessage() );
+ }
+
+ public void testMissingRequiredCollectionTypeParameter()
+ {
+ MojoDescriptor mojoDescriptor = new MojoDescriptor();
+ mojoDescriptor.setGoal( "goal" );
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setGoalPrefix( "goalPrefix" );
+ pluginDescriptor.setArtifactId( "artifactId" );
+ mojoDescriptor.setPluginDescriptor( pluginDescriptor );
+
+ Parameter parameter = new Parameter();
+ parameter.setType( "java.util.List" );
+ parameter.setName( "toAddresses" );
+
+ parameter.setRequired( true );
+
+ PluginParameterException exception =
+ new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
+
+ assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
+ "\n" +
+ "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
+ "\n" +
+ "<configuration>\n" +
+ " ...\n" +
+ " <toAddresses>\n" +
+ " <item>VALUE</item>\n" +
+ " </toAddresses>\n" +
+ "</configuration>.\n", exception.buildDiagnosticMessage() );
+ }
+
+ public void testMissingRequiredMapTypeParameter()
+ {
+ MojoDescriptor mojoDescriptor = new MojoDescriptor();
+ mojoDescriptor.setGoal( "goal" );
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setGoalPrefix( "goalPrefix" );
+ pluginDescriptor.setArtifactId( "artifactId" );
+ mojoDescriptor.setPluginDescriptor( pluginDescriptor );
+
+ Parameter parameter = new Parameter();
+ parameter.setType( "java.util.Map" );
+ parameter.setName( "toAddresses" );
+
+ parameter.setRequired( true );
+
+ PluginParameterException exception =
+ new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
+
+ assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
+ "\n" +
+ "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
+ "\n" +
+ "<configuration>\n" +
+ " ...\n" +
+ " <toAddresses>\n" +
+ " <KEY>VALUE</KEY>\n" +
+ " </toAddresses>\n" +
+ "</configuration>.\n", exception.buildDiagnosticMessage() );
+ }
+
+ public void testMissingRequiredPropertiesTypeParameter()
+ {
+ MojoDescriptor mojoDescriptor = new MojoDescriptor();
+ mojoDescriptor.setGoal( "goal" );
+ PluginDescriptor pluginDescriptor = new PluginDescriptor();
+ pluginDescriptor.setGoalPrefix( "goalPrefix" );
+ pluginDescriptor.setArtifactId( "artifactId" );
+ mojoDescriptor.setPluginDescriptor( pluginDescriptor );
+
+ Parameter parameter = new Parameter();
+ parameter.setType( "java.util.Properties" );
+ parameter.setName( "toAddresses" );
+
+ parameter.setRequired( true );
+
+ PluginParameterException exception =
+ new PluginParameterException( mojoDescriptor, Collections.singletonList( parameter ) );
+
+ assertEquals( "One or more required plugin parameters are invalid/missing for 'goalPrefix:goal'\n" +
+ "\n" +
+ "[0] Inside the definition for plugin 'artifactId', specify the following:\n" +
+ "\n" +
+ "<configuration>\n" +
+ " ...\n" +
+ " <toAddresses>\n" +
+ " <property>\n" +
+ " <name>KEY</name>\n" +
+ " <value>VALUE</value>\n" +
+ " </property>\n" +
+ " </toAddresses>\n" +
+ "</configuration>.\n", exception.buildDiagnosticMessage() );
+ }
+
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
new file mode 100644
index 00000000..5f6744c9
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorTest.java
@@ -0,0 +1,447 @@
+package org.apache.maven.plugin;
+
+/*
+ * 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.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.maven.AbstractCoreMavenComponentTestCase;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.ArtifactUtils;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.DefaultMavenExecutionResult;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.Build;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Model;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
+import org.apache.maven.project.DuplicateProjectException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.repository.RepositorySystem;
+import org.codehaus.plexus.MutablePlexusContainer;
+import org.codehaus.plexus.PlexusContainer;
+import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
+import org.codehaus.plexus.util.dag.CycleDetectedException;
+
+/**
+ * @author Jason van Zyl
+ */
+public class PluginParameterExpressionEvaluatorTest
+ extends AbstractCoreMavenComponentTestCase
+{
+ private static final String FS = System.getProperty( "file.separator" );
+
+ private RepositorySystem factory;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ factory = lookup( RepositorySystem.class );
+ }
+
+ @Override
+ protected void tearDown()
+ throws Exception
+ {
+ factory = null;
+ super.tearDown();
+ }
+
+ public void testPluginDescriptorExpressionReference()
+ throws Exception
+ {
+ MojoExecution exec = newMojoExecution();
+
+ MavenSession session = newMavenSession();
+
+ Object result = new PluginParameterExpressionEvaluator( session, exec ).evaluate( "${plugin}" );
+
+ System.out.println( "Result: " + result );
+
+ assertSame( "${plugin} expression does not return plugin descriptor.",
+ exec.getMojoDescriptor().getPluginDescriptor(),
+ result );
+ }
+
+ public void testPluginArtifactsExpressionReference()
+ throws Exception
+ {
+ MojoExecution exec = newMojoExecution();
+
+ Artifact depArtifact = createArtifact( "group", "artifact", "1" );
+
+ List<Artifact> deps = new ArrayList<Artifact>();
+ deps.add( depArtifact );
+
+ exec.getMojoDescriptor().getPluginDescriptor().setArtifacts( deps );
+
+ MavenSession session = newMavenSession();
+
+ @SuppressWarnings( "unchecked" )
+ List<Artifact> depResults =
+ (List<Artifact>) new PluginParameterExpressionEvaluator( session, exec ).evaluate( "${plugin.artifacts}" );
+
+ System.out.println( "Result: " + depResults );
+
+ assertNotNull( depResults );
+ assertEquals( 1, depResults.size() );
+ assertSame( "dependency artifact is wrong.", depArtifact, depResults.get( 0 ) );
+ }
+
+ public void testPluginArtifactMapExpressionReference()
+ throws Exception
+ {
+ MojoExecution exec = newMojoExecution();
+
+ Artifact depArtifact = createArtifact( "group", "artifact", "1" );
+
+ List<Artifact> deps = new ArrayList<Artifact>();
+ deps.add( depArtifact );
+
+ exec.getMojoDescriptor().getPluginDescriptor().setArtifacts( deps );
+
+ MavenSession session = newMavenSession();
+
+ @SuppressWarnings( "unchecked" )
+ Map<String, Artifact> depResults =
+ (Map<String, Artifact>) new PluginParameterExpressionEvaluator( session, exec ).evaluate( "${plugin.artifactMap}" );
+
+ System.out.println( "Result: " + depResults );
+
+ assertNotNull( depResults );
+ assertEquals( 1, depResults.size() );
+ assertSame( "dependency artifact is wrong.",
+ depArtifact,
+ depResults.get( ArtifactUtils.versionlessKey( depArtifact ) ) );
+ }
+
+ public void testPluginArtifactIdExpressionReference()
+ throws Exception
+ {
+ MojoExecution exec = newMojoExecution();
+
+ MavenSession session = newMavenSession();
+
+ Object result = new PluginParameterExpressionEvaluator( session, exec ).evaluate( "${plugin.artifactId}" );
+
+ System.out.println( "Result: " + result );
+
+ assertSame( "${plugin.artifactId} expression does not return plugin descriptor's artifactId.",
+ exec.getMojoDescriptor().getPluginDescriptor().getArtifactId(),
+ result );
+ }
+
+ public void testValueExtractionWithAPomValueContainingAPath()
+ throws Exception
+ {
+ String expected = getTestFile( "target/test-classes/target/classes" ).getCanonicalPath();
+
+ Build build = new Build();
+ build.setDirectory( expected.substring( 0, expected.length() - "/classes".length() ) );
+
+ Model model = new Model();
+ model.setBuild( build );
+
+ MavenProject project = new MavenProject( model );
+ project.setFile( new File( "pom.xml" ).getCanonicalFile() );
+
+ ExpressionEvaluator expressionEvaluator = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = expressionEvaluator.evaluate( "${project.build.directory}/classes" );
+ String actual = new File( value.toString() ).getCanonicalPath();
+
+ assertEquals( expected, actual );
+ }
+
+ public void testEscapedVariablePassthrough()
+ throws Exception
+ {
+ String var = "${var}";
+
+ Model model = new Model();
+ model.setVersion( "1" );
+
+ MavenProject project = new MavenProject( model );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = ee.evaluate( "$" + var );
+
+ assertEquals( var, value );
+ }
+
+ public void testEscapedVariablePassthroughInLargerExpression()
+ throws Exception
+ {
+ String var = "${var}";
+ String key = var + " with version: ${project.version}";
+
+ Model model = new Model();
+ model.setVersion( "1" );
+
+ MavenProject project = new MavenProject( model );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = ee.evaluate( "$" + key );
+
+ assertEquals( "${var} with version: 1", value );
+ }
+
+ public void testMultipleSubExpressionsInLargerExpression()
+ throws Exception
+ {
+ String key = "${project.artifactId} with version: ${project.version}";
+
+ Model model = new Model();
+ model.setArtifactId( "test" );
+ model.setVersion( "1" );
+
+ MavenProject project = new MavenProject( model );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = ee.evaluate( key );
+
+ assertEquals( "test with version: 1", value );
+ }
+
+ public void testMissingPOMPropertyRefInLargerExpression()
+ throws Exception
+ {
+ String expr = "/path/to/someproject-${baseVersion}";
+
+ MavenProject project = new MavenProject( new Model() );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = ee.evaluate( expr );
+
+ assertEquals( expr, value );
+ }
+
+ public void testPOMPropertyExtractionWithMissingProject_WithDotNotation()
+ throws Exception
+ {
+ String key = "m2.name";
+ String checkValue = "value";
+
+ Properties properties = new Properties();
+ properties.setProperty( key, checkValue );
+
+ Model model = new Model();
+ model.setProperties( properties );
+
+ MavenProject project = new MavenProject( model );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( project, null, new Properties() );
+
+ Object value = ee.evaluate( "${" + key + "}" );
+
+ assertEquals( checkValue, value );
+ }
+
+ public void testBasedirExtractionWithMissingProject()
+ throws Exception
+ {
+ ExpressionEvaluator ee = createExpressionEvaluator( null, null, new Properties() );
+
+ Object value = ee.evaluate( "${basedir}" );
+
+ assertEquals( System.getProperty( "user.dir" ), value );
+ }
+
+ public void testValueExtractionFromSystemPropertiesWithMissingProject()
+ throws Exception
+ {
+ String sysprop = "PPEET_sysprop1";
+
+ Properties executionProperties = new Properties();
+
+ if ( executionProperties.getProperty( sysprop ) == null )
+ {
+ executionProperties.setProperty( sysprop, "value" );
+ }
+
+ ExpressionEvaluator ee = createExpressionEvaluator( null, null, executionProperties );
+
+ Object value = ee.evaluate( "${" + sysprop + "}" );
+
+ assertEquals( "value", value );
+ }
+
+ public void testValueExtractionFromSystemPropertiesWithMissingProject_WithDotNotation()
+ throws Exception
+ {
+ String sysprop = "PPEET.sysprop2";
+
+ Properties executionProperties = new Properties();
+
+ if ( executionProperties.getProperty( sysprop ) == null )
+ {
+ executionProperties.setProperty( sysprop, "value" );
+ }
+
+ ExpressionEvaluator ee = createExpressionEvaluator( null, null, executionProperties );
+
+ Object value = ee.evaluate( "${" + sysprop + "}" );
+
+ assertEquals( "value", value );
+ }
+
+ @SuppressWarnings( "deprecation" )
+ private static MavenSession createSession( PlexusContainer container, ArtifactRepository repo, Properties properties )
+ throws CycleDetectedException, DuplicateProjectException
+ {
+ MavenExecutionRequest request = new DefaultMavenExecutionRequest()
+ .setSystemProperties( properties )
+ .setGoals( Collections.<String>emptyList() )
+ .setBaseDirectory( new File( "" ) )
+ .setLocalRepository( repo );
+
+ return new MavenSession( container, request, new DefaultMavenExecutionResult(), Collections.<MavenProject>emptyList() );
+ }
+
+ public void testLocalRepositoryExtraction()
+ throws Exception
+ {
+ ExpressionEvaluator expressionEvaluator =
+ createExpressionEvaluator( createDefaultProject(), null, new Properties() );
+ Object value = expressionEvaluator.evaluate( "${localRepository}" );
+
+ assertEquals( "local", ( (ArtifactRepository) value ).getId() );
+ }
+
+ public void testTwoExpressions()
+ throws Exception
+ {
+ Build build = new Build();
+ build.setDirectory( "expected-directory" );
+ build.setFinalName( "expected-finalName" );
+
+ Model model = new Model();
+ model.setBuild( build );
+
+ ExpressionEvaluator expressionEvaluator =
+ createExpressionEvaluator( new MavenProject( model ), null, new Properties() );
+
+ Object value = expressionEvaluator.evaluate( "${project.build.directory}" + FS + "${project.build.finalName}" );
+
+ assertEquals( "expected-directory" + File.separatorChar + "expected-finalName", value );
+ }
+
+ public void testShouldExtractPluginArtifacts()
+ throws Exception
+ {
+ PluginDescriptor pd = new PluginDescriptor();
+
+ Artifact artifact = createArtifact( "testGroup", "testArtifact", "1.0" );
+
+ pd.setArtifacts( Collections.singletonList( artifact ) );
+
+ ExpressionEvaluator ee = createExpressionEvaluator( createDefaultProject(), pd, new Properties() );
+
+ Object value = ee.evaluate( "${plugin.artifacts}" );
+
+ assertTrue( value instanceof List );
+
+ @SuppressWarnings( "unchecked" )
+ List<Artifact> artifacts = (List<Artifact>) value;
+
+ assertEquals( 1, artifacts.size() );
+
+ Artifact result = artifacts.get( 0 );
+
+ assertEquals( "testGroup", result.getGroupId() );
+ }
+
+ private MavenProject createDefaultProject()
+ {
+ return new MavenProject( new Model() );
+ }
+
+ private ExpressionEvaluator createExpressionEvaluator( MavenProject project, PluginDescriptor pluginDescriptor, Properties executionProperties )
+ throws Exception
+ {
+ ArtifactRepository repo = factory.createDefaultLocalRepository();
+
+ MutablePlexusContainer container = (MutablePlexusContainer) getContainer();
+ MavenSession session = createSession( container, repo, executionProperties );
+ session.setCurrentProject( project );
+
+ MojoDescriptor mojo = new MojoDescriptor();
+ mojo.setPluginDescriptor( pluginDescriptor );
+ mojo.setGoal( "goal" );
+
+ MojoExecution mojoExecution = new MojoExecution( mojo );
+
+ return new PluginParameterExpressionEvaluator( session, mojoExecution );
+ }
+
+ protected Artifact createArtifact( String groupId, String artifactId, String version )
+ throws Exception
+ {
+ Dependency dependency = new Dependency();
+ dependency.setGroupId( groupId );
+ dependency.setArtifactId( artifactId );
+ dependency.setVersion( version );
+ dependency.setType( "jar" );
+ dependency.setScope( "compile" );
+
+ return factory.createDependencyArtifact( dependency );
+ }
+
+ private MojoExecution newMojoExecution()
+ {
+ PluginDescriptor pd = new PluginDescriptor();
+ pd.setArtifactId( "my-plugin" );
+ pd.setGroupId( "org.myco.plugins" );
+ pd.setVersion( "1" );
+
+ MojoDescriptor md = new MojoDescriptor();
+ md.setPluginDescriptor( pd );
+
+ pd.addComponentDescriptor( md );
+
+ return new MojoExecution( md );
+ }
+
+ private MavenSession newMavenSession()
+ throws Exception
+ {
+ return createMavenSession( null );
+ }
+
+ @Override
+ protected String getProjectsDirectory()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java
new file mode 100644
index 00000000..d350770c
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-core/src/test/java/org/apache/maven/plugin/internal/DefaultLegacySupportTest.java
@@ -0,0 +1,74 @@
+package org.apache.maven.plugin.internal;
+/*
+ * 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 org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
+import org.apache.maven.execution.MavenSession;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class DefaultLegacySupportTest extends TestCase {
+ final CountDownLatch latch = new CountDownLatch(1);
+ final DefaultLegacySupport defaultLegacySupport = new DefaultLegacySupport();
+
+ public void testSetSession() throws Exception {
+
+ MavenExecutionRequest mavenExecutionRequest = new DefaultMavenExecutionRequest();
+ MavenSession m1 = new MavenSession(null, null, mavenExecutionRequest, null);
+ defaultLegacySupport.setSession(m1);
+
+ MyRunnable myRunnable = new MyRunnable();
+ Thread thread = new Thread(myRunnable);
+ thread.start();
+
+ MavenSession m2 = new MavenSession(null, null, mavenExecutionRequest, null);
+ defaultLegacySupport.setSession(m2);
+ latch.countDown();
+ thread.join();
+ assertNull( myRunnable.getSession());
+ }
+
+
+ class MyRunnable implements Runnable {
+
+ private volatile MavenSession session;
+
+ public void run() {
+ try
+ {
+ latch.await();
+ }
+ catch (InterruptedException ingore)
+ {
+ // Test may fail if we get interrupted
+ }
+ session = defaultLegacySupport.getSession();
+ }
+
+ public MavenSession getSession() {
+ return session;
+ }
+ }
+
+}