use of org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact in project gradle by gradle.
the class JvmPluginsHelper method configureDocumentationVariantWithArtifact.
public static void configureDocumentationVariantWithArtifact(String variantName, @Nullable String featureName, String docsType, List<Capability> capabilities, String jarTaskName, Object artifactSource, @Nullable AdhocComponentWithVariants component, ConfigurationContainer configurations, TaskContainer tasks, ObjectFactory objectFactory, FileResolver fileResolver) {
Configuration variant = maybeCreateInvisibleConfig(configurations, variantName, docsType + " elements for " + (featureName == null ? "main" : featureName) + ".", true);
AttributeContainer attributes = variant.getAttributes();
attributes.attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_RUNTIME));
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.class, Category.DOCUMENTATION));
attributes.attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.class, Bundling.EXTERNAL));
attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objectFactory.named(DocsType.class, docsType));
capabilities.forEach(variant.getOutgoing()::capability);
if (!tasks.getNames().contains(jarTaskName)) {
TaskProvider<Jar> jarTask = tasks.register(jarTaskName, Jar.class, jar -> {
jar.setDescription("Assembles a jar archive containing the " + (featureName == null ? "main " + docsType + "." : (docsType + " of the '" + featureName + "' feature.")));
jar.setGroup(BasePlugin.BUILD_GROUP);
jar.from(artifactSource);
jar.getArchiveClassifier().set(camelToKebabCase(featureName == null ? docsType : (featureName + "-" + docsType)));
});
if (tasks.getNames().contains(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)) {
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(jarTask));
}
}
TaskProvider<Task> jar = tasks.named(jarTaskName);
variant.getOutgoing().artifact(new LazyPublishArtifact(jar, fileResolver));
if (component != null) {
component.addVariantsFromConfiguration(variant, new JavaConfigurationVariantMapping("runtime", true));
}
}
use of org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact in project gradle by gradle.
the class DefaultJvmVariantBuilder method configureDocumentationVariantWithArtifact.
public void configureDocumentationVariantWithArtifact(String variantName, @Nullable String name, @Nullable String displayName, String docsType, String jarTaskName, Object artifactSource, @Nullable AdhocComponentWithVariants component) {
Configuration variant = configurations.maybeCreate(variantName);
variant.setVisible(false);
variant.setDescription(docsType + " elements for " + (displayName == null ? "main" : displayName) + ".");
variant.setCanBeResolved(false);
variant.setCanBeConsumed(true);
jvmPluginServices.configureAttributes(variant, attributes -> attributes.documentation(docsType).runtimeUsage().withExternalDependencies());
capabilities.forEach(variant.getOutgoing()::capability);
if (!tasks.getNames().contains(jarTaskName)) {
TaskProvider<Jar> jarTask = tasks.register(jarTaskName, Jar.class, jar -> {
jar.setDescription("Assembles a jar archive containing the " + (displayName == null ? "main " + docsType + "." : (docsType + " of the '" + displayName + "'.")));
jar.setGroup(BasePlugin.BUILD_GROUP);
jar.from(artifactSource);
jar.getArchiveClassifier().set(TextUtil.camelToKebabCase(name == null ? docsType : (name + "-" + docsType)));
});
if (tasks.getNames().contains(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)) {
tasks.named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME).configure(task -> task.dependsOn(jarTask));
}
}
TaskProvider<Task> jar = tasks.named(jarTaskName);
variant.getOutgoing().artifact(new LazyPublishArtifact(jar, project.getFileResolver()));
if (published && component != null) {
component.addVariantsFromConfiguration(variant, new JavaConfigurationVariantMapping("runtime", true));
}
}
use of org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact in project gradle by gradle.
the class CppLibraryPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(CppBasePlugin.class);
final TaskContainer tasks = project.getTasks();
final ObjectFactory objectFactory = project.getObjects();
final ProviderFactory providers = project.getProviders();
// Add the library and extension
final DefaultCppLibrary library = componentFactory.newInstance(CppLibrary.class, DefaultCppLibrary.class, "main");
project.getExtensions().add(CppLibrary.class, "library", library);
project.getComponents().add(library);
// Configure the component
library.getBaseName().convention(project.getName());
library.getTargetMachines().convention(useHostAsDefaultTargetMachine(targetMachineFactory));
library.getDevelopmentBinary().convention(project.provider(new Callable<CppBinary>() {
@Override
public CppBinary call() throws Exception {
return getDebugSharedHostStream().findFirst().orElse(getDebugStaticHostStream().findFirst().orElse(getDebugSharedStream().findFirst().orElse(getDebugStaticStream().findFirst().orElse(null))));
}
private Stream<CppBinary> getDebugStream() {
return library.getBinaries().get().stream().filter(binary -> !binary.isOptimized());
}
private Stream<CppBinary> getDebugSharedStream() {
return getDebugStream().filter(CppSharedLibrary.class::isInstance);
}
private Stream<CppBinary> getDebugSharedHostStream() {
return getDebugSharedStream().filter(binary -> Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture()));
}
private Stream<CppBinary> getDebugStaticStream() {
return getDebugStream().filter(CppStaticLibrary.class::isInstance);
}
private Stream<CppBinary> getDebugStaticHostStream() {
return getDebugStaticStream().filter(binary -> Architectures.forInput(binary.getTargetMachine().getArchitecture().getName()).equals(DefaultNativePlatform.host().getArchitecture()));
}
}));
library.getBinaries().whenElementKnown(binary -> {
library.getMainPublication().addVariant(binary);
});
project.afterEvaluate(p -> {
// TODO: make build type configurable for components
Dimensions.libraryVariants(library.getBaseName(), library.getLinkage(), library.getTargetMachines(), objectFactory, attributesFactory, providers.provider(() -> project.getGroup().toString()), providers.provider(() -> project.getVersion().toString()), variantIdentity -> {
if (tryToBuildOnHost(variantIdentity)) {
ToolChainSelector.Result<CppPlatform> result = toolChainSelector.select(CppPlatform.class, new DefaultCppPlatform(variantIdentity.getTargetMachine()));
if (variantIdentity.getLinkage().equals(Linkage.SHARED)) {
library.addSharedLibrary(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
} else {
library.addStaticLibrary(variantIdentity, result.getTargetPlatform(), result.getToolChain(), result.getPlatformToolProvider());
}
} else {
// Known, but not buildable
library.getMainPublication().addVariant(variantIdentity);
}
});
// TODO - deal with more than one header dir, e.g. generated public headers
final Configuration apiElements = library.getApiElements();
Provider<File> publicHeaders = providers.provider(() -> {
Set<File> files = library.getPublicHeaderDirs().getFiles();
if (files.size() != 1) {
throw new UnsupportedOperationException(String.format("The C++ library plugin currently requires exactly one public header directory, however there are %d directories configured: %s", files.size(), files));
}
return files.iterator().next();
});
apiElements.getOutgoing().artifact(publicHeaders);
project.getPluginManager().withPlugin("maven-publish", appliedPlugin -> {
final TaskProvider<Zip> headersZip = tasks.register("cppHeaders", Zip.class, task -> {
task.from(library.getPublicHeaderFiles());
task.getDestinationDirectory().set(project.getLayout().getBuildDirectory().dir("headers"));
task.getArchiveClassifier().set("cpp-api-headers");
task.getArchiveFileName().set("cpp-api-headers.zip");
});
library.getMainPublication().addArtifact(new LazyPublishArtifact(headersZip, ((ProjectInternal) project).getFileResolver()));
});
library.getBinaries().realizeNow();
});
}
use of org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact in project gradle by gradle.
the class EarPlugin method setupEarTask.
private void setupEarTask(final Project project, EarPluginConvention convention, PluginContainer plugins) {
TaskProvider<Ear> ear = project.getTasks().register(EAR_TASK_NAME, Ear.class, new Action<Ear>() {
@Override
public void execute(Ear ear) {
ear.setDescription("Generates a ear archive with all the modules, the application descriptor and the libraries.");
ear.setGroup(BasePlugin.BUILD_GROUP);
ear.getGenerateDeploymentDescriptor().convention(convention.getGenerateDeploymentDescriptor());
plugins.withType(JavaPlugin.class, javaPlugin -> {
final JavaPluginExtension javaPluginExtension = project.getExtensions().findByType(JavaPluginExtension.class);
SourceSet sourceSet = mainSourceSetOf(javaPluginExtension);
sourceSet.getResources().srcDir(ear.getAppDirectory());
});
}
});
DeploymentDescriptor deploymentDescriptor = convention.getDeploymentDescriptor();
if (deploymentDescriptor != null) {
if (deploymentDescriptor.getDisplayName() == null) {
deploymentDescriptor.setDisplayName(project.getName());
}
if (deploymentDescriptor.getDescription() == null) {
deploymentDescriptor.setDescription(project.getDescription());
}
}
project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(new LazyPublishArtifact(ear, ((ProjectInternal) project).getFileResolver()));
project.getTasks().withType(Ear.class).configureEach(new Action<Ear>() {
@Override
public void execute(Ear task) {
}
});
}
use of org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact in project gradle by gradle.
the class WarPlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.class);
final WarPluginConvention pluginConvention = new DefaultWarPluginConvention(project);
project.getConvention().getPlugins().put("war", pluginConvention);
project.getTasks().withType(War.class).configureEach(task -> {
task.getWebAppDirectory().convention(project.getLayout().dir(project.provider(() -> pluginConvention.getWebAppDir())));
task.from(task.getWebAppDirectory());
task.dependsOn((Callable) () -> project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath());
task.classpath((Callable) () -> {
FileCollection runtimeClasspath = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME).getRuntimeClasspath();
Configuration providedRuntime = project.getConfigurations().getByName(PROVIDED_RUNTIME_CONFIGURATION_NAME);
return runtimeClasspath.minus(providedRuntime);
});
});
TaskProvider<War> war = project.getTasks().register(WAR_TASK_NAME, War.class, warTask -> {
warTask.setDescription("Generates a war archive with all the compiled classes, the web-app content and the libraries.");
warTask.setGroup(BasePlugin.BUILD_GROUP);
});
PublishArtifact warArtifact = new LazyPublishArtifact(war, ((ProjectInternal) project).getFileResolver());
project.getExtensions().getByType(DefaultArtifactPublicationSet.class).addCandidate(warArtifact);
configureConfigurations(project.getConfigurations());
configureComponent(project, warArtifact);
}
Aggregations