Skip to content

Commit 3e5e434

Browse files
committed
[MSHADE-406] More tests pass.
1 parent c01f486 commit 3e5e434

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@
340340
<setupInclude>setup/*/pom.xml</setupInclude>
341341
</setupIncludes>
342342
<pomIncludes>
343+
<!-- FIXME: Revert back to all tests -->
343344
<pomInclude>projects/*/pom.xml</pomInclude>
345+
<!-- <pomInclude>projects/MSHADE-391_noRelocationKeepOriginalClasses/pom.xml</pomInclude>-->
346+
<!-- <pomInclude>projects/MultiReleaseJar-*/pom.xml</pomInclude>-->
347+
<!-- <pomInclude>projects/MultiReleaseJar-shade-relocate/pom.xml</pomInclude> -->
344348
</pomIncludes>
345349
<projectsDirectory>src/it</projectsDirectory>
346350
<settingsFile>src/it/mrm/settings.xml</settingsFile>

src/main/java/org/apache/maven/plugins/shade/DefaultShader.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.objectweb.asm.commons.Remapper;
7171
import org.slf4j.Logger;
7272
import org.slf4j.LoggerFactory;
73+
import org.vafer.jdependency.Clazz;
7374

7475
/**
7576
* @author Jason van Zyl
@@ -593,8 +594,14 @@ private void addRemappedClass(
593594
renamedClass = originalClass;
594595
}
595596

596-
// Need to take the .class off for remapping evaluation
597-
String mappedName = packageMapper.map(name.substring(0, name.indexOf('.')), true, false);
597+
String mappedName;
598+
if (Clazz.isMultiReleaseClassFile(name)) {
599+
mappedName = packageMapper.map(name, true, false); // .substring(0, name.indexOf('.'));
600+
} else {
601+
// Need to take the .class off for remapping evaluation
602+
mappedName = packageMapper.map(name.substring(0, name.indexOf('.')), true, false);
603+
}
604+
logger.debug("Rewrote class bytecode: >> TO MAPPED NAME: {}", mappedName);
598605

599606
try {
600607
// Now we put it back on so the class file is written out with the right extension.
@@ -728,11 +735,19 @@ public String map(String entityName, boolean mapPaths, final boolean mapPackages
728735
String prefix = "";
729736
String suffix = "";
730737

731-
Matcher m = CLASS_PATTERN.matcher(entityName);
732-
if (m.matches()) {
733-
prefix = m.group(1) + "L";
734-
suffix = ";";
735-
entityName = m.group(2);
738+
boolean isMultiReleaseClassFile = Clazz.isMultiReleaseClassFile(entityName);
739+
740+
if (isMultiReleaseClassFile) {
741+
Clazz.ParsedFileName parsedFileName = Clazz.parseClassFileName(entityName);
742+
prefix = "META-INF/versions/" + parsedFileName.forJava + "/";
743+
entityName = parsedFileName.className.replace(".", "/");
744+
} else {
745+
Matcher m = CLASS_PATTERN.matcher(entityName);
746+
if (m.matches()) {
747+
prefix = m.group(1) + "L";
748+
suffix = ";";
749+
entityName = m.group(2);
750+
}
736751
}
737752

738753
for (Relocator r : relocators) {
@@ -744,6 +759,7 @@ public String map(String entityName, boolean mapPaths, final boolean mapPackages
744759
break;
745760
}
746761
}
762+
747763
return value;
748764
}
749765
}

src/main/java/org/apache/maven/plugins/shade/relocation/SimpleRelocator.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ public boolean canRelocatePath(String path) {
182182

183183
if (path.endsWith(".class")) {
184184
Clazz.ParsedFileName parsedFileName = Clazz.parseClassFileName(path);
185-
path = parsedFileName.className.replace(".", "/");
185+
if (parsedFileName != null && parsedFileName.className != null) {
186+
path = parsedFileName.className.replace(".", "/");
187+
}
186188
}
187189

188190
// Allow for annoying option of an extra / on the front of a path. See MSHADE-119; comes from

0 commit comments

Comments
 (0)