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 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;
}
use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.
the class CustomSourceSetCreator method configureJacocoTask.
private void configureJacocoTask(final JacocoReportBase pJacocoTask) {
pJacocoTask.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
final SourceSet csaccessSourceSet = sourceSets.getByName(CSACCESS_SOURCESET_NAME);
pJacocoTask.setClassDirectories(csaccessSourceSet.getOutput().getClassesDirs());
pJacocoTask.setSourceDirectories(csaccessSourceSet.getJava().getSourceDirectories());
final FileCollection execFiles = project.files(project.getTasks().withType(CsaccessTestTask.class).stream().map((final CsaccessTestTask task) -> {
//
return new File(project.getBuildDir() + "/jacoco", task.getName() + ".exec");
}).collect(Collectors.toList()));
pJacocoTask.setExecutionData(execFiles);
}
use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.
the class CustomSourceSetCreator method establishCsAccessSourceSet.
public CustomSourceSetCreator establishCsAccessSourceSet() {
final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
// Create the 'csaccess' source set
final SourceSet csaccessSourceSet = sourceSets.create(CSACCESS_SOURCESET_NAME);
csaccessSourceSet.setCompileClasspath(csaccessSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput()));
csaccessSourceSet.setRuntimeClasspath(csaccessSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput()));
sourceSets.add(csaccessSourceSet);
// Derive all its configurations from 'main', so 'csaccess' code can see 'main' code
final ConfigurationContainer configurations = project.getConfigurations();
final Configuration compileConfig = configurations.getByName(mainSourceSet.getCompileConfigurationName());
final Configuration compileOnlyConfig = configurations.getByName(mainSourceSet.getCompileOnlyConfigurationName());
final Configuration compileClasspathConfig = configurations.getByName(mainSourceSet.getCompileClasspathConfigurationName());
final Configuration runtimeConfig = configurations.getByName(mainSourceSet.getRuntimeConfigurationName());
configurations.getByName(csaccessSourceSet.getCompileConfigurationName()).extendsFrom(compileConfig);
configurations.getByName(csaccessSourceSet.getCompileOnlyConfigurationName()).extendsFrom(compileOnlyConfig);
configurations.getByName(csaccessSourceSet.getCompileClasspathConfigurationName()).extendsFrom(compileClasspathConfig);
configurations.getByName(csaccessSourceSet.getRuntimeConfigurationName()).extendsFrom(runtimeConfig);
// Wire task dependencies to match the classpath dependencies (arrow means "depends on"):
// - compileTestJava -> compileCsaccessJava
// - testClasses -> csaccessClasses
// - jar -> csaccessClasses
final TaskContainer tasks = project.getTasks();
tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getCompileJavaTaskName()));
tasks.getByName(JavaPlugin.TEST_CLASSES_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName()));
tasks.getByName(JavaPlugin.JAR_TASK_NAME).dependsOn(tasks.getByName(csaccessSourceSet.getClassesTaskName()));
return this;
}
use of org.gradle.api.tasks.SourceSet in project jib by google.
the class GradleSourceFilesConfigurationTest method setUp.
@Before
public void setUp() throws URISyntaxException, IOException {
Project mockProject = Mockito.mock(Project.class);
Convention mockConvention = Mockito.mock(Convention.class);
JavaPluginConvention mockJavaPluginConvention = Mockito.mock(JavaPluginConvention.class);
SourceSetContainer mockSourceSetContainer = Mockito.mock(SourceSetContainer.class);
SourceSet mockMainSourceSet = Mockito.mock(SourceSet.class);
SourceSetOutput mockMainSourceSetOutput = Mockito.mock(SourceSetOutput.class);
Set<File> classesFiles = ImmutableSet.of(Paths.get(Resources.getResource("application/classes").toURI()).toFile());
FileCollection classesFileCollection = new TestFileCollection(classesFiles);
File resourcesOutputDir = Paths.get(Resources.getResource("application/resources").toURI()).toFile();
Set<File> allFiles = new HashSet<>(classesFiles);
allFiles.add(resourcesOutputDir);
allFiles.add(Paths.get(Resources.getResource("application/dependencies/libraryB.jar").toURI()).toFile());
allFiles.add(Paths.get(Resources.getResource("application/dependencies/libraryA.jar").toURI()).toFile());
allFiles.add(Paths.get(Resources.getResource("application/dependencies/dependency-1.0.0.jar").toURI()).toFile());
FileCollection runtimeFileCollection = new TestFileCollection(allFiles);
Mockito.when(mockProject.getConvention()).thenReturn(mockConvention);
Mockito.when(mockConvention.getPlugin(JavaPluginConvention.class)).thenReturn(mockJavaPluginConvention);
Mockito.when(mockJavaPluginConvention.getSourceSets()).thenReturn(mockSourceSetContainer);
Mockito.when(mockSourceSetContainer.getByName("main")).thenReturn(mockMainSourceSet);
Mockito.when(mockMainSourceSet.getOutput()).thenReturn(mockMainSourceSetOutput);
Mockito.when(mockMainSourceSetOutput.getClassesDirs()).thenReturn(classesFileCollection);
Mockito.when(mockMainSourceSetOutput.getResourcesDir()).thenReturn(resourcesOutputDir);
Mockito.when(mockMainSourceSet.getRuntimeClasspath()).thenReturn(runtimeFileCollection);
testGradleSourceFilesConfiguration = GradleSourceFilesConfiguration.getForProject(mockProject);
}
Aggregations