-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-46577] More robust resource loading strategy
- Loading branch information
Cyrille Le Clerc
committed
Dec 10, 2017
1 parent
a57a33b
commit 76e6db8
Showing
4 changed files
with
45 additions
and
3 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
22 changes: 22 additions & 0 deletions
22
jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/util/ClassUtils.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
package org.jenkinsci.plugins.pipeline.maven.util; | |||
|
|||
import java.io.InputStream; | |||
|
|||
import javax.annotation.Nonnull; | |||
import javax.annotation.Nullable; | |||
|
|||
/** | |||
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a> | |||
*/ | |||
public class ClassUtils { | |||
|
|||
@Nullable | |||
public static InputStream getResourceAsStream(@Nonnull String resourcePath) { | |||
InputStream result = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourcePath); | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
if(result == null) { | |||
result = ClassUtils.class.getClassLoader().getResourceAsStream(resourcePath); | |||
This comment has been minimized.
Sorry, something went wrong. |
|||
} | |||
return result; | |||
} | |||
|
|||
} |
18 changes: 18 additions & 0 deletions
18
jenkins-plugin/src/test/java/org/jenkinsci/plugins/pipeline/maven/util/ClassUtilsTest.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,18 @@ | |||
package org.jenkinsci.plugins.pipeline.maven.util; | |||
|
|||
import org.junit.Test; | |||
|
|||
import java.io.InputStream; | |||
|
|||
/** | |||
* @author <a href="mailto:cleclerc@cloudbees.com">Cyrille Le Clerc</a> | |||
*/ | |||
public class ClassUtilsTest { | |||
|
|||
@Test | |||
public void testGetResource(){ | |||
InputStream in = ClassUtils.getResourceAsStream("org/jenkinsci/plugins/pipeline/maven/util/classutils-test-1.txt"); | |||
|
|||
|
|||
} | |||
} |
Empty file.
Do not even bother checking this.