Skip to content

Commit

Permalink
devonfw#1518 Added Jacoco check On Cli and Maven projects
Browse files Browse the repository at this point in the history
  • Loading branch information
MansourD committed Oct 19, 2022
1 parent 5e1c199 commit 3a8482d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.util.stream.Stream;

import org.apache.commons.io.FileUtils;
import java.util.Arrays;

import org.apache.commons.lang3.StringUtils;
import org.codehaus.plexus.archiver.tar.TarGZipUnArchiver;
import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
Expand All @@ -24,6 +22,7 @@
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.zeroturnaround.exec.ProcessExecutor;
import org.zeroturnaround.exec.ProcessResult;
Expand All @@ -37,6 +36,9 @@
/** Common test implementation for CLI tests */
public class AbstractCliTest {

/** Logger instance. */
private static final Logger LOG = LoggerFactory.getLogger(AbstractCliTest.class);

/** Java tool options */
private static final String JAVA_TOOL_OPTIONS = "CGCLI_JAVA_OPTIONS";

Expand Down Expand Up @@ -237,11 +239,16 @@ protected void execute(String[] args, boolean useDevTemplates, boolean assureFai
.redirectOutput(Slf4jStream.of(LoggerFactory.getLogger(getClass().getName() + ".cliprocess")).asInfo());

// enable jacoco coverage monitoring for external processes (especially for CI/CD)
if (!StringUtils.isEmpty(MavenMetadata.JACOCO_AGENT_ARGS)) {
if (!StringUtils.isEmpty(MavenMetadata.JACOCO_AGENT_ARGS)
&& !StringUtils.startsWith(MavenMetadata.JACOCO_AGENT_ARGS, "$")) {
System.out.println(System.getenv(JAVA_TOOL_OPTIONS));
pe.environment(JAVA_TOOL_OPTIONS, MavenMetadata.JACOCO_AGENT_ARGS

// .replaceFirst("destfile=[^,]+(,)?", "")
// + ",output=tcpclient,sessionid=test,inclnolocationclasses=true,inclbootstrapclasses=true "
+ "" + (System.getenv(JAVA_TOOL_OPTIONS) == null ? "" : " " + System.getenv(JAVA_TOOL_OPTIONS)));
} else {
LOG.warn("No value for JACOCO is set!");
}

new SystemExit().execute(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.shared.invoker.DefaultInvocationRequest;
import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest;
Expand Down Expand Up @@ -138,9 +139,14 @@ protected File runMavenInvoker(File testProject, File templatesProject, String l
request.setUserSettingsFile(this.mvnSettingsFile);
request.setBatchMode(true);
// https://stackoverflow.com/a/66801171
request.setMavenOpts(
"-Xmx4096m -Djansi.force=true -Djansi.passthrough=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn "
+ MavenMetadata.JACOCO_AGENT_ARGS);
if (!StringUtils.startsWith(MavenMetadata.JACOCO_AGENT_ARGS, "$")) {
request.setMavenOpts(
"-Xmx4096m -Djansi.force=true -Djansi.passthrough=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn "
+ MavenMetadata.JACOCO_AGENT_ARGS);
} else {
request.setMavenOpts(
"-Xmx4096m -Djansi.force=true -Djansi.passthrough=true -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn");
}

Invoker invoker = new DefaultInvoker();
LOG.info("Executing maven invoker for unit test ...");
Expand Down

0 comments on commit 3a8482d

Please sign in to comment.