com.martiansoftware.jsap.JSAPResult Java Examples

The following examples show how to use com.martiansoftware.jsap.JSAPResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GZIPIndexer.java    From BUbiNG with Apache License 2.0 6 votes vote down vote up
public static void main(String[] arg) throws IOException, JSAPException {
	final SimpleJSAP jsap = new SimpleJSAP(GZIPIndexer.class.getName(), "Computes and stores a quasi-succinct index for a compressed archive.",
			new Parameter[] {
				new UnflaggedOption("archive", JSAP.STRING_PARSER, JSAP.REQUIRED, "The name a GZIP's archive."),
				new UnflaggedOption("index", JSAP.STRING_PARSER, JSAP.REQUIRED, "The output (a serialized LongBigList of pointers to the records in the archive) filename."),
			}
	);

	final JSAPResult jsapResult = jsap.parse(arg);
	if (jsap.messagePrinted()) return;

	final FastBufferedInputStream input = new FastBufferedInputStream(new FileInputStream(jsapResult.getString("archive")));
	ProgressLogger pl = new ProgressLogger(LOGGER, 1, TimeUnit.MINUTES, "records");
	pl.start("Scanning...");
	final EliasFanoMonotoneLongBigList list = new EliasFanoMonotoneLongBigList(index(input, pl));
	pl.done();
	BinIO.storeObject(list, jsapResult.getString("index"));
}
 
Example #2
Source File: GZIPArchiveWriterTest.java    From BUbiNG with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, JSAPException {

	SimpleJSAP jsap = new SimpleJSAP(GZIPArchiveReader.class.getName(), "Writes some random records on disk.",
		new Parameter[] {
			new Switch("fully", 'f', "fully",
				"Whether to read fully the record (and do a minimal cosnsistency check)."),
			new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY,
				"The path to read from."), });

	JSAPResult jsapResult = jsap.parse(args);
	if (jsap.messagePrinted())
	    System.exit(1);

	final boolean fully = jsapResult.getBoolean("fully");
	GZIPArchiveReader gzar = new GZIPArchiveReader(new FileInputStream(jsapResult.getString("path")));
	for (;;) {
	    ReadEntry e = gzar.getEntry();
	    if (e == null)
		break;
	    InputStream inflater = e.lazyInflater.get();
	    if (fully)
		ByteStreams.toByteArray(inflater);
	    e.lazyInflater.consume();
	    System.out.println(e);
	}
    }
 
Example #3
Source File: GitRepositoryLauncher.java    From repairnator with MIT License 5 votes vote down vote up
public GitRepositoryLauncher(String[] args) throws JSAPException {
    InputStream propertyStream = getClass().getResourceAsStream("/version.properties");
    Properties properties = new Properties();
    if (propertyStream != null) {
        try {
            properties.load(propertyStream);
        } catch (IOException e) {
            LOGGER.error("Error while loading property file.", e);
        }
        LOGGER.info("PIPELINE VERSION: "+properties.getProperty("PIPELINE_VERSION"));
    } else {
        LOGGER.info("No information about PIPELINE VERSION has been found.");
    }

    jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.PIPELINE);
    this.initConfig(arguments);

    checkToolsLoaded(jsap);
    this.checkNopolSolverPath(jsap);
    LOGGER.info("The pipeline will try to repair the following repository id: " + getConfig().getGitRepositoryId());
    
    if (getConfig().isDebug()) {
        Utils.setLoggersLevel(Level.DEBUG);
    } else {
        Utils.setLoggersLevel(Level.INFO);
    }

    this.initSerializerEngines();
    this.initNotifiers();
}
 
Example #4
Source File: CheckBranchLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private CheckBranchLauncher(String[] args) throws JSAPException {
    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.CHECKBRANCHES);

    this.initConfig(arguments);
    this.initNotifiers();
}
 
Example #5
Source File: LauncherUtils.java    From repairnator with MIT License 5 votes vote down vote up
public static void checkArguments(JSAP jsap, JSAPResult arguments, LauncherType launcherType) {
    if (!arguments.success()) {
        // print out specific error messages describing the problems
        for (java.util.Iterator<?> errs = arguments.getErrorMessageIterator(); errs.hasNext();) {
            System.err.println("Error: " + errs.next());
        }
    }

    if (getArgHelp(arguments)) {
        printUsage(jsap, launcherType);
    }


    checkPushUrlArg(jsap, arguments, launcherType);
}
 
Example #6
Source File: LauncherUtils.java    From repairnator with MIT License 5 votes vote down vote up
public static void checkPushUrlArg(JSAP jsap, JSAPResult arguments, LauncherType launcherType) {
    if (getArgPushUrl(arguments) != null) {
        if (!Utils.matchesGithubRepoUrl(getArgPushUrl(arguments))) {
            System.err.println("The value of the argument pushurl is wrong.");
            LauncherUtils.printUsage(jsap, launcherType);
        }
    }
}
 
Example #7
Source File: RTLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private RTLauncher(String[] args) throws JSAPException {
    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.REALTIME);

    this.initConfig(arguments);
    this.initSerializerEngines();
    this.initNotifiers();
    this.initSummaryEmails();
}
 
Example #8
Source File: CheckBranchLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private void initConfig(JSAPResult arguments) {
    this.config = RepairnatorConfig.getInstance();

    if (LauncherUtils.getArgDebug(arguments)) {
        this.config.setDebug(true);
    }
    this.config.setRunId(LauncherUtils.getArgRunId(arguments));
    if (LauncherUtils.gerArgBearsMode(arguments)) {
        this.config.setLauncherMode(LauncherMode.BEARS);
    } else {
        this.config.setLauncherMode(LauncherMode.REPAIR);
    }
    this.config.setInputPath(LauncherUtils.getArgInput(arguments).getPath());
    this.config.setOutputPath(LauncherUtils.getArgOutput(arguments).getAbsolutePath());
    this.config.setNotifyEndProcess(LauncherUtils.getArgNotifyEndProcess(arguments));
    this.config.setSmtpServer(LauncherUtils.getArgSmtpServer(arguments));
    this.config.setSmtpPort(LauncherUtils.getArgSmtpPort(arguments));
    this.config.setSmtpTLS(LauncherUtils.getArgSmtpTLS(arguments));
    this.config.setSmtpUsername(LauncherUtils.getArgSmtpUsername(arguments));
    this.config.setSmtpPassword(LauncherUtils.getArgSmtpPassword(arguments));
    this.config.setNotifyTo(LauncherUtils.getArgNotifyto(arguments));
    this.config.setDockerImageName(LauncherUtils.getArgDockerImageName(arguments));
    this.config.setSkipDelete(LauncherUtils.getArgSkipDelete(arguments));
    this.config.setNbThreads(LauncherUtils.getArgNbThreads(arguments));
    this.config.setGlobalTimeout(LauncherUtils.getArgGlobalTimeout(arguments));
    this.config.setHumanPatch(arguments.getBoolean("humanPatch"));
    this.config.setRepository(arguments.getString("repository"));
}
 
Example #9
Source File: Main.java    From nopol with GNU General Public License v2.0 5 votes vote down vote up
private boolean parseArguments(String[] args) {
	JSAPResult jsapConfig = jsap.parse(args);
	if (!jsapConfig.success()) {
		System.err.println();
		for (Iterator<?> errs = jsapConfig.getErrorMessageIterator(); errs.hasNext(); ) {
			System.err.println("Error: " + errs.next());
		}
		showUsage();
		return false;
	}
	String[] sources = jsapConfig.getStringArray("source");
	final File[] sourceFiles = new File[sources.length];
	for (int i = 0; i < sources.length; i++) {
		String path = sources[i];
		File sourceFile = FileLibrary.openFrom(path);
		sourceFiles[i] = sourceFile;
	}

	final URL[] classpath = JavaLibrary.classpathFrom(jsapConfig.getString("classpath"));

	this.nopolContext = new NopolContext(sourceFiles, classpath, jsapConfig.getStringArray("test"));

	nopolContext.setType(strToStatementType(jsapConfig.getString("type")));
	nopolContext.setMode(strToMode(jsapConfig.getString("mode")));
	nopolContext.setSynthesis(strToSynthesis(jsapConfig.getString("synthesis")));
	nopolContext.setOracle(strToOracle(jsapConfig.getString("oracle")));
	nopolContext.setSolver(strToSolver(jsapConfig.getString("solver")));
	if (jsapConfig.getString("solverPath") != null) {
		nopolContext.setSolverPath(jsapConfig.getString("solverPath"));
		SolverFactory.setSolver(nopolContext.getSolver(), nopolContext.getSolverPath());
	}
	nopolContext.setComplianceLevel(jsapConfig.getInt("complianceLevel", nopolContext.getComplianceLevel())); 
	nopolContext.setMaxTimeInMinutes(jsapConfig.getInt("maxTime", nopolContext.getMaxTimeInMinutes()));
	nopolContext.setMaxTimeEachTypeOfFixInMinutes(jsapConfig.getLong("maxTimeType",nopolContext.getMaxTimeEachTypeOfFixInMinutes()));

	nopolContext.setLocalizer(strToLocalizer(jsapConfig.getString("faultLocalization")));
	nopolContext.setOutputFolder(jsapConfig.getString("outputFolder"));
	nopolContext.setJson(jsapConfig.getBoolean("outputJson", false));
	return true;
}
 
Example #10
Source File: BranchLauncher.java    From repairnator with MIT License 5 votes vote down vote up
public static void main(String[] args) throws JSAPException {
	JSAP jsap = defineBasicArgs();
	JSAPResult jsapResult = jsap.parse(args);
	
	MainProcess mainProcess = getMainProcess(jsap,args);
	mainProcess.run();
}
 
Example #11
Source File: PermutedFrontCodedStringList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, ClassNotFoundException, JSAPException {

		SimpleJSAP jsap = new SimpleJSAP( PermutedFrontCodedStringList.class.getName(), "Builds a permuted front-coded list of strings using a given front-coded string list and permutation",  
				new Parameter[] {
					new Switch( "invert", 'i', "invert", "Invert permutation before creating the permuted list." ),
					new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.REQUIRED, "A front-coded string list." ),
					new UnflaggedOption( "permutation", JSAP.STRING_PARSER, JSAP.REQUIRED, "A permutation for the indices of the list." ),
					new UnflaggedOption( "permutedList", JSAP.STRING_PARSER, JSAP.REQUIRED, "A the filename for the resulting permuted list." ),
			} );

		JSAPResult jsapResult = jsap.parse( arg ); 
		if ( jsap.messagePrinted() ) return;
		
		int[] basePermutation =  BinIO.loadInts( jsapResult.getString( "permutation" ) ), permutation;
		if ( jsapResult.getBoolean( "invert" ) ) {
			int i = basePermutation.length;
			permutation = new int[ i ];
			while( i-- != 0 ) permutation[ basePermutation[ i ] ] = i;
		}
		else permutation = basePermutation;
		
		basePermutation = null;
		
		BinIO.storeObject( 
				new PermutedFrontCodedStringList( (FrontCodedStringList)BinIO.loadObject( jsapResult.getString( "list" ) ), permutation ), 
				jsapResult.getString( "permutedList" ) 
		);
	}
 
Example #12
Source File: ShiftAddXorSignedStringMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main( final String[] arg ) throws NoSuchMethodException, IOException, JSAPException, ClassNotFoundException {

	final SimpleJSAP jsap = new SimpleJSAP( ShiftAddXorSignedStringMap.class.getName(), "Builds a shift-add-xor signed string map by reading a newline-separated list of strings and a function built on the same list of strings.",
			new Parameter[] {
		new FlaggedOption( "bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read strings." ),
		new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The string file encoding." ),
		new Switch( "zipped", 'z', "zipped", "The string list is compressed in gzip format." ),
		new FlaggedOption( "width", JSAP.INTEGER_PARSER, Integer.toString( Integer.SIZE ), JSAP.NOT_REQUIRED, 'w', "width", "The signature width in bits." ),
		new UnflaggedOption( "function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the function to be signed." ),
		new UnflaggedOption( "map", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the resulting serialised signed string map." ),
		new UnflaggedOption( "stringFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "Read strings from this file instead of standard input." ),
	});

	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;

	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final String functionName = jsapResult.getString( "function" );
	final String mapName = jsapResult.getString( "map" );
	final String stringFile = jsapResult.getString( "stringFile" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	final int width = jsapResult.getInt( "width" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );

	final InputStream inputStream = stringFile != null ? new FileInputStream( stringFile ) : System.in;
	final Iterator<MutableString> iterator = new LineIterator( new FastBufferedReader( new InputStreamReader( zipped ? new GZIPInputStream( inputStream ) : inputStream, encoding ), bufferSize ) );
	final Object2LongFunction<CharSequence> function = (Object2LongFunction<CharSequence>)BinIO.loadObject( functionName );
	LOGGER.info( "Signing..." );
	BinIO.storeObject( new ShiftAddXorSignedStringMap( iterator, function, width ), mapName );
	LOGGER.info( "Completed." );
}
 
Example #13
Source File: BuildAnalyzerLauncher.java    From repairnator with MIT License 5 votes vote down vote up
private BuildAnalyzerLauncher(String[] args) throws JSAPException {
    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.DOCKERPOOL);

    this.initConfig(arguments);
    this.initSerializerEngines();
    this.initNotifiers();
}
 
Example #14
Source File: LegacyLauncher.java    From repairnator with MIT License 5 votes vote down vote up
public LegacyLauncher(String[] args) throws JSAPException {
    InputStream propertyStream = getClass().getResourceAsStream("/version.properties");
    Properties properties = new Properties();
    if (propertyStream != null) {
        try {
            properties.load(propertyStream);
        } catch (IOException e) {
            LOGGER.error("Error while loading property file.", e);
        }
        LOGGER.info("PIPELINE VERSION: "+properties.getProperty("PIPELINE_VERSION"));
    } else {
        LOGGER.info("No information about PIPELINE VERSION has been found.");
    }

    JSAP jsap = this.defineArgs();
    JSAPResult arguments = jsap.parse(args);
    LauncherUtils.checkArguments(jsap, arguments, LauncherType.PIPELINE);
    this.initConfig(arguments);

    if (this.getConfig().getLauncherMode() == LauncherMode.REPAIR) {
        this.checkToolsLoaded(jsap);
        this.checkNopolSolverPath(jsap);
        LOGGER.info("The pipeline will try to repair the following build id: "+this.getConfig().getBuildId());
    } else {
        this.checkNextBuildId(jsap);
        LOGGER.info("The pipeline will try to reproduce a bug from build "+this.getConfig().getBuildId()+" and its corresponding patch from build "+this.getConfig().getNextBuildId());
    }

    if (this.getConfig().isDebug()) {
        Utils.setLoggersLevel(Level.DEBUG);
    } else {
        Utils.setLoggersLevel(Level.INFO);
    }

    this.initSerializerEngines();
    this.initNotifiers();
}
 
Example #15
Source File: FrontCodedStringList.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {
	
	final SimpleJSAP jsap = new SimpleJSAP( FrontCodedStringList.class.getName(), "Builds a front-coded string list reading from standard input a newline-separated ordered list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", IntSizeStringParser.getParser(), "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new FlaggedOption( "ratio", IntSizeStringParser.getParser(), "4", JSAP.NOT_REQUIRED, 'r',  "ratio", "The compression ratio." ),
				new Switch( "utf8", 'u', "utf8", "Store the strings as UTF-8 byte arrays." ),
				new Switch( "zipped", 'z', "zipped", "The term list is compressed in gzip format." ),
				new UnflaggedOption( "frontCodedList", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised front-coded list." )
	});
	
	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;
	
	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final int ratio = jsapResult.getInt( "ratio" );
	final boolean utf8 = jsapResult.getBoolean( "utf8" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );
	final String listName = jsapResult.getString( "frontCodedList" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	
	final ProgressLogger pl = new ProgressLogger();
	pl.itemsName = "words";
	pl.start( "Reading words..." );
	final FrontCodedStringList frontCodedStringList = new FrontCodedStringList( new LineIterator( new FastBufferedReader( 
			new InputStreamReader( zipped ? new GZIPInputStream( System.in ) : System.in, encoding ), bufferSize ), pl ), ratio, utf8 );
	pl.done();

	System.err.print( "Writing to file..." );
	BinIO.storeObject( frontCodedStringList, listName );
	System.err.println( " done." );
}
 
Example #16
Source File: Launcher.java    From repairnator with MIT License 5 votes vote down vote up
public static void main(String[] args) throws JSAPException{
    JSAP jsap = defineBasicArgs();
    JSAPResult jsapResult = jsap.parse(args); 
    String choice = jsapResult.getString("launcherChoice");

    if (choice.equals("OLD") ) {
        launcher = new LegacyLauncher(args);
    } else {
        launcher = new BranchLauncher(args);
    }
    RepairnatorConfig.getInstance().setSonarRules(removeDuplicatesInArray(jsapResult.getString("sonarRules").split(",")));
    launcher.launch();
}
 
Example #17
Source File: Launcher.java    From repairnator with MIT License 5 votes vote down vote up
public static void init(String[] args) throws JSAPException{
    JSAP jsap = defineBasicArgs();
    JSAPResult res = jsap.parse(args);
    String choice = res.getString("launcherChoice");
    if (choice.equals("OLD")) {
        launcher = new LegacyLauncher(args);
    } else {
        launcher = new BranchLauncher(args);
    }
}
 
Example #18
Source File: RandomReadWritesTest.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws JSAPException, IOException, InterruptedException {
	final SimpleJSAP jsap = new SimpleJSAP(RandomReadWritesTest.class.getName(), "Writes some random records on disk.",
		new Parameter[] {
			new FlaggedOption("random", JSAP.INTEGER_PARSER, "100", JSAP.NOT_REQUIRED, 'r', "random", "The number of random record to sample from."),
			new FlaggedOption("body", JSAP.INTSIZE_PARSER, "4K", JSAP.NOT_REQUIRED, 'b', "body", "The maximum size of the random generated body (in bytes)."),
			new Switch("fully", 'f', "fully", "Whether to read fully the record (and do a minimal sequential cosnsistency check)."),
			new Switch("writeonly", 'w', "writeonly", "Whether to skip the read part (if present, 'fully' will be ignored."),
			new UnflaggedOption("path", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The path to write to."),
			new UnflaggedOption("records", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The numer of records to write."),
	});

	final JSAPResult jsapResult = jsap.parse(args);
	if (jsap.messagePrinted()) System.exit(1);

	final String path = jsapResult.getString("path");
	final boolean compress = path.endsWith(".gz");
	final boolean fully = jsapResult.getBoolean("fully");
	final int parallel = compress ? 1 : 0;

	final int body = jsapResult.getInt("body");

	final WarcRecord[] rnd = prepareRndRecords(jsapResult.getInt("random"), RESPONSE_PROBABILITY, MAX_NUMBER_OF_HEADERS, MAX_LENGTH_OF_HEADER, body);
	final int[] sequence = writeRecords(path, jsapResult.getInt("records"), rnd, parallel);
	if (! jsapResult.getBoolean("writeonly"))
		readRecords(path, sequence, body, fully, compress);

}
 
Example #19
Source File: HttpResponseWarcRecordTest.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static void main(String[] arg) throws JSAPException, URISyntaxException, NoSuchAlgorithmException, ClientProtocolException, IOException, InterruptedException, ConfigurationException, IllegalArgumentException, ClassNotFoundException {

		SimpleJSAP jsap = new SimpleJSAP(HttpResponseWarcRecordTest.class.getName(), "Outputs an URL (given as argument) as the UncompressedWarcWriter would do",
			new Parameter[] {
				new UnflaggedOption("url", JSAP.STRING_PARSER, JSAP.REQUIRED, "The url of the page."),
			});

		JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) System.exit(1);

		final String url = jsapResult.getString("url");

		final URI uri = new URI(url);
		final WarcWriter writer = new UncompressedWarcWriter(System.out);

		// Setup FetchData
		final RuntimeConfiguration testConfiguration = Helpers.getTestConfiguration(null);
		final HttpClient httpClient = FetchDataTest.getHttpClient(null, false);
		final FetchData fetchData = new FetchData(testConfiguration);

		fetchData.fetch(uri, httpClient, null, null, false);
		final HttpResponseWarcRecord record = new HttpResponseWarcRecord(uri, fetchData.response());
		writer.write(record);
		fetchData.close();
		System.out.println(record);

		writer.close();
	}
 
Example #20
Source File: TernaryIntervalSearchTree.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {

		final SimpleJSAP jsap = new SimpleJSAP( TernaryIntervalSearchTree.class.getName(), "Builds a ternary interval search tree reading from standard input a newline-separated list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", JSAP.INTSIZE_PARSER, "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new UnflaggedOption( "tree", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised tree." )
		});

		JSAPResult jsapResult = jsap.parse( arg );
		if ( jsap.messagePrinted() ) return;

		final TernaryIntervalSearchTree tree = new TernaryIntervalSearchTree();
		
		MutableString term = new MutableString();
		final ProgressLogger pl = new ProgressLogger();
		pl.itemsName = "terms";
		final FastBufferedReader terms = new FastBufferedReader( new InputStreamReader( System.in, (Charset)jsapResult.getObject( "encoding" ) ), jsapResult.getInt( "bufferSize" ) );
				
		pl.start( "Reading terms..." );

		while( terms.readLine( term ) != null ) {
			pl.update();
			tree.add( term );
		}

		pl.done();

		BinIO.storeObject( tree, jsapResult.getString( "tree" ) );
	}
 
Example #21
Source File: LiterallySignedStringMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static void main( final String[] arg ) throws IOException, JSAPException, ClassNotFoundException, SecurityException, NoSuchMethodException {

	final SimpleJSAP jsap = new SimpleJSAP( LiterallySignedStringMap.class.getName(), "Builds a shift-add-xor signed string map by reading a newline-separated list of strings and a function built on the same list of strings.",
			new Parameter[] {
		new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The string file encoding." ),
		new Switch( "zipped", 'z', "zipped", "The string list is compressed in gzip format." ),
		new Switch( "text", 't', "text", "The string list actually a text file, with one string per line." ),
		new UnflaggedOption( "function", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the function to be signed." ),
		new UnflaggedOption( "list", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the serialised list of strings, or of a text file containing a list of strings, if -t is specified." ),
		new UnflaggedOption( "map", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename of the resulting map." ),
	});

	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;

	final String functionName = jsapResult.getString( "function" );
	final String listName = jsapResult.getString( "list" );
	final String mapName = jsapResult.getString( "map" );

	
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );
	final boolean zipped = jsapResult.getBoolean( "zipped" );
	final boolean text = jsapResult.getBoolean( "text" );
	
	ObjectList<MutableString> list = text ? new FileLinesCollection( listName, encoding.toString(), zipped ).allLines() : (ObjectList)BinIO.loadObject( listName );
	
	LOGGER.info( "Signing..." );
	BinIO.storeObject( new LiterallySignedStringMap( (Object2LongFunction)BinIO.loadObject( functionName ), list ), mapName );
	LOGGER.info( "Completed." );
}
 
Example #22
Source File: BloomFilter.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public static void main( final String[] arg ) throws IOException, JSAPException, NoSuchMethodException {
	
	final SimpleJSAP jsap = new SimpleJSAP( BloomFilter.class.getName(), "Creates a Bloom filter reading from standard input a newline-separated list of terms.",
			new Parameter[] {
				new FlaggedOption( "bufferSize", IntSizeStringParser.getParser(), "64Ki", JSAP.NOT_REQUIRED, 'b',  "buffer-size", "The size of the I/O buffer used to read terms." ),
				new FlaggedOption( "encoding", ForNameStringParser.getParser( Charset.class ), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding." ),
				new UnflaggedOption( "bloomFilter", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised front-coded list." ),
				new UnflaggedOption( "size", JSAP.INTSIZE_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The size of the filter (i.e., the expected number of elements in the filter; usually, the number of terms)." ),
				new UnflaggedOption( "precision", JSAP.INTEGER_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The precision of the filter." )
	});
	
	JSAPResult jsapResult = jsap.parse( arg );
	if ( jsap.messagePrinted() ) return;
	
	final int bufferSize = jsapResult.getInt( "bufferSize" );
	final String filterName = jsapResult.getString( "bloomFilter" );
	final Charset encoding = (Charset)jsapResult.getObject( "encoding" );

	BloomFilter filter = new BloomFilter( jsapResult.getInt( "size" ), jsapResult.getInt( "precision" ) );
	final ProgressLogger pl = new ProgressLogger();
	pl.itemsName = "terms";
	pl.start( "Reading terms..." );
	MutableString s = new MutableString();
	FastBufferedReader reader = new FastBufferedReader( new InputStreamReader( System.in, encoding ), bufferSize );
	while( reader.readLine( s ) != null ) { 
		filter.add( s );
		pl.lightUpdate();
	}
	pl.done();

	BinIO.storeObject( filter, filterName );
}
 
Example #23
Source File: Agent.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static void main(final String arg[]) throws Exception {
	final SimpleJSAP jsap = new SimpleJSAP(Agent.class.getName(), "Starts a BUbiNG agent (note that you must enable JMX by means of the standard Java system properties).",
			new Parameter[] {
				new FlaggedOption("weight", JSAP.INTEGER_PARSER, "1", JSAP.NOT_REQUIRED, 'w', "weight", "The agent weight."),
				new FlaggedOption("group", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'g', "group", "The JGroups group identifier (must be the same for all cooperating agents)."),
				new FlaggedOption("jmxHost", JSAP.STRING_PARSER, InetAddress.getLocalHost().getHostAddress(), JSAP.REQUIRED, 'h', "jmx-host", "The IP address (possibly specified by a host name) that will be used to expose the JMX RMI connector to other agents."),
				new FlaggedOption("rootDir", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'r', "root-dir", "The root directory."),
				new Switch("new", 'n', "new", "Start a new crawl"),
				new FlaggedOption("properties", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, 'P', "properties", "The properties used to configure the agent."),
				new UnflaggedOption("name", JSAP.STRING_PARSER, JSAP.REQUIRED, "The agent name (an identifier that must be unique across the group).")
		});

		final JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) System.exit(1);

		// JMX *must* be set up.
		final String portProperty = System.getProperty(JMX_REMOTE_PORT_SYSTEM_PROPERTY);
		if (portProperty == null) throw new IllegalArgumentException("You must specify a JMX service port using the property " + JMX_REMOTE_PORT_SYSTEM_PROPERTY);

		final String name = jsapResult.getString("name");
		final int weight = jsapResult.getInt("weight");
		final String group = jsapResult.getString("group");
		final String host = jsapResult.getString("jmxHost");
		final int port = Integer.parseInt(portProperty);

		final BaseConfiguration additional = new BaseConfiguration();
		additional.addProperty("name", name);
		additional.addProperty("group", group);
		additional.addProperty("weight", Integer.toString(weight));
		additional.addProperty("crawlIsNew", Boolean.valueOf(jsapResult.getBoolean("new")));
		if (jsapResult.userSpecified("rootDir")) additional.addProperty("rootDir", jsapResult.getString("rootDir"));

		new Agent(host, port, new RuntimeConfiguration(new StartupConfiguration(jsapResult.getString("properties"), additional)));
		System.exit(0); // Kills remaining FetchingThread instances, if any.
}
 
Example #24
Source File: LauncherUtils.java    From repairnator with MIT License 5 votes vote down vote up
public static File getArgOutput(JSAPResult arguments) {
    File output = new File(arguments.getString("output"));
    if (!output.exists()) { 
        output.mkdirs();
    }
    return output;
}
 
Example #25
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static String getArgSmtpPassword(JSAPResult arguments) {
    return arguments.getString("smtpPassword");
}
 
Example #26
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static String[] getArgNotifyto(JSAPResult arguments) {
    return arguments.getStringArray("notifyto");
}
 
Example #27
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static String getArgLogDirectory(JSAPResult arguments) {
    return arguments.getString("output");
}
 
Example #28
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static boolean getArgSkipDelete(JSAPResult arguments) {
    return arguments.getBoolean("skipDelete");
}
 
Example #29
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static int getArgNbThreads(JSAPResult arguments) {
    return arguments.getInt("threads");
}
 
Example #30
Source File: LauncherUtils.java    From repairnator with MIT License 4 votes vote down vote up
public static int getArgGlobalTimeout(JSAPResult arguments) {
    return arguments.getInt("globalTimeout");
}