From 06a02a3a6a0e026c5f7d8aca073074cb3dd0d1da Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 11:08:11 +0200 Subject: [PATCH 1/7] some cleanups --- .../org/pitest/maven/SurefireConfigConverter.java | 14 +++++++------- .../generator/ReportGenerationResultEnum.java | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pitest-maven/src/main/java/org/pitest/maven/SurefireConfigConverter.java b/pitest-maven/src/main/java/org/pitest/maven/SurefireConfigConverter.java index ce66ab936..8469c4b21 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/SurefireConfigConverter.java +++ b/pitest-maven/src/main/java/org/pitest/maven/SurefireConfigConverter.java @@ -1,10 +1,5 @@ package org.pitest.maven; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; - import org.codehaus.plexus.util.xml.Xpp3Dom; import org.pitest.functional.F; import org.pitest.functional.FCollection; @@ -13,6 +8,11 @@ import org.pitest.testapi.TestGroupConfig; import org.pitest.util.Glob; +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; + /** * Extracts configuration from surefire plugin and create pitest equivalents */ @@ -44,7 +44,7 @@ private List extractStrings(String element, Xpp3Dom configuration) { String[] parts = groups.getValue().split(" "); return Arrays.asList(parts); } else { - return Collections. emptyList(); + return Collections.emptyList(); } } @@ -74,7 +74,7 @@ private List extract(String childname, Xpp3Dom config) { return result; } - return Collections. emptyList(); + return Collections.emptyList(); } } diff --git a/pitest-maven/src/main/java/org/pitest/maven/report/generator/ReportGenerationResultEnum.java b/pitest-maven/src/main/java/org/pitest/maven/report/generator/ReportGenerationResultEnum.java index d39d8708a..e0a8ee7d1 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/report/generator/ReportGenerationResultEnum.java +++ b/pitest-maven/src/main/java/org/pitest/maven/report/generator/ReportGenerationResultEnum.java @@ -1,12 +1,12 @@ /* * Copyright 2015 Jason Fehr - * + * * Licensed 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. @@ -16,8 +16,8 @@ public enum ReportGenerationResultEnum { - SUCCESS, - FAILURE, - NOT_EXECUTED; - + SUCCESS, + FAILURE, + NOT_EXECUTED + } From 9b874babdc06d610a6ea9d470994c26c00049d77 Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 12:27:16 +0200 Subject: [PATCH 2/7] added environmentVariables in plugin configuration --- .../main/java/org/pitest/maven/PitMojo.java | 40 ++++++++++++------- .../java/org/pitest/maven/PitMojoTest.java | 30 +++++++++----- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java b/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java index 7e42d845a..c96916656 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java +++ b/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java @@ -1,11 +1,5 @@ package org.pitest.maven; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; - import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -21,9 +15,15 @@ import org.pitest.plugin.ClientClasspathPlugin; import org.pitest.plugin.ToolClasspathPlugin; import org.slf4j.bridge.SLF4JBridgeHandler; - import uk.org.lidalia.sysoutslf4j.context.SysOutOverSLF4J; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + /** * Goal which runs a coverage mutation report * @@ -287,27 +287,36 @@ public class PitMojo extends AbstractMojo { /** * honours common skipTests flag in a maven run - * + * * @parameter default-value="false" */ private boolean skipTests; /** * Use slf4j for logging - * + * * @parameter default-value="false" expression="${useSlf4j}" */ private boolean useSlf4j; - + /** * Configuration properties. - * + * * Value pairs may be used by pitest plugins. - * + * * @parameter */ private Map configuration; + /** + * environment configuration + * + * Value pairs may be used by pitest plugins. + * + * @parameter + */ + private Map environmentVariables = new HashMap(); + /** * Internal: Project to interact with. @@ -326,7 +335,7 @@ public class PitMojo extends AbstractMojo { * @readonly */ private Map pluginArtifactMap; - + protected final GoalStrategy goalStrategy; public PitMojo() { @@ -559,9 +568,12 @@ public List getClasspathDependencyExcludes() { public boolean isParseSurefireConfig() { return this.parseSurefireConfig; } - + public Map getPluginProperties() { return configuration; } + public Map getEnvironmentVariables() { + return environmentVariables; + } } diff --git a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java index 3c6a8c083..7f4b7a8a0 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -1,12 +1,5 @@ package org.pitest.maven; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.File; - import org.apache.maven.model.Build; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -17,6 +10,11 @@ import org.pitest.mutationtest.statistics.MutationStatistics; import org.pitest.mutationtest.tooling.CombinedStatistics; +import java.io.File; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + public class PitMojoTest extends BasePitMojoTest { private PitMojo testee; @@ -44,7 +42,7 @@ public void testDoesNotAnalysePomProjects() throws Exception { verify(this.executionStrategy, never()).execute(any(File.class), any(ReportOptions.class), any(PluginServices.class)); } - + public void testDoesNotAnalyseProjectsWithSkipFlagSet() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("true")); this.testee.execute(); @@ -63,7 +61,7 @@ public void testThrowsMojoFailureExceptionWhenMutationScoreBelowThreshold() // pass } } - + public void testDoesNotThrowsMojoFailureExceptionWhenMutationScoreOnThreshold() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("21")); @@ -75,7 +73,7 @@ public void testDoesNotThrowsMojoFailureExceptionWhenMutationScoreOnThreshold() fail(); } } - + public void testThrowsMojoFailureExceptionWhenCoverageBelowThreshold() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("50")); @@ -87,7 +85,7 @@ public void testThrowsMojoFailureExceptionWhenCoverageBelowThreshold() // pass } } - + public void testDoesNotThrowMojoFailureExceptionWhenCoverageOnThreshold() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("50")); @@ -100,6 +98,16 @@ public void testDoesNotThrowMojoFailureExceptionWhenCoverageOnThreshold() } } + public void testConfigureEnvironmentVariable() + throws Exception { + this.testee = createPITMojo(createPomWithConfiguration("\n" + + " \n" + + " :20\n" + + " ")); + + assertEquals(System.getenv("DISPLAY"),":20"); + } + private void setupCoverage(long mutationScore, int lines, int linesCovered) throws MojoExecutionException { final MutationStatistics stats = Mockito.mock(MutationStatistics.class); when(stats.getPercentageDetected()).thenReturn(mutationScore); From 8c9379579f76f17fbe71af5e902bf8e44a27c320 Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 12:35:37 +0200 Subject: [PATCH 3/7] code cleanup: removed unnecessary final and this, less code means better readability --- .../java/org/pitest/process/JavaProcess.java | 109 +++++++++--------- .../org/pitest/process/JavaProcessTest.java | 14 +-- 2 files changed, 63 insertions(+), 60 deletions(-) diff --git a/pitest/src/main/java/org/pitest/process/JavaProcess.java b/pitest/src/main/java/org/pitest/process/JavaProcess.java index 2051dec46..edea41fe9 100644 --- a/pitest/src/main/java/org/pitest/process/JavaProcess.java +++ b/pitest/src/main/java/org/pitest/process/JavaProcess.java @@ -1,12 +1,12 @@ /* * Copyright 2010 Henry Coles - * + * * Licensed 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. @@ -14,7 +14,13 @@ */ package org.pitest.process; -import static org.pitest.functional.prelude.Prelude.or; +import org.pitest.functional.FCollection; +import org.pitest.functional.FunctionalList; +import org.pitest.functional.Option; +import org.pitest.functional.SideEffect1; +import org.pitest.functional.predicate.Predicate; +import org.pitest.util.Monitor; +import org.pitest.util.StreamMonitor; import java.io.File; import java.io.IOException; @@ -24,59 +30,55 @@ import java.util.List; import java.util.Map; -import org.pitest.functional.FCollection; -import org.pitest.functional.FunctionalList; -import org.pitest.functional.Option; -import org.pitest.functional.SideEffect1; -import org.pitest.functional.predicate.Predicate; -import org.pitest.util.Monitor; -import org.pitest.util.StreamMonitor; +import static org.pitest.functional.prelude.Prelude.or; public class JavaProcess { private final Process process; - private final Monitor out; private final Monitor err; - public JavaProcess(final Process process, - final SideEffect1 sysoutHandler, - final SideEffect1 syserrHandler) { + public JavaProcess( Process process, + SideEffect1 sysoutHandler, + SideEffect1 syserrHandler) { this.process = process; - this.out = new StreamMonitor(process.getInputStream(), sysoutHandler); - this.err = new StreamMonitor(process.getErrorStream(), syserrHandler); - this.out.requestStart(); - this.err.requestStart(); + + out = new StreamMonitor(process.getInputStream(), sysoutHandler); + err = new StreamMonitor(process.getErrorStream(), syserrHandler); + out.requestStart(); + err.requestStart(); } public void destroy() { - this.out.requestStop(); - this.err.requestStop(); - this.process.destroy(); + out.requestStop(); + err.requestStop(); + process.destroy(); } public int waitToDie() throws InterruptedException { - final int exitVal = this.process.waitFor(); - this.out.requestStop(); - this.err.requestStop(); + int exitVal = process.waitFor(); + out.requestStop(); + err.requestStop(); return exitVal; } public boolean isAlive() { try { - this.process.exitValue(); + process.exitValue(); return false; - } catch (final IllegalThreadStateException e) { + } catch (IllegalThreadStateException e) { return true; } } - private static List createLaunchArgs(final String javaProcess, - final JavaAgent agentJarLocator, final List args, - final Class mainClass, final List programArgs) { + private static List createLaunchArgs( String javaProcess, + JavaAgent agentJarLocator, + List args, + Class mainClass, + List programArgs) { - final List cmd = new ArrayList(); + List cmd = new ArrayList(); cmd.add(javaProcess); cmd.addAll(args); @@ -88,25 +90,24 @@ private static List createLaunchArgs(final String javaProcess, return cmd; } - private static void addPITJavaAgent(final JavaAgent agentJarLocator, - final List cmd) { - final Option jarLocation = agentJarLocator.getJarLocation(); - for (final String each : jarLocation) { + private static void addPITJavaAgent(JavaAgent agentJarLocator, List cmd) { + Option jarLocation = agentJarLocator.getJarLocation(); + for (String each : jarLocation) { cmd.add("-javaagent:" + each); } } - private static void addLaunchJavaAgents(final List cmd) { - final RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); + private static void addLaunchJavaAgents(List cmd) { + RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); @SuppressWarnings("unchecked") - final FunctionalList agents = FCollection.filter( + FunctionalList agents = FCollection.filter( rt.getInputArguments(), or(isJavaAgentParam(), isEnvironmentSetting())); cmd.addAll(agents); } private static Predicate isEnvironmentSetting() { return new Predicate() { - public Boolean apply(final String a) { + public Boolean apply(String a) { return a.startsWith("-D"); } }; @@ -121,27 +122,30 @@ public Boolean apply(final String a) { }; } - public static JavaProcess launch(final File workingDirectory, - final String javaProc, final SideEffect1 systemOutHandler, - final SideEffect1 sysErrHandler, final List args, - final Class mainClass, final List programArgs, - final JavaAgent javaAgent, final String initialClassPath) + public static JavaProcess launch(File workingDirectory, + String javaProc, + SideEffect1 systemOutHandler, + SideEffect1 sysErrHandler, + List args, + Class mainClass, + List programArgs, + JavaAgent javaAgent, + String initialClassPath) throws IOException { - final List cmd = createLaunchArgs(javaProc, javaAgent, args, + List cmd = createLaunchArgs(javaProc, javaAgent, args, mainClass, programArgs); - + // IBM jdk adds this, thereby breaking everything removeClassPathProperties(cmd); - - final ProcessBuilder processBuilder = new ProcessBuilder(cmd); + + ProcessBuilder processBuilder = new ProcessBuilder(cmd); processBuilder.directory(workingDirectory); - - final Map env = processBuilder.environment(); + + Map env = processBuilder.environment(); env.put("CLASSPATH", initialClassPath); - - final Process process = processBuilder.start(); + Process process = processBuilder.start(); return new JavaProcess(process, systemOutHandler, sysErrHandler); } @@ -150,7 +154,6 @@ private static void removeClassPathProperties(List cmd) { if (cmd.get(i).startsWith("-Djava.class.path")) { cmd.remove(i); } - } } diff --git a/pitest/src/test/java/org/pitest/process/JavaProcessTest.java b/pitest/src/test/java/org/pitest/process/JavaProcessTest.java index dccae8e13..98469b2c2 100644 --- a/pitest/src/test/java/org/pitest/process/JavaProcessTest.java +++ b/pitest/src/test/java/org/pitest/process/JavaProcessTest.java @@ -1,16 +1,16 @@ package org.pitest.process; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.Test; +import org.pitest.classpath.ClassPath; +import org.pitest.functional.SideEffect1; +import org.pitest.util.NullJavaAgent; import java.io.File; import java.io.IOException; import java.util.Collections; -import org.junit.Test; -import org.pitest.classpath.ClassPath; -import org.pitest.functional.SideEffect1; -import org.pitest.util.NullJavaAgent; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class JavaProcessTest { @@ -31,7 +31,7 @@ public static void main(final String[] args) { public void waitToDieShouldReturnProcessExitCode() throws IOException, InterruptedException { DefaultJavaExecutableLocator je = new DefaultJavaExecutableLocator(); - final JavaProcess jp = JavaProcess.launch( + JavaProcess jp = JavaProcess.launch( new File(System.getProperty("user.dir")), je.javaExecutable(), nullHandler(), nullHandler(), Collections. emptyList(), JavaProcessTest.class, Collections. emptyList(), NullJavaAgent.instance(), From 94f999a1dd5fd437bf50cf20fabd235353812bb8 Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 13:39:42 +0200 Subject: [PATCH 4/7] fixed PitMojo test --- .../src/test/java/org/pitest/maven/PitMojoTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java index 7f4b7a8a0..d16b8aad2 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -98,14 +98,14 @@ public void testDoesNotThrowMojoFailureExceptionWhenCoverageOnThreshold() } } - public void testConfigureEnvironmentVariable() - throws Exception { - this.testee = createPITMojo(createPomWithConfiguration("\n" + + public void testConfigureEnvironmentVariable() throws Exception { + + PitMojo mojo = createPITMojo(createPomWithConfiguration("\n" + " \n" + " :20\n" + " ")); - assertEquals(System.getenv("DISPLAY"),":20"); + assertEquals(mojo.getEnvironmentVariables().get("DISPLAY"),":20"); } private void setupCoverage(long mutationScore, int lines, int linesCovered) throws MojoExecutionException { From da0600f809619c4d90e30427a329ce698d1452a6 Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 13:41:32 +0200 Subject: [PATCH 5/7] refactored and cleanup of JavaProcess.java and WrappingProcess.java (just one step) --- .../java/org/pitest/process/JavaProcess.java | 102 -------------- .../org/pitest/process/WrappingProcess.java | 131 +++++++++++++++--- ...cessTest.java => WrappingProcessTest.java} | 114 ++++++++------- 3 files changed, 175 insertions(+), 172 deletions(-) rename pitest/src/test/java/org/pitest/process/{JavaProcessTest.java => WrappingProcessTest.java} (55%) diff --git a/pitest/src/main/java/org/pitest/process/JavaProcess.java b/pitest/src/main/java/org/pitest/process/JavaProcess.java index edea41fe9..5789c0b12 100644 --- a/pitest/src/main/java/org/pitest/process/JavaProcess.java +++ b/pitest/src/main/java/org/pitest/process/JavaProcess.java @@ -14,24 +14,10 @@ */ package org.pitest.process; -import org.pitest.functional.FCollection; -import org.pitest.functional.FunctionalList; -import org.pitest.functional.Option; import org.pitest.functional.SideEffect1; -import org.pitest.functional.predicate.Predicate; import org.pitest.util.Monitor; import org.pitest.util.StreamMonitor; -import java.io.File; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.lang.management.RuntimeMXBean; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import static org.pitest.functional.prelude.Prelude.or; - public class JavaProcess { private final Process process; @@ -45,9 +31,6 @@ public JavaProcess( Process process, out = new StreamMonitor(process.getInputStream(), sysoutHandler); err = new StreamMonitor(process.getErrorStream(), syserrHandler); - out.requestStart(); - err.requestStart(); - } public void destroy() { @@ -72,89 +55,4 @@ public boolean isAlive() { } } - private static List createLaunchArgs( String javaProcess, - JavaAgent agentJarLocator, - List args, - Class mainClass, - List programArgs) { - - List cmd = new ArrayList(); - cmd.add(javaProcess); - cmd.addAll(args); - - addPITJavaAgent(agentJarLocator, cmd); - addLaunchJavaAgents(cmd); - - cmd.add(mainClass.getName()); - cmd.addAll(programArgs); - return cmd; - } - - private static void addPITJavaAgent(JavaAgent agentJarLocator, List cmd) { - Option jarLocation = agentJarLocator.getJarLocation(); - for (String each : jarLocation) { - cmd.add("-javaagent:" + each); - } - } - - private static void addLaunchJavaAgents(List cmd) { - RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); - @SuppressWarnings("unchecked") - FunctionalList agents = FCollection.filter( - rt.getInputArguments(), or(isJavaAgentParam(), isEnvironmentSetting())); - cmd.addAll(agents); - } - - private static Predicate isEnvironmentSetting() { - return new Predicate() { - public Boolean apply(String a) { - return a.startsWith("-D"); - } - }; - } - - private static Predicate isJavaAgentParam() { - return new Predicate() { - public Boolean apply(final String a) { - return a.toLowerCase().startsWith("-javaagent"); - } - - }; - } - - public static JavaProcess launch(File workingDirectory, - String javaProc, - SideEffect1 systemOutHandler, - SideEffect1 sysErrHandler, - List args, - Class mainClass, - List programArgs, - JavaAgent javaAgent, - String initialClassPath) - throws IOException { - - List cmd = createLaunchArgs(javaProc, javaAgent, args, - mainClass, programArgs); - - // IBM jdk adds this, thereby breaking everything - removeClassPathProperties(cmd); - - ProcessBuilder processBuilder = new ProcessBuilder(cmd); - processBuilder.directory(workingDirectory); - - Map env = processBuilder.environment(); - env.put("CLASSPATH", initialClassPath); - - Process process = processBuilder.start(); - return new JavaProcess(process, systemOutHandler, sysErrHandler); - } - - private static void removeClassPathProperties(List cmd) { - for (int i = cmd.size() - 1; i >= 0; i--) { - if (cmd.get(i).startsWith("-Djava.class.path")) { - cmd.remove(i); - } - } - } - } diff --git a/pitest/src/main/java/org/pitest/process/WrappingProcess.java b/pitest/src/main/java/org/pitest/process/WrappingProcess.java index ba78acea0..c5e2b65bf 100644 --- a/pitest/src/main/java/org/pitest/process/WrappingProcess.java +++ b/pitest/src/main/java/org/pitest/process/WrappingProcess.java @@ -1,39 +1,134 @@ package org.pitest.process; +import org.pitest.functional.FCollection; +import org.pitest.functional.FunctionalList; +import org.pitest.functional.Option; +import org.pitest.functional.predicate.Predicate; + +import java.io.File; import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.Map; -public class WrappingProcess { +import static org.pitest.functional.prelude.Prelude.or; - private final int port; - private final ProcessArgs argsBuilder; - private final Class slaveClass; +public class WrappingProcess { - private JavaProcess process; + private final int port; + private final ProcessArgs processArgs; + private final Class slaveClass; + private JavaProcess process; - public WrappingProcess(final int port, final ProcessArgs args, - final Class slaveClass) { + public WrappingProcess(int port, ProcessArgs args, Class slaveClass) { this.port = port; - this.argsBuilder = args; + this.processArgs = args; this.slaveClass = slaveClass; } public void start() throws IOException { - final String[] args = { "" + this.port }; - this.process = JavaProcess.launch(this.argsBuilder.getWorkingDir(), - this.argsBuilder.getJavaExecutable(), this.argsBuilder.getStdout(), - this.argsBuilder.getStdErr(), this.argsBuilder.getJvmArgs(), - this.slaveClass, Arrays.asList(args), - this.argsBuilder.getJavaAgentFinder(), - this.argsBuilder.getLaunchClassPath()); + final String[] args = {"" + this.port}; + + ProcessBuilder processBuilder = createProcessBuilder( + processArgs.getJavaExecutable(), + processArgs.getJvmArgs(), + slaveClass, + Arrays.asList(args), + processArgs.getJavaAgentFinder()); + + configureProcessBuilder(processBuilder, + processArgs.getWorkingDir(), + processArgs.getLaunchClassPath()); + + Process process = processBuilder.start(); + this.process = new JavaProcess(process, + processArgs.getStdout(), + processArgs.getStdErr()); } - public int waitToDie() throws InterruptedException { - return this.process.waitToDie(); + private void configureProcessBuilder(ProcessBuilder processBuilder, + File workingDirectory, + String initialClassPath) { + processBuilder.directory(workingDirectory); + Map env = processBuilder.environment(); + env.put("CLASSPATH", initialClassPath); } public void destroy() { - this.process.destroy(); + process.destroy(); + } + + private static ProcessBuilder createProcessBuilder(String javaProc, List args, Class mainClass, List programArgs, JavaAgent javaAgent) { + List cmd = createLaunchArgs(javaProc, javaAgent, args, + mainClass, programArgs); + + // IBM jdk adds this, thereby breaking everything + removeClassPathProperties(cmd); + + return new ProcessBuilder(cmd); + } + + private static void removeClassPathProperties(List cmd) { + for (int i = cmd.size() - 1; i >= 0; i--) { + if (cmd.get(i).startsWith("-Djava.class.path")) { + cmd.remove(i); + } + } + } + + private static List createLaunchArgs(String javaProcess, + JavaAgent agentJarLocator, + List args, + Class mainClass, + List programArgs) { + + List cmd = new ArrayList(); + cmd.add(javaProcess); + cmd.addAll(args); + + addPITJavaAgent(agentJarLocator, cmd); + addLaunchJavaAgents(cmd); + + cmd.add(mainClass.getName()); + cmd.addAll(programArgs); + return cmd; } + private static void addPITJavaAgent(JavaAgent agentJarLocator, List cmd) { + Option jarLocation = agentJarLocator.getJarLocation(); + for (String each : jarLocation) { + cmd.add("-javaagent:" + each); + } + } + + private static void addLaunchJavaAgents(List cmd) { + RuntimeMXBean rt = ManagementFactory.getRuntimeMXBean(); + @SuppressWarnings("unchecked") + FunctionalList agents = FCollection.filter( + rt.getInputArguments(), or(isJavaAgentParam(), isEnvironmentSetting())); + cmd.addAll(agents); + } + + private static Predicate isEnvironmentSetting() { + return new Predicate() { + public Boolean apply(String a) { + return a.startsWith("-D"); + } + }; + } + + private static Predicate isJavaAgentParam() { + return new Predicate() { + public Boolean apply(String a) { + return a.toLowerCase().startsWith("-javaagent"); + } + }; + } + + public JavaProcess getProcess() { + return process; + } } diff --git a/pitest/src/test/java/org/pitest/process/JavaProcessTest.java b/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java similarity index 55% rename from pitest/src/test/java/org/pitest/process/JavaProcessTest.java rename to pitest/src/test/java/org/pitest/process/WrappingProcessTest.java index 98469b2c2..3901e8088 100644 --- a/pitest/src/test/java/org/pitest/process/JavaProcessTest.java +++ b/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java @@ -1,52 +1,62 @@ -package org.pitest.process; - -import org.junit.Test; -import org.pitest.classpath.ClassPath; -import org.pitest.functional.SideEffect1; -import org.pitest.util.NullJavaAgent; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -public class JavaProcessTest { - - private static final int EXIT_CODE = 10; - - public static void main(final String[] args) { - try { - System.out.println("Sleeping"); - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - System.out.println("Exiting"); - System.exit(EXIT_CODE); - } - - @Test - public void waitToDieShouldReturnProcessExitCode() throws IOException, - InterruptedException { - DefaultJavaExecutableLocator je = new DefaultJavaExecutableLocator(); - JavaProcess jp = JavaProcess.launch( - new File(System.getProperty("user.dir")), je.javaExecutable(), nullHandler(), nullHandler(), - Collections. emptyList(), JavaProcessTest.class, - Collections. emptyList(), NullJavaAgent.instance(), - new ClassPath().getLocalClassPath()); - assertTrue(jp.isAlive()); - assertEquals(EXIT_CODE, jp.waitToDie()); - } - - private SideEffect1 nullHandler() { - return new SideEffect1() { - public void apply(final String a) { - - } - - }; - } - -} +package org.pitest.process; + +import org.junit.Test; +import org.pitest.classpath.ClassPath; +import org.pitest.functional.SideEffect1; +import org.pitest.util.NullJavaAgent; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class WrappingProcessTest { + + private static final int EXIT_CODE = 10; + + public static void main(final String[] args) { + try { + System.out.println("Sleeping"); + Thread.sleep(100); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + System.out.println("Exiting"); + System.exit(EXIT_CODE); + } + + @Test + public void waitToDieShouldReturnProcessExitCode() throws IOException, + InterruptedException { + + LaunchOptions launchOptions = new LaunchOptions( + NullJavaAgent.instance(), + new DefaultJavaExecutableLocator(), + Collections.emptyList()); + + ProcessArgs processArgs = ProcessArgs.withClassPath(new ClassPath().getLocalClassPath()) + .andBaseDir(new File(System.getProperty("user.dir"))) + .andLaunchOptions(launchOptions) + .andStdout(nullHandler()) + .andStderr(nullHandler()); + + WrappingProcess wrappingProcess = new WrappingProcess(-1,processArgs,getClass()); + wrappingProcess.start(); + JavaProcess process = wrappingProcess.getProcess(); + + assertTrue(process.isAlive()); + assertEquals(EXIT_CODE, process.waitToDie()); + } + + private SideEffect1 nullHandler() { + return new SideEffect1() { + public void apply(final String a) { + + } + + }; + } + +} From 43651fd72a2df71578a6078c747e92060ea57d36 Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Mon, 11 May 2015 17:56:09 +0200 Subject: [PATCH 6/7] added propagation of environment variables to underlying java processes here is an example to pass Xvfb-Display to the pitest runs ``` org.apache.maven.plugins maven-jar-plugin default-jar never org.codehaus.mojo selenium-maven-plugin 2.3 start pre-integration-test xvfb true :${xvfb.display} org.pitest pitest-maven 1.1.6-SNAPSHOT :${xvfb.display} ... integration-test mutationCoverage ``` --- .../commandline/MutationCoverageReport.java | 18 +++++---- .../java/org/pitest/maven/GoalStrategy.java | 11 ++++-- .../main/java/org/pitest/maven/PitMojo.java | 2 +- .../java/org/pitest/maven/RunPitStrategy.java | 18 +++++---- .../main/java/org/pitest/maven/ScmMojo.java | 37 +++++++++--------- .../java/org/pitest/maven/PitMojoTest.java | 9 +++-- .../java/org/pitest/maven/ScmMojoTest.java | 28 +++++++------ .../mutationtest/tooling/EntryPoint.java | 38 ++++++++++-------- .../org/pitest/process/LaunchOptions.java | 39 +++++++++++-------- .../java/org/pitest/process/ProcessArgs.java | 22 +++++++---- .../org/pitest/process/WrappingProcess.java | 14 +++++-- .../pitest/mutationtest/ReportTestBase.java | 18 ++++----- .../mutationtest/TestMutationTesting.java | 39 ++++++------------- .../pitest/process/WrappingProcessTest.java | 4 +- 14 files changed, 155 insertions(+), 142 deletions(-) diff --git a/pitest-command-line/src/main/java/org/pitest/mutationtest/commandline/MutationCoverageReport.java b/pitest-command-line/src/main/java/org/pitest/mutationtest/commandline/MutationCoverageReport.java index 67b7c24e4..db238cbe2 100644 --- a/pitest-command-line/src/main/java/org/pitest/mutationtest/commandline/MutationCoverageReport.java +++ b/pitest-command-line/src/main/java/org/pitest/mutationtest/commandline/MutationCoverageReport.java @@ -1,12 +1,12 @@ /* * Copyright 2010 Henry Coles - * + * * Licensed 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. @@ -23,6 +23,8 @@ import org.pitest.mutationtest.tooling.EntryPoint; import org.pitest.util.Unchecked; +import java.util.HashMap; + /** * Entry point for command line interface */ @@ -39,9 +41,9 @@ public static void main(final String[] args) { System.out.println(">>>> " + pr.getErrorMessage().value()); } else { final ReportOptions data = pr.getOptions(); - + final CombinedStatistics stats = runReport(data, plugins); - + throwErrorIfScoreBelowCoverageThreshold(stats.getCoverageSummary(), data.getCoverageThreshold()); throwErrorIfScoreBelowMutationThreshold(stats.getMutationStatistics(), data.getMutationThreshold()); } @@ -66,10 +68,10 @@ private static void throwErrorIfScoreBelowMutationThreshold( } } - private static CombinedStatistics runReport(final ReportOptions data, PluginServices plugins) { + private static CombinedStatistics runReport(ReportOptions data, PluginServices plugins) { - final EntryPoint e = new EntryPoint(); - final AnalysisResult result = e.execute(null, data, plugins); + EntryPoint e = new EntryPoint(); + AnalysisResult result = e.execute(null, data, plugins,new HashMap()); if (result.getError().hasSome()) { throw Unchecked.translateCheckedException(result.getError().value()); } diff --git a/pitest-maven/src/main/java/org/pitest/maven/GoalStrategy.java b/pitest-maven/src/main/java/org/pitest/maven/GoalStrategy.java index 8f1b637c0..250403a3a 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/GoalStrategy.java +++ b/pitest-maven/src/main/java/org/pitest/maven/GoalStrategy.java @@ -14,15 +14,18 @@ */ package org.pitest.maven; -import java.io.File; - import org.apache.maven.plugin.MojoExecutionException; import org.pitest.mutationtest.config.PluginServices; import org.pitest.mutationtest.config.ReportOptions; import org.pitest.mutationtest.tooling.CombinedStatistics; +import java.io.File; +import java.util.Map; + public interface GoalStrategy { - CombinedStatistics execute(File baseDir, ReportOptions options, - PluginServices plugins) throws MojoExecutionException; + CombinedStatistics execute(File baseDir, + ReportOptions options, + PluginServices plugins, + Map environmentVariables) throws MojoExecutionException; } diff --git a/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java b/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java index c96916656..a3b9bae92 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java +++ b/pitest-maven/src/main/java/org/pitest/maven/PitMojo.java @@ -415,7 +415,7 @@ protected Option analyse() throws MojoExecutionException { final ReportOptions data = new MojoToReportOptionsConverter(this, new SurefireConfigConverter(), this.filter).convert(); return Option.some(this.goalStrategy.execute(detectBaseDir(), data, - this.plugins)); + this.plugins,this.environmentVariables)); } protected File detectBaseDir() { diff --git a/pitest-maven/src/main/java/org/pitest/maven/RunPitStrategy.java b/pitest-maven/src/main/java/org/pitest/maven/RunPitStrategy.java index f19121c4a..4c55a809f 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/RunPitStrategy.java +++ b/pitest-maven/src/main/java/org/pitest/maven/RunPitStrategy.java @@ -1,12 +1,12 @@ /* * Copyright 2011 Henry Coles - * + * * Licensed 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. @@ -14,8 +14,6 @@ */ package org.pitest.maven; -import java.io.File; - import org.apache.maven.plugin.MojoExecutionException; import org.pitest.mutationtest.config.PluginServices; import org.pitest.mutationtest.config.ReportOptions; @@ -23,13 +21,19 @@ import org.pitest.mutationtest.tooling.CombinedStatistics; import org.pitest.mutationtest.tooling.EntryPoint; +import java.io.File; +import java.util.Map; + public class RunPitStrategy implements GoalStrategy { - public CombinedStatistics execute(final File baseDir, final ReportOptions data, PluginServices plugins) + public CombinedStatistics execute(File baseDir, + ReportOptions data, + PluginServices plugins, + Map environmentVariables) throws MojoExecutionException { EntryPoint e = new EntryPoint(); - AnalysisResult result = e.execute(baseDir, data, plugins); + AnalysisResult result = e.execute(baseDir, data, plugins,environmentVariables); if ( result.getError().hasSome() ) { throw new MojoExecutionException("fail", result.getError().value()); } diff --git a/pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java b/pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java index ba09b31e3..a33c68dcd 100644 --- a/pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java +++ b/pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java @@ -1,13 +1,5 @@ package org.pitest.maven; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.scm.ScmException; @@ -26,15 +18,24 @@ import org.pitest.mutationtest.config.ReportOptions; import org.pitest.mutationtest.tooling.CombinedStatistics; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + /** * Goal which runs a coverage mutation report only for files that have been * modified or introduced locally based on the source control configured in * maven. - * + * * @goal scmMutationCoverage - * + * * @requiresDependencyResolution test - * + * * @phase integration-test */ public class ScmMojo extends PitMojo { @@ -47,9 +48,9 @@ public class ScmMojo extends PitMojo { /** * List of scm status to include. Names match those defined by the maven scm * plugin. - * + * * Common values include ADDED,MODIFIED (the defaults) & UNKNOWN. - * + * * @parameter expression="${include}" */ private HashSet include; @@ -57,14 +58,14 @@ public class ScmMojo extends PitMojo { /** * Connection type to use when querying scm for changed files. Can either be * "connection" or "developerConnection". - * + * * @parameter default-value="connection" expression="${connectionType}" */ private String connectionType; /** * Project basedir - * + * * @parameter expression="${basedir}" * @required */ @@ -73,7 +74,7 @@ public class ScmMojo extends PitMojo { /** * Base of scm root. For a multi module project this is probably the parent * project. - * + * * @parameter expression="${project.parent.basedir}" */ private File scmRootDir; @@ -104,7 +105,7 @@ protected Option analyse() throws MojoExecutionException { final ReportOptions data = new MojoToReportOptionsConverter(this, new SurefireConfigConverter(),filter).convert(); data.setFailWhenNoMutations(false); - return Option.some(this.goalStrategy.execute(detectBaseDir(), data, plugins)); + return Option.some(this.goalStrategy.execute(detectBaseDir(), data, plugins,new HashMap())); } @@ -210,7 +211,7 @@ public void setConnectionType(final String connectionType) { public void setScmRootDir(final File scmRootDir) { this.scmRootDir = scmRootDir; } - + /** * A bug in maven 2 requires that all list fields * declare a concrete list type diff --git a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java index d16b8aad2..986c98b71 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -11,6 +11,7 @@ import org.pitest.mutationtest.tooling.CombinedStatistics; import java.io.File; +import java.util.HashMap; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -32,7 +33,7 @@ public void testRunsAMutationReportWhenMutationCoverageGoalTrigered() this.testee.getProject().setBuild(build); this.testee.execute(); verify(this.executionStrategy).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),new HashMap()); } public void testDoesNotAnalysePomProjects() throws Exception { @@ -40,14 +41,14 @@ public void testDoesNotAnalysePomProjects() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("")); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),new HashMap()); } public void testDoesNotAnalyseProjectsWithSkipFlagSet() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("true")); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),new HashMap()); } public void testThrowsMojoFailureExceptionWhenMutationScoreBelowThreshold() @@ -115,7 +116,7 @@ private void setupCoverage(long mutationScore, int lines, int linesCovered) thro final CombinedStatistics cs = new CombinedStatistics(stats,sum); when( this.executionStrategy.execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class))).thenReturn(cs); + any(ReportOptions.class), any(PluginServices.class),new HashMap())).thenReturn(cs); } } diff --git a/pitest-maven/src/test/java/org/pitest/maven/ScmMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/ScmMojoTest.java index a7e77d18d..84ac6f0c0 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/ScmMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/ScmMojoTest.java @@ -1,15 +1,5 @@ package org.pitest.maven; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.File; -import java.util.Arrays; -import java.util.Collections; - import org.apache.maven.model.Build; import org.apache.maven.model.Scm; import org.apache.maven.plugin.MojoExecutionException; @@ -24,6 +14,14 @@ import org.pitest.mutationtest.config.PluginServices; import org.pitest.mutationtest.config.ReportOptions; +import java.io.File; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + public class ScmMojoTest extends BasePitMojoTest { private ScmMojo testee; @@ -91,7 +89,7 @@ public void testClassesAddedToScmAreMutationTested() throws Exception { setFileWithStatus(ScmFileStatus.ADDED); this.testee.execute(); verify(this.executionStrategy).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } private void setFileWithStatus(final ScmFileStatus status) @@ -107,7 +105,7 @@ public void testModifiedClassesAreMutationTested() throws Exception { setFileWithStatus(ScmFileStatus.MODIFIED); this.testee.execute(); verify(this.executionStrategy).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testUnknownAndDeletedClassesAreNotMutationTested() @@ -120,7 +118,7 @@ public void testUnknownAndDeletedClassesAreNotMutationTested() "foo/bar/Bar.java", ScmFileStatus.UNKNOWN)))); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testCanOverrideInspectedStatus() throws Exception { @@ -131,7 +129,7 @@ public void testCanOverrideInspectedStatus() throws Exception { createPomWithConfiguration("DELETEDUNKNOWN")); this.testee.execute(); verify(this.executionStrategy, times(1)).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testDoesNotAnalysePomProjects() throws Exception { @@ -140,7 +138,7 @@ public void testDoesNotAnalysePomProjects() throws Exception { when(this.project.getPackaging()).thenReturn("pom"); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class)); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } private void setupConnection() { diff --git a/pitest/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java b/pitest/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java index 94e112857..b35bc42e1 100644 --- a/pitest/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java +++ b/pitest/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java @@ -1,9 +1,5 @@ package org.pitest.mutationtest.tooling; -import java.io.File; -import java.io.IOException; -import java.io.Reader; - import org.pitest.classpath.ClassPath; import org.pitest.classpath.ClassPathByteArraySource; import org.pitest.classpath.CodeSource; @@ -24,28 +20,35 @@ import org.pitest.util.ResultOutputStrategy; import org.pitest.util.Timings; +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.util.Map; + public class EntryPoint { /** * Convenient entry point for tools to run mutation analysis. - * + * * The big grab bag of config stored in ReportOptions must be setup correctly * first. - * - * @param baseDir + * @param baseDir * directory from which analysis will be run * @param data - * big mess of configuration options - * + * @param environmentVariables + * */ - public AnalysisResult execute(final File baseDir, final ReportOptions data, final PluginServices plugins) { - final SettingsFactory settings = new SettingsFactory(data, plugins); - return execute(baseDir, data, settings); + public AnalysisResult execute(File baseDir, + ReportOptions data, + PluginServices plugins, + Map environmentVariables) { + SettingsFactory settings = new SettingsFactory(data, plugins); + return execute(baseDir, data, settings,environmentVariables); } /** * Entry point for tools with tool specific behaviour - * + * * @param baseDir * directory from which analysis will be run * @param data @@ -54,8 +57,10 @@ public AnalysisResult execute(final File baseDir, final ReportOptions data, fina * factory for various strategies. Override default to provide tool * specific behaviours */ - public AnalysisResult execute(final File baseDir, final ReportOptions data, - final SettingsFactory settings) { + public AnalysisResult execute(File baseDir, + ReportOptions data, + SettingsFactory settings, + Map environmentVariables) { final ClassPath cp = data.getClassPath(); @@ -76,8 +81,7 @@ public AnalysisResult execute(final File baseDir, final ReportOptions data, .createListener(); final CoverageOptions coverageOptions = settings.createCoverageOptions(); - final LaunchOptions launchOptions = new LaunchOptions(ja, - settings.getJavaExecutable(), data.getJvmArgs()); + final LaunchOptions launchOptions = new LaunchOptions(ja,settings.getJavaExecutable(), data.getJvmArgs(),environmentVariables); final ProjectClassPaths cps = data.getMutationClassPaths(); final CodeSource code = new CodeSource(cps, coverageOptions.getPitConfig() diff --git a/pitest/src/main/java/org/pitest/process/LaunchOptions.java b/pitest/src/main/java/org/pitest/process/LaunchOptions.java index 732ced6da..bedc622ee 100644 --- a/pitest/src/main/java/org/pitest/process/LaunchOptions.java +++ b/pitest/src/main/java/org/pitest/process/LaunchOptions.java @@ -1,39 +1,43 @@ /* * Copyright 2011 Henry Coles - * - * Licensed 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. + * + * Licensed 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. */ package org.pitest.process; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class LaunchOptions { private final JavaAgent javaAgentFinder; private final List childJVMArgs; private final JavaExecutableLocator javaExecutable; + private final Map environmentVariables; - public LaunchOptions(final JavaAgent javaAgentFinder) { + public LaunchOptions(JavaAgent javaAgentFinder) { this(javaAgentFinder, new DefaultJavaExecutableLocator(), Collections - . emptyList()); + . emptyList(),new HashMap()); } - public LaunchOptions(final JavaAgent javaAgentFinder, - final JavaExecutableLocator javaExecutable, - final List childJVMArgs) { + public LaunchOptions( JavaAgent javaAgentFinder, + JavaExecutableLocator javaExecutable, + List childJVMArgs,Map environmentVariables) { this.javaAgentFinder = javaAgentFinder; this.childJVMArgs = childJVMArgs; this.javaExecutable = javaExecutable; + this.environmentVariables = environmentVariables; } public JavaAgent getJavaAgentFinder() { @@ -48,4 +52,7 @@ public String getJavaExecutable() { return this.javaExecutable.javaExecutable(); } + public Map getEnvironmentVariables() { + return environmentVariables; + } } diff --git a/pitest/src/main/java/org/pitest/process/ProcessArgs.java b/pitest/src/main/java/org/pitest/process/ProcessArgs.java index 5ed267365..a1541b5dd 100644 --- a/pitest/src/main/java/org/pitest/process/ProcessArgs.java +++ b/pitest/src/main/java/org/pitest/process/ProcessArgs.java @@ -1,12 +1,12 @@ /* * Copyright 2011 Henry Coles - * + * * Licensed 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. @@ -14,15 +14,16 @@ */ package org.pitest.process; -import static org.pitest.functional.prelude.Prelude.print; -import static org.pitest.functional.prelude.Prelude.printTo; +import org.pitest.classpath.ClassPath; +import org.pitest.functional.SideEffect1; import java.io.File; import java.util.Collections; import java.util.List; +import java.util.Map; -import org.pitest.classpath.ClassPath; -import org.pitest.functional.SideEffect1; +import static org.pitest.functional.prelude.Prelude.print; +import static org.pitest.functional.prelude.Prelude.printTo; public final class ProcessArgs { @@ -33,6 +34,7 @@ public final class ProcessArgs { private JavaAgent javaAgentFinder; private File workingDir = null; private String javaExecutable; + private Map environmentVariables; private ProcessArgs(final String launchClassPath) { this.launchClassPath = launchClassPath; @@ -105,7 +107,11 @@ public ProcessArgs andLaunchOptions(final LaunchOptions launchOptions) { this.jvmArgs = launchOptions.getChildJVMArgs(); this.javaAgentFinder = launchOptions.getJavaAgentFinder(); this.javaExecutable = launchOptions.getJavaExecutable(); + this.environmentVariables = launchOptions.getEnvironmentVariables(); return this; } -}; + public Map getEnvironmentVariables() { + return environmentVariables; + } +} diff --git a/pitest/src/main/java/org/pitest/process/WrappingProcess.java b/pitest/src/main/java/org/pitest/process/WrappingProcess.java index c5e2b65bf..4baa08f57 100644 --- a/pitest/src/main/java/org/pitest/process/WrappingProcess.java +++ b/pitest/src/main/java/org/pitest/process/WrappingProcess.java @@ -21,6 +21,7 @@ public class WrappingProcess { private final int port; private final ProcessArgs processArgs; private final Class slaveClass; + private JavaProcess process; public WrappingProcess(int port, ProcessArgs args, Class slaveClass) { @@ -41,7 +42,8 @@ public void start() throws IOException { configureProcessBuilder(processBuilder, processArgs.getWorkingDir(), - processArgs.getLaunchClassPath()); + processArgs.getLaunchClassPath(), + processArgs.getEnvironmentVariables()); Process process = processBuilder.start(); this.process = new JavaProcess(process, @@ -51,10 +53,14 @@ public void start() throws IOException { private void configureProcessBuilder(ProcessBuilder processBuilder, File workingDirectory, - String initialClassPath) { + String initialClassPath, Map environmentVariables) { processBuilder.directory(workingDirectory); - Map env = processBuilder.environment(); - env.put("CLASSPATH", initialClassPath); + Map environment = processBuilder.environment(); + environment.put("CLASSPATH", initialClassPath); + + for (Map.Entry entry:environmentVariables.entrySet()) { + environment.put(entry.getKey(), entry.getValue()); + } } public void destroy() { diff --git a/pitest/src/test/java/org/pitest/mutationtest/ReportTestBase.java b/pitest/src/test/java/org/pitest/mutationtest/ReportTestBase.java index 280ea5466..a0915a572 100644 --- a/pitest/src/test/java/org/pitest/mutationtest/ReportTestBase.java +++ b/pitest/src/test/java/org/pitest/mutationtest/ReportTestBase.java @@ -1,15 +1,5 @@ package org.pitest.mutationtest; -import static org.junit.Assert.assertEquals; - -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - import org.junit.Before; import org.pitest.classpath.ClassPathRoot; import org.pitest.classpath.CodeSource; @@ -39,6 +29,12 @@ import org.pitest.util.Timings; import org.pitest.util.Unchecked; +import java.io.File; +import java.io.IOException; +import java.util.*; + +import static org.junit.Assert.assertEquals; + public abstract class ReportTestBase { protected MetaDataExtractor metaDataExtractor; @@ -101,7 +97,7 @@ protected void createAndRun(final Configuration configuration) { final CoverageOptions coverageOptions = createCoverageOptions(configuration); final LaunchOptions launchOptions = new LaunchOptions(agent, - new DefaultJavaExecutableLocator(), this.data.getJvmArgs()); + new DefaultJavaExecutableLocator(), this.data.getJvmArgs(),new HashMap()); final PathFilter pf = new PathFilter(new True(), new True()); diff --git a/pitest/src/test/java/org/pitest/mutationtest/TestMutationTesting.java b/pitest/src/test/java/org/pitest/mutationtest/TestMutationTesting.java index 96dfccd26..30dfb8705 100644 --- a/pitest/src/test/java/org/pitest/mutationtest/TestMutationTesting.java +++ b/pitest/src/test/java/org/pitest/mutationtest/TestMutationTesting.java @@ -1,12 +1,12 @@ /* * Copyright 2010 Henry Coles - * + * * Licensed 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. @@ -14,21 +14,8 @@ */ package org.pitest.mutationtest; -import static org.junit.Assert.assertEquals; -import static org.pitest.mutationtest.DetectionStatus.KILLED; -import static org.pitest.mutationtest.DetectionStatus.MEMORY_ERROR; -import static org.pitest.mutationtest.DetectionStatus.NON_VIABLE; -import static org.pitest.mutationtest.DetectionStatus.NO_COVERAGE; -import static org.pitest.mutationtest.DetectionStatus.SURVIVED; -import static org.pitest.mutationtest.DetectionStatus.TIMED_OUT; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - +import com.example.MutationsInNestedClasses; +import com.example.MutationsInNestedClassesTest; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -50,13 +37,7 @@ import org.pitest.functional.predicate.False; import org.pitest.functional.predicate.Predicate; import org.pitest.functional.prelude.Prelude; -import org.pitest.mutationtest.build.DefaultGrouper; -import org.pitest.mutationtest.build.DefaultTestPrioritiser; -import org.pitest.mutationtest.build.MutationAnalysisUnit; -import org.pitest.mutationtest.build.MutationSource; -import org.pitest.mutationtest.build.MutationTestBuilder; -import org.pitest.mutationtest.build.PercentAndConstantTimeoutStrategy; -import org.pitest.mutationtest.build.WorkerFactory; +import org.pitest.mutationtest.build.*; import org.pitest.mutationtest.config.DefaultDependencyPathPredicate; import org.pitest.mutationtest.config.ReportOptions; import org.pitest.mutationtest.engine.MutationEngine; @@ -76,8 +57,10 @@ import org.pitest.util.IsolationUtils; import org.pitest.util.Timings; -import com.example.MutationsInNestedClasses; -import com.example.MutationsInNestedClassesTest; +import java.util.*; + +import static org.junit.Assert.assertEquals; +import static org.pitest.mutationtest.DetectionStatus.*; @Category(SystemTest.class) public class TestMutationTesting { @@ -340,7 +323,7 @@ private void createEngineAndRun(final ReportOptions data, final CoverageOptions coverageOptions = createCoverageOptions(data); final LaunchOptions launchOptions = new LaunchOptions(agent, - new DefaultJavaExecutableLocator(), data.getJvmArgs()); + new DefaultJavaExecutableLocator(), data.getJvmArgs(),new HashMap()); final PathFilter pf = new PathFilter( Prelude.not(new DefaultDependencyPathPredicate()), diff --git a/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java b/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java index 3901e8088..87238bb87 100644 --- a/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java +++ b/pitest/src/test/java/org/pitest/process/WrappingProcessTest.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -34,7 +35,8 @@ public void waitToDieShouldReturnProcessExitCode() throws IOException, LaunchOptions launchOptions = new LaunchOptions( NullJavaAgent.instance(), new DefaultJavaExecutableLocator(), - Collections.emptyList()); + Collections.emptyList(), + new HashMap()); ProcessArgs processArgs = ProcessArgs.withClassPath(new ClassPath().getLocalClassPath()) .andBaseDir(new File(System.getProperty("user.dir"))) From 2c0524034473686b04244d7f797301700e70ecaa Mon Sep 17 00:00:00 2001 From: "Lars K.W. Gohlke" Date: Tue, 12 May 2015 13:34:05 +0200 Subject: [PATCH 7/7] fixed PitMojoTest --- .../src/test/java/org/pitest/maven/PitMojoTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java index 986c98b71..7abcc0b8d 100644 --- a/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java +++ b/pitest-maven/src/test/java/org/pitest/maven/PitMojoTest.java @@ -11,7 +11,7 @@ import org.pitest.mutationtest.tooling.CombinedStatistics; import java.io.File; -import java.util.HashMap; +import java.util.Map; import static org.mockito.Matchers.any; import static org.mockito.Mockito.*; @@ -33,7 +33,7 @@ public void testRunsAMutationReportWhenMutationCoverageGoalTrigered() this.testee.getProject().setBuild(build); this.testee.execute(); verify(this.executionStrategy).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class),new HashMap()); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testDoesNotAnalysePomProjects() throws Exception { @@ -41,14 +41,14 @@ public void testDoesNotAnalysePomProjects() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("")); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class),new HashMap()); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testDoesNotAnalyseProjectsWithSkipFlagSet() throws Exception { this.testee = createPITMojo(createPomWithConfiguration("true")); this.testee.execute(); verify(this.executionStrategy, never()).execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class),new HashMap()); + any(ReportOptions.class), any(PluginServices.class),any(Map.class)); } public void testThrowsMojoFailureExceptionWhenMutationScoreBelowThreshold() @@ -116,7 +116,7 @@ private void setupCoverage(long mutationScore, int lines, int linesCovered) thro final CombinedStatistics cs = new CombinedStatistics(stats,sum); when( this.executionStrategy.execute(any(File.class), - any(ReportOptions.class), any(PluginServices.class),new HashMap())).thenReturn(cs); + any(ReportOptions.class), any(PluginServices.class),any(Map.class))).thenReturn(cs); } }