From c3702d4cbfa891b65a05b127d3140941c3cea0b8 Mon Sep 17 00:00:00 2001 From: John Engelman Date: Thu, 11 Apr 2013 17:24:48 -0500 Subject: [PATCH] closes Issue #14 - fix bad method call to BAOS.write --- README.md | 2 +- gradle.properties | 2 +- it/appending-transformer/build.gradle | 13 +++++++ .../maven/its/shade/at/one/0.1/one-0.1.jar | Bin 0 -> 2275 bytes .../maven/its/shade/at/one/0.1/one-0.1.pom | 36 ++++++++++++++++++ .../maven/its/shade/at/one/maven-metadata.xml | 12 ++++++ .../maven/its/shade/at/two/0.1/two-0.1.jar | Bin 0 -> 2278 bytes .../maven/its/shade/at/two/0.1/two-0.1.pom | 36 ++++++++++++++++++ .../maven/its/shade/at/two/maven-metadata.xml | 12 ++++++ it/appending-transformer/verify.groovy | 23 +++++++++++ .../build.gradle | 2 +- it/settings.gradle | 28 +++++++------- .../plugins/shadow/ShadowTaskExtension.groovy | 6 ++- .../api/plugins/shadow/filter/Filter.groovy | 2 + .../plugins/shadow/impl/DefaultCaster.groovy | 11 ++---- .../transformers/AppendingTransformer.groovy | 2 +- 16 files changed, 160 insertions(+), 27 deletions(-) create mode 100644 it/appending-transformer/build.gradle create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.jar create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.pom create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/one/maven-metadata.xml create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.jar create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.pom create mode 100644 it/appending-transformer/repo/org/apache/maven/its/shade/at/two/maven-metadata.xml create mode 100644 it/appending-transformer/verify.groovy diff --git a/README.md b/README.md index 73c1646e0..aab457224 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ How to use } } dependencies { - classpath 'org.gradle.plugins:shadow:0.7.2' + classpath 'org.gradle.plugins:shadow:0.7.3' } } diff --git a/gradle.properties b/gradle.properties index d9c015fb3..718c30dd8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -currentVersion=0.7.2 +currentVersion=0.7.3 bintray_repo=gradle-plugins bintray_package=org.gradle.plugins:shadow diff --git a/it/appending-transformer/build.gradle b/it/appending-transformer/build.gradle new file mode 100644 index 000000000..b79a0cdfa --- /dev/null +++ b/it/appending-transformer/build.gradle @@ -0,0 +1,13 @@ +import org.gradle.api.plugins.shadow.transformers.AppendingTransformer + +dependencies { + compile 'org.apache.maven.its.shade.at:one:0.1' + compile 'org.apache.maven.its.shade.at:two:0.1' +} + +shadow { + artifactAttached = false + transformer(AppendingTransformer) { + resource = 'META-INF/services/org.apache.maven.Shade' + } +} diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.jar b/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.jar new file mode 100644 index 0000000000000000000000000000000000000000..54608dbc657f45a4e9406e5dd47147edb6b1bc7b GIT binary patch literal 2275 zcmWIWW@h1H0D+W_QX4P>N^k;cU)K;vT~9wZ{Q#&k4u)i)vX=eNc{700^*}6wtjyQZ z&(qB{I7H9a?X&Nh(>~t1dKY=Ub+yi&Ilno`;EM5sr$stm=T7K&>pF3;KUoqsMNIpE zO2y7O-9f_MLBS<+wbqKra0^W~4ic>qJ{|NKDC1>Z>~-Lg-^$9!&Yd#@Hj2cqpOQ0y zby*eLN4K^;F?(VdU@l_-yA0?UI1mD|;2tPWEh@`QPAx|BNpq?0Ej^$*10dGGsy@Fc zT`#d9F*zeuFE_C)HBT=%BQYiQ^m*^lfUpmr`3tuOeK;L{!dv(JNfxfDOT?b0JyV^w zL`-{1N{X0v1IyRTM#Vvl2sfe!GC#7NVDsS)#EcP;L*X8RD8_JIW=XMLG025_#YH7} z%rYX`to*!GxOp55A?>9$_P+!c&tzg?SjWP^U`dvF1^Kyp6}dU3A<_A>4MghPAKA}Y zXuBn-q2$)#ErF}nSqC!4`{Iu75l>qx|2>^=ohP zwU}JUvMFP$IlIx2Ws1X9-=i~6tSn0@ec}IN-Z8PFREgBh^H@%N&6F}o{>ykn;&Kho z;dQT>t}*j2(K>9q@k8I1m?hio8n^!BU*xpb@nQco?Mo$FnXd^#kjwJYiIgY!$`&rmd_$7MFEij`w`T2+S z*8+dUtF-)5_>vFHxE$cp@f7#0nUJ1kwWT*FnqWpr?qLR$iV$m}jxegf!G(7yP z@V?-}-yIKL8#y8qZ|qnOramZeEo8zXw< zC0{#Ew)z1qiWr$hm~of*KyLwo0K;2H5DhPF5ZbWU03gL6u%uBPNW!%t)dvU@u$RUs+iXzTjWGKj$!0@Ja+vwp%W{|vOB(fnB|JPriK=x#=0i(%MEGLQLI`W* cSjn{pk)Z;-S=m4)asuI9ptC;!&17Hz00yM(k^lez literal 0 HcmV?d00001 diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.pom b/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.pom new file mode 100644 index 000000000..9afd94c00 --- /dev/null +++ b/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/0.1/one-0.1.pom @@ -0,0 +1,36 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.at + one + 0.1 + jar + + + + maven-core-it + file:///${basedir}/repo + + + diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/maven-metadata.xml b/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/maven-metadata.xml new file mode 100644 index 000000000..e5df2f10f --- /dev/null +++ b/it/appending-transformer/repo/org/apache/maven/its/shade/at/one/maven-metadata.xml @@ -0,0 +1,12 @@ + + + org.apache.maven.its.shade.at + one + 0.1 + + + 0.1 + + 20100321160306 + + diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.jar b/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.jar new file mode 100644 index 0000000000000000000000000000000000000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={%>Fe&5Bg(2aKsq7Hv}dtP+0J!|-Wr`sA_xdm@z{#~`=`rq9WAm8$j z7goM-fD1^T=+j$DfC;@4h#kmI@C8Nr1*t_PnW@F1XEt&jG7xBZXgi_Y;ziw)TaFqf zLKFG?elevNZsa1)S< zZiEZ472YrtmNb6Esvo1M1Q+G_Tm>qeApqp6bVejs!HQ~_ldu=o2+dP4HDkC3z39em zHmLAMnEilcvmr$}%zW&HIn0J7jRwFX9v&SKj}ve^$b4wgjtF1uSqNc`A}hJpATm^d UH!B;+L{1>Q3v~8ppqUH|0Pg+lVgLXD literal 0 HcmV?d00001 diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.pom b/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.pom new file mode 100644 index 000000000..699b60661 --- /dev/null +++ b/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/0.1/two-0.1.pom @@ -0,0 +1,36 @@ + + + + + + 4.0.0 + + org.apache.maven.its.shade.at + two + 0.1 + jar + + + + maven-core-it + file:///${basedir}/repo + + + diff --git a/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/maven-metadata.xml b/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/maven-metadata.xml new file mode 100644 index 000000000..ec6af2713 --- /dev/null +++ b/it/appending-transformer/repo/org/apache/maven/its/shade/at/two/maven-metadata.xml @@ -0,0 +1,12 @@ + + + org.apache.maven.its.shade.at + two + 0.1 + + + 0.1 + + 20100321160331 + + diff --git a/it/appending-transformer/verify.groovy b/it/appending-transformer/verify.groovy new file mode 100644 index 000000000..f034e9ea6 --- /dev/null +++ b/it/appending-transformer/verify.groovy @@ -0,0 +1,23 @@ +{ project -> + + def jar = file("${buildDir}/libs/${project.name}-${currentVersion}.jar") + + assert jar.exists() + + def jarFile = zipTree(jar) + + def shadeService = jarFile.matching { + include { fileTreeElement -> + fileTreeElement.relativePath.toString() == 'META-INF/services/org.apache.maven.Shade' + } + }.files as List + + assert shadeService.size() == 1 + + def serviceText = shadeService[0].text + def providers = serviceText.split('(\r\n)|(\r)|(\n)') + assert providers.size() == 2 + assert providers[0] == 'one # NOTE: No newline terminates this line/file' + assert providers[1] == 'two # NOTE: No newline terminates this line/file' + +} diff --git a/it/filter-artifact-contents-shortcut/build.gradle b/it/filter-artifact-contents-shortcut/build.gradle index 5729d487c..c679293d5 100644 --- a/it/filter-artifact-contents-shortcut/build.gradle +++ b/it/filter-artifact-contents-shortcut/build.gradle @@ -12,7 +12,7 @@ shadow { exclude 'org/apache/*' exclude 'org/apache/maven/b/' } - include 'META-INF/MANIFEST.MF' +// include 'META-INF/MANIFEST.MF' exclude 'org/*' exclude 'META-INF/**/' } diff --git a/it/settings.gradle b/it/settings.gradle index 96356fe74..fc12e95fa 100644 --- a/it/settings.gradle +++ b/it/settings.gradle @@ -1,14 +1,14 @@ -include 'archivesBaseName' -include 'archivesBaseName-attached' -include 'artifact-includes-excludes' -include 'artifact-includes-excludes-shortcut' -include 'baseName' -include 'baseName-attached' -include 'filter-artifact-contents' -include 'implicit-inclusion-of-project-artifact' -include 'manifest-retained' -include 'manifest-transformed' -include 'non-runtime-scope-excluded' -include 'pom-packaging' -include 'services-resource-transformer' -include 'xml-transformer-ignores-dtd' \ No newline at end of file +import groovy.io.FileType + +def path = [] as LinkedList +rootDir.traverse( + type: FileType.FILES, + nameFilter: ~/.+\.gradle/, + maxDepth: 3, + preDir: { path << it.name }, + postDir: { path.removeLast() } +) { + if (path) { + include path.join(':') + } +} diff --git a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/ShadowTaskExtension.groovy b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/ShadowTaskExtension.groovy index 1eed76958..64eb490aa 100644 --- a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/ShadowTaskExtension.groovy +++ b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/ShadowTaskExtension.groovy @@ -65,11 +65,13 @@ class ShadowTaskExtension { ShadowTaskExtension filter(String artifact, Closure c) { if (!artifact) throw new GradleException('Must specify artifact for filter!') - ArchiveFilter filter = new ArchiveFilter(artifact: artifact) + ArchiveFilter filter = filters.find { it.artifact == artifact } ?: new ArchiveFilter(artifact: artifact) c.delegate = filter c.resolveStrategy = Closure.DELEGATE_ONLY c() - filters << filter + if (!filters.contains(filter)) { + filters << filter + } this } diff --git a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/filter/Filter.groovy b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/filter/Filter.groovy index a706edd3e..c4ae500b5 100644 --- a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/filter/Filter.groovy +++ b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/filter/Filter.groovy @@ -32,5 +32,7 @@ interface Filter { boolean isFiltered(String classFile) + boolean isSpecificallyIncluded(String classFile) + void finished() } diff --git a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/impl/DefaultCaster.groovy b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/impl/DefaultCaster.groovy index 10994cf40..c0bb312ff 100644 --- a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/impl/DefaultCaster.groovy +++ b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/impl/DefaultCaster.groovy @@ -246,13 +246,10 @@ class DefaultCaster implements Caster { } private boolean isFiltered(List filters, String name) { - for (Filter filter : filters) { - if (filter.isFiltered(name)) { - return true - } - } - - return false +// if (filters.any { it.isSpecificallyIncluded(name)}) { +// return false +// } + return filters.any { it.isFiltered(name) } } private boolean resourceTransformed(List resourceTransformers, String name, InputStream is, diff --git a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/transformers/AppendingTransformer.groovy b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/transformers/AppendingTransformer.groovy index 5acac08f7..3c5c628ef 100644 --- a/shadow/src/main/groovy/org/gradle/api/plugins/shadow/transformers/AppendingTransformer.groovy +++ b/shadow/src/main/groovy/org/gradle/api/plugins/shadow/transformers/AppendingTransformer.groovy @@ -48,7 +48,7 @@ class AppendingTransformer implements Transformer { void transform(String path, InputStream is, List relocators) { IOUtil.copy(is, data) - data.write('\n') + data.write('\n'.bytes) is.close() }