Search in sources :

Example 46 with SourceSet

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;
}
Also used : SourceFolder(org.gradle.plugins.ide.eclipse.model.SourceFolder) SourceSet(org.gradle.api.tasks.SourceSet) DirectoryTree(org.gradle.api.file.DirectoryTree) File(java.io.File)

Example 47 with SourceSet

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;
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Dependency(org.gradle.api.artifacts.Dependency) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) File(java.io.File)

Example 48 with SourceSet

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);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) File(java.io.File)

Example 49 with SourceSet

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;
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) TaskContainer(org.gradle.api.tasks.TaskContainer) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Example 50 with SourceSet

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);
}
Also used : Project(org.gradle.api.Project) SourceSet(org.gradle.api.tasks.SourceSet) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) Convention(org.gradle.api.plugins.Convention) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) AbstractFileCollection(org.gradle.api.internal.file.AbstractFileCollection) FileCollection(org.gradle.api.file.FileCollection) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) SourceSetOutput(org.gradle.api.tasks.SourceSetOutput) File(java.io.File) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)76 File (java.io.File)34 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)31 Configuration (org.gradle.api.artifacts.Configuration)26 Project (org.gradle.api.Project)24 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)23 Task (org.gradle.api.Task)18 List (java.util.List)17 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)17 JavaPlugin (org.gradle.api.plugins.JavaPlugin)16 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)16 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)16 Plugin (org.gradle.api.Plugin)15 FileCollection (org.gradle.api.file.FileCollection)15 Action (org.gradle.api.Action)14 TaskProvider (org.gradle.api.tasks.TaskProvider)14 Set (java.util.Set)13 Jar (org.gradle.api.tasks.bundling.Jar)13 Collections (java.util.Collections)12 Collectors (java.util.stream.Collectors)12