Skip to content

Commit

Permalink
Save System.out and print other information
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Mar 6, 2024
1 parent 5952021 commit 83ecc70
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.List;
import java.util.regex.Pattern;

Expand All @@ -32,10 +33,17 @@ public class XtextGeneratorIT {

private final static boolean debug = Boolean.getBoolean("xtext.it.tests.debug");
private final static boolean fork = !debug;

private static String ROOT = "/it/generate";
private static File testDir;

/**
* As soon as a {@link Verifier} object is created System.out and System.err are
* captured by the verifier; we save the original System.out here so that we can
* print information to the console later.
*/
private static PrintStream systemOut;

/**
* This is the local Maven repository (typically ~/.m2/repository) that we
* will pass to the parent POM of IT projects through the property "local-central".
Expand All @@ -47,20 +55,24 @@ public class XtextGeneratorIT {

@BeforeClass
static public void setUpOnce() throws IOException, VerificationException {
systemOut = System.out;
testDir = extractTestRoot();
if (fork) {
System.out.println("maven.home=" + System.getProperty("maven.home"));
systemOut.println("Current maven.home=" + System.getProperty("maven.home"));
File mvnExecutable = new File(new Verifier(testDir.getAbsolutePath()).getExecutable());
if (!mvnExecutable.exists()) {
String mavenHome = findMaven();
if (mavenHome != null) {
System.setProperty("maven.home", mavenHome);
systemOut.println("Detected maven.home=" + System.getProperty("maven.home"));
} else {
Assert.fail("Maven home not found. Tried to call '" + mvnExecutable
+ "'.\nConsider to set the envVar 'M2_HOME' or System property 'maven.home'.\n"
+ "Current settings are: maven.home=" + System.getProperty("maven.home") + " M2_HOME="
+ CommandLineUtils.getSystemEnvVars().getProperty("M2_HOME"));
}
} else {
systemOut.println("Maven executable: " + mvnExecutable);
}
}
verifyErrorFreeLog("" /*root*/, false, "clean", "install");
Expand All @@ -79,8 +91,8 @@ private static File extractTestRoot() throws IOException {
String localCentralRepository = System.getProperty("maven.repo.local",
System.getProperty("user.home") + "/.m2/repository");
localRepoDir = new File( localCentralRepository );
System.out.println("IT projects will be executed from " + testDir);
System.out.println("Local Maven Central Repository " + localRepoDir);
systemOut.println("IT projects will be executed from " + testDir);
systemOut.println("Local Maven Central Repository " + localRepoDir);
testDir = ResourceExtractor.extractResourcePath(XtextGeneratorIT.class, ROOT, tempDir, true);
return testDir;
}
Expand Down Expand Up @@ -280,7 +292,7 @@ private static Verifier verifyErrorFreeLog(String pathToTestProject, boolean upd
verifier.verifyErrorFreeLog();
if (debug) {
List<String> lines = verifier.loadFile(verifier.getBasedir(), verifier.getLogFileName(), false);
System.out.println(Joiner.on('\n').join(lines));
systemOut.println(Joiner.on('\n').join(lines));
}
verifier.resetStreams();
return verifier;
Expand All @@ -295,7 +307,7 @@ private static Verifier newVerifier(String pathToTestProject) throws IOException
String modMvnOpts = (mvnOpts != null ? mvnOpts + " " : "") + "-Xmx1g";
verifier.setEnvironmentVariable("MAVEN_OPTS", modMvnOpts);
if (debug) {
System.out.println("Modified Maven Opts: " + modMvnOpts);
systemOut.println("Modified Maven Opts: " + modMvnOpts);
}
} else {
verifier.setForkJvm(false);
Expand Down

0 comments on commit 83ecc70

Please sign in to comment.