Skip to content

Commit

Permalink
JAVA-8886 🚧 updated inputs, now applies real agent to test app tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPhillips2020 committed Jan 10, 2025
1 parent 5e3197f commit 4e02564
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public void apply(final Project target) {

resolveAgentTask.configure(
task -> {
task.setFileString("contrast.jar");
task.setFileString(
target.getLayout().getBuildDirectory().getAsFile().get().getPath() + "/contrast.jar");
task.setAgent(
new File(
target.getLayout().getBuildDirectory().getAsFile().get().getPath(),
Expand All @@ -43,6 +44,7 @@ public void apply(final Project target) {
.register(
"contrastCheck",
task -> {
task.dependsOn(resolveAgentTask);
target
.getTasks()
.withType(Test.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void setAgent(File agent) {
void resolveAgent() {
System.out.println("running RESOLVE AGENT");
final ContrastSDK sdk = ContrastSDKService.getInstance(config);
agent = retrieveAgent(sdk, config.getJarPath(), config.getOrgUuid(), getProject());
agent = retrieveAgent(sdk, getFileString(), config.getOrgUuid(), getProject());
}

/** Use ContrastSDK to download agent and return the path where agent jar is stored */
Expand All @@ -67,20 +67,15 @@ public static File retrieveAgent(
if (jarPath != null) {
final Path agent = Paths.get(jarPath);
if (!Files.exists(agent)) {
throw new GradleException("Unable to find java agent at " + jarPath);
logger.debug("Unable to find java agent at " + jarPath);
} else {
logger.debug("Agent provided via configuration retrieved");
return new File(agent.toString());
}
logger.debug("Agent provided via configuration retrieved");
return new File(agent.toString());
}

logger.debug("No agent path provided, checking for cached agent");

final Path agent = Paths.get(project.getProjectDir().getPath()).resolve(AGENT_NAME);
if (Files.exists(agent)) {
System.out.println("Agent jar found at " + project.getProjectDir().getPath());
return new File(agent.toString());
}

logger.debug("Attempting to retrieve agent from TeamServer");
// If no jar is provided, and no jarpath configured, attempt to retrieve the agent from TS
final byte[] bytes;
Expand All @@ -97,7 +92,7 @@ public static File retrieveAgent(
logger.debug("Project dir already exists");
}

downloadedAgent = target.resolve(AGENT_NAME);
downloadedAgent = target.resolve(jarPath);

Files.write(downloadedAgent, bytes, StandardOpenOption.CREATE, StandardOpenOption.WRITE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void verify_attaches_agent_to_tests() throws IOException {
final GradleRunner testRunner = GradleRunner.create();
testRunner.forwardOutput();
testRunner.withPluginClasspath();
testRunner.withArguments("fakeTask", "contrastCheck");
// outputs debug logs to stdout for testing
testRunner.withDebug(true);
testRunner.withProjectDir(projectDir);
Expand All @@ -58,7 +59,7 @@ void verify_attaches_agent_to_tests() throws IOException {
.getTasks()
.forEach(
buildTask -> {
assertEquals(buildTask.getOutcome(), TaskOutcome.SUCCESS);
assertEquals(buildTask.getOutcome(), TaskOutcome.UP_TO_DATE);
});

for (final String arg : AGENT_ARGS) {
Expand Down

0 comments on commit 4e02564

Please sign in to comment.