Changeset 5c99491
- Timestamp:
- Aug 23, 2010, 4:21:10 PM (8 years ago)
- Branches:
- master
- Children:
- d7023f0
- Parents:
- c60bc67
- Location:
- core
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
core/pom.xml
rc60bc67 r5c99491 55 55 </plugins> 56 56 </build> 57 58 <dependencies> 59 <dependency> 60 <groupId>commons-cli</groupId> 61 <artifactId>commons-cli</artifactId> 62 <version>1.2</version> 63 </dependency> 64 </dependencies> 57 65 58 66 <reporting> -
core/src/main/java/de/erichseifert/warp/core/DataPresenter.java
rc60bc67 r5c99491 153 153 * This constructor uses a <code>MemoryStorage</code> as storage 154 154 * and a <code>CLI</code> as user interface by default. 155 */ 156 protected DataPresenter() { 157 this(new MemoryStorage(), new CLI()); 155 * @param args Command line arguments. 156 */ 157 protected DataPresenter(String... args) { 158 this(new MemoryStorage(), args); 158 159 } 159 160 160 161 /** 161 162 * Creates a <code>DataPresenter</code> object with the specified 162 * storage and user interface.163 * storage and a command line user interface. 163 164 * @param storage Replay storage. 164 * @param ui User interface.165 */ 166 protected DataPresenter(ReplayStorage storage, WARPUI ui) {165 * @param args Command line arguments. 166 */ 167 protected DataPresenter(ReplayStorage storage, String... args) { 167 168 this.storage = storage; 168 this.ui = ui;169 this.ui = new CLI(this, args); 169 170 invalidFiles = new LinkedHashSet<File>(); 170 171 } … … 192 193 * @param dir 193 194 */ 194 public void parseDir(File dir, ProgressListener listener) {195 public void parseDir(File dir, ProgressListener... listeners) { 195 196 if (dir == null) { 196 197 return; … … 208 209 209 210 // Start parsing routine 210 ParserThread parserThread = new ParserThread(dir, storage, invalidFiles, listener );211 ParserThread parserThread = new ParserThread(dir, storage, invalidFiles, listeners); 211 212 parserThread.start(); 212 213 } … … 292 293 return ui; 293 294 } 295 296 public void setStoragePath(String path) throws IOException { 297 storage.setStoragePath(path); 298 } 299 300 public String getStoragePath() { 301 return storage.getStoragePath(); 302 } 294 303 } -
core/src/main/java/de/erichseifert/warp/core/WARP.java
rc60bc67 r5c99491 34 34 /** 35 35 * Creates a <code>WARP</code> object. 36 * @param args Command line arguments. 36 37 */ 37 public WARP() { 38 public WARP(String... args) { 39 super(args); 38 40 WARPUI ui = getUi(); 39 41 ui.setReplays(getStorage().getDescriptors()); … … 45 47 46 48 /** 47 * @param args No command line arguments are processed.49 * @param args Command line arguments. 48 50 */ 49 51 public static void main(String[] args) { 50 new WARP( );52 new WARP(args); 51 53 } 52 54 } -
core/src/main/java/de/erichseifert/warp/core/io/BufferedStorage.java
rc60bc67 r5c99491 23 23 24 24 import java.io.File; 25 import java.io.IOException; 25 26 import java.util.LinkedHashMap; 26 27 import java.util.Map; … … 164 165 storage.clear(); 165 166 } 167 168 @Override 169 public String getStoragePath() { 170 return storage.getStoragePath(); 171 } 172 173 @Override 174 public void setStoragePath(String path) throws IOException { 175 storage.setStoragePath(path); 176 } 166 177 } -
core/src/main/java/de/erichseifert/warp/core/io/MemoryStorage.java
rc60bc67 r5c99491 23 23 24 24 import java.io.File; 25 import java.io.IOException; 25 26 import java.util.HashMap; 26 27 import java.util.HashSet; … … 120 121 cache.clear(); 121 122 } 123 124 @Override 125 public String getStoragePath() { 126 return null; 127 } 128 129 @Override 130 public void setStoragePath(String path) throws IOException { 131 } 122 132 } -
core/src/main/java/de/erichseifert/warp/core/io/ReplayStorage.java
rc60bc67 r5c99491 23 23 24 24 import java.io.File; 25 import java.io.IOException; 25 26 import java.util.Map; 26 27 import java.util.Set; … … 121 122 */ 122 123 void clear(); 124 125 String getStoragePath(); 126 void setStoragePath(String path) throws IOException; 123 127 } -
core/src/main/java/de/erichseifert/warp/core/io/SerializingStorage.java
rc60bc67 r5c99491 388 388 } 389 389 } 390 391 @Override 392 public String getStoragePath() { 393 return storageDir.getAbsolutePath(); 394 } 395 396 @Override 397 public void setStoragePath(String path) throws IOException { 398 File dst = new File(path); 399 boolean moveSuccessful = storageDir.renameTo(dst); 400 if (!moveSuccessful) { 401 throw new IOException(String.format("Could not move %s to %s.", storageDir.getAbsolutePath(), dst.getAbsolutePath())); 402 } 403 } 390 404 } -
core/src/main/java/de/erichseifert/warp/core/ui/CLI.java
rc60bc67 r5c99491 22 22 package de.erichseifert.warp.core.ui; 23 23 24 import java.io.File; 25 import java.io.IOException; 24 26 import java.util.Set; 25 27 28 import org.apache.commons.cli.CommandLine; 29 import org.apache.commons.cli.CommandLineParser; 30 import org.apache.commons.cli.HelpFormatter; 31 import org.apache.commons.cli.Option; 32 import org.apache.commons.cli.OptionBuilder; 33 import org.apache.commons.cli.Options; 34 import org.apache.commons.cli.ParseException; 35 import org.apache.commons.cli.PosixParser; 36 37 import de.erichseifert.warp.core.DataPresenter; 26 38 import de.erichseifert.warp.core.replay.ReplayDescriptor; 27 39 28 40 public class CLI implements WARPUI { 29 41 30 public CLI() { 31 System.err.println(getClass().getName()+" is not implemented."); 42 public CLI(DataPresenter presenter, String[] args) { 43 // Create options 44 Options opts = new Options(); 45 @SuppressWarnings("static-access") 46 Option parseOpt = OptionBuilder.withArgName("src dst").hasArgs(2) 47 .withValueSeparator(' ') 48 .withDescription("Parses the files in the specified source folder storing it in the specified destination folder. If the destination folder is \"\", the parsed replays will be stored in memory.") 49 .withLongOpt("parse").create("p"); 50 opts.addOption(parseOpt); 51 //opts.addOption("p", "parse", true, "Parses the files in the specified folder"); 52 opts.addOption("v", "verbose", false, "Verbose mode (not implemented)"); 53 //opts.addOption(null, "path", true, "Save path of parsed replays. Parsed replays are stored in the memory, if no path is set. (not implemented)"); 54 55 // Create help 56 HelpFormatter help = new HelpFormatter(); 57 help.printHelp("WARP", opts); 58 59 // Process arguments 60 CommandLineParser parser = new PosixParser(); 61 CommandLine cl = null; 62 try { 63 cl = parser.parse(opts, args, true); 64 } catch (ParseException e) { 65 e.printStackTrace(); 66 // TODO Auto-generated catch block 67 return; 68 } 69 70 if (cl.hasOption("p")) { 71 String[] paths = cl.getOptionValues("p"); 72 File src = new File(paths[0]); 73 if (!paths[1].isEmpty()) { 74 try { 75 presenter.setStoragePath(paths[1]); 76 } catch (IOException e) { 77 // TODO Auto-generated catch block 78 e.printStackTrace(); 79 } 80 } 81 presenter.parseDir(src); 82 } 83 32 84 } 33 85
Note: See TracChangeset
for help on using the changeset viewer.