Skip to content

Commit

Permalink
538 stops after start (#540)
Browse files Browse the repository at this point in the history
* Update to substance 8.0 to avoid NullPointerException
* Showing startup error to user.
  • Loading branch information
otros-systems authored Aug 25, 2018
1 parent e86c3ab commit 67ce0af
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 27 deletions.
Binary file added Common-libs/lib/substance-8.0.02.jar
Binary file not shown.
Binary file added Common-libs/lib/substance-swingx-8.0.00.jar
Binary file not shown.
Binary file added Common-libs/lib/trident-1.5.00.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

public class ThemeConfig implements Theme {
private DataConfiguration configuration;
private UIDefaults lookAndFeelDefaults;

public ThemeConfig(Configuration configuration) {
this.configuration = new DataConfiguration(configuration);
final LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
lookAndFeelDefaults = lookAndFeel.getDefaults();
}

@Override
Expand All @@ -34,9 +37,7 @@ public void clear(ThemeKey themeKey) {

@Override
public Theme.Type themeType() {

final LookAndFeel lookAndFeel = UIManager.getLookAndFeel();
final Color color = lookAndFeel.getDefaults().getColor("Label.background");
final Color color = lookAndFeelDefaults.getColor("Label.background");
if (Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), new float[3])[2] > 0.5f) {
return Type.Light;
} else {
Expand Down
56 changes: 35 additions & 21 deletions OtrosStarter/src/main/java/pl/otros/starter/StartApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
package pl.otros.starter;

import javax.swing.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
Expand All @@ -31,7 +28,7 @@ public class StartApp {

private static final Logger LOGGER = Logger.getLogger(StartApp.class.getName());

public static void main(String[] args) throws IOException {
public static void main(String[] args) {


final String runningJava = System.getProperty("java.version");
Expand All @@ -43,46 +40,63 @@ public static void main(String[] args) throws IOException {
JOptionPane.showMessageDialog(null, "Java version have to at least 1.8, your version is " + runningJava, "Java is too old", JOptionPane.ERROR_MESSAGE);
}

ClassLoaderResolver flatFileClassLoaderResolver = new FlatFileClassLoaderResolver();
String olvHome = System.getProperty("OLV_HOME");
InputStream in = new FileInputStream(new File(olvHome, "classpath.txt"));

URL[] classPathUrls = flatFileClassLoaderResolver.getClassPathUrls(in);
LOGGER.info("Added " + classPathUrls.length + " jars to classpath");
for (URL url : classPathUrls) {
LOGGER.info("Using classpath: " + url.toExternalForm());
}

URLClassLoader urlClassLoader = new URLClassLoader(classPathUrls, StartApp.class.getClassLoader());
Thread.currentThread().setContextClassLoader(urlClassLoader);
String classToStart = "pl.otros.logview.gui.LogViewMainFrame";
int errorCode = 0;
try {
ClassLoaderResolver flatFileClassLoaderResolver = new FlatFileClassLoaderResolver();
String olvHome = System.getProperty("OLV_HOME");
InputStream in = new FileInputStream(new File(olvHome, "classpath.txt"));

URL[] classPathUrls = flatFileClassLoaderResolver.getClassPathUrls(in);
LOGGER.info("Added " + classPathUrls.length + " jars to classpath");
for (URL url : classPathUrls) {
LOGGER.info("Using classpath: " + url.toExternalForm());
}

URLClassLoader urlClassLoader = new URLClassLoader(classPathUrls, StartApp.class.getClassLoader());
Thread.currentThread().setContextClassLoader(urlClassLoader);
Class<?> aClass = urlClassLoader.loadClass(classToStart);
Method method = aClass.getMethod("main", String[].class);
method.invoke(null, (Object) args); // static method doesn't have an instance

} catch (ClassNotFoundException e) {
System.err.printf("Cant load class %s: %s", classToStart, e.getMessage());
System.err.printf("Can't load class %s: %s", classToStart, e.getMessage());
e.printStackTrace();
showError(e);
errorCode = 1;
} catch (InvocationTargetException e) {
System.err.printf("Cant invoke method main on class %s: %s", classToStart, e.getMessage());
System.err.printf("Can't invoke method main on class %s: %s", classToStart, e.getMessage());
e.printStackTrace();
showError(e);
errorCode = 2;
} catch (IllegalAccessException e) {
System.err.printf("Cant invoke method main on class %s: %s", classToStart, e.getMessage());
System.err.printf("Can't invoke method main on class %s: %s", classToStart, e.getMessage());
e.printStackTrace();
showError(e);
errorCode = 3;
} catch (NoSuchMethodException e) {
System.err.printf("Cant find method main on class %s: %s", classToStart, e.getMessage());
System.err.printf("Can't find method main on class %s: %s", classToStart, e.getMessage());
e.printStackTrace();
showError(e);
errorCode = 4;
} catch (Exception e){
System.err.printf("Can't start application %s: %s", classToStart, e.getMessage());
e.printStackTrace();
showError(e);
errorCode = 5;
}
if (errorCode != 0) {
System.exit(errorCode);
}

}

private static void showError(Exception exception){
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
exception.printStackTrace(new PrintStream(outputStream));
JTextArea textArea = new JTextArea("Can't start OtrosLogViewer\n" + new String(outputStream.toByteArray()));
textArea.setEditable(false);
JOptionPane.showMessageDialog(null,new JScrollPane(textArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS));

}
}
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ project(':Common-libs') {
dependencies {
compile fileTree(dir: 'lib', include: '*.jar')
compile 'com.beust:jcommander:1.29'
compile 'com.github.insubstantial:trident:7.3'
compile 'com.github.insubstantial:substance-swingx:7.3'
compile 'com.google.guava:guava:23.0'
compile 'com.google.code.gson:gson:2.8.2'
compile 'com.jcraft:jsch:0.1.+'
Expand All @@ -87,7 +85,6 @@ project(':Common-libs') {
compile 'org.swinglabs.swingx:swingx-all:1.+'
compile 'org.swinglabs:jxlayer:3.0.4'
compile 'org.ocpsoft.prettytime:prettytime:3.1.0.Final'
compile 'com.github.insubstantial:substance:7.3'
compile 'org.apache.sling:org.apache.sling.commons.json:2.0.10'
compile 'ch.qos.logback:logback-core:1.1.3'
compile 'ch.qos.logback:logback-classic:1.1.3'
Expand Down

0 comments on commit 67ce0af

Please sign in to comment.