Skip to content

Commit

Permalink
1.1.1 maintenance release, reworked class path generation method, rem…
Browse files Browse the repository at this point in the history
…oved usage of jcabi-aether to avoid NPE with complex settings.xml
  • Loading branch information
raydac committed Jun 7, 2015
1 parent 65e31cb commit 80f8479
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 19 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.1.1
- reworked test class path generating mechanism, removed usage of jcabi-aether because sometime it throws NPE with complex settings.xml

1.1.0
- reworked project structure
- added @JUteTest annotation to mark tests to be started with JUte (provided by the jute-annotations artefact)
Expand Down
21 changes: 10 additions & 11 deletions jute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
Expand All @@ -46,17 +56,6 @@
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.10.1</version>
<exclusions>
<exclusion>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-all</artifactId>
Expand Down
51 changes: 44 additions & 7 deletions jute/src/main/java/com/igormaznitsa/jute/JuteMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
import com.igormaznitsa.jute.TestContainer.TestResult;
import com.igormaznitsa.jute.runners.JUnitSingleTestMethodRunner;
import com.igormaznitsa.jute.runners.JUteSingleTestMethodRunner;
import com.jcabi.aether.Classpath;
import java.io.*;
import java.net.URISyntaxException;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.io.*;
import org.apache.commons.io.filefilter.*;
import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.*;
import org.apache.maven.plugin.logging.Log;
Expand All @@ -36,6 +35,7 @@
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import org.objectweb.asm.*;
import org.apache.maven.artifact.Artifact;
import org.springframework.util.AntPathMatcher;

/**
Expand Down Expand Up @@ -64,9 +64,6 @@ public class JuteMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject project;

@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

/**
* List of test method names to be included into testing. Wildcard pattern can
* be used. By default all non-ignored test methods are included.
Expand Down Expand Up @@ -225,6 +222,26 @@ public class JuteMojo extends AbstractMojo {
@Parameter(name = "in")
private String in;

/**
* The value contains folder of compiled test classes.
*/
@Parameter(name = "testClassesDirectory", defaultValue = "${project.build.testOutputDirectory}")
private File testClassesDirectory;

/**
* The value contains folder of compiled project classes.
*/
@Parameter(name = "classesDirectory", defaultValue = "${project.build.outputDirectory}")
private File classesDirectory;

public File getTestClassesDirectory() {
return this.testClassesDirectory;
}

public File getClassesDirectory() {
return this.classesDirectory;
}

public String getIn() {
return this.in;
}
Expand Down Expand Up @@ -434,6 +451,26 @@ private static File getFilePathToJVMInterpreter(final String jvmInterpreter) {
return result;
}

private Collection<File> getClassPathAsFiles() {
final List<File> result = new ArrayList<File>();
if (this.testClassesDirectory != null) {
result.add(this.testClassesDirectory);
}
if (this.classesDirectory != null) {
result.add(this.classesDirectory);
}

for (final Artifact a : project.getArtifacts()) {
if (a.getArtifactHandler().isAddedToClasspath()) {
File file = a.getFile();
if (file != null) {
result.add(file);
}
}
}
return result;
}

private String makeClassPath(final File mojoJarPath, final Collection<File> files) {
final StringBuilder result = new StringBuilder();

Expand All @@ -459,7 +496,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}

final File testFolder = new File(this.project.getBuild().getTestOutputDirectory());
final File testFolder = this.testClassesDirectory;
if (!testFolder.isDirectory()) {
getLog().info("No test folder");
return;
Expand All @@ -475,7 +512,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

final File javaInterpreter = getFilePathToJVMInterpreter(this.java);
final String testClassPath = makeClassPath(pathToMojoJar, new Classpath(project, new File(session.getLocalRepository().getBasedir()), "test"));
final String testClassPath = makeClassPath(pathToMojoJar, getClassPathAsFiles());

final TestContainer baseTestConfig = new TestContainer(null, null, null, javaInterpreter == null ? this.java : javaInterpreter.getAbsolutePath(), this.jvmOptions, this.in, -1, this.enforcePrintConsole, false, this.timeout);

Expand Down
4 changes: 4 additions & 0 deletions jute/src/test/java/com/igormaznitsa/jute/JuteMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public void testDefaultConfig() throws Exception {
assertFalse(myMojo.isSkipTests());
assertFalse(myMojo.isEnforcePrintConsole());
assertNull(myMojo.getJUteTest());
assertNull(myMojo.getClassesDirectory());
assertNull(myMojo.getTestClassesDirectory());
}

public void testNonDefaultConfig() throws Exception {
Expand Down Expand Up @@ -93,5 +95,7 @@ public void testNonDefaultConfig() throws Exception {
assertTrue(myMojo.isEnforcePrintConsole());
assertEquals("Some test text",myMojo.getIn());
assertEquals("some.package.DefaultTest#Method", myMojo.getJUteTest());
assertEquals("target/classes",myMojo.getClassesDirectory().toString());
assertEquals("target/test-classes",myMojo.getTestClassesDirectory().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
</property>
</javaProperties>
<juteTest>some.package.DefaultTest#Method</juteTest>
<classesDirectory>target/classes</classesDirectory>
<testClassesDirectory>target/test-classes</testClassesDirectory>
</configuration>
</plugin>
</plugins>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</prerequisites>

<properties>
<parent.version>1.1.1-SNAPSHOT</parent.version>
<parent.version>1.1.1</parent.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
Expand Down

0 comments on commit 80f8479

Please sign in to comment.