T lookupMojo( String groupId, String artifactId, Stri
T mojo = (T) lookup( Mojo.class, groupId + ":" + artifactId + ":" + version + ":" + goal );
- LoggerManager loggerManager = getContainer().lookup( LoggerManager.class );
-
- Log mojoLogger = new DefaultLog( loggerManager.getLoggerForComponent( Mojo.ROLE ) );
-
- mojo.setLog( mojoLogger );
-
if ( pluginConfiguration != null )
{
/* requires v10 of plexus container for lookup on expression evaluator
@@ -494,7 +488,6 @@ protected MavenSession newMavenSession( MavenProject project )
MavenSession session = new MavenSession( container, MavenRepositorySystemUtils.newSession(), request, result );
session.setCurrentProject( project );
- //noinspection ArraysAsListWithZeroOrOneArgument
session.setProjects( Arrays.asList( project ) );
return session;
}
@@ -525,7 +518,7 @@ private void finalizeMojoConfiguration( MojoExecution mojoExecution )
executionConfiguration = new Xpp3Dom( "configuration" );
}
- Xpp3Dom defaultConfiguration = MojoDescriptorCreator.convert( mojoDescriptor );
+ Xpp3Dom defaultConfiguration = new Xpp3Dom( MojoDescriptorCreator.convert( mojoDescriptor ) );
Xpp3Dom finalConfiguration = new Xpp3Dom( "configuration" );
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
index 618d36f6..73bc8eea 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ArtifactStubFactory.java
@@ -316,7 +316,7 @@ public void createUnpackableFile( Artifact artifact, File destFile )
WarArchiver war = (WarArchiver) archiver;
// the use of this is counter-intuitive:
// http://jira.codehaus.org/browse/PLX-286
- war.setExpectWebXml( false );
+ war.setIgnoreWebxml( false );
}
archiver.createArchive();
}
@@ -549,7 +549,7 @@ public static void setVariableValueToObject( Object object, String variable, Obj
*/
public static String getFormattedFileName( Artifact artifact, boolean removeVersion )
{
- String destFileName;
+ String destFileName = null;
// if there is a file and we aren't stripping the version, just get the
// name directly
@@ -560,7 +560,7 @@ public static String getFormattedFileName( Artifact artifact, boolean removeVers
else
// if offline
{
- String versionString;
+ String versionString = null;
if ( !removeVersion )
{
versionString = "-" + artifact.getVersion();
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java
new file mode 100644
index 00000000..6fb4f247
--- /dev/null
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoLogWrapper.java
@@ -0,0 +1,146 @@
+package org.apache.maven.plugin.testing;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.plugin.logging.Log;
+import org.slf4j.Logger;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * @author jdcasey
+ */
+public class MojoLogWrapper
+ implements Log
+{
+ private final Logger logger;
+
+ public MojoLogWrapper( Logger logger )
+ {
+ this.logger = requireNonNull( logger );
+ }
+
+ public void debug( CharSequence content )
+ {
+ logger.debug( toString( content ) );
+ }
+
+ private String toString( CharSequence content )
+ {
+ if ( content == null )
+ {
+ return "";
+ }
+ else
+ {
+ return content.toString();
+ }
+ }
+
+ @Override
+ public void debug( CharSequence content, Throwable error )
+ {
+ logger.debug( toString( content ), error );
+ }
+
+ @Override
+ public void debug( Throwable error )
+ {
+ logger.debug( "", error );
+ }
+
+ @Override
+ public void info( CharSequence content )
+ {
+ logger.info( toString( content ) );
+ }
+
+ @Override
+ public void info( CharSequence content, Throwable error )
+ {
+ logger.info( toString( content ), error );
+ }
+
+ @Override
+ public void info( Throwable error )
+ {
+ logger.info( "", error );
+ }
+
+ @Override
+ public void warn( CharSequence content )
+ {
+ logger.warn( toString( content ) );
+ }
+
+ @Override
+ public void warn( CharSequence content, Throwable error )
+ {
+ logger.warn( toString( content ), error );
+ }
+
+ @Override
+ public void warn( Throwable error )
+ {
+ logger.warn( "", error );
+ }
+
+ @Override
+ public void error( CharSequence content )
+ {
+ logger.error( toString( content ) );
+ }
+
+ @Override
+ public void error( CharSequence content, Throwable error )
+ {
+ logger.error( toString( content ), error );
+ }
+
+ @Override
+ public void error( Throwable error )
+ {
+ logger.error( "", error );
+ }
+
+ @Override
+ public boolean isDebugEnabled()
+ {
+ return logger.isDebugEnabled();
+ }
+
+ @Override
+ public boolean isInfoEnabled()
+ {
+ return logger.isInfoEnabled();
+ }
+
+ @Override
+ public boolean isWarnEnabled()
+ {
+ return logger.isWarnEnabled();
+ }
+
+ @Override
+ public boolean isErrorEnabled()
+ {
+ return logger.isErrorEnabled();
+ }
+}
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
index 04d25644..b430bd83 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/MojoRule.java
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.util.Map;
+import org.apache.maven.api.Session;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
@@ -49,8 +50,8 @@
/**
* {@link TestRule} for usage with Junit-4.10ff. This is just a wrapper for an embedded
- * {@link AbstractMojoTestCase}, so all protected methods of the TestCase are
- * exhibited as public in the rule. You may annotate single tests methods with
+ * {@link AbstractMojoTestCase}, so all {@code protected} methods of the TestCase are
+ * exhibited as {@code public} in the rule. You may annotate single tests methods with
* {@link WithoutMojo} to prevent the rule from firing.
*
* @author Mirko Friedenhagen
@@ -87,8 +88,7 @@ protected void before() throws Throwable
/**
* May be overridden in the implementation to do stuff after the current test was run.
*/
- @SuppressWarnings( "EmptyMethod" )
- protected void after()
+ protected void after()
{
}
@@ -407,6 +407,7 @@ public void executeMojo( MavenSession session, MavenProject project, MojoExecuti
{
sessionScope.enter();
sessionScope.seed( MavenSession.class, session );
+ sessionScope.seed( Session.class, session.getSession() );
MojoExecutionScope executionScope = lookup( MojoExecutionScope.class );
try
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java
index 92172f96..3fed91fe 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/ResolverExpressionEvaluatorStub.java
@@ -21,12 +21,11 @@
import java.io.File;
-import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
import org.apache.maven.artifact.repository.MavenArtifactRepository;
+import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
-import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
/**
* Stub for {@link ExpressionEvaluator}
@@ -76,7 +75,7 @@ public Object evaluate( String expr )
}
// Was not an expression
- if ( expression.contains( "$$" ) )
+ if ( expression.indexOf( "$$" ) > -1 )
{
return expression.replaceAll( "\\$\\$", "\\$" );
}
@@ -102,11 +101,9 @@ else if ( expression.startsWith( "basedir" ) || expression.startsWith( "project.
}
else if ( "localRepository".equals( expression ) )
{
- return new MavenArtifactRepository( "localRepository",
- "file://" + new File( PlexusTestCase.getBasedir(), "target/local-repo" ).getAbsolutePath(),
- new DefaultRepositoryLayout(),
- new ArtifactRepositoryPolicy( true, "release", "always" ),
- new ArtifactRepositoryPolicy( true, "snapshot", "never" ) );
+ File localRepo = new File( PlexusTestCase.getBasedir(), "target/local-repo" );
+ return new MavenArtifactRepository( "localRepository", "file://" + localRepo.getAbsolutePath(),
+ new DefaultRepositoryLayout(), null, null );
}
else
{
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
index b183c3e4..f8712923 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/resources/TestResources.java
@@ -21,7 +21,6 @@
import java.io.File;
import java.io.IOException;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
@@ -73,7 +72,8 @@ protected void starting( Description d )
/**
* Creates new clean copy of test project directory structure. The copy is named after both the test being executed
* and test project name, which allows the same test project can be used by multiple tests and by different
- * instances of the same parametrized tests.
+ * instances of the same parametrized tests.
+ *
* TODO Provide alternative working directory naming for Windows, which still limits path names to ~250 charecters
*/
public File getBasedir( String project )
@@ -117,7 +117,11 @@ public static void assertDirectoryContents( File dir, String... expectedPaths )
scanner.addDefaultExcludes();
scanner.scan();
- Set actual = new TreeSet<>( Arrays.asList( scanner.getIncludedFiles() ) );
+ Set actual = new TreeSet<>();
+ for ( String path : scanner.getIncludedFiles() )
+ {
+ actual.add( path );
+ }
for ( String path : scanner.getIncludedDirectories() )
{
if ( path.length() > 0 )
@@ -129,7 +133,10 @@ public static void assertDirectoryContents( File dir, String... expectedPaths )
Set expected = new TreeSet<>();
if ( expectedPaths != null )
{
- expected.addAll( Arrays.asList( expectedPaths ) );
+ for ( String path : expectedPaths )
+ {
+ expected.add( path );
+ }
}
// compare textual representation to make diff easier to understand
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java
index 33b7dbae..63f15c51 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/ArtifactStub.java
@@ -185,7 +185,14 @@ public String getId()
@Override
public String getDependencyConflictId()
{
- return getGroupId() + ":" + getArtifactId() + ":" + getType() + ":" + getClassifier();
+ StringBuffer buffer = new StringBuffer();
+
+ buffer.append( getGroupId() );
+ buffer.append( ":" ).append( getArtifactId() );
+ buffer.append( ":" ).append( getType() );
+ buffer.append( ":" ).append( getClassifier() );
+
+ return buffer.toString();
}
/**
@@ -193,7 +200,6 @@ public String getDependencyConflictId()
*
* @see org.apache.maven.artifact.Artifact#addMetadata(org.apache.maven.artifact.metadata.ArtifactMetadata)
*/
- @SuppressWarnings( "deprecation" )
@Override
public void addMetadata( ArtifactMetadata artifactMetadata )
{
@@ -204,7 +210,6 @@ public void addMetadata( ArtifactMetadata artifactMetadata )
* @return null.
* @see org.apache.maven.artifact.Artifact#getMetadataList()
*/
- @SuppressWarnings( "deprecation" )
@Override
public Collection getMetadataList()
{
@@ -544,7 +549,6 @@ public boolean isFromAuthoritativeRepository()
return true;
}
- @SuppressWarnings( "EmptyMethod" )
public void setFromAuthoritativeRepository( boolean fromAuthoritativeRepository )
{
// nothing
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
index 4b81e857..aacb6e73 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/MavenProjectStub.java
@@ -69,7 +69,6 @@
*
* @author jesse
*/
-@SuppressWarnings( "FieldCanBeLocal" )
public class MavenProjectStub
extends MavenProject
{
@@ -283,14 +282,19 @@ public void setRemoteArtifactRepositories( List list )
@Override
public List getRemoteArtifactRepositories()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/** {@inheritDoc} */
@Override
public boolean hasParent()
{
- return parent != null;
+ if ( parent != null )
+ {
+ return true;
+ }
+
+ return false;
}
/** {@inheritDoc} */
@@ -333,7 +337,7 @@ public void setDependencies( List list )
@Override
public List getDependencies()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -956,7 +960,7 @@ public void setMailingLists( List list )
@Override
public List getMailingLists()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -989,7 +993,7 @@ public void setDevelopers( List list )
@Override
public List getDevelopers()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1022,7 +1026,7 @@ public void setContributors( List list )
@Override
public List getContributors()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1058,7 +1062,7 @@ public Build getBuild()
@Override
public List getResources()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1069,7 +1073,7 @@ public List getResources()
@Override
public List getTestResources()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1160,7 +1164,7 @@ public void setArtifacts( Set set )
@Override
public Set getArtifacts()
{
- return Collections.emptySet();
+ return Collections.emptySet();
}
/**
@@ -1171,7 +1175,7 @@ public Set getArtifacts()
@Override
public Map getArtifactMap()
{
- return Collections.emptyMap();
+ return Collections.emptyMap();
}
/**
@@ -1193,7 +1197,7 @@ public void setPluginArtifacts( Set set )
@Override
public Set getPluginArtifacts()
{
- return Collections.emptySet();
+ return Collections.emptySet();
}
/**
@@ -1204,7 +1208,7 @@ public Set getPluginArtifacts()
@Override
public Map getPluginArtifactMap()
{
- return Collections.emptyMap();
+ return Collections.emptyMap();
}
/**
@@ -1226,7 +1230,7 @@ public void setReportArtifacts( Set set )
@Override
public Set getReportArtifacts()
{
- return Collections.emptySet();
+ return Collections.emptySet();
}
/**
@@ -1237,7 +1241,7 @@ public Set getReportArtifacts()
@Override
public Map getReportArtifactMap()
{
- return Collections.emptyMap();
+ return Collections.emptyMap();
}
/**
@@ -1259,7 +1263,7 @@ public void setExtensionArtifacts( Set set )
@Override
public Set getExtensionArtifacts()
{
- return Collections.emptySet();
+ return Collections.emptySet();
}
/**
@@ -1270,7 +1274,7 @@ public Set getExtensionArtifacts()
@Override
public Map getExtensionArtifactMap()
{
- return Collections.emptyMap();
+ return Collections.emptyMap();
}
/**
@@ -1303,7 +1307,7 @@ public Artifact getParentArtifact()
@Override
public List getRepositories()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1314,7 +1318,7 @@ public List getRepositories()
@Override
public List getReportPlugins()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1325,7 +1329,7 @@ public List getReportPlugins()
@Override
public List getBuildPlugins()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1336,7 +1340,7 @@ public List getBuildPlugins()
@Override
public List getModules()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1353,7 +1357,6 @@ public PluginManagement getPluginManagement()
/**
* By default, do nothing.
*/
- @SuppressWarnings( "EmptyMethod" )
public void addPlugin( Plugin plugin )
{
// nop
@@ -1364,7 +1367,6 @@ public void addPlugin( Plugin plugin )
*
* @param plugin
*/
- @SuppressWarnings( "EmptyMethod" )
public void injectPluginManagementInfo( Plugin plugin )
{
// nop
@@ -1417,7 +1419,7 @@ public ArtifactRepository getDistributionManagementArtifactRepository()
@Override
public List getPluginRepositories()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/** {@inheritDoc} */
@@ -1573,7 +1575,7 @@ public Model getOriginalModel()
@Override
public List getBuildExtensions()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1585,7 +1587,7 @@ public List getBuildExtensions()
public Set createArtifacts( ArtifactFactory artifactFactory, String string,
ArtifactFilter artifactFilter )
{
- return Collections.emptySet();
+ return Collections.emptySet();
}
/**
@@ -1629,7 +1631,7 @@ public Properties getProperties()
@Override
public List getFilters()
{
- return Collections.emptyList();
+ return Collections.emptyList();
}
/**
@@ -1640,7 +1642,7 @@ public List getFilters()
@Override
public Map getProjectReferences()
{
- return Collections.emptyMap();
+ return Collections.emptyMap();
}
/** {@inheritDoc} */
diff --git a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
index 65995c83..3a5d7cb9 100644
--- a/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
+++ b/maven-plugin-testing-harness/src/main/java/org/apache/maven/plugin/testing/stubs/StubArtifactRepository.java
@@ -37,7 +37,7 @@
public class StubArtifactRepository
implements ArtifactRepository
{
- private final String baseDir;
+ private String baseDir = null;
/**
* Default constructor
@@ -274,4 +274,16 @@ public void setMirroredRepositories( List artifactRepositori
{
// no op
}
+
+ @Override
+ public boolean isBlocked()
+ {
+ return false;
+ }
+
+ @Override
+ public void setBlocked( boolean blocked )
+ {
+ // no op
+ }
}
diff --git a/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt b/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt
index cd63995b..749611f7 100644
--- a/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt
+++ b/maven-plugin-testing-harness/src/site/apt/getting-started/index.apt
@@ -34,7 +34,7 @@ Cookbook: How To Use Maven Plugin Testing Harness?
<<>> which is generated by the Maven Archetype Plugin, i.e.:
+---+
-mvn archetype:generate \
+mvn archetype:create \
-DgroupId=org.apache.maven.plugin.my \
-DartifactId=maven-my-plugin \
-DarchetypeArtifactId=maven-archetype-mojo
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java
new file mode 100644
index 00000000..b86a8d07
--- /dev/null
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/api/plugin/testing/ExpressionEvaluatorTest.java
@@ -0,0 +1,111 @@
+package org.apache.maven.api.plugin.testing;
+
+/*
+ * 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 javax.inject.Named;
+
+import java.nio.file.Paths;
+import java.util.Properties;
+
+import com.google.inject.Provides;
+import org.apache.maven.api.Session;
+import org.apache.maven.api.plugin.MojoException;
+import org.apache.maven.api.plugin.testing.InjectMojo;
+import org.apache.maven.api.plugin.testing.MojoTest;
+import org.apache.maven.api.plugin.testing.stubs.SessionStub;
+import org.codehaus.plexus.util.StringUtils;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.doReturn;
+
+/**
+ * @author Edwin Punzalan
+ */
+@MojoTest
+public class ExpressionEvaluatorTest
+{
+
+ private static final String LOCAL_REPO = "target/local-repo/";
+ private static final String ARTIFACT_ID = "maven-test-mojo";
+ private static final String COORDINATES = "groupId:" + ARTIFACT_ID + ":version:goal";
+ private static final String CONFIG =
+ "\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " " + ARTIFACT_ID + "\n"
+ + " \n"
+ + " ${basedir}\n"
+ + " ${basedir}/workDirectory\n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + " \n"
+ + "\n";
+
+ @Test
+ @InjectMojo( goal = COORDINATES, pom = CONFIG )
+ public void testInjection( ExpressionEvaluatorMojo mojo )
+ {
+ assertDoesNotThrow( mojo::execute );
+ }
+
+ @Named( COORDINATES )
+ public static class ExpressionEvaluatorMojo
+ implements org.apache.maven.api.plugin.Mojo
+ {
+ private String basedir;
+
+ private String workdir;
+
+ /** {@inheritDoc} */
+ @Override
+ public void execute()
+ throws MojoException
+ {
+ if ( StringUtils.isEmpty( basedir ) )
+ {
+ throw new MojoException( "basedir was not injected." );
+ }
+
+ if ( StringUtils.isEmpty( workdir ) )
+ {
+ throw new MojoException( "workdir was not injected." );
+ }
+ else if ( !workdir.startsWith( basedir ) )
+ {
+ throw new MojoException( "workdir does not start with basedir." );
+ }
+ }
+ }
+
+ @Provides @SuppressWarnings( "unused" )
+ Session session()
+ {
+ Session session = SessionStub.getMockSession( LOCAL_REPO );
+ doReturn( new Properties() ).when( session ).getSystemProperties();
+ doReturn( new Properties() ).when( session ).getUserProperties();
+ doAnswer( iom -> Paths.get( MojoExtension.getBasedir() ) ).when( session ).getExecutionRootDirectory();
+ return session;
+ }
+
+}
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java
index dfbd8ab6..52070bf2 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ArtifactStubFactoryTest.java
@@ -22,10 +22,14 @@
import java.io.IOException;
import junit.framework.TestCase;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class ArtifactStubFactoryTest
- extends TestCase
{
+ @Test
public void testVersionChecks() throws IOException
{
ArtifactStubFactory factory = new ArtifactStubFactory();
@@ -35,7 +39,8 @@ public void testVersionChecks() throws IOException
assertFalse(factory.getSnapshotArtifact().isRelease());
}
- public void testCreateFiles()
+ @Test
+ public void testCreateFiles() throws IOException
{
ArtifactStubFactory factory = new ArtifactStubFactory();
assertFalse(factory.isCreateFiles());
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
index 5f1f802d..2d4faa0d 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorMojo.java
@@ -22,6 +22,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
import org.codehaus.plexus.util.StringUtils;
/**
@@ -39,7 +40,7 @@ public class ExpressionEvaluatorMojo
/** {@inheritDoc} */
@Override
public void execute()
- throws MojoExecutionException
+ throws MojoExecutionException, MojoFailureException
{
if ( StringUtils.isEmpty( basedir ) )
{
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
index e4666d59..3939bd2b 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/ExpressionEvaluatorTest.java
@@ -32,6 +32,7 @@
public class ExpressionEvaluatorTest
extends AbstractMojoTestCase
{
+ private Xpp3Dom pomDom;
private PlexusConfiguration pluginConfiguration;
@@ -42,22 +43,24 @@ protected void setUp()
{
super.setUp();
- String pom = "" + "\n"
- + " " + "\n"
- + " " + "\n"
- + " " + "\n"
- + " maven-test-mojo" + "\n"
- + " " + "\n"
- + " ${basedir}" + "\n"
- + " ${basedir}/workDirectory" + "\n"
- + " ${localRepository}" + "\n"
- + " " + "\n"
- + " " + "\n"
- + " " + "\n"
- + " " + "\n"
- + "" + "\n";
+ StringBuffer pom = new StringBuffer();
- Xpp3Dom pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
+ pom.append( "" ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " maven-test-mojo" ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " ${basedir}" ).append( "\n" );
+ pom.append( " ${basedir}/workDirectory" ).append( "\n" );
+ pom.append( " ${localRepository}" ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( " " ).append( "\n" );
+ pom.append( "" ).append( "\n" );
+
+ pomDom = Xpp3DomBuilder.build( new StringReader( pom.toString() ) );
pluginConfiguration = extractPluginConfiguration( "maven-test-mojo", pomDom );
}
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java
index 0c7bc589..86a3902a 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoRuleTest.java
@@ -43,14 +43,18 @@ public class MojoRuleTest
private boolean beforeWasCalled = false;
@Rule
- public final MojoRule rule = new MojoRule() {
+ public MojoRule rule = new MojoRule() {
@Override
- protected void before()
+ protected void before() throws Throwable
{
beforeWasCalled = true;
}
};
+
+ private String pom;
+
+ private Xpp3Dom pomDom;
private PlexusConfiguration pluginConfiguration;
@@ -60,7 +64,8 @@ public void setUp()
throws Exception
{
- String pom = "" +
+ pom =
+ "" +
"" +
"" +
"" +
@@ -74,15 +79,17 @@ public void setUp()
"" +
"";
- Xpp3Dom pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
+ pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
pluginConfiguration = rule.extractPluginConfiguration( "maven-simple-plugin", pomDom );
}
/**
+ * @throws Exception if any
*/
@Test
public void testPluginConfigurationExtraction()
+ throws Exception
{
assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() );
@@ -159,12 +166,14 @@ public void testSettingMojoVariables()
@Test
@WithoutMojo
public void testNoRuleWrapper()
+ throws Exception
{
assertFalse( "before executed although WithMojo annotation was added", beforeWasCalled );
}
@Test
public void testWithRuleWrapper()
+ throws Exception
{
assertTrue( "before executed because WithMojo annotation was not added", beforeWasCalled );
}
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java
index 6858175e..8cf1f23d 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/MojoTestCaseTest.java
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.maven.api.plugin.testing.MojoTest;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
@@ -29,9 +30,13 @@
/**
* @author Jason van Zyl
*/
+@MojoTest
public class MojoTestCaseTest
extends AbstractMojoTestCase
{
+ private String pom;
+
+ private Xpp3Dom pomDom;
private PlexusConfiguration pluginConfiguration;
@@ -42,7 +47,8 @@ protected void setUp()
{
super.setUp();
- String pom = "" +
+ pom =
+ "" +
"" +
"" +
"" +
@@ -56,14 +62,16 @@ protected void setUp()
"" +
"";
- Xpp3Dom pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
+ pomDom = Xpp3DomBuilder.build( new StringReader( pom ) );
pluginConfiguration = extractPluginConfiguration( "maven-simple-plugin", pomDom );
}
/**
+ * @throws Exception if any
*/
public void testPluginConfigurationExtraction()
+ throws Exception
{
assertEquals( "valueOne", pluginConfiguration.getChild( "keyOne" ).getValue() );
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java
index 3fb57c00..c4f32be6 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/PluginArtifactFileTest.java
@@ -30,6 +30,7 @@ public class PluginArtifactFileTest
private static final String FS = System.getProperty( "file.separator" );
public void testArtifact()
+ throws Exception
{
MojoExecution execution = newMojoExecution( "parameters" ); // TODO dedicated test mojo
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java
index 3d1bd109..85ea293b 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/SimpleMojo.java
@@ -20,6 +20,7 @@
*/
import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
/**
* @author Jason van Zyl
@@ -43,6 +44,7 @@ public String getKeyTwo()
@Override
public void execute()
+ throws MojoExecutionException
{
}
}
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
index 25135ac5..4d782df0 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/TestSilentLog.java
@@ -31,7 +31,7 @@ public class TestSilentLog
public void testLog()
{
Log log = new SilentLog();
- String text = "Text";
+ String text = new String( "Text" );
Throwable e = new RuntimeException();
log.debug( text );
log.debug( text, e );
@@ -54,7 +54,7 @@ public void testLog()
public void testLogger()
{
Logger log = new SilentLog();
- String text = "Text";
+ String text = new String( "Text" );
Throwable e = new RuntimeException();
log.debug( text );
diff --git a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java
index 36c4b65b..c7a78e31 100644
--- a/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java
+++ b/maven-plugin-testing-harness/src/test/java/org/apache/maven/plugin/testing/resources/TestResourcesTest.java
@@ -23,7 +23,7 @@
public class TestResourcesTest
{
- public final TestResources resources = new TestResources();
+ public TestResources resources = new TestResources();
@Test( expected = IllegalStateException.class )
public void testNoRuleAnnotation()
diff --git a/pom.xml b/pom.xml
index 58864ee1..a09f9e24 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@ under the License.
org.apache.maven.plugin-testing
maven-plugin-testing
- 3.4.0-SNAPSHOT
+ 4.0.0-SNAPSHOT
pom
Maven Plugin Testing
@@ -67,7 +67,7 @@ under the License.
3.0.0-M7
- 3.2.5
+ 4.0.0-alpha-2
plugin-testing-archives/LATEST
8
2020-04-07T21:04:00Z