Skip to content
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
Expand Up @@ -13,6 +13,13 @@ muzzle {

addTestSuiteForDir('latestDepTest', 'test')

def mavenRepositoryProxy = providers.gradleProperty('mavenRepositoryProxy')
tasks.withType(Test).configureEach {
if (mavenRepositoryProxy.isPresent()) {
environment 'MAVEN_REPOSITORY_PROXY', mavenRepositoryProxy.get()
}
}

dependencies {
compileOnly 'org.apache.maven:maven-embedder:3.2.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
}

def "test #testcaseName"() {
String workingDirectory = projectFolder.toString()

def exitCode = new MavenCli().doMain(args.toArray(new String[0]), workingDirectory, null, null)
def exitCode = executeMaven(args)

assertEquals(expectedExitCode, exitCode)
assertSpansData(testcaseName)
Expand Down Expand Up @@ -71,17 +69,24 @@ class MavenInstrumentationTest extends CiVisibilityInstrumentationTest {
* before proceeding with running the build
*/
void givenMavenDependenciesAreLoaded() {
String[] args = ["org.apache.maven.plugins:maven-dependency-plugin:go-offline"]
String workingDirectory = projectFolder.toString()
for (int attempt = 0; attempt < DEPENDENCIES_DOWNLOAD_RETRIES; attempt++) {
def exitCode = new MavenCli().doMain(args, workingDirectory, null, null)
def exitCode = executeMaven(["org.apache.maven.plugins:maven-dependency-plugin:go-offline"])
if (exitCode == 0) {
return
}
}
throw new AssertionError((Object) "Tried to download dependencies $DEPENDENCIES_DOWNLOAD_RETRIES times and failed")
}

private int executeMaven(List<String> args) {
def arguments = new ArrayList<>(args)
if (System.getenv("MAVEN_REPOSITORY_PROXY") != null) {
def settingsFile = new File(getClass().getResource("/settings.mirror.xml").toURI())
arguments.addAll(["-s", settingsFile.absolutePath])
}
return new MavenCli().doMain(arguments.toArray(new String[0]), projectFolder.toString(), null, null)
}

@Override
String instrumentedLibraryName() {
return "maven"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package datadog.trace.instrumentation.maven3;

import static java.util.Collections.addAll;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.PrintStream;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
Expand Down Expand Up @@ -51,17 +54,24 @@ protected void customizeContainer(PlexusContainer container) {

File pomFile = new File(AbstractMavenTest.class.getResource(pomPath).toURI());

String[] arguments = new String[additionalArgs.length + 4];
arguments[0] = "-f";
arguments[1] = pomFile.getAbsolutePath();
arguments[2] = goal;
List<String> arguments = new ArrayList<>();
addAll(arguments, "-f", pomFile.getAbsolutePath(), goal);
// Cap Aether's HTTP read timeout so a stalled Maven Central fetch fails fast.
// Default is 30 min, which exceeds the 20-min Gradle test task timeout and turns
// a network stall into an opaque "Timeout has been exceeded" task abort.
arguments[3] = "-Daether.connector.requestTimeout=60000";
System.arraycopy(additionalArgs, 0, arguments, 4, additionalArgs.length);
arguments.add("-Daether.connector.requestTimeout=60000");
if (System.getenv("MAVEN_REPOSITORY_PROXY") != null) {
File settingsFile =
new File(AbstractMavenTest.class.getResource("/settings.mirror.xml").toURI());
addAll(arguments, "-s", settingsFile.getAbsolutePath());
}
addAll(arguments, additionalArgs);

mavenCli.doMain(arguments, WORKING_DIRECTORY.toAbsolutePath().toString(), stdOut, stderr);
mavenCli.doMain(
arguments.toArray(new String[0]),
WORKING_DIRECTORY.toAbsolutePath().toString(),
stdOut,
stderr);

Exception error = spy.handlerError.get();
if (error != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<settings>
<mirrors>
<mirror>
<id>env-proxy</id>
<mirrorOf>*</mirrorOf>
<url>${env.MAVEN_REPOSITORY_PROXY}</url>
</mirror>
</mirrors>
</settings>
Loading