Skip to content

Commit

Permalink
Pass the local maven repo path to the tests as maven.repo.local syste…
Browse files Browse the repository at this point in the history
…m property and the maven settings as mave.settings property
  • Loading branch information
aloubyansky committed Mar 9, 2021
1 parent d1e3a28 commit 66cd0da
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 34 deletions.
6 changes: 4 additions & 2 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
<maven.repo.local>${settings.localRepository}</maven.repo.local>
<maven.settings>${session.request.userSettingsFile.path}</maven.settings>
<project.version>${project.version}</project.version> <!-- some dev tools tests need this -->
</systemPropertyVariables>
<argLine>${jacoco.agent.argLine} -Xmx1500m</argLine> <!-- limit the amount of memory surefire can use, 1500m should be plenty-->
Expand All @@ -331,7 +332,8 @@
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<maven.repo>${settings.localRepository}</maven.repo>
<maven.repo.local>${settings.localRepository}</maven.repo.local>
<maven.settings>${session.request.userSettingsFile.path}</maven.settings>
<project.version>${project.version}</project.version> <!-- some dev tools tests need this -->
</systemPropertyVariables>
<!-- https://lists.apache.org/thread.html/r9030808273c82ac6d7b9602d34d446c7d8c4e8aa02c41bca164df1c5%40%3Cdev.maven.apache.org%3E -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,12 @@ private InvocationResult setup(Properties params)

params.setProperty("platformArtifactId", "quarkus-bom");
params.setProperty("platformVersion", getQuarkusCoreVersion());
enableDevToolsTestConfig(params);

InvocationRequest request = new DefaultInvocationRequest();
request.setBatchMode(true);
request.setGoals(Collections.singletonList(
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion() + ":create"));
request.setProperties(params);
getEnv().forEach(request::addShellEnvironment);
File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
12 changes: 0 additions & 12 deletions integration-tests/maven/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<project.version>${project.version}</project.version>
</systemPropertyVariables>
</configuration>
</plugin>

<plugin>
Expand All @@ -94,11 +89,6 @@
</goals>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<project.version>${project.version}</project.version>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
Expand All @@ -121,8 +111,6 @@
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<project.version>${project.version}</project.version>

<!-- add a system property that can be used by JUnit to determine whether a native image can be built -->
<quarkus.test.native>true</quarkus.test.native>
</systemPropertyVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,8 @@ private void addExtension(boolean plural, String ext)
} else {
properties.setProperty("extension", ext);
}
enableDevToolsTestConfig(properties);
request.setProperties(properties);

getEnv().forEach(request::addShellEnvironment);
File log = new File(testDir, "build-add-extension-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ private InvocationResult setup(Properties params)
request.setDebug(false);
request.setShowErrors(true);
request.setProperties(params);
getEnv().forEach(request::addShellEnvironment);
File log = new File(testDir.getParent(), "build-create-extension-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ private InvocationResult setup(Properties params)
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion() + ":create-jbang"));
request.setDebug(false);
request.setShowErrors(true);
enableDevToolsTestConfig(params);
request.setProperties(params);
getEnv().forEach(request::addShellEnvironment);
File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ private InvocationResult executeCreate(Properties params)
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion() + ":create"));
request.setDebug(false);
request.setShowErrors(true);
enableDevToolsTestConfig(params);
request.setProperties(params);

getEnv().forEach(request::addShellEnvironment);
PrintStreamLogger logger = getPrintStreamLogger("create-codestart.log");
invoker.setLogger(logger);
return invoker.execute(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,8 @@ private InvocationResult setup(Properties params)
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion() + ":create"));
request.setDebug(false);
request.setShowErrors(true);
enableDevToolsTestConfig(params);
request.setProperties(params);
getEnv().forEach(request::addShellEnvironment);

File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void generateConfig(String filename)
Properties properties = new Properties();
properties.setProperty("file", filename);
request.setProperties(properties);
getEnv().forEach(request::addShellEnvironment);

File log = new File(testDir, "build-generate-config-" + testDir.getName() + ".log");
PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.DEBUG);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ private List<String> listExtensions()
request.setGoals(Collections.singletonList(
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion()
+ ":list-extensions"));
getEnv().forEach(request::addShellEnvironment);
enableDevToolsTestConfig(request);

File outputLog = new File(testDir, "output.log");
InvocationOutputHandler outputHandler = new PrintStreamHandler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ private InvocationResult setup(Properties params)
}
params.setProperty("platformArtifactId", getBomArtifactId());
params.setProperty("platformVersion", getQuarkusCoreVersion());
enableDevToolsTestConfig(params);

InvocationRequest request = new DefaultInvocationRequest();
request.setBatchMode(true);
request.setGoals(Collections.singletonList(
getMavenPluginGroupId() + ":" + getMavenPluginArtifactId() + ":" + getMavenPluginVersion() + ":create"));
request.setProperties(params);
getEnv().forEach(request::addShellEnvironment);
File log = new File(testDir, "build-create-" + testDir.getName() + ".log");
final PrintStreamLogger logger = new PrintStreamLogger(new PrintStream(new FileOutputStream(log), false, "UTF-8"),
InvokerLogger.INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,46 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.shared.invoker.DefaultInvoker;
import org.apache.maven.shared.invoker.InvocationRequest;
import org.apache.maven.shared.invoker.InvocationResult;
import org.apache.maven.shared.invoker.Invoker;
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;

import io.quarkus.devtools.test.RegistryClientTestHelper;
import io.quarkus.test.devmode.util.DevModeTestUtils;

public class MojoTestBase {

public static Invoker initInvoker(File root) {
Invoker invoker = new DefaultInvoker();
public Invoker initInvoker(File root) {
Invoker invoker = new DefaultInvoker() {
@Override
public InvocationResult execute(InvocationRequest request)
throws MavenInvocationException {
passUserSettings(request);
getEnv().forEach(request::addShellEnvironment);
enableDevToolsTestConfig(request);
return super.execute(request);
}
};
invoker.setWorkingDirectory(root);
String repo = System.getProperty("maven.repo");
String repo = System.getProperty("maven.repo.local");
if (repo == null) {
repo = new File(System.getProperty("user.home"), ".m2/repository").getAbsolutePath();
}
invoker.setLocalRepositoryDirectory(new File(repo));
return invoker;
}

public static void passUserSettings(InvocationRequest request) {
final String mvnSettings = System.getProperty("maven.settings");
if (mvnSettings != null) {
final File settingsFile = new File(mvnSettings);
if (settingsFile.exists()) {
request.setUserSettingsFile(settingsFile);
}
}
}

public static File initEmptyProject(String name) {
File tc = new File("target/test-classes/" + name);
if (tc.isDirectory()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.maven.shared.invoker.PrintStreamHandler;
import org.apache.maven.shared.invoker.PrintStreamLogger;

import io.quarkus.maven.it.MojoTestBase;
import io.quarkus.test.devmode.util.DevModeTestUtils;

/**
Expand All @@ -37,7 +38,7 @@ public class RunningInvoker extends MavenProcessInvoker {
public RunningInvoker(File basedir, boolean debug) {
this.debug = debug;
setWorkingDirectory(basedir);
String repo = System.getProperty("maven.repo");
String repo = System.getProperty("maven.repo.local");
if (repo == null) {
repo = new File(System.getProperty("user.home"), ".m2/repository").getAbsolutePath();
}
Expand Down Expand Up @@ -130,6 +131,7 @@ public MavenProcessInvocationResult execute(List<String> goals, Map<String, Stri

@Override
public InvocationResult execute(InvocationRequest request) throws MavenInvocationException {
MojoTestBase.passUserSettings(request);
return super.execute(request);
}

Expand Down

0 comments on commit 66cd0da

Please sign in to comment.