Skip to content

Add support for multi-release jars #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public abstract class MisplacedClassProcessor implements JarProcessor {
struct.skipTransform = true;
return true;
}
if (!originalClassName.equals(struct.name)) {
if (!originalClassName.equals(struct.getClassName())) {
System.err.println(formatMisplacedClassMessage(struct, originalClassName));
handleMisplacedClass(struct, originalClassName);
if (!shouldTransform()) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/github/johnynek/jarjar/util/EntryStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,30 @@

package com.github.johnynek.jarjar.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EntryStruct {
private static final Pattern NAME_PARTS_PATTERN = Pattern.compile("((?:META-INF/versions/[1-9][0-9]*/)?)(.*)");

public byte[] data;
public String name;
public long time;
public boolean skipTransform;

/**
* Returns a version path prefix such as "META-INF/versions/9/" if the entry is a versioned
* entry in a multi-release JAR, or an empty string otherise.
*/
public String getVersionPrefix() {
Matcher matcher = NAME_PARTS_PATTERN.matcher(name);
matcher.matches();
return matcher.group(1);
}

public String getClassName() {
Matcher matcher = NAME_PARTS_PATTERN.matcher(name);
matcher.matches();
return matcher.group(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean process(EntryStruct struct) throws IOException {
throw new IOException("Unable to transform " + struct.name, e);
}
struct.data = w.toByteArray();
struct.name = pathFromName(w.getClassName());
struct.name = struct.getVersionPrefix() + pathFromName(w.getClassName());
}
return true;
}
Expand Down