Skip to content

Commit

Permalink
IGNITE-23094 Added support for custom Maven settings file path for al…
Browse files Browse the repository at this point in the history
…l commands in Compatibility tests. (#11499)
  • Loading branch information
petrov-mg authored Aug 30, 2024
1 parent 9cecf19 commit df0fee1
Showing 1 changed file with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.Callable;
Expand All @@ -43,8 +42,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.apache.ignite.internal.util.lang.GridFunc.isEmpty;

/**
* Provides some useful methods to work with Maven.
*/
Expand All @@ -55,12 +52,6 @@ public class MavenUtils {
/** */
private static final String MAVEN_DEPENDENCY_PLUGIN = "org.apache.maven.plugins:maven-dependency-plugin:3.2.0";

/** */
private static final String GG_MVN_REPO = "http://www.gridgainsystems.com/nexus/content/repositories/external";

/** Set this flag to true if running PDS compatibility tests locally. */
private static boolean useGgRepo;

/**
* Gets a path to an artifact with given version and groupId=org.apache.ignite and artifactId={@code artifactId}.
* <br>
Expand Down Expand Up @@ -187,29 +178,12 @@ private static Collection<String> mavenProjectRepositories() throws Exception {
private static void downloadArtifact(String artifact) throws Exception {
X.println("Downloading artifact... Identifier: " + artifact);

// Default platform independ path for maven settings file.
Path locProxyMavenSettings = Paths.get(System.getProperty("user.home"), ".m2", "local-proxy.xml");

String locProxyMavenSettingsFromEnv = System.getenv("LOCAL_PROXY_MAVEN_SETTINGS");

GridStringBuilder mavenCmdArgs = new SB(" ").a(MAVEN_DEPENDENCY_PLUGIN).a(":get -Dartifact=" + artifact);

if (!isEmpty(locProxyMavenSettingsFromEnv))
locProxyMavenSettings = Paths.get(locProxyMavenSettingsFromEnv);

if (Files.exists(locProxyMavenSettings))
mavenCmdArgs.a(" -s " + locProxyMavenSettings.toString());
else {
Collection<String> repos = new ArrayList<>();

if (useGgRepo)
repos.add(GG_MVN_REPO);
Collection<String> repos = mavenProjectRepositories();

repos.addAll(mavenProjectRepositories());

if (!repos.isEmpty())
mavenCmdArgs.a(" -DremoteRepositories=").a(String.join(",", repos));
}
if (!repos.isEmpty())
mavenCmdArgs.a(" -DremoteRepositories=").a(String.join(",", repos));

exec(buildMvnCommand() + mavenCmdArgs.toString());

Expand Down Expand Up @@ -268,6 +242,27 @@ private static String exec(String cmd) throws Exception {
* @return Maven executable command.
*/
private static String buildMvnCommand() {
String mvnCmd = resolveMavenApplicationPath();

Path mvnSettingsFilePath = resolveMavenSettingsFilePath();

if (Files.exists(mvnSettingsFilePath))
mvnCmd += " -s " + mvnSettingsFilePath;

return mvnCmd;
}

/** */
private static Path resolveMavenSettingsFilePath() {
String settingsPathEnv = System.getenv("LOCAL_PROXY_MAVEN_SETTINGS");

return F.isEmpty(settingsPathEnv)
? Paths.get(System.getProperty("user.home"), ".m2", "local-proxy.xml")
: Paths.get(settingsPathEnv);
}

/** */
private static String resolveMavenApplicationPath() {
String m2Home = System.getenv("M2_HOME");

if (m2Home == null)
Expand Down

0 comments on commit df0fee1

Please sign in to comment.