* print version/revision/jre identifier

* just print help if started with no arguments in headless mode instead of crashing when trying to start the GUI
This commit is contained in:
Reinhard Pointner 2011-11-29 03:14:39 +00:00
parent 81e9a604c7
commit c93377010c
4 changed files with 60 additions and 12 deletions

View File

@ -2,10 +2,11 @@
package net.sourceforge.filebot; package net.sourceforge.filebot;
import static java.awt.GraphicsEnvironment.*;
import static javax.swing.JFrame.*; import static javax.swing.JFrame.*;
import static net.sourceforge.filebot.Settings.*;
import static net.sourceforge.tuned.ui.TunedUtilities.*; import static net.sourceforge.tuned.ui.TunedUtilities.*;
import java.awt.GraphicsEnvironment;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.security.CodeSource; import java.security.CodeSource;
@ -39,7 +40,7 @@ public class Main {
/** /**
* @param args * @param args
*/ */
public static void main(String... args) throws Exception { public static void main(String... arguments) throws Exception {
// initialize this stuff before anything else // initialize this stuff before anything else
initializeCache(); initializeCache();
initializeSecurityManager(); initializeSecurityManager();
@ -47,15 +48,20 @@ public class Main {
try { try {
// parse arguments // parse arguments
final ArgumentProcessor cli = new ArgumentProcessor(); final ArgumentProcessor cli = new ArgumentProcessor();
final ArgumentBean argumentBean = cli.parse(args); final ArgumentBean args = cli.parse(arguments);
if (argumentBean.printHelp() || (GraphicsEnvironment.isHeadless() && !argumentBean.runCLI())) { if (args.printHelp() || args.printVersion() || isHeadless()) {
// just print help message and exit afterwards System.out.format("%s / %s%n%n", getApplicationIdentifier(), getJavaRuntimeIdentifier());
cli.printHelp(argumentBean);
if (args.printHelp() || (!args.printVersion() && isHeadless())) {
cli.printHelp(args);
}
// just print help message or version string and then exit
System.exit(0); System.exit(0);
} }
if (argumentBean.clearUserData()) { if (args.clearUserData()) {
// clear preferences and cache // clear preferences and cache
System.out.println("Reset preferences and clear cache."); System.out.println("Reset preferences and clear cache.");
Settings.forPackage(Main.class).clear(); Settings.forPackage(Main.class).clear();
@ -63,11 +69,11 @@ public class Main {
} }
// initialize analytics // initialize analytics
Analytics.setEnabled(!argumentBean.disableAnalytics); Analytics.setEnabled(!args.disableAnalytics);
// CLI mode => run command-line interface and then exit // CLI mode => run command-line interface and then exit
if (argumentBean.runCLI()) { if (args.runCLI()) {
int status = cli.process(argumentBean, new CmdlineOperations()); int status = cli.process(args, new CmdlineOperations());
System.exit(status); System.exit(status);
} }
@ -83,7 +89,7 @@ public class Main {
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.getMessage(), e); Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.getMessage(), e);
} }
startUserInterface(argumentBean); startUserInterface(args);
} }
}); });
} catch (CmdLineException e) { } catch (CmdLineException e) {

View File

@ -2,9 +2,16 @@
package net.sourceforge.filebot; package net.sourceforge.filebot;
import static net.sourceforge.tuned.StringUtilities.*;
import java.awt.GraphicsEnvironment;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.jar.Manifest;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException; import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences; import java.util.prefs.Preferences;
@ -129,4 +136,26 @@ public final class Settings {
throw ExceptionUtilities.asRuntimeException(e); throw ExceptionUtilities.asRuntimeException(e);
} }
} }
public static String getApplicationIdentifier() {
String rev = null;
try {
Manifest manifest = new Manifest(Settings.class.getResourceAsStream("/META-INF/MANIFEST.MF"));
rev = manifest.getMainAttributes().getValue("Built-Revision");
} catch (IOException e) {
Logger.getLogger(Settings.class.getName()).log(Level.WARNING, e.getMessage());
}
return joinBy(" ", getApplicationName(), getApplicationVersion(), String.format("(r%s)", rev != null ? rev : 0));
}
public static String getJavaRuntimeIdentifier() {
String name = System.getProperty("java.runtime.name");
String version = System.getProperty("java.version");
String headless = GraphicsEnvironment.isHeadless() ? "(headless)" : null;
return joinBy(" ", name, version, headless);
}
} }

View File

@ -61,7 +61,7 @@ public class ArgumentBean {
@Option(name = "-mediainfo", usage = "Get media info") @Option(name = "-mediainfo", usage = "Get media info")
public boolean mediaInfo = false; public boolean mediaInfo = false;
@Option(name = "-script", usage = "Run Groovy script") @Option(name = "-script", usage = "Run Groovy script", metaVar = "robot.groovy")
public String script = null; public String script = null;
@Option(name = "-trust-script", usage = "Lift scripting restrictions") @Option(name = "-trust-script", usage = "Lift scripting restrictions")
@ -79,6 +79,9 @@ public class ArgumentBean {
@Option(name = "-no-analytics", usage = "Disable analytics") @Option(name = "-no-analytics", usage = "Disable analytics")
public boolean disableAnalytics = false; public boolean disableAnalytics = false;
@Option(name = "-version", usage = "Print version identifier")
public boolean version = false;
@Option(name = "-help", usage = "Print this help message") @Option(name = "-help", usage = "Print this help message")
public boolean help = false; public boolean help = false;
@ -96,6 +99,11 @@ public class ArgumentBean {
} }
public boolean printVersion() {
return version;
}
public boolean printHelp() { public boolean printHelp() {
return help; return help;
} }

View File

@ -14,6 +14,11 @@ public final class StringUtilities {
} }
public static String joinBy(CharSequence delimiter, Object... values) {
return join(asList(values), delimiter);
}
public static String join(Object[] values, CharSequence delimiter) { public static String join(Object[] values, CharSequence delimiter) {
return join(asList(values), delimiter); return join(asList(values), delimiter);
} }