Skip to content

Commit

Permalink
Avoid accessing Logger via project instance from Gradle execution phase
Browse files Browse the repository at this point in the history
Accessing project from task actions is prohibited when configuration cache is used.

If Quarkus plugin is to be compatible with CC eventually it should be avoided.

Signed-off-by: Konstantin Gribov <grossws@gmail.com>
  • Loading branch information
grossws committed Apr 16, 2023
1 parent 9a75983 commit 1b0b5f5
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ public void checkRequiredExtensions() {
.collect(Collectors.toList());

if (containerImageExtensions.isEmpty()) {
getProject().getLogger().warn("Task: {} requires a container image extension.", getName());
getProject().getLogger().warn("Available container image exntesions: [{}]",
getLogger().warn("Task: {} requires a container image extension.", getName());
getLogger().warn("Available container image exntesions: [{}]",
extensions.stream().collect(Collectors.joining(", ")));
getProject().getLogger().warn("To add an extension to the project, you can run one of the commands below:");
getLogger().warn("To add an extension to the project, you can run one of the commands below:");
extensions.forEach(e -> {
getProject().getLogger().warn("\tgradle addExtension --extensions={}", e);
getLogger().warn("\tgradle addExtension --extensions={}", e);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ public void checkRequiredExtensions() {
List<Builder> availableBuidlers = availableBuilders();
Optional<Builder> missingBuilder = Optional.of(builder()).filter(Predicate.not(availableBuidlers::contains));
missingBuilder.map(builder -> QUARKUS_CONTAINER_IMAGE_PREFIX + builder.name()).ifPresent(missingDependency -> {
getProject().getLogger().warn("Task: {} requires extensions: {}", getName(), missingDependency);
getProject().getLogger().warn("To add the extensions to the project you can run the following command:");
getProject().getLogger().warn("\tgradle addExtension --extensions={}", missingDependency);
getLogger().warn("Task: {} requires extensions: {}", getName(), missingDependency);
getLogger().warn("To add the extensions to the project you can run the following command:");
getLogger().warn("\tgradle addExtension --extensions={}", missingDependency);
abort("Aborting.");
});

if (!missingBuilder.isPresent() && availableBuidlers.isEmpty()) {
getProject().getLogger().warn("Task: {} requires on of extensions: {}", getName(),
getLogger().warn("Task: {} requires on of extensions: {}", getName(),
Arrays.stream(Builder.values()).map(Builder::name).collect(Collectors.joining(", ", "[", "]")));
getProject().getLogger().warn("To add the extensions to the project you can run the following command:");
getProject().getLogger().warn("\tgradle addExtension --extensions=<extension name>");
getLogger().warn("To add the extensions to the project you can run the following command:");
getLogger().warn("\tgradle addExtension --extensions=<extension name>");
abort("Aborting.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void generateBuild() {
}

void abort(String message, Object... args) {
getProject().getLogger().warn(message, args);
getLogger().warn(message, args);
getProject().getTasks().stream()
.filter(t -> t != this)
.filter(t -> !t.getState().getExecuted()).forEach(t -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private QuarkusDevModeLauncher newLauncher() throws Exception {
File file = p.toFile();
if (file.exists() && configuredParentFirst.contains(artifact.getKey())
&& filesIncludedInClasspath.add(file)) {
getProject().getLogger().debug("Adding dependency {}", file);
getLogger().debug("Adding dependency {}", file);
builder.classpathEntry(artifact.getKey(), file);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public QuarkusInfo() {

@TaskAction
public void logInfo() {

getProject().getLogger().warn(getName() + " is experimental, its options and output might change in future versions");
getLogger().warn(getName() + " is experimental, its options and output might change in future versions");

final QuarkusProject quarkusProject = getQuarkusProject(false);
final QuarkusCommandOutcome outcome;
Expand All @@ -44,7 +43,7 @@ public void logInfo() {
throw new GradleException("Failed to collect Quarkus project information", e);
}
if (outcome.getValue(ProjectInfoCommandHandler.RECOMMENDATIONS_AVAILABLE, false)) {
this.getProject().getLogger().warn(
getLogger().warn(
"Non-recommended Quarkus platform BOM and/or extension versions were found. For more details, please, execute 'gradle quarkusUpdate --rectify'");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void setInstalled(boolean installed) {

@TaskAction
public void listExtensions() {
getProject().getLogger().info("");
getLogger().info("");
if (installed) {
getProject().getLogger().info("Imported Quarkus platforms:");
getLogger().info("Imported Quarkus platforms:");
importedPlatforms().forEach(coords -> {
final StringBuilder buf = new StringBuilder();
buf.append(coords.getGroupId()).append(":")
Expand All @@ -40,13 +40,13 @@ public void listExtensions() {
messageWriter().info(buf.toString());
});
} else {
getProject().getLogger().info("Available Quarkus platforms:");
getLogger().info("Available Quarkus platforms:");
try {
new ListPlatforms(getQuarkusProject(installed)).execute();
} catch (Exception e) {
throw new GradleException("Unable to list platforms", e);
}
}
getProject().getLogger().info("");
getLogger().info("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected QuarkusProject getQuarkusProject(boolean limitExtensionsToImportedPlat
}

protected GradleMessageWriter messageWriter() {
return new GradleMessageWriter(getProject().getLogger());
return new GradleMessageWriter(getLogger());
}

protected static URL toURL(String url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ public QuarkusUpdate() {

@TaskAction
public void logUpdates() {

getProject().getLogger().warn(getName() + " is experimental, its options and output might change in future versions");
getLogger().warn(getName() + " is experimental, its options and output might change in future versions");
final QuarkusProject quarkusProject = getQuarkusProject(false);
final ExtensionCatalog targetCatalog;
try {
Expand Down

0 comments on commit 1b0b5f5

Please sign in to comment.