1
package org.herac.tuxguitar.gui.util;
6
import org.herac.tuxguitar.gui.TuxGuitar;
7
import org.herac.tuxguitar.util.TGVersion;
9
public class ArgumentParser {
10
private static final String[] OPTION_HELP = new String[]{"-h","--help"};
11
private static final String[] OPTION_VERSION = new String[]{"-v","--version"};
12
private static final String[] OPTION_JRE_INFO = new String[]{"-i","--system-info"};
14
private String[] arguments;
15
private boolean processAndExit;
18
public ArgumentParser(String[] arguments){
19
this.arguments = arguments;
20
this.processAndExit = false;
29
if(!processAndExit()){
33
}catch(Throwable throwable){
34
throwable.printStackTrace();
38
private void checkHelp(){
39
for(int i = 0;i < this.arguments.length;i++){
40
for(int j = 0;j < OPTION_HELP.length;j++){
41
if(this.arguments[i].equals(OPTION_HELP[j])){
42
print("usage: TuxGuitar [file]");
44
print(" -h, --help Show help options");
45
print(" -v, --version Show version information and exit");
46
print(" -i, --system-info Show the JVM system information");
47
print(" -D<name>=<value> Set a JVM system property");
49
this.processAndExit = true;
55
private void checkVersion(){
56
for(int i = 0;i < this.arguments.length;i++){
57
for(int j = 0;j < OPTION_VERSION.length;j++){
58
if(this.arguments[i].equals(OPTION_VERSION[j])){
59
print(TuxGuitar.APPLICATION_NAME + " - " + TGVersion.CURRENT.getVersion());
61
this.processAndExit = true;
67
private void checkSystemInfo(){
68
for(int i = 0;i < this.arguments.length;i++){
69
for(int j = 0;j < OPTION_JRE_INFO.length;j++){
70
if(this.arguments[i].equals(OPTION_JRE_INFO[j])){
71
print("System Info:");
72
print("-> OS-Name: " + System.getProperty("os.name"));
73
print("-> OS-Arch: " + System.getProperty("os.arch"));
74
print("-> OS-Version: " + System.getProperty("os.version"));
75
print("-> JVM-Name: " + System.getProperty("java.vm.name"));
76
print("-> JVM-Version: " + System.getProperty("java.vm.version"));
77
print("-> JVM-Vendor: " + System.getProperty("java.vm.vendor"));
78
print("-> Java-Version: " + System.getProperty("java.version"));
79
print("-> Java-Vendor: " + System.getProperty("java.vendor"));
80
print("-> Java-Home: " + System.getProperty("java.home"));
81
print("-> Java-Class-Path: " + System.getProperty("java.class.path"));
82
print("-> Java-Library-Path: " + System.getProperty("java.library.path"));
84
this.processAndExit = true;
90
private void checkProperties(){
91
for(int i = 0;i < this.arguments.length;i++){
92
if(this.arguments[i].indexOf("-D") == 0 && this.arguments[i].indexOf("=") > 0){
93
String[] property = this.arguments[i].substring(2).split("=");
94
if( property != null && property.length == 2 ){
95
System.setProperty( property[0],property[1]);
101
private void checkURL(){
102
for(int i = 0;i < this.arguments.length;i++){
103
if(makeURL(this.arguments[i])){
109
private boolean makeURL(String spec){
111
File file = new File(spec);
113
this.url = file.toURI().toURL();
115
this.url = new URL(spec);
117
}catch(Throwable throwable){
120
return (this.url != null);
123
public boolean processAndExit(){
124
return this.processAndExit;
127
public URL getURL() {
131
protected void print(String s){
135
protected void print(String s, boolean ignoreNull){
136
if(!ignoreNull || s != null){
137
System.out.println( s );