-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "compatibility with configuration cache for image tasks"
- Loading branch information
Showing
13 changed files
with
136 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 13 additions & 19 deletions
32
...ls/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/ImageBuild.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,27 @@ | ||
|
||
package io.quarkus.gradle.tasks; | ||
|
||
import static io.quarkus.gradle.tasks.ImageCheckRequirementsTask.QUARKUS_CONTAINER_IMAGE_BUILD; | ||
import static io.quarkus.gradle.tasks.ImageCheckRequirementsTask.QUARKUS_CONTAINER_IMAGE_BUILDER; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.tasks.TaskAction; | ||
import org.gradle.api.provider.MapProperty; | ||
import org.gradle.api.tasks.options.Option; | ||
|
||
public abstract class ImageBuild extends ImageTask { | ||
|
||
@Inject | ||
public ImageBuild() { | ||
super("Perform an image build", true); | ||
Optional<Builder> builder = Optional.empty(); | ||
|
||
@Option(option = "builder", description = "The container image extension to use for building the image (e.g. docker, jib, buildpack, openshift).") | ||
public void setBuilder(Builder builder) { | ||
this.builder = Optional.of(builder); | ||
} | ||
|
||
@TaskAction | ||
public void imageBuild() throws IOException { | ||
Map<String, String> forcedProperties = new HashMap<String, String>(); | ||
File imageBuilder = getBuilderName().get().getAsFile(); | ||
String inputString = new String(Files.readAllBytes(imageBuilder.toPath())); | ||
@Inject | ||
public ImageBuild() { | ||
super("Perform an image build"); | ||
MapProperty<String, String> forcedProperties = extension().forcedPropertiesProperty(); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_BUILD, "true"); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_BUILDER, inputString); | ||
getAdditionalForcedProperties().get().getProperties().putAll(forcedProperties); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_BUILDER, getProject().provider(() -> builder().name())); | ||
} | ||
} |
121 changes: 0 additions & 121 deletions
121
...-application-plugin/src/main/java/io/quarkus/gradle/tasks/ImageCheckRequirementsTask.java
This file was deleted.
Oops, something went wrong.
39 changes: 29 additions & 10 deletions
39
...ols/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/ImagePush.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,45 @@ | ||
package io.quarkus.gradle.tasks; | ||
|
||
import static io.quarkus.gradle.tasks.ImageCheckRequirementsTask.*; | ||
package io.quarkus.gradle.tasks; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.gradle.api.provider.MapProperty; | ||
import org.gradle.api.tasks.TaskAction; | ||
|
||
public abstract class ImagePush extends ImageTask { | ||
|
||
@Inject | ||
public ImagePush() { | ||
super("Perform an image push", true); | ||
super("Perform an image push"); | ||
MapProperty<String, String> forcedProperties = extension().forcedPropertiesProperty(); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_BUILD, "true"); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_PUSH, "true"); | ||
} | ||
|
||
@TaskAction | ||
public void imagePush() { | ||
Map<String, String> forcedProperties = new HashMap<String, String>(); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_BUILD, "true"); | ||
forcedProperties.put(QUARKUS_CONTAINER_IMAGE_PUSH, "true"); | ||
getAdditionalForcedProperties().get().getProperties().putAll(forcedProperties); | ||
public void checkRequiredExtensions() { | ||
List<String> containerImageExtensions = getProject().getConfigurations().stream() | ||
.flatMap(c -> c.getDependencies().stream()) | ||
.map(d -> d.getName()) | ||
.filter(n -> n.startsWith(QUARKUS_CONTAINER_IMAGE_PREFIX)) | ||
.map(n -> n.replaceAll("-deployment$", "")) | ||
.collect(Collectors.toList()); | ||
|
||
List<String> extensions = Arrays.stream(ImageBuild.Builder.values()).map(b -> QUARKUS_CONTAINER_IMAGE_PREFIX + b.name()) | ||
.collect(Collectors.toList()); | ||
|
||
if (containerImageExtensions.isEmpty()) { | ||
getLogger().warn("Task: {} requires a container image extension.", getName()); | ||
getLogger().warn("Available container image exntesions: [{}]", | ||
extensions.stream().collect(Collectors.joining(", "))); | ||
getLogger().warn("To add an extension to the project, you can run one of the commands below:"); | ||
extensions.forEach(e -> { | ||
getLogger().warn("\tgradle addExtension --extensions={}", e); | ||
}); | ||
} | ||
} | ||
} |
92 changes: 82 additions & 10 deletions
92
...ols/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/ImageTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,95 @@ | ||
|
||
package io.quarkus.gradle.tasks; | ||
|
||
import org.gradle.api.file.RegularFileProperty; | ||
import org.gradle.api.tasks.InputFile; | ||
import org.gradle.api.tasks.PathSensitive; | ||
import org.gradle.api.tasks.PathSensitivity; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
import org.gradle.api.tasks.TaskAction; | ||
|
||
import io.quarkus.gradle.dependency.ApplicationDeploymentClasspathBuilder; | ||
import io.quarkus.gradle.tooling.ToolingUtils; | ||
import io.quarkus.runtime.LaunchMode; | ||
|
||
public abstract class ImageTask extends QuarkusBuildTask { | ||
|
||
ImageTask(String description, boolean compatible) { | ||
super(description, compatible); | ||
private static final String DEPLOYMENT_SUFFIX = "-deployment"; | ||
static final String QUARKUS_PREFIX = "quarkus-"; | ||
static final String QUARKUS_CONTAINER_IMAGE_PREFIX = "quarkus-container-image-"; | ||
static final String QUARKUS_CONTAINER_IMAGE_BUILD = "quarkus.container-image.build"; | ||
static final String QUARKUS_CONTAINER_IMAGE_PUSH = "quarkus.container-image.push"; | ||
static final String QUARKUS_CONTAINER_IMAGE_BUILDER = "quarkus.container-image.builder"; | ||
|
||
static final Map<String, Builder> BUILDERS = new HashMap<>(); | ||
static { | ||
for (Builder builder : Builder.values()) { | ||
BUILDERS.put(builder.name(), builder); | ||
} | ||
} | ||
|
||
@InputFile | ||
@PathSensitive(PathSensitivity.RELATIVE) | ||
public abstract RegularFileProperty getBuilderName(); | ||
enum Builder { | ||
docker, | ||
jib, | ||
buildpack, | ||
openshift | ||
} | ||
|
||
public ImageTask(String description) { | ||
super(description, false); | ||
} | ||
|
||
public Builder builder() { | ||
return builderFromSystemProperties() | ||
.or(() -> availableBuilders().stream().findFirst()) | ||
.orElse(Builder.docker); | ||
} | ||
|
||
Optional<Builder> builderFromSystemProperties() { | ||
return Optional.ofNullable(System.getProperty(QUARKUS_CONTAINER_IMAGE_BUILDER)) | ||
.filter(BUILDERS::containsKey) | ||
.map(BUILDERS::get); | ||
} | ||
|
||
List<Builder> availableBuilders() { | ||
// This will only pickup direct dependencies and not transitives | ||
// This means that extensions like quarkus-container-image-openshift via quarkus-openshift are not picked up | ||
// So, let's relax our filters a bit so that we can pickup quarkus-openshift directly (relax the prefix requirement). | ||
return getProject().getConfigurations() | ||
.getByName(ToolingUtils.toDeploymentConfigurationName( | ||
ApplicationDeploymentClasspathBuilder.getFinalRuntimeConfigName(LaunchMode.NORMAL))) | ||
.getDependencies().stream() | ||
.map(d -> d.getName()) | ||
.filter(n -> n.startsWith(QUARKUS_CONTAINER_IMAGE_PREFIX) || n.startsWith(QUARKUS_PREFIX)) | ||
.map(n -> n.replace(QUARKUS_CONTAINER_IMAGE_PREFIX, "").replace(QUARKUS_PREFIX, "").replace(DEPLOYMENT_SUFFIX, | ||
"")) | ||
.filter(BUILDERS::containsKey) | ||
.map(BUILDERS::get) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@TaskAction | ||
public void imageTask() { | ||
public void checkRequiredExtensions() { | ||
// Currently forcedDependencies() is not implemented for gradle. | ||
// So, let's give users a meaningful warning message. | ||
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 -> { | ||
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()) { | ||
getLogger().warn("Task: {} requires on of extensions: {}", getName(), | ||
Arrays.stream(Builder.values()).map(Builder::name).collect(Collectors.joining(", ", "[", "]"))); | ||
getLogger().warn("To add the extensions to the project you can run the following command:"); | ||
getLogger().warn("\tgradle addExtension --extensions=<extension name>"); | ||
abort("Aborting."); | ||
} | ||
} | ||
} |
Oops, something went wrong.