From 84cd6169d78679ffbba25d78f1e55880ee87882b Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 25 Jun 2014 16:11:42 +0400 Subject: [PATCH] Gradle: fix compatibility with Gradle 2.0 --- .../lib/gradle-base-services-groovy-1.12.jar | Bin 0 -> 4913 bytes .../gradle-tooling-extension-api.iml | 1 + .../builder/WarModelBuilderImpl.groovy | 140 ++++++++++++++++++ .../tooling/builder/WarModelBuilderImpl.java | 140 ------------------ .../build.gradle | 2 +- .../builder/AbstractModelBuilderTest.java | 10 +- 6 files changed, 148 insertions(+), 145 deletions(-) create mode 100644 plugins/gradle/lib/gradle-base-services-groovy-1.12.jar create mode 100644 plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.groovy delete mode 100644 plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/WarModelBuilderImpl.java diff --git a/plugins/gradle/lib/gradle-base-services-groovy-1.12.jar b/plugins/gradle/lib/gradle-base-services-groovy-1.12.jar new file mode 100644 index 0000000000000000000000000000000000000000..511609f89d082ae0b49f91fe729cc1b36bec688e GIT binary patch literal 4913 zcmb7I2{@E%8y+bMlWizVNOs0Hqhn|6lQDJ)*)^1XtT7@>h_Z~GH1;(@mPnS=Sc_D4 z*^(_IvQ+fX{7#*duFn6TXRh~~cdqNX@AvuUd*A1I?oUsf{4f;&KuHOZG|y545bY4@ zLbPMVp`&gD1H+LTV&nk5pB#-^-xMek9gK+s^mj)c7!t0bZfGQ`qp_~j(~Zyui}nMx z!9smK&#Mi@2O)3gKK6j|@Lru>VYmnx)nbHw@@$@&VEqZ+g4sM@ace=85_xroa18|LKGBw6S+~_(xaTpIvR-oqlo0OtC-tL`J+*;?mGx-Qli2 zHqK7=Fgq_NH&<0>H?+5>gSwxcgFERrkA$e5vke-ZWY~=yRR$>}rrckOCcMAdEJ(*+ z>~3m;(-O#GFt~e@Ym*UmnL-BQxUAN4{sEhix4!rI?UJi5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pO8p@Cpi=)1uL(Ip)b9tt|Ceq* zxWYjZ_ty%RL}~YLR@iUS4)T-uzW>vt-f-VYw~spd3;%wnc#z^?r}&+uCM5HB6hHNi z2l+_&?;(+D!@iM1`b>PX2X1*kq#u>yAlJc4@tv(EM4IM*as5&^4w4@{+JBMH9{=|T WT~GT61&M)%_`wjL?VbPb#{U2*;L{=i literal 0 HcmV?d00001 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 e115edc96975..3cfcbe4d7383 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 @@ + 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 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 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 warModels = new ArrayList(); - - - for (Task task : project.getTasks()) { - if (task instanceof War) { - final WarModelImpl warModel = - new WarModelImpl(((War)task).getArchiveName(), webAppDirName, webAppDir); - final List webResources = new ArrayList(); - - final War warTask = (War)task; - warModel.setWebXml(warTask.getWebXml()); - - warTask.getRootSpec().walk(new Action() { - @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 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 b00e0f506524..15029f1bba0b 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 @@ -65,6 +65,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*)\\]"); @@ -84,10 +85,11 @@ public abstract class AbstractModelBuilderTest { @Parameterized.Parameters public static Collection 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); }