/** @param args */ public static void main(String[] args) { try { System.out.println("Program started..."); System.out.println("Parsing command line arguments..."); OptionsParser options = new OptionsParser(args); System.out.println("Parsing command line arguments ended."); System.out.println("Connecting to device..."); INovacomController controller = Novacom.getController(); INovacomDevice device = controller.connectDefaultDevice(); System.out.println("Connected to device successfully."); System.out.println("Acquiring filesystem..."); PalmSynchronizer sync = new PalmSynchronizer(); String devicePath = options.GetDevicePath(); String backupPath = options.GetBackupPath(); sync.AcquireItems(device, devicePath, backupPath); System.out.println("Acquiring filesystem finished."); System.out.println("Program ended successfully."); } catch (Exception e) { System.out.println("Program failed."); e.printStackTrace(); } }
/** * Implementation of Tool::run(). Orchestrates the copy of source file(s) to target location, by: * 1. Creating a list of files to be copied to target. 2. Launching a Map-only job to copy the * files. (Delegates to execute().) * * @param argv: List of arguments passed to DistCp, from the ToolRunner. * @return On success, it returns 0. Else, -1. */ public int run(String[] argv) { try { inputOptions = (OptionsParser.parse(argv)); LOG.info("Input Options: " + inputOptions); } catch (Throwable e) { LOG.error("Invalid arguments: ", e); System.err.println("Invalid arguments: " + e.getMessage()); OptionsParser.usage(); return DistCpConstants.INVALID_ARGUMENT; } try { execute(); } catch (InvalidInputException e) { LOG.error("Invalid input: ", e); return DistCpConstants.INVALID_ARGUMENT; } catch (DuplicateFileException e) { LOG.error("Duplicate files in input path: ", e); return DistCpConstants.DUPLICATE_INPUT; } catch (Exception e) { LOG.error("Exception encountered ", e); return DistCpConstants.UNKNOWN_ERROR; } return DistCpConstants.SUCCESS; }
// Might want to call this again after some command-line options were changed. public static void printOptions() { boolean saveMakeThunk = makeThunk; makeThunk = false; parser.doGetOptionPairs().printEasy(getFile("options.map")); parser.doGetOptionStrings().printEasy(getFile("options.help")); makeThunk = saveMakeThunk; }
@Override public void initOptionsParser(OptionsParser optsParser) { optsParser .setOption("splitSep=<regex>", "Define custom split seperator.") .setOption("joinSep=<regex>", "Define custom join seperator when printing.") .setOption("inputFile=<file>", "Specify input file.") .setOption("reverseCut", "Keep the cut column and remove others.") .setSummary( "Split each input line and cut out the zero based column specified.\n" + "If no inputFile is given then STDIN is used.\n" + "\n" + "You may use negative indexing on cutting column. When using negative\n" + "indexes, make sure you use \"--\" after thec command so it will not\n" + "parse as option flag.\n" + "") .setUsage("ztool Cut [Options] [cutColumnIdx ...]\n") .setExamples( " ztool Cut 2 --inputFile=data.txt\n" + " ztool Printf \"a b c\\nd e f\" | ztool Cut 2\n" + " ztool Printf \"a b c\\nd e f\" | ztool Cut -- -1\n" + " ztool Printf \"a b c\\nd e f\" | ztool Cut -r -- -1\n" + " ztool Printf \"a|b|c\\nd|e|f\" | ztool Cut --splitSep=\"\\|\"\n" + " ztool Printf \"a|b|c\\nd|e|f\" | ztool Cut --splitSep=\"\\|\" 1\n" + ""); }
/** * Constructs a build from a list of command args. Sets the same JavacRunner for both compilation * and annotation processing. * * @param optionsParser the parsed command line args. * @param extraPlugins extraneous plugins to use in addition to the strict dependency module. * @param depsBuilder a preconstructed dependency module builder. * @throws InvalidCommandLineException on any command line error */ public JavaLibraryBuildRequest( OptionsParser optionsParser, List<BlazeJavaCompilerPlugin> extraPlugins, DependencyModule.Builder depsBuilder) throws InvalidCommandLineException, IOException { depsBuilder.addDirectMappings(optionsParser.getDirectMappings()); depsBuilder.addIndirectMappings(optionsParser.getIndirectMappings()); if (optionsParser.getStrictJavaDeps() != null) { depsBuilder.setStrictJavaDeps(optionsParser.getStrictJavaDeps()); } if (optionsParser.getOutputDepsProtoFile() != null) { depsBuilder.setOutputDepsProtoFile(optionsParser.getOutputDepsProtoFile()); } depsBuilder.addDepsArtifacts(optionsParser.getDepsArtifacts()); if (optionsParser.reduceClasspath()) { depsBuilder.setReduceClasspath(); } if (optionsParser.getRuleKind() != null) { depsBuilder.setRuleKind(optionsParser.getRuleKind()); } if (optionsParser.getTargetLabel() != null) { depsBuilder.setTargetLabel(optionsParser.getTargetLabel()); } this.dependencyModule = depsBuilder.build(); AnnotationProcessingModule.Builder processingBuilder = AnnotationProcessingModule.builder(); if (optionsParser.getSourceGenDir() != null) { processingBuilder.setSourceGenDir(Paths.get(optionsParser.getSourceGenDir())); } if (optionsParser.getManifestProtoPath() != null) { processingBuilder.setManifestProtoPath(Paths.get(optionsParser.getManifestProtoPath())); } processingBuilder.addAllSourceRoots(optionsParser.getSourceRoots()); this.processingModule = processingBuilder.build(); ImmutableList.Builder<BlazeJavaCompilerPlugin> pluginsBuilder = ImmutableList.<BlazeJavaCompilerPlugin>builder().add(dependencyModule.getPlugin()); processingModule.registerPlugin(pluginsBuilder); pluginsBuilder.addAll(extraPlugins); this.plugins = pluginsBuilder.build(); this.compressJar = optionsParser.compressJar(); this.sourceFiles = optionsParser.getSourceFiles(); this.sourceJars = ImmutableList.copyOf(optionsParser.getSourceJars()); this.messageFiles = ImmutableList.copyOf(optionsParser.getMessageFiles()); this.resourceFiles = ImmutableList.copyOf(optionsParser.getResourceFiles()); this.resourceJars = ImmutableList.copyOf(optionsParser.getResourceJars()); this.rootResourceFiles = ImmutableList.copyOf(optionsParser.getRootResourceFiles()); this.classPath = optionsParser.getClassPath(); this.extdir = optionsParser.getExtdir(); this.processorPath = optionsParser.getProcessorPath(); this.processorNames = optionsParser.getProcessorNames(); // Since the default behavior of this tool with no arguments is "rm -fr <classDir>", let's not // default to ".", shall we? if (optionsParser.getClassDir() != null) { this.classDir = optionsParser.getClassDir(); } else { this.classDir = "classes"; } if (optionsParser.getTempDir() != null) { this.tempDir = optionsParser.getTempDir(); } else { this.tempDir = "_tmp"; } this.outputJar = optionsParser.getOutputJar(); ImmutableList.Builder<AbstractPostProcessor> postProcessors = ImmutableList.builder(); for (Entry<String, List<String>> entry : optionsParser.getPostProcessors().entrySet()) { postProcessors.add(AbstractPostProcessor.create(entry.getKey(), entry.getValue())); } this.postProcessors = postProcessors.build(); this.javacOpts = ImmutableList.copyOf(optionsParser.getJavacOpts()); this.sourceGenDir = optionsParser.getSourceGenDir(); this.generatedSourcesOutputJar = optionsParser.getGeneratedSourcesOutputJar(); this.generatedClassOutputJar = optionsParser.getManifestProtoPath(); }
public static void init(String[] args, Object... objects) { // Parse options parser = new OptionsParser(); parser.doRegister("log", LogInfo.class); parser.doRegister("exec", Execution.class); parser.doRegisterAll(objects); // These options are specific to the execution, so we don't want to overwrite them // with a previous execution's. parser.setDefaultDirFileName("options.map"); parser.setIgnoreOptsFromFileName( "options.map", ListUtils.newList( "log.file", "exec.execDir", "exec.execPoolDir", "exec.actualPoolDir", "exec.makeThunk")); if (!parser.doParse(args)) System.exit(1); // Load classes if (jarFiles.size() > 0) { List<String> names = new ArrayList(); for (String jarFile : jarFiles) names.add(new File(jarFile).getName()); stderr.println("Loading JAR files: " + StrUtils.join(names)); for (String jarFile : jarFiles) // Load classes ClassInitializer.initializeJar(jarFile); } // Set character encoding if (charEncoding != null) CharEncUtils.setCharEncoding(charEncoding); if (printOptionsAndExit) { // Just print options and exit parser.doGetOptionPairs().print(stdout); System.exit(0); } // Create a new directory if (create) { createVirtualExecDir(); stderr.println(virtualExecDir); if (!makeThunk) LogInfo.file = getFile("log"); // Copy the Jar files for reference if (!makeThunk) { for (String jarFile : jarFiles) Utils.systemHard(String.format("cp %s %s", jarFile, virtualExecDir)); } } else { LogInfo.file = ""; } if (!makeThunk) { LogInfo.init(); if (startMainTrack) track("main()", true); } // Output options if (!makeThunk && virtualExecDir != null) logs("Execution directory: " + virtualExecDir); if (!makeThunk) getInfo().printEasy(getFile("info.map")); printOptions(); if (create && addToView.size() > 0) IOUtils.printLinesHard(Execution.getFile("addToView"), addToView); // Start monitoring if (!makeThunk && monitor) { monitorThread = new MonitorThread(); monitorThread.start(); } if (!makeThunk) Record.init(Execution.getFile("record")); }