From: Simon Brandhof Date: Tue, 15 Mar 2016 09:13:02 +0000 (+0100) Subject: Add org.sonar.api.utils.System2#getResource(name) X-Git-Tag: 5.5-M11~127 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=17402317a7bff902f6e1311da38f2cdc16a10f87;p=sonarqube.git Add org.sonar.api.utils.System2#getResource(name) --- diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java index aa15e0ba139..8dd268f4c7c 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/System2.java @@ -19,16 +19,15 @@ */ package org.sonar.api.utils; -import org.apache.commons.lang.SystemUtils; -import org.sonar.api.batch.BatchSide; -import org.sonar.api.server.ServerSide; - -import javax.annotation.CheckForNull; - +import java.net.URL; import java.util.Date; import java.util.Map; import java.util.Properties; import java.util.TimeZone; +import javax.annotation.CheckForNull; +import org.apache.commons.lang.SystemUtils; +import org.sonar.api.batch.BatchSide; +import org.sonar.api.server.ServerSide; /** * Proxy over {@link java.lang.System}. It aims to improve testability of classes @@ -141,6 +140,14 @@ public class System2 { return TimeZone.getDefault(); } + /** + * @since 5.5 + * @see Class#getResource(String) + */ + public URL getResource(String name) { + return getClass().getResource(name); + } + /** * Closes the object and throws an {@link java.lang.IllegalStateException} on error. * @since 5.1 diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java index a50c67788cb..3e410424f29 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/System2Test.java @@ -90,6 +90,12 @@ public class System2Test { System2.INSTANCE.println("foo"); } + @Test + public void testGetResource() throws Exception { + String name = "META-INF/MANIFEST.MF"; + assertThat(System2.INSTANCE.getResource(name)).isEqualTo(getClass().getResource(name)); + } + @Test public void close() { class MyCloseable implements Closeable {