Skip to content

Commit

Permalink
Heuristic implementation of ReflectionUtil.classpathToString that wor…
Browse files Browse the repository at this point in the history
…ks on Java 11
  • Loading branch information
mernst committed Sep 8, 2020
1 parent ae943ec commit d369cb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Reflection-Util change log

## 1.0.1

- Make ReflectionUtil.classpathToString work on Java 11

## 1.0.0

- Release 1.0.0.
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/plumelib/reflection/ReflectionPlume.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

package org.plumelib.reflection;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -248,7 +249,8 @@ public static void addToClasspath(String dir) {
*
* @return the classpath as a multi-line string
*/
public static String classpathToString() {
@SuppressWarnings("UnusedMethod") // This implementation works only on Java 8, not Java 11.
private static String classpathToStringJava8Only() {
StringJoiner result = new StringJoiner(System.lineSeparator());
ClassLoader cl = ClassLoader.getSystemClassLoader();
URL[] urls = ((URLClassLoader) cl).getURLs();
Expand All @@ -258,6 +260,16 @@ public static String classpathToString() {
return result.toString();
}

/**
* Returns the classpath as a multi-line string.
*
* @return the classpath as a multi-line string
*/
public static String classpathToString() {
return System.getProperty("java.class.path")
.replace(File.pathSeparator, System.lineSeparator());
}

///////////////////////////////////////////////////////////////////////////
/// Method
///
Expand Down

0 comments on commit d369cb6

Please sign in to comment.