Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document and Cleanup Plugins #17

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
14 changes: 4 additions & 10 deletions src/main/java/org/terracotta/build/plugins/BlacklistPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencyScopeConfiguration;
import org.gradle.api.artifacts.MutableVersionConstraint;
import org.gradle.api.plugins.JavaBasePlugin;
import org.gradle.api.tasks.SourceSetContainer;
Expand All @@ -12,18 +13,15 @@

import static org.gradle.api.tasks.SourceSet.TEST_SOURCE_SET_NAME;

@SuppressWarnings("UnstableApiUsage")
public class BlacklistPlugin implements Plugin<Project> {

private static final String BLACKLIST_CONFIGURATION = "blacklist";
private static final String TEST_BLACKLIST_CONFIGURATION = "testBlacklist";

@Override
public void apply(Project project) {
NamedDomainObjectProvider<Configuration> blacklist = project.getConfigurations().register(BLACKLIST_CONFIGURATION, config -> {
config.setVisible(false);
config.setCanBeConsumed(false);
config.setCanBeResolved(false);
});
NamedDomainObjectProvider<DependencyScopeConfiguration> blacklist = project.getConfigurations().dependencyScope(BLACKLIST_CONFIGURATION);

project.getConfigurations().configureEach(other -> {
Configuration config = blacklist.get();
Expand All @@ -32,11 +30,7 @@ public void apply(Project project) {
}
});

NamedDomainObjectProvider<Configuration> testBlacklist = project.getConfigurations().register(TEST_BLACKLIST_CONFIGURATION, config -> {
config.setVisible(false);
config.setCanBeConsumed(false);
config.setCanBeResolved(false);
});
NamedDomainObjectProvider<DependencyScopeConfiguration> testBlacklist = project.getConfigurations().dependencyScope(TEST_BLACKLIST_CONFIGURATION);

project.getPlugins().withType(JavaBasePlugin.class).configureEach(javaBasePlugin -> {
project.getExtensions().configure(SourceSetContainer.class, sourceSets ->
Expand Down
50 changes: 29 additions & 21 deletions src/main/java/org/terracotta/build/plugins/PackagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@

import javax.inject.Inject;

import static org.gradle.api.internal.tasks.JvmConstants.JAVA_COMPONENT_NAME;
import static org.gradle.api.artifacts.Dependency.DEFAULT_CONFIGURATION;
import static org.gradle.api.internal.tasks.JvmConstants.RUNTIME_ELEMENTS_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.API_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.COMPILE_ONLY_API_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME;
import static org.gradle.api.plugins.JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME;
import static org.terracotta.build.plugins.packaging.PackageInternal.CONTENTS_API_CONFIGURATION_NAME;
import static org.terracotta.build.plugins.packaging.PackageInternal.CONTENTS_CONFIGURATION_NAME;
import static org.terracotta.build.plugins.packaging.PackageInternal.PROVIDED_CONFIGURATION_NAME;
import static org.terracotta.build.plugins.packaging.PackageInternal.UNPACKAGED_JAVA_RUNTIME;
import static org.terracotta.build.plugins.packaging.PackageInternal.camelPrefix;

/**
* EhDistribute
* A plugin which assembles partial uber-jars.
*/
@SuppressWarnings("UnstableApiUsage")
public abstract class PackagePlugin implements Plugin<Project> {

public static final String PACKAGE_COMPONENT_NAME = "package";
public static final String EXPLODED_JAVA_RUNTIME = "exploded-java-runtime";
public static final String COMMON_PREFIX = "common";

@Inject
Expand All @@ -50,13 +51,16 @@ public abstract class PackagePlugin implements Plugin<Project> {
public void apply(Project project) {
project.getPlugins().apply(BasePlugin.class);

AdhocComponentWithVariants javaComponent = getSoftwareComponentFactory().adhoc(JAVA_COMPONENT_NAME);
project.getComponents().add(javaComponent);
project.getComponents().registerFactory(AdhocComponentWithVariants.class, getSoftwareComponentFactory()::adhoc);
NamedDomainObjectProvider<AdhocComponentWithVariants> component = project.getComponents().register(PACKAGE_COMPONENT_NAME, AdhocComponentWithVariants.class);

project.getTasks().withType(ShadowJar.class).configureEach(shadow -> shadow.getExtensions().create("osgi", OsgiManifestJarExtension.class, shadow));


ConfigurationContainer configurations = project.getConfigurations();
/*
* Create the set of common dependency scopes that all the package specific scopes extend.
*/
NamedDomainObjectProvider<DependencyScopeConfiguration> commonContentsApi = configurations.dependencyScope(camelPrefix(COMMON_PREFIX, CONTENTS_API_CONFIGURATION_NAME),
c -> c.setDescription("API dependencies for all packages contents."));
configurations.dependencyScope(camelPrefix(COMMON_PREFIX, CONTENTS_CONFIGURATION_NAME),
Expand All @@ -70,41 +74,45 @@ public void apply(Project project) {
c -> c.setDescription("Compile-only API dependencies for all packaged artifacts."));
configurations.dependencyScope(camelPrefix(COMMON_PREFIX, RUNTIME_ONLY_CONFIGURATION_NAME),
c -> c.setDescription("Runtime-only dependencies for all packaged artifacts."));
configurations.dependencyScope(camelPrefix(COMMON_PREFIX, PROVIDED_CONFIGURATION_NAME),
c -> c.setDescription("'Provided' API dependencies for all packaged artifacts."));

PackagingExtensionInternal packaging = (PackagingExtensionInternal) project.getExtensions().create(PackagingExtension.class, "packaging", PackagingExtensionInternal.class);
packaging.getDefaultPackage().create();
packaging.getVariants().all(PackageInternal::create);

configurations.named(DEFAULT_CONFIGURATION).configure(c -> c.extendsFrom(configurations.getByName(RUNTIME_ELEMENTS_CONFIGURATION_NAME)));

project.getPlugins().withType(MavenPublishPlugin.class).configureEach(plugin -> {
project.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.getPublications().register("mavenJava", MavenPublication.class, mavenPublication -> {
mavenPublication.from(javaComponent);
publishing.getPublications().register("mavenPackage", MavenPublication.class, mavenPublication -> {
mavenPublication.from(component.get());
});
});
});
}

public static void augmentAttributeSchema(AttributesSchema schema) {
schema.attribute(Usage.USAGE_ATTRIBUTE, strategy -> strategy.getCompatibilityRules().add(UnpackagedJavaRuntimeCompatibility.class));
schema.attribute(Usage.USAGE_ATTRIBUTE, strategy -> strategy.getCompatibilityRules().add(ExplodedJavaRuntimeCompatibility.class));
}

public static class UnpackagedJavaRuntimeCompatibility implements AttributeCompatibilityRule<Usage> {
@SuppressWarnings("deprecation")
public static class ExplodedJavaRuntimeCompatibility implements AttributeCompatibilityRule<Usage> {

@Override
public void execute(CompatibilityCheckDetails<Usage> details) {
Usage consumer = details.getConsumerValue();
Usage consumerValue = details.getConsumerValue();
Usage producerValue = details.getProducerValue();

if (consumerValue == null) {
details.compatible();
return;
}

if (consumer != null && UNPACKAGED_JAVA_RUNTIME.equals(consumer.getName())) {
Usage producer = details.getProducerValue();
if (producer != null) {
switch (producer.getName()) {
case Usage.JAVA_RUNTIME:
if (producerValue != null && EXPLODED_JAVA_RUNTIME.equals(consumerValue.getName())) {
switch (producerValue.getName()) {
case Usage.JAVA_RUNTIME:
case JavaEcosystemSupport.DEPRECATED_JAVA_RUNTIME_JARS:
details.compatible();
break;
}
details.compatible();
break;
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions src/main/java/org/terracotta/build/plugins/VoltronPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.DependencyScopeConfiguration;
import org.gradle.api.artifacts.ModuleDependency;
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.artifacts.ResolvableConfiguration;
import org.gradle.api.artifacts.dsl.DependencyFactory;
import org.gradle.api.capabilities.Capability;
import org.gradle.api.file.FileCollection;
Expand Down Expand Up @@ -44,6 +46,7 @@ public class VoltronPlugin implements Plugin<Project> {
public static final String XML_CONFIG_VARIANT_NAME = "xml";
public static final String VOLTRON_CONFIGURATION_NAME = "voltron";
public static final String SERVICE_CONFIGURATION_NAME = "service";
private static final String PROVIDED_CLASSPATH_CONFIGURATION_NAME = "providedClasspath";

@Override
public void apply(Project project) {
Expand All @@ -67,16 +70,12 @@ public void apply(Project project) {
});
});

NamedDomainObjectProvider<Configuration> voltron = project.getConfigurations().register(VOLTRON_CONFIGURATION_NAME, config -> {
config.setDescription("Dependencies provided by the platform Kit, either from server/lib or from plugins/api");
config.setCanBeResolved(true);
config.setCanBeConsumed(true);
});
NamedDomainObjectProvider<Configuration> service = project.getConfigurations().register(SERVICE_CONFIGURATION_NAME, config -> {
config.setDescription("Services consumed by this plugin");
config.setCanBeResolved(true);
config.setCanBeConsumed(true);
});
NamedDomainObjectProvider<DependencyScopeConfiguration> voltron = project.getConfigurations().dependencyScope(VOLTRON_CONFIGURATION_NAME,
c -> c.setDescription("Dependencies provided by the platform Kit, either from server/lib or from plugins/api"));
NamedDomainObjectProvider<DependencyScopeConfiguration> service = project.getConfigurations().dependencyScope(SERVICE_CONFIGURATION_NAME,
c -> c.setDescription("Services consumed by this plugin"));
NamedDomainObjectProvider<ResolvableConfiguration> providedClasspath = project.getConfigurations().resolvable(PROVIDED_CLASSPATH_CONFIGURATION_NAME, c -> c.extendsFrom(voltron.get(), service.get()));

project.getConfigurations().named(JavaPlugin.API_CONFIGURATION_NAME, config -> config.extendsFrom(service.get()));
project.getConfigurations().named(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, config -> config.extendsFrom(voltron.get()));
project.getConfigurations().named(JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME, config -> config.extendsFrom(voltron.get()));
Expand All @@ -85,10 +84,9 @@ public void apply(Project project) {
NamedDomainObjectProvider<Configuration> runtimeClasspath = project.getConfigurations().named(RUNTIME_CLASSPATH_CONFIGURATION_NAME);

jar.getInputs().property(RUNTIME_CLASSPATH_CONFIGURATION_NAME, runtimeClasspath.flatMap(c -> c.getElements().map(e -> e.stream().map(f -> f.getAsFile().getName()).collect(toSet()))));
jar.getInputs().property(SERVICE_CONFIGURATION_NAME, service.flatMap(c -> c.getElements().map(e -> e.stream().map(f -> f.getAsFile().getName()).collect(toSet()))));
jar.getInputs().property(VOLTRON_CONFIGURATION_NAME, voltron.flatMap(c -> c.getElements().map(e -> e.stream().map(f -> f.getAsFile().getName()).collect(toSet()))));
jar.getInputs().property(PROVIDED_CLASSPATH_CONFIGURATION_NAME, providedClasspath.flatMap(c -> c.getElements().map(e -> e.stream().map(f -> f.getAsFile().getName()).collect(toSet()))));

Provider<String> voltronClasspath = runtimeClasspath.zip(service.zip(voltron, FileCollection::plus), FileCollection::minus)
Provider<String> voltronClasspath = runtimeClasspath.zip(providedClasspath, FileCollection::minus)
.map(c -> c.getFiles().stream().map(File::getName).collect(joining(" ")));
jar.manifest(manifest -> manifest.attributes(mapOf(Attributes.Name.CLASS_PATH.toString(), voltronClasspath)));
});
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/org/terracotta/build/plugins/docker/DockerBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import static java.util.Collections.emptyMap;
import static java.util.stream.Stream.of;

/**
* Docker '{@code docker build}' task.
*/
public abstract class DockerBuild extends DockerTask {

public DockerBuild() {
Expand Down Expand Up @@ -62,21 +65,51 @@ public void build() {
});
}

/**
* Dockerfile to build
*
* @return target Dockerfile
*/
@InputFile
public abstract RegularFileProperty getDockerfile();

/**
* Assembled environment for the Dockerfile
*
* @return dockerfile environment
*/
@InputDirectory @SkipWhenEmpty
public abstract DirectoryProperty getEnvironment();

/**
* Image ID file where the resultant image hash will be written
*
* @return output image id file
*/
@OutputFile
public abstract RegularFileProperty getImageIdFile();

/**
* Metadata labels to apply to the image.
*
* @return image metadata labels
*/
@Input
public abstract MapProperty<String, String> getMetadata();

/**
* Map of input build arguments
*
* @return build arguments
*/
@Input
public abstract MapProperty<String, String> getBuildArgs();

/**
* Reusltant image hash/id.
*
* @return output image hash
*/
@Internal
public Provider<String> getImageId() {
return getImageIdFile().map(DockerBuild::readImageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.terracotta.build.Utils.mapOf;
import static org.terracotta.build.plugins.docker.DockerEcosystemPlugin.DOCKER_IMAGE_ID;

@SuppressWarnings("UnstableApiUsage")
public class DockerBuildPlugin implements Plugin<Project> {

private static final Pattern DOCKERFILE_EVAL_PATTERN = Pattern.compile("\\$\\$\\{(?<expression>.+)}");
Expand All @@ -47,12 +48,18 @@ public void apply(Project project) {

DockerExtension dockerExtension = project.getExtensions().getByType(DockerExtension.class);

/*
* Attach build extension to docker extension installed by ecosystem plugin.
*/
DockerBuildExtension buildExtension = ((ExtensionAware) dockerExtension).getExtensions().create("build", DockerBuildExtension.class);

BuildInfoExtension buildInfo = project.getExtensions().getByType(BuildInfoExtension.class);

configureBuildDefaults(project, buildExtension, buildInfo);

/*
*
*/
TaskProvider<Sync> dockerEnvironment = project.getTasks().register("dockerEnvironment", Sync.class, sync -> {
sync.setDescription("Assembles the Docker build environment.");
sync.setGroup(LifecycleBasePlugin.BUILD_GROUP);
Expand Down Expand Up @@ -179,14 +186,11 @@ public void apply(Project project) {
purge.getArguments().add("--force");
});

project.getConfigurations().register("outgoingDocker", config -> {
config.setDescription("Built Docker image-id files.");
config.setCanBeConsumed(true);
config.setCanBeResolved(false);
config.setVisible(false);
config.attributes(attrs -> attrs.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, DOCKER_IMAGE_ID)));
config.outgoing(outgoing -> outgoing.artifact(dockerBuild));
});
project.getConfigurations().consumable("outgoingDocker", c -> c
.setDescription("Built Docker image-id files.")
.attributes(attrs -> attrs.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, DOCKER_IMAGE_ID)))
.outgoing(outgoing -> outgoing.artifact(dockerBuild))
);

project.getPlugins().withType(CopyrightPlugin.class).configureEach(plugin ->
((ExtensionAware) buildExtension).getExtensions().add("copyright", plugin.createCopyrightSet(project, "docker", copyright -> {
Expand All @@ -203,9 +207,9 @@ private void configureBuildDefaults(Project project, DockerBuildExtension docker
dockerBuild.getBuildArgs().convention(emptyMap());
dockerBuild.getDockerReadme().convention(dockerSourceBase.file("README.md"));
dockerBuild.getContentsDirectory().convention(dockerSourceBase.dir("contents"));
dockerBuild.getDocTemplates().convention(project.getLayout().getProjectDirectory().dir("../doc/templates"));
dockerBuild.getDocTemplates().convention(project.getLayout().getProjectDirectory().dir("doc/templates"));
dockerBuild.getDocMetadata().convention(emptyMap());
dockerBuild.getSagDocDirectory().convention(project.getLayout().getProjectDirectory().dir("../doc/acr-data"));
dockerBuild.getSagDocDirectory().convention(project.getLayout().getProjectDirectory().dir("doc/acr-data"));

dockerBuild.getTags().convention(project.provider(() -> singletonList(project.getVersion().toString())));
dockerBuild.getMetadata().put("gradle.build.host", getLocalHostName(project));
Expand Down
Loading