From 1f940f973a5da908c57814e8c788157e33dcbbfc Mon Sep 17 00:00:00 2001 From: Alex Ruiz Date: Mon, 26 May 2014 16:52:22 -0700 Subject: Added output folders to ModuleExtendedModel. Change-Id: I60bedaaa53c03f6613a9883d54f150ad1ba9ea09 (cherry picked from commit 69faf310f77b828ef4501bab19cf76dd94e0fc0c) --- .../BaseGradleProjectResolverExtension.java | 35 ++++++++---- .../gradle/model/ExtIdeaCompilerOutput.java | 47 ++++++++++++++++ .../plugins/gradle/model/ModuleExtendedModel.java | 7 +++ .../builder/ModuleExtendedModelBuilderImpl.java | 16 ++++++ .../tooling/internal/IdeaCompilerOutputImpl.java | 63 ++++++++++++++++++++++ .../tooling/internal/ModuleExtendedModelImpl.java | 11 ++++ 6 files changed, 170 insertions(+), 9 deletions(-) create mode 100644 plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExtIdeaCompilerOutput.java create mode 100644 plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaCompilerOutputImpl.java (limited to 'plugins') diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java index 9b1b288e2e8e..1a12d23fd062 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseGradleProjectResolverExtension.java @@ -214,23 +214,40 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver public void populateModuleCompileOutputSettings(@NotNull IdeaModule gradleModule, @NotNull DataNode ideModule) { IdeaCompilerOutput moduleCompilerOutput = gradleModule.getCompilerOutput(); - if (moduleCompilerOutput == null) { - return; - } - File sourceCompileOutputPath = moduleCompilerOutput.getOutputDir(); + File sourceCompileOutputPath = null; + File testCompileOutputPath = null; + boolean inheritOutputDirs = false; + ModuleData moduleData = ideModule.getData(); + if (moduleCompilerOutput != null) { + sourceCompileOutputPath = moduleCompilerOutput.getOutputDir(); + testCompileOutputPath = moduleCompilerOutput.getTestOutputDir(); + inheritOutputDirs = moduleCompilerOutput.getInheritOutputDirs(); + } + + if (!inheritOutputDirs && (sourceCompileOutputPath == null || testCompileOutputPath == null)) { + ModuleExtendedModel moduleExtendedModel = resolverCtx.getExtraProject(gradleModule, ModuleExtendedModel.class); + if (moduleExtendedModel != null) { + ExtIdeaCompilerOutput output = moduleExtendedModel.getCompilerOutput(); + if (output != null) { + if (sourceCompileOutputPath == null) { + sourceCompileOutputPath = output.getMainClassesDir(); + } + if (testCompileOutputPath == null) { + testCompileOutputPath = output.getTestClassesDir(); + } + } + } + } + if (sourceCompileOutputPath != null) { moduleData.setCompileOutputPath(ExternalSystemSourceType.SOURCE, sourceCompileOutputPath.getAbsolutePath()); } - - File testCompileOutputPath = moduleCompilerOutput.getTestOutputDir(); if (testCompileOutputPath != null) { moduleData.setCompileOutputPath(ExternalSystemSourceType.TEST, testCompileOutputPath.getAbsolutePath()); } - moduleData.setInheritProjectCompileOutputPath( - moduleCompilerOutput.getInheritOutputDirs() || sourceCompileOutputPath == null || testCompileOutputPath == null - ); + moduleData.setInheritProjectCompileOutputPath(inheritOutputDirs || sourceCompileOutputPath == null); } @Override diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExtIdeaCompilerOutput.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExtIdeaCompilerOutput.java new file mode 100644 index 000000000000..9ec688246599 --- /dev/null +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ExtIdeaCompilerOutput.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.model; + +import org.gradle.api.Nullable; + +import java.io.File; +import java.io.Serializable; + +public interface ExtIdeaCompilerOutput extends Serializable { + /** + * @return the directory to generate the classes of the "main" source set into. + */ + @Nullable + File getMainClassesDir(); + + /** + * @return the directory to generate the resources of the "main" source set into. + */ + @Nullable + File getMainResourcesDir(); + + /** + * @return the directory to generate the classes of the "test" source set into. + */ + @Nullable + File getTestClassesDir(); + + /** + * @return the directory to generate the resources of the "test" source set into. + */ + @Nullable + File getTestResourcesDir(); +} diff --git a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java index e9a99b93c82e..97dfd2547b73 100644 --- a/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java +++ b/plugins/gradle/tooling-extension-api/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java @@ -67,4 +67,11 @@ public interface ModuleExtendedModel extends Serializable { * @return the build directory. */ File getBuildDir(); + + /** + * The compiler output directories. + * + * @return the compiler output directories. + */ + ExtIdeaCompilerOutput getCompilerOutput(); } diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImpl.java index aa878c6ea5a6..30af82087785 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImpl.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImpl.java @@ -20,6 +20,7 @@ import org.gradle.api.Project; import org.gradle.api.Task; import org.gradle.api.tasks.SourceSet; import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.SourceSetOutput; import org.gradle.api.tasks.bundling.Jar; import org.gradle.api.tasks.testing.Test; import org.gradle.plugins.ide.idea.IdeaPlugin; @@ -28,6 +29,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot; import org.jetbrains.plugins.gradle.model.ModuleExtendedModel; import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.internal.IdeaCompilerOutputImpl; import org.jetbrains.plugins.gradle.tooling.internal.IdeaContentRootImpl; import org.jetbrains.plugins.gradle.tooling.internal.IdeaSourceDirectoryImpl; import org.jetbrains.plugins.gradle.tooling.internal.ModuleExtendedModelImpl; @@ -93,11 +95,24 @@ public class ModuleExtendedModelBuilderImpl implements ModelBuilderService { } } + 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); @@ -164,6 +179,7 @@ public class ModuleExtendedModelBuilderImpl implements ModelBuilderService { } moduleVersionModel.setContentRoots(Collections.singleton(contentRoot)); + moduleVersionModel.setCompilerOutput(compilerOutput); return moduleVersionModel; } diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaCompilerOutputImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaCompilerOutputImpl.java new file mode 100644 index 000000000000..214e99909a5c --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaCompilerOutputImpl.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.plugins.gradle.tooling.internal; + +import org.jetbrains.plugins.gradle.model.ExtIdeaCompilerOutput; + +import java.io.File; + +public class IdeaCompilerOutputImpl implements ExtIdeaCompilerOutput { + private File myMainClassesDir; + private File myMainResourcesDir; + private File myTestClassesDir; + private File myTestResourcesDir; + + @Override + public File getMainClassesDir() { + return myMainClassesDir; + } + + @Override + public File getMainResourcesDir() { + return myMainResourcesDir; + } + + @Override + public File getTestClassesDir() { + return myTestClassesDir; + } + + @Override + public File getTestResourcesDir() { + return myTestResourcesDir; + } + + public void setMainClassesDir(File mainClassesDir) { + myMainClassesDir = mainClassesDir; + } + + public void setMainResourcesDir(File mainResourcesDir) { + myMainResourcesDir = mainResourcesDir; + } + + public void setTestClassesDir(File testClassesDir) { + myTestClassesDir = testClassesDir; + } + + public void setTestResourcesDir(File testResourcesDir) { + myTestResourcesDir = testResourcesDir; + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java index 4eea475b4d18..547029c273f2 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java @@ -17,6 +17,7 @@ package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.internal.ImmutableDomainObjectSet; +import org.jetbrains.plugins.gradle.model.ExtIdeaCompilerOutput; import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot; import org.jetbrains.plugins.gradle.model.ModuleExtendedModel; @@ -36,6 +37,7 @@ public class ModuleExtendedModelImpl implements ModuleExtendedModel { private final File myBuildDir; private List myArtifacts; private Set myContentRoots; + private ExtIdeaCompilerOutput myCompilerOutput; public ModuleExtendedModelImpl(String name, String group, String version, File buildDir) { myName = name; @@ -83,4 +85,13 @@ public class ModuleExtendedModelImpl implements ModuleExtendedModel { public void setContentRoots(Set contentRoots) { myContentRoots = contentRoots == null ? Collections.emptySet() : contentRoots; } + + @Override + public ExtIdeaCompilerOutput getCompilerOutput() { + return myCompilerOutput; + } + + public void setCompilerOutput(ExtIdeaCompilerOutput compilerOutput) { + myCompilerOutput = compilerOutput; + } } -- cgit v1.2.3