Search in sources :

Example 11 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class JavaGradlePluginPlugin method configureTaskPropertiesValidation.

private void configureTaskPropertiesValidation(Project project) {
    ValidateTaskProperties validator = project.getTasks().create(VALIDATE_TASK_PROPERTIES_TASK_NAME, ValidateTaskProperties.class);
    validator.setGroup(PLUGIN_DEVELOPMENT_GROUP);
    validator.setDescription(VALIDATE_TASK_PROPERTIES_TASK_DESCRIPTION);
    validator.getOutputFile().set(project.getLayout().getBuildDirectory().file("reports/task-properties/report.txt"));
    final SourceSet mainSourceSet = project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    validator.setClasses(mainSourceSet.getOutput().getClassesDirs());
    validator.setClasspath(mainSourceSet.getCompileClasspath());
    validator.dependsOn(mainSourceSet.getOutput());
    project.getTasks().getByName(JavaBasePlugin.CHECK_TASK_NAME).dependsOn(validator);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ValidateTaskProperties(org.gradle.plugin.devel.tasks.ValidateTaskProperties)

Example 12 with SourceSet

use of org.gradle.api.tasks.SourceSet in project gradle by gradle.

the class JavaLibraryPlugin method addApiToMainSourceSet.

private void addApiToMainSourceSet(Project project, JavaPluginConvention convention, ConfigurationContainer configurations) {
    SourceSet sourceSet = convention.getSourceSets().getByName("main");
    Configuration apiConfiguration = configurations.maybeCreate(sourceSet.getApiConfigurationName());
    apiConfiguration.setVisible(false);
    apiConfiguration.setDescription("API dependencies for " + sourceSet + ".");
    apiConfiguration.setCanBeResolved(false);
    apiConfiguration.setCanBeConsumed(false);
    Configuration apiElementsConfiguration = configurations.getByName(sourceSet.getApiElementsConfigurationName());
    apiElementsConfiguration.extendsFrom(apiConfiguration);
    final JavaCompile javaCompile = (JavaCompile) project.getTasks().getByPath(COMPILE_JAVA_TASK_NAME);
    // Define a classes variant to use for compilation
    ConfigurationPublications publications = apiElementsConfiguration.getOutgoing();
    ConfigurationVariant variant = publications.getVariants().create("classes");
    variant.getAttributes().attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.class, Usage.JAVA_API_CLASSES));
    variant.artifact(new JavaPlugin.IntermediateJavaArtifact(ArtifactTypeDefinition.JVM_CLASS_DIRECTORY, javaCompile) {

        @Override
        public File getFile() {
            return javaCompile.getDestinationDir();
        }
    });
    Configuration implementationConfiguration = configurations.getByName(sourceSet.getImplementationConfigurationName());
    implementationConfiguration.extendsFrom(apiConfiguration);
    Configuration compileConfiguration = configurations.getByName(sourceSet.getCompileConfigurationName());
    apiConfiguration.extendsFrom(compileConfiguration);
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) ConfigurationVariant(org.gradle.api.artifacts.ConfigurationVariant) Usage(org.gradle.api.attributes.Usage) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationPublications(org.gradle.api.artifacts.ConfigurationPublications) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) File(java.io.File)

Example 13 with SourceSet

use of org.gradle.api.tasks.SourceSet in project checkstyle-idea by jshiell.

the class CustomSourceSetCreator method establishCsAccessTestSourceSet.

public CustomSourceSetCreator establishCsAccessTestSourceSet() {
    final SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
    final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
    final SourceSet csaccessSourceSet = sourceSets.getByName(CSACCESS_SOURCESET_NAME);
    final SourceSet testSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    // Create the 'csaccess' source set
    final SourceSet csaccessTestSourceSet = sourceSets.create(CSACCESSTEST_SOURCESET_NAME);
    csaccessTestSourceSet.setCompileClasspath(csaccessTestSourceSet.getCompileClasspath().plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput()));
    csaccessTestSourceSet.setRuntimeClasspath(csaccessTestSourceSet.getRuntimeClasspath().plus(mainSourceSet.getOutput()).plus(csaccessSourceSet.getOutput()));
    sourceSets.add(csaccessTestSourceSet);
    // Derive all its configurations from 'test' and 'csaccess'
    final ConfigurationContainer configurations = project.getConfigurations();
    final Configuration csaccessCompileConfig = configurations.getByName(csaccessSourceSet.getCompileConfigurationName());
    final Configuration csaccessCompileOnlyConfig = configurations.getByName(csaccessSourceSet.getCompileOnlyConfigurationName());
    final Configuration csaccessCompileClasspathConfig = configurations.getByName(csaccessSourceSet.getCompileClasspathConfigurationName());
    final Configuration csaccessRuntimeConfig = configurations.getByName(csaccessSourceSet.getRuntimeConfigurationName());
    final Configuration testCompileConfig = configurations.getByName(testSourceSet.getCompileConfigurationName());
    final Configuration testCompileOnlyConfig = configurations.getByName(testSourceSet.getCompileOnlyConfigurationName());
    final Configuration testCompileClasspathConfig = configurations.getByName(testSourceSet.getCompileClasspathConfigurationName());
    final Configuration testRuntimeConfig = configurations.getByName(testSourceSet.getRuntimeConfigurationName());
    configurations.getByName(csaccessTestSourceSet.getCompileConfigurationName()).extendsFrom(csaccessCompileConfig, testCompileConfig);
    configurations.getByName(csaccessTestSourceSet.getCompileOnlyConfigurationName()).extendsFrom(csaccessCompileOnlyConfig, testCompileOnlyConfig);
    configurations.getByName(csaccessTestSourceSet.getCompileClasspathConfigurationName()).extendsFrom(csaccessCompileClasspathConfig, testCompileClasspathConfig);
    configurations.getByName(csaccessTestSourceSet.getRuntimeConfigurationName()).extendsFrom(csaccessRuntimeConfig, testRuntimeConfig);
    // Wire task dependencies to match the classpath dependencies (arrow means "depends on"):
    // - compileCsaccessTestJava -> compileCsaccessJava
    // - csaccessTestClasses     -> csaccessClasses
    final TaskContainer tasks = project.getTasks();
    tasks.getByName(csaccessTestSourceSet.getCompileJavaTaskName()).dependsOn(tasks.getByName(csaccessSourceSet.getCompileJavaTaskName()));
    tasks.getByName(csaccessTestSourceSet.getClassesTaskName()).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 14 with SourceSet

use of org.gradle.api.tasks.SourceSet in project crnk-framework by crnk-project.

the class RuntimeClassLoaderFactory method getProjectLibraries.

public Set<File> getProjectLibraries() {
    Set<File> classpath = new HashSet<>();
    SourceSetContainer sourceSets = (SourceSetContainer) project.getProperties().get("sourceSets");
    if (sourceSets != null) {
        SortedSet<String> availableSourceSetNames = sourceSets.getNames();
        for (String sourceSetName : Arrays.asList("main", "test", "integrationTest")) {
            if (availableSourceSetNames.contains(sourceSetName)) {
                SourceSet sourceSet = sourceSets.getByName(sourceSetName);
                classpath.add(sourceSet.getOutput().getClassesDir());
            }
        }
    }
    // add  dependencies from configured gradle configuration to url (usually test or integrationTest)
    TSGeneratorConfig generatorConfiguration = project.getExtensions().getByType(TSGeneratorConfig.class);
    String configurationName = generatorConfiguration.getRuntime().getConfiguration();
    ConfigurationContainer configurations = project.getConfigurations();
    Configuration runtimeConfiguration = configurations.findByName(configurationName + "Runtime");
    if (runtimeConfiguration == null) {
        runtimeConfiguration = configurations.getByName(configurationName);
    }
    classpath.addAll(runtimeConfiguration.getFiles());
    for (File file : classpath) {
        LOGGER.debug("classpath entry: {}", file);
    }
    return classpath;
}
Also used : SourceSet(org.gradle.api.tasks.SourceSet) TSNpmConfiguration(io.crnk.gen.typescript.TSNpmConfiguration) Configuration(org.gradle.api.artifacts.Configuration) TSRuntimeConfiguration(io.crnk.gen.typescript.TSRuntimeConfiguration) TSGeneratorConfig(io.crnk.gen.typescript.TSGeneratorConfig) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) File(java.io.File) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) HashSet(java.util.HashSet)

Example 15 with SourceSet

use of org.gradle.api.tasks.SourceSet in project Entitas-Java by Rubentxu.

the class TestProject method getSrcDirs.

@Override
public List<String> getSrcDirs() {
    SourceSetContainer sourceSets = javaConvention.getSourceSets();
    SourceSet mainSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME);
    return mainSourceSet.getAllSource().getSrcDirs().stream().map(f -> {
        try {
            return f.getCanonicalPath();
        } catch (IOException e) {
            return "";
        }
    }).collect(Collectors.toList());
}
Also used : List(java.util.List) Project(org.gradle.api.Project) JavaPluginConvention(org.gradle.api.plugins.JavaPluginConvention) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) JavaPlugin(org.gradle.api.plugins.JavaPlugin) IOException(java.io.IOException) IAppDomain(ilargia.entitas.codeGeneration.interfaces.IAppDomain) Collectors(java.util.stream.Collectors) SourceSet(org.gradle.api.tasks.SourceSet) SourceSet(org.gradle.api.tasks.SourceSet) IOException(java.io.IOException) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer)

Aggregations

SourceSet (org.gradle.api.tasks.SourceSet)55 File (java.io.File)28 SourceSetContainer (org.gradle.api.tasks.SourceSetContainer)24 Project (org.gradle.api.Project)20 Configuration (org.gradle.api.artifacts.Configuration)19 JavaPluginConvention (org.gradle.api.plugins.JavaPluginConvention)18 JavaCompile (org.gradle.api.tasks.compile.JavaCompile)15 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)14 List (java.util.List)13 Task (org.gradle.api.Task)13 JavaPlugin (org.gradle.api.plugins.JavaPlugin)12 JavaPluginExtension (org.gradle.api.plugins.JavaPluginExtension)12 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)11 Collections (java.util.Collections)10 Action (org.gradle.api.Action)10 Plugin (org.gradle.api.Plugin)10 JavaBasePlugin (org.gradle.api.plugins.JavaBasePlugin)10 Jar (org.gradle.api.tasks.bundling.Jar)10 HashSet (java.util.HashSet)9