Skip to content

Commit

Permalink
Fix idea plugin convention mappings (gradle#8749)
Browse files Browse the repository at this point in the history
Signed-off-by: Björn Kautler <Bjoern@Kautler.net>
  • Loading branch information
Vampire committed Aug 17, 2021
1 parent f596512 commit 3ccd016
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,42 +369,50 @@ public FileCollection call() {

// Convention
ConventionMapping convention = ((IConventionAware) ideaModel.getModule()).getConventionMapping();
Set<File> sourceDirs = Sets.newLinkedHashSet();
convention.map("sourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
return sourceSets.getByName("main").getAllJava().getSrcDirs();
sourceDirs.addAll(sourceSets.getByName("main").getAllJava().getSrcDirs());
return sourceDirs;
}
});
Set<File> testSourceDirs = Sets.newLinkedHashSet();
convention.map("testSourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
return sourceSets.getByName("test").getAllJava().getSrcDirs();
testSourceDirs.addAll(sourceSets.getByName("test").getAllJava().getSrcDirs());
return testSourceDirs;
}
});
Set<File> resourceDirs = Sets.newLinkedHashSet();
convention.map("resourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
public Set<File> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
return sourceSets.getByName("main").getResources().getSrcDirs();
resourceDirs.addAll(sourceSets.getByName("main").getResources().getSrcDirs());
return resourceDirs;
}
});
Set<File> testResourceDirs = Sets.newLinkedHashSet();
convention.map("testResourceDirs", new Callable<Set<File>>() {
@Override
public Set<File> call() throws Exception {
public Set<File> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
return sourceSets.getByName("test").getResources().getSrcDirs();
testResourceDirs.addAll(sourceSets.getByName("test").getResources().getSrcDirs());
return testResourceDirs;
}
});
Map<String, FileCollection> singleEntryLibraries = new LinkedHashMap<String, FileCollection>(2);
convention.map("singleEntryLibraries", new Callable<Map<String, FileCollection>>() {
@Override
public Map<String, FileCollection> call() {
SourceSetContainer sourceSets = project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets();
LinkedHashMap<String, FileCollection> map = new LinkedHashMap<String, FileCollection>(2);
map.put("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
map.put("TEST", sourceSets.getByName("test").getOutput().getDirs());
return map;
singleEntryLibraries.putIfAbsent("RUNTIME", sourceSets.getByName("main").getOutput().getDirs());
singleEntryLibraries.putIfAbsent("TEST", sourceSets.getByName("test").getOutput().getDirs());
return singleEntryLibraries;
}

});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.gradle.plugins.ide.idea.model.IdeaLanguageLevel
import org.gradle.plugins.ide.idea.model.IdeaModel
import org.gradle.test.fixtures.AbstractProjectBuilderSpec
import org.gradle.util.TestUtil
import spock.lang.Issue

import static org.gradle.api.reflect.TypeOf.typeOf

Expand Down Expand Up @@ -213,6 +214,7 @@ class IdeaPluginTest extends AbstractProjectBuilderSpec {
publicTypeOfExtension("idea") == typeOf(IdeaModel)
}

@Issue('https://github.com/gradle/gradle/issues/8749')
def "can add to file set properties"() {
given:
applyPluginToProjects()
Expand All @@ -228,6 +230,23 @@ class IdeaPluginTest extends AbstractProjectBuilderSpec {
property << [{ it.sourceDirs }, { it.testSourceDirs }, { it.resourceDirs }, { it.testResourceDirs }, { it.excludeDirs }]
}

@Issue('https://github.com/gradle/gradle/issues/8749')
def "can add to file set properties when java plugin is applied too"() {
given:
project.apply plugin: JavaPlugin
applyPluginToProjects()
def source = new File("foo")

when:
property(project.idea.module).add(source)

then:
property(project.idea.module).contains(source)

where:
property << [{ it.sourceDirs }, { it.testSourceDirs }, { it.resourceDirs }, { it.testResourceDirs }, { it.excludeDirs }]
}

private TypeOf<?> publicTypeOfExtension(String named) {
project.extensions.extensionsSchema.find { it.name == named }.publicType
}
Expand Down

0 comments on commit 3ccd016

Please sign in to comment.