You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2016/10/13 19:31:06 UTC
[05/25] maven-surefire git commit: [SUREFIRE-1198] Failsafe does not
allow to configure the jar file to use
[SUREFIRE-1198] Failsafe does not allow to configure the jar file to use
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/f1aea633
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/f1aea633
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/f1aea633
Branch: refs/heads/junit5
Commit: f1aea63320b66e635e0dc27e4f9ecd0e155099d9
Parents: 53c7980
Author: Tibor17 <ti...@lycos.com>
Authored: Sun Sep 25 04:19:47 2016 +0200
Committer: Tibor17 <ti...@lycos.com>
Committed: Sun Sep 25 04:19:47 2016 +0200
----------------------------------------------------------------------
maven-failsafe-plugin/pom.xml | 5 +++
.../plugin/failsafe/IntegrationTestMojo.java | 40 +++++++++++++++-----
.../failsafe/IntegrationTestMojoTest.java | 1 +
.../apt/examples/configuring-classpath.apt.vm | 1 +
maven-surefire-plugin/src/site/fml/faq.fml | 11 ++++++
pom.xml | 7 ++--
6 files changed, 51 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/maven-failsafe-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/maven-failsafe-plugin/pom.xml b/maven-failsafe-plugin/pom.xml
index ff02870..91c7677 100644
--- a/maven-failsafe-plugin/pom.xml
+++ b/maven-failsafe-plugin/pom.xml
@@ -73,6 +73,11 @@
<type>zip</type>
<classifier>site-source</classifier>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
----------------------------------------------------------------------
diff --git a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
index 9f30534..b3f76db 100644
--- a/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
+++ b/maven-failsafe-plugin/src/main/java/org/apache/maven/plugin/failsafe/IntegrationTestMojo.java
@@ -25,7 +25,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
@@ -58,9 +57,12 @@ public class IntegrationTestMojo
* The path representing project <em>JAR</em> file, if exists; Otherwise the directory containing generated
* classes of the project being tested. This will be included after the test classes in the test classpath.
*/
- @Parameter( defaultValue = "${project.build.outputDirectory}" )
+ @Parameter
private File classesDirectory;
+ @Parameter( readonly = true, defaultValue = "${project.build.outputDirectory}" )
+ private File defaultClassesDirectory;
+
/**
* Set this to "true" to skip running integration tests, but still compile them. Its use is NOT RECOMMENDED, but
* quite convenient on occasion.
@@ -388,6 +390,23 @@ public class IntegrationTestMojo
}
}
+ private boolean isJarArtifact( File artifactFile )
+ {
+ return artifactFile != null && artifactFile.isFile() && artifactFile.getName().toLowerCase().endsWith( ".jar" );
+ }
+
+ private static File toAbsoluteCanonical( File f )
+ {
+ try
+ {
+ return f == null ? null : f.getAbsoluteFile().getCanonicalFile();
+ }
+ catch ( IOException e )
+ {
+ throw new IllegalStateException( e.getLocalizedMessage(), e );
+ }
+ }
+
@SuppressWarnings( "deprecation" )
protected boolean isSkipExecution()
{
@@ -481,18 +500,19 @@ public class IntegrationTestMojo
*/
public File getClassesDirectory()
{
- Artifact artifact = getProject().getArtifact();
- File artifactFile = artifact.getFile();
-
- boolean useArtifactFile = artifactFile != null && artifactFile.isFile()
- && artifactFile.getName().toLowerCase().endsWith( ".jar" );
-
- return useArtifactFile ? artifactFile : classesDirectory;
+ File artifact = getProject().getArtifact().getFile();
+ boolean isDefaultClsDir = classesDirectory == null;
+ return isDefaultClsDir ? ( isJarArtifact( artifact ) ? artifact : defaultClassesDirectory ) : classesDirectory;
}
public void setClassesDirectory( File classesDirectory )
{
- this.classesDirectory = classesDirectory;
+ this.classesDirectory = toAbsoluteCanonical( classesDirectory );
+ }
+
+ public void setDefaultClassesDirectory( File defaultClassesDirectory )
+ {
+ this.defaultClassesDirectory = toAbsoluteCanonical( defaultClassesDirectory );
}
public File getReportsDirectory()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
----------------------------------------------------------------------
diff --git a/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
new file mode 100644
index 0000000..cd69d68
--- /dev/null
+++ b/maven-failsafe-plugin/src/test/java/org/apache/maven/plugin/failsafe/IntegrationTestMojoTest.java
@@ -0,0 +1 @@
+package org.apache.maven.plugin.failsafe;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.versioning.Invali
dVersionSpecificationException;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static org.apache.maven.artifact.versioning.VersionRange.createFromVersionSpec;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
import static org.fest.assertions.Assertions.assertThat;
/**
* @since 2.19.2
*/
public class IntegrationTestMojoTest
{
private IntegrationTestMojo mojo;
@Before
public void init() throws InvalidVersionSpecificationException, IOException
{
Artifact artifact = new DefaultArtifact( "g", "a", createFromVersionSpec( "1.0" ), "compile", "jar", "", null );
artifact.setFile( new File( "./target/tmp/a-1.0.jar" ) );
new File( "./target/tmp" ).mkdir();
artifact.getFile().createNewFile();
mojo = spy( IntegrationTestMojo.class );
MavenProject project =
mock( MavenProject.class );
when( project.getArtifact() ).thenReturn( artifact );
when( mojo.getProject() ).thenReturn( project );
}
@Test
public void shouldBeJar()
{
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "a-1.0.jar" );
}
@Test
public void shouldBeAnotherJar()
{
mojo.setClassesDirectory( new File( "./target/another-1.0.jar" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertThat( binaries.getName() ).isEqualTo( "another-1.0.jar" );
}
@Test
public void shouldBeClasses()
{
mojo.setClassesDirectory( new File( "./target/classes" ) );
mojo.setDefaultClassesDirectory( new File( "./target/classes" ) );
File binaries = mojo.getClassesDirectory();
assertT
hat( binaries.getName() ).isEqualTo( "classes" );
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/maven-surefire-plugin/src/site/apt/examples/configuring-classpath.apt.vm
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/apt/examples/configuring-classpath.apt.vm b/maven-surefire-plugin/src/site/apt/examples/configuring-classpath.apt.vm
index 809f268..75e1e9d 100644
--- a/maven-surefire-plugin/src/site/apt/examples/configuring-classpath.apt.vm
+++ b/maven-surefire-plugin/src/site/apt/examples/configuring-classpath.apt.vm
@@ -48,6 +48,7 @@ The Default Classpath
#{if}(${project.artifactId}=="maven-failsafe-plugin")
Notice that loading JAR file is preferable over the output classes directory in the maven-failsafe-plugin.
+ This behavior can be changed by configuration parameter <<<classesDirectory>>>.
#{end}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/maven-surefire-plugin/src/site/fml/faq.fml
----------------------------------------------------------------------
diff --git a/maven-surefire-plugin/src/site/fml/faq.fml b/maven-surefire-plugin/src/site/fml/faq.fml
index b1ec6da..6be7913 100644
--- a/maven-surefire-plugin/src/site/fml/faq.fml
+++ b/maven-surefire-plugin/src/site/fml/faq.fml
@@ -97,5 +97,16 @@ under the License.
</p>
</answer>
</faq>
+ <faq id="failsafe-jar">
+ <question>How maven-failsafe-plugin allows me to configure the jar file or classes to use</question>
+ <answer>
+ <p>
+ By default maven-failsafe-plugin uses project artifact file if packaging is set to "jar" in pom.xml.
+ This can be modified and for instance set to main project classes if you use configuration parameter
+ "classesDirectory". This would mean that you set value "${project.build.outputDirectory}" for the parameter
+ "classesDirectory" in the configuration of plugin.
+ </p>
+ </answer>
+ </faq>
</part>
</faqs>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/f1aea633/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 94b2ea6..77c0385 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,10 +221,9 @@
<version>1.6</version>
</dependency>
<dependency>
- <groupId>jmock</groupId>
- <artifactId>jmock</artifactId>
- <version>1.0.1</version>
- <scope>test</scope>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
</dependency>
<dependency>
<groupId>junit</groupId>