org.gradle.api.file.CopySpec Java Examples

The following examples show how to use org.gradle.api.file.CopySpec. 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: JavaLibraryPlugin.java    From shipkit with MIT License 6 votes vote down vote up
@Override
public void apply(final Project project) {
    project.getPlugins().apply("java");

    final CopySpec license = project.copySpec(copy -> copy.from(project.getRootDir()).include("LICENSE"));

    ((Jar) project.getTasks().getByName("jar")).with(license);

    final Jar sourcesJar = project.getTasks().create(SOURCES_JAR_TASK, Jar.class, jar -> {
        jar.from(JavaPluginUtil.getMainSourceSet(project).getAllSource());
        jar.setClassifier("sources");
        jar.with(license);
    });

    final Task javadocJar = project.getTasks().create(JAVADOC_JAR_TASK, Jar.class, jar -> {
        jar.from(project.getTasks().getByName("javadoc"));
        jar.setClassifier("javadoc");
        jar.with(license);
    });

    project.getArtifacts().add("archives", sourcesJar);
    project.getArtifacts().add("archives", javadocJar);
}
 
Example #2
Source File: LibraryCache.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
public static void unzipAar(final File bundle, final File folderOut, final Project project) throws IOException {
    FileUtils.deleteFolder(folderOut);
    folderOut.mkdirs();
    project.copy(new Action<CopySpec>() {
        @Override
        public void execute(CopySpec copySpec) {
            copySpec.from(project.zipTree(bundle));
            copySpec.into(new Object[]{folderOut});
            copySpec.filesMatching("**/*.jar", new Action<FileCopyDetails>() {
                @Override
                public void execute(FileCopyDetails details) {
                    setRelativePath(details, new RelativePath(false, FD_JARS).plus(details.getRelativePath()));
                }
            });
        }
    });
}
 
Example #3
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

    String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
    String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

    File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
    Action<CopySpec> extractOverlay = copySpec -> {
        copySpec.into(destinationDir);
        copySpec.from(warTree);
    };

    Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            project.sync(extractOverlay);
        }

        project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

        ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                .builtBy(extractOverlayTask);

        project.getDependencies().add(getClasspathConfigurationName(overlay), classes);

        FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #4
Source File: DefaultConfigurableFileTree.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public WorkResult copy(final Closure closure) {
    return fileCopier.copy(new Action<CopySpec>() {
        public void execute(CopySpec copySpec) {
            copySpec.from(DefaultConfigurableFileTree.this);
            ConfigureUtil.configure(closure, copySpec);
        }
    });
}
 
Example #5
Source File: WarOverlayPlugin.java    From gradle-plugins with MIT License 5 votes vote down vote up
private void configureOverlay(WarOverlay overlay, Callable<FileTree> warTree) {
    War warTask = overlay.getWarTask();

    String capitalizedWarTaskName = StringGroovyMethods.capitalize((CharSequence) warTask.getName());
    String capitalizedOverlayName = StringGroovyMethods.capitalize((CharSequence) overlay.getName());

    File destinationDir = new File(project.getBuildDir(), String.format("overlays/%s/%s", warTask.getName(), overlay.getName()));
    Action<CopySpec> extractOverlay = copySpec -> {
        copySpec.into(destinationDir);
        copySpec.from(warTree);
    };

    Sync extractOverlayTask = project.getTasks().create(String.format("extract%s%sOverlay", capitalizedOverlayName, capitalizedWarTaskName), Sync.class, extractOverlay);

    overlay.getWarCopySpec().from(extractOverlayTask);

    if (overlay.isEnableCompilation()) {

        if (!destinationDir.exists() || isEmpty(destinationDir)) {
            project.sync(extractOverlay);
        }

        project.getTasks().getByName(CLEAN_TASK_NAME).finalizedBy(extractOverlayTask);

        ConfigurableFileCollection classes = project.files(new File(destinationDir, "WEB-INF/classes"))
                .builtBy(extractOverlayTask);

        project.getDependencies().add(getClasspathConfigurationName(overlay), classes);

        FileTree libs = project.files(extractOverlayTask).builtBy(extractOverlayTask).getAsFileTree()
                .matching(patternFilterable -> patternFilterable.include("WEB-INF/lib/**"));

        project.getDependencies().add(getClasspathConfigurationName(overlay), libs);
    }
}
 
Example #6
Source File: FileCopier.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private DestinationRootCopySpec createCopySpec(Action<? super CopySpec> action) {
    DefaultCopySpec copySpec = new DefaultCopySpec(this.fileResolver, instantiator);
    DestinationRootCopySpec destinationRootCopySpec = new DestinationRootCopySpec(fileResolver, copySpec);
    CopySpec wrapped = instantiator.newInstance(CopySpecWrapper.class, destinationRootCopySpec);
    action.execute(wrapped);
    return destinationRootCopySpec;
}
 
Example #7
Source File: DefaultConfigurableFileTree.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public WorkResult copy(final Closure closure) {
    return fileCopier.copy(new Action<CopySpec>() {
        public void execute(CopySpec copySpec) {
            copySpec.from(DefaultConfigurableFileTree.this);
            ConfigureUtil.configure(closure, copySpec);
        }
    });
}
 
Example #8
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(Iterable<String> includes) {
    return getWarCopySpec().include(includes);
}
 
Example #9
Source File: GitPublishExtension.java    From gradle-git-publish with Apache License 2.0 4 votes vote down vote up
public CopySpec getContents() {
  return contents;
}
 
Example #10
Source File: GenerateClientLibrarySourceTask.java    From endpoints-framework-gradle-plugin with Apache License 2.0 4 votes vote down vote up
/** Task entry point. */
@TaskAction
public void generateSource() {
  boolean x = getProject().delete(generatedSrcDir);
  File[] zips =
      getClientLibDir()
          .listFiles(
              new FilenameFilter() {
                @Override
                public boolean accept(File dir, String name) {
                  return name.endsWith(".zip");
                }
              });

  final File tmpDir = new File(getTemporaryDir(), "endpoints-tmp");
  getProject().delete(tmpDir);
  getProject().mkdir(tmpDir);
  for (final File zip : zips) {
    // Use ant unzip, gradle unzip is having issues
    // with strangely formed client libraries
    getAnt()
        .invokeMethod(
            "unzip",
            new HashMap<String, String>() {
              {
                put("src", zip.getPath());
                put("dest", tmpDir.getPath());
              }
            });
  }

  for (File unzippedDir : tmpDir.listFiles()) {
    final File srcDir = new File(unzippedDir, "src/main/java");
    if (srcDir.exists() && srcDir.isDirectory()) {
      getProject()
          .copy(
              new Action<CopySpec>() {
                @Override
                public void execute(CopySpec copySpec) {
                  copySpec.from(srcDir);
                  copySpec.into(generatedSrcDir);
                }
              });
    }
  }
}
 
Example #11
Source File: AbstractProject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult sync(Action<? super CopySpec> action) {
    return fileOperations.sync(action);
}
 
Example #12
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(Closure includeSpec) {
    return getWarCopySpec().include(includeSpec);
}
 
Example #13
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(Spec<FileTreeElement> includeSpec) {
    return getWarCopySpec().include(includeSpec);
}
 
Example #14
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Action<? super CopySpec> action) {
    return fileOperations.copySpec(action);
}
 
Example #15
Source File: Jar.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Internal
public CopySpec getMetaInf() {
    return metaInf.addChild();
}
 
Example #16
Source File: PlayDistributionPlugin.java    From playframework with Apache License 2.0 4 votes vote down vote up
private void createDistributionContentTasks(Project project, Distribution distribution) {
    PlayExtension playExtension = (PlayExtension) project.getExtensions().getByName(PlayApplicationPlugin.PLAY_EXTENSION_NAME);
    TaskProvider<Jar> mainJarTask = project.getTasks().named(JAR_TASK_NAME, Jar.class);
    TaskProvider<Jar> assetsJarTask = project.getTasks().named(PlayApplicationPlugin.ASSETS_JAR_TASK_NAME, Jar.class);

    final File distJarDir = new File(project.getBuildDir(), "distributionJars/" + distribution.getName());
    final String capitalizedDistName = capitalizeDistributionName(distribution.getName());
    final String jarTaskName = "create" + capitalizedDistName + "DistributionJar";

    TaskProvider<Jar> distributionJarTask = project.getTasks().register(jarTaskName, Jar.class, jar -> {
        jar.setDescription("Assembles an application jar suitable for deployment.");
        jar.dependsOn(mainJarTask, assetsJarTask);
        jar.from(project.zipTree(mainJarTask.get().getArchivePath()));
        jar.setDestinationDir(distJarDir);
        jar.setBaseName(mainJarTask.get().getBaseName());

        Map<String, Object> classpath = new HashMap<>();
        classpath.put("Class-Path", new PlayManifestClasspath(project.getConfigurations().getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME), assetsJarTask.get().getArchivePath()));
        jar.getManifest().attributes(classpath);
    });

    final File scriptsDir = new File(project.getBuildDir(), "scripts");
    String createStartScriptsTaskName = "create" + capitalizedDistName + "StartScripts";
    TaskProvider<CreateStartScripts> createStartScriptsTask = project.getTasks().register(createStartScriptsTaskName, CreateStartScripts.class, createStartScripts -> {
        createStartScripts.setDescription("Creates OS specific scripts to run the distribution.");
        createStartScripts.setClasspath(distributionJarTask.get().getOutputs().getFiles());
        createStartScripts.setMainClassName(getMainClass(playExtension.getPlatform()));
        createStartScripts.setApplicationName(distribution.getName());
        createStartScripts.setOutputDir(scriptsDir);
    });

    CopySpec distSpec = distribution.getContents();
    distSpec.into("lib", copySpec -> {
        copySpec.from(distributionJarTask);
        copySpec.from(assetsJarTask.get().getArchivePath());
        copySpec.from(project.getConfigurations().getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME));
        copySpec.eachFile(new PrefixArtifactFileNames(project.getConfigurations().getByName(RUNTIME_CLASSPATH_CONFIGURATION_NAME)));
    });

    distSpec.into("bin", copySpec -> {
        copySpec.from(createStartScriptsTask);
        copySpec.setFileMode(0755);
    });

    distSpec.into("conf", copySpec -> copySpec.from("conf").exclude("routes"));
    distSpec.from("README");
}
 
Example #17
Source File: DefaultDistribution.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public DefaultDistribution(String name, CopySpec contents) {
    this.name = name;
    this.contents = contents;
}
 
Example #18
Source File: FileCopier.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult copy(Action<? super CopySpec> action) {
    DestinationRootCopySpec copySpec = createCopySpec(action);
    File destinationDir = copySpec.getDestinationDir();
    return doCopy(copySpec, getCopyVisitor(destinationDir));
}
 
Example #19
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(String... includes) {
    return getWarCopySpec().include(includes);
}
 
Example #20
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(Iterable<String> includes) {
    return getWarCopySpec().include(includes);
}
 
Example #21
Source File: DefaultScript.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Closure closure) {
    return fileOperations.copySpec(closure);
}
 
Example #22
Source File: AbstractProject.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Action<? super CopySpec> action) {
    return fileOperations.copySpec(action);
}
 
Example #23
Source File: DefaultDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec contents(Action<? super CopySpec> action) {
    action.execute(contents);
    return contents;
}
 
Example #24
Source File: FileCopier.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult sync(Action<? super CopySpec> action) {
    DestinationRootCopySpec copySpec = createCopySpec(action);
    File destinationDir = copySpec.getDestinationDir();
    return doCopy(copySpec, new SyncCopyActionDecorator(destinationDir, getCopyVisitor(destinationDir)));
}
 
Example #25
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec include(Spec<FileTreeElement> includeSpec) {
    return getWarCopySpec().include(includeSpec);
}
 
Example #26
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult sync(Action<? super CopySpec> action) {
    return fileOperations.sync(action);
}
 
Example #27
Source File: DefaultDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec getContents() {
    return contents;
}
 
Example #28
Source File: WarOverlay.java    From gradle-plugins with MIT License 4 votes vote down vote up
public CopySpec setIncludes(Iterable<String> includes) {
    return getWarCopySpec().setIncludes(includes);
}
 
Example #29
Source File: DefaultDistribution.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec contents(Action<? super CopySpec> action) {
    action.execute(contents);
    return contents;
}
 
Example #30
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult sync(Action<? super CopySpec> action) {
    return fileOperations.sync(action);
}