-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix broken JRT URL handling for JDK >= 13
With JDK 13 some wrongly implemented behavior of JRT path handling was fixed. I.e. by JEP-220 (https://openjdk.java.net/jeps/220) while URIs possess the shape of `jrt:/module.name/some/clazz/Name.class` the respective (virtual) file system path for JRTs supposedly has the shape of `/modules/module.name/some/clazz/Name.class`. Unfortunately ArchUnit was relying on the wrongly implemented version of `JrtFileSystemProvider` which would return a path for JRTs of `/module.name/some/clazz/Name.class`. Thus with JDK >= 13 the URI handling for JRTs was broken. This will now be fixed by relying on pure JRT URI handling without relying on conversion to `java.nio.file.Path`. We simply split the path of a JRT URI on `/` and treat the first segment as module name, the rest of the segments as the resource/class name (e.g. `module.name` and `some/clazz/Name.class`). Note that we unfortunately cannot use `URI.getPath()` within `NormalizedUri` to retrieve the path without the schema, since `URI.getPath()` will return `null` for JAR URIs (i.e. `jar:file:/...`). Signed-off-by: Peter Gafert <[email protected]>
- Loading branch information
1 parent
27e4251
commit 852c808
Showing
5 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
archunit/src/test/java/com/tngtech/archunit/core/importer/NormalizedUriTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.tngtech.archunit.core.importer; | ||
|
||
import java.net.URI; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class NormalizedUriTest { | ||
@Test | ||
public void normalizes_URI() { | ||
NormalizedUri uri = NormalizedUri.from(URI.create("prot:/some/.././uri/.")); | ||
|
||
assertThat(uri.toURI()).isEqualTo(URI.create("prot:/uri/")); | ||
} | ||
|
||
@Test | ||
public void normalizes_URI_from_string() { | ||
NormalizedUri uri = NormalizedUri.from("prot:/some/../uri/."); | ||
|
||
assertThat(uri.toURI()).isEqualTo(URI.create("prot:/uri/")); | ||
} | ||
|
||
@Test | ||
public void parses_first_segment() { | ||
NormalizedUri uri = NormalizedUri.from("jrt:/java.base/java/io/File.class"); | ||
|
||
assertThat(uri.getFirstSegment()).isEqualTo("java.base"); | ||
|
||
uri = NormalizedUri.from("jrt:/java.base"); | ||
|
||
assertThat(uri.getFirstSegment()).isEqualTo("java.base"); | ||
} | ||
|
||
@Test | ||
public void parses_tail_segments() { | ||
NormalizedUri uri = NormalizedUri.from("jrt:/java.base/java/io/File.class"); | ||
|
||
assertThat(uri.getTailSegments()).isEqualTo("java/io/File.class"); | ||
|
||
uri = NormalizedUri.from("jrt:/java.base"); | ||
|
||
assertThat(uri.getTailSegments()).isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters