Skip to content

Bombe 0.5.0 #13

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

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
341f35a
0.5.0: Start dev cycle
jamierocks Feb 28, 2020
c12547c
Merge branch 'hotfix-0.4.1' into develop
jamierocks May 26, 2020
9536ffa
Add reader for method signatures
jamierocks Aug 11, 2020
60e95ff
Merge branch 'hotfix-0.4.2' into develop
jamierocks Aug 11, 2020
24b088e
Merge branch 'hotfix-0.3.4' into master-0.3.x
jamierocks Aug 19, 2020
2ddfc7a
Merge branch 'hotfix-0.4.3' into develop
jamierocks Aug 19, 2020
212dea4
Resolve split package between bombe and bombe-jar
zml2008 Sep 8, 2020
9b773ce
Add Automatic-Module-Name
zml2008 Sep 8, 2020
daadc46
Pull CompositeClassProvider from Atlas
jamierocks Jan 2, 2021
7384cc2
Replace Guava i/o copy with our own
jamierocks Jan 2, 2021
addddbb
Use Attributes.Name.MAIN_CLASS
jamierocks Feb 1, 2021
9fbe60e
Update Gradle wrapper, Groovy, and Spock
jamierocks Feb 1, 2021
9dde468
0.3.5: Begin dev cycle
jamierocks Feb 5, 2021
cc2c082
Deprecate legacy Jars utility
jamierocks Feb 5, 2021
bcd1576
Allow transformers to mark entries for removal
jamierocks Feb 5, 2021
d542c20
Allow transformers to introduce entries
jamierocks Feb 5, 2021
44f1ced
asm: Strip jar file signatures in the remapping transformer
zml2008 Feb 5, 2021
fec8cd2
Use Attributes.Name.MAIN_CLASS
jamierocks Feb 1, 2021
ae08b10
0.3.5: Release Time
jamierocks Feb 9, 2021
2137e8e
0.4.4: Start dev cycle
jamierocks Feb 9, 2021
f9e0edc
Merge branch 'release-0.3.5' into release-0.4.4
jamierocks Feb 9, 2021
66d436c
0.4.4: Release Time
jamierocks Feb 9, 2021
7adf3c4
Merge branch 'release-0.4.4' into develop
jamierocks Feb 9, 2021
c822ed1
Basic multi-release jar handling
zml2008 Apr 5, 2021
5f6fa89
0.5.0: Begin changelog
jamierocks Aug 29, 2021
aef4659
Merge pull request GH-18 from github:zml2008/Bombe
jamierocks Aug 29, 2021
b4dc52c
GH-17 Prevent TypeReader from erroneously reading faulty objects
jamierocks Aug 29, 2021
446e809
Prevent TypeReader from throwing an exception when testing for one
jamierocks Aug 29, 2021
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ script:
- ./gradlew build
- ./gradlew codeCoverageReport
after_success:
- '[[ "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" = "develop" ]] && ./gradlew uploadArchives'
- '[[ "$TRAVIS_PULL_REQUEST" = "false" && "$TRAVIS_BRANCH" = "develop" ]] && ./gradlew publish'
- bash <(curl -s https://codecov.io/bash)

# Ugh.
Expand Down

This file was deleted.

14 changes: 10 additions & 4 deletions bombe-jar/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
dependencies {
compile project(':bombe')
compileOnly "org.ow2.asm:asm-commons:$asmVersion"
testCompile "org.ow2.asm:asm-commons:$asmVersion"
}
api project(':bombe')
implementation "org.ow2.asm:asm-commons:$asmVersion"
testImplementation "org.ow2.asm:asm-commons:$asmVersion"
}

jar {
manifest.attributes(
'Automatic-Module-Name': "${project.group}.bombe.jar"
)
}
109 changes: 103 additions & 6 deletions bombe-jar/src/main/java/org/cadixdev/bombe/jar/AbstractJarEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import java.io.IOException;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;

/**
Expand All @@ -42,11 +43,45 @@
*/
public abstract class AbstractJarEntry {

/**
* A {@link #getVersion()} value for jar entries that are at the base
* version in the jar.
*/
public static final int UNVERSIONED = -1;

private static final String META_INF = "META-INF/";
private static final String VERSIONS_PREFIX = META_INF + "versions/";

protected final String name;
protected final long time;
private String unversionedName;
private int version = UNVERSIONED;
private String packageName;
private String simpleName;

/**
* Create a new jar entry for a specific multi-release variant.
*
* <p>If {@code unversionedName} starts with {@code META-INF}, it will be
* treated as being in the base version no matter what value is provided for
* {@code version}, to match the behavior of the JDK's {@link JarFile}.</p>
*
* @param version the Java version number to associate this entry with
* @param unversionedName the name without any versioned prefix
* @param time the time the entry was created at
*/
protected AbstractJarEntry(final int version, final String unversionedName, final long time) {
if (version == UNVERSIONED || unversionedName.startsWith(META_INF)) {
this.name = unversionedName;
}
else {
this.version = version;
this.unversionedName = unversionedName;
this.name = VERSIONS_PREFIX + version + '/' + unversionedName;
}
this.time = time;
}

protected AbstractJarEntry(final String name, final long time) {
this.name = name;
this.time = time;
Expand All @@ -55,6 +90,8 @@
/**
* Gets the fully-qualified name of the jar entry.
*
* <p>This method does not have any special handling for multi-release jars.</p>
*
* @return The name
*/
public final String getName() {
Expand All @@ -70,6 +107,49 @@
return this.time;
}

/**
* Get the name of this entry, as it will be seen by a multi-release-aware
* jar handler.
*
* <p>When a file path is in the {@code META-INF/versions/} folder but does
* not provide a valid multi-release version, it will be treated as if it
* were an ordinary, un-versioned resource.</p>
*
* <p>This will always handle multi-release paths, even when the
* {@code Multi-Release} manifest attribute is set to false.</p>
*
* @return the full entry name, without any version prefix
*/
public final String getUnversionedName() {
if (this.unversionedName != null) return this.unversionedName;

if (!this.name.startsWith(VERSIONS_PREFIX)) {
return this.unversionedName = this.name;
}
// <version number>/<path>
final String trimmed = this.name.substring(VERSIONS_PREFIX.length());
final int divider = trimmed.indexOf('/');
if (divider == -1) { // malformed, ignore
return this.unversionedName = this.name;

Check warning on line 133 in bombe-jar/src/main/java/org/cadixdev/bombe/jar/AbstractJarEntry.java

View check run for this annotation

Codecov / codecov/patch

bombe-jar/src/main/java/org/cadixdev/bombe/jar/AbstractJarEntry.java#L133

Added line #L133 was not covered by tests
}

final String version = trimmed.substring(0, divider);
final String unversioned = trimmed.substring(divider + 1);
try {
if (!unversioned.startsWith(META_INF)) { // Files already within META-INF cannot be versioned
final int parsedVersion = Integer.parseInt(version);
if (parsedVersion >= 0) {
this.version = parsedVersion;
return this.unversionedName = unversioned;
}
}
}
catch (final NumberFormatException ignored) { // invalid integer, treat as unversioned
// fall through
}
return this.unversionedName = this.name;
}

/**
* Gets the package that contains the jar entry, an empty
* string if in the root package.
Expand All @@ -78,9 +158,10 @@
*/
public final String getPackage() {
if (this.packageName != null) return this.packageName;
final int index = this.name.lastIndexOf('/');
final String name = this.getUnversionedName();
final int index = name.lastIndexOf('/');
if (index == -1) return this.packageName = "";
return this.packageName = this.name.substring(0, index);
return this.packageName = name.substring(0, index);
}

/**
Expand All @@ -92,12 +173,28 @@
if (this.simpleName != null) return this.simpleName;
final int packageLength = this.getPackage().isEmpty() ? -1 : this.getPackage().length();
final int extensionLength = this.getExtension().isEmpty() ? -1 : this.getExtension().length();
return this.simpleName = this.name.substring(
final String name = this.getUnversionedName();
return this.simpleName = name.substring(
packageLength + 1,
this.name.length() - (extensionLength + 1)
name.length() - (extensionLength + 1)
);
}

/**
* If this is a multi-release variant of a class file in a multi-release
* jar, the version associated with this variant.
*
* @return the version, or {@link #UNVERSIONED} if this is the base version,
* or a file that would not be interpreted as a multi-release variant
* within the version folder.
* @see #getUnversionedName() for a description of the conditions on multi-release jars
*/
public int getVersion() {
if (this.unversionedName != null) return this.version;
this.getUnversionedName(); // initialize versions
return this.version;
}

/**
* Gets the extension of the jar entry.
*
Expand Down Expand Up @@ -132,9 +229,9 @@
/**
* Processes the jar entry with the given transformer.
*
* @param vistor The transformer
* @param visitor The transformer
* @return The jar entry
*/
public abstract AbstractJarEntry accept(final JarEntryTransformer vistor);
public abstract AbstractJarEntry accept(final JarEntryTransformer visitor);

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

private final byte[] contents;

public JarClassEntry(final int version, final String unversionedName, final long time, final byte[] contents) {
super(version, unversionedName, time);
this.contents = contents;
}

public JarClassEntry(final String name, final long time, final byte[] contents) {
super(name, time);
this.contents = contents;
Expand All @@ -58,8 +63,8 @@
}

@Override
public final JarClassEntry accept(final JarEntryTransformer vistor) {
return vistor.transform(this);
public final JarClassEntry accept(final JarEntryTransformer visitor) {
return visitor.transform(this);

Check warning on line 67 in bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarClassEntry.java

View check run for this annotation

Codecov / codecov/patch

bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarClassEntry.java#L67

Added line #L67 was not covered by tests
}

}
Loading