Search in sources :

Example 71 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project hudson-2.x by hudson.

the class Launcher method main.

public static void main(String... args) throws Exception {
    Launcher launcher = new Launcher();
    CmdLineParser parser = new CmdLineParser(launcher);
    try {
        parser.parseArgument(args);
        launcher.run();
    } catch (CmdLineException e) {
        System.err.println(e.getMessage());
        System.err.println("java -jar slave.jar [options...]");
        parser.printUsage(System.err);
        System.err.println();
    }
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 72 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project buck by facebook.

the class AdditionalOptionsCmdLineParser method parseAdditionalOptions.

@SuppressWarnings("unchecked")
private void parseAdditionalOptions(ClassParser classParser, Object bean, Set<Class<?>> visited) {
    // so an empty visited set means we're parsing the top-level bean.
    if (!visited.isEmpty()) {
        // 'Parse' the class of the bean looking for annotations.
        classParser.parse(bean, this);
    }
    Class<?> beanClass = bean.getClass();
    if (visited.contains(beanClass)) {
        throw new IllegalAnnotationError(beanClass.getCanonicalName() + " used more than once.");
    } else {
        visited.add(beanClass);
    }
    for (Field f : beanClass.getDeclaredFields()) {
        if (f.isAnnotationPresent(AdditionalOptions.class)) {
            try {
                // TODO(mrkane27): nicer to do this lazily in parseArgument()
                Object fieldValue = f.getType().newInstance();
                Setters.create(f, bean).addValue(fieldValue);
                parseAdditionalOptions(classParser, fieldValue, visited);
            } catch (CmdLineException | IllegalAccessException | InstantiationException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) IllegalAnnotationError(org.kohsuke.args4j.IllegalAnnotationError) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 73 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project gitblit by gitblit.

the class FederationClient method main.

public static void main(String[] args) {
    Params params = new Params();
    CmdLineParser parser = new CmdLineParser(params);
    try {
        parser.parseArgument(args);
    } catch (CmdLineException t) {
        usage(parser, t);
    }
    System.out.println("Gitblit Federation Client v" + Constants.getVersion() + " (" + Constants.getBuildDate() + ")");
    // command-line specified base folder
    File baseFolder = new File(System.getProperty("user.dir"));
    if (!StringUtils.isEmpty(params.baseFolder)) {
        baseFolder = new File(params.baseFolder);
    }
    File regFile = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, baseFolder, params.registrationsFile);
    FileSettings settings = new FileSettings(regFile.getAbsolutePath());
    List<FederationModel> registrations = new ArrayList<FederationModel>();
    if (StringUtils.isEmpty(params.url)) {
        registrations.addAll(FederationUtils.getFederationRegistrations(settings));
    } else {
        if (StringUtils.isEmpty(params.token)) {
            System.out.println("Must specify --token parameter!");
            System.exit(0);
        }
        FederationModel model = new FederationModel("Gitblit");
        model.url = params.url;
        model.token = params.token;
        model.mirror = params.mirror;
        model.bare = params.bare;
        model.folder = "";
        registrations.add(model);
    }
    if (registrations.size() == 0) {
        System.out.println("No Federation Registrations!  Nothing to do.");
        System.exit(0);
    }
    // command-line specified repositories folder
    if (!StringUtils.isEmpty(params.repositoriesFolder)) {
        settings.overrideSetting(Keys.git.repositoriesFolder, new File(params.repositoriesFolder).getAbsolutePath());
    }
    // configure the Gitblit singleton for minimal, non-server operation
    XssFilter xssFilter = new AllowXssFilter();
    RuntimeManager runtime = new RuntimeManager(settings, xssFilter, baseFolder).start();
    NoopNotificationManager notifications = new NoopNotificationManager().start();
    UserManager users = new UserManager(runtime, null).start();
    RepositoryManager repositories = new RepositoryManager(runtime, null, users).start();
    FederationManager federation = new FederationManager(runtime, notifications, repositories).start();
    IGitblit gitblit = new GitblitManager(null, null, runtime, null, notifications, users, null, repositories, null, federation, null);
    FederationPullService puller = new FederationPullService(gitblit, federation.getFederationRegistrations()) {

        @Override
        public void reschedule(FederationModel registration) {
        // NOOP
        }
    };
    puller.run();
    System.out.println("Finished.");
    System.exit(0);
}
Also used : FederationModel(com.gitblit.models.FederationModel) CmdLineParser(org.kohsuke.args4j.CmdLineParser) GitblitManager(com.gitblit.manager.GitblitManager) FederationManager(com.gitblit.manager.FederationManager) ArrayList(java.util.ArrayList) RuntimeManager(com.gitblit.manager.RuntimeManager) IGitblit(com.gitblit.manager.IGitblit) FederationPullService(com.gitblit.service.FederationPullService) UserManager(com.gitblit.manager.UserManager) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) XssFilter(com.gitblit.utils.XssFilter) AllowXssFilter(com.gitblit.utils.XssFilter.AllowXssFilter) RepositoryManager(com.gitblit.manager.RepositoryManager) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 74 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project gitblit by gitblit.

the class MigrateTickets method main.

public static void main(String... args) {
    MigrateTickets migrate = new MigrateTickets();
    // filter out the baseFolder parameter
    List<String> filtered = new ArrayList<String>();
    String folder = "data";
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("--baseFolder")) {
            if (i + 1 == args.length) {
                System.out.println("Invalid --baseFolder parameter!");
                System.exit(-1);
            } else if (!".".equals(args[i + 1])) {
                folder = args[i + 1];
            }
            i = i + 1;
        } else {
            filtered.add(arg);
        }
    }
    Params.baseFolder = folder;
    Params params = new Params();
    CmdLineParser parser = new CmdLineParser(params);
    try {
        parser.parseArgument(filtered);
        if (params.help) {
            migrate.usage(parser, null);
            return;
        }
    } catch (CmdLineException t) {
        migrate.usage(parser, t);
        return;
    }
    // load the settings
    FileSettings settings = params.FILESETTINGS;
    if (!StringUtils.isEmpty(params.settingsfile)) {
        if (new File(params.settingsfile).exists()) {
            settings = new FileSettings(params.settingsfile);
        }
    }
    // migrate tickets
    migrate.migrate(new File(Params.baseFolder), settings, params.outputServiceName);
    System.exit(0);
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) ArrayList(java.util.ArrayList) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 75 with CmdLineException

use of org.kohsuke.args4j.CmdLineException in project gitblit by gitblit.

the class ReindexTickets method main.

public static void main(String... args) {
    ReindexTickets reindex = new ReindexTickets();
    // filter out the baseFolder parameter
    List<String> filtered = new ArrayList<String>();
    String folder = "data";
    for (int i = 0; i < args.length; i++) {
        String arg = args[i];
        if (arg.equals("--baseFolder")) {
            if (i + 1 == args.length) {
                System.out.println("Invalid --baseFolder parameter!");
                System.exit(-1);
            } else if (!".".equals(args[i + 1])) {
                folder = args[i + 1];
            }
            i = i + 1;
        } else {
            filtered.add(arg);
        }
    }
    Params.baseFolder = folder;
    Params params = new Params();
    CmdLineParser parser = new CmdLineParser(params);
    try {
        parser.parseArgument(filtered);
        if (params.help) {
            reindex.usage(parser, null);
            return;
        }
    } catch (CmdLineException t) {
        reindex.usage(parser, t);
        return;
    }
    // load the settings
    FileSettings settings = params.FILESETTINGS;
    if (!StringUtils.isEmpty(params.settingsfile)) {
        if (new File(params.settingsfile).exists()) {
            settings = new FileSettings(params.settingsfile);
        }
    }
    // reindex tickets
    reindex.reindex(new File(Params.baseFolder), settings);
    System.exit(0);
}
Also used : CmdLineParser(org.kohsuke.args4j.CmdLineParser) ArrayList(java.util.ArrayList) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException)

Aggregations

CmdLineException (org.kohsuke.args4j.CmdLineException)105 CmdLineParser (org.kohsuke.args4j.CmdLineParser)80 IOException (java.io.IOException)16 File (java.io.File)14 ArrayList (java.util.ArrayList)11 PrintStream (java.io.PrintStream)7 StringWriter (java.io.StringWriter)6 List (java.util.List)5 FileOutputStream (java.io.FileOutputStream)4 Path (java.nio.file.Path)4 CmdLineParser (com.google.gerrit.util.cli.CmdLineParser)3 FeatureExtractors (io.anserini.ltr.feature.FeatureExtractors)3 Qrels (io.anserini.util.Qrels)3 Directory (org.apache.lucene.store.Directory)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 ConsoleReporter (com.codahale.metrics.ConsoleReporter)2 MetricRegistry (com.codahale.metrics.MetricRegistry)2 Project (com.google.gerrit.reviewdb.client.Project)2 OrmException (com.google.gwtorm.server.OrmException)2 Hudson (hudson.model.Hudson)2