use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.
the class PublishingPlugin method apply.
@Override
public void apply(final Project project) {
RepositoryHandler repositories = publicationServices.createRepositoryHandler();
PublicationContainer publications = instantiator.newInstance(DefaultPublicationContainer.class, instantiator, collectionCallbackActionDecorator);
PublishingExtension extension = project.getExtensions().create(PublishingExtension.class, PublishingExtension.NAME, DefaultPublishingExtension.class, repositories, publications);
project.getTasks().register(PUBLISH_LIFECYCLE_TASK_NAME, task -> {
task.setDescription("Publishes all publications produced by this project.");
task.setGroup(PUBLISH_TASK_GROUP);
});
extension.getPublications().all(publication -> {
PublicationInternal<?> internalPublication = Cast.uncheckedNonnullCast(publication);
ProjectInternal projectInternal = (ProjectInternal) project;
projectPublicationRegistry.registerPublication(projectInternal, internalPublication);
});
bridgeToSoftwareModelIfNeeded((ProjectInternal) project);
validatePublishingModelWhenComplete(project, extension);
}
use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.
the class IdeaDependenciesProvider method visitDependencies.
private IdeaDependenciesVisitor visitDependencies(IdeaModule ideaModule, GeneratedIdeaScope scope) {
ProjectInternal projectInternal = (ProjectInternal) ideaModule.getProject();
final DependencyHandler handler = projectInternal.getDependencies();
final Collection<Configuration> plusConfigurations = getPlusConfigurations(ideaModule, scope);
final Collection<Configuration> minusConfigurations = getMinusConfigurations(ideaModule, scope);
final JavaModuleDetector javaModuleDetector = projectInternal.getServices().get(JavaModuleDetector.class);
final IdeaDependenciesVisitor visitor = new IdeaDependenciesVisitor(ideaModule, scope.name());
return projectInternal.getOwner().fromMutableState(p -> {
new IdeDependencySet(handler, javaModuleDetector, plusConfigurations, minusConfigurations, false, gradleApiSourcesResolver).visit(visitor);
return visitor;
});
}
use of org.gradle.api.internal.project.ProjectInternal in project gradle by gradle.
the class CppBasePlugin method apply.
@Override
public void apply(final Project project) {
project.getPluginManager().apply(NativeBasePlugin.class);
project.getPluginManager().apply(StandardToolChainsPlugin.class);
final TaskContainer tasks = project.getTasks();
final DirectoryProperty buildDirectory = project.getLayout().getBuildDirectory();
// Create the tasks for each C++ binary that is registered
project.getComponents().withType(DefaultCppBinary.class, binary -> {
final Names names = binary.getNames();
String language = "cpp";
TaskProvider<CppCompile> compile = tasks.register(names.getCompileTaskName(language), CppCompile.class, task -> {
final Callable<List<File>> systemIncludes = () -> binary.getPlatformToolProvider().getSystemLibraries(ToolType.CPP_COMPILER).getIncludeDirs();
task.includes(binary.getCompileIncludePath());
task.getSystemIncludes().from(systemIncludes);
task.source(binary.getCppSource());
if (binary.isDebuggable()) {
task.setDebuggable(true);
}
if (binary.isOptimized()) {
task.setOptimized(true);
}
task.getTargetPlatform().set(binary.getNativePlatform());
task.getToolChain().set(binary.getToolChain());
task.getObjectFileDir().set(buildDirectory.dir("obj/" + names.getDirName()));
if (binary instanceof CppSharedLibrary) {
task.setPositionIndependentCode(true);
}
});
binary.getObjectsDir().set(compile.flatMap(task -> task.getObjectFileDir()));
binary.getCompileTask().set(compile);
});
project.getComponents().withType(ProductionCppComponent.class, component -> {
project.afterEvaluate(p -> {
DefaultCppComponent componentInternal = (DefaultCppComponent) component;
publicationRegistry.registerPublication((ProjectInternal) project, new NativeProjectPublication(componentInternal.getDisplayName(), new SwiftPmTarget(component.getBaseName().get())));
});
});
}
use of org.gradle.api.internal.project.ProjectInternal 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.project.ProjectInternal in project gradle by gradle.
the class XCTestConventionPlugin method configureTestSuiteBuildingTasks.
private void configureTestSuiteBuildingTasks(final Project project, final DefaultSwiftXCTestBinary binary) {
// Overwrite the source to exclude `LinuxMain.swift`
SwiftCompile compile = binary.getCompileTask().get();
compile.getSource().setFrom(binary.getSwiftSource().getAsFileTree().matching(patterns -> patterns.include("**/*").exclude("**/LinuxMain.swift")));
if (binary instanceof SwiftXCTestBundle) {
TaskContainer tasks = project.getTasks();
final Names names = binary.getNames();
// TODO - creating a bundle should be done by some general purpose plugin
// TODO - make this lazy
final DefaultNativePlatform currentPlatform = new DefaultNativePlatform("current");
final ModelRegistry modelRegistry = ((ProjectInternal) project).getModelRegistry();
final NativeToolChain toolChain = modelRegistry.realize("toolChains", NativeToolChainRegistryInternal.class).getForPlatform(currentPlatform);
// Platform specific arguments
// TODO: Need to lazily configure compile task
// TODO: Ultimately, this should be some kind of 3rd party dependency that's visible to dependency management.
compile.getCompilerArgs().addAll(project.provider(() -> {
File platformSdkPath = sdkPlatformPathLocator.find();
File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
// Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
return Arrays.asList("-parse-as-library", "-F" + frameworkDir.getAbsolutePath(), "-I", extraInclude.getAbsolutePath(), "-v");
}));
// Add a link task
final TaskProvider<LinkMachOBundle> link = tasks.register(names.getTaskName("link"), LinkMachOBundle.class, task -> {
task.getLinkerArgs().set(project.provider(() -> {
File platformSdkPath = sdkPlatformPathLocator.find();
File frameworkDir = new File(platformSdkPath, "Developer/Library/Frameworks");
// Since Xcode 11/12, the XCTest framework is being replaced by a different library that's available in the sdk root
File extraInclude = new File(platformSdkPath, "Developer/usr/lib");
return Lists.newArrayList("-F" + frameworkDir.getAbsolutePath(), "-L", extraInclude.getAbsolutePath(), "-framework", "XCTest", "-Xlinker", "-rpath", "-Xlinker", "@executable_path/../Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/../Frameworks");
}));
task.source(binary.getObjects());
task.lib(binary.getLinkLibraries());
final PlatformToolProvider toolProvider = ((NativeToolChainInternal) toolChain).select(currentPlatform);
Provider<RegularFile> exeLocation = project.getLayout().getBuildDirectory().file(binary.getBaseName().map(baseName -> toolProvider.getExecutableName("exe/" + names.getDirName() + baseName)));
task.getLinkedFile().set(exeLocation);
task.getTargetPlatform().set(currentPlatform);
task.getToolChain().set(toolChain);
task.getDebuggable().set(binary.isDebuggable());
});
final TaskProvider<InstallXCTestBundle> install = tasks.register(names.getTaskName("install"), InstallXCTestBundle.class, task -> {
task.getBundleBinaryFile().set(link.get().getLinkedFile());
task.getInstallDirectory().set(project.getLayout().getBuildDirectory().dir("install/" + names.getDirName()));
});
binary.getInstallDirectory().set(install.flatMap(task -> task.getInstallDirectory()));
binary.getExecutableFile().set(link.flatMap(task -> task.getLinkedFile()));
DefaultSwiftXCTestBundle bundle = (DefaultSwiftXCTestBundle) binary;
bundle.getLinkTask().set(link);
bundle.getRunScriptFile().set(install.flatMap(task -> task.getRunScriptFile()));
} else {
DefaultSwiftXCTestExecutable executable = (DefaultSwiftXCTestExecutable) binary;
executable.getRunScriptFile().set(executable.getInstallTask().flatMap(task -> task.getRunScriptFile()));
// Rename `LinuxMain.swift` to `main.swift` so the entry point is correctly detected by swiftc
if (binary.getTargetMachine().getOperatingSystemFamily().isLinux()) {
TaskProvider<Sync> renameLinuxMainTask = project.getTasks().register("renameLinuxMain", Sync.class, task -> {
task.from(binary.getSwiftSource());
task.into(project.provider(() -> task.getTemporaryDir()));
task.include("LinuxMain.swift");
task.rename(it -> "main.swift");
});
compile.getSource().from(project.files(renameLinuxMainTask).getAsFileTree().matching(patterns -> patterns.include("**/*.swift")));
}
}
}
Aggregations