Search in sources :

Example 1 with DistributionContainer

use of org.gradle.api.distribution.DistributionContainer in project gradle by gradle.

the class ApplicationPlugin method apply.

@Override
public void apply(final Project project) {
    this.project = project;
    project.getPluginManager().apply(JavaPlugin.class);
    project.getPluginManager().apply(DistributionPlugin.class);
    addPluginConvention();
    addRunTask();
    addCreateScriptsTask();
    Distribution distribution = ((DistributionContainer) project.getExtensions().getByName("distributions")).getByName(DistributionPlugin.MAIN_DISTRIBUTION_NAME);
    ((IConventionAware) distribution).getConventionMapping().map("baseName", new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return pluginConvention.getApplicationName();
        }
    });
    configureDistSpec(distribution.getContents());
    configureInstallTask(project.getTasks().getAt(TASK_INSTALL_NAME));
}
Also used : Distribution(org.gradle.api.distribution.Distribution) GradleException(org.gradle.api.GradleException) DistributionContainer(org.gradle.api.distribution.DistributionContainer)

Example 2 with DistributionContainer

use of org.gradle.api.distribution.DistributionContainer in project gradle by gradle.

the class DistributionPlugin method apply.

@Override
public void apply(final ProjectInternal project) {
    project.getPluginManager().apply(BasePlugin.class);
    DistributionContainer distributions = project.getExtensions().create(DistributionContainer.class, "distributions", DefaultDistributionContainer.class, Distribution.class, instantiator, fileOperations);
    // TODO - refactor this action out so it can be unit tested
    distributions.all(new Action<Distribution>() {

        @Override
        public void execute(final Distribution dist) {
            ((IConventionAware) dist).getConventionMapping().map("baseName", new Callable<Object>() {

                @Override
                public Object call() throws Exception {
                    return dist.getName().equals(MAIN_DISTRIBUTION_NAME) ? project.getName() : String.format("%s-%s", project.getName(), dist.getName());
                }
            });
            dist.getContents().from("src/" + dist.getName() + "/dist");
            String zipTaskName = MAIN_DISTRIBUTION_NAME.equals(dist.getName()) ? TASK_DIST_ZIP_NAME : dist.getName() + "DistZip";
            Task zipTask = configureArchiveTask(project, zipTaskName, dist, Zip.class);
            String tarTaskName = MAIN_DISTRIBUTION_NAME.equals(dist.getName()) ? TASK_DIST_TAR_NAME : dist.getName() + "DistTar";
            Task tarTask = configureArchiveTask(project, tarTaskName, dist, Tar.class);
            addAssembleTask(project, dist, zipTask, tarTask);
            addInstallTask(project, dist);
        }
    });
    distributions.create(MAIN_DISTRIBUTION_NAME);
}
Also used : Zip(org.gradle.api.tasks.bundling.Zip) AbstractArchiveTask(org.gradle.api.tasks.bundling.AbstractArchiveTask) Task(org.gradle.api.Task) Tar(org.gradle.api.tasks.bundling.Tar) Distribution(org.gradle.api.distribution.Distribution) IConventionAware(org.gradle.api.internal.IConventionAware) Callable(java.util.concurrent.Callable) DistributionContainer(org.gradle.api.distribution.DistributionContainer) DefaultDistributionContainer(org.gradle.api.distribution.internal.DefaultDistributionContainer)

Aggregations

Distribution (org.gradle.api.distribution.Distribution)2 DistributionContainer (org.gradle.api.distribution.DistributionContainer)2 Callable (java.util.concurrent.Callable)1 GradleException (org.gradle.api.GradleException)1 Task (org.gradle.api.Task)1 DefaultDistributionContainer (org.gradle.api.distribution.internal.DefaultDistributionContainer)1 IConventionAware (org.gradle.api.internal.IConventionAware)1 AbstractArchiveTask (org.gradle.api.tasks.bundling.AbstractArchiveTask)1 Tar (org.gradle.api.tasks.bundling.Tar)1 Zip (org.gradle.api.tasks.bundling.Zip)1