mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Gradle: compiler output folder configuration fix;
related issue - IDEA-128514 Gradle project totally fails to build
This commit is contained in:
+11
@@ -43,6 +43,8 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector
|
||||
@NotNull
|
||||
private List<ExternalFilter> myFilters;
|
||||
|
||||
private boolean myInheritedCompilerOutput;
|
||||
|
||||
public DefaultExternalSourceDirectorySet() {
|
||||
mySrcDirs = new HashSet<File>();
|
||||
myExcludes = new HashSet<String>();
|
||||
@@ -88,6 +90,15 @@ public class DefaultExternalSourceDirectorySet implements ExternalSourceDirector
|
||||
return myOutputDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompilerOutputPathInherited() {
|
||||
return myInheritedCompilerOutput;
|
||||
}
|
||||
|
||||
public void setInheritedCompilerOutput(boolean inheritedCompilerOutput) {
|
||||
myInheritedCompilerOutput = inheritedCompilerOutput;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<String> getIncludes() {
|
||||
|
||||
+6
@@ -36,6 +36,12 @@ public interface ExternalSourceDirectorySet extends Serializable {
|
||||
@NotNull
|
||||
File getOutputDir();
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if compiler output for this ExternalSourceDirectorySet should is inherited from IDEA project
|
||||
* @return true if compiler output path is inherited, false otherwise
|
||||
*/
|
||||
boolean isCompilerOutputPathInherited();
|
||||
|
||||
@NotNull
|
||||
Set<String> getExcludes();
|
||||
@NotNull
|
||||
|
||||
+6
-2
@@ -157,6 +157,11 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
|
||||
assertEquals(testOutput, getAbsolutePath(e.getCompilerOutputUrlForTests()));
|
||||
}
|
||||
|
||||
protected void assertModuleInheritedOutput(String moduleName) {
|
||||
CompilerModuleExtension e = getCompilerExtension(moduleName);
|
||||
assertTrue(e.isCompilerOutputPathInherited());
|
||||
}
|
||||
|
||||
private static String getAbsolutePath(String path) {
|
||||
path = VfsUtil.urlToPath(path);
|
||||
path = PathUtil.getCanonicalPath(path);
|
||||
@@ -168,8 +173,7 @@ public abstract class ExternalSystemImportingTestCase extends ExternalSystemTest
|
||||
}
|
||||
|
||||
protected CompilerModuleExtension getCompilerExtension(String module) {
|
||||
ModuleRootManager m = getRootManager(module);
|
||||
return CompilerModuleExtension.getInstance(m.getModule());
|
||||
return CompilerModuleExtension.getInstance(getModule(module));
|
||||
}
|
||||
|
||||
protected void assertModuleLibDep(String moduleName, String depName) {
|
||||
|
||||
+2
@@ -107,6 +107,8 @@ public class GradleOrderEnumeratorHandler extends OrderEnumerationHandler {
|
||||
final ExternalSourceDirectorySet directorySet = externalSourceSet.getSources().get(sourceType);
|
||||
if (directorySet == null) return;
|
||||
|
||||
if (directorySet.isCompilerOutputPathInherited()) return;
|
||||
|
||||
result.add(VfsUtilCore.pathToUrl(directorySet.getOutputDir().getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
+22
-14
@@ -230,8 +230,8 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
|
||||
File sourceCompileOutputPath = null;
|
||||
File testCompileOutputPath = null;
|
||||
File resourceCompileOutputPath;
|
||||
File testResourceCompileOutputPath;
|
||||
File resourceCompileOutputPath = null;
|
||||
File testResourceCompileOutputPath = null;
|
||||
boolean inheritOutputDirs = false;
|
||||
|
||||
ModuleData moduleData = ideModule.getData();
|
||||
@@ -244,21 +244,22 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
ExternalProject externalProject = resolverCtx.getExtraProject(gradleModule, ExternalProject.class);
|
||||
if (externalProject != null) {
|
||||
externalProject = new DefaultExternalProject(externalProject);
|
||||
}
|
||||
|
||||
if (!inheritOutputDirs && (sourceCompileOutputPath == null || testCompileOutputPath == null)) {
|
||||
sourceCompileOutputPath = getCompileOutputPath(externalProject, MAIN_SOURCE_SET, ExternalSystemSourceType.SOURCE);
|
||||
resourceCompileOutputPath = getCompileOutputPath(externalProject, MAIN_SOURCE_SET, ExternalSystemSourceType.RESOURCE);
|
||||
testCompileOutputPath = getCompileOutputPath(externalProject, TEST_SOURCE_SET, ExternalSystemSourceType.TEST);
|
||||
testResourceCompileOutputPath = getCompileOutputPath(externalProject, TEST_SOURCE_SET, ExternalSystemSourceType.TEST_RESOURCE);
|
||||
}
|
||||
else {
|
||||
resourceCompileOutputPath = sourceCompileOutputPath;
|
||||
testResourceCompileOutputPath = testCompileOutputPath;
|
||||
|
||||
if (externalProject != null) {
|
||||
if (!inheritOutputDirs && (sourceCompileOutputPath == null || testCompileOutputPath == null)) {
|
||||
sourceCompileOutputPath = getCompileOutputPath(externalProject, MAIN_SOURCE_SET, ExternalSystemSourceType.SOURCE);
|
||||
resourceCompileOutputPath = getCompileOutputPath(externalProject, MAIN_SOURCE_SET, ExternalSystemSourceType.RESOURCE);
|
||||
testCompileOutputPath = getCompileOutputPath(externalProject, TEST_SOURCE_SET, ExternalSystemSourceType.TEST);
|
||||
testResourceCompileOutputPath = getCompileOutputPath(externalProject, TEST_SOURCE_SET, ExternalSystemSourceType.TEST_RESOURCE);
|
||||
}
|
||||
else if (!inheritOutputDirs) {
|
||||
resourceCompileOutputPath = sourceCompileOutputPath;
|
||||
testResourceCompileOutputPath = testCompileOutputPath;
|
||||
final ExternalSourceSet mainSourceSet = externalProject.getSourceSets().get(MAIN_SOURCE_SET);
|
||||
if (mainSourceSet != null) {
|
||||
final ExternalSourceDirectorySet sourceDirectories = mainSourceSet.getSources().get(ExternalSystemSourceType.SOURCE);
|
||||
if (sourceDirectories instanceof DefaultExternalSourceDirectorySet) {
|
||||
((DefaultExternalSourceDirectorySet)sourceDirectories).setOutputDir(sourceCompileOutputPath);
|
||||
}
|
||||
final ExternalSourceDirectorySet resourceDirectories = mainSourceSet.getSources().get(ExternalSystemSourceType.RESOURCE);
|
||||
if (resourceDirectories instanceof DefaultExternalSourceDirectorySet) {
|
||||
((DefaultExternalSourceDirectorySet)resourceDirectories).setOutputDir(sourceCompileOutputPath);
|
||||
@@ -266,6 +267,10 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
}
|
||||
final ExternalSourceSet testSourceSet = externalProject.getSourceSets().get(TEST_SOURCE_SET);
|
||||
if (testSourceSet != null) {
|
||||
final ExternalSourceDirectorySet testDirectories = testSourceSet.getSources().get(ExternalSystemSourceType.TEST);
|
||||
if (testDirectories instanceof DefaultExternalSourceDirectorySet) {
|
||||
((DefaultExternalSourceDirectorySet)testDirectories).setOutputDir(testCompileOutputPath);
|
||||
}
|
||||
final ExternalSourceDirectorySet testResourceDirectories = testSourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE);
|
||||
if (testResourceDirectories instanceof DefaultExternalSourceDirectorySet) {
|
||||
((DefaultExternalSourceDirectorySet)testResourceDirectories).setOutputDir(testCompileOutputPath);
|
||||
@@ -277,6 +282,9 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
|
||||
projectDataNode.createOrReplaceChild(ExternalProjectDataService.KEY, externalProject);
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG.warn(String.format("Unable to get ExternalProject model for '%s'", gradleModule.getName()));
|
||||
}
|
||||
|
||||
if (sourceCompileOutputPath != null) {
|
||||
moduleData.setCompileOutputPath(ExternalSystemSourceType.SOURCE, sourceCompileOutputPath.getAbsolutePath());
|
||||
|
||||
+31
-5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.gradle.importing;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
@@ -34,14 +35,39 @@ public class GradleFoldersImportingTest extends GradleImportingTestCase {
|
||||
assertModules("project");
|
||||
assertContentRoots("project", getProjectPath());
|
||||
|
||||
assertSources("project", "src/main/java");
|
||||
assertResources("project", "src/main/resources");
|
||||
assertTestSources("project", "src/test/java");
|
||||
assertTestResources("project", "src/test/resources");
|
||||
assertExcludes("project", ".gradle", "build");
|
||||
assertDefaultGradleJavaProjectFolders("project");
|
||||
|
||||
assertModuleOutput("project",
|
||||
getProjectPath() + "/build/classes/main",
|
||||
getProjectPath() + "/build/classes/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProjectWithInheritedOutputDirs() throws Exception {
|
||||
|
||||
importProject(
|
||||
"apply plugin: 'java'\n" +
|
||||
"apply plugin: 'idea'\n" +
|
||||
"idea {\n" +
|
||||
" module {\n" +
|
||||
" inheritOutputDirs = true\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
|
||||
assertModules("project");
|
||||
assertContentRoots("project", getProjectPath());
|
||||
|
||||
assertDefaultGradleJavaProjectFolders("project");
|
||||
|
||||
assertModuleInheritedOutput("project");
|
||||
}
|
||||
|
||||
protected void assertDefaultGradleJavaProjectFolders(@NotNull String moduleName) {
|
||||
assertSources(moduleName, "src/main/java");
|
||||
assertResources(moduleName, "src/main/resources");
|
||||
assertTestSources(moduleName, "src/test/java");
|
||||
assertTestResources(moduleName, "src/test/resources");
|
||||
assertExcludes(moduleName, ".gradle", "build");
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -26,6 +26,7 @@ import org.gradle.api.file.FileCopyDetails
|
||||
import org.gradle.api.tasks.SourceSet
|
||||
import org.gradle.api.tasks.SourceSetContainer
|
||||
import org.gradle.api.tasks.util.PatternFilterable
|
||||
import org.gradle.plugins.ide.idea.IdeaPlugin
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
|
||||
@@ -109,6 +110,9 @@ class ExternalProjectBuilderImpl implements ModelBuilderService {
|
||||
}
|
||||
|
||||
static Map<String, ExternalSourceSet> getSourceSets(Project project) {
|
||||
final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class);
|
||||
boolean inheritOutputDirs = ideaPlugin?.model?.module?.inheritOutputDirs ?: false
|
||||
|
||||
def result = [:] as Map<String, ExternalSourceSet>
|
||||
if (!project.hasProperty("sourceSets") || !(project.sourceSets instanceof SourceSetContainer)) {
|
||||
return result
|
||||
@@ -128,11 +132,13 @@ class ExternalProjectBuilderImpl implements ModelBuilderService {
|
||||
resourcesDirectorySet.name = sourceSet.resources.name
|
||||
resourcesDirectorySet.srcDirs = sourceSet.resources.srcDirs
|
||||
resourcesDirectorySet.outputDir = sourceSet.output.resourcesDir
|
||||
resourcesDirectorySet.inheritedCompilerOutput = inheritOutputDirs
|
||||
|
||||
ExternalSourceDirectorySet javaDirectorySet = new DefaultExternalSourceDirectorySet()
|
||||
javaDirectorySet.name = sourceSet.allJava.name
|
||||
javaDirectorySet.srcDirs = sourceSet.allJava.srcDirs
|
||||
javaDirectorySet.outputDir = sourceSet.output.classesDir
|
||||
javaDirectorySet.inheritedCompilerOutput = inheritOutputDirs
|
||||
// javaDirectorySet.excludes = javaExcludes + sourceSet.java.excludes;
|
||||
// javaDirectorySet.includes = javaIncludes + sourceSet.java.includes;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user