From dcaadbf6f7407ff0f33a9963e8f3137db704866b Mon Sep 17 00:00:00 2001 From: Dennis Rippinger Date: Fri, 11 May 2018 12:53:23 +0200 Subject: [PATCH] Fixed missing `apple.security` to SecurityTest. Issue: #67 Also fixes a problem related to running JUnit Tests from IntelliJ on Mac systems. IntelliJ resides in a folder `IntelliJ App` (mind the space) which executes the JUnit tests and adds therefore its own Jars to the classpath. When converted from an URL into an URI we recieve an illegal character exception. The fix was to UrlEscape the path variable within the `newUrl` method. Signed-off-by: Dennis Rippinger --- .../java/com/tngtech/archunit/exampletest/SecurityTest.java | 2 +- .../archunit/integration/SecurityIntegrationTest.java | 2 +- .../java/com/tngtech/archunit/core/importer/UrlSource.java | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/archunit-example/src/test/java/com/tngtech/archunit/exampletest/SecurityTest.java b/archunit-example/src/test/java/com/tngtech/archunit/exampletest/SecurityTest.java index 1401763cb6..83a4430c70 100644 --- a/archunit-example/src/test/java/com/tngtech/archunit/exampletest/SecurityTest.java +++ b/archunit-example/src/test/java/com/tngtech/archunit/exampletest/SecurityTest.java @@ -27,7 +27,7 @@ public void only_security_infrastructure_should_use_java_security() { @Test public void only_security_infrastructure_should_use_java_security_on_whole_classpath() { ArchRule rule = classes().that().resideInAPackage("java.security.cert..") - .should().onlyBeAccessed().byAnyPackage("..example.security..", "java..", "..sun..", "javax.."); + .should().onlyBeAccessed().byAnyPackage("..example.security..", "java..", "..sun..", "javax..", "apple.security.."); JavaClasses classes = new ClassFileImporter().importClasspath(onlyAppAndRuntime()); diff --git a/archunit-integration-test/src/test/java/com/tngtech/archunit/integration/SecurityIntegrationTest.java b/archunit-integration-test/src/test/java/com/tngtech/archunit/integration/SecurityIntegrationTest.java index 18ad30211a..f97a3aabec 100644 --- a/archunit-integration-test/src/test/java/com/tngtech/archunit/integration/SecurityIntegrationTest.java +++ b/archunit-integration-test/src/test/java/com/tngtech/archunit/integration/SecurityIntegrationTest.java @@ -29,7 +29,7 @@ public void only_security_infrastructure_should_use_java_security() { @Override public void only_security_infrastructure_should_use_java_security_on_whole_classpath() { expectViolationFromWrongSecurityCheck("classes that reside in a package 'java.security.cert..' " - + "should only be accessed by any package ['..example.security..', 'java..', '..sun..', 'javax..']"); + + "should only be accessed by any package ['..example.security..', 'java..', '..sun..', 'javax..', 'apple.security..']"); super.only_security_infrastructure_should_use_java_security_on_whole_classpath(); } diff --git a/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java b/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java index bb92745c35..8a518c7ae1 100644 --- a/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java +++ b/archunit/src/main/java/com/tngtech/archunit/core/importer/UrlSource.java @@ -28,6 +28,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; +import com.google.common.net.UrlEscapers; import com.tngtech.archunit.Internal; import com.tngtech.archunit.base.ArchUnitException.LocationException; import com.tngtech.archunit.base.Optional; @@ -96,10 +97,13 @@ private static Optional newJarUri(String path) { private static Optional newUrl(String protocol, String path) { try { - return Optional.of(new URL(protocol + "://" + path)); + return Optional.of(new URL(protocol + "://" + UrlEscapers.urlFragmentEscaper().escape(path))); } catch (MalformedURLException e) { LOG.warn("Cannot parse URL from path " + path, e); return Optional.absent(); + } catch (IllegalArgumentException e){ + LOG.warn("Cannot escape fragments from path" + path, e); + return Optional.absent(); } }