* 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:
parent
81e9a604c7
commit
c93377010c
|
@ -2,10 +2,11 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import static java.awt.GraphicsEnvironment.*;
|
||||
import static javax.swing.JFrame.*;
|
||||
import static net.sourceforge.filebot.Settings.*;
|
||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.security.CodeSource;
|
||||
|
@ -39,7 +40,7 @@ public class Main {
|
|||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String... args) throws Exception {
|
||||
public static void main(String... arguments) throws Exception {
|
||||
// initialize this stuff before anything else
|
||||
initializeCache();
|
||||
initializeSecurityManager();
|
||||
|
@ -47,15 +48,20 @@ public class Main {
|
|||
try {
|
||||
// parse arguments
|
||||
final ArgumentProcessor cli = new ArgumentProcessor();
|
||||
final ArgumentBean argumentBean = cli.parse(args);
|
||||
final ArgumentBean args = cli.parse(arguments);
|
||||
|
||||
if (argumentBean.printHelp() || (GraphicsEnvironment.isHeadless() && !argumentBean.runCLI())) {
|
||||
// just print help message and exit afterwards
|
||||
cli.printHelp(argumentBean);
|
||||
if (args.printHelp() || args.printVersion() || isHeadless()) {
|
||||
System.out.format("%s / %s%n%n", getApplicationIdentifier(), getJavaRuntimeIdentifier());
|
||||
|
||||
if (args.printHelp() || (!args.printVersion() && isHeadless())) {
|
||||
cli.printHelp(args);
|
||||
}
|
||||
|
||||
// just print help message or version string and then exit
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
if (argumentBean.clearUserData()) {
|
||||
if (args.clearUserData()) {
|
||||
// clear preferences and cache
|
||||
System.out.println("Reset preferences and clear cache.");
|
||||
Settings.forPackage(Main.class).clear();
|
||||
|
@ -63,11 +69,11 @@ public class Main {
|
|||
}
|
||||
|
||||
// initialize analytics
|
||||
Analytics.setEnabled(!argumentBean.disableAnalytics);
|
||||
Analytics.setEnabled(!args.disableAnalytics);
|
||||
|
||||
// CLI mode => run command-line interface and then exit
|
||||
if (argumentBean.runCLI()) {
|
||||
int status = cli.process(argumentBean, new CmdlineOperations());
|
||||
if (args.runCLI()) {
|
||||
int status = cli.process(args, new CmdlineOperations());
|
||||
System.exit(status);
|
||||
}
|
||||
|
||||
|
@ -83,7 +89,7 @@ public class Main {
|
|||
Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
|
||||
startUserInterface(argumentBean);
|
||||
startUserInterface(args);
|
||||
}
|
||||
});
|
||||
} catch (CmdLineException e) {
|
||||
|
|
|
@ -2,9 +2,16 @@
|
|||
package net.sourceforge.filebot;
|
||||
|
||||
|
||||
import static net.sourceforge.tuned.StringUtilities.*;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
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.Preferences;
|
||||
|
||||
|
@ -129,4 +136,26 @@ public final class Settings {
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class ArgumentBean {
|
|||
@Option(name = "-mediainfo", usage = "Get media info")
|
||||
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;
|
||||
|
||||
@Option(name = "-trust-script", usage = "Lift scripting restrictions")
|
||||
|
@ -79,6 +79,9 @@ public class ArgumentBean {
|
|||
@Option(name = "-no-analytics", usage = "Disable analytics")
|
||||
public boolean disableAnalytics = false;
|
||||
|
||||
@Option(name = "-version", usage = "Print version identifier")
|
||||
public boolean version = false;
|
||||
|
||||
@Option(name = "-help", usage = "Print this help message")
|
||||
public boolean help = false;
|
||||
|
||||
|
@ -96,6 +99,11 @@ public class ArgumentBean {
|
|||
}
|
||||
|
||||
|
||||
public boolean printVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
public boolean printHelp() {
|
||||
return help;
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
return join(asList(values), delimiter);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue