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: 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 #2
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 #3
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 #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: 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 #6
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 #7
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 #8
Source File: Jar.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec getMetaInf() {
    return metaInf.addChild();
}
 
Example #9
Source File: AntGroovydoc.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void execute(final FileCollection source, File destDir, boolean use, String windowTitle, String docTitle, String header, String footer, String overview, boolean includePrivate, final Set<Groovydoc.Link> links, final Iterable<File> groovyClasspath, Iterable<File> classpath, Project project) {

        final File tmpDir = new File(project.getBuildDir(), "tmp/groovydoc");
        FileOperations fileOperations = (ProjectInternal) project;
        fileOperations.delete(tmpDir);
        fileOperations.copy(new Action<CopySpec>() {
            public void execute(CopySpec copySpec) {
                copySpec.from(source).into(tmpDir);
            }
        });

        final Map<String, Object> args = Maps.newLinkedHashMap();
        args.put("sourcepath", tmpDir.toString());
        args.put("destdir", destDir);
        args.put("use", use);
        args.put("private", includePrivate);
        putIfNotNull(args, "windowtitle", windowTitle);
        putIfNotNull(args, "doctitle", docTitle);
        putIfNotNull(args, "header", header);
        putIfNotNull(args, "footer", footer);
        putIfNotNull(args, "overview", overview);

        List<File> combinedClasspath = ImmutableList.<File>builder()
                .addAll(classpath)
                .addAll(groovyClasspath)
                .build();

        ant.withClasspath(combinedClasspath).execute(new Closure<Object>(this, this) {
            @SuppressWarnings("UnusedDeclaration")
            public Object doCall(Object it) {
                final GroovyObjectSupport antBuilder = (GroovyObjectSupport) it;

                antBuilder.invokeMethod("taskdef", ImmutableMap.of(
                        "name", "groovydoc",
                        "classname", "org.codehaus.groovy.ant.Groovydoc"
                ));

                antBuilder.invokeMethod("groovydoc", new Object[]{args, new Closure<Object>(this, this) {
                    public Object doCall(Object ignore) {
                        for (Groovydoc.Link link : links) {
                            antBuilder.invokeMethod("link", new Object[]{
                                    ImmutableMap.of(
                                            "packages", Joiner.on(",").join(link.getPackages()),
                                            "href", link.getUrl()
                                    )
                            });
                        }

                        return null;
                    }
                }});

                return null;
            }
        });
    }
 
Example #10
Source File: DefaultDistribution.java    From Pushjet-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 #11
Source File: DefaultScript.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 #12
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult copy(Action<? super CopySpec> action) {
    return getFileOperations().copy(action);
}
 
Example #13
Source File: FileCopier.java    From Pushjet-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 #14
Source File: AbstractProject.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Closure closure) {
    return copySpec(new ClosureBackedAction<CopySpec>(closure));
}
 
Example #15
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Closure closure) {
    return fileOperations.copySpec(closure);
}
 
Example #16
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult copy(Action<? super CopySpec> action) {
    return fileOperations.copy(action);
}
 
Example #17
Source File: DefaultDistribution.java    From Pushjet-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: DestinationRootCopySpec.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public CopySpec into(Object destinationDir) {
    this.destinationDir = destinationDir;
    return this;
}
 
Example #19
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 #20
Source File: DefaultScript.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public WorkResult copy(Action<? super CopySpec> action) {
    return fileOperations.copy(action);
}
 
Example #21
Source File: AbstractProject.java    From Pushjet-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: 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(new ClosureBackedAction<CopySpec>(closure));
}
 
Example #23
Source File: DefaultScript.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 #24
Source File: DefaultDistribution.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec getContents() {
    return contents;
}
 
Example #25
Source File: DefaultDistribution.java    From pushfish-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 #26
Source File: DefaultScript.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public CopySpec copySpec(Closure closure) {
    return fileOperations.copySpec(new ClosureBackedAction<CopySpec>(closure));
}
 
Example #27
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);
}
 
Example #28
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 #29
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 #30
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);
}