Java Code Examples for org.gradle.api.internal.ConventionMapping#map()

The following examples show how to use org.gradle.api.internal.ConventionMapping#map() . 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: MavenPublishTaskModelRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    GenerateMavenPom generatePomTask = project.getTasks().create(descriptorTaskName, GenerateMavenPom.class);
    generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
    generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    generatePomTask.setPom(publication.getPom());

    ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
    descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return new File(project.getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
        }
    });

    // Wire the generated pom into the publication.
    publication.setPomFile(generatePomTask.getOutputs().getFiles());
}
 
Example 2
Source File: JavaLanguagePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Preconfigures the specified compile task based on the specified source set and class directory binary.
 *
 * @param compile the compile task to be preconfigured
 * @param sourceSet the source set for the compile task
 * @param binary the binary for the compile task
 */
public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinary binary) {
    compile.setDescription(String.format("Compiles %s.", sourceSet));
    compile.setSource(sourceSet.getSource());
    compile.dependsOn(sourceSet);
    ConventionMapping conventionMapping = compile.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath().getFiles();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return binary.getClassesDir();
        }
    });
}
 
Example 3
Source File: JavaBasePlugin.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void createCompileJavaTaskForBinary(final SourceSet sourceSet, SourceDirectorySet javaSourceSet, Project target) {
    JavaCompile compileTask = target.getTasks().create(sourceSet.getCompileJavaTaskName(), JavaCompile.class);
    compileTask.setDescription("Compiles " + javaSourceSet + ".");
    compileTask.setSource(javaSourceSet);
    ConventionMapping conventionMapping = compileTask.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
 
Example 4
Source File: JavaBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
 
Example 5
Source File: OsgiPluginConvention.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) {
    OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
    ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
    final OsgiHelper osgiHelper = new OsgiHelper();

    mapping.map("version", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getVersion(project.getVersion().toString());
        }
    });
    mapping.map("name", new Callable<Object>() {
        public Object call() throws Exception {
            return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
        }
    });
    mapping.map("symbolicName", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getBundleSymbolicName(project);
        }
    });

    return osgiManifest;
}
 
Example 6
Source File: OsgiPluginConvention.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private OsgiManifest createDefaultOsgiManifest(final ProjectInternal project) {
    OsgiManifest osgiManifest = project.getServices().get(Instantiator.class).newInstance(DefaultOsgiManifest.class, project.getFileResolver());
    ConventionMapping mapping = ((IConventionAware) osgiManifest).getConventionMapping();
    final OsgiHelper osgiHelper = new OsgiHelper();

    mapping.map("version", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getVersion(project.getVersion().toString());
        }
    });
    mapping.map("name", new Callable<Object>() {
        public Object call() throws Exception {
            return project.getConvention().getPlugin(BasePluginConvention.class).getArchivesBaseName();
        }
    });
    mapping.map("symbolicName", new Callable<Object>() {
        public Object call() throws Exception {
            return osgiHelper.getBundleSymbolicName(project);
        }
    });

    return osgiManifest;
}
 
Example 7
Source File: MavenPublishTaskModelRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void createGeneratePomTask(final MavenPublicationInternal publication, String publicationName) {
    String descriptorTaskName = String.format("generatePomFileFor%sPublication", capitalize(publicationName));
    GenerateMavenPom generatePomTask = project.getTasks().create(descriptorTaskName, GenerateMavenPom.class);
    generatePomTask.setDescription(String.format("Generates the Maven POM file for publication '%s'.", publication.getName()));
    generatePomTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
    generatePomTask.setPom(publication.getPom());

    ConventionMapping descriptorTaskConventionMapping = new DslObject(generatePomTask).getConventionMapping();
    descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return new File(project.getBuildDir(), "publications/" + publication.getName() + "/pom-default.xml");
        }
    });

    // Wire the generated pom into the publication.
    publication.setPomFile(generatePomTask.getOutputs().getFiles());
}
 
Example 8
Source File: JavaBasePlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
 
Example 9
Source File: LegacyJavaComponentPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Preconfigures the specified compile task based on the specified source set and class directory binary.
 *
 * @param compile the compile task to be preconfigured
 * @param sourceSet the source set for the compile task
 * @param binary the binary for the compile task
 */
public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinarySpec binary) {
    compile.setDescription(String.format("Compiles %s.", sourceSet));
    compile.setSource(sourceSet.getSource());
    compile.dependsOn(sourceSet);
    ConventionMapping conventionMapping = compile.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath().getFiles();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return binary.getClassesDir();
        }
    });
}
 
Example 10
Source File: LegacyJavaComponentPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Preconfigures the specified compile task based on the specified source set and class directory binary.
 *
 * @param compile the compile task to be preconfigured
 * @param sourceSet the source set for the compile task
 * @param binary the binary for the compile task
 */
public void configureCompileTask(AbstractCompile compile, final JavaSourceSet sourceSet, final ClassDirectoryBinarySpec binary) {
    compile.setDescription(String.format("Compiles %s.", sourceSet));
    compile.setSource(sourceSet.getSource());
    compile.dependsOn(sourceSet);
    ConventionMapping conventionMapping = compile.getConventionMapping();
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath().getFiles();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return binary.getClassesDir();
        }
    });
}
 
Example 11
Source File: JavaBasePlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void configureForSourceSet(final SourceSet sourceSet, AbstractCompile compile) {
    ConventionMapping conventionMapping;
    compile.setDescription(String.format("Compiles the %s.", sourceSet.getJava()));
    conventionMapping = compile.getConventionMapping();
    compile.setSource(sourceSet.getJava());
    conventionMapping.map("classpath", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getCompileClasspath();
        }
    });
    conventionMapping.map("destinationDir", new Callable<Object>() {
        public Object call() throws Exception {
            return sourceSet.getOutput().getClassesDir();
        }
    });
}
 
Example 12
Source File: IvyPublicationTasksModelRule.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void createTasks(TaskContainer tasks, PublishingExtension publishingExtension) {
    PublicationContainer publications = publishingExtension.getPublications();
    RepositoryHandler repositories = publishingExtension.getRepositories();

    for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) {

        final String publicationName = publication.getName();
        final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName));

        GenerateIvyDescriptor descriptorTask = tasks.create(descriptorTaskName, GenerateIvyDescriptor.class);
        descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName()));
        descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        descriptorTask.setDescriptor(publication.getDescriptor());

        ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping();
        descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
            public Object call() throws Exception {
                return new File(project.getBuildDir(), "publications/" + publication.getName() + "/ivy.xml");
            }
        });

        publication.setDescriptorFile(descriptorTask.getOutputs().getFiles());

        for (IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) {
            final String repositoryName = repository.getName();
            final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName));

            PublishToIvyRepository publishTask = tasks.create(publishTaskName, PublishToIvyRepository.class);
            publishTask.setPublication(publication);
            publishTask.setRepository(repository);
            publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
            publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName));

            tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTask);
        }
    }
}
 
Example 13
Source File: IvyPublicationTasksModelRule.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void createTasks(TaskContainer tasks, PublishingExtension publishingExtension) {
    PublicationContainer publications = publishingExtension.getPublications();
    RepositoryHandler repositories = publishingExtension.getRepositories();

    for (final IvyPublicationInternal publication : publications.withType(IvyPublicationInternal.class)) {

        final String publicationName = publication.getName();
        final String descriptorTaskName = String.format("generateDescriptorFileFor%sPublication", capitalize(publicationName));

        GenerateIvyDescriptor descriptorTask = tasks.create(descriptorTaskName, GenerateIvyDescriptor.class);
        descriptorTask.setDescription(String.format("Generates the Ivy Module Descriptor XML file for publication '%s'.", publication.getName()));
        descriptorTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
        descriptorTask.setDescriptor(publication.getDescriptor());

        ConventionMapping descriptorTaskConventionMapping = new DslObject(descriptorTask).getConventionMapping();
        descriptorTaskConventionMapping.map("destination", new Callable<Object>() {
            public Object call() throws Exception {
                return new File(project.getBuildDir(), "publications/" + publication.getName() + "/ivy.xml");
            }
        });

        publication.setDescriptorFile(descriptorTask.getOutputs().getFiles());

        for (IvyArtifactRepository repository : repositories.withType(IvyArtifactRepository.class)) {
            final String repositoryName = repository.getName();
            final String publishTaskName = String.format("publish%sPublicationTo%sRepository", capitalize(publicationName), capitalize(repositoryName));

            PublishToIvyRepository publishTask = tasks.create(publishTaskName, PublishToIvyRepository.class);
            publishTask.setPublication(publication);
            publishTask.setRepository(repository);
            publishTask.setGroup(PublishingPlugin.PUBLISH_TASK_GROUP);
            publishTask.setDescription(String.format("Publishes Ivy publication '%s' to Ivy repository '%s'.", publicationName, repositoryName));

            tasks.getByName(PublishingPlugin.PUBLISH_LIFECYCLE_TASK_NAME).dependsOn(publishTask);
        }
    }
}
 
Example 14
Source File: LegacyJavaComponentPlugin.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setClassesDirConvention(ClassDirectoryBinarySpecInternal binary, final Project target) {
    final BinaryNamingScheme namingScheme = binary.getNamingScheme();
    ConventionMapping conventionMapping = new DslObject(binary).getConventionMapping();
    conventionMapping.map("classesDir", new Callable<File>() {
        public File call() throws Exception {
            return new File(new File(target.getBuildDir(), "classes"), namingScheme.getOutputDirectoryBase());
        }
    });
}
 
Example 15
Source File: LegacyJavaComponentPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setClassesDirConvention(ClassDirectoryBinarySpecInternal binary, final Project target) {
    final BinaryNamingScheme namingScheme = binary.getNamingScheme();
    ConventionMapping conventionMapping = new DslObject(binary).getConventionMapping();
    conventionMapping.map("classesDir", new Callable<File>() {
        public File call() throws Exception {
            return new File(new File(target.getBuildDir(), "classes"), namingScheme.getOutputDirectoryBase());
        }
    });
}
 
Example 16
Source File: GwtDevTask.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void configureCodeServer(final Project project, final PutnamiExtension extention) {
	final DevOption options = extention.getDev();
	options.init(project);

	ConventionMapping convention = ((IConventionAware) this).getConventionMapping();
	convention.map("modules", new Callable<List<String>>() {
		@Override
		public List<String> call()  {
			return extention.getModule();
		}
	});
}
 
Example 17
Source File: GwtSetUpTask.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void configure(final PutnamiExtension extension) {
	ConventionMapping mapping = ((IConventionAware) this).getConventionMapping();

	mapping.map("modules", new Callable<List<String>>() {
		@Override
		public List<String> call()  {
			return extension.getModule();
		}
	});
}
 
Example 18
Source File: GwtCompileTask.java    From putnami-gradle-plugin with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void configure(final Project project, final PutnamiExtension extention) {
	final CompilerOption options = extention.getCompile();
	options.init(project);
	options.setLocalWorkers(evalWorkers(options));

	final ConfigurableFileCollection sources = project.files();
	addSourceSet(sources, project, SourceSet.MAIN_SOURCE_SET_NAME);

	final Configuration compileClasspath = project.getConfigurations().getByName(
		JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME);
	compileClasspath.getDependencies().withType(ProjectDependency.class, new Action<ProjectDependency>() {
		@Override
		public void execute(ProjectDependency dep) {
			addSourceSet(sources, dep.getDependencyProject(), SourceSet.MAIN_SOURCE_SET_NAME);
		}
	});

	ConventionMapping mapping = ((IConventionAware) this).getConventionMapping();

	mapping.map("modules", new Callable<List<String>>() {
		@Override
		public List<String> call()  {
			return extention.getModule();
		}
	});
	mapping.map("war", new Callable<File>() {
		@Override
		public File call()  {
			return options.getWar();
		}
	});
	mapping.map("src", new Callable<FileCollection>() {
		@Override
		public FileCollection call()  {
			return sources;
		}
	});
}
 
Example 19
Source File: BuildDashboardPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().apply(ReportingBasePlugin.class);

    final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class);

    DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml();
    ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping();
    htmlReportConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard");
        }
    });

    Action<Task> captureReportingTasks = new Action<Task>() {
        public void execute(Task task) {
            if (!(task instanceof Reporting)) {
                return;
            }

            Reporting reporting = (Reporting) task;

            buildDashboardTask.aggregate(reporting);

            if (!task.equals(buildDashboardTask)) {
                task.finalizedBy(buildDashboardTask);
            }
        }
    };

    for (Project aProject : project.getAllprojects()) {
        aProject.getTasks().all(captureReportingTasks);
    }
}
 
Example 20
Source File: BuildDashboardPlugin.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void apply(final ProjectInternal project) {
    project.getPlugins().apply(ReportingBasePlugin.class);

    final GenerateBuildDashboard buildDashboardTask = project.getTasks().create(BUILD_DASHBOARD_TASK_NAME, GenerateBuildDashboard.class);
    buildDashboardTask.setDescription("Generates a dashboard of all the reports produced by this build.");
    buildDashboardTask.setGroup("reporting");

    DirectoryReport htmlReport = buildDashboardTask.getReports().getHtml();
    ConventionMapping htmlReportConventionMapping = new DslObject(htmlReport).getConventionMapping();
    htmlReportConventionMapping.map("destination", new Callable<Object>() {
        public Object call() throws Exception {
            return project.getExtensions().getByType(ReportingExtension.class).file("buildDashboard");
        }
    });

    Action<Task> captureReportingTasks = new Action<Task>() {
        public void execute(Task task) {
            if (!(task instanceof Reporting)) {
                return;
            }

            Reporting reporting = (Reporting) task;

            buildDashboardTask.aggregate(reporting);

            if (!task.equals(buildDashboardTask)) {
                task.finalizedBy(buildDashboardTask);
            }
        }
    };

    for (Project aProject : project.getAllprojects()) {
        aProject.getTasks().all(captureReportingTasks);
    }
}