-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70e7afb
commit a62e262
Showing
4 changed files
with
87 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,13 +28,17 @@ | |
*/ | ||
package edu.umd.cs.guitar.ripper; | ||
|
||
import java.net.URL; | ||
|
||
import org.kohsuke.args4j.CmdLineException; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.spi.StringArrayOptionHandler; | ||
|
||
|
||
/** | ||
* This class provides the <code>main</code> method of SWTRipper. | ||
* | ||
* @author Gabe Gorelick | ||
* @author <a href="mailto:[email protected]"> Matt Kirn </a> | ||
* @author <a href="mailto:[email protected]"> Alex Loeb </a> | ||
*/ | ||
|
@@ -50,6 +54,9 @@ public class SWTRipperMain { | |
* command line arguments | ||
*/ | ||
public static void main(String[] args) { | ||
CmdLineParser.registerHandler(String[].class, StringArrayOptionHandler.class); | ||
CmdLineParser.registerHandler(URL[].class, URLArrayOptionHandler.class); | ||
|
||
SWTRipperConfiguration configuration = new SWTRipperConfiguration(); | ||
CmdLineParser parser = new CmdLineParser(configuration); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package edu.umd.cs.guitar.ripper; | ||
|
||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
|
||
import org.kohsuke.args4j.CmdLineException; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.OptionDef; | ||
import org.kohsuke.args4j.spi.OptionHandler; | ||
import org.kohsuke.args4j.spi.Parameters; | ||
import org.kohsuke.args4j.spi.Setter; | ||
|
||
public class URLArrayOptionHandler extends OptionHandler<URL[]> { | ||
|
||
public URLArrayOptionHandler(CmdLineParser parser, OptionDef option, | ||
Setter<? super URL[]> setter) { | ||
|
||
super(parser, option, setter); | ||
} | ||
|
||
@Override | ||
public int parseArguments(Parameters params) throws CmdLineException { | ||
int counter = 0; | ||
|
||
ArrayList<URL> values = new ArrayList<URL>(); | ||
while (true) { | ||
String param; | ||
try { | ||
param = params.getParameter(counter); | ||
} catch (CmdLineException ex) { | ||
break; | ||
} | ||
if (param.startsWith("-")) { | ||
break; | ||
} | ||
|
||
for (String str : param.split(" ")) { | ||
try { | ||
values.add(new URL(str)); | ||
} catch (MalformedURLException e) { | ||
throw new CmdLineException("Illegal URL value: " + str); | ||
} | ||
} | ||
counter++; | ||
} | ||
|
||
this.setter.addValue(values.toArray(new URL[values.size()])); | ||
return counter; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return "URL[]" | ||
*/ | ||
@Override | ||
public String getDefaultMetaVariable() { | ||
return "URL[]"; | ||
} | ||
|
||
} |