Skip to content

Commit

Permalink
ensure tasks that use moduleJvmArgs have task inputs set correctly (#…
Browse files Browse the repository at this point in the history
…2477)

add input properties for each task that uses moduleJvmArgs so that when the extension value changes, the task will no longer be up-to-date.
  • Loading branch information
bjlaub authored Jan 30, 2023
1 parent d801c3e commit 25de8da
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-2477.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
fix:
description: add input properties for each task that uses moduleJvmArgs so that
when the extension value changes, the task will no longer be up-to-date.
links:
- https://github.com/palantir/gradle-baseline/pull/2477
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ public Iterable<String> asArguments() {
return arguments;
}
});

setTaskInputsFromExtension(javaCompile, extension);
});

TaskProvider<Task> javadocTaskProvider = null;
Expand Down Expand Up @@ -175,6 +177,8 @@ public void execute(Task task) {
}
}
});

setTaskInputsFromExtension(javadocTask, extension);
});
}
});
Expand All @@ -198,6 +202,8 @@ public Iterable<String> asArguments() {
return arguments;
}
});

setTaskInputsFromExtension(test, extension);
}
});

Expand All @@ -220,6 +226,8 @@ public Iterable<String> asArguments() {
return arguments;
}
});

setTaskInputsFromExtension(javaExec, extension);
}
});

Expand Down Expand Up @@ -256,11 +264,19 @@ public void execute(Manifest manifest) {
});
}
});

setTaskInputsFromExtension(jar, extension);
}
});
});
}

private static void setTaskInputsFromExtension(Task task, BaselineModuleJvmArgsExtension extension) {
task.getInputs().property("baseline-module-jvm-args-extension-exports", extension.exports());
task.getInputs().property("baseline-module-jvm-args-extension-opens", extension.opens());
task.getInputs().property("baseline-module-jvm-args-extension-enablePreview", extension.getEnablePreview());
}

private static void addManifestAttribute(
Jar jarTask, Manifest manifest, String attributeName, Provider<Set<String>> valueProperty) {
Project project = jarTask.getProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,47 @@ class BaselineModuleJvmArgsIntegrationTest extends IntegrationSpec {
ExecutionResult result = runTasksWithFailure('jar')
result.standardError.contains('separated by a single slash')
}

def 'Task not up-to-date when extension value changes'() {
when:
buildFile << '''
application {
mainClass = 'com.Example'
}
moduleJvmArgs {
exports = ['java.management/sun.management']
}
'''.stripIndent(true)
writeJavaSourceFile('''
package com;
public class Example {
public static void main(String[] args) {
System.out.println(String.join(
" ",
java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments()));
}
}
'''.stripIndent(true))

ExecutionResult resultBeforeChange = runTasksSuccessfully('jar')

buildFile.text = standardBuildFile + '''
application {
mainClass = 'com.Example\'
}
moduleJvmArgs {
exports = ['java.management/sun.management123']
}
'''.stripIndent(true)

ExecutionResult resultAfterChange = runTasksSuccessfully('jar')

then:
!resultBeforeChange.wasUpToDate('jar')
resultBeforeChange.wasExecuted('jar')
!resultAfterChange.wasUpToDate('jar')
resultAfterChange.wasExecuted('jar')
}
}

0 comments on commit 25de8da

Please sign in to comment.