diff --git a/build/scripts/layouts.gant b/build/scripts/layouts.gant index df4487148e04..17b3ffe1faa1 100644 --- a/build/scripts/layouts.gant +++ b/build/scripts/layouts.gant @@ -329,6 +329,15 @@ public def layoutCommunityPlugins(String home) { jar("gradle.jar") { module("gradle") } + jar("gradle-tooling-extension.jar") { + module("gradle-tooling-extension") + } + jar("gradle-tooling-extension-v1.9.jar") { + module("gradle-tooling-extension-v1.9") + } + jar("gradle-tooling-extension-v1.11.jar") { + module("gradle-tooling-extension-v1.11") + } fileset(dir: "$home/plugins/gradle/lib") { include(name: "*.jar") } } diff --git a/platform/external-system-api/external-system-api.iml b/platform/external-system-api/external-system-api.iml index 8df6aab6806b..ac3b9ed2df70 100644 --- a/platform/external-system-api/external-system-api.iml +++ b/platform/external-system-api/external-system-api.iml @@ -9,10 +9,10 @@ - - - - + + + + diff --git a/plugins/gradle/gradle.iml b/plugins/gradle/gradle.iml index 9c852ed6ffc1..4f67303c2ac0 100644 --- a/plugins/gradle/gradle.iml +++ b/plugins/gradle/gradle.iml @@ -9,8 +9,10 @@ - + + + @@ -20,108 +22,32 @@ - - + - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -164,9 +90,7 @@ - - - + @@ -187,8 +111,10 @@ + + + - diff --git a/plugins/gradle/src/META-INF/gradle-scala-integration.xml b/plugins/gradle/src/META-INF/gradle-scala-integration.xml new file mode 100644 index 000000000000..707d61670f1a --- /dev/null +++ b/plugins/gradle/src/META-INF/gradle-scala-integration.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/plugins/gradle/src/META-INF/plugin.xml b/plugins/gradle/src/META-INF/plugin.xml index 034ef355421d..5b349a5b580a 100644 --- a/plugins/gradle/src/META-INF/plugin.xml +++ b/plugins/gradle/src/META-INF/plugin.xml @@ -24,6 +24,7 @@ org.intellij.groovy com.intellij.javaee org.jetbrains.idea.maven + org.intellij.scala diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java index f95c8a01a21c..ba83d93658cc 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/javaee/JavaEEGradleProjectResolverExtension.java @@ -20,7 +20,6 @@ import com.intellij.openapi.externalSystem.model.DataNode; import com.intellij.openapi.externalSystem.model.project.ModuleData; import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; import com.intellij.openapi.externalSystem.util.Order; -import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.idea.IdeaModule; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.WarModel; @@ -28,6 +27,7 @@ import org.jetbrains.plugins.gradle.model.data.WarModelData; import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension; import org.jetbrains.plugins.gradle.util.GradleConstants; +import java.util.Collections; import java.util.Set; /** @@ -58,6 +58,6 @@ public class JavaEEGradleProjectResolverExtension extends AbstractProjectResolve @NotNull @Override public Set getExtraProjectModelClasses() { - return ContainerUtil.set(WarModel.class); + return Collections.singleton(WarModel.class); } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/scala/ScalaGradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/scala/ScalaGradleProjectResolverExtension.java new file mode 100644 index 000000000000..657d064e2886 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/integrations/scala/ScalaGradleProjectResolverExtension.java @@ -0,0 +1,113 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.integrations.scala; + +import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.externalSystem.model.DataNode; +import com.intellij.openapi.externalSystem.model.project.ModuleData; +import com.intellij.openapi.externalSystem.util.ExternalSystemConstants; +import com.intellij.openapi.externalSystem.util.Order; +import org.gradle.tooling.model.idea.IdeaModule; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ScalaCompileOptions; +import org.jetbrains.plugins.gradle.model.ScalaForkOptions; +import org.jetbrains.plugins.gradle.model.ScalaModel; +import org.jetbrains.plugins.gradle.model.data.ScalaCompileOptionsData; +import org.jetbrains.plugins.gradle.model.data.ScalaModelData; +import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension; +import org.jetbrains.plugins.gradle.util.GradleConstants; + +import java.util.Collections; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +@Order(ExternalSystemConstants.UNORDERED) +public class ScalaGradleProjectResolverExtension extends AbstractProjectResolverExtension { + private static final Logger LOG = Logger.getInstance(ScalaGradleProjectResolverExtension.class); + + @Override + public void populateModuleExtraModels(@NotNull IdeaModule gradleModule, @NotNull DataNode ideModule) { + ScalaModel scalaModel = resolverCtx.getExtraProject(gradleModule, ScalaModel.class); + if (scalaModel != null) { + ScalaModelData scalaModelData = create(scalaModel); + ideModule.createChild(ScalaModelData.KEY, scalaModelData); + } + + nextResolver.populateModuleExtraModels(gradleModule, ideModule); + } + + @NotNull + @Override + public Set getExtraProjectModelClasses() { + return Collections.singleton(ScalaModel.class); + } + + + @NotNull + private static ScalaModelData create(@NotNull ScalaModel scalaModel) { + ScalaModelData scalaModelData = new ScalaModelData(GradleConstants.SYSTEM_ID); + scalaModelData.setZincClasspath(scalaModel.getZincClasspath()); + scalaModelData.setScalaClasspath(scalaModel.getScalaClasspath()); + scalaModelData.setScalaCompileOptions(create((scalaModel.getScalaCompileOptions()))); + scalaModelData.setSourceCompatibility(scalaModel.getSourceCompatibility()); + scalaModelData.setTargetCompatibility(scalaModel.getTargetCompatibility()); + return scalaModelData; + } + + @Nullable + @Contract("null -> null") + private static ScalaCompileOptionsData create(@Nullable ScalaCompileOptions options) { + if (options == null) return null; + + ScalaCompileOptionsData result = new ScalaCompileOptionsData(); + + result.setAdditionalParameters(options.getAdditionalParameters()); + result.setDaemonServer(options.getDaemonServer()); + result.setDebugLevel(options.getDebugLevel()); + result.setDeprecation(options.isDeprecation()); + result.setEncoding(options.getEncoding()); + result.setFailOnError(options.isFailOnError()); + result.setForce(options.getForce()); + result.setFork(options.isFork()); + result.setListFiles(options.isListFiles()); + result.setLoggingLevel(options.getLoggingLevel()); + result.setDebugLevel(options.getDebugLevel()); + result.setLoggingPhases(options.getLoggingPhases()); + result.setOptimize(options.isOptimize()); + result.setUnchecked(options.isUnchecked()); + result.setUseAnt(options.isUseAnt()); + result.setUseCompileDaemon(options.isUseCompileDaemon()); + result.setForkOptions(create(options.getForkOptions())); + return result; + } + + @Nullable + @Contract("null -> null") + private static ScalaCompileOptionsData.ScalaForkOptions create(@Nullable ScalaForkOptions options) { + if (options == null) return null; + + ScalaCompileOptionsData.ScalaForkOptions result = new ScalaCompileOptionsData.ScalaForkOptions(); + result.setJvmArgs(options.getJvmArgs()); + result.setMemoryInitialSize(options.getMemoryInitialSize()); + result.setMemoryMaximumSize(options.getMemoryMaximumSize()); + return result; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/BuildScriptClasspathData.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/BuildScriptClasspathData.java index cc252a9750a0..0f52cd8c5bc5 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/BuildScriptClasspathData.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/BuildScriptClasspathData.java @@ -19,8 +19,12 @@ import com.intellij.openapi.externalSystem.model.Key; import com.intellij.openapi.externalSystem.model.ProjectKeys; import com.intellij.openapi.externalSystem.model.ProjectSystemId; import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData; +import com.intellij.openapi.util.io.FileUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.io.File; +import java.io.Serializable; import java.util.List; /** @@ -46,4 +50,61 @@ public class BuildScriptClasspathData extends AbstractExternalEntityData { public List getClasspathEntries() { return myClasspathEntries; } + + public static class ClasspathEntry implements Serializable { + + private static final long serialVersionUID = 1L; + + @NotNull + private final File myClassesFile; + + @Nullable + private final File mySourcesFile; + + @Nullable + private final File myJavadocFile; + + public ClasspathEntry(@NotNull File classesFile, @Nullable File sourcesFile, @Nullable File javadocFile) { + myClassesFile = classesFile; + mySourcesFile = sourcesFile; + myJavadocFile = javadocFile; + } + + @NotNull + public File getClassesFile() { + return myClassesFile; + } + + @Nullable + public File getSourcesFile() { + return mySourcesFile; + } + + @Nullable + public File getJavadocFile() { + return myJavadocFile; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ClasspathEntry)) return false; + + ClasspathEntry entry = (ClasspathEntry)o; + + if (!FileUtil.filesEqual(myClassesFile, entry.myClassesFile)) return false; + if (!FileUtil.filesEqual(myJavadocFile, entry.myJavadocFile)) return false; + if (!FileUtil.filesEqual(mySourcesFile, entry.mySourcesFile)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = FileUtil.fileHashCode(myClassesFile); + result = 31 * result + FileUtil.fileHashCode(mySourcesFile); + result = 31 * result + FileUtil.fileHashCode(myJavadocFile); + return result; + } + } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ClasspathEntry.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ClasspathEntry.java deleted file mode 100644 index fa0959ff74ad..000000000000 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ClasspathEntry.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * 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.data; - -import com.intellij.openapi.util.io.FileUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.io.File; -import java.io.Serializable; - -/** - * @author Vladislav.Soroka - * @since 12/23/13 - */ -public class ClasspathEntry implements Serializable { - - private static final long serialVersionUID = 1L; - - @NotNull - private final File myClassesFile; - - @Nullable - private final File mySourcesFile; - - @Nullable - private final File myJavadocFile; - - public ClasspathEntry(@NotNull File classesFile, @Nullable File sourcesFile, @Nullable File javadocFile) { - myClassesFile = classesFile; - mySourcesFile = sourcesFile; - myJavadocFile = javadocFile; - } - - @NotNull - public File getClassesFile() { - return myClassesFile; - } - - @Nullable - public File getSourcesFile() { - return mySourcesFile; - } - - @Nullable - public File getJavadocFile() { - return myJavadocFile; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClasspathEntry)) return false; - - ClasspathEntry entry = (ClasspathEntry)o; - - if (!FileUtil.filesEqual(myClassesFile, entry.myClassesFile)) return false; - if (!FileUtil.filesEqual(myJavadocFile, entry.myJavadocFile)) return false; - if (!FileUtil.filesEqual(mySourcesFile, entry.mySourcesFile)) return false; - - return true; - } - - @Override - public int hashCode() { - int result = FileUtil.fileHashCode(myClassesFile); - result = 31 * result + FileUtil.fileHashCode(mySourcesFile); - result = 31 * result + FileUtil.fileHashCode(myJavadocFile); - return result; - } -} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaCompileOptionsData.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaCompileOptionsData.java new file mode 100644 index 000000000000..14f8bdc98080 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaCompileOptionsData.java @@ -0,0 +1,212 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.data; + +import java.io.Serializable; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaCompileOptionsData implements Serializable { + private static final long serialVersionUID = 1L; + + private boolean useCompileDaemon; + private String daemonServer; + private boolean failOnError; + private boolean deprecation; + private boolean unchecked; + private String debugLevel; + private boolean optimize; + private String encoding; + private String force; + private String targetCompatibility; + private List additionalParameters; + private boolean listFiles; + private String loggingLevel; + private List loggingPhases; + private boolean fork; + private ScalaForkOptions forkOptions; + private boolean useAnt; + + public boolean isUseCompileDaemon() { + return useCompileDaemon; + } + + public void setUseCompileDaemon(boolean useCompileDaemon) { + this.useCompileDaemon = useCompileDaemon; + } + + public String getDaemonServer() { + return daemonServer; + } + + public void setDaemonServer(String daemonServer) { + this.daemonServer = daemonServer; + } + + public boolean isFailOnError() { + return failOnError; + } + + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + + public boolean isDeprecation() { + return deprecation; + } + + public void setDeprecation(boolean deprecation) { + this.deprecation = deprecation; + } + + public boolean isUnchecked() { + return unchecked; + } + + public void setUnchecked(boolean unchecked) { + this.unchecked = unchecked; + } + + public String getDebugLevel() { + return debugLevel; + } + + public void setDebugLevel(String debugLevel) { + this.debugLevel = debugLevel; + } + + public boolean isOptimize() { + return optimize; + } + + public void setOptimize(boolean optimize) { + this.optimize = optimize; + } + + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + public String getForce() { + return force; + } + + public void setForce(String force) { + this.force = force; + } + + public String getTargetCompatibility() { + return targetCompatibility; + } + + public void setTargetCompatibility(String targetCompatibility) { + this.targetCompatibility = targetCompatibility; + } + + public List getAdditionalParameters() { + return additionalParameters; + } + + public void setAdditionalParameters(List additionalParameters) { + this.additionalParameters = additionalParameters; + } + + public boolean isListFiles() { + return listFiles; + } + + public void setListFiles(boolean listFiles) { + this.listFiles = listFiles; + } + + public String getLoggingLevel() { + return loggingLevel; + } + + public void setLoggingLevel(String loggingLevel) { + this.loggingLevel = loggingLevel; + } + + public List getLoggingPhases() { + return loggingPhases; + } + + public void setLoggingPhases(List loggingPhases) { + this.loggingPhases = loggingPhases; + } + + public boolean isFork() { + return fork; + } + + public void setFork(boolean fork) { + this.fork = fork; + } + + public boolean isUseAnt() { + return useAnt; + } + + public void setUseAnt(boolean useAnt) { + this.useAnt = useAnt; + } + + public ScalaForkOptions getForkOptions() { + return forkOptions; + } + + public void setForkOptions(ScalaForkOptions forkOptions) { + this.forkOptions = forkOptions; + } + + public static class ScalaForkOptions implements Serializable { + private static final long serialVersionUID = 1L; + private String memoryInitialSize; + private String memoryMaximumSize; + private List jvmArgs; + + public String getMemoryInitialSize() { + return memoryInitialSize; + } + + public void setMemoryInitialSize(String memoryInitialSize) { + this.memoryInitialSize = memoryInitialSize; + } + + public String getMemoryMaximumSize() { + return memoryMaximumSize; + } + + public void setMemoryMaximumSize(String memoryMaximumSize) { + this.memoryMaximumSize = memoryMaximumSize; + } + + public List getJvmArgs() { + return jvmArgs; + } + + public void setJvmArgs(List jvmArgs) { + this.jvmArgs = jvmArgs; + } + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaModelData.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaModelData.java new file mode 100644 index 000000000000..3e9d62ce7be1 --- /dev/null +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/data/ScalaModelData.java @@ -0,0 +1,120 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.data; + +import com.intellij.openapi.externalSystem.model.Key; +import com.intellij.openapi.externalSystem.model.ProjectKeys; +import com.intellij.openapi.externalSystem.model.ProjectSystemId; +import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData; +import org.jetbrains.annotations.NotNull; + +import java.io.File; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaModelData extends AbstractExternalEntityData { + private static final long serialVersionUID = 1L; + + @NotNull + public static final Key KEY = Key.create(ScalaModelData.class, ProjectKeys.LIBRARY_DEPENDENCY.getProcessingWeight() + 1); + private Set scalaClasspath; + private Set zincClasspath; + private ScalaCompileOptionsData scalaCompileOptions; + private String sourceCompatibility; + private String targetCompatibility; + + + public ScalaModelData(@NotNull ProjectSystemId owner) { + super(owner); + } + + public Set getScalaClasspath() { + return scalaClasspath; + } + + public void setScalaClasspath(Set scalaClasspath) { + this.scalaClasspath = scalaClasspath; + } + + public Set getZincClasspath() { + return zincClasspath; + } + + public void setZincClasspath(Set zincClasspath) { + this.zincClasspath = zincClasspath; + } + + public ScalaCompileOptionsData getScalaCompileOptions() { + return scalaCompileOptions; + } + + public void setScalaCompileOptions(ScalaCompileOptionsData scalaCompileOptions) { + this.scalaCompileOptions = scalaCompileOptions; + } + + public String getSourceCompatibility() { + return sourceCompatibility; + } + + public void setSourceCompatibility(String sourceCompatibility) { + this.sourceCompatibility = sourceCompatibility; + } + + public String getTargetCompatibility() { + return targetCompatibility; + } + + public void setTargetCompatibility(String targetCompatibility) { + this.targetCompatibility = targetCompatibility; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof ScalaModelData)) return false; + if (!super.equals(o)) return false; + + ScalaModelData data = (ScalaModelData)o; + + if (scalaClasspath != null ? !scalaClasspath.equals(data.scalaClasspath) : data.scalaClasspath != null) return false; + if (scalaCompileOptions != null ? !scalaCompileOptions.equals(data.scalaCompileOptions) : data.scalaCompileOptions != null) { + return false; + } + if (sourceCompatibility != null ? !sourceCompatibility.equals(data.sourceCompatibility) : data.sourceCompatibility != null) { + return false; + } + if (targetCompatibility != null ? !targetCompatibility.equals(data.targetCompatibility) : data.targetCompatibility != null) { + return false; + } + if (zincClasspath != null ? !zincClasspath.equals(data.zincClasspath) : data.zincClasspath != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = super.hashCode(); + result = 31 * result + (scalaClasspath != null ? scalaClasspath.hashCode() : 0); + result = 31 * result + (zincClasspath != null ? zincClasspath.hashCode() : 0); + result = 31 * result + (scalaCompileOptions != null ? scalaCompileOptions.hashCode() : 0); + result = 31 * result + (sourceCompatibility != null ? sourceCompatibility.hashCode() : 0); + result = 31 * result + (targetCompatibility != null ? targetCompatibility.hashCode() : 0); + return result; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/ExtraModelBuilder.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/ExtraModelBuilder.java deleted file mode 100644 index 2619557bd761..000000000000 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/ExtraModelBuilder.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * 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.internal; - -import org.gradle.api.Project; -import org.gradle.tooling.provider.model.ToolingModelBuilder; -import org.jetbrains.plugins.gradle.model.ModelBuilderService; - -import java.util.ServiceLoader; - -/** - * @author Vladislav.Soroka - * @since 11/5/13 - */ -@SuppressWarnings("UnusedDeclaration") -public class ExtraModelBuilder implements ToolingModelBuilder { - private static ServiceLoader buildersLoader = - ServiceLoader.load(ModelBuilderService.class, ExtraModelBuilder.class.getClassLoader()); - - @Override - public boolean canBuild(String modelName) { - for (ModelBuilderService service : buildersLoader) { - if (service.canBuild(modelName)) return true; - } - return false; - } - - @Override - public Object buildAll(String modelName, Project project) { - for (ModelBuilderService service : buildersLoader) { - if (service.canBuild(modelName)) { - return service.buildAll(modelName, project); - } - } - throw new IllegalArgumentException("Unsupported model: " + modelName); - } -} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/GradleInstallationManager.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/GradleInstallationManager.java index 95fdb0a7f244..c21c3ad289c1 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/GradleInstallationManager.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/GradleInstallationManager.java @@ -14,7 +14,6 @@ import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtilRt; import org.gradle.StartParameter; -import org.gradle.api.tasks.wrapper.Wrapper; import org.gradle.util.DistributionLocator; import org.gradle.util.GradleVersion; import org.gradle.wrapper.PathAssembler; @@ -465,7 +464,7 @@ public class GradleInstallationManager { } File gradleSystemDir; - if (Wrapper.PathBase.PROJECT.name().equals(wrapperConfiguration.getDistributionBase())) { + if ("PROJECT".equals(wrapperConfiguration.getDistributionBase())) { gradleSystemDir = new File(linkedProjectPath, ".gradle"); } else { diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/AbstractProjectImportErrorHandler.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/AbstractProjectImportErrorHandler.java index 35bfdeb97058..3281724a55ec 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/AbstractProjectImportErrorHandler.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/AbstractProjectImportErrorHandler.java @@ -15,10 +15,9 @@ */ package org.jetbrains.plugins.gradle.service.project; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; import com.intellij.openapi.externalSystem.model.ExternalSystemException; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.text.StringUtil; import org.gradle.api.internal.LocationAwareException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -81,8 +80,8 @@ public abstract class AbstractProjectImportErrorHandler { String location = error.getMessage(); if (location != null && location.startsWith("Build file '")) { // Only the first line contains the location of the error. Discard the rest. - Iterable lines = Splitter.on('\n').split(location); - return lines.iterator().next(); + String[] lines = StringUtil.splitByLines(location); + return lines.length > 0 ? lines[0] : null; } } return null; @@ -96,8 +95,7 @@ public abstract class AbstractProjectImportErrorHandler { newMsg = "Cause: " + newMsg; } - if (!Strings.isNullOrEmpty(location)) { - assert location != null; + if (!StringUtil.isEmpty(location)) { Matcher matcher = ERROR_LOCATION_PATTERN.matcher(location); if(matcher.find()) { String href = "error in file: " + matcher.group(1) + " at line: " + matcher.group(2); 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 8ab9ad9b14e5..4c8fd248b82c 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 @@ -55,7 +55,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.*; import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData; -import org.jetbrains.plugins.gradle.model.data.ClasspathEntry; import org.jetbrains.plugins.gradle.util.GradleBundle; import org.jetbrains.plugins.gradle.util.GradleConstants; import org.jetbrains.plugins.gradle.util.GradleUtil; @@ -156,11 +155,11 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver public void populateModuleExtraModels(@NotNull IdeaModule gradleModule, @NotNull DataNode ideModule) { BuildScriptClasspathModel buildScriptClasspathModel = resolverCtx.getExtraProject(gradleModule, BuildScriptClasspathModel.class); if (buildScriptClasspathModel != null) { - List classpathEntries = - ContainerUtil.map(buildScriptClasspathModel.getClasspath(), new Function() { + List classpathEntries = + ContainerUtil.map(buildScriptClasspathModel.getClasspath(), new Function() { @Override - public ClasspathEntry fun(ClasspathEntryModel model) { - return new ClasspathEntry(model.getClassesFile(), model.getSourcesFile(), model.getJavadocFile()); + public BuildScriptClasspathData.ClasspathEntry fun(ClasspathEntryModel model) { + return new BuildScriptClasspathData.ClasspathEntry(model.getClassesFile(), model.getSourcesFile(), model.getJavadocFile()); } }); BuildScriptClasspathData buildScriptClasspathData = @@ -366,6 +365,7 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(JavaModuleType.class)); ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(ModuleType.class)); ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(EmptyModuleType.class)); + ContainerUtilRt.addIfNotNull(additionalEntries, PathUtil.getJarPathForClass(ProjectImportAction.class)); for (String entry : additionalEntries) { classPath.add(entry); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseProjectImportErrorHandler.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseProjectImportErrorHandler.java index aa60940ffa94..71f77f50367d 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseProjectImportErrorHandler.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/BaseProjectImportErrorHandler.java @@ -15,7 +15,6 @@ */ package org.jetbrains.plugins.gradle.service.project; -import com.google.common.base.Strings; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.externalSystem.model.ExternalSystemException; import com.intellij.openapi.util.Pair; @@ -54,7 +53,7 @@ public class BaseProjectImportErrorHandler extends AbstractProjectImportErrorHan Throwable rootCause = rootCauseAndLocation.getFirst(); String location = rootCauseAndLocation.getSecond(); - if (location == null && !Strings.isNullOrEmpty(buildFilePath)) { + if (location == null && !StringUtil.isEmpty(buildFilePath)) { location = String.format("Build file: '%1$s'", buildFilePath); } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java index 5015c8308867..b3198c79c9c3 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleExecutionHelper.java @@ -35,6 +35,7 @@ import org.gradle.tooling.internal.consumer.Distribution; import org.gradle.tooling.model.build.BuildEnvironment; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.settings.DistributionType; import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -45,9 +46,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.lang.reflect.Field; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; /** @@ -202,6 +201,7 @@ public class GradleExecutionHelper { return f.fun(connection); } catch (Throwable e) { + LOG.warn("Gradle execution error", e); Throwable rootCause = ExceptionUtil.getRootCause(e); throw new ExternalSystemException(ExceptionUtil.getMessage(rootCause)); } @@ -378,16 +378,13 @@ public class GradleExecutionHelper { @Nullable public static File generateInitScript(boolean isBuildSrcProject) { - InputStream stream = GradleProjectResolver.class.getResourceAsStream("/org/jetbrains/plugins/gradle/model/internal/init.gradle"); + InputStream stream = ProjectImportAction.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/init.gradle"); try { if (stream == null) { LOG.warn("Can't get init script template"); return null; } - - String jarPath = PathUtil.getCanonicalPath(PathUtil.getJarPathForClass(GradleProjectResolver.class)); - String s = FileUtil.loadTextAndClose(stream).replace("${JAR_PATH}", jarPath); - + String s = FileUtil.loadTextAndClose(stream).replace("${EXTENSIONS_JARS_PATH}", getToolingExtensionsJarPaths()); if (isBuildSrcProject) { String buildSrcDefaultInitScript = getBuildSrcDefaultInitScript(); if (buildSrcDefaultInitScript == null) return null; @@ -410,7 +407,7 @@ public class GradleExecutionHelper { @Nullable public static String getBuildSrcDefaultInitScript() { InputStream stream = - GradleProjectResolver.class.getResourceAsStream("/org/jetbrains/plugins/gradle/model/internal/buildSrcInit.gradle"); + ProjectImportAction.class.getResourceAsStream("/org/jetbrains/plugins/gradle/tooling/internal/buildSrcInit.gradle"); try { if (stream == null) return null; return FileUtil.loadTextAndClose(stream); @@ -434,4 +431,29 @@ public class GradleExecutionHelper { return null; } } + + @NotNull + private static String getToolingExtensionsJarPaths() throws ClassNotFoundException { + final ArrayList> list = ContainerUtil.newArrayList( + // add gradle-tooling-extension jar + Class.forName("org.jetbrains.plugins.gradle.model.ProjectImportAction"), + // add gradle-tooling-extension-v1.9 jar + Class.forName("org.jetbrains.plugins.gradle.tooling.v1_9.builder.ModelBuildScriptClasspathBuilderImpl"), + // add gradle-tooling-extension-v1.11 jar + Class.forName("org.jetbrains.plugins.gradle.tooling.v1_11.builder.ModelBuildScriptClasspathBuilderImpl") + ); + + StringBuilder buf = new StringBuilder(); + buf.append('['); + for (Iterator> it = list.iterator(); it.hasNext(); ) { + Class aClass = it.next(); + String jarPath = PathUtil.getCanonicalPath(PathUtil.getJarPathForClass(aClass)); + buf.append('\"').append(jarPath).append('\"'); + if (it.hasNext()) { + buf.append(','); + } + } + buf.append(']'); + return buf.toString(); + } } diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java index 58120f90a4d4..ffc0b74b49a8 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolver.java @@ -47,6 +47,7 @@ import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.tooling.model.idea.IdeaProject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.remote.impl.GradleLibraryNamesMixer; import org.jetbrains.plugins.gradle.settings.ClassHolder; import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverExtension.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverExtension.java index 7b101158857d..1b0af6841869 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverExtension.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/GradleProjectResolverExtension.java @@ -26,12 +26,10 @@ import com.intellij.openapi.externalSystem.model.task.TaskData; import com.intellij.openapi.externalSystem.service.ParametersEnhancer; import com.intellij.openapi.util.KeyValue; import org.gradle.tooling.model.idea.IdeaModule; -import org.gradle.tooling.model.idea.IdeaProject; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.GradleManager; -import java.io.File; import java.util.Collection; import java.util.List; import java.util.Set; @@ -67,7 +65,7 @@ public interface GradleProjectResolverExtension extends ParametersEnhancer { ModuleData createModule(@NotNull IdeaModule gradleModule, @NotNull ProjectData projectData); /** - * Populates extra models of the given ide module on the basis of the information provided by {@link org.jetbrains.plugins.gradle.model.ModelBuilderService} + * Populates extra models of the given ide module on the basis of the information provided by {@link org.jetbrains.plugins.gradle.tooling.ModelBuilderService} * * @param ideModule corresponding module from intellij gradle plugin domain */ diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectResolverContext.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectResolverContext.java index 0f9bc3987e09..b7f94dd57122 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectResolverContext.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectResolverContext.java @@ -21,6 +21,7 @@ import org.gradle.tooling.ProjectConnection; import org.gradle.tooling.model.idea.IdeaModule; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.settings.GradleExecutionSettings; import java.util.Collection; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/BuildClasspathModuleGradleDataService.java b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/BuildClasspathModuleGradleDataService.java index 907f2903ef09..28c30d86e341 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/BuildClasspathModuleGradleDataService.java +++ b/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/data/BuildClasspathModuleGradleDataService.java @@ -37,7 +37,6 @@ import com.intellij.util.containers.FactoryMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.data.BuildScriptClasspathData; -import org.jetbrains.plugins.gradle.model.data.ClasspathEntry; import org.jetbrains.plugins.gradle.service.GradleBuildClasspathManager; import org.jetbrains.plugins.gradle.service.GradleInstallationManager; import org.jetbrains.plugins.gradle.settings.GradleProjectSettings; @@ -121,7 +120,7 @@ public class BuildClasspathModuleGradleDataService implements ProjectDataService final Set buildClasspath = ContainerUtil.newHashSet(); BuildScriptClasspathData buildScriptClasspathData = node.getData(); - for (ClasspathEntry classpathEntry : buildScriptClasspathData.getClasspathEntries()) { + for (BuildScriptClasspathData.ClasspathEntry classpathEntry : buildScriptClasspathData.getClasspathEntries()) { if (classpathEntry.getSourcesFile() != null) { buildClasspath.add(FileUtil.toCanonicalPath(classpathEntry.getSourcesFile().getPath())); } diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleContentRootTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleContentRootTest.java deleted file mode 100644 index e060b7f7d2da..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleContentRootTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.jetbrains.plugins.gradle.model; - -import com.intellij.openapi.externalSystem.model.project.ContentRootData; -import com.intellij.openapi.externalSystem.model.project.ModuleData; -import com.intellij.openapi.externalSystem.model.project.ExternalSystemSourceType; -import org.junit.Test; - -/** - * @author Denis Zhdanov - * @since 8/31/11 1:33 PM - */ -public class GradleContentRootTest { - - @Test(expected = IllegalArgumentException.class) - public void pathOutOfContentRoot() { - throw new IllegalArgumentException(); - // TODO den implement -// ContentRootData contentRoot = new ContentRootData(new ModuleData("module", "."), "./my-content-root"); -// contentRoot.storePath(ExternalSystemSourceType.SOURCE, "./my-dir-out-of-content-root"); - } -} diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleProjectTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleProjectTest.java deleted file mode 100644 index 77e92bd2298e..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/GradleProjectTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.jetbrains.plugins.gradle.model; - -import com.intellij.openapi.externalSystem.model.project.ProjectData; -import com.intellij.openapi.projectRoots.JavaSdkVersion; -import org.jetbrains.annotations.NotNull; -import org.junit.Before; -import org.junit.Test; - -import java.io.File; - -import static org.junit.Assert.assertEquals; - -/** - * @author Denis Zhdanov - * @since 8/29/11 1:28 PM - */ -public class GradleProjectTest { - - private ProjectData myProject; - - @Before - public void setUp() { - String path = new File(".").getPath(); - // TODO den implement -// myProject = new ProjectData(path, path, id); - } - - @Test - public void jdkVersion() { - doTestJdkVersion("4", JavaSdkVersion.JDK_1_4); - doTestJdkVersion(" 5", JavaSdkVersion.JDK_1_5); - doTestJdkVersion("6 ", JavaSdkVersion.JDK_1_6); - doTestJdkVersion(" 7 ", JavaSdkVersion.JDK_1_7); - doTestJdkVersion(" 1.4 ", JavaSdkVersion.JDK_1_4); - doTestJdkVersion("this is version 1.5.1_0b12 ", JavaSdkVersion.JDK_1_5); - } - - private void doTestJdkVersion(@NotNull String version, @NotNull JavaSdkVersion expected) { - // TODO den implement -// myProject.setJdkVersion(version); -// assertEquals(expected, myProject.getJdkVersion()); - } -} diff --git a/plugins/gradle/tooling-extension-v1.11/gradle-tooling-extension-v1.11.iml b/plugins/gradle/tooling-extension-v1.11/gradle-tooling-extension-v1.11.iml new file mode 100644 index 000000000000..710a9317468d --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.11/gradle-tooling-extension-v1.11.iml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/gradle/tooling-extension-v1.11/lib/gradle-1.11-rc-1-src.zip b/plugins/gradle/tooling-extension-v1.11/lib/gradle-1.11-rc-1-src.zip new file mode 100644 index 000000000000..355aee4bc8e9 Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.11/lib/gradle-1.11-rc-1-src.zip differ diff --git a/plugins/gradle/tooling-extension-v1.11/lib/gradle-base-services-1.11-rc-1.jar b/plugins/gradle/tooling-extension-v1.11/lib/gradle-base-services-1.11-rc-1.jar new file mode 100644 index 000000000000..27283d8d7faa Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.11/lib/gradle-base-services-1.11-rc-1.jar differ diff --git a/plugins/gradle/tooling-extension-v1.11/lib/gradle-core-1.11-rc-1.jar b/plugins/gradle/tooling-extension-v1.11/lib/gradle-core-1.11-rc-1.jar new file mode 100644 index 000000000000..19d23560f5a0 Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.11/lib/gradle-core-1.11-rc-1.jar differ diff --git a/plugins/gradle/tooling-extension-v1.11/lib/gradle-ide-1.11-rc-1.jar b/plugins/gradle/tooling-extension-v1.11/lib/gradle-ide-1.11-rc-1.jar new file mode 100644 index 000000000000..881d355a4c79 Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.11/lib/gradle-ide-1.11-rc-1.jar differ diff --git a/plugins/gradle/tooling-extension-v1.11/lib/gradle-tooling-api-1.11-rc-1.jar b/plugins/gradle/tooling-extension-v1.11/lib/gradle-tooling-api-1.11-rc-1.jar new file mode 100644 index 000000000000..25557d75ba54 Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.11/lib/gradle-tooling-api-1.11-rc-1.jar differ diff --git a/plugins/gradle/src/META-INF/services/org.jetbrains.plugins.gradle.model.ModelBuilderService b/plugins/gradle/tooling-extension-v1.11/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService similarity index 62% rename from plugins/gradle/src/META-INF/services/org.jetbrains.plugins.gradle.model.ModelBuilderService rename to plugins/gradle/tooling-extension-v1.11/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService index 430ac6f37ba0..b8b70b014573 100644 --- a/plugins/gradle/src/META-INF/services/org.jetbrains.plugins.gradle.model.ModelBuilderService +++ b/plugins/gradle/tooling-extension-v1.11/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -1,5 +1,5 @@ # -# Copyright 2000-2013 JetBrains s.r.o. +# Copyright 2000-2014 JetBrains s.r.o. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,7 +13,5 @@ # See the License for the specific language governing permissions and # limitations under the License. # -org.jetbrains.plugins.gradle.model.builder.WarModelBuilderImpl -org.jetbrains.plugins.gradle.model.builder.ModelDependenciesBuilderImpl -org.jetbrains.plugins.gradle.model.builder.ModuleExtendedModelBuilderImpl -org.jetbrains.plugins.gradle.model.builder.ModelBuildScriptClasspathBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_11.builder.ModelDependenciesBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_11.builder.ModelBuildScriptClasspathBuilderImpl diff --git a/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelBuildScriptClasspathBuilderImpl.java b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelBuildScriptClasspathBuilderImpl.java new file mode 100644 index 000000000000..792a7316545d --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelBuildScriptClasspathBuilderImpl.java @@ -0,0 +1,111 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_11.builder; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.plugins.ide.idea.IdeaPlugin; +import org.gradle.plugins.ide.idea.model.IdeaModel; +import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; +import org.gradle.plugins.ide.internal.resolver.model.IdeLocalFileDependency; +import org.gradle.plugins.ide.internal.resolver.model.IdeRepoFileDependency; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel; +import org.jetbrains.plugins.gradle.model.ClasspathEntryModel; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; +import org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl; +import org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +/** + * @author Vladislav.Soroka + * @since 12/20/13 + */ +@TargetVersions("1.11+") +public class ModelBuildScriptClasspathBuilderImpl implements ModelBuilderService { + + private final Map cache = new ConcurrentHashMap(); + + @Override + public boolean canBuild(String modelName) { + return BuildScriptClasspathModel.class.getName().equals(modelName); + } + + @Nullable + @Override + public Object buildAll(final String modelName, final Project project) { + BuildScriptClasspathModelImpl buildScriptClasspath = cache.get(project.getPath()); + if (buildScriptClasspath != null) return buildScriptClasspath; + + boolean offline = false; + boolean downloadJavadoc = false; + boolean downloadSources = true; + + final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class); + + if (ideaPlugin != null) { + IdeaModel ideaModel = ideaPlugin.getModel(); + if (ideaModel != null && ideaModel.getModule() != null) { + offline = ideaModel.getModule().isOffline(); + downloadJavadoc = ideaModel.getModule().isDownloadJavadoc(); + downloadSources = ideaModel.getModule().isDownloadSources(); + } + } + + buildScriptClasspath = new BuildScriptClasspathModelImpl(); + Project parent = project.getParent(); + if (parent != null) { + BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl)buildAll(modelName, parent); + if (parentBuildScriptClasspath != null) { + for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) { + buildScriptClasspath.add(classpathEntryModel); + } + } + } + + final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor(); + + final Configuration configuration = project.getBuildscript().getConfigurations().findByName("classpath"); + Collection plusConfigurations = Collections.singletonList(configuration); + + if (!offline) { + // download sources and/or javadoc + List repoFileDependencies = dependenciesExtractor.extractRepoFileDependencies( + project.getConfigurations(), plusConfigurations, new ArrayList(), downloadSources, downloadJavadoc); + + for (IdeRepoFileDependency dependency : repoFileDependencies) { + if (dependency.getFile() == null) continue; + + buildScriptClasspath.add( + new ClasspathEntryModelImpl(dependency.getFile(), dependency.getSourceFile(), dependency.getJavadocFile())); + } + } + + final Collection localFileDependencies = + dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList()); + + for (IdeLocalFileDependency dependency : localFileDependencies) { + if (dependency.getFile() == null) continue; + buildScriptClasspath.add(new ClasspathEntryModelImpl(dependency.getFile(), null, null)); + } + + cache.put(project.getPath(), buildScriptClasspath); + return buildScriptClasspath; + } +} diff --git a/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelDependenciesBuilderImpl.java b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelDependenciesBuilderImpl.java new file mode 100644 index 000000000000..aafe69565d2e --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/builder/ModelDependenciesBuilderImpl.java @@ -0,0 +1,158 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_11.builder; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.plugins.ide.idea.IdeaPlugin; +import org.gradle.plugins.ide.idea.model.IdeaModel; +import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; +import org.gradle.plugins.ide.internal.resolver.model.IdeLocalFileDependency; +import org.gradle.plugins.ide.internal.resolver.model.IdeProjectDependency; +import org.gradle.plugins.ide.internal.resolver.model.IdeRepoFileDependency; +import org.gradle.tooling.model.idea.IdeaDependency; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.GradleDependencyScope; +import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; +import org.jetbrains.plugins.gradle.tooling.internal.*; +import org.jetbrains.plugins.gradle.tooling.v1_11.internal.DependencyVersionId; + +import java.util.*; + +import static org.jetbrains.plugins.gradle.tooling.v1_11.internal.ModelDependenciesBuilderImplHelper.*; + +/** + * @author Vladislav.Soroka + * @since 11/5/13 + */ +@TargetVersions("1.11+") +public class ModelDependenciesBuilderImpl implements ModelBuilderService { + + @Override + public boolean canBuild(String modelName) { + return ProjectDependenciesModel.class.getName().equals(modelName); + } + + @Nullable + @Override + public Object buildAll(final String modelName, final Project project) { + final List dependencies = new ArrayList(); + + final Map scopesMap = new LinkedHashMap(); + final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor(); + + boolean offline = false; + boolean downloadJavadoc = false; + boolean downloadSources = true; + + final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class); + Map>> userScopes = Collections.emptyMap(); + if (ideaPlugin != null) { + IdeaModel ideaModel = ideaPlugin.getModel(); + if (ideaModel != null && ideaModel.getModule() != null) { + offline = ideaModel.getModule().isOffline(); + downloadJavadoc = ideaModel.getModule().isDownloadJavadoc(); + downloadSources = ideaModel.getModule().isDownloadSources(); + userScopes = ideaModel.getModule().getScopes(); + } + } + + for (final Configuration configuration : project.getConfigurations()) { + Collection plusConfigurations = new ArrayList(); + plusConfigurations.add(configuration); + + final Collection ideProjectDependencies = + dependenciesExtractor.extractProjectDependencies(project, plusConfigurations, new ArrayList()); + + for (IdeProjectDependency ideProjectDependency : ideProjectDependencies) { + merge(scopesMap, ideProjectDependency, userScopes); + } + + if (!offline) { + final Collection ideRepoFileDependencies = + dependenciesExtractor.extractRepoFileDependencies( + project.getConfigurations(), plusConfigurations, new ArrayList(), downloadSources, downloadJavadoc); + for (IdeRepoFileDependency repoFileDependency : ideRepoFileDependencies) { + merge(scopesMap, repoFileDependency, userScopes); + } + } + + final Collection ideLocalFileDependencies = + dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList()); + for (IdeLocalFileDependency fileDependency : ideLocalFileDependencies) { + merge(scopesMap, fileDependency, userScopes); + } + } + + for (Map.Entry entry : scopesMap.entrySet()) { + DependencyVersionId versionId = entry.getKey(); + for (GradleDependencyScope scope : entry.getValue().getScopes()) { + if (versionId.getIdeDependency() instanceof IdeRepoFileDependency) { + IdeRepoFileDependency repoFileDependency = + (IdeRepoFileDependency)versionId.getIdeDependency(); + IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( + new IdeaDependencyScopeImpl(scope), + versionId.getName(), + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + libraryDependency.setFile(repoFileDependency.getFile()); + libraryDependency.setSource(repoFileDependency.getSourceFile()); + libraryDependency.setJavadoc(repoFileDependency.getJavadocFile()); + dependencies.add(libraryDependency); + } + else if (versionId.getIdeDependency() instanceof IdeProjectDependency) { + IdeProjectDependency projectDependency = + (IdeProjectDependency)versionId.getIdeDependency(); + + String ideaModuleName = findDeDuplicatedModuleName(projectDependency.getProject()); + if (ideaModuleName == null) { + ideaModuleName = versionId.getName(); + } + + IdeaModuleDependencyImpl moduleDependency = new IdeaModuleDependencyImpl( + new IdeaDependencyScopeImpl(scope), + ideaModuleName, + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + moduleDependency.setIdeaModule(new StubIdeaModule(ideaModuleName)); + dependencies.add(moduleDependency); + } + else if (versionId.getIdeDependency() instanceof IdeLocalFileDependency) { + IdeLocalFileDependency fileDependency = + (IdeLocalFileDependency)versionId.getIdeDependency(); + IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( + new IdeaDependencyScopeImpl(scope), + versionId.getName(), + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + libraryDependency.setFile(fileDependency.getFile()); + attachGradleSdkSources(libraryDependency, fileDependency); + dependencies.add(libraryDependency); + } + } + } + + return new ProjectDependenciesModelImpl(project.getPath(), dependencies); + } +} diff --git a/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/DependencyVersionId.java b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/DependencyVersionId.java new file mode 100644 index 000000000000..a9af2acbe747 --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/DependencyVersionId.java @@ -0,0 +1,96 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_11.internal; + +import org.gradle.plugins.ide.internal.resolver.model.IdeDependency; + +/** + * @author Vladislav.Soroka + * @since 11/25/13 + */ +public class DependencyVersionId { + private final IdeDependency myIdeDependency; + private final String myName; + private final String myGroup; + private final String myVersion; + private final String myClassifier; + + public DependencyVersionId(IdeDependency dependency, + String name, + String group, + String version, + String classifier) { + myIdeDependency = dependency; + myName = name; + myGroup = group; + myVersion = version; + myClassifier = classifier; + } + + public String getName() { + return myName; + } + + public String getGroup() { + return myGroup; + } + + public String getVersion() { + return myVersion; + } + + public String getClassifier() { + return myClassifier; + } + + public IdeDependency getIdeDependency() { + return myIdeDependency; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof DependencyVersionId)) return false; + + DependencyVersionId id = (DependencyVersionId)o; + + if (myGroup != null ? !myGroup.equals(id.myGroup) : id.myGroup != null) return false; + if (myName != null ? !myName.equals(id.myName) : id.myName != null) return false; + if (myVersion != null ? !myVersion.equals(id.myVersion) : id.myVersion != null) return false; + if (myClassifier != null ? !myClassifier.equals(id.myClassifier) : id.myClassifier != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = myName != null ? myName.hashCode() : 0; + result = 31 * result + (myGroup != null ? myGroup.hashCode() : 0); + result = 31 * result + (myVersion != null ? myVersion.hashCode() : 0); + result = 31 * result + (myClassifier != null ? myClassifier.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "DependencyVersionId{" + + "name='" + myName + '\'' + + ", group='" + myGroup + '\'' + + ", version='" + myVersion + '\'' + + ", classifier='" + myClassifier + '\'' + + '}'; + } +} diff --git a/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/ModelDependenciesBuilderImplHelper.java b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/ModelDependenciesBuilderImplHelper.java new file mode 100644 index 000000000000..65eedbd4e6a7 --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.11/src/org/jetbrains/plugins/gradle/tooling/v1_11/internal/ModelDependenciesBuilderImplHelper.java @@ -0,0 +1,221 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_11.internal; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.api.artifacts.ModuleIdentifier; +import org.gradle.api.artifacts.ModuleVersionIdentifier; +import org.gradle.plugins.ide.idea.GenerateIdeaModule; +import org.gradle.plugins.ide.internal.resolver.model.IdeLocalFileDependency; +import org.gradle.plugins.ide.internal.resolver.model.IdeProjectDependency; +import org.gradle.plugins.ide.internal.resolver.model.IdeRepoFileDependency; +import org.gradle.plugins.ide.internal.resolver.model.UnresolvedIdeRepoFileDependency; +import org.gradle.util.GradleVersion; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.GradleDependencyScope; +import org.jetbrains.plugins.gradle.tooling.internal.IdeaSingleEntryLibraryDependencyImpl; +import org.jetbrains.plugins.gradle.tooling.internal.Scopes; + +import java.io.File; +import java.io.Serializable; +import java.util.Collection; +import java.util.Map; + +/** + * @author Vladislav.Soroka + * @since 2/3/14 + */ +public class ModelDependenciesBuilderImplHelper { + + private static final String MODULE_PROPERTY = "ideaModule"; + private static final String VERSION_PROPERTY = "version"; + private static final String GROUP_PROPERTY = "group"; + + + public static void attachGradleSdkSources(IdeaSingleEntryLibraryDependencyImpl libraryDependency, + IdeLocalFileDependency localFileDependency) { + final String libName = localFileDependency.getFile().getName(); + if (localFileDependency.getFile() == null || !libName.startsWith("gradle-")) return; + + File libOrPluginsFile = localFileDependency.getFile().getParentFile(); + if (libOrPluginsFile != null && ("plugins".equals(libOrPluginsFile.getName()))) { + libOrPluginsFile = libOrPluginsFile.getParentFile(); + } + + if (libOrPluginsFile != null && "lib".equals(libOrPluginsFile.getName()) && libOrPluginsFile.getParentFile() != null) { + File srcDir = new File(libOrPluginsFile.getParentFile(), "src"); + if (GradleVersion.current().compareTo(GradleVersion.version("1.9")) >= 0) { + int endIndex = libName.indexOf(GradleVersion.current().getVersion() + ".jar"); + if (endIndex != -1) { + String srcDirChild = libName.substring("gradle-".length(), endIndex - 1); + srcDir = new File(srcDir, srcDirChild); + } + } + + if (srcDir.isDirectory()) { + libraryDependency.setSource(srcDir); + } + } + } + + @Nullable + public static String findDeDuplicatedModuleName(Project project) { + if (project.hasProperty(MODULE_PROPERTY)) { + Object ideaModule = project.property(MODULE_PROPERTY); + if (ideaModule instanceof GenerateIdeaModule) { + GenerateIdeaModule generateIdeaModule = (GenerateIdeaModule)ideaModule; + return generateIdeaModule.getModule().getName(); + } + } + return null; + } + + public static void merge(Map map, + IdeProjectDependency dependency, + Map>> userScopes) { + final String configurationName = dependency.getDeclaredConfiguration().getName(); + final GradleDependencyScope scope = deduceScope(configurationName, userScopes); + if (scope == null) return; + + final Project project = dependency.getProject(); + final String version = project.hasProperty(VERSION_PROPERTY) ? str(project.property(VERSION_PROPERTY)) : ""; + final String group = project.hasProperty(GROUP_PROPERTY) ? str(project.property(GROUP_PROPERTY)) : ""; + + DependencyVersionId versionId = + new DependencyVersionId(dependency, project.getName(), group, version, null); + Scopes scopes = map.get(versionId); + if (scopes == null) { + map.put(versionId, new Scopes(scope)); + } + else { + scopes.add(scope); + } + } + + public static String str(Object o) { + return String.valueOf(o == null ? "" : o); + } + + public static void merge(Map map, + IdeRepoFileDependency dependency, + Map>> userScopes) { + final String configurationName = dependency.getDeclaredConfiguration().getName(); + final GradleDependencyScope scope = deduceScope(configurationName, userScopes); + if (scope == null) return; + + final ModuleVersionIdentifier dependencyId; + if (dependency instanceof UnresolvedIdeRepoFileDependency) { + UnresolvedIdeRepoFileDependency unresolvedDependency = + (UnresolvedIdeRepoFileDependency)dependency; + dependencyId = new MyModuleVersionIdentifier(unresolvedDependency.getFile().getName()); + } + else { + dependencyId = dependency.getId(); + } + + String classifier = parseClassifier(dependencyId, dependency.getFile()); + DependencyVersionId versionId = + new DependencyVersionId(dependency, dependencyId.getName(), dependencyId.getGroup(), dependencyId.getVersion(), classifier); + Scopes scopes = map.get(versionId); + if (scopes == null) { + map.put(versionId, new Scopes(scope)); + } + else { + scopes.add(scope); + } + } + + public static String parseClassifier(ModuleVersionIdentifier dependencyId, File dependencyFile) { + if (dependencyFile == null) return null; + String dependencyFileName = dependencyFile.getName(); + int i = dependencyFileName.indexOf(dependencyId.getName() + '-' + dependencyId.getVersion() + '-'); + return i != -1 ? dependencyFileName.substring(i, dependencyFileName.length()) : null; + } + + public static void merge(Map map, + IdeLocalFileDependency dependency, + Map>> userScopes) { + + final String configurationName = dependency.getDeclaredConfiguration().getName(); + final GradleDependencyScope scope = deduceScope(configurationName, userScopes); + if (scope == null) return; + + String path = dependency.getFile().getPath(); + DependencyVersionId versionId = new DependencyVersionId(dependency, path, "", "", null); + Scopes scopes = map.get(versionId); + if (scopes == null) { + map.put(versionId, new Scopes(scope)); + } + else { + scopes.add(scope); + } + } + + /** + * Deduce configuration scope based on configuration name using gradle conventions. + * IDEA gradle plugin only 'plus' configuration used to support configuration based on a custom configuration (not conventional) + * + * @param configurationName gradle configuration name + * @param userScopes gradle IDEA plugin scopes map + * @return deduced scope + */ + public static GradleDependencyScope deduceScope(String configurationName, + Map>> userScopes) { + GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName); + for (Map.Entry>> entry : userScopes.entrySet()) { + Collection plusConfigurations = entry.getValue().get("plus"); + if (plusConfigurations == null) continue; + + for (Configuration plus : plusConfigurations) { + if (plus.getName().equals(configurationName)) { + return GradleDependencyScope.fromIdeaMappingName(entry.getKey().toLowerCase()); + } + } + } + + return scope; + } + + public static class MyModuleVersionIdentifier implements ModuleVersionIdentifier, Serializable { + private final String myName; + + public MyModuleVersionIdentifier(String name) { + + myName = name; + } + + @Override + public String getVersion() { + return null; + } + + @Override + public String getGroup() { + return null; + } + + @Override + public String getName() { + return myName; + } + + @Override + public ModuleIdentifier getModule() { + return null; + } + } +} diff --git a/plugins/gradle/tooling-extension-v1.9/gradle-tooling-extension-v1.9.iml b/plugins/gradle/tooling-extension-v1.9/gradle-tooling-extension-v1.9.iml new file mode 100644 index 000000000000..19fbea9949dc --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.9/gradle-tooling-extension-v1.9.iml @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/gradle/lib/gradle-build-init-1.9.jar b/plugins/gradle/tooling-extension-v1.9/lib/gradle-build-init-1.9.jar similarity index 100% rename from plugins/gradle/lib/gradle-build-init-1.9.jar rename to plugins/gradle/tooling-extension-v1.9/lib/gradle-build-init-1.9.jar diff --git a/plugins/gradle/lib/gradle-ide-1.9.jar b/plugins/gradle/tooling-extension-v1.9/lib/gradle-ide-1.9.jar similarity index 100% rename from plugins/gradle/lib/gradle-ide-1.9.jar rename to plugins/gradle/tooling-extension-v1.9/lib/gradle-ide-1.9.jar diff --git a/plugins/gradle/lib/gradle-plugins-1.9.jar b/plugins/gradle/tooling-extension-v1.9/lib/gradle-plugins-1.9.jar similarity index 100% rename from plugins/gradle/lib/gradle-plugins-1.9.jar rename to plugins/gradle/tooling-extension-v1.9/lib/gradle-plugins-1.9.jar diff --git a/plugins/gradle/tooling-extension-v1.9/lib/gradle-scala-1.9.jar b/plugins/gradle/tooling-extension-v1.9/lib/gradle-scala-1.9.jar new file mode 100644 index 000000000000..aa6a20a2f45a Binary files /dev/null and b/plugins/gradle/tooling-extension-v1.9/lib/gradle-scala-1.9.jar differ diff --git a/plugins/gradle/tooling-extension-v1.9/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/gradle/tooling-extension-v1.9/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 000000000000..88d820771085 --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.9/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1,20 @@ +# +# Copyright 2000-2014 JetBrains s.r.o. +# +# 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. +# +org.jetbrains.plugins.gradle.tooling.v1_9.builder.WarModelBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_9.builder.ModelDependenciesBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_9.builder.ModuleExtendedModelBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_9.builder.ModelBuildScriptClasspathBuilderImpl +org.jetbrains.plugins.gradle.tooling.v1_9.builder.ScalaModelBuilderImpl diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelBuildScriptClasspathBuilderImpl.java similarity index 91% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImpl.java rename to plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelBuildScriptClasspathBuilderImpl.java index 5572290c996a..b4de8baaa953 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImpl.java +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelBuildScriptClasspathBuilderImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.v1_9.builder; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; @@ -23,9 +23,10 @@ import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel; import org.jetbrains.plugins.gradle.model.ClasspathEntryModel; -import org.jetbrains.plugins.gradle.model.ModelBuilderService; -import org.jetbrains.plugins.gradle.model.internal.BuildScriptClasspathModelImpl; -import org.jetbrains.plugins.gradle.model.internal.ClasspathEntryModelImpl; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; +import org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl; +import org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -34,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap; * @author Vladislav.Soroka * @since 12/20/13 */ +@TargetVersions("1.8 <=> 1.10") public class ModelBuildScriptClasspathBuilderImpl implements ModelBuilderService { private final Map cache = new ConcurrentHashMap(); diff --git a/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelDependenciesBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelDependenciesBuilderImpl.java new file mode 100644 index 000000000000..5c32a503ad5b --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModelDependenciesBuilderImpl.java @@ -0,0 +1,154 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_9.builder; + +import org.gradle.api.Project; +import org.gradle.api.artifacts.Configuration; +import org.gradle.plugins.ide.idea.IdeaPlugin; +import org.gradle.plugins.ide.idea.model.IdeaModel; +import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; +import org.gradle.tooling.model.idea.IdeaDependency; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.GradleDependencyScope; +import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; +import org.jetbrains.plugins.gradle.tooling.internal.*; +import org.jetbrains.plugins.gradle.tooling.v1_9.internal.DependencyVersionId; +import org.jetbrains.plugins.gradle.tooling.v1_9.internal.ModelDependenciesBuilderImplHelper; + +import java.util.*; + +/** + * @author Vladislav.Soroka + * @since 11/5/13 + */ +@TargetVersions("1.8 <=> 1.10") +public class ModelDependenciesBuilderImpl implements ModelBuilderService { + @Override + public boolean canBuild(String modelName) { + return ProjectDependenciesModel.class.getName().equals(modelName); + } + + @Nullable + @Override + public Object buildAll(final String modelName, final Project project) { + + final List dependencies = new ArrayList(); + + final Map scopesMap = new LinkedHashMap(); + final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor(); + + boolean offline = false; + boolean downloadJavadoc = false; + boolean downloadSources = true; + + final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class); + Map>> userScopes = Collections.emptyMap(); + if (ideaPlugin != null) { + IdeaModel ideaModel = ideaPlugin.getModel(); + if (ideaModel != null && ideaModel.getModule() != null) { + offline = ideaModel.getModule().isOffline(); + downloadJavadoc = ideaModel.getModule().isDownloadJavadoc(); + downloadSources = ideaModel.getModule().isDownloadSources(); + userScopes = ideaModel.getModule().getScopes(); + } + } + + for (final Configuration configuration : project.getConfigurations()) { + Collection plusConfigurations = new ArrayList(); + plusConfigurations.add(configuration); + + final List ideProjectDependencies = + dependenciesExtractor.extractProjectDependencies(plusConfigurations, new ArrayList()); + + for (IdeDependenciesExtractor.IdeProjectDependency ideProjectDependency : ideProjectDependencies) { + ModelDependenciesBuilderImplHelper.merge(scopesMap, ideProjectDependency, userScopes); + } + + if (!offline) { + final Collection ideRepoFileDependencies = + dependenciesExtractor.extractRepoFileDependencies( + project.getConfigurations(), plusConfigurations, new ArrayList(), downloadSources, downloadJavadoc); + for (IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency : ideRepoFileDependencies) { + ModelDependenciesBuilderImplHelper.merge(scopesMap, repoFileDependency, userScopes); + } + } + + final List ideLocalFileDependencies = + dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList()); + for (IdeDependenciesExtractor.IdeLocalFileDependency fileDependency : ideLocalFileDependencies) { + ModelDependenciesBuilderImplHelper.merge(scopesMap, fileDependency, userScopes); + } + } + + for (Map.Entry entry : scopesMap.entrySet()) { + DependencyVersionId versionId = entry.getKey(); + for (GradleDependencyScope scope : entry.getValue().getScopes()) { + if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeRepoFileDependency) { + IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency = + (IdeDependenciesExtractor.IdeRepoFileDependency)versionId.getIdeDependency(); + IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( + new IdeaDependencyScopeImpl(scope), + versionId.getName(), + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + libraryDependency.setFile(repoFileDependency.getFile()); + libraryDependency.setSource(repoFileDependency.getSourceFile()); + libraryDependency.setJavadoc(repoFileDependency.getJavadocFile()); + dependencies.add(libraryDependency); + } + else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeProjectDependency) { + IdeDependenciesExtractor.IdeProjectDependency projectDependency = + (IdeDependenciesExtractor.IdeProjectDependency)versionId.getIdeDependency(); + + String ideaModuleName = ModelDependenciesBuilderImplHelper.findDeDuplicatedModuleName(projectDependency.getProject()); + if (ideaModuleName == null) { + ideaModuleName = versionId.getName(); + } + + IdeaModuleDependencyImpl moduleDependency = new IdeaModuleDependencyImpl( + new IdeaDependencyScopeImpl(scope), + ideaModuleName, + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + moduleDependency.setIdeaModule(new StubIdeaModule(ideaModuleName)); + dependencies.add(moduleDependency); + } + else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeLocalFileDependency) { + IdeDependenciesExtractor.IdeLocalFileDependency fileDependency = + (IdeDependenciesExtractor.IdeLocalFileDependency)versionId.getIdeDependency(); + IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( + new IdeaDependencyScopeImpl(scope), + versionId.getName(), + versionId.getGroup(), + versionId.getVersion(), + versionId.getClassifier() + ); + libraryDependency.setFile(fileDependency.getFile()); + ModelDependenciesBuilderImplHelper.attachGradleSdkSources(libraryDependency, fileDependency); + dependencies.add(libraryDependency); + } + } + } + + return new ProjectDependenciesModelImpl(project.getPath(), dependencies); + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModuleExtendedModelBuilderImpl.java similarity index 96% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImpl.java rename to plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModuleExtendedModelBuilderImpl.java index 44eb6cfe328b..d1068806dd0a 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImpl.java +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ModuleExtendedModelBuilderImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.v1_9.builder; import groovy.lang.GroovyObject; import org.gradle.api.Project; @@ -26,11 +26,11 @@ import org.gradle.plugins.ide.idea.IdeaPlugin; import org.gradle.plugins.ide.idea.model.IdeaModel; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot; -import org.jetbrains.plugins.gradle.model.ModelBuilderService; import org.jetbrains.plugins.gradle.model.ModuleExtendedModel; -import org.jetbrains.plugins.gradle.model.internal.IdeaContentRootImpl; -import org.jetbrains.plugins.gradle.model.internal.IdeaSourceDirectoryImpl; -import org.jetbrains.plugins.gradle.model.internal.ModuleExtendedModelImpl; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.internal.IdeaContentRootImpl; +import org.jetbrains.plugins.gradle.tooling.internal.IdeaSourceDirectoryImpl; +import org.jetbrains.plugins.gradle.tooling.internal.ModuleExtendedModelImpl; import java.io.File; import java.io.IOException; diff --git a/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ScalaModelBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ScalaModelBuilderImpl.java new file mode 100644 index 000000000000..b885b7faa710 --- /dev/null +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/ScalaModelBuilderImpl.java @@ -0,0 +1,105 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.v1_9.builder; + +import org.gradle.api.Project; +import org.gradle.api.Task; +import org.gradle.api.plugins.scala.ScalaPlugin; +import org.gradle.api.tasks.scala.ScalaCompile; +import org.gradle.api.tasks.scala.ScalaCompileOptions; +import org.gradle.api.tasks.scala.ScalaForkOptions; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ScalaModel; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaCompileOptionsImpl; +import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaForkOptionsImpl; +import org.jetbrains.plugins.gradle.tooling.internal.scala.ScalaModelImpl; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaModelBuilderImpl implements ModelBuilderService { + + private static final String COMPILE_SCALA_TASK = "compileScala"; + + @Override + public boolean canBuild(String modelName) { + return ScalaModel.class.getName().equals(modelName); + } + + @Override + public Object buildAll(String modelName, Project project) { + final ScalaPlugin scalaPlugin = project.getPlugins().findPlugin(ScalaPlugin.class); + if (scalaPlugin == null) return null; + + final ScalaModelImpl scalaModel = new ScalaModelImpl(); + + for (Task task : project.getTasks()) { + if (task instanceof ScalaCompile && COMPILE_SCALA_TASK.equals(task.getName())) { + ScalaCompile scalaCompile = (ScalaCompile)task; + scalaModel.setScalaClasspath(scalaCompile.getScalaClasspath().getFiles()); + scalaModel.setZincClasspath(scalaCompile.getZincClasspath().getFiles()); + scalaModel.setScalaCompileOptions(create(scalaCompile.getScalaCompileOptions())); + scalaModel.setTargetCompatibility(scalaCompile.getTargetCompatibility()); + scalaModel.setSourceCompatibility(scalaCompile.getSourceCompatibility()); + break; + } + } + + return scalaModel; + } + + @Nullable + @Contract("null -> null") + private static ScalaCompileOptionsImpl create(@Nullable ScalaCompileOptions options) { + if (options == null) return null; + + ScalaCompileOptionsImpl result = new ScalaCompileOptionsImpl(); + result.setAdditionalParameters(options.getAdditionalParameters()); + result.setDaemonServer(options.getDaemonServer()); + result.setDebugLevel(options.getDebugLevel()); + result.setDeprecation(options.isDeprecation()); + result.setEncoding(options.getEncoding()); + result.setFailOnError(options.isFailOnError()); + result.setForce(options.getForce()); + result.setFork(options.isFork()); + result.setForkOptions(create(options.getForkOptions())); + result.setListFiles(options.isListFiles()); + result.setLoggingLevel(options.getLoggingLevel()); + result.setDebugLevel(options.getDebugLevel()); + result.setLoggingPhases(options.getLoggingPhases()); + result.setOptimize(options.isOptimize()); + result.setUnchecked(options.isUnchecked()); + result.setUseAnt(options.isUseAnt()); + result.setUseCompileDaemon(options.isUseCompileDaemon()); + + return result; + } + + @Nullable + @Contract("null -> null") + private static ScalaForkOptionsImpl create(@Nullable ScalaForkOptions forkOptions) { + if (forkOptions == null) return null; + + ScalaForkOptionsImpl result = new ScalaForkOptionsImpl(); + result.setJvmArgs(forkOptions.getJvmArgs()); + result.setMemoryInitialSize(forkOptions.getMemoryInitialSize()); + result.setMemoryMaximumSize(forkOptions.getMemoryMaximumSize()); + return result; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/WarModelBuilderImpl.java similarity index 95% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImpl.java rename to plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/WarModelBuilderImpl.java index 8a1d2a133bf8..dfac5c354543 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImpl.java +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/builder/WarModelBuilderImpl.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.v1_9.builder; import org.gradle.api.Action; import org.gradle.api.Project; @@ -25,9 +25,9 @@ import org.gradle.api.java.archives.Manifest; import org.gradle.api.plugins.WarPlugin; import org.gradle.api.tasks.bundling.War; import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.gradle.model.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; import org.jetbrains.plugins.gradle.model.WarModel; -import org.jetbrains.plugins.gradle.model.internal.WarModelImpl; +import org.jetbrains.plugins.gradle.tooling.internal.WarModelImpl; import java.io.File; import java.io.StringWriter; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/DependencyVersionId.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/DependencyVersionId.java similarity index 96% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/DependencyVersionId.java rename to plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/DependencyVersionId.java index e8658cfeaea9..20e812375265 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/DependencyVersionId.java +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/DependencyVersionId.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.v1_9.internal; import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImpl.java b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/ModelDependenciesBuilderImplHelper.java similarity index 52% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImpl.java rename to plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/ModelDependenciesBuilderImplHelper.java index 4c0e3914185e..26a04a096032 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImpl.java +++ b/plugins/gradle/tooling-extension-v1.9/src/org/jetbrains/plugins/gradle/tooling/v1_9/internal/ModelDependenciesBuilderImplHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,152 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.v1_9.internal; import org.gradle.api.Project; import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ModuleIdentifier; import org.gradle.api.artifacts.ModuleVersionIdentifier; import org.gradle.plugins.ide.idea.GenerateIdeaModule; -import org.gradle.plugins.ide.idea.IdeaPlugin; -import org.gradle.plugins.ide.idea.model.IdeaModel; import org.gradle.plugins.ide.internal.IdeDependenciesExtractor; -import org.gradle.tooling.model.idea.IdeaDependency; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.gradle.model.GradleDependencyScope; -import org.jetbrains.plugins.gradle.model.ModelBuilderService; -import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel; -import org.jetbrains.plugins.gradle.model.internal.*; +import org.jetbrains.plugins.gradle.tooling.internal.IdeaSingleEntryLibraryDependencyImpl; +import org.jetbrains.plugins.gradle.tooling.internal.Scopes; import java.io.File; import java.io.Serializable; -import java.util.*; +import java.util.Collection; +import java.util.Map; /** * @author Vladislav.Soroka - * @since 11/5/13 + * @since 2/3/14 */ -public class ModelDependenciesBuilderImpl implements ModelBuilderService { +public class ModelDependenciesBuilderImplHelper { private static final String MODULE_PROPERTY = "ideaModule"; private static final String VERSION_PROPERTY = "version"; private static final String GROUP_PROPERTY = "group"; - @Override - public boolean canBuild(String modelName) { - return ProjectDependenciesModel.class.getName().equals(modelName); - } - @Nullable - @Override - public Object buildAll(final String modelName, final Project project) { - final List dependencies = new ArrayList(); - - final Map scopesMap = new LinkedHashMap(); - final IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor(); - - boolean offline = false; - boolean downloadJavadoc = false; - boolean downloadSources = true; - - final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class); - Map>> userScopes = Collections.emptyMap(); - if (ideaPlugin != null) { - IdeaModel ideaModel = ideaPlugin.getModel(); - if (ideaModel != null && ideaModel.getModule() != null) { - offline = ideaModel.getModule().isOffline(); - downloadJavadoc = ideaModel.getModule().isDownloadJavadoc(); - downloadSources = ideaModel.getModule().isDownloadSources(); - userScopes = ideaModel.getModule().getScopes(); - } - } - - for (final Configuration configuration : project.getConfigurations()) { - Collection plusConfigurations = new ArrayList(); - plusConfigurations.add(configuration); - - final List ideProjectDependencies = - dependenciesExtractor.extractProjectDependencies(plusConfigurations, new ArrayList()); - - for (IdeDependenciesExtractor.IdeProjectDependency ideProjectDependency : ideProjectDependencies) { - merge(scopesMap, ideProjectDependency, userScopes); - } - - if (!offline) { - final Collection ideRepoFileDependencies = - dependenciesExtractor.extractRepoFileDependencies( - project.getConfigurations(), plusConfigurations, new ArrayList(), downloadSources, downloadJavadoc); - for (IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency : ideRepoFileDependencies) { - merge(scopesMap, repoFileDependency, userScopes); - } - } - - final List ideLocalFileDependencies = - dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList()); - for (IdeDependenciesExtractor.IdeLocalFileDependency fileDependency : ideLocalFileDependencies) { - merge(scopesMap, fileDependency, userScopes); - } - } - - for (Map.Entry entry : scopesMap.entrySet()) { - DependencyVersionId versionId = entry.getKey(); - for (GradleDependencyScope scope : entry.getValue().getScopes()) { - if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeRepoFileDependency) { - IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency = - (IdeDependenciesExtractor.IdeRepoFileDependency)versionId.getIdeDependency(); - IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( - new IdeaDependencyScopeImpl(scope), - versionId.getName(), - versionId.getGroup(), - versionId.getVersion(), - versionId.getClassifier() - ); - libraryDependency.setFile(repoFileDependency.getFile()); - libraryDependency.setSource(repoFileDependency.getSourceFile()); - libraryDependency.setJavadoc(repoFileDependency.getJavadocFile()); - dependencies.add(libraryDependency); - } - else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeProjectDependency) { - IdeDependenciesExtractor.IdeProjectDependency projectDependency = - (IdeDependenciesExtractor.IdeProjectDependency)versionId.getIdeDependency(); - - String ideaModuleName = findDeDuplicatedModuleName(projectDependency.getProject()); - if (ideaModuleName == null) { - ideaModuleName = versionId.getName(); - } - - IdeaModuleDependencyImpl moduleDependency = new IdeaModuleDependencyImpl( - new IdeaDependencyScopeImpl(scope), - ideaModuleName, - versionId.getGroup(), - versionId.getVersion(), - versionId.getClassifier() - ); - moduleDependency.setIdeaModule(new StubIdeaModule(ideaModuleName)); - dependencies.add(moduleDependency); - } - else if (versionId.getIdeDependency() instanceof IdeDependenciesExtractor.IdeLocalFileDependency) { - IdeDependenciesExtractor.IdeLocalFileDependency fileDependency = - (IdeDependenciesExtractor.IdeLocalFileDependency)versionId.getIdeDependency(); - IdeaSingleEntryLibraryDependencyImpl libraryDependency = new IdeaSingleEntryLibraryDependencyImpl( - new IdeaDependencyScopeImpl(scope), - versionId.getName(), - versionId.getGroup(), - versionId.getVersion(), - versionId.getClassifier() - ); - libraryDependency.setFile(fileDependency.getFile()); - attachGradleSdkSources(libraryDependency, fileDependency); - dependencies.add(libraryDependency); - } - } - } - - return new ProjectDependenciesModelImpl(project.getPath(), dependencies); - } - - private static void attachGradleSdkSources(IdeaSingleEntryLibraryDependencyImpl libraryDependency, + public static void attachGradleSdkSources(IdeaSingleEntryLibraryDependencyImpl libraryDependency, IdeDependenciesExtractor.IdeLocalFileDependency localFileDependency) { final String libName = localFileDependency.getFile().getName(); if (localFileDependency.getFile() == null || !libName.startsWith("gradle-")) return; @@ -185,7 +70,7 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { } @Nullable - private static String findDeDuplicatedModuleName(Project project) { + public static String findDeDuplicatedModuleName(Project project) { if (project.hasProperty(MODULE_PROPERTY)) { Object ideaModule = project.property(MODULE_PROPERTY); if (ideaModule instanceof GenerateIdeaModule) { @@ -196,7 +81,7 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { return null; } - private static void merge(Map map, + public static void merge(Map map, IdeDependenciesExtractor.IdeProjectDependency dependency, Map>> userScopes) { final String configurationName = dependency.getDeclaredConfiguration().getName(); @@ -218,11 +103,11 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { } } - private static String str(Object o) { + public static String str(Object o) { return String.valueOf(o == null ? "" : o); } - private static void merge(Map map, + public static void merge(Map map, IdeDependenciesExtractor.IdeRepoFileDependency dependency, Map>> userScopes) { final String configurationName = dependency.getDeclaredConfiguration().getName(); @@ -251,14 +136,14 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { } } - private static String parseClassifier(ModuleVersionIdentifier dependencyId, File dependencyFile) { + public static String parseClassifier(ModuleVersionIdentifier dependencyId, File dependencyFile) { if (dependencyFile == null) return null; String dependencyFileName = dependencyFile.getName(); int i = dependencyFileName.indexOf(dependencyId.getName() + '-' + dependencyId.getVersion() + '-'); return i != -1 ? dependencyFileName.substring(i, dependencyFileName.length()) : null; } - private static void merge(Map map, + public static void merge(Map map, IdeDependenciesExtractor.IdeLocalFileDependency dependency, Map>> userScopes) { @@ -286,7 +171,7 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { * @param userScopes gradle IDEA plugin scopes map * @return deduced scope */ - private static GradleDependencyScope deduceScope(String configurationName, + public static GradleDependencyScope deduceScope(String configurationName, Map>> userScopes) { GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName); for (Map.Entry>> entry : userScopes.entrySet()) { @@ -303,7 +188,7 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService { return scope; } - private static class MyModuleVersionIdentifier implements ModuleVersionIdentifier, Serializable { + public static class MyModuleVersionIdentifier implements ModuleVersionIdentifier, Serializable { private final String myName; public MyModuleVersionIdentifier(String name) { diff --git a/plugins/gradle/tooling-extension/gradle-tooling-extension.iml b/plugins/gradle/tooling-extension/gradle-tooling-extension.iml new file mode 100644 index 000000000000..571daaf47263 --- /dev/null +++ b/plugins/gradle/tooling-extension/gradle-tooling-extension.iml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/plugins/gradle/tooling-extension/lib/gradle-build-init-1.9.jar b/plugins/gradle/tooling-extension/lib/gradle-build-init-1.9.jar new file mode 100644 index 000000000000..421eb96fc5ae Binary files /dev/null and b/plugins/gradle/tooling-extension/lib/gradle-build-init-1.9.jar differ diff --git a/plugins/gradle/tooling-extension/lib/gradle-ide-1.9.jar b/plugins/gradle/tooling-extension/lib/gradle-ide-1.9.jar new file mode 100644 index 000000000000..7f818b60b043 Binary files /dev/null and b/plugins/gradle/tooling-extension/lib/gradle-ide-1.9.jar differ diff --git a/plugins/gradle/tooling-extension/lib/gradle-plugins-1.9.jar b/plugins/gradle/tooling-extension/lib/gradle-plugins-1.9.jar new file mode 100644 index 000000000000..17b11d061282 Binary files /dev/null and b/plugins/gradle/tooling-extension/lib/gradle-plugins-1.9.jar differ diff --git a/plugins/gradle/tooling-extension/lib/gradle-scala-1.9.jar b/plugins/gradle/tooling-extension/lib/gradle-scala-1.9.jar new file mode 100644 index 000000000000..aa6a20a2f45a Binary files /dev/null and b/plugins/gradle/tooling-extension/lib/gradle-scala-1.9.jar differ diff --git a/plugins/gradle/tooling-extension/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/gradle/tooling-extension/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 000000000000..8a3203c44d6d --- /dev/null +++ b/plugins/gradle/tooling-extension/src/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1,15 @@ +# +# Copyright 2000-2014 JetBrains s.r.o. +# +# 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. +# diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/BuildScriptClasspathModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/BuildScriptClasspathModel.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/BuildScriptClasspathModel.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/BuildScriptClasspathModel.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ClasspathEntryModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ClasspathEntryModel.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/ClasspathEntryModel.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ClasspathEntryModel.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ExtIdeaContentRoot.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ExtIdeaContentRoot.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/ExtIdeaContentRoot.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ExtIdeaContentRoot.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleDependencyScope.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/GradleDependencyScope.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/GradleDependencyScope.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/GradleDependencyScope.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ModuleExtendedModel.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ProjectDependenciesModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ProjectDependenciesModel.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/ProjectDependenciesModel.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ProjectDependenciesModel.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectImportAction.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java similarity index 98% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectImportAction.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java index 407f12c6981a..af6f4fed60f4 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/service/project/ProjectImportAction.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ProjectImportAction.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.service.project; +package org.jetbrains.plugins.gradle.model; import com.intellij.openapi.externalSystem.model.ExternalSystemException; import org.gradle.tooling.BuildAction; diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaCompileOptions.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaCompileOptions.java new file mode 100644 index 000000000000..596659a62687 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaCompileOptions.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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 java.io.Serializable; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public interface ScalaCompileOptions extends Serializable { + boolean isUseCompileDaemon(); + + String getDaemonServer(); + + boolean isFailOnError(); + + boolean isDeprecation(); + + boolean isUnchecked(); + + String getDebugLevel(); + + boolean isOptimize(); + + String getEncoding(); + + String getForce(); + + List getAdditionalParameters(); + + boolean isListFiles(); + + String getLoggingLevel(); + + List getLoggingPhases(); + + boolean isFork(); + + boolean isUseAnt(); + + ScalaForkOptions getForkOptions(); +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaForkOptions.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaForkOptions.java new file mode 100644 index 000000000000..9dd0cefbf722 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaForkOptions.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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 java.io.Serializable; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public interface ScalaForkOptions extends Serializable { + String getMemoryInitialSize(); + + String getMemoryMaximumSize(); + + List getJvmArgs(); +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaModel.java new file mode 100644 index 000000000000..7e72400f05ca --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/ScalaModel.java @@ -0,0 +1,38 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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 java.io.File; +import java.io.Serializable; +import java.util.Map; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public interface ScalaModel extends Serializable { + + Set getScalaClasspath(); + + Set getZincClasspath(); + + ScalaCompileOptions getScalaCompileOptions(); + + String getSourceCompatibility(); + + String getTargetCompatibility(); +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/WarModel.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/WarModel.java similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/WarModel.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/model/WarModel.java diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ModelBuilderService.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/ModelBuilderService.java similarity index 90% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/ModelBuilderService.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/ModelBuilderService.java index 3a76dbee7c60..4b972fa2e0c7 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/ModelBuilderService.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/ModelBuilderService.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model; +package org.jetbrains.plugins.gradle.tooling; import org.gradle.api.Project; diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/annotation/TargetVersions.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/annotation/TargetVersions.java new file mode 100644 index 000000000000..a5d81fb21a0e --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/annotation/TargetVersions.java @@ -0,0 +1,28 @@ +/* + * Copyright 2012 the original author or authors. + * + * 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.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface TargetVersions { + String value(); + boolean checkBaseVersions() default true; +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/AbstractGradleDependency.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/AbstractGradleDependency.java similarity index 97% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/AbstractGradleDependency.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/AbstractGradleDependency.java index 948081ae35db..16cef89ff2d0 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/AbstractGradleDependency.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/AbstractGradleDependency.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.idea.IdeaDependencyScope; diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/BuildScriptClasspathModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/BuildScriptClasspathModelImpl.java new file mode 100644 index 000000000000..608df19f680a --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/BuildScriptClasspathModelImpl.java @@ -0,0 +1,47 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.gradle.tooling.model.DomainObjectSet; +import org.gradle.tooling.model.internal.ImmutableDomainObjectSet; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel; +import org.jetbrains.plugins.gradle.model.ClasspathEntryModel; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 12/20/13 + */ +public class BuildScriptClasspathModelImpl implements BuildScriptClasspathModel { + + private final List myClasspathEntries; + + public BuildScriptClasspathModelImpl() { + myClasspathEntries = new ArrayList(); + } + + @Override + public DomainObjectSet getClasspath() { + return ImmutableDomainObjectSet.of(myClasspathEntries); + } + + public void add(@NotNull ClasspathEntryModel classpathEntryModel) { + myClasspathEntries.add(classpathEntryModel); + } +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ClasspathEntryModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ClasspathEntryModelImpl.java new file mode 100644 index 000000000000..2a9783c34eb1 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ClasspathEntryModelImpl.java @@ -0,0 +1,60 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.plugins.gradle.model.ClasspathEntryModel; + +import java.io.File; +import java.io.Serializable; + +/** + * @author Vladislav.Soroka + * @since 12/20/13 + */ +public class ClasspathEntryModelImpl implements ClasspathEntryModel, Serializable { + @NotNull + private final File classesFile; + @Nullable + private final File sourcesFile; + @Nullable + private final File javadocFile; + + public ClasspathEntryModelImpl(@NotNull File classesFile, @Nullable File sourcesFile, @Nullable File javadocFile) { + this.classesFile = classesFile; + this.sourcesFile = sourcesFile; + this.javadocFile = javadocFile; + } + + @NotNull + @Override + public File getClassesFile() { + return classesFile; + } + + @Nullable + @Override + public File getSourcesFile() { + return sourcesFile; + } + + @Nullable + @Override + public File getJavadocFile() { + return javadocFile; + } +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilder.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilder.java new file mode 100644 index 000000000000..cdcb8a55089b --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilder.java @@ -0,0 +1,99 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.gradle.api.Project; +import org.gradle.tooling.provider.model.ToolingModelBuilder; +import org.gradle.util.GradleVersion; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.TestOnly; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; + +import java.util.ServiceLoader; + +/** + * @author Vladislav.Soroka + * @since 11/5/13 + */ +@SuppressWarnings("UnusedDeclaration") +public class ExtraModelBuilder implements ToolingModelBuilder { + private static final String RANGE_TOKEN = " <=> "; + private static ServiceLoader buildersLoader = + ServiceLoader.load(ModelBuilderService.class, ExtraModelBuilder.class.getClassLoader()); + + @NotNull + private final GradleVersion myCurrentGradleVersion; + + public ExtraModelBuilder() { + this.myCurrentGradleVersion = GradleVersion.current(); + } + + @TestOnly + public ExtraModelBuilder(@NotNull GradleVersion gradleVersion) { + this.myCurrentGradleVersion = gradleVersion; + } + + @Override + public boolean canBuild(String modelName) { + for (ModelBuilderService service : buildersLoader) { + if (service.canBuild(modelName) && isVersionMatch(service)) return true; + } + return false; + } + + @Override + public Object buildAll(String modelName, Project project) { + for (ModelBuilderService service : buildersLoader) { + if (service.canBuild(modelName) && isVersionMatch(service)) { + return service.buildAll(modelName, project); + } + } + throw new IllegalArgumentException("Unsupported model: " + modelName); + } + + private boolean isVersionMatch(@NotNull ModelBuilderService builderService) { + TargetVersions targetVersions = builderService.getClass().getAnnotation(TargetVersions.class); + if (targetVersions == null || targetVersions.value() == null || targetVersions.value().isEmpty()) return true; + + final GradleVersion current = adjust(myCurrentGradleVersion, targetVersions.checkBaseVersions()); + + if (targetVersions.value().endsWith("+")) { + String minVersion = targetVersions.value().substring(0, targetVersions.value().length() - 1); + return compare(current, minVersion, targetVersions.checkBaseVersions()) >= 0; + } + else { + final int rangeIndex = targetVersions.value().indexOf(RANGE_TOKEN); + if (rangeIndex != -1) { + String minVersion = targetVersions.value().substring(0, rangeIndex); + String maxVersion = targetVersions.value().substring(rangeIndex + RANGE_TOKEN.length()); + return compare(current, minVersion, targetVersions.checkBaseVersions()) >= 0 && + compare(current, maxVersion, targetVersions.checkBaseVersions()) <= 0; + } + else { + return compare(current, targetVersions.value(), targetVersions.checkBaseVersions()) == 0; + } + } + } + + private static int compare(@NotNull GradleVersion gradleVersion, @NotNull String otherGradleVersion, boolean checkBaseVersions) { + return gradleVersion.compareTo(adjust(GradleVersion.version(otherGradleVersion), checkBaseVersions)); + } + + private static GradleVersion adjust(@NotNull GradleVersion version, boolean checkBaseVersions) { + return checkBaseVersions ? version.getBaseVersion() : version; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaContentRootImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaContentRootImpl.java similarity index 97% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaContentRootImpl.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaContentRootImpl.java index 86a37411c8cc..a2dbfe8da332 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaContentRootImpl.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaContentRootImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaSourceDirectory; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaDependencyScopeImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaDependencyScopeImpl.java similarity index 94% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaDependencyScopeImpl.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaDependencyScopeImpl.java index aa7f5af7e656..6e10e562d131 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaDependencyScopeImpl.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaDependencyScopeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.idea.IdeaDependencyScope; import org.jetbrains.plugins.gradle.model.GradleDependencyScope; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaModuleDependencyImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaModuleDependencyImpl.java similarity index 94% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaModuleDependencyImpl.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaModuleDependencyImpl.java index 6890ebd505c1..5b5d0df86921 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaModuleDependencyImpl.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaModuleDependencyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.idea.IdeaDependencyScope; import org.gradle.tooling.model.idea.IdeaModule; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSingleEntryLibraryDependencyImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSingleEntryLibraryDependencyImpl.java similarity index 95% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSingleEntryLibraryDependencyImpl.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSingleEntryLibraryDependencyImpl.java index 7012a3681299..13025c97f88a 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSingleEntryLibraryDependencyImpl.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSingleEntryLibraryDependencyImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.GradleModuleVersion; import org.gradle.tooling.model.idea.IdeaDependencyScope; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSourceDirectoryImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSourceDirectoryImpl.java similarity index 91% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSourceDirectoryImpl.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSourceDirectoryImpl.java index bcc37bd14124..f038fb85fef4 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/IdeaSourceDirectoryImpl.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/IdeaSourceDirectoryImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.idea.IdeaSourceDirectory; diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java new file mode 100644 index 000000000000..46ecbf1aae63 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ModuleExtendedModelImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.gradle.tooling.model.DomainObjectSet; +import org.gradle.tooling.model.internal.ImmutableDomainObjectSet; +import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot; +import org.jetbrains.plugins.gradle.model.ModuleExtendedModel; + +import java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 11/8/13 + */ +public class ModuleExtendedModelImpl implements ModuleExtendedModel { + private final String myName; + private final String myGroup; + private final String myVersion; + private List myArtifacts; + private Set myContentRoots; + + public ModuleExtendedModelImpl(String name, String group, String version) { + myName = name; + myGroup = group; + myVersion = version; + myArtifacts = Collections.emptyList(); + myContentRoots = Collections.emptySet(); + } + + @Override + public String getName() { + return myName; + } + + @Override + public String getGroup() { + return myGroup; + } + + @Override + public String getVersion() { + return myVersion; + } + + @Override + public List getArtifacts() { + return myArtifacts; + } + + public void setArtifacts(List artifacts) { + this.myArtifacts = artifacts == null ? Collections.emptyList() : artifacts; + } + + @Override + public DomainObjectSet getContentRoots() { + return ImmutableDomainObjectSet.of(myContentRoots); + } + + public void setContentRoots(Set contentRoots) { + myContentRoots = contentRoots == null ? Collections.emptySet() : contentRoots; + } +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ProjectDependenciesModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ProjectDependenciesModelImpl.java new file mode 100644 index 000000000000..1a57dc555fa2 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/ProjectDependenciesModelImpl.java @@ -0,0 +1,52 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.gradle.tooling.model.idea.IdeaDependency; +import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel; + +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 11/8/13 + */ +public class ProjectDependenciesModelImpl implements ProjectDependenciesModel { + private final String projectName; + private final List myDependencies; + + public ProjectDependenciesModelImpl(String projectName, List dependencies) { + this.projectName = projectName; + myDependencies = dependencies; + } + + @Override + public String getProjectName() { + return projectName; + } + + @Override + public List getDependencies() { + return myDependencies; + } + + @Override + public String toString() { + return "ProjectDependenciesModelImpl{" + + "projectName='" + projectName + '\'' + + '}'; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/Scopes.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/Scopes.java similarity index 97% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/Scopes.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/Scopes.java index cc0155e5678d..3f4772316177 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/Scopes.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/Scopes.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.jetbrains.plugins.gradle.model.GradleDependencyScope; diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/StubIdeaModule.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/StubIdeaModule.java similarity index 95% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/StubIdeaModule.java rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/StubIdeaModule.java index 0e8d2bc6068d..1662240dd368 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/StubIdeaModule.java +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/StubIdeaModule.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.internal; +package org.jetbrains.plugins.gradle.tooling.internal; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.GradleProject; diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/WarModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/WarModelImpl.java new file mode 100644 index 000000000000..b35e4be6231f --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/WarModelImpl.java @@ -0,0 +1,86 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.WarModel; + +import java.io.File; +import java.util.Map; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 11/5/13 + */ +public class WarModelImpl implements WarModel { + private final String myWebAppDirName; + private final File myWebAppDir; + private File myWebXml; + private Map> myWebRoots; + private Set myClasspath; + private String myManifestContent; + + public WarModelImpl(String webAppDirName, File webAppDir) { + myWebAppDirName = webAppDirName; + myWebAppDir = webAppDir; + } + + @Override + public String getWebAppDirName() { + return myWebAppDirName; + } + + @Override + public File getWebAppDir() { + return myWebAppDir; + } + + public void setWebXml(File webXml) { + myWebXml = webXml; + } + + @Override + public File getWebXml() { + return myWebXml; + } + + @Override + public Map> getWebRoots() { + return myWebRoots; + } + + public void setWebRoots(Map> webRoots) { + myWebRoots = webRoots; + } + + public void setClasspath(Set classpath) { + myClasspath = classpath; + } + + @Override + public Set getClasspath() { + return myClasspath; + } + + public void setManifestContent(String manifestContent) { + myManifestContent = manifestContent; + } + + @Override + public String getManifestContent() { + return myManifestContent; + } +} diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/buildSrcInit.gradle b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/buildSrcInit.gradle similarity index 100% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/buildSrcInit.gradle rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/buildSrcInit.gradle diff --git a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/init.gradle b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/init.gradle similarity index 87% rename from plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/init.gradle rename to plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/init.gradle index 4f382fd42590..d9c1e3bc538e 100644 --- a/plugins/gradle/src/org/jetbrains/plugins/gradle/model/internal/init.gradle +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/init.gradle @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,10 @@ class JetGradlePlugin implements Plugin { } try { - URL[] urls = [new File("${JAR_PATH}").toURI().toURL()] + String[] paths = ${EXTENSIONS_JARS_PATH} + URL[] urls = paths.collect{ new File(it).toURI().toURL() } URLClassLoader classLoader = new URLClassLoader(urls, getClass().classLoader) - Class modelClass = classLoader.loadClass('org.jetbrains.plugins.gradle.model.internal.ExtraModelBuilder') + Class modelClass = classLoader.loadClass('org.jetbrains.plugins.gradle.tooling.internal.ExtraModelBuilder') allprojects { apply plugin: 'idea' idea.module.ext.set('resourceDirs', []) diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaCompileOptionsImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaCompileOptionsImpl.java new file mode 100644 index 000000000000..b40d0cb1b187 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaCompileOptionsImpl.java @@ -0,0 +1,188 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.scala; + +import org.jetbrains.plugins.gradle.model.ScalaCompileOptions; +import org.jetbrains.plugins.gradle.model.ScalaForkOptions; + +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaCompileOptionsImpl implements ScalaCompileOptions { + private boolean useCompileDaemon; + private String daemonServer; + private boolean failOnError; + private boolean deprecation; + private boolean unchecked; + private String debugLevel; + private boolean optimize; + private String encoding; + private String force; + private List additionalParameters; + private boolean listFiles; + private String loggingLevel; + private List loggingPhases; + private boolean fork; + private ScalaForkOptionsImpl forkOptions; + private boolean useAnt; + + @Override + public boolean isUseCompileDaemon() { + return useCompileDaemon; + } + + public void setUseCompileDaemon(boolean useCompileDaemon) { + this.useCompileDaemon = useCompileDaemon; + } + + @Override + public String getDaemonServer() { + return daemonServer; + } + + public void setDaemonServer(String daemonServer) { + this.daemonServer = daemonServer; + } + + @Override + public boolean isFailOnError() { + return failOnError; + } + + public void setFailOnError(boolean failOnError) { + this.failOnError = failOnError; + } + + @Override + public boolean isDeprecation() { + return deprecation; + } + + public void setDeprecation(boolean deprecation) { + this.deprecation = deprecation; + } + + @Override + public boolean isUnchecked() { + return unchecked; + } + + public void setUnchecked(boolean unchecked) { + this.unchecked = unchecked; + } + + @Override + public String getDebugLevel() { + return debugLevel; + } + + public void setDebugLevel(String debugLevel) { + this.debugLevel = debugLevel; + } + + @Override + public boolean isOptimize() { + return optimize; + } + + public void setOptimize(boolean optimize) { + this.optimize = optimize; + } + + @Override + public String getEncoding() { + return encoding; + } + + public void setEncoding(String encoding) { + this.encoding = encoding; + } + + @Override + public String getForce() { + return force; + } + + public void setForce(String force) { + this.force = force; + } + + @Override + public List getAdditionalParameters() { + return additionalParameters; + } + + public void setAdditionalParameters(List additionalParameters) { + this.additionalParameters = additionalParameters; + } + + @Override + public boolean isListFiles() { + return listFiles; + } + + public void setListFiles(boolean listFiles) { + this.listFiles = listFiles; + } + + @Override + public String getLoggingLevel() { + return loggingLevel; + } + + public void setLoggingLevel(String loggingLevel) { + this.loggingLevel = loggingLevel; + } + + @Override + public List getLoggingPhases() { + return loggingPhases; + } + + public void setLoggingPhases(List loggingPhases) { + this.loggingPhases = loggingPhases; + } + + @Override + public boolean isFork() { + return fork; + } + + public void setFork(boolean fork) { + this.fork = fork; + } + + @Override + public boolean isUseAnt() { + return useAnt; + } + + public void setUseAnt(boolean useAnt) { + this.useAnt = useAnt; + } + + @Override + public ScalaForkOptions getForkOptions() { + return forkOptions; + } + + public void setForkOptions(ScalaForkOptionsImpl forkOptions) { + this.forkOptions = forkOptions; + } +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaForkOptionsImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaForkOptionsImpl.java new file mode 100644 index 000000000000..cd5612d59f6f --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaForkOptionsImpl.java @@ -0,0 +1,57 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.scala; + +import org.jetbrains.plugins.gradle.model.ScalaForkOptions; + +import java.util.List; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaForkOptionsImpl implements ScalaForkOptions { + private String memoryInitialSize; + private String memoryMaximumSize; + private List jvmArgs; + + @Override + public String getMemoryInitialSize() { + return memoryInitialSize; + } + + public void setMemoryInitialSize(String memoryInitialSize) { + this.memoryInitialSize = memoryInitialSize; + } + + @Override + public String getMemoryMaximumSize() { + return memoryMaximumSize; + } + + public void setMemoryMaximumSize(String memoryMaximumSize) { + this.memoryMaximumSize = memoryMaximumSize; + } + + @Override + public List getJvmArgs() { + return jvmArgs; + } + + public void setJvmArgs(List jvmArgs) { + this.jvmArgs = jvmArgs; + } +} diff --git a/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaModelImpl.java b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaModelImpl.java new file mode 100644 index 000000000000..e019ca5b5368 --- /dev/null +++ b/plugins/gradle/tooling-extension/src/org/jetbrains/plugins/gradle/tooling/internal/scala/ScalaModelImpl.java @@ -0,0 +1,79 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.scala; + +import org.jetbrains.plugins.gradle.model.ScalaCompileOptions; +import org.jetbrains.plugins.gradle.model.ScalaModel; + +import java.io.File; +import java.util.Set; + +/** + * @author Vladislav.Soroka + * @since 1/31/14 + */ +public class ScalaModelImpl implements ScalaModel { + private Set scalaClasspath; + private Set zincClasspath; + private String sourceCompatibility; + private String targetCompatibility; + private ScalaCompileOptionsImpl scalaCompileOptions; + + @Override + public Set getScalaClasspath() { + return scalaClasspath; + } + + public void setScalaClasspath(Set scalaClasspath) { + this.scalaClasspath = scalaClasspath; + } + + @Override + public Set getZincClasspath() { + return zincClasspath; + } + + public void setZincClasspath(Set zincClasspath) { + this.zincClasspath = zincClasspath; + } + + @Override + public ScalaCompileOptions getScalaCompileOptions() { + return scalaCompileOptions; + } + + public void setScalaCompileOptions(ScalaCompileOptionsImpl scalaCompileOptions) { + this.scalaCompileOptions = scalaCompileOptions; + } + + @Override + public String getSourceCompatibility() { + return sourceCompatibility; + } + + public void setSourceCompatibility(String sourceCompatibility) { + this.sourceCompatibility = sourceCompatibility; + } + + @Override + public String getTargetCompatibility() { + return targetCompatibility; + } + + public void setTargetCompatibility(String targetCompatibility) { + this.targetCompatibility = targetCompatibility; + } +} diff --git a/plugins/gradle/testData/testDefaultDependenciesModel/build.gradle b/plugins/gradle/tooling-extension/testData/testDefaultDependenciesModel/build.gradle similarity index 100% rename from plugins/gradle/testData/testDefaultDependenciesModel/build.gradle rename to plugins/gradle/tooling-extension/testData/testDefaultDependenciesModel/build.gradle diff --git a/plugins/gradle/testData/testDefaultDependenciesModel/settings.gradle b/plugins/gradle/tooling-extension/testData/testDefaultDependenciesModel/settings.gradle similarity index 100% rename from plugins/gradle/testData/testDefaultDependenciesModel/settings.gradle rename to plugins/gradle/tooling-extension/testData/testDefaultDependenciesModel/settings.gradle diff --git a/plugins/gradle/testData/testDefaultWarModel/build.gradle b/plugins/gradle/tooling-extension/testData/testDefaultWarModel/build.gradle similarity index 100% rename from plugins/gradle/testData/testDefaultWarModel/build.gradle rename to plugins/gradle/tooling-extension/testData/testDefaultWarModel/build.gradle diff --git a/plugins/gradle/testData/testDefaultWarModel/settings.gradle b/plugins/gradle/tooling-extension/testData/testDefaultWarModel/settings.gradle similarity index 100% rename from plugins/gradle/testData/testDefaultWarModel/settings.gradle rename to plugins/gradle/tooling-extension/testData/testDefaultWarModel/settings.gradle diff --git a/plugins/gradle/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle b/plugins/gradle/tooling-extension/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle similarity index 100% rename from plugins/gradle/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle rename to plugins/gradle/tooling-extension/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle diff --git a/plugins/gradle/testData/testGradleIdeaPluginPlusScopesDependenciesModel/settings.gradle b/plugins/gradle/tooling-extension/testData/testGradleIdeaPluginPlusScopesDependenciesModel/settings.gradle similarity index 100% rename from plugins/gradle/testData/testGradleIdeaPluginPlusScopesDependenciesModel/settings.gradle rename to plugins/gradle/tooling-extension/testData/testGradleIdeaPluginPlusScopesDependenciesModel/settings.gradle diff --git a/plugins/gradle/testData/testGradleSourcesSetsInterpretation/build.gradle b/plugins/gradle/tooling-extension/testData/testGradleSourcesSetsInterpretation/build.gradle similarity index 100% rename from plugins/gradle/testData/testGradleSourcesSetsInterpretation/build.gradle rename to plugins/gradle/tooling-extension/testData/testGradleSourcesSetsInterpretation/build.gradle diff --git a/plugins/gradle/testData/testGradleSourcesSetsInterpretation/settings.gradle b/plugins/gradle/tooling-extension/testData/testGradleSourcesSetsInterpretation/settings.gradle similarity index 100% rename from plugins/gradle/testData/testGradleSourcesSetsInterpretation/settings.gradle rename to plugins/gradle/tooling-extension/testData/testGradleSourcesSetsInterpretation/settings.gradle diff --git a/plugins/gradle/testData/testModelBuildScriptClasspathBuilder/build.gradle b/plugins/gradle/tooling-extension/testData/testModelBuildScriptClasspathBuilder/build.gradle similarity index 100% rename from plugins/gradle/testData/testModelBuildScriptClasspathBuilder/build.gradle rename to plugins/gradle/tooling-extension/testData/testModelBuildScriptClasspathBuilder/build.gradle diff --git a/plugins/gradle/testData/testModelBuildScriptClasspathBuilder/settings.gradle b/plugins/gradle/tooling-extension/testData/testModelBuildScriptClasspathBuilder/settings.gradle similarity index 100% rename from plugins/gradle/testData/testModelBuildScriptClasspathBuilder/settings.gradle rename to plugins/gradle/tooling-extension/testData/testModelBuildScriptClasspathBuilder/settings.gradle diff --git a/plugins/gradle/tooling-extension/testSources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/plugins/gradle/tooling-extension/testSources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService new file mode 100644 index 000000000000..1ef2a6e6f830 --- /dev/null +++ b/plugins/gradle/tooling-extension/testSources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -0,0 +1,19 @@ +# +# Copyright 2000-2014 JetBrains s.r.o. +# +# 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. +# +org.jetbrains.plugins.gradle.tooling.internal.ExtraModelBuilderTest$TestModelBuilderService_v_1_8 +org.jetbrains.plugins.gradle.tooling.internal.ExtraModelBuilderTest$TestModelBuilderService_v_1_8_or_Above +org.jetbrains.plugins.gradle.tooling.internal.ExtraModelBuilderTest$TestModelBuilderService_between_v_1_8_and_1_9 +org.jetbrains.plugins.gradle.tooling.internal.ExtraModelBuilderTest$TestModelBuilderService_between_v_1_8_and_1_9_NotBase diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/AbstractModelBuilderTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java similarity index 65% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/AbstractModelBuilderTest.java rename to plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java index fe5e70377843..e69ab842ebbf 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/AbstractModelBuilderTest.java +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java @@ -13,24 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.builder; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.BuildActionExecuter; import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; import org.gradle.tooling.internal.consumer.DefaultGradleConnector; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.service.project.GradleExecutionHelper; -import org.jetbrains.plugins.gradle.service.project.ProjectImportAction; import org.jetbrains.plugins.gradle.util.GradleConstants; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; import java.io.File; +import java.util.Arrays; +import java.util.Collection; import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import static org.junit.Assert.assertNotNull; @@ -38,36 +44,73 @@ import static org.junit.Assert.assertNotNull; * @author Vladislav.Soroka * @since 11/29/13 */ +@RunWith(value = Parameterized.class) public abstract class AbstractModelBuilderTest { + + public static final String GRADLE_v1_9 = "1.9"; + public static final String GRADLE_v1_10 = "1.10"; + public static final String GRADLE_v1_11 = "1.11-rc-1"; + + public static final Pattern TEST_METHOD_NAME_PATTERN; + + static { + TEST_METHOD_NAME_PATTERN = Pattern.compile("(.*)\\[(\\d*)\\]"); + } + private static File ourTempDir; + + @NotNull + private final String gradleVersion; protected File testDir; protected ProjectImportAction.AllModels allModels; @Rule public TestName name = new TestName(); + public AbstractModelBuilderTest(@NotNull String gradleVersion) { + this.gradleVersion = gradleVersion; + } + + @Parameterized.Parameters + public static Collection data() { + Object[][] data = new Object[][]{ + {AbstractModelBuilderTest.GRADLE_v1_9}, + {AbstractModelBuilderTest.GRADLE_v1_10}, + {AbstractModelBuilderTest.GRADLE_v1_11}}; + return Arrays.asList(data); + } + + @Before public void setUp() throws Exception { ensureTempDirCreated(); - testDir = new File(ourTempDir, name.getMethodName()); + + String methodName = name.getMethodName(); + Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName); + if (m.matches()) { + methodName = m.group(1); + } + + testDir = new File(ourTempDir, methodName); testDir.mkdirs(); FileUtil.writeToFile( new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME), FileUtil.loadTextAndClose(getClass().getResourceAsStream( - String.format("/%s/%s", name.getMethodName(), GradleConstants.DEFAULT_SCRIPT_NAME)) + String.format("/%s/%s", methodName, GradleConstants.DEFAULT_SCRIPT_NAME)) ) ); FileUtil.writeToFile( new File(testDir, GradleConstants.SETTINGS_FILE_NAME), FileUtil.loadTextAndClose(getClass().getResourceAsStream( - String.format("/%s/%s", name.getMethodName(), GradleConstants.SETTINGS_FILE_NAME)) + String.format("/%s/%s", methodName, GradleConstants.SETTINGS_FILE_NAME)) ) ); GradleConnector connector = GradleConnector.newConnector(); DefaultGradleConnector gradleConnector = (DefaultGradleConnector)connector; + gradleConnector.useGradleVersion(gradleVersion); gradleConnector.forProjectDirectory(testDir); ProjectConnection connection = gradleConnector.connect(); diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImplTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelBuildScriptClasspathBuilderImplTest.java similarity index 90% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImplTest.java rename to plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelBuildScriptClasspathBuilderImplTest.java index d802d086e4df..c624b599a26a 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelBuildScriptClasspathBuilderImplTest.java +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelBuildScriptClasspathBuilderImplTest.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.builder; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaModule; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel; import org.jetbrains.plugins.gradle.model.ClasspathEntryModel; import org.junit.Test; @@ -35,10 +36,12 @@ import static org.junit.Assert.assertTrue; */ public class ModelBuildScriptClasspathBuilderImplTest extends AbstractModelBuilderTest { + public ModelBuildScriptClasspathBuilderImplTest(@NotNull String gradleVersion) { + super(gradleVersion); + } + @Test public void testModelBuildScriptClasspathBuilder() throws Exception { - ModelBuildScriptClasspathBuilderImpl buildScriptClasspathBuilder = new ModelBuildScriptClasspathBuilderImpl(); - assertTrue(buildScriptClasspathBuilder.canBuild("org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel")); DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); @@ -61,7 +64,8 @@ public class ModelBuildScriptClasspathBuilderImplTest extends AbstractModelBuild assertEquals("Wrong build classpath for module: " + module.getName(), 1, classpathModel.getClasspath().size()); ClasspathEntryModel classpathEntry = classpathModel.getClasspath().getAt(0); - assertEquals("Wrong build classpath for module: " + module.getName(), "inheritedDep.jar", classpathEntry.getClassesFile().getName()); + assertEquals("Wrong build classpath for module: " + module.getName(), "inheritedDep.jar", + classpathEntry.getClassesFile().getName()); } else if (module.getName().equals("moduleWithoutAdditionalClasspath") || module.getName().equals("testModelBuildScriptClasspathBuilder")) { diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImplTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelDependenciesBuilderImplTest.java similarity index 92% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImplTest.java rename to plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelDependenciesBuilderImplTest.java index 8cf50ef62af5..4ebb800a3cff 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModelDependenciesBuilderImplTest.java +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModelDependenciesBuilderImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.builder; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; @@ -25,7 +25,6 @@ import org.gradle.tooling.model.idea.IdeaSingleEntryLibraryDependency; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.GradleDependencyScope; import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel; -import org.junit.Assert; import org.junit.Test; import java.util.List; @@ -42,11 +41,12 @@ import static org.junit.Assert.assertNotNull; */ public class ModelDependenciesBuilderImplTest extends AbstractModelBuilderTest { + public ModelDependenciesBuilderImplTest(@NotNull String gradleVersion) { + super(gradleVersion); + } + @Test public void testDefaultDependenciesModel() throws Exception { - ModelDependenciesBuilderImpl dependenciesBuilder = new ModelDependenciesBuilderImpl(); - assertTrue(dependenciesBuilder.canBuild("org.jetbrains.plugins.gradle.model.ProjectDependenciesModel")); - DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); final int modulesSize = 3; @@ -76,9 +76,6 @@ public class ModelDependenciesBuilderImplTest extends AbstractModelBuilderTest { @Test public void testGradleIdeaPluginPlusScopesDependenciesModel() throws Exception { - ModelDependenciesBuilderImpl dependenciesBuilder = new ModelDependenciesBuilderImpl(); - assertTrue(dependenciesBuilder.canBuild("org.jetbrains.plugins.gradle.model.ProjectDependenciesModel")); - DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); final int modulesSize = 5; diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImplTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImplTest.java similarity index 97% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImplTest.java rename to plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImplTest.java index 9694c9d37345..70e96dfe3c27 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/ModuleExtendedModelBuilderImplTest.java +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/ModuleExtendedModelBuilderImplTest.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.builder; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.Function; @@ -21,6 +21,7 @@ import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.tooling.model.idea.IdeaSourceDirectory; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.ExtIdeaContentRoot; import org.jetbrains.plugins.gradle.model.ModuleExtendedModel; import org.junit.Assert; @@ -43,13 +44,14 @@ import static org.junit.Assert.assertTrue; */ public class ModuleExtendedModelBuilderImplTest extends AbstractModelBuilderTest { + public ModuleExtendedModelBuilderImplTest(@NotNull String gradleVersion) { + super(gradleVersion); + } + @Test public void testGradleSourcesSetsInterpretation() throws Exception { final int modulesSize = 7; - ModuleExtendedModelBuilderImpl moduleExtendedModelBuilder = new ModuleExtendedModelBuilderImpl(); - assertTrue(moduleExtendedModelBuilder.canBuild("org.jetbrains.plugins.gradle.model.ModuleExtendedModel")); - DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); List models = diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImplTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImplTest.java similarity index 85% rename from plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImplTest.java rename to plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImplTest.java index e0aff5949eb9..72f45c7f9d63 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/model/builder/WarModelBuilderImplTest.java +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImplTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.jetbrains.plugins.gradle.model.builder; +package org.jetbrains.plugins.gradle.tooling.builder; import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.gradle.tooling.model.DomainObjectSet; import org.gradle.tooling.model.idea.IdeaModule; +import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.model.WarModel; import org.junit.Test; @@ -26,7 +27,6 @@ import java.util.List; import java.util.Set; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** * @author Vladislav.Soroka @@ -34,11 +34,12 @@ import static org.junit.Assert.assertTrue; */ public class WarModelBuilderImplTest extends AbstractModelBuilderTest { + public WarModelBuilderImplTest(@NotNull String gradleVersion) { + super(gradleVersion); + } + @Test public void testDefaultWarModel() throws Exception { - WarModelBuilderImpl warModelBuilder = new WarModelBuilderImpl(); - assertTrue(warModelBuilder.canBuild("org.jetbrains.plugins.gradle.model.WarModel")); - DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); List ideaModule = ContainerUtil.mapNotNull(ideaModules, new Function() { diff --git a/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilderTest.java b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilderTest.java new file mode 100644 index 000000000000..a4b8d2fc0d6d --- /dev/null +++ b/plugins/gradle/tooling-extension/testSources/org/jetbrains/plugins/gradle/tooling/internal/ExtraModelBuilderTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * 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.gradle.api.Project; +import org.gradle.util.GradleVersion; +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; +import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * @author Vladislav.Soroka + * @since 2/3/14 + */ +public class ExtraModelBuilderTest { + + @Test + public void testVersionMatching() throws Exception { + + assertTrue(isMatching("1.8", TestModelBuilderService_v_1_8.class)); + assertTrue(isMatching("1.8-rc-1", TestModelBuilderService_v_1_8.class)); + assertFalse(isMatching("1.7", TestModelBuilderService_v_1_8.class)); + assertFalse(isMatching("1.7-rc-1", TestModelBuilderService_v_1_8.class)); + assertFalse(isMatching("1.9", TestModelBuilderService_v_1_8.class)); + + assertTrue(isMatching("1.8", TestModelBuilderService_v_1_8_or_Above.class)); + assertTrue(isMatching("1.8-rc-1", TestModelBuilderService_v_1_8_or_Above.class)); + assertFalse(isMatching("1.7", TestModelBuilderService_v_1_8_or_Above.class)); + assertTrue(isMatching("1.9", TestModelBuilderService_v_1_8_or_Above.class)); + assertTrue(isMatching("1.10", TestModelBuilderService_v_1_8_or_Above.class)); + + assertTrue(isMatching("1.8", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertTrue(isMatching("1.8-20130903233633+0000", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertFalse(isMatching("1.7", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertFalse(isMatching("1.7-20130903233633+0000", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertTrue(isMatching("1.9", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertTrue(isMatching("1.9-20131007220022+0000", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertFalse(isMatching("1.10", TestModelBuilderService_between_v_1_8_and_1_9.class)); + assertFalse(isMatching("1.10-20131007220022+0000", TestModelBuilderService_between_v_1_8_and_1_9.class)); + + assertTrue(isMatching("1.8", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertFalse(isMatching("1.8-20130903233633+0000", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertFalse(isMatching("1.7", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertFalse(isMatching("1.7-20130903233633+0000", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertTrue(isMatching("1.9", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertTrue(isMatching("1.9-20131007220022+0000", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertFalse(isMatching("1.10", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + assertFalse(isMatching("1.10-20131007220022+0000", TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class)); + } + + @TargetVersions("1.8") + public static class TestModelBuilderService_v_1_8 implements ModelBuilderService { + @Override + public boolean canBuild(String modelName) { + return TestModelBuilderService_v_1_8.class.getName().equals(modelName); + } + + @Override + public Object buildAll(String modelName, Project project) { + return null; + } + } + + @TargetVersions("1.8+") + public static class TestModelBuilderService_v_1_8_or_Above implements ModelBuilderService { + @Override + public boolean canBuild(String modelName) { + return TestModelBuilderService_v_1_8_or_Above.class.getName().equals(modelName); + } + + @Override + public Object buildAll(String modelName, Project project) { + return null; + } + } + + @TargetVersions("1.8 <=> 1.9") + public static class TestModelBuilderService_between_v_1_8_and_1_9 implements ModelBuilderService { + @Override + public boolean canBuild(String modelName) { + return TestModelBuilderService_between_v_1_8_and_1_9.class.getName().equals(modelName); + } + + @Override + public Object buildAll(String modelName, Project project) { + return null; + } + } + + @TargetVersions(value = "1.8 <=> 1.9", checkBaseVersions = false) + public static class TestModelBuilderService_between_v_1_8_and_1_9_NotBase implements ModelBuilderService { + @Override + public boolean canBuild(String modelName) { + return TestModelBuilderService_between_v_1_8_and_1_9_NotBase.class.getName().equals(modelName); + } + + @Override + public Object buildAll(String modelName, Project project) { + return null; + } + } + + + private static boolean isMatching(String version, Class aClass) { + return new ExtraModelBuilder(GradleVersion.version(version)).canBuild(aClass.getName()); + } +}