use of org.gradle.api.tasks.SourceSet in project gradle by gradle.
the class SourceFoldersCreator method projectRelativeFolders.
private List<SourceFolder> projectRelativeFolders(Iterable<SourceSet> sourceSets, 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);
entries.add(folder);
}
}
}
return entries;
}
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 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.
public void apply(final Project project) {
project.getPluginManager().apply(JavaPlugin.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.");
antlrConfiguration.defaultDependencies(new Action<DependencySet>() {
@Override
public void execute(DependencySet dependencies) {
dependencies.add(project.getDependencies().create("antlr:antlr:2.7.7@jar"));
}
});
project.getConfigurations().getByName(COMPILE_CONFIGURATION_NAME).extendsFrom(antlrConfiguration);
// Wire the antlr configuration into all antlr tasks
project.getTasks().withType(AntlrTask.class, new Action<AntlrTask>() {
public void execute(AntlrTask antlrTask) {
antlrTask.getConventionMapping().map("antlrClasspath", new Callable<Object>() {
public Object call() throws Exception {
return project.getConfigurations().getByName(ANTLR_CONFIGURATION_NAME);
}
});
}
});
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().all(new Action<SourceSet>() {
public void execute(SourceSet sourceSet) {
// for each source set we will:
// 1) Add a new 'antlr' virtual directory mapping
final AntlrSourceVirtualDirectoryImpl antlrDirectoryDelegate = new AntlrSourceVirtualDirectoryImpl(((DefaultSourceSet) sourceSet).getDisplayName(), sourceDirectorySetFactory);
new DslObject(sourceSet).getConvention().getPlugins().put(AntlrSourceVirtualDirectory.NAME, antlrDirectoryDelegate);
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");
AntlrTask antlrTask = project.getTasks().create(taskName, AntlrTask.class);
antlrTask.setDescription("Processes the " + sourceSet.getName() + " Antlr grammars.");
// 3) set up convention mapping for default sources (allows user to not have to specify)
antlrTask.setSource(antlrDirectoryDelegate.getAntlr());
// 4) 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);
antlrTask.setOutputDirectory(outputDirectory);
sourceSet.getJava().srcDir(outputDirectory);
// 6) register fact that antlr should be run before compiling
project.getTasks().getByName(sourceSet.getCompileJavaTaskName()).dependsOn(taskName);
}
});
}
use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.
the class CsaccessTestTask method getClasspath.
/**
* Overriding getClasspath() in order to set the final classpath is an unusual solution, but it was the only
* solution which included the classpath entries generated by the IntelliJ plugin creation plugin (which, in my
* humble opinion, should be considered seriously broken).
*
* @return the classpath to use to execute the tests
*/
@Override
public FileCollection getClasspath() {
final FileCollection originalClasspath = super.getClasspath();
FileCollection effectiveClasspath = null;
if (originalClasspath != null) {
final Project project = getProject();
final JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);
final SourceSetContainer sourceSets = javaConvention.getSourceSets();
final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
final SourceSet csaccessSourceSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESS_SOURCESET_NAME);
final SourceSet csaccessTestSrcSet = sourceSets.getByName(CustomSourceSetCreator.CSACCESSTEST_SOURCESET_NAME);
final Dependency csDep = CheckstyleVersions.createCheckstyleDependency(project, csVersion);
final ConfigurationContainer configurations = project.getConfigurations();
final Set<File> csJars = configurations.detachedConfiguration(csDep).getFiles();
effectiveClasspath = project.files(csaccessTestSrcSet.getOutput().getResourcesDir(), csaccessSourceSet.getOutput().getResourcesDir(), mainSourceSet.getOutput().getResourcesDir()).plus(csaccessTestSrcSet.getOutput().getClassesDirs()).plus(csaccessSourceSet.getOutput().getClassesDirs()).plus(mainSourceSet.getOutput().getClassesDirs()).plus(project.files(csJars)).plus(originalClasspath).minus(testSourceSet.getOutput().getClassesDirs()).minus(project.files(testSourceSet.getOutput().getResourcesDir()));
// getLogger().lifecycle("--------------------------------------------------------------------------");
// getLogger().lifecycle("Effective classpath of " + getName() + ":");
// for (File f : effectiveClasspath) {
// getLogger().lifecycle("\t- " + f.getAbsolutePath());
// }
}
return effectiveClasspath;
}
Aggregations