-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repackages java class deps with jarjar links
- applies jarjar links during source-deps phase - after munging clj sources jar all class files into one jar - apply jarjar links on this jar file - remove directories from target/srcdeps containing class files - unzip jarjar links output jar file into target/srcdeps - repackage prefix is generated from projectname and project version - util fn to figure out where to find java class files. - some jarjar helpers inlined so they are accessible properly - main processor is stripped so it only does packag remapping - cleans up logging msgs - gets rid of eval-in - jumps to 0.4.0 - updates readme - prefixing in transient deps - takes care of class references in namespace body - cleans up - args handling - readme - uses the latest mranderson
- Loading branch information
1 parent
b4ba165
commit 6332fef
Showing
8 changed files
with
554 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* Copied from Jar Jar Links 1.4 | ||
* | ||
* Original licence | ||
* | ||
* Copyright 2007 Google Inc. | ||
* | ||
* 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 mranderson.util; | ||
|
||
import com.tonicsystems.jarjar.*; | ||
import com.tonicsystems.jarjar.ext_util.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
public class JjMainProcessor implements JarProcessor | ||
{ | ||
private final boolean verbose; | ||
private final JarProcessorChain chain; | ||
private final Map<String, String> renames = new HashMap<String, String>(); | ||
|
||
public JjMainProcessor(List<PatternElement> patterns, boolean verbose, boolean skipManifest) { | ||
this.verbose = verbose; | ||
List<Rule> ruleList = new ArrayList<Rule>(); | ||
for (PatternElement pattern : patterns) { | ||
if (pattern instanceof Rule) { | ||
ruleList.add((Rule) pattern); | ||
} | ||
} | ||
|
||
JjPackageRemapper pr = new JjPackageRemapper(ruleList, verbose); | ||
|
||
List<JarProcessor> processors = new ArrayList<JarProcessor>(); | ||
processors.add(new JarTransformerChain(new RemappingClassTransformer[]{ new RemappingClassTransformer(pr) })); | ||
chain = new JarProcessorChain(processors.toArray(new JarProcessor[processors.size()])); | ||
} | ||
|
||
public void strip(File file) throws IOException { | ||
return; | ||
} | ||
|
||
/** | ||
* Returns the <code>.class</code> files to delete. As well the root-parameter as the rename ones | ||
* are taken in consideration, so that the concerned files are not listed in the result. | ||
* | ||
* @return the paths of the files in the jar-archive, including the <code>.class</code> suffix | ||
*/ | ||
private Set<String> getExcludes() { | ||
return new HashSet<String>(); | ||
} | ||
|
||
/** | ||
* | ||
* @param struct | ||
* @return <code>true</code> if the entry is to include in the output jar | ||
* @throws IOException | ||
*/ | ||
public boolean process(EntryStruct struct) throws IOException { | ||
String name = struct.name; | ||
boolean keepIt = chain.process(struct); | ||
if (keepIt) { | ||
if (!name.equals(struct.name)) { | ||
if (verbose) | ||
System.err.println("Renamed " + name + " -> " + struct.name); | ||
} | ||
} else { | ||
if (verbose) | ||
System.err.println("Removed " + name); | ||
} | ||
return keepIt; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/** | ||
* Copied from Jar Jar Links 1.4 | ||
* | ||
* Original licence | ||
* | ||
* Copyright 2007 Google Inc. | ||
* | ||
* 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 mranderson.util; | ||
|
||
import com.tonicsystems.jarjar.*; | ||
import com.tonicsystems.jarjar.asm.*; | ||
import com.tonicsystems.jarjar.asm.commons.*; | ||
import java.util.*; | ||
import java.util.regex.Pattern; | ||
|
||
public class JjPackageRemapper extends Remapper | ||
{ | ||
private static final String RESOURCE_SUFFIX = "RESOURCE"; | ||
|
||
private static final Pattern ARRAY_FOR_NAME_PATTERN | ||
= Pattern.compile("\\[L[\\p{javaJavaIdentifierPart}\\.]+?;"); | ||
|
||
private final List<JjWildcard> wildcards; | ||
private final Map<String, String> typeCache = new HashMap<String, String>(); | ||
private final Map<String, String> pathCache = new HashMap<String, String>(); | ||
private final Map<Object, String> valueCache = new HashMap<Object, String>(); | ||
private final boolean verbose; | ||
|
||
private static List<JjWildcard> createWildcards(List<? extends PatternElement> patterns) { | ||
List<JjWildcard> wildcards = new ArrayList<JjWildcard>(); | ||
for (PatternElement pattern : patterns) { | ||
String result = (pattern instanceof Rule) ? ((Rule)pattern).getResult() : ""; | ||
String expr = pattern.getPattern(); | ||
if (expr.indexOf('/') >= 0) | ||
throw new IllegalArgumentException("Patterns cannot contain slashes"); | ||
wildcards.add(new JjWildcard(expr.replace('.', '/'), result)); | ||
} | ||
return wildcards; | ||
} | ||
|
||
public JjPackageRemapper(List<Rule> ruleList, boolean verbose) { | ||
this.verbose = verbose; | ||
wildcards = createWildcards(ruleList); | ||
} | ||
|
||
// also used by KeepProcessor | ||
static boolean isArrayForName(String value) { | ||
return ARRAY_FOR_NAME_PATTERN.matcher(value).matches(); | ||
} | ||
|
||
public String map(String key) { | ||
String s = typeCache.get(key); | ||
if (s == null) { | ||
s = replaceHelper(key); | ||
if (key.equals(s)) | ||
s = null; | ||
typeCache.put(key, s); | ||
} | ||
return s; | ||
} | ||
|
||
public String mapPath(String path) { | ||
String s = pathCache.get(path); | ||
if (s == null) { | ||
s = path; | ||
int slash = s.lastIndexOf('/'); | ||
String end; | ||
if (slash < 0) { | ||
end = s; | ||
s = RESOURCE_SUFFIX; | ||
} else { | ||
end = s.substring(slash + 1); | ||
s = s.substring(0, slash + 1) + RESOURCE_SUFFIX; | ||
} | ||
boolean absolute = s.startsWith("/"); | ||
if (absolute) s = s.substring(1); | ||
|
||
s = replaceHelper(s); | ||
|
||
if (absolute) s = "/" + s; | ||
if (s.indexOf(RESOURCE_SUFFIX) < 0) | ||
return path; | ||
s = s.substring(0, s.length() - RESOURCE_SUFFIX.length()) + end; | ||
pathCache.put(path, s); | ||
} | ||
return s; | ||
} | ||
|
||
public Object mapValue(Object value) { | ||
if (value instanceof String) { | ||
String s = valueCache.get(value); | ||
if (s == null) { | ||
s = (String)value; | ||
if (isArrayForName(s)) { | ||
String desc1 = s.replace('.', '/'); | ||
String desc2 = mapDesc(desc1); | ||
if (!desc2.equals(desc1)) | ||
return desc2.replace('/', '.'); | ||
} else { | ||
s = mapPath(s); | ||
if (s.equals(value)) { | ||
boolean hasDot = s.indexOf('.') >= 0; | ||
boolean hasSlash = s.indexOf('/') >= 0; | ||
if (!(hasDot && hasSlash)) { | ||
if (hasDot) { | ||
s = replaceHelper(s.replace('.', '/')).replace('/', '.'); | ||
} else { | ||
s = replaceHelper(s); | ||
} | ||
} | ||
} | ||
} | ||
valueCache.put(value, s); | ||
} | ||
// TODO: add back class name to verbose message | ||
if (verbose && !s.equals(value)) | ||
System.err.println("Changed \"" + value + "\" -> \"" + s + "\""); | ||
return s; | ||
} else { | ||
return super.mapValue(value); | ||
} | ||
} | ||
|
||
private String replaceHelper(String value) { | ||
for (JjWildcard wildcard : wildcards) { | ||
String test = wildcard.replace(value); | ||
if (test != null) | ||
return test; | ||
} | ||
return value; | ||
} | ||
} |
Oops, something went wrong.