Skip to content

Commit 5eaf09f

Browse files
committed
add maven shade transformer to relocate package names in clojure sources
1 parent 263fade commit 5eaf09f

File tree

4 files changed

+141
-2
lines changed

4 files changed

+141
-2
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@
128128
</prerequisites>
129129

130130
<modules>
131+
<module>storm-buildtools/maven-shade-clojure-transformer</module>
131132
<module>storm-core</module>
132133
</modules>
133134

@@ -151,6 +152,7 @@
151152
<compojure.version>1.1.3</compojure.version>
152153
<hiccup.version>0.3.6</hiccup.version>
153154
<commons-io.verson>1.4</commons-io.verson>
155+
<commons-lang.version>2.5</commons-lang.version>
154156
<commons-exec.version>1.1</commons-exec.version>
155157
<clj-time.version>0.4.1</clj-time.version>
156158
<curator.version>1.0.1</curator.version>
@@ -272,6 +274,11 @@
272274
<artifactId>commons-exec</artifactId>
273275
<version>${commons-exec.version}</version>
274276
</dependency>
277+
<dependency>
278+
<groupId>commons-lang</groupId>
279+
<artifactId>commons-lang</artifactId>
280+
<version>${commons-lang.version}</version>
281+
</dependency>
275282
<dependency>
276283
<groupId>clj-time</groupId>
277284
<artifactId>clj-time</artifactId>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<parent>
24+
<artifactId>storm</artifactId>
25+
<groupId>org.apache.storm</groupId>
26+
<version>0.9.2-incubating-SNAPSHOT</version>
27+
<relativePath>../../pom.xml</relativePath>
28+
</parent>
29+
30+
<groupId>org.apache.storm</groupId>
31+
<artifactId>maven-shade-clojure-transformer</artifactId>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.maven.plugins</groupId>
36+
<artifactId>maven-shade-plugin</artifactId>
37+
<version>2.2</version>
38+
<scope>provided</scope>
39+
</dependency>
40+
</dependencies>
41+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.storm.maven.shade.clojure;
19+
20+
import org.apache.maven.plugins.shade.relocation.Relocator;
21+
import org.apache.maven.plugins.shade.resource.ResourceTransformer;
22+
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.HashMap;
27+
import java.util.List;
28+
import java.util.jar.JarEntry;
29+
import java.util.jar.JarOutputStream;
30+
31+
32+
public class ClojureTransformer implements ResourceTransformer {
33+
34+
private HashMap<String, String> entries = new HashMap<String, String>();
35+
36+
@Override
37+
public boolean canTransformResource(String s) {
38+
if(s.endsWith(".clj")){
39+
return true;
40+
}
41+
return false;
42+
}
43+
44+
@Override
45+
public void processResource(String s, InputStream inputStream, List<Relocator> relocators) throws IOException {
46+
47+
ByteArrayOutputStream out = new ByteArrayOutputStream();
48+
int b;
49+
while((b = inputStream.read()) != -1){
50+
out.write(b);
51+
}
52+
String data = out.toString();
53+
54+
for(Relocator rel : relocators){
55+
data = rel.applyToSourceContent(data);
56+
}
57+
this.entries.put(s, data);
58+
}
59+
60+
@Override
61+
public boolean hasTransformedResource() {
62+
return true;
63+
}
64+
65+
@Override
66+
public void modifyOutputStream(JarOutputStream jarOut) throws IOException {
67+
for(String key : this.entries.keySet()){
68+
jarOut.putNextEntry(new JarEntry(key));
69+
jarOut.write(this.entries.get(key).getBytes());
70+
}
71+
}
72+
}

storm-core/pom.xml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@
8686
<groupId>org.apache.commons</groupId>
8787
<artifactId>commons-exec</artifactId>
8888
</dependency>
89+
<dependency>
90+
<groupId>commons-lang</groupId>
91+
<artifactId>commons-lang</artifactId>
92+
</dependency>
8993
<dependency>
9094
<groupId>org.apache.thrift</groupId>
9195
<artifactId>libthrift</artifactId>
@@ -96,6 +100,10 @@
96100
<groupId>org.slf4j</groupId>
97101
<artifactId>slf4j-api</artifactId>
98102
</exclusion>
103+
<exclusion>
104+
<groupId>javax.servlet</groupId>
105+
<artifactId>servlet-api</artifactId>
106+
</exclusion>
99107
</exclusions>
100108
</dependency>
101109

@@ -223,12 +231,13 @@
223231
</executions>
224232
<configuration>
225233
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
226-
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
227-
<createDependencyReducedPom>true</createDependencyReducedPom>
228234
<promoteTransitiveDependencies>false</promoteTransitiveDependencies>
235+
<createDependencyReducedPom>true</createDependencyReducedPom>
236+
<minimizeJar>false</minimizeJar>
229237
<artifactSet>
230238
<includes>
231239
<include>org.apache.thrift:*</include>
240+
<include>odg.apache.storm:*</include>
232241
</includes>
233242
</artifactSet>
234243

@@ -238,6 +247,9 @@
238247
<shadedPattern>org.apache.thrift7</shadedPattern>
239248
</relocation>
240249
</relocations>
250+
<transformers>
251+
<transformer implementation="org.apache.storm.maven.shade.clojure.ClojureTransformer"/>
252+
</transformers>
241253
<filters>
242254
<filter>
243255
<artifact>*:*</artifact>
@@ -253,6 +265,13 @@
253265
</filter>
254266
</filters>
255267
</configuration>
268+
<dependencies>
269+
<dependency>
270+
<groupId>org.apache.storm</groupId>
271+
<artifactId>maven-shade-clojure-transformer</artifactId>
272+
<version>${project.version}</version>
273+
</dependency>
274+
</dependencies>
256275
</plugin>
257276

258277
</plugins>

0 commit comments

Comments
 (0)