Index: exectck/src/main/java/org/apache/jdo/exectck/Utilities.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- exectck/src/main/java/org/apache/jdo/exectck/Utilities.java (revision 1852570) +++ exectck/src/main/java/org/apache/jdo/exectck/Utilities.java (date 1566587124000) @@ -5,25 +5,20 @@ * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.jdo.exectck; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; +import javax.jdo.JDOException; +import java.io.*; import java.net.URL; import java.net.URLClassLoader; import java.nio.CharBuffer; @@ -32,13 +27,12 @@ import java.util.Calendar; import java.util.List; import java.util.Map; -import javax.jdo.JDOException; public class Utilities { Utilities() { } - + public static final String DATE_FORMAT_NOW = "yyyyMMdd-HHmmss"; /* @@ -57,7 +51,7 @@ public static String urls2ClasspathString(ArrayList urls) { StringBuffer cp = new StringBuffer(); - for (URL url: urls) { + for (URL url : urls) { cp.append(url.getPath()); cp.append(File.pathSeparator); } @@ -65,9 +59,9 @@ } public static String removeSubstrs(String master, String exclude) { - String [] deleteThese = exclude.split(" "); + String[] deleteThese = exclude.split(" "); String filtered = master; - for (String sub: deleteThese) { + for (String sub : deleteThese) { filtered = filtered.replaceAll(sub.trim(), ""); } return filtered.trim(); @@ -90,37 +84,42 @@ //Get the System Classloader ClassLoader loader = ClassLoader.getSystemClassLoader(); - - //Get the URLs - URL[] urls = ((URLClassLoader) loader).getURLs(); - - for (int i = 0; i < urls.length; i++) { - System.out.println(" " + urls[i].getFile()); + if (loader != null) { + printClassloaderURLs(loader); } - - //Get the System Classloader + //Get the Context Classloader loader = Thread.currentThread().getContextClassLoader(); + if (loader != null) { + printClassloaderURLs(loader); + } + + //if both the context classloader and system classloader returns null + if (loader == null) { + throw new RuntimeException("Both the context classloader and the system classloader are not found"); + } + } + + private void printClassloaderURLs(ClassLoader loader) { //Get the URLs - urls = ((URLClassLoader) loader).getURLs(); + URL[] urls = ((URLClassLoader) loader).getURLs(); for (int i = 0; i < urls.length; i++) { System.out.println(" " + urls[i].getFile()); } - } - static String readFile( String fileName ) throws IOException { - BufferedReader reader = new BufferedReader( new FileReader (fileName)); - String line = null; - StringBuffer stringBuf = new StringBuffer(); - String ls = System.getProperty("line.separator"); - while( ( line = reader.readLine() ) != null ) { - stringBuf.append( line ); - stringBuf.append( ls ); - } - return stringBuf.toString(); - } + static String readFile(String fileName) throws IOException { + BufferedReader reader = new BufferedReader(new FileReader(fileName)); + String line = null; + StringBuffer stringBuf = new StringBuffer(); + String ls = System.getProperty("line.separator"); + while ((line = reader.readLine()) != null) { + stringBuf.append(line); + stringBuf.append(ls); + } + return stringBuf.toString(); + } InvocationResult invokeTest(List command) { InvocationResult result = new InvocationResult(); @@ -149,14 +148,14 @@ jdoex.printStackTrace(); Throwable[] throwables = jdoex.getNestedExceptions(); System.out.println("Exception throwables of size: " + throwables.length); - for (Throwable throwable: throwables) { + for (Throwable throwable : throwables) { throwable.printStackTrace(); } } return result; } - InvocationResult invokeTest(List command, File directory) { + InvocationResult invokeTest(List command, File directory) { InvocationResult result = new InvocationResult(); try { ProcessBuilder builder = new ProcessBuilder(command); @@ -184,7 +183,7 @@ jdoex.printStackTrace(); Throwable[] throwables = jdoex.getNestedExceptions(); System.out.println("Exception throwables of size: " + throwables.length); - for (Throwable throwable: throwables) { + for (Throwable throwable : throwables) { throwable.printStackTrace(); } }