diff options
author | Alex Ruiz <alruiz@google.com> | 2014-07-08 19:58:18 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-07-02 20:49:53 +0000 |
commit | 7e8985802a70244120ec4eb6344d1d40fbd584d6 (patch) | |
tree | 9ad4bc1c74ea7bb50b95b61249ced871c051725f | |
parent | 276760500b6afbdaff47f3ec1627ff494f904c9d (diff) | |
parent | bc29dcb6dc2be741135f06420617cd0a3e90de3f (diff) | |
download | idea-7e8985802a70244120ec4eb6344d1d40fbd584d6.tar.gz |
Merge "Gradle: fix compatibility with Gradle 2.0 (cherry picked from commit 84cd616)" into idea133
6 files changed, 148 insertions, 145 deletions
diff --git a/plugins/gradle/lib/gradle-base-services-groovy-1.12.jar b/plugins/gradle/lib/gradle-base-services-groovy-1.12.jar Binary files differnew file mode 100644 index 000000000000..511609f89d08 --- /dev/null +++ b/plugins/gradle/lib/gradle-base-services-groovy-1.12.jar diff --git a/plugins/gradle/tooling-extension-api/gradle-tooling-extension-api.iml b/plugins/gradle/tooling-extension-api/gradle-tooling-extension-api.iml index 898ae3d4e65c..3d2c4e4fed68 100644 --- a/plugins/gradle/tooling-extension-api/gradle-tooling-extension-api.iml +++ b/plugins/gradle/tooling-extension-api/gradle-tooling-extension-api.iml @@ -19,6 +19,7 @@ <root url="jar://$MODULE_DIR$/../lib/gradle-messaging-1.12.jar!/" /> <root url="jar://$MODULE_DIR$/../lib/gradle-wrapper-1.12.jar!/" /> <root url="jar://$MODULE_DIR$/../lib/gradle-base-services-1.12.jar!/" /> + <root url="jar://$MODULE_DIR$/../lib/gradle-base-services-groovy-1.12.jar!/" /> <root url="jar://$MODULE_DIR$/../lib/gradle-native-1.12.jar!/" /> </CLASSES> <JAVADOC /> diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy new file mode 100644 index 000000000000..a48ebd45f39e --- /dev/null +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy @@ -0,0 +1,140 @@ +/* + * 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.builder + +import org.gradle.api.Project +import org.gradle.api.Task +import org.gradle.api.file.FileVisitDetails +import org.gradle.api.file.FileVisitor +import org.gradle.api.java.archives.Manifest +import org.gradle.api.plugins.WarPlugin +import org.gradle.api.tasks.bundling.War +import org.gradle.util.GradleVersion +import org.jetbrains.annotations.NotNull +import org.jetbrains.annotations.Nullable +import org.jetbrains.plugins.gradle.model.web.WebConfiguration +import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService +import org.jetbrains.plugins.gradle.tooling.internal.web.WarModelImpl +import org.jetbrains.plugins.gradle.tooling.internal.web.WebConfigurationImpl +import org.jetbrains.plugins.gradle.tooling.internal.web.WebResourceImpl + +/** + * @author Vladislav.Soroka + * @since 6/25/2014 + */ +class WarModelBuilderImpl implements ModelBuilderService { + + private static final String WEB_APP_DIR_PROPERTY = "webAppDir" + private static final String WEB_APP_DIR_NAME_PROPERTY = "webAppDirName" + + @Override + public boolean canBuild(String modelName) { + return WebConfiguration.name.equals(modelName) + } + + @Nullable + @Override + public Object buildAll(String modelName, Project project) { + final WarPlugin warPlugin = project.plugins.findPlugin(WarPlugin) + if (warPlugin == null) return null + + final String webAppDirName = !project.hasProperty(WEB_APP_DIR_NAME_PROPERTY) ? + "src/main/webapp" : String.valueOf(project.property(WEB_APP_DIR_NAME_PROPERTY)) + + final File webAppDir = !project.hasProperty(WEB_APP_DIR_PROPERTY) ? new File(project.projectDir, webAppDirName) : + (File)project.property(WEB_APP_DIR_PROPERTY) + + def warModels = [] + + project.tasks.each { Task task -> + if (task instanceof War) { + final WarModelImpl warModel = + new WarModelImpl((task as War).archiveName, webAppDirName, webAppDir) + + final List<WebConfiguration.WebResource> webResources = [] + final War warTask = task as War + warModel.webXml = warTask.webXml + + warTask.rootSpec.walk({ def resolver -> + // def resolver -> + // in Gradle v1.x - org.gradle.api.internal.file.copy.CopySpecInternal + // in Gradle v2.x - org.gradle.api.internal.file.copy.CopySpecResolver + + if (resolver.metaClass.respondsTo(resolver, 'setIncludeEmptyDirs', boolean)) { + resolver.setIncludeEmptyDirs(true) + } + if (!resolver.metaClass.respondsTo(resolver, 'getDestPath') || + !resolver.metaClass.respondsTo(resolver, 'getSource')) { + throw new RuntimeException("${GradleVersion.current()} is not supported by web artifact importer") + } + + final String relativePath = resolver.destPath.pathString + resolver.source.visit(new FileVisitor() { + @Override + public void visitDir(FileVisitDetails dirDetails) { + try { + addPath(webResources, relativePath, dirDetails.path, dirDetails.file) + } + catch (Exception ignore) { + } + } + + @Override + public void visitFile(FileVisitDetails fileDetails) { + try { + if (warTask.webXml == null || + !fileDetails.file.canonicalPath.equals(warTask.webXml.canonicalPath)) { + addPath(webResources, relativePath, fileDetails.path, fileDetails.file) + } + } + catch (Exception ignore) { + } + } + }) + }) + + warModel.webResources = webResources + warModel.classpath = warTask.classpath.files + + Manifest manifest = warTask.manifest + if (manifest != null) { + def writer = new StringWriter() + manifest.writeTo(writer) + warModel.manifestContent = writer.toString() + } + warModels.add(warModel) + } + } + + new WebConfigurationImpl(warModels) + } + + @NotNull + @Override + public ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { + ErrorMessageBuilder.create( + project, e, "Web project import errors" + ).withDescription("Web Facets/Artifacts will not be configured") + } + + private static addPath(List<WebConfiguration.WebResource> webResources, String warRelativePath, String fileRelativePath, File file) { + warRelativePath = warRelativePath == null ? "" : warRelativePath + + WebConfiguration.WebResource webResource = new WebResourceImpl(warRelativePath, fileRelativePath, file) + webResources.add(webResource) + } +} diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.java b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.java deleted file mode 100644 index 62e02eeffc17..000000000000 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.java +++ /dev/null @@ -1,140 +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.tooling.builder; - -import org.gradle.api.Action; -import org.gradle.api.Project; -import org.gradle.api.Task; -import org.gradle.api.file.FileVisitDetails; -import org.gradle.api.file.FileVisitor; -import org.gradle.api.internal.file.copy.CopySpecInternal; -import org.gradle.api.java.archives.Manifest; -import org.gradle.api.plugins.WarPlugin; -import org.gradle.api.tasks.bundling.War; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.plugins.gradle.model.web.WebConfiguration; -import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder; -import org.jetbrains.plugins.gradle.tooling.ModelBuilderService; -import org.jetbrains.plugins.gradle.tooling.internal.web.WarModelImpl; -import org.jetbrains.plugins.gradle.tooling.internal.web.WebConfigurationImpl; -import org.jetbrains.plugins.gradle.tooling.internal.web.WebResourceImpl; - -import java.io.File; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.List; - -/** - * @author Vladislav.Soroka - * @since 11/5/13 - */ -public class WarModelBuilderImpl implements ModelBuilderService { - - private static final String WEB_APP_DIR_PROPERTY = "webAppDir"; - private static final String WEB_APP_DIR_NAME_PROPERTY = "webAppDirName"; - - @Override - public boolean canBuild(String modelName) { - return WebConfiguration.class.getName().equals(modelName); - } - - @Nullable - @Override - public Object buildAll(String modelName, Project project) { - final WarPlugin warPlugin = project.getPlugins().findPlugin(WarPlugin.class); - if (warPlugin == null) return null; - - final String webAppDirName = !project.hasProperty(WEB_APP_DIR_NAME_PROPERTY) ? - "src/main/webapp" : String.valueOf(project.property(WEB_APP_DIR_NAME_PROPERTY)); - - final File webAppDir = !project.hasProperty(WEB_APP_DIR_PROPERTY) - ? new File(project.getProjectDir(), webAppDirName) - : (File)project.property(WEB_APP_DIR_PROPERTY); - - - List<WebConfiguration.WarModel> warModels = new ArrayList<WebConfiguration.WarModel>(); - - - for (Task task : project.getTasks()) { - if (task instanceof War) { - final WarModelImpl warModel = - new WarModelImpl(((War)task).getArchiveName(), webAppDirName, webAppDir); - final List<WebConfiguration.WebResource> webResources = new ArrayList<WebConfiguration.WebResource>(); - - final War warTask = (War)task; - warModel.setWebXml(warTask.getWebXml()); - - warTask.getRootSpec().walk(new Action<CopySpecInternal>() { - @Override - public void execute(CopySpecInternal internal) { - final String relativePath = internal.getDestPath().getPathString(); - internal.getSource().visit(new FileVisitor() { - @Override - public void visitDir(FileVisitDetails dirDetails) { - try { - addPath(webResources, relativePath, dirDetails.getPath(), dirDetails.getFile()); - } - catch (Exception ignore) { - } - } - - @Override - public void visitFile(FileVisitDetails fileDetails) { - try { - if (warTask.getWebXml() == null || - !fileDetails.getFile().getCanonicalPath().equals(warTask.getWebXml().getCanonicalPath())) { - addPath(webResources, relativePath, fileDetails.getPath(), fileDetails.getFile()); - } - } - catch (Exception ignore) { - } - } - }); - } - }); - - warModel.setWebResources(webResources); - warModel.setClasspath(warTask.getClasspath().getFiles()); - - Manifest manifest = warTask.getManifest(); - if (manifest != null) { - StringWriter writer = new StringWriter(); - manifest.writeTo(writer); - warModel.setManifestContent(writer.toString()); - } - warModels.add(warModel); - } - } - - return new WebConfigurationImpl(warModels); - } - - @NotNull - @Override - public ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { - return ErrorMessageBuilder.create( - project, e, "Web project import errors" - ).withDescription("Web Facets/Artifacts will not be configured"); - } - - private static void addPath(List<WebConfiguration.WebResource> webResources, String warRelativePath, String fileRelativePath, File file) { - warRelativePath = warRelativePath == null ? "" : warRelativePath; - - WebConfiguration.WebResource webResource = new WebResourceImpl(warRelativePath, fileRelativePath, file); - webResources.add(webResource); - } -} diff --git a/plugins/gradle/tooling-extension-impl/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle b/plugins/gradle/tooling-extension-impl/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle index 83fcd7abb38a..93e11920b30f 100644 --- a/plugins/gradle/tooling-extension-impl/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle +++ b/plugins/gradle/tooling-extension-impl/testData/testGradleIdeaPluginPlusScopesDependenciesModel/build.gradle @@ -20,7 +20,7 @@ allprojects { idea { module { - scopes.PROVIDED.plus += configurations.provided + scopes.PROVIDED.plus += [configurations.provided] } } } diff --git a/plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java b/plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java index e1bb31ddbb39..e25eb17c5d4e 100644 --- a/plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java +++ b/plugins/gradle/tooling-extension-impl/testSources/org/jetbrains/plugins/gradle/tooling/builder/AbstractModelBuilderTest.java @@ -59,6 +59,7 @@ public abstract class AbstractModelBuilderTest { public static final String GRADLE_v1_10 = "1.10"; public static final String GRADLE_v1_11 = "1.11"; public static final String GRADLE_v1_12 = "1.12"; + public static final String GRADLE_v2_0 = "2.0-rc-2"; public static final Pattern TEST_METHOD_NAME_PATTERN = Pattern.compile("(.*)\\[(\\d*)\\]"); private static final int DEFAULT_DAEMON_MAX_IDLE_TIME = 5; @@ -79,10 +80,11 @@ public abstract class AbstractModelBuilderTest { @Parameterized.Parameters public static Collection<Object[]> data() { Object[][] data = { - {AbstractModelBuilderTest.GRADLE_v1_9}, - {AbstractModelBuilderTest.GRADLE_v1_10}, - {AbstractModelBuilderTest.GRADLE_v1_11}, - {AbstractModelBuilderTest.GRADLE_v1_12} + {GRADLE_v1_9}, + {GRADLE_v1_10}, + {GRADLE_v1_11}, + {GRADLE_v1_12}, + {GRADLE_v2_0} }; return Arrays.asList(data); } |