Author: [log in to unmask]
Date: Tue Oct 27 20:16:20 2015
New Revision: 3899
Log:
Fix finding of resources in monitoring app when not using the bin jar.
Added:
java/trunk/detector-data/src/
java/trunk/detector-data/src/main/
java/trunk/detector-data/src/main/java/
java/trunk/detector-data/src/main/java/org/
java/trunk/detector-data/src/main/java/org/hps/
java/trunk/detector-data/src/main/java/org/hps/data/
java/trunk/detector-data/src/main/java/org/hps/data/detectors/
java/trunk/detector-data/src/main/java/org/hps/data/detectors/DetectorDataResources.java
Modified:
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/JobSettingsPanel.java
java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/util/ResourceUtil.java
java/trunk/steering-files/src/main/java/org/hps/steering/SteeringFileCatalog.java
Added: java/trunk/detector-data/src/main/java/org/hps/data/detectors/DetectorDataResources.java
=============================================================================
--- java/trunk/detector-data/src/main/java/org/hps/data/detectors/DetectorDataResources.java (added)
+++ java/trunk/detector-data/src/main/java/org/hps/data/detectors/DetectorDataResources.java Tue Oct 27 20:16:20 2015
@@ -0,0 +1,63 @@
+package org.hps.data.detectors;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeSet;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Get information about available HPS detector resources.
+ *
+ * @author Jeremy McCormick, SLAc
+ */
+public class DetectorDataResources {
+
+ private DetectorDataResources() {
+ }
+
+ /**
+ * Find a list of available detector names.
+ * <p>
+ * Only those detectors that have names starting with "HPS" in their <code>detector.properties</code> files will be
+ * returned.
+ *
+ * @return the list of available HPS detector names
+ */
+ public static Set<String> getDetectorNames() {
+ final ClassLoader classLoader = DetectorDataResources.class.getClassLoader();
+ final Set<String> detectorNames = new TreeSet<String>();
+ final URL url = DetectorDataResources.class.getResource("DetectorDataResources.class");
+ final String protocol = url.getProtocol();
+ if (!"jar".equals(protocol)) {
+ throw new RuntimeException("Unsupported URL protocol: " + url.getProtocol());
+ }
+ try {
+ final JarURLConnection con = (JarURLConnection) url.openConnection();
+ final JarFile archive = con.getJarFile();
+ final Enumeration<JarEntry> entries = archive.entries();
+ while (entries.hasMoreElements()) {
+ final JarEntry entry = entries.nextElement();
+ if (entry.getName().endsWith("detector.properties")) {
+ final InputStream inputStream = classLoader.getResourceAsStream(entry.getName());
+ if (inputStream == null) {
+ throw new RuntimeException("Failed to load jar entry: " + entry.getName());
+ }
+ final Properties properties = new Properties();
+ properties.load(inputStream);
+ final String detectorName = properties.getProperty("name");
+ detectorNames.add(detectorName);
+ }
+ }
+ archive.close();
+ } catch (final IOException e) {
+ throw new RuntimeException(e);
+ }
+ return detectorNames;
+ }
+}
Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/JobSettingsPanel.java
=============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/JobSettingsPanel.java (original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/JobSettingsPanel.java Tue Oct 27 20:16:20 2015
@@ -8,6 +8,7 @@
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
+import java.util.Set;
import java.util.logging.Level;
import javax.swing.JButton;
@@ -18,10 +19,12 @@
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileFilter;
+import org.hps.data.detectors.DetectorDataResources;
import org.hps.monitoring.application.model.ConfigurationModel;
import org.hps.monitoring.application.model.SteeringType;
import org.hps.monitoring.application.util.ResourceUtil;
import org.hps.record.enums.ProcessingStage;
+import org.hps.steering.SteeringFileCatalog;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
@@ -246,8 +249,9 @@
// Listen on changes to the configuration which will then be automatically pushed to the GUI.
model.addPropertyChangeListener(this);
+ Set<String> steeringFileResources = SteeringFileCatalog.getSteeringResources();
this.steeringResourcesComboBox = this.addComboBoxMultiline("Steering File Resource",
- ResourceUtil.findSteeringResources(STEERING_PACKAGE));
+ steeringFileResources.toArray(new String[steeringFileResources.size()]));
this.steeringResourcesComboBox.setActionCommand(Commands.STEERING_RESOURCE_CHANGED);
this.steeringResourcesComboBox.addActionListener(this);
@@ -266,8 +270,9 @@
this.addComponent("Processing Stage", this.processingStageComboBox);
this.processingStageComboBox.setActionCommand(Commands.PROCESSING_STAGE_CHANGED);
this.processingStageComboBox.addActionListener(this);
-
- this.detectorNameComboBox = this.addComboBox("Detector Name", ResourceUtil.findDetectorNames());
+
+ Set<String> detectorNames = DetectorDataResources.getDetectorNames();
+ this.detectorNameComboBox = this.addComboBox("Detector Name", detectorNames.toArray(new String[detectorNames.size()]));
this.detectorNameComboBox.setActionCommand(Commands.DETECTOR_NAME_CHANGED);
this.detectorNameComboBox.addActionListener(this);
Modified: java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/util/ResourceUtil.java
=============================================================================
--- java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/util/ResourceUtil.java (original)
+++ java/trunk/monitoring-app/src/main/java/org/hps/monitoring/application/util/ResourceUtil.java Tue Oct 27 20:16:20 2015
@@ -24,50 +24,7 @@
* @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
*/
public final class ResourceUtil {
-
- /**
- * Find a list of available detector names.
- * <p>
- * Only those detectors that have names starting with "HPS" in their <code>detector.properties</code> files will be
- * returned.
- *
- * @return the list of available HPS detector names
- */
- public static String[] findDetectorNames() {
- final ClassLoader classLoader = ResourceUtil.class.getClassLoader();
- final List<String> detectorNames = new ArrayList<String>();
- final URL url = ResourceUtil.class.getResource("ResourceUtil.class");
- final String protocol = url.getProtocol();
- if (!"jar".equals(protocol)) {
- throw new RuntimeException("Unsupported URL protocol: " + url.getProtocol());
- }
- try {
- final JarURLConnection con = (JarURLConnection) url.openConnection();
- final JarFile archive = con.getJarFile();
- final Enumeration<JarEntry> entries = archive.entries();
- while (entries.hasMoreElements()) {
- final JarEntry entry = entries.nextElement();
- if (entry.getName().endsWith("detector.properties")) {
- final InputStream inputStream = classLoader.getResourceAsStream(entry.getName());
- if (inputStream == null) {
- throw new RuntimeException("Failed to load jar entry: " + entry.getName());
- }
- final Properties properties = new Properties();
- properties.load(inputStream);
- final String detectorName = properties.getProperty("name");
- if (detectorName.startsWith("HPS")) {
- detectorNames.add(detectorName);
- }
- }
- }
- archive.close();
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- Collections.sort(detectorNames);
- return detectorNames.toArray(new String[detectorNames.size()]);
- }
-
+
/**
* Find all classes that implement {@link org.hps.record.LCSimEventBuilder} and return a list of their canonical
* names.
@@ -83,48 +40,12 @@
}
return classNames.toArray(new String[classNames.size()]);
}
-
- /**
- * Get all of the files with the extension "lcsim" which are in a certain package.
- *
- * @param packageName the package name for filtering the list of resources
- * @return a list of embedded steering file resources
- */
- public static String[] findSteeringResources(final String packageName) {
- final List<String> resources = new ArrayList<String>();
- final URL url = ResourceUtil.class.getResource("ResourceUtil.class");
- final String scheme = url.getProtocol();
- if (!"jar".equals(scheme)) {
- throw new RuntimeException("Unsupported URL protocol: " + url.getProtocol());
- }
- try {
- final JarURLConnection con = (JarURLConnection) url.openConnection();
- final JarFile archive = con.getJarFile();
- final Enumeration<JarEntry> entries = archive.entries();
- while (entries.hasMoreElements()) {
- final JarEntry entry = entries.nextElement();
- if (entry.getName().endsWith(".lcsim") && entry.getName().contains(packageName)) {
- resources.add(entry.getName());
- }
- }
- archive.close();
- } catch (final IOException e) {
- throw new RuntimeException(e);
- }
- java.util.Collections.sort(resources);
- final String[] arr = new String[resources.size()];
- for (int i = 0; i < arr.length; i++) {
- arr[i] = resources.get(i);
- }
- return arr;
- }
-
+
/**
* Get the list of available conditions tags from the conditions system.
*
* @return the list of available conditions tags
*/
- // FIXME: This method probably does not belong in this class.
public static String[] getConditionsTags() {
return DatabaseConditionsManager.getInstance().getAvailableTags().toArray(new String[] {});
}
Modified: java/trunk/steering-files/src/main/java/org/hps/steering/SteeringFileCatalog.java
=============================================================================
--- java/trunk/steering-files/src/main/java/org/hps/steering/SteeringFileCatalog.java (original)
+++ java/trunk/steering-files/src/main/java/org/hps/steering/SteeringFileCatalog.java Tue Oct 27 20:16:20 2015
@@ -3,9 +3,9 @@
import java.io.IOException;
import java.net.JarURLConnection;
import java.net.URL;
-import java.util.ArrayList;
import java.util.Enumeration;
-import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -16,6 +16,9 @@
*/
public final class SteeringFileCatalog {
+ /**
+ * Do not allow class instantiation.
+ */
private SteeringFileCatalog() {
}
@@ -23,8 +26,8 @@
* Find the list of steering files in the standard resource directory.
* @return The list of steering files.
*/
- public static List<String> find() {
- return find("org/hps/steering");
+ public static Set<String> getSteeringResources() {
+ return findSteeringResources("org/hps/steering/monitoring");
}
/**
@@ -32,9 +35,9 @@
* @param resourceDirectory The resource directory.
* @return The list of matching steering files.
*/
- public static List<String> find(String resourceDirectory) {
- List<String> resources = new ArrayList<String>();
- URL url = SteeringFileCatalog.class.getResource("SteeringFileCatalog.class");
+ private static Set<String> findSteeringResources(String resourceDirectory) {
+ Set<String> resources = new TreeSet<String>();
+ URL url = SteeringFileCatalog.class.getResource("SteeringFileCatalog.class");
String scheme = url.getProtocol();
if (!"jar".equals(scheme)) {
throw new IllegalArgumentException("Unsupported URL protocol: " + url.getProtocol());
@@ -44,10 +47,10 @@
JarFile archive = con.getJarFile();
Enumeration<JarEntry> entries = archive.entries();
while (entries.hasMoreElements()) {
- JarEntry entry = entries.nextElement();
- if (entry.getName().endsWith(".lcsim") &&
- (resourceDirectory == null || resourceDirectory.length() == 0 || entry.getName().contains(resourceDirectory))) {
- // Accept the file if it ends with .lcsim and the resource directory matches or is not set (e.g. null or zero length string).
+ JarEntry entry = entries.nextElement();
+ //System.out.println("entry: " + entry.getName());
+ // Accept the file if it ends with .lcsim and the resource directory matches or is null.
+ if (entry.getName().endsWith(".lcsim") && entry.getName().startsWith(resourceDirectory)) {
resources.add("/" + entry.getName());
}
}
@@ -57,4 +60,4 @@
}
return resources;
}
-}
+}
|