Skip to content

Add support for JBoss jar:file format to DependencyResolver #8428

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
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 @@ -71,7 +71,9 @@ private static JarReader.Extracted resolveNestedJar(final URI uri) throws IOExce
path = path.substring("file:".length());
final int sepIdx = path.indexOf("!/");
if (sepIdx == -1) {
throw new IllegalArgumentException("Invalid nested jar path: " + path);
// JBoss may use the "jar:file" format to reference jar files instead of nested jars.
// These look like: jar:file:/path/to.jar!/
return JarReader.readJarFile(path);
}
final String outerPath = path.substring(0, sepIdx);
final String innerPath = path.substring(sepIdx + 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ class DependencyResolverSpecification extends DepSpecification {
'Implementation-Title' : implementationTitle,
'Implementation-Version': implementationVersion,
]
File file = new File(testDir, filename)
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))
ZipEntry e = new ZipEntry("META-INF/MANIFEST.MF")
def manifest = attributes.findAll { it.value != null }.collect { k, v -> "$k: $v" }.join('\n')
out.putNextEntry(e)
out.write(manifest.getBytes(Charset.forName('UTF-8')))
out.closeEntry()
out.close()
File file = prepareJar(filename, attributes)

when:
def dependencies = DependencyResolver.resolve(file.toURI())
Expand Down Expand Up @@ -66,6 +59,18 @@ class DependencyResolverSpecification extends DepSpecification {
'com.samskivert.jmustache' | 'jmustache' | '1.14.0' | null | null | 'jmustache-1.14.jar' || 'com.samskivert:jmustache' | '1.14'
}

private File prepareJar(final filename, final attributes) {
File file = new File(testDir, filename)
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file))
ZipEntry e = new ZipEntry("META-INF/MANIFEST.MF")
def manifest = attributes.findAll { it.value != null }.collect { k, v -> "$k: $v" }.join('\n')
out.putNextEntry(e)
out.write(manifest.getBytes(Charset.forName('UTF-8')))
out.closeEntry()
out.close()
file
}

void 'jar without pom.properties get resolved with hash'() {
expect:
knownJarCheck(
Expand Down Expand Up @@ -328,4 +333,23 @@ class DependencyResolverSpecification extends DepSpecification {
assert dep.version == opts['version']
assert dep.hash == opts['hash']
}

void 'JBoss may use the "jar:file" format to reference jar files instead of nested jars'(){
setup:
final attributes = [
'Bundle-SymbolicName' : null,
'Bundle-Name' : null,
'Bundle-Version' : null,
'Implementation-Title' : 'JUnit',
'Implementation-Version': '4.12',
]
final file = prepareJar("junit-4.12.jar", attributes)
final uri = new URI("jar:"+file.toURI()+"!/")

when:
final deps = DependencyResolver.resolve(uri)

then:
deps.size() == 1
}
}
Loading