Skip to content

Commit 3036806

Browse files
committed
Merge branch 'release-0.3.5' into master-0.3.x
2 parents 24b088e + ae08b10 commit 3036806

File tree

6 files changed

+93
-13
lines changed

6 files changed

+93
-13
lines changed

bombe-asm/src/main/java/org/cadixdev/bombe/asm/jar/JarEntryRemappingTransformer.java

+32-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@
3030

3131
package org.cadixdev.bombe.asm.jar;
3232

33+
import static java.util.jar.Attributes.Name.MAIN_CLASS;
34+
3335
import org.cadixdev.bombe.jar.JarClassEntry;
3436
import org.cadixdev.bombe.jar.JarEntryTransformer;
3537
import org.cadixdev.bombe.jar.JarManifestEntry;
38+
import org.cadixdev.bombe.jar.JarResourceEntry;
3639
import org.cadixdev.bombe.jar.JarServiceProviderConfigurationEntry;
3740
import org.cadixdev.bombe.jar.ServiceProviderConfiguration;
3841
import org.objectweb.asm.ClassReader;
@@ -41,7 +44,9 @@
4144
import org.objectweb.asm.commons.ClassRemapper;
4245
import org.objectweb.asm.commons.Remapper;
4346

47+
import java.util.Iterator;
4448
import java.util.List;
49+
import java.util.Map;
4550
import java.util.function.BiFunction;
4651
import java.util.jar.Attributes;
4752
import java.util.stream.Collectors;
@@ -55,6 +60,8 @@
5560
*/
5661
public class JarEntryRemappingTransformer implements JarEntryTransformer {
5762

63+
private static final Attributes.Name SHA_256_DIGEST = new Attributes.Name("SHA-256-Digest");
64+
5865
private final Remapper remapper;
5966
private final BiFunction<ClassVisitor, Remapper, ClassRemapper> clsRemapper;
6067

@@ -86,14 +93,24 @@ public JarClassEntry transform(final JarClassEntry entry) {
8693
@Override
8794
public JarManifestEntry transform(final JarManifestEntry entry) {
8895
// Remap the Main-Class attribute, if present
89-
if (entry.getManifest().getMainAttributes().containsKey(new Attributes.Name("Main-Class"))) {
90-
final String mainClassObf = entry.getManifest().getMainAttributes().getValue("Main-Class")
96+
if (entry.getManifest().getMainAttributes().containsKey(MAIN_CLASS)) {
97+
final String mainClassObf = entry.getManifest().getMainAttributes().getValue(MAIN_CLASS)
9198
.replace('.', '/');
9299
final String mainClassDeobf = this.remapper.map(mainClassObf)
93100
.replace('/', '.');
94101

95-
// Since Manifest is mutable, we need'nt create a new entry \o/
96-
entry.getManifest().getMainAttributes().putValue("Main-Class", mainClassDeobf);
102+
// Since Manifest is mutable, we needn't create a new entry \o/
103+
entry.getManifest().getMainAttributes().put(MAIN_CLASS, mainClassDeobf);
104+
}
105+
106+
// Remove all signature entries
107+
for (final Iterator<Map.Entry<String, Attributes>> it = entry.getManifest().getEntries().entrySet().iterator(); it.hasNext();) {
108+
final Map.Entry<String, Attributes> section = it.next();
109+
if (section.getValue().remove(SHA_256_DIGEST) != null) {
110+
if (section.getValue().isEmpty()) {
111+
it.remove();
112+
}
113+
}
97114
}
98115

99116
return entry;
@@ -119,4 +136,15 @@ public JarServiceProviderConfigurationEntry transform(final JarServiceProviderCo
119136
return new JarServiceProviderConfigurationEntry(entry.getTime(), config);
120137
}
121138

139+
@Override
140+
public JarResourceEntry transform(final JarResourceEntry entry) {
141+
// Strip signature files from metadata
142+
if (entry.getName().startsWith("META-INF")) {
143+
if (entry.getExtension().equals("RSA")
144+
|| entry.getExtension().equals("SF")) {
145+
return null;
146+
}
147+
}
148+
return entry;
149+
}
122150
}

bombe/src/main/java/org/cadixdev/bombe/analysis/InheritanceProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public Map<MethodSignature, InheritanceType> getMethods() {
432432
@Override
433433
public Set<ClassInfo> provideParents(final InheritanceProvider provider) {
434434
if (this.parents == null) {
435-
ClassInfo.super.provideParents(provider, this.parents = new HashSet<>());
435+
super.provideParents(provider, this.parents = new HashSet<>());
436436
}
437437
return this.parents;
438438
}

bombe/src/main/java/org/cadixdev/bombe/jar/JarEntryTransformer.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030

3131
package org.cadixdev.bombe.jar;
3232

33+
import java.util.Collections;
34+
import java.util.List;
35+
3336
/**
3437
* A visitor for {@link AbstractJarEntry}, allowing them be be
3538
* transformed.
@@ -41,42 +44,64 @@ public interface JarEntryTransformer {
4144

4245
/**
4346
* Transforms the given class entry.
47+
* <p>
48+
* It is possible to remove entries by returning {@code null}, when this
49+
* occurs no further transformers will process the entry.
4450
*
4551
* @param entry The class entry
46-
* @return The transformed entry
52+
* @return The transformed entry, or {@code null} if the entry should be removed
4753
*/
4854
default JarClassEntry transform(final JarClassEntry entry) {
4955
return entry;
5056
}
5157

5258
/**
5359
* Transforms the given resource entry.
60+
* <p>
61+
* It is possible to remove entries by returning {@code null}, when this
62+
* occurs no further transformers will process the entry.
5463
*
5564
* @param entry The resource entry
56-
* @return The transformed entry
65+
* @return The transformed entry, or {@code null} if the entry should be removed
5766
*/
5867
default JarResourceEntry transform(final JarResourceEntry entry) {
5968
return entry;
6069
}
6170

6271
/**
6372
* Transforms the given manifest entry.
73+
* <p>
74+
* It is possible to remove entries by returning {@code null}, when this
75+
* occurs no further transformers will process the entry.
6476
*
6577
* @param entry The manifest entry
66-
* @return The transformed entry
78+
* @return The transformed entry, or {@code null} if the entry should be removed
6779
*/
6880
default JarManifestEntry transform(final JarManifestEntry entry) {
6981
return entry;
7082
}
7183

7284
/**
7385
* Transforms the given service provider configuration entry.
86+
* <p>
87+
* It is possible to remove entries by returning {@code null}, when this
88+
* occurs no further transformers will process the entry.
7489
*
7590
* @param entry The service provider configuration entry
76-
* @return The transformed entry
91+
* @return The transformed entry, or {@code null} if the entry should be removed
7792
*/
7893
default JarServiceProviderConfigurationEntry transform(final JarServiceProviderConfigurationEntry entry) {
7994
return entry;
8095
}
8196

97+
/**
98+
* Provides a list of {@link AbstractJarEntry jar entries} to add into the
99+
* processed jar file.
100+
*
101+
* @return Entries to add into the final jar
102+
*/
103+
default List<AbstractJarEntry> additions() {
104+
return Collections.emptyList();
105+
}
106+
82107
}

bombe/src/main/java/org/cadixdev/bombe/jar/Jars.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.io.InputStream;
3838
import java.nio.file.Files;
3939
import java.nio.file.Path;
40+
import java.util.Arrays;
41+
import java.util.Collection;
4042
import java.util.HashSet;
4143
import java.util.Objects;
4244
import java.util.Set;
@@ -51,7 +53,9 @@
5153
*
5254
* @author Jamie Mansfield
5355
* @since 0.3.0
56+
* @deprecated 0.3.5 - Migrate to Atlas
5457
*/
58+
@Deprecated
5559
public final class Jars {
5660

5761
/**
@@ -120,14 +124,22 @@ public static void transform(final Path input, final Path output, final JarEntry
120124
* @return The jar output stream
121125
*/
122126
public static JarOutputStream transform(final JarFile jarFile, final JarOutputStream jos, final JarEntryTransformer... transformers) {
123-
final Set<String> packages = new HashSet<>();
124-
walk(jarFile)
127+
final Stream<AbstractJarEntry> transformations = walk(jarFile)
125128
.map(entry -> {
126129
for (final JarEntryTransformer transformer : transformers) {
127130
entry = entry.accept(transformer);
131+
132+
if (entry == null) return null;
128133
}
129134
return entry;
130135
})
136+
.filter(Objects::nonNull);
137+
final Stream<AbstractJarEntry> additions = Arrays.stream(transformers)
138+
.map(JarEntryTransformer::additions)
139+
.flatMap(Collection::stream);
140+
141+
final Set<String> packages = new HashSet<>();
142+
Stream.concat(transformations, additions)
131143
.forEach(entry -> {
132144
try {
133145
if (!packages.contains(entry.getPackage())) {

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ subprojects {
77

88
group = 'org.cadixdev'
99
archivesBaseName = project.name.toLowerCase()
10-
version = '0.3.4'
10+
version = '0.3.5'
1111

1212
repositories {
1313
mavenCentral()
@@ -106,7 +106,7 @@ subprojects {
106106
developer {
107107
id = 'jamierocks'
108108
name = 'Jamie Mansfield'
109-
email = 'dev@jamierocks.uk'
109+
email = 'jmansfield@cadixdev.org'
110110
url = 'https://www.jamiemansfield.me/'
111111
timezone = 'Europe/London'
112112
}

changelogs/0.3.5.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Bombe 0.3.5
2+
===
3+
4+
Bombe 0.3.5 is a small release introducing some new APIs to bolster the
5+
capabilities of the jar transformation framework, namely allowing entries to be
6+
introduced. To accomplish this, a `JarEntryTransformer#additions()` method has
7+
been introduced. The `Jars` utility has been updated to support this, and a
8+
release of Atlas will be made shortly to implement this feature.
9+
10+
The `Jars` utility has been deprecated in this version, advising consumers to
11+
switch to Atlas. Jars was removed in 0.4.0, so this just serves as a final
12+
notice to any lingering applications using the utility.
13+
14+
The remapping transformer will additionally strip signature files and entries
15+
in the manifest. This transformer may in future be available standalone.

0 commit comments

Comments
 (0)