From 72afe354f3d84e0f215b393c9f5fdbb60df61c42 Mon Sep 17 00:00:00 2001 From: "Vladislav.Soroka" Date: Wed, 29 Jun 2016 15:57:59 +0300 Subject: [PATCH] IDEA-157986 Gradle: filtering in processResources using org.apache.tools.ant.filters.EscapeUnicode filter not working --- .../compiler/GradleResourceFilteringTest.java | 18 +++++++++++++++ .../builder/ExternalProjectBuilderImpl.groovy | 23 +++++++++++-------- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java index 0da7b2ea953b..005a60356120 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/compiler/GradleResourceFilteringTest.java @@ -215,6 +215,24 @@ public class GradleResourceFilteringTest extends GradleCompilingTestCase { assertCopied("build/resources/main/dir/file.txt", "some text myPropValue another text"); } + @Test + public void testEscapeUnicodeFilter() throws Exception { + createProjectSubFile( + "src/main/resources/dir/file.txt", "some text テキスト"); + importProject( + "apply plugin: 'java'\n" + + "\n" + + "import org.apache.tools.ant.filters.*\n" + + "processResources {\n" + + " filter (EscapeUnicode)\n" + + "}" + ); + assertModules("project", "project_main", "project_test"); + compileModules("project_main"); + + assertCopied("build/resources/main/dir/file.txt", "some text \\u30c6\\u30ad\\u30b9\\u30c8"); + } + @Test public void testFiltersChain() throws Exception { createProjectSubFile( diff --git a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalProjectBuilderImpl.groovy b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalProjectBuilderImpl.groovy index ed5056cb05cf..91efbcd0988c 100644 --- a/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalProjectBuilderImpl.groovy +++ b/plugins/gradle/tooling-extension-impl/src/org/jetbrains/plugins/gradle/tooling/builder/ExternalProjectBuilderImpl.groovy @@ -463,23 +463,26 @@ class ExternalProjectBuilderImpl implements ModelBuilderService { if(copyActions) { copyActions.each { Action action -> - if (action.hasProperty('val$filterType') && action.hasProperty('val$properties')) { + if (action.hasProperty('val$filterType')) { //noinspection GrUnresolvedAccess def filterType = (action?.val$filterType as Class).name def filter = [filterType: filterType] as DefaultExternalFilter - //noinspection GrUnresolvedAccess - def props = action?.val$properties - if (props) { - if ('org.apache.tools.ant.filters.ExpandProperties'.equals(filterType) && props['project']) { - if (props['project']) filter.propertiesAsJsonMap = new GsonBuilder().create().toJson(props['project'].properties); - } - else { - filter.propertiesAsJsonMap = new GsonBuilder().create().toJson(props); + + if(action.hasProperty('val$properties')) { + //noinspection GrUnresolvedAccess + def props = action?.val$properties + if (props) { + if ('org.apache.tools.ant.filters.ExpandProperties' == filterType && props['project']) { + if (props['project']) filter.propertiesAsJsonMap = new GsonBuilder().create().toJson(props['project'].properties); + } + else { + filter.propertiesAsJsonMap = new GsonBuilder().create().toJson(props); + } } } filterReaders << filter } - else if (action.class.simpleName.equals('RenamingCopyAction') && action.hasProperty('transformer')) { + else if (action.class.simpleName == 'RenamingCopyAction' && action.hasProperty('transformer')) { //noinspection GrUnresolvedAccess if (action.transformer.hasProperty('matcher') && action?.transformer?.hasProperty('replacement')) { //noinspection GrUnresolvedAccess