use of org.gradle.api.tasks.Copy in project rest.li by linkedin.
the class PegasusPlugin method configureRestModelGeneration.
protected void configureRestModelGeneration(Project project, SourceSet sourceSet) {
if (sourceSet.getAllSource().isEmpty()) {
project.getLogger().info("No source files found for sourceSet {}. Skipping idl generation.", sourceSet.getName());
return;
}
// afterEvaluate needed so that api project can be overridden via ext.apiProject
project.afterEvaluate(p -> {
// find api project here instead of in each project's plugin configuration
// this allows api project relation options (ext.api*) to be specified anywhere in the build.gradle file
// alternatively, pass closures to task configuration, and evaluate the closures when task is executed
Project apiProject = getCheckedApiProject(project);
// make sure the api project is evaluated. Important for configure-on-demand mode.
if (apiProject != null) {
project.evaluationDependsOn(apiProject.getPath());
if (!apiProject.getPlugins().hasPlugin(_thisPluginType)) {
apiProject = null;
}
}
if (apiProject == null) {
return;
}
Task untypedJarTask = project.getTasks().findByName(sourceSet.getJarTaskName());
if (!(untypedJarTask instanceof Jar)) {
return;
}
Jar jarTask = (Jar) untypedJarTask;
String snapshotCompatPropertyName = findProperty(FileCompatibilityType.SNAPSHOT);
if (project.hasProperty(snapshotCompatPropertyName) && "off".equalsIgnoreCase((String) project.property(snapshotCompatPropertyName))) {
project.getLogger().lifecycle("Project {} snapshot compatibility level \"OFF\" is deprecated. Default to \"IGNORE\".", project.getPath());
}
// generate the rest model
FileCollection restModelCodegenClasspath = project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION).plus(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME)).plus(sourceSet.getRuntimeClasspath());
String destinationDirPrefix = getGeneratedDirPath(project, sourceSet, REST_GEN_TYPE) + File.separatorChar;
FileCollection restModelResolverPath = apiProject.files(getDataSchemaPath(project, sourceSet)).plus(getDataModelConfig(apiProject, sourceSet));
Set<File> watchedRestModelInputDirs = buildWatchedRestModelInputDirs(project, sourceSet);
Set<File> restModelInputDirs = difference(sourceSet.getAllSource().getSrcDirs(), sourceSet.getResources().getSrcDirs());
Task generateRestModelTask = project.getTasks().create(sourceSet.getTaskName("generate", "restModel"), GenerateRestModelTask.class, task -> {
task.dependsOn(project.getTasks().getByName(sourceSet.getClassesTaskName()));
task.setCodegenClasspath(restModelCodegenClasspath);
task.setWatchedCodegenClasspath(restModelCodegenClasspath.filter(file -> !"main".equals(file.getName()) && !"classes".equals(file.getName())));
task.setInputDirs(restModelInputDirs);
task.setWatchedInputDirs(watchedRestModelInputDirs.isEmpty() ? restModelInputDirs : watchedRestModelInputDirs);
// we need all the artifacts from runtime for any private implementation classes the server code might need.
task.setSnapshotDestinationDir(project.file(destinationDirPrefix + "snapshot"));
task.setIdlDestinationDir(project.file(destinationDirPrefix + "idl"));
@SuppressWarnings("unchecked") Map<String, PegasusOptions> pegasusOptions = (Map<String, PegasusOptions>) project.getExtensions().getExtraProperties().get("pegasus");
task.setIdlOptions(pegasusOptions.get(sourceSet.getName()).idlOptions);
task.setResolverPath(restModelResolverPath);
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> !isPropertyTrue(project, SKIP_GENERATE_REST_MODEL));
task.doFirst(new CacheableAction<>(t -> deleteGeneratedDir(project, sourceSet, REST_GEN_TYPE)));
});
File apiSnapshotDir = apiProject.file(getSnapshotPath(apiProject, sourceSet));
File apiIdlDir = apiProject.file(getIdlPath(apiProject, sourceSet));
apiSnapshotDir.mkdirs();
if (!isPropertyTrue(project, SKIP_IDL_CHECK)) {
apiIdlDir.mkdirs();
}
CheckRestModelTask checkRestModelTask = project.getTasks().create(sourceSet.getTaskName("check", "RestModel"), CheckRestModelTask.class, task -> {
task.dependsOn(generateRestModelTask);
task.setCurrentSnapshotFiles(SharedFileUtils.getSnapshotFiles(project, destinationDirPrefix));
task.setPreviousSnapshotDirectory(apiSnapshotDir);
task.setCurrentIdlFiles(SharedFileUtils.getIdlFiles(project, destinationDirPrefix));
task.setPreviousIdlDirectory(apiIdlDir);
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
task.setModelCompatLevel(PropertyUtil.findCompatLevel(project, FileCompatibilityType.SNAPSHOT));
task.onlyIf(t -> !isPropertyTrue(project, SKIP_IDL_CHECK));
task.doLast(new CacheableAction<>(t -> {
if (!task.isEquivalent()) {
_restModelCompatMessage.append(task.getWholeMessage());
}
}));
});
CheckSnapshotTask checkSnapshotTask = project.getTasks().create(sourceSet.getTaskName("check", "Snapshot"), CheckSnapshotTask.class, task -> {
task.dependsOn(generateRestModelTask);
task.setCurrentSnapshotFiles(SharedFileUtils.getSnapshotFiles(project, destinationDirPrefix));
task.setPreviousSnapshotDirectory(apiSnapshotDir);
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
task.setSnapshotCompatLevel(PropertyUtil.findCompatLevel(project, FileCompatibilityType.SNAPSHOT));
task.onlyIf(t -> isPropertyTrue(project, SKIP_IDL_CHECK));
});
CheckIdlTask checkIdlTask = project.getTasks().create(sourceSet.getTaskName("check", "Idl"), CheckIdlTask.class, task -> {
task.dependsOn(generateRestModelTask);
task.setCurrentIdlFiles(SharedFileUtils.getIdlFiles(project, destinationDirPrefix));
task.setPreviousIdlDirectory(apiIdlDir);
task.setResolverPath(restModelResolverPath);
task.setCodegenClasspath(project.getConfigurations().getByName(PEGASUS_PLUGIN_CONFIGURATION));
task.setIdlCompatLevel(PropertyUtil.findCompatLevel(project, FileCompatibilityType.IDL));
if (isPropertyTrue(project, ENABLE_ARG_FILE)) {
task.setEnableArgFile(true);
}
task.onlyIf(t -> !isPropertyTrue(project, SKIP_IDL_CHECK) && !"OFF".equals(PropertyUtil.findCompatLevel(project, FileCompatibilityType.IDL)));
});
// rest model publishing involves cross-project reference
// configure after all projects have been evaluated
// the file copy can be turned off by "rest.model.noPublish" flag
Task publishRestliSnapshotTask = project.getTasks().create(sourceSet.getTaskName("publish", "RestliSnapshot"), PublishRestModelTask.class, task -> {
task.dependsOn(checkRestModelTask, checkSnapshotTask, checkIdlTask);
task.from(SharedFileUtils.getSnapshotFiles(project, destinationDirPrefix));
task.into(apiSnapshotDir);
task.setSuffix(SNAPSHOT_FILE_SUFFIX);
task.onlyIf(t -> !isPropertyTrue(project, SNAPSHOT_NO_PUBLISH) && ((isPropertyTrue(project, SKIP_IDL_CHECK) && isTaskSuccessful(checkSnapshotTask) && checkSnapshotTask.getSummaryTarget().exists() && !isResultEquivalent(checkSnapshotTask.getSummaryTarget())) || (!isPropertyTrue(project, SKIP_IDL_CHECK) && isTaskSuccessful(checkRestModelTask) && checkRestModelTask.getSummaryTarget().exists() && !isResultEquivalent(checkRestModelTask.getSummaryTarget()))));
});
Task publishRestliIdlTask = project.getTasks().create(sourceSet.getTaskName("publish", "RestliIdl"), PublishRestModelTask.class, task -> {
task.dependsOn(checkRestModelTask, checkIdlTask, checkSnapshotTask);
task.from(SharedFileUtils.getIdlFiles(project, destinationDirPrefix));
task.into(apiIdlDir);
task.setSuffix(IDL_FILE_SUFFIX);
task.onlyIf(t -> !isPropertyTrue(project, IDL_NO_PUBLISH) && ((isPropertyTrue(project, SKIP_IDL_CHECK) && isTaskSuccessful(checkSnapshotTask) && checkSnapshotTask.getSummaryTarget().exists() && !isResultEquivalent(checkSnapshotTask.getSummaryTarget(), true)) || (!isPropertyTrue(project, SKIP_IDL_CHECK) && ((isTaskSuccessful(checkRestModelTask) && checkRestModelTask.getSummaryTarget().exists() && !isResultEquivalent(checkRestModelTask.getSummaryTarget(), true)) || (isTaskSuccessful(checkIdlTask) && checkIdlTask.getSummaryTarget().exists() && !isResultEquivalent(checkIdlTask.getSummaryTarget()))))));
});
project.getLogger().info("API project selected for {} is {}", publishRestliIdlTask.getPath(), apiProject.getPath());
jarTask.from(SharedFileUtils.getIdlFiles(project, destinationDirPrefix));
// add generated .restspec.json files as resources to the jar
jarTask.dependsOn(publishRestliSnapshotTask, publishRestliIdlTask);
ChangedFileReportTask changedFileReportTask = (ChangedFileReportTask) project.getTasks().getByName("changedFilesReport");
// Use the files from apiDir for generating the changed files report as we need to notify user only when
// source system files are modified.
changedFileReportTask.setIdlFiles(SharedFileUtils.getSuffixedFiles(project, apiIdlDir, IDL_FILE_SUFFIX));
changedFileReportTask.setSnapshotFiles(SharedFileUtils.getSuffixedFiles(project, apiSnapshotDir, SNAPSHOT_FILE_SUFFIX));
changedFileReportTask.mustRunAfter(publishRestliSnapshotTask, publishRestliIdlTask);
changedFileReportTask.doLast(new CacheableAction<>(t -> {
if (!changedFileReportTask.getNeedCheckinFiles().isEmpty()) {
project.getLogger().info("Adding modified files to need checkin list...");
_needCheckinFiles.addAll(changedFileReportTask.getNeedCheckinFiles());
_needBuildFolders.add(getCheckedApiProject(project).getPath());
}
}));
});
}
use of org.gradle.api.tasks.Copy in project checkstyle-idea by jshiell.
the class GradlePluginMain method createCopyCheckstyleArtifactsToSandboxTask.
private void createCopyCheckstyleArtifactsToSandboxTask(final Project project, final boolean test) {
final TaskContainer tasks = project.getTasks();
final String taskName = test ? "copyCheckstyleArtifactsToTestSandbox" : "copyCheckstyleArtifactsToSandbox";
final TaskProvider<Copy> taskProvider = tasks.register(taskName, Copy.class);
taskProvider.configure((Copy copyTask) -> {
copyTask.setGroup("intellij");
copyTask.setDescription("Adds the gathered Checkstyle artifacts to the prepared " + (test ? "test " : "") + "sandbox");
final GatherCheckstyleArtifactsTask gatherTask = (GatherCheckstyleArtifactsTask) tasks.getByName(GatherCheckstyleArtifactsTask.NAME);
copyTask.dependsOn(gatherTask, "prepareTestingSandbox");
if (test) {
tasks.getByName(JavaPlugin.TEST_TASK_NAME).dependsOn(copyTask);
tasks.getByName(CsaccessTestTask.NAME).dependsOn(copyTask);
forEachXTest(tasks, xTask -> xTask.dependsOn(copyTask));
} else {
tasks.getByName("buildSearchableOptions").dependsOn(copyTask);
}
copyTask.from(gatherTask.getBundledJarsDir());
copyTask.into(new File(project.getBuildDir(), "idea-sandbox/plugins" + (test ? "-test" : "") + "/CheckStyle-IDEA/" + CSLIB_TARGET_SUBFOLDER));
});
}
use of org.gradle.api.tasks.Copy in project gradle by gradle.
the class JavaBasePlugin method createProcessResourcesTaskForBinary.
private void createProcessResourcesTaskForBinary(final SourceSet sourceSet, SourceDirectorySet resourceSet, final Project target) {
Copy resourcesTask = target.getTasks().create(sourceSet.getProcessResourcesTaskName(), ProcessResources.class);
resourcesTask.setDescription("Processes " + resourceSet + ".");
new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() {
public File call() throws Exception {
return sourceSet.getOutput().getResourcesDir();
}
});
resourcesTask.from(resourceSet);
}
use of org.gradle.api.tasks.Copy in project spring-boot by spring-projects.
the class MavenPluginPlugin method addPopulateIntTestMavenRepositoryTask.
private void addPopulateIntTestMavenRepositoryTask(Project project) {
Configuration runtimeClasspathWithMetadata = project.getConfigurations().create("runtimeClasspathWithMetadata");
runtimeClasspathWithMetadata.extendsFrom(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
runtimeClasspathWithMetadata.attributes((attributes) -> attributes.attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.getObjects().named(DocsType.class, "maven-repository")));
RuntimeClasspathMavenRepository runtimeClasspathMavenRepository = project.getTasks().create("runtimeClasspathMavenRepository", RuntimeClasspathMavenRepository.class);
runtimeClasspathMavenRepository.getOutputDirectory().set(new File(project.getBuildDir(), "runtime-classpath-repository"));
project.getDependencies().components((components) -> components.all(MavenRepositoryComponentMetadataRule.class));
Copy task = project.getTasks().create("populateIntTestMavenRepository", Copy.class);
task.setDestinationDir(new File(project.getBuildDir(), "int-test-maven-repository"));
task.with(copyIntTestMavenRepositoryFiles(project, runtimeClasspathMavenRepository));
task.dependsOn(project.getTasks().getByName(MavenRepositoryPlugin.PUBLISH_TO_PROJECT_REPOSITORY_TASK_NAME));
project.getTasks().getByName(IntegrationTestPlugin.INT_TEST_TASK_NAME).dependsOn(task);
}
use of org.gradle.api.tasks.Copy in project curiostack by curioswitch.
the class StaticSitePlugin method apply.
@Override
public void apply(Project project) {
project.getPlugins().apply(NodePlugin.class);
var config = StaticSiteExtension.create(project);
var mergeSite = project.getTasks().register("mergeSite", Copy.class, t -> {
t.from("src");
t.into("build/site");
for (SiteProject site : config.getSites().get()) {
site.getProject().getPlugins().withType(LifecycleBasePlugin.class, unused -> t.dependsOn(site.getProject().getTasks().named(LifecycleBasePlugin.ASSEMBLE_TASK_NAME)));
t.from(site.getBuildDir(), copy -> copy.into(site.getOutputSubDir()));
}
});
var assemble = project.getTasks().named("assemble");
assemble.configure(t -> t.dependsOn(mergeSite));
var yarn = project.getRootProject().getTasks().named("yarn");
var deployAlpha = project.getTasks().register("deployAlpha", GcloudTask.class, t -> {
t.dependsOn(assemble);
// TODO(choko): Remove this major hack - the command line has two --project flags
// and we're just lucky the later is used.
t.args(config.getAppEngineProject().map(appEngineProject -> ImmutableList.of("app", "deploy", "--project=" + appEngineProject)));
});
var deployProd = project.getTasks().register("deployProd", NodeTask.class, t -> {
t.dependsOn(yarn, assemble);
t.args(config.getFirebaseProject().map(firebaseProject -> ImmutableList.of("run", "firebase", "--project", firebaseProject, "deploy")));
});
project.getTasks().register("preview", NodeTask.class, t -> {
t.dependsOn(yarn, assemble);
t.args("run", "superstatic", "--port=8080");
});
CurioGenericCiPlugin.addToReleaseBuild(project, deployProd);
project.afterEvaluate(unused -> {
if (config.getAutoDeployAlpha().get()) {
CurioGenericCiPlugin.addToMasterBuild(project, deployAlpha);
}
});
}
Aggregations