Search in sources :

Example 1 with CopySpec

use of org.gradle.api.file.CopySpec in project gradle by gradle.

the class Ear method lib.

/**
     * Adds dependency libraries to include in the 'lib' directory of the EAR archive.
     *
     * <p>The given action is executed to configure a {@code CopySpec}.</p>
     *
     * @param configureAction The action.
     * @return The created {@code CopySpec}
     * @since 3.5
     */
public CopySpec lib(Action<? super CopySpec> configureAction) {
    CopySpec copySpec = getLib();
    configureAction.execute(copySpec);
    return copySpec;
}
Also used : CopySpec(org.gradle.api.file.CopySpec)

Example 2 with CopySpec

use of org.gradle.api.file.CopySpec in project gradle by gradle.

the class DefaultCopySpec method filesMatching.

public CopySpec filesMatching(Iterable<String> patterns, Action<? super FileCopyDetails> action) {
    if (!patterns.iterator().hasNext()) {
        throw new InvalidUserDataException("must provide at least one pattern to match");
    }
    List<Spec> matchers = new ArrayList<Spec>();
    for (String pattern : patterns) {
        matchers.add(PatternMatcherFactory.getPatternMatcher(true, isCaseSensitive(), pattern));
    }
    Spec unionMatcher = Specs.union(matchers.toArray(new Spec[matchers.size()]));
    return eachFile(new MatchingCopyAction(unionMatcher, action));
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) ArrayList(java.util.ArrayList) CopySpec(org.gradle.api.file.CopySpec) CopyProcessingSpec(org.gradle.api.file.CopyProcessingSpec) Spec(org.gradle.api.specs.Spec)

Example 3 with CopySpec

use of org.gradle.api.file.CopySpec in project gradle by gradle.

the class PlayDistributionPlugin method createDistributionContentTasks.

@Mutate
void createDistributionContentTasks(ModelMap<Task> tasks, @Path("buildDir") final File buildDir, @Path("distributions") final PlayDistributionContainer distributions, final PlayPluginConfigurations configurations) {
    for (final PlayDistribution distribution : distributions.withType(PlayDistribution.class)) {
        final PlayApplicationBinarySpec binary = distribution.getBinary();
        if (binary == null) {
            throw new InvalidUserCodeException(String.format("Play Distribution '%s' does not have a configured Play binary.", distribution.getName()));
        }
        final File distJarDir = new File(buildDir, "distributionJars/" + distribution.getName());
        final String jarTaskName = "create" + StringUtils.capitalize(distribution.getName()) + "DistributionJar";
        tasks.create(jarTaskName, Jar.class, new Action<Jar>() {

            @Override
            public void execute(Jar jar) {
                jar.setDescription("Assembles an application jar suitable for deployment for the " + binary + ".");
                jar.dependsOn(binary.getTasks().withType(Jar.class));
                jar.from(jar.getProject().zipTree(binary.getJarFile()));
                jar.setDestinationDir(distJarDir);
                jar.setArchiveName(binary.getJarFile().getName());
                Map<String, Object> classpath = Maps.newHashMap();
                classpath.put("Class-Path", new PlayManifestClasspath(configurations.getPlayRun(), binary.getAssetsJarFile()));
                jar.getManifest().attributes(classpath);
            }
        });
        final Task distributionJar = tasks.get(jarTaskName);
        final File scriptsDir = new File(buildDir, "scripts/" + distribution.getName());
        String createStartScriptsTaskName = "create" + StringUtils.capitalize(distribution.getName() + "StartScripts");
        tasks.create(createStartScriptsTaskName, CreateStartScripts.class, new Action<CreateStartScripts>() {

            @Override
            public void execute(CreateStartScripts createStartScripts) {
                createStartScripts.setDescription("Creates OS specific scripts to run the " + binary + ".");
                createStartScripts.setClasspath(distributionJar.getOutputs().getFiles());
                createStartScripts.setMainClassName("play.core.server.NettyServer");
                createStartScripts.setApplicationName(distribution.getName());
                createStartScripts.setOutputDir(scriptsDir);
            }
        });
        Task createStartScripts = tasks.get(createStartScriptsTaskName);
        CopySpecInternal distSpec = (CopySpecInternal) distribution.getContents();
        CopySpec libSpec = distSpec.addChild().into("lib");
        libSpec.from(distributionJar);
        libSpec.from(binary.getAssetsJarFile());
        libSpec.from(configurations.getPlayRun().getAllArtifacts());
        libSpec.eachFile(new PrefixArtifactFileNames(configurations.getPlayRun()));
        CopySpec binSpec = distSpec.addChild().into("bin");
        binSpec.from(createStartScripts);
        binSpec.setFileMode(0755);
        CopySpec confSpec = distSpec.addChild().into("conf");
        confSpec.from("conf").exclude("routes");
        distSpec.from("README");
    }
}
Also used : CopySpec(org.gradle.api.file.CopySpec) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) InvalidUserCodeException(org.gradle.api.InvalidUserCodeException) PlayDistribution(org.gradle.play.distribution.PlayDistribution) DefaultPlayDistribution(org.gradle.play.internal.distribution.DefaultPlayDistribution) PlayApplicationBinarySpec(org.gradle.play.PlayApplicationBinarySpec) CreateStartScripts(org.gradle.api.tasks.application.CreateStartScripts) Jar(org.gradle.jvm.tasks.Jar) CopySpecInternal(org.gradle.api.internal.file.copy.CopySpecInternal) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with CopySpec

use of org.gradle.api.file.CopySpec in project gradle by gradle.

the class JavaLibraryDistributionPlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    this.project = project;
    project.getPluginManager().apply(JavaPlugin.class);
    project.getPluginManager().apply(DistributionPlugin.class);
    DefaultDistributionContainer defaultDistributionContainer = (DefaultDistributionContainer) project.getExtensions().findByName("distributions");
    CopySpec contentSpec = defaultDistributionContainer.getByName(DistributionPlugin.MAIN_DISTRIBUTION_NAME).getContents();
    Jar jar = (Jar) project.getTasks().getByName(JavaPlugin.JAR_TASK_NAME);
    CopySpec childSpec = project.copySpec();
    childSpec.from(jar);
    childSpec.from(project.file("src/dist"));
    CopySpec libSpec = project.copySpec();
    libSpec.into("lib");
    libSpec.from(project.getConfigurations().getByName("runtime"));
    childSpec.with(libSpec);
    contentSpec.with(childSpec);
}
Also used : CopySpec(org.gradle.api.file.CopySpec) Jar(org.gradle.api.tasks.bundling.Jar) DefaultDistributionContainer(org.gradle.api.distribution.internal.DefaultDistributionContainer)

Example 5 with CopySpec

use of org.gradle.api.file.CopySpec in project gradle by gradle.

the class ApplicationPlugin method configureDistSpec.

private CopySpec configureDistSpec(CopySpec distSpec) {
    Task jar = project.getTasks().getAt(JavaPlugin.JAR_TASK_NAME);
    Task startScripts = project.getTasks().getAt(TASK_START_SCRIPTS_NAME);
    CopySpec libChildSpec = project.copySpec();
    libChildSpec.into("lib");
    libChildSpec.from(jar);
    libChildSpec.from(project.getConfigurations().getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME));
    CopySpec binChildSpec = project.copySpec();
    binChildSpec.into("bin");
    binChildSpec.from(startScripts);
    binChildSpec.setFileMode(0755);
    CopySpec childSpec = project.copySpec();
    childSpec.from(project.file("src/dist"));
    childSpec.with(libChildSpec);
    childSpec.with(binChildSpec);
    distSpec.with(childSpec);
    distSpec.with(pluginConvention.getApplicationDistribution());
    return distSpec;
}
Also used : CopySpec(org.gradle.api.file.CopySpec) Task(org.gradle.api.Task)

Aggregations

CopySpec (org.gradle.api.file.CopySpec)13 File (java.io.File)3 ArrayList (java.util.ArrayList)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)2 Task (org.gradle.api.Task)2 CopyProcessingSpec (org.gradle.api.file.CopyProcessingSpec)2 Spec (org.gradle.api.specs.Spec)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1 GradleException (org.gradle.api.GradleException)1 InvalidUserCodeException (org.gradle.api.InvalidUserCodeException)1 DefaultDistributionContainer (org.gradle.api.distribution.internal.DefaultDistributionContainer)1 RelativePath (org.gradle.api.file.RelativePath)1 ArchivePublishArtifact (org.gradle.api.internal.artifacts.publish.ArchivePublishArtifact)1 FileOperations (org.gradle.api.internal.file.FileOperations)1 CopySpecInternal (org.gradle.api.internal.file.copy.CopySpecInternal)1