Index: modules/library/metadata/src/main/java/org/geotools/factory/GeoTools.java =================================================================== --- modules/library/metadata/src/main/java/org/geotools/factory/GeoTools.java (revision 38126) +++ modules/library/metadata/src/main/java/org/geotools/factory/GeoTools.java (working copy) @@ -17,14 +17,18 @@ package org.geotools.factory; import java.awt.RenderingHints; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; @@ -32,8 +36,8 @@ import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; +import org.geotools.resources.Arguments; import org.geotools.resources.Classes; -import org.geotools.resources.Arguments; import org.geotools.resources.i18n.Errors; import org.geotools.resources.i18n.ErrorKeys; import org.geotools.util.logging.LoggerFactory; @@ -202,7 +206,7 @@ */ private GeoTools() { } - + /** * Binds the specified {@linkplain System#getProperty(String) system property} * to the specified key. Only one key can be binded to a given system property. @@ -226,8 +230,79 @@ throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$2, "property", property)); } + + /** + * Returns summary information about GeoTools and the current environment. This is + * a shortcut for {@code getAboutInfo(true, true, true}. + * + * @return requested information as a string + * + * @see #getAboutInfo(boolean, boolean, boolean) + */ + public static String getAboutInfo() { + return getAboutInfo(true, true, true); + } /** + * Returns summary information about GeoTools and the current environment. + * + * @param showJava whether to include Java version + * @param showOS whether to include operating system name and version + * @param showGeoToolsJars whether to include a listing of GeoTools jars on the classpath + * + * @return requested information as a string + */ + public static String getAboutInfo(boolean showJava, boolean showOS, boolean showGeoToolsJars) { + final String newline = String.format("%n"); + final String indent = " "; + + final StringBuilder sb = new StringBuilder("GeoTools version "); + + sb.append(getVersion().toString()); + if (sb.toString().endsWith("SNAPSHOT")) { + sb.append(" (built from r").append(getBuildRevision().toString()).append(")"); + } + + if (showJava) { + sb.append(newline).append("Java version: "); + sb.append(System.getProperty("java.version")); + } + + if (showOS) { + sb.append(newline).append("Operating system: "); + sb.append(System.getProperty("os.name")).append(' ').append(System.getProperty("os.version")); + } + + if (showGeoToolsJars) { + sb.append(newline).append("GeoTools jars on classpath:"); + for (String jarName : getGeoToolsJars()) { + sb.append(newline).append(indent).append(jarName); + } + } + + return sb.toString(); + } + + private static List getGeoToolsJars() { + final Pattern pattern = Pattern.compile(".*\\/" + getVersion() + "\\/(gt-.*jar$)"); + List jarNames = new ArrayList(); + + String pathSep = System.getProperty("path.separator"); + String classpath = System.getProperty("java.class.path"); + StringTokenizer st = new StringTokenizer(classpath, pathSep); + while (st.hasMoreTokens()) { + String path = st.nextToken(); + Matcher matcher = pattern.matcher(path); + if (matcher.find()) { + jarNames.add(matcher.group(1)); + } + } + + Collections.sort(jarNames); + return jarNames; + } + + /** * Reports back the version of GeoTools being used. * * @return The current GeoTools version.