org.gradle.api.tasks.Copy Java Examples
The following examples show how to use
org.gradle.api.tasks.Copy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LegacyJavaComponentPlugin.java From Pushjet-Android with BSD 2-Clause "Simplified" License | 6 votes |
private void createProcessResourcesTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) { final BinaryNamingScheme namingScheme = binary.getNamingScheme(); binary.getSource().withType(JvmResourceSet.class).all(new Action<JvmResourceSet>() { public void execute(JvmResourceSet resourceSet) { Copy resourcesTask = target.getTasks().create(namingScheme.getTaskName("process", "resources"), ProcessResources.class); resourcesTask.setDescription(String.format("Processes %s.", resourceSet)); new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() { public File call() throws Exception { return binary.getResourcesDir(); } }); binary.getTasks().add(resourcesTask); binary.builtBy(resourcesTask); resourcesTask.from(resourceSet.getSource()); } }); }
Example #2
Source File: CuriostackRootPlugin.java From curiostack with MIT License | 6 votes |
private static void setupDataSources(Project project) { // TODO(choko): Preconfigure XML as well Configuration configuration = project.getConfigurations().create("jdbcDrivers"); project .getDependencies() .add(configuration.getName(), "com.google.cloud.sql:mysql-socket-factory"); project .getTasks() .register( "setupDataSources", Copy.class, t -> { t.from(configuration); t.into(".ideaDataSources/drivers"); }); }
Example #3
Source File: LegacyJavaComponentPlugin.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void createProcessResourcesTaskForBinary(final ClassDirectoryBinarySpecInternal binary, final Project target) { final BinaryNamingScheme namingScheme = binary.getNamingScheme(); binary.getSource().withType(JvmResourceSet.class).all(new Action<JvmResourceSet>() { public void execute(JvmResourceSet resourceSet) { Copy resourcesTask = target.getTasks().create(namingScheme.getTaskName("process", "resources"), ProcessResources.class); resourcesTask.setDescription(String.format("Processes %s.", resourceSet)); new DslObject(resourcesTask).getConventionMapping().map("destinationDir", new Callable<File>() { public File call() throws Exception { return binary.getResourcesDir(); } }); binary.getTasks().add(resourcesTask); binary.builtBy(resourcesTask); resourcesTask.from(resourceSet.getSource()); } }); }
Example #4
Source File: JavadocPlugin.java From shipkit with MIT License | 5 votes |
@Override public void apply(Project project) { project.getPlugins().apply(GitPlugin.class); ShipkitConfiguration conf = project.getPlugins().apply(ShipkitConfigurationPlugin.class).getConfiguration(); CloneGitRepositoryTask cloneJavadocTask = createCloneJavadocTask(project, conf); GitCheckOutTask checkoutJavadocRepoBranch = createCheckoutJavadocReposBranch(project, conf); checkoutJavadocRepoBranch.dependsOn(cloneJavadocTask); CopyTasks copyTasks = createCopyJavadocToStageTasks(project); Task refreshVersionJavadocTask = createRefreshVersionJavadocTask(project, copyTasks.copyToVersionTasks); Task refreshCurrentJavadocTask = createRefreshCurrentJavadocTask(project, copyTasks.copyToCurrentTasks); //refresh javadoc first so that if there is no javadoc we will avoid cloning cloneJavadocTask.mustRunAfter(refreshVersionJavadocTask); Copy copyStageToRepoDir = createCopyStageToRepoDirTask(project, conf); copyStageToRepoDir.dependsOn(checkoutJavadocRepoBranch, refreshVersionJavadocTask, refreshCurrentJavadocTask); GitCommitTask commitJavadocTask = createGitCommitTask(project, conf); commitJavadocTask.dependsOn(copyStageToRepoDir); GitPushTask pushJavadoc = createPushJavadocTask(project, conf); pushJavadoc.dependsOn(commitJavadocTask); Task releaseJavadocTask = createReleaseJavadocTask(project); releaseJavadocTask.dependsOn(cloneJavadocTask, commitJavadocTask, pushJavadoc); // To avoid missing of performRelease task, when org.shipkit.javadoc plugin is applied before org.shipkit.java DeferredConfiguration.deferredConfiguration(project, () -> { Task performReleaseTask = project.getRootProject().getTasks().findByName(PERFORM_RELEASE_TASK); if (performReleaseTask != null) { performReleaseTask.dependsOn(releaseJavadocTask); } }); deleteBuildDIrInRootProjectWhenCleanTask(project); }
Example #5
Source File: JdkDownloadPlugin.java From crate with Apache License 2.0 | 5 votes |
private static TaskProvider<?> createExtractTask( String taskName, Project rootProject, boolean isWindows, Provider<Directory> extractPath, Supplier<File> jdkBundle) { if (isWindows) { Action<CopySpec> removeRootDir = copy -> { // remove extra unnecessary directory levels copy.eachFile(details -> { Path newPathSegments = trimArchiveExtractPath(details.getRelativePath().getPathString()); String[] segments = StreamSupport.stream(newPathSegments.spliterator(), false) .map(Path::toString) .toArray(String[]::new); details.setRelativePath(new RelativePath(true, segments)); }); copy.setIncludeEmptyDirs(false); }; return rootProject.getTasks().register(taskName, Copy.class, copyTask -> { copyTask.doFirst(t -> rootProject.delete(extractPath)); copyTask.into(extractPath); Callable<FileTree> fileGetter = () -> rootProject.zipTree(jdkBundle.get()); copyTask.from(fileGetter, removeRootDir); }); } else { /* * Gradle TarFileTree does not resolve symlinks, so we have to manually * extract and preserve the symlinks. cf. https://github.com/gradle/gradle/issues/3982 * and https://discuss.gradle.org/t/tar-and-untar-losing-symbolic-links/2039 */ return rootProject.getTasks().register(taskName, SymbolicLinkPreservingUntarTask.class, task -> { task.getTarFile().fileProvider(rootProject.provider(jdkBundle::get)); task.getExtractPath().set(extractPath); task.setTransform(JdkDownloadPlugin::trimArchiveExtractPath); }); } }
Example #6
Source File: GitPublishPlugin.java From gradle-git-publish with Apache License 2.0 | 5 votes |
private Copy createCopyTask(Project project, GitPublishExtension extension) { return project.getTasks().create(COPY_TASK, Copy.class, task -> { task.setGroup("publishing"); task.setDescription("Copy contents to be published to git."); task.with(extension.getContents()); task.into(extension.getRepoDir()); }); }
Example #7
Source File: JavadocPlugin.java From shipkit with MIT License | 5 votes |
private Copy createCopyStageToRepoDirTask(Project project, ShipkitConfiguration conf) { String directory = conf.getLenient().getJavadoc().getRepositoryDirectory(); return TaskMaker.task(project, COPY_JAVADOC_STAGE_TO_REPO_DIR_TASK, Copy.class, task -> { task.setDescription("Copy prepared Javadocs from stage directory to the repository directory"); task.from(getJavadocStageDir(project)); task.into(getJavadocRepoCloneDir(project, directory)); }); }
Example #8
Source File: JavadocPlugin.java From shipkit with MIT License | 5 votes |
private CopyTasks createCopyJavadocToStageTasks(Project project) { Set<Copy> copyToVersionTasks = new HashSet<>(); Set<Copy> copyToCurrentTasks = new HashSet<>(); Set<Task> javadocJarSet = project.getTasksByName("javadocJar", true); if (javadocJarSet.isEmpty()) { LOGGER.warn("Not found any 'javadocJar' task. You probably applied 'org.shipkit.javadoc' plugin before 'org.shipkit.java'. " + "Please apply 'org.shipkit.java' plugin first!"); } javadocJarSet.stream() .map(task -> (Jar) task) .forEach(javadocJarTask -> { Copy copyToVersionTask = TaskMaker.task(javadocJarTask.getProject(), COPY_JAVADOC_TO_STAGE_VERSION_DIR_TASK, Copy.class, copyTask -> { copyTask.setDescription("Extracts contents of javadoc jar to the staging /version directory"); copyTask.dependsOn(javadocJarTask); copyTask.from(project.zipTree(javadocJarTask.getArchivePath())); // TODO how? : note that we need to use Closure/Callable because 'baseName' can be set by user later copyTask.into(getJavadocStageDir(project) + "/" + javadocJarTask.getBaseName() + "/" + project.getVersion()); }); copyToVersionTasks.add(copyToVersionTask); Copy copyToCurrentTask = TaskMaker.task(javadocJarTask.getProject(), COPY_JAVADOC_TO_STAGE_CURRENT_DIR_TASK, Copy.class, copyTask -> { copyTask.setDescription("Extracts contents of javadoc jar to the staging /current directory"); copyTask.dependsOn(copyToVersionTask); copyTask.from(copyToVersionTask.getDestinationDir()); // TODO how? : note that we need to use Closure/Callable because 'baseName' can be set by user later copyTask.into(getJavadocStageDir(project) + "/" + javadocJarTask.getBaseName() + "/current"); }); copyToCurrentTasks.add(copyToCurrentTask); }); return new CopyTasks(copyToVersionTasks, copyToCurrentTasks); }
Example #9
Source File: JavaBasePlugin.java From javaide with GNU General Public License v3.0 | 5 votes |
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); }
Example #10
Source File: CloudV2Plugin.java From commerce-gradle-plugin with Apache License 2.0 | 5 votes |
private void configureCloudExtensionPackBootstrap(Project project, boolean useCloudExtensionPack) { if (!useCloudExtensionPack) { return; } Task cleanCep = project.getTasks().create("cleanCloudExtensionPack", Delete.class, d -> { d.delete(extension.getCloudExtensionPackFolder().getAsFile()); }); Copy unpackCep = project.getTasks().create("unpackCloudExtensionPack", Copy.class, c -> { c.dependsOn(cleanCep); c.from(project.provider(() -> project.getConfigurations() .getByName(EXTENSION_PACK) .getFiles() .stream() .map(project::zipTree) .collect(Collectors.toSet()) ) ); c.into(extension.getCloudExtensionPackFolder().getAsFile()); c.doLast(a -> project.getConfigurations().getByName(EXTENSION_PACK) .getResolvedConfiguration() .getFirstLevelModuleDependencies() .forEach(r -> a.getLogger().lifecycle("Using Cloud Extension Pack: {}", r.getModuleVersion()))); }); Task bootstrapPlatform = project.getTasks().getByName("bootstrapPlatform"); bootstrapPlatform.dependsOn(unpackCep); String reservedTypeCodes = "hybris/bin/platform/ext/core/resources/core/unittest/reservedTypecodes.txt"; Copy copyTypeCodes = project.getTasks().create("copyCEPTypeCode", Copy.class, c -> { c.mustRunAfter(unpackCep); c.mustRunAfter("unpackPlatform"); c.from(extension.getCloudExtensionPackFolder().file(reservedTypeCodes)); c.into(project.file(reservedTypeCodes).getParent()); }); bootstrapPlatform.dependsOn(copyTypeCodes); PatchLocalExtensions patch = project.getTasks().create("patchLocalExtensions", PatchLocalExtensions.class, p -> { p.getTarget().set(project.file("hybris/config/localextensions.xml")); p.getCepFolder().set(extension.getCloudExtensionPackFolder()); }); bootstrapPlatform.dependsOn(patch); }
Example #11
Source File: CloudServicesPackagingPlugin.java From commerce-gradle-plugin with Apache License 2.0 | 5 votes |
private void setupSolrPackaging(Project p, PackagingExtension extension, Path packageFolder, Zip zipPackage, Task cleanTargetFolder) { // FIXME This is only POC for Solr configuration only. Set<String> environments = extension.getEnvironments().get(); Path configurationFolder = extension.getConfigurationFolder().getAsFile().get().toPath(); for (String environment : environments) { Path sourceFolder = configurationFolder.resolve(environment).resolve("solr"); Path commonFolder = configurationFolder.resolve(COMMON_CONFIG).resolve("solr"); Path targetFolder = packageFolder.resolve("solr/config/" + environment); Copy copySolrCommonConfig = p.getTasks().create("copySolrCommonEnv_" + environment, Copy.class, t -> { t.from(commonFolder); t.into(targetFolder); t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); t.exclude(SOLR_CONFIG_EXCLUDE); }); copySolrCommonConfig.dependsOn(cleanTargetFolder); Copy copySolrConfig = p.getTasks().create("copySolrEnv_" + environment, Copy.class, t -> { t.from(sourceFolder); t.into(targetFolder); t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); t.exclude(SOLR_CONFIG_EXCLUDE); }); copySolrConfig.dependsOn(copySolrCommonConfig); zipPackage.dependsOn(copySolrConfig); } }
Example #12
Source File: PythonFlyerPlugin.java From pygradle with Apache License 2.0 | 4 votes |
@Override public void apply(final Project project) { project.getPlugins().apply(PythonWebApplicationPlugin.class); /* * This configuration is used to connect the Python project to the Ember project. * We will use this configuration to access the static resource, create the symlink and package the resource. */ final Configuration resourceConf = project.getConfigurations().create("resource"); /* * Under the Python project, we need to make a link to the Ember resource(<ember-project>/dist for now). * By doing this, it becomes easier for the Python project to access the resource files. * And for both local development and LID deployment, the resource folder will have the * same relative directory. This will also simplify the logic in python project. */ project.getTasks().create(TASK_SETUP_RESOURCE_LINK, task -> { task.dependsOn(resourceConf); task.doLast(it -> { if (!Paths.get(project.getProjectDir().getAbsolutePath(), "resource").toFile().exists()) { project.getLogger().lifecycle("Making the Symlink: {}{}resource --> {}", project.getProjectDir(), File.separatorChar, String.valueOf(resourceConf.getSingleFile())); FileSystemUtils.makeSymLinkUnchecked(resourceConf.getSingleFile(), new File(project.getProjectDir(), "resource")); } }); }); project.getTasks().getByName(StandardTextValues.TASK_INSTALL_PROJECT.getValue()) .dependsOn(project.getTasks().getByName(TASK_SETUP_RESOURCE_LINK)); /* * In order to make the resource files accessible when deploying the project, we need to copy the * static files into the 'deployable' directory. */ project.getTasks().create(TASK_PACKAGE_RESOURCE_FILES, Copy.class, copy -> { final DeployableExtension deployableExtension = ExtensionUtils.maybeCreateDeployableExtension(project); copy.dependsOn(project.getTasks().getByName(PythonWebApplicationPlugin.TASK_BUILD_WEB_APPLICATION)); copy.from(resourceConf); copy.into(deployableExtension.getDeployableBuildDir().toPath().resolve("resource")); }); // Make sure we've copied all the files before running the task: packageDeployable project.getTasks().getByName(ApplicationContainer.TASK_PACKAGE_DEPLOYABLE) .dependsOn(project.getTasks().getByName(TASK_PACKAGE_RESOURCE_FILES)); }
Example #13
Source File: StaticSitePlugin.java From curiostack with MIT License | 4 votes |
@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); } }); }
Example #14
Source File: JavadocPlugin.java From shipkit with MIT License | 4 votes |
private Task createRefreshVersionJavadocTask(Project project, Set<Copy> copyToVersionTasks) { return TaskMaker.task(project, REFRESH_VERSION_JAVADOC_TASK, task -> { task.dependsOn(copyToVersionTasks); task.setDescription("Copy Javadocs from all modules to the staging /version directory"); }); }
Example #15
Source File: JavadocPlugin.java From shipkit with MIT License | 4 votes |
private Task createRefreshCurrentJavadocTask(Project project, Set<Copy> copyToCurrentTasks) { return TaskMaker.task(project, REFRESH_CURRENT_JAVADOC_TASK, task -> { task.dependsOn(copyToCurrentTasks); task.setDescription("Copy Javadocs from all modules to the staging /current directory"); }); }
Example #16
Source File: JavadocPlugin.java From shipkit with MIT License | 4 votes |
private CopyTasks(Set<Copy> copyToVersionTasks, Set<Copy> copyToCurrentTasks) { this.copyToVersionTasks = copyToVersionTasks; this.copyToCurrentTasks = copyToCurrentTasks; }
Example #17
Source File: CloudServicesPackagingPlugin.java From commerce-gradle-plugin with Apache License 2.0 | 4 votes |
private void setupDatahubPackaging(Project p, PackagingExtension extension, Path packageFolder, Zip zipPackage, Task cleanTargetFolder) { Copy copyDataHubWar = p.getTasks().create("copyDataHubWar", Copy.class, t -> { t.from(extension.getDatahubWar(), s -> s.rename(".*", "datahub-webapp.war")); t.into(packageFolder.resolve("datahub/bin")); t.onlyIf(a -> { if (a.getInputs().getSourceFiles().isEmpty()) { throw new StopExecutionException("no datahub file found"); } return true; }); }); copyDataHubWar.dependsOn(cleanTargetFolder); zipPackage.dependsOn(copyDataHubWar); Set<String> environments = extension.getEnvironments().get(); Path configurationFolder = extension.getConfigurationFolder().getAsFile().get().toPath(); for (String environment : environments) { Path sourceFolder = configurationFolder.resolve(environment).resolve("datahub"); Path commonFolder = configurationFolder.resolve(COMMON_CONFIG).resolve("datahub"); Path targetFolder = packageFolder.resolve("datahub/config/" + environment); Copy copyCommonConfig = p.getTasks().create("copyDatahubCommonEnv_" + environment, Copy.class, t -> { t.from(commonFolder); t.into(targetFolder); t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); t.exclude(DATAHUB_CONFIG_EXCLUDE); }); copyCommonConfig.dependsOn(cleanTargetFolder); Copy copyDatahubConfig = p.getTasks().create("copyDatahubEnv_" + environment, Copy.class, t -> { t.from(sourceFolder); t.into(targetFolder); t.setDuplicatesStrategy(DuplicatesStrategy.INCLUDE); t.exclude(DATAHUB_CONFIG_EXCLUDE); }); copyDatahubConfig.dependsOn(copyCommonConfig); MergePropertyFiles mergeProperties = p.getTasks().create("mergeDatahub_customer.properties_" + environment, MergePropertyFiles.class, t -> { t.getInputFiles().setFrom(Arrays.asList( commonFolder.resolve("customer.properties"), sourceFolder.resolve("customer.properties") )); t.setOutputFile(targetFolder.resolve("customer.properties")); }); mergeProperties.dependsOn(copyDatahubConfig); zipPackage.dependsOn(mergeProperties); } }