Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate environment variables to surefire run #197

Merged
merged 7 commits into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
*/
Expand All @@ -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());
}
Expand All @@ -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<String, String>());
if (result.getError().hasSome()) {
throw Unchecked.translateCheckedException(result.getError().value());
}
Expand Down
11 changes: 7 additions & 4 deletions pitest-maven/src/main/java/org/pitest/maven/GoalStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String,String> environmentVariables) throws MojoExecutionException;
}
42 changes: 27 additions & 15 deletions pitest-maven/src/main/java/org/pitest/maven/PitMojo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
*
Expand Down Expand Up @@ -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<String, String> configuration;

/**
* environment configuration
*
* Value pairs may be used by pitest plugins.
*
* @parameter
*/
private Map<String, String> environmentVariables = new HashMap<String, String>();


/**
* <i>Internal</i>: Project to interact with.
Expand All @@ -326,7 +335,7 @@ public class PitMojo extends AbstractMojo {
* @readonly
*/
private Map<String, Artifact> pluginArtifactMap;

protected final GoalStrategy goalStrategy;

public PitMojo() {
Expand Down Expand Up @@ -406,7 +415,7 @@ protected Option<CombinedStatistics> 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() {
Expand Down Expand Up @@ -559,9 +568,12 @@ public List<String> getClasspathDependencyExcludes() {
public boolean isParseSurefireConfig() {
return this.parseSurefireConfig;
}

public Map<String, String> getPluginProperties() {
return configuration;
}

public Map<String, String> getEnvironmentVariables() {
return environmentVariables;
}
}
18 changes: 11 additions & 7 deletions pitest-maven/src/main/java/org/pitest/maven/RunPitStrategy.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
/*
* 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.
*/
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.AnalysisResult;
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<String,String> 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());
}
Expand Down
37 changes: 19 additions & 18 deletions pitest-maven/src/main/java/org/pitest/maven/ScmMojo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand All @@ -47,24 +48,24 @@ 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<String> include;

/**
* 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
*/
Expand All @@ -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;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected Option<CombinedStatistics> 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<String, String>()));

}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
*/
Expand Down Expand Up @@ -44,7 +44,7 @@ private List<String> extractStrings(String element, Xpp3Dom configuration) {
String[] parts = groups.getValue().split(" ");
return Arrays.asList(parts);
} else {
return Collections.<String> emptyList();
return Collections.emptyList();
}
}

Expand Down Expand Up @@ -74,7 +74,7 @@ private List<String> extract(String childname, Xpp3Dom config) {
return result;
}

return Collections.<String> emptyList();
return Collections.emptyList();
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,8 +16,8 @@

public enum ReportGenerationResultEnum {

SUCCESS,
FAILURE,
NOT_EXECUTED;
SUCCESS,
FAILURE,
NOT_EXECUTED

}
Loading