use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class EclipsePlugin method configureJavaClasspath.
private static void configureJavaClasspath(final Project project, final TaskProvider<GenerateEclipseClasspath> task, final EclipseModel model, Collection<SourceSet> testSourceSetsConvention, Collection<Configuration> testConfigurationsConvention) {
project.getPlugins().withType(JavaPlugin.class, new Action<JavaPlugin>() {
@Override
public void execute(JavaPlugin javaPlugin) {
((IConventionAware) model.getClasspath()).getConventionMapping().map("plusConfigurations", new Callable<Collection<Configuration>>() {
@Override
public Collection<Configuration> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
List<Configuration> sourceSetsConfigurations = Lists.newArrayListWithCapacity(sourceSets.size() * 2);
ConfigurationContainer configurations = project.getConfigurations();
for (SourceSet sourceSet : sourceSets) {
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getCompileClasspathConfigurationName()));
sourceSetsConfigurations.add(configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
return sourceSetsConfigurations;
}
}).cache();
((IConventionAware) model.getClasspath()).getConventionMapping().map("classFolders", new Callable<List<File>>() {
@Override
public List<File> call() {
List<File> result = Lists.newArrayList();
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
result.addAll(sourceSet.getOutput().getDirs().getFiles());
}
return result;
}
});
task.configure(new Action<GenerateEclipseClasspath>() {
@Override
public void execute(GenerateEclipseClasspath task) {
for (SourceSet sourceSet : project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets()) {
task.dependsOn(sourceSet.getOutput().getDirs());
}
}
});
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
sourceSets.configureEach(new Action<SourceSet>() {
@Override
public void execute(SourceSet sourceSet) {
if (sourceSet.getName().toLowerCase(Locale.ROOT).contains("test")) {
// source sets with 'test' in their name are marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the source sets with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
}
});
project.getConfigurations().all(new Action<Configuration>() {
@Override
public void execute(Configuration configuration) {
if (configuration.isCanBeResolved() && configuration.getName().toLowerCase(Locale.ROOT).contains("test")) {
// resolved dependencies from custom configurations with 'test' in their name are marked as test on the Eclipse classpath
testConfigurationsConvention.add(configuration);
}
}
});
}
});
project.getPlugins().withType(JavaTestFixturesPlugin.class, new Action<JavaTestFixturesPlugin>() {
@Override
public void execute(JavaTestFixturesPlugin javaTestFixturesPlugin) {
model.getClasspath().getContainsTestFixtures().convention(true);
project.getPluginManager().withPlugin("java", new Action<AppliedPlugin>() {
@Override
public void execute(AppliedPlugin appliedPlugin) {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
SourceSet sourceSet = sourceSets.getByName(TestFixturesSupport.TEST_FIXTURE_SOURCESET_NAME);
// the testFixtures source set is marked as test on the Eclipse classpath
testSourceSetsConvention.add(sourceSet);
// resolved dependencies from the testFixtures source set are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(sourceSet.getRuntimeClasspathConfigurationName()));
}
});
}
});
project.getPlugins().withType(TestSuiteBasePlugin.class, testSuiteBasePlugin -> {
TestingExtension testing = project.getExtensions().getByType(TestingExtension.class);
ExtensiblePolymorphicDomainObjectContainer<TestSuite> suites = testing.getSuites();
suites.withType(JvmTestSuite.class).configureEach(jvmTestSuite -> {
// jvm test suite source sets are marked as test on the Eclipse classpath
testSourceSetsConvention.add(jvmTestSuite.getSources());
// resolved dependencies from jvm test suites are marked as test on the Eclipse classpath
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getCompileClasspathConfigurationName()));
testConfigurationsConvention.add(project.getConfigurations().findByName(jvmTestSuite.getSources().getRuntimeClasspathConfigurationName()));
});
});
}
use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class SourceFoldersCreator method collectSourceSetOutputPaths.
private Map<SourceSet, String> collectSourceSetOutputPaths(Iterable<SourceSet> sourceSets, String defaultOutputPath) {
Set<String> existingPaths = Sets.newHashSet(defaultOutputPath);
Map<SourceSet, String> result = Maps.newHashMap();
for (SourceSet sourceSet : sourceSets) {
String path = collectSourceSetOutputPath(sourceSet.getName(), existingPaths, "");
existingPaths.add(path);
result.put(sourceSet, path);
}
return result;
}
use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class SourceFoldersCreator method configureProjectRelativeFolders.
private List<SourceFolder> configureProjectRelativeFolders(Iterable<SourceSet> sourceSets, Collection<SourceSet> testSourceSets, Function<File, String> provideRelativePath, File defaultOutputDir) {
String defaultOutputPath = PathUtil.normalizePath(provideRelativePath.apply(defaultOutputDir));
ArrayList<SourceFolder> entries = Lists.newArrayList();
List<SourceSet> sortedSourceSets = sortSourceSetsAsPerUsualConvention(sourceSets);
Map<SourceSet, String> sourceSetOutputPaths = collectSourceSetOutputPaths(sortedSourceSets, defaultOutputPath);
Multimap<SourceSet, SourceSet> sourceSetUsages = getSourceSetUsages(sortedSourceSets);
for (SourceSet sourceSet : sortedSourceSets) {
List<DirectoryTree> sortedSourceDirs = sortSourceDirsAsPerUsualConvention(sourceSet.getAllSource().getSrcDirTrees());
for (DirectoryTree tree : sortedSourceDirs) {
File dir = tree.getDir();
if (dir.isDirectory()) {
String relativePath = provideRelativePath.apply(dir);
SourceFolder folder = new SourceFolder(relativePath, null);
folder.setDir(dir);
folder.setName(dir.getName());
folder.setIncludes(getIncludesForTree(sourceSet, tree));
folder.setExcludes(getExcludesForTree(sourceSet, tree));
folder.setOutput(sourceSetOutputPaths.get(sourceSet));
addScopeAttributes(folder, sourceSet, sourceSetUsages);
addSourceSetAttributeIfNeeded(sourceSet, folder, testSourceSets);
entries.add(folder);
}
}
}
return entries;
}
use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class SourceFoldersCreator method getUsingSourceSetNames.
private List<String> getUsingSourceSetNames(SourceSet sourceSet, Multimap<SourceSet, SourceSet> sourceSetUsages) {
Collection<SourceSet> usingSourceSets = sourceSetUsages.get(sourceSet);
List<String> usingSourceSetNames = Lists.newArrayList();
for (SourceSet usingSourceSet : usingSourceSets) {
usingSourceSetNames.add(sanitizeNameForAttribute(usingSourceSet));
}
return usingSourceSetNames;
}
use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class AntlrPlugin method apply.
@SuppressWarnings("deprecation")
@Override
public void apply(final Project project) {
project.getPluginManager().apply(JavaLibraryPlugin.class);
// set up a configuration named 'antlr' for the user to specify the antlr libs to use in case
// they want a specific version etc.
final Configuration antlrConfiguration = project.getConfigurations().create(ANTLR_CONFIGURATION_NAME).setVisible(false).setDescription("The Antlr libraries to be used for this project.");
((DeprecatableConfiguration) antlrConfiguration).deprecateForConsumption(deprecation -> deprecation.willBecomeAnErrorInGradle8().withUpgradeGuideSection(7, "plugin_configuration_consumption"));
antlrConfiguration.defaultDependencies(dependencies -> dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar")));
Configuration apiConfiguration = project.getConfigurations().getByName(JavaPlugin.API_CONFIGURATION_NAME);
apiConfiguration.extendsFrom(antlrConfiguration);
// Wire the antlr configuration into all antlr tasks
project.getTasks().withType(AntlrTask.class).configureEach(antlrTask -> antlrTask.getConventionMapping().map("antlrClasspath", () -> project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME)));
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().all(new Action<SourceSet>() {
@Override
public void execute(final SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new org.gradle.api.plugins.antlr.internal.AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), objectFactory);
new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
sourceSet.getExtensions().add(AntlrSourceDirectorySet.class, AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate.getAntlr());
final String srcDir = "src/" + sourceSet.getName() + "/antlr";
antlrDirectoryDelegate.getAntlr().srcDir(srcDir);
sourceSet.getAllSource().source(antlrDirectoryDelegate.getAntlr());
// 2) create an AntlrTask for this sourceSet following the gradle
// naming conventions via call to sourceSet.getTaskName()
final String taskName = sourceSet.getTaskName("generate", "GrammarSource");
// 3) Set up the Antlr output directory (adding to javac inputs!)
final String outputDirectoryName = project.getBuildDir() + "/generated-src/antlr/" + sourceSet.getName();
final File outputDirectory = new File(outputDirectoryName);
sourceSet.getJava().srcDir(outputDirectory);
project.getTasks().register(taskName, AntlrTask.class, new Action<AntlrTask>() {
@Override
public void execute(AntlrTask antlrTask) {
antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
// 4) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
antlrTask.setOutputDirectory(outputDirectory);
}
});
// 5) register fact that antlr should be run before compiling
project.getTasks().named(sourceSet.getCompileJavaTaskName(), new Action<Task>() {
@Override
public void execute(Task task) {
task.dependsOn(taskName);
}
});
}
});
}
Aggregations