Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdennis committed Oct 27, 2023
1 parent 0e19861 commit 9a00d9b
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 244 deletions.
36 changes: 21 additions & 15 deletions src/main/java/org/terracotta/build/plugins/PackagePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.gradle.api.attributes.Usage;
import org.gradle.api.component.AdhocComponentWithVariants;
import org.gradle.api.component.SoftwareComponentFactory;
import org.gradle.api.internal.ReusableAction;
import org.gradle.api.internal.artifacts.JavaEcosystemSupport;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.publish.PublishingExtension;
Expand All @@ -24,15 +25,16 @@

import javax.inject.Inject;

import java.util.Set;

import static org.gradle.api.attributes.Usage.JAVA_API;
import static org.gradle.api.internal.tasks.JvmConstants.JAVA_COMPONENT_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;

/**
Expand All @@ -41,6 +43,8 @@
@SuppressWarnings("UnstableApiUsage")
public abstract class PackagePlugin implements Plugin<Project> {

public static final String EXPLODED_JAVA_RUNTIME = "exploded-java-runtime";

public static final String COMMON_PREFIX = "common";

@Inject
Expand Down Expand Up @@ -70,8 +74,6 @@ 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();
Expand All @@ -87,24 +89,28 @@ public void apply(Project project) {
}

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
71 changes: 68 additions & 3 deletions src/main/java/org/terracotta/build/plugins/packaging/Package.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,107 @@
package org.terracotta.build.plugins.packaging;

import org.gradle.api.Action;
import org.gradle.api.DomainObjectSet;
import org.gradle.api.Named;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.artifacts.Dependency;
import org.gradle.api.artifacts.DependencySet;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Property;
import org.gradle.api.provider.SetProperty;

import javax.inject.Inject;

public interface Package {

/**
* Package the contributing source and register the produced JAR as a variant, à la {@link JavaPluginExtension#withSourcesJar()}.
*/
void withSourcesJar();

/**
* Generate then package Javadoc and register the produced JAR as a variant, à la {@link JavaPluginExtension#withJavadocJar()}.
* <p>
* The javadoc is by default generated by executing the Javadoc tool over the merged source code of the contributing
* dependencies.
*/
default void withJavadocJar() {
withJavadocJar(javadoc -> {});
}

/**
* Generate then package Javadoc and register the produced JAR as a variant, à la {@link JavaPluginExtension#withJavadocJar()}.
* <p>
* Javdoc generation is customized using the provided action.
*/
void withJavadocJar(Action<Javadoc> action);

/**
* The set of additional optional feature variants.
* <p>
* Optional feature variants share the same primary artifact but provide additional dependencies mapped to additional
* outgoing variants, or to optional in Maven.
*
* @return the additional optional feature variants
*/
NamedDomainObjectContainer<? extends OptionalFeature> getOptionalFeatures();

interface OptionalFeature extends Named, CustomCapabilities {}

interface Javadoc {

SetProperty<Dependency> getClasspath();
/**
* The additional dependencies required for Javadoc generation.
*
* @return the additional javadoc classpath dependencies
*/
DomainObjectSet<Dependency> getClasspath();

/**
* The dependency that defines the public Javadoc for this package, or an absent value if Javadoc should be generated from merged sources.
*
* @return the optional javadoc dependency
*/
Property<Dependency> getArtifact();

default void classpath(Object dependency) {
classpath(dependency, d -> {});
/**
* Add a dependency to the Javadoc classpath by parsing the given notation
*
* @param notation dependency notation
* @see org.gradle.api.artifacts.dsl.DependencyHandler
*/
default void classpath(Object notation) {
classpath(notation, d -> {});
}

/**
* Add a dependency to the Javadoc classpath by parsing the given notation
* and configuring it using the provided action.
*
* @param notation dependency notation
* @param action configuring action
* @see org.gradle.api.artifacts.dsl.DependencyHandler
*/
void classpath(Object notation, Action<? super Dependency> action);

/**
* Assign a dependency to provide the Javadoc of this package by parsing the given notation.
*
* @param notation dependency notation
* @see org.gradle.api.artifacts.dsl.DependencyHandler
*/
default void from(Object notation) {
from(notation, d -> {});
}

/**
* Assign a dependency to provide the Javadoc of this package by parsing the given notation
* and configuring it using the provided action.
*
* @param notation dependency notation
* @param action configuring action
* @see org.gradle.api.artifacts.dsl.DependencyHandler
*/
void from(Object notation, Action<? super Dependency> action);
}
}
Loading

0 comments on commit 9a00d9b

Please sign in to comment.