Search in sources :

Example 6 with ConfigurationContainer

use of org.gradle.api.artifacts.ConfigurationContainer in project intellij-community by JetBrains.

the class ModuleExtendedModelBuilderImpl method buildAll.

@Nullable
@Override
public Object buildAll(String modelName, Project project) {
    final String moduleName = project.getName();
    final String moduleGroup = project.getGroup().toString();
    final String moduleVersion = project.getVersion().toString();
    final File buildDir = project.getBuildDir();
    String javaSourceCompatibility = null;
    for (Task task : project.getTasks()) {
        if (task instanceof JavaCompile) {
            JavaCompile javaCompile = (JavaCompile) task;
            javaSourceCompatibility = javaCompile.getSourceCompatibility();
            if (task.getName().equals("compileJava"))
                break;
        }
    }
    final ModuleExtendedModelImpl moduleVersionModel = new ModuleExtendedModelImpl(moduleName, moduleGroup, moduleVersion, buildDir, javaSourceCompatibility);
    final List<File> artifacts = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Jar) {
            Jar jar = (Jar) task;
            artifacts.add(jar.getArchivePath());
        }
    }
    moduleVersionModel.setArtifacts(artifacts);
    final Set<String> sourceDirectories = new HashSet<String>();
    final Set<String> testDirectories = new HashSet<String>();
    final Set<String> resourceDirectories = new HashSet<String>();
    final Set<String> testResourceDirectories = new HashSet<String>();
    final List<File> testClassesDirs = new ArrayList<File>();
    for (Task task : project.getTasks()) {
        if (task instanceof Test) {
            Test test = (Test) task;
            testClassesDirs.add(test.getTestClassesDir());
            if (test.hasProperty(TEST_SRC_DIRS_PROPERTY)) {
                Object testSrcDirs = test.property(TEST_SRC_DIRS_PROPERTY);
                if (testSrcDirs instanceof Iterable) {
                    for (Object dir : Iterable.class.cast(testSrcDirs)) {
                        addFilePath(testDirectories, dir);
                    }
                }
            }
        }
    }
    IdeaCompilerOutputImpl compilerOutput = new IdeaCompilerOutputImpl();
    if (project.hasProperty(SOURCE_SETS_PROPERTY)) {
        Object sourceSets = project.property(SOURCE_SETS_PROPERTY);
        if (sourceSets instanceof SourceSetContainer) {
            SourceSetContainer sourceSetContainer = (SourceSetContainer) sourceSets;
            for (SourceSet sourceSet : sourceSetContainer) {
                SourceSetOutput output = sourceSet.getOutput();
                if (SourceSet.TEST_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setTestClassesDir(output.getClassesDir());
                    compilerOutput.setTestResourcesDir(output.getResourcesDir());
                }
                if (SourceSet.MAIN_SOURCE_SET_NAME.equals(sourceSet.getName())) {
                    compilerOutput.setMainClassesDir(output.getClassesDir());
                    compilerOutput.setMainResourcesDir(output.getResourcesDir());
                }
                for (File javaSrcDir : sourceSet.getAllJava().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testDirectories : sourceDirectories, javaSrcDir);
                }
                for (File resourcesSrcDir : sourceSet.getResources().getSrcDirs()) {
                    boolean isTestDir = isTestDir(sourceSet, testClassesDirs);
                    addFilePath(isTestDir ? testResourceDirectories : resourceDirectories, resourcesSrcDir);
                }
            }
        }
    }
    File projectDir = project.getProjectDir();
    IdeaContentRootImpl contentRoot = new IdeaContentRootImpl(projectDir);
    final Set<String> ideaSourceDirectories = new HashSet<String>();
    final Set<String> ideaTestDirectories = new HashSet<String>();
    final Set<String> ideaGeneratedDirectories = new HashSet<String>();
    final Set<File> excludeDirectories = new HashSet<File>();
    enrichDataFromIdeaPlugin(project, excludeDirectories, ideaSourceDirectories, ideaTestDirectories, ideaGeneratedDirectories);
    if (ideaSourceDirectories.isEmpty()) {
        sourceDirectories.clear();
        resourceDirectories.clear();
    }
    if (ideaTestDirectories.isEmpty()) {
        testDirectories.clear();
        testResourceDirectories.clear();
    }
    ideaSourceDirectories.removeAll(resourceDirectories);
    sourceDirectories.removeAll(ideaTestDirectories);
    sourceDirectories.addAll(ideaSourceDirectories);
    ideaTestDirectories.removeAll(testResourceDirectories);
    testDirectories.addAll(ideaTestDirectories);
    // ensure disjoint directories with different type
    resourceDirectories.removeAll(sourceDirectories);
    testDirectories.removeAll(sourceDirectories);
    testResourceDirectories.removeAll(testDirectories);
    for (String javaDir : sourceDirectories) {
        contentRoot.addSourceDirectory(new IdeaSourceDirectoryImpl(new File(javaDir), ideaGeneratedDirectories.contains(javaDir)));
    }
    for (String testDir : testDirectories) {
        contentRoot.addTestDirectory(new IdeaSourceDirectoryImpl(new File(testDir), ideaGeneratedDirectories.contains(testDir)));
    }
    for (String resourceDir : resourceDirectories) {
        contentRoot.addResourceDirectory(new IdeaSourceDirectoryImpl(new File(resourceDir)));
    }
    for (String testResourceDir : testResourceDirectories) {
        contentRoot.addTestResourceDirectory(new IdeaSourceDirectoryImpl(new File(testResourceDir)));
    }
    for (File excludeDir : excludeDirectories) {
        contentRoot.addExcludeDirectory(excludeDir);
    }
    moduleVersionModel.setContentRoots(Collections.<ExtIdeaContentRoot>singleton(contentRoot));
    moduleVersionModel.setCompilerOutput(compilerOutput);
    ConfigurationContainer configurations = project.getConfigurations();
    SortedMap<String, Configuration> configurationsByName = configurations.getAsMap();
    Map<String, Set<File>> artifactsByConfiguration = new HashMap<String, Set<File>>();
    for (Map.Entry<String, Configuration> configurationEntry : configurationsByName.entrySet()) {
        Set<File> files = configurationEntry.getValue().getAllArtifacts().getFiles().getFiles();
        artifactsByConfiguration.put(configurationEntry.getKey(), files);
    }
    moduleVersionModel.setArtifactsByConfiguration(artifactsByConfiguration);
    return moduleVersionModel;
}
Also used : Task(org.gradle.api.Task) SourceSet(org.gradle.api.tasks.SourceSet) Configuration(org.gradle.api.artifacts.Configuration) IdeaContentRootImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaContentRootImpl) SourceSetContainer(org.gradle.api.tasks.SourceSetContainer) SourceSetOutput(org.gradle.api.tasks.SourceSetOutput) ModuleExtendedModelImpl(org.jetbrains.plugins.gradle.tooling.internal.ModuleExtendedModelImpl) SourceSet(org.gradle.api.tasks.SourceSet) Test(org.gradle.api.tasks.testing.Test) IdeaSourceDirectoryImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaSourceDirectoryImpl) IdeaCompilerOutputImpl(org.jetbrains.plugins.gradle.tooling.internal.IdeaCompilerOutputImpl) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Jar(org.gradle.api.tasks.bundling.Jar) File(java.io.File) JavaCompile(org.gradle.api.tasks.compile.JavaCompile) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with ConfigurationContainer

use of org.gradle.api.artifacts.ConfigurationContainer in project gradle by gradle.

the class EarPlugin method configureConfigurations.

private void configureConfigurations(final Project project) {
    ConfigurationContainer configurations = project.getConfigurations();
    Configuration moduleConfiguration = configurations.create(DEPLOY_CONFIGURATION_NAME).setVisible(false).setTransitive(false).setDescription("Classpath for deployable modules, not transitive.");
    Configuration earlibConfiguration = configurations.create(EARLIB_CONFIGURATION_NAME).setVisible(false).setDescription("Classpath for module dependencies.");
    configurations.getByName(Dependency.DEFAULT_CONFIGURATION).extendsFrom(moduleConfiguration, earlibConfiguration);
}
Also used : Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer)

Example 8 with ConfigurationContainer

use of org.gradle.api.artifacts.ConfigurationContainer in project gradle by gradle.

the class DefaultProjectDependency method findProjectConfiguration.

@Override
public Configuration findProjectConfiguration() {
    ConfigurationContainer dependencyConfigurations = getDependencyProject().getConfigurations();
    String declaredConfiguration = getTargetConfiguration();
    Configuration selectedConfiguration = dependencyConfigurations.getByName(GUtil.elvis(declaredConfiguration, Dependency.DEFAULT_CONFIGURATION));
    if (!selectedConfiguration.isCanBeConsumed()) {
        throw new ConfigurationNotConsumableException(dependencyProject.getDisplayName(), selectedConfiguration.getName());
    }
    return selectedConfiguration;
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) Configuration(org.gradle.api.artifacts.Configuration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer)

Example 9 with ConfigurationContainer

use of org.gradle.api.artifacts.ConfigurationContainer in project gradle by gradle.

the class JavaBasePlugin method configureSourceSetDefaults.

private BridgedBinaries configureSourceSetDefaults(final JavaPluginConvention pluginConvention) {
    final Project project = pluginConvention.getProject();
    final List<ClassDirectoryBinarySpecInternal> binaries = Lists.newArrayList();
    pluginConvention.getSourceSets().all(new Action<SourceSet>() {

        public void execute(final SourceSet sourceSet) {
            ConventionMapping outputConventionMapping = ((IConventionAware) sourceSet.getOutput()).getConventionMapping();
            ConfigurationContainer configurations = project.getConfigurations();
            defineConfigurationsForSourceSet(sourceSet, configurations);
            definePathsForSourceSet(sourceSet, outputConventionMapping, project);
            createProcessResourcesTaskForBinary(sourceSet, sourceSet.getResources(), project);
            createCompileJavaTaskForBinary(sourceSet, sourceSet.getJava(), project);
            createBinaryLifecycleTask(sourceSet, project);
            DefaultComponentSpecIdentifier binaryId = new DefaultComponentSpecIdentifier(project.getPath(), sourceSet.getName());
            ClassDirectoryBinarySpecInternal binary = instantiator.newInstance(DefaultClassDirectoryBinarySpec.class, binaryId, sourceSet, javaToolChain, DefaultJavaPlatform.current(), instantiator, taskFactory);
            Classpath compileClasspath = new SourceSetCompileClasspath(sourceSet);
            DefaultJavaSourceSet javaSourceSet = instantiator.newInstance(DefaultJavaSourceSet.class, binaryId.child("java"), sourceSet.getJava(), compileClasspath);
            JvmResourceSet resourceSet = instantiator.newInstance(DefaultJvmResourceSet.class, binaryId.child("resources"), sourceSet.getResources());
            binary.addSourceSet(javaSourceSet);
            binary.addSourceSet(resourceSet);
            attachTasksToBinary(binary, sourceSet, project);
            binaries.add(binary);
        }
    });
    return new BridgedBinaries(binaries);
}
Also used : ClassDirectoryBinarySpecInternal(org.gradle.api.internal.jvm.ClassDirectoryBinarySpecInternal) ConventionMapping(org.gradle.api.internal.ConventionMapping) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) JvmResourceSet(org.gradle.language.jvm.JvmResourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) Project(org.gradle.api.Project) ProjectSourceSet(org.gradle.language.base.ProjectSourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) SourceSet(org.gradle.api.tasks.SourceSet) DefaultJvmResourceSet(org.gradle.api.internal.java.DefaultJvmResourceSet) DefaultJavaSourceSet(org.gradle.api.internal.java.DefaultJavaSourceSet) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) DefaultClassDirectoryBinarySpec(org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec) Classpath(org.gradle.jvm.Classpath) SourceSetCompileClasspath(org.gradle.api.internal.tasks.SourceSetCompileClasspath) DefaultComponentSpecIdentifier(org.gradle.platform.base.internal.DefaultComponentSpecIdentifier)

Example 10 with ConfigurationContainer

use of org.gradle.api.artifacts.ConfigurationContainer in project gradle by gradle.

the class JavaLibraryPlugin method apply.

@Override
public void apply(Project project) {
    project.getPluginManager().apply(JavaPlugin.class);
    JavaPluginConvention convention = (JavaPluginConvention) project.getConvention().getPlugins().get("java");
    ConfigurationContainer configurations = project.getConfigurations();
    addApiToMainSourceSet(convention, configurations);
}
Also used : ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer)

Aggregations

ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)10 Configuration (org.gradle.api.artifacts.Configuration)8 Project (org.gradle.api.Project)2 SourceSet (org.gradle.api.tasks.SourceSet)2 File (java.io.File)1 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Action (org.gradle.api.Action)1 Task (org.gradle.api.Task)1 Dependency (org.gradle.api.artifacts.Dependency)1 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)1 FileCollection (org.gradle.api.file.FileCollection)1 ConventionMapping (org.gradle.api.internal.ConventionMapping)1 DefaultExternalModuleDependency (org.gradle.api.internal.artifacts.dependencies.DefaultExternalModuleDependency)1 DefaultJavaSourceSet (org.gradle.api.internal.java.DefaultJavaSourceSet)1 DefaultJvmResourceSet (org.gradle.api.internal.java.DefaultJvmResourceSet)1 ClassDirectoryBinarySpecInternal (org.gradle.api.internal.jvm.ClassDirectoryBinarySpecInternal)1 DefaultClassDirectoryBinarySpec (org.gradle.api.internal.jvm.DefaultClassDirectoryBinarySpec)1 DefaultArtifactPublicationSet (org.gradle.api.internal.plugins.DefaultArtifactPublicationSet)1