Search in sources :

Example 1 with Platform

use of aQute.jpm.platform.Platform in project bnd by bndtools.

the class Main method _jpm.

/**
	 * Initialize the repository and other global vars.
	 * 
	 * @param opts the options
	 * @throws IOException
	 */
@Description("Just Another Package Manager for Java (\"jpm help jpm\" to see a list of global options)")
public void _jpm(JpmOptions opts) throws IOException {
    try {
        setExceptions(opts.exceptions());
        setTrace(opts.trace());
        setPedantic(opts.pedantic());
        Platform platform = Platform.getPlatform(this, opts.os());
        if (opts.base() != null)
            base = IO.getFile(base, opts.base());
        if (opts.settings() != null) {
            settings = new Settings(opts.settings());
            logger.debug("Using settings file: {}", opts.settings());
        } else {
            settings = new Settings(platform.getConfigFile());
            logger.debug("Using settings file: {}", platform.getConfigFile());
        }
        File homeDir;
        File binDir;
        String home = settings.get(JPM_CONFIG_HOME);
        String bin = settings.get(JPM_CONFIG_BIN);
        if (opts.home() != null) {
            logger.debug("home set");
            homeDir = IO.getFile(base, opts.home());
            binDir = new File(homeDir, "bin");
        } else if (opts.user()) {
            logger.debug("user set");
            homeDir = platform.getLocal();
            binDir = new File(homeDir, "bin");
        } else if (!opts.global() && home != null) {
            logger.debug("global or in settings");
            homeDir = new File(home);
            binDir = new File(bin);
        } else {
            logger.debug("default");
            homeDir = platform.getGlobal();
            binDir = platform.getGlobalBinDir();
        }
        logger.debug("home={}, bin={}", homeDir, binDir);
        if (opts.bindir() != null) {
            logger.debug("bindir set");
            binDir = new File(opts.bindir());
            if (!binDir.isAbsolute())
                binDir = new File(base, opts.bindir());
            binDir = binDir.getAbsoluteFile();
        } else if (bin != null && !opts.user() && !opts.global()) {
            binDir = new File(bin);
        }
        logger.debug("home={}, bin={}", homeDir, binDir);
        url = opts.library();
        if (url == null)
            url = settings.get("library.url");
        jpm = new JustAnotherPackageManager(this, platform, homeDir, binDir);
        platform.setJpm(jpm);
        jpm.setLibrary(url == null ? null : new URI(url));
        try {
            this.options = opts;
            if (opts.xtesting())
                jpm.setUnderTest();
            CommandLine handler = opts._command();
            List<String> arguments = opts._arguments();
            if (arguments.isEmpty()) {
                Justif j = new Justif();
                Formatter f = j.formatter();
                handler.help(f, this);
                err.println(j.wrap());
            } else {
                String cmd = arguments.remove(0);
                String help = handler.execute(this, cmd, arguments);
                if (help != null) {
                    err.println(help);
                }
            }
            if (options.width() > 0)
                this.width = options.width();
        } finally {
            jpm.close();
        }
    } catch (InvocationTargetException t) {
        Throwable tt = t;
        while (tt instanceof InvocationTargetException) tt = ((InvocationTargetException) tt).getTargetException();
        exception(tt, "%s", tt);
    } catch (Throwable t) {
        exception(t, "Failed %s", t);
    } finally {
        // Check if we need to wait for it to finish
        if (opts.key()) {
            System.out.println("Hit a key to continue ...");
            System.in.read();
        }
    }
    if (!check(opts.failok())) {
        System.exit(getErrors().size());
    }
}
Also used : JustAnotherPackageManager(aQute.jpm.lib.JustAnotherPackageManager) CommandLine(aQute.lib.getopt.CommandLine) Platform(aQute.jpm.platform.Platform) Justif(aQute.lib.justif.Justif) Formatter(java.util.Formatter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) URI(java.net.URI) Settings(aQute.lib.settings.Settings) InvocationTargetException(java.lang.reflect.InvocationTargetException) Description(aQute.lib.getopt.Description)

Aggregations

JustAnotherPackageManager (aQute.jpm.lib.JustAnotherPackageManager)1 Platform (aQute.jpm.platform.Platform)1 CommandLine (aQute.lib.getopt.CommandLine)1 Description (aQute.lib.getopt.Description)1 Justif (aQute.lib.justif.Justif)1 Settings (aQute.lib.settings.Settings)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URI (java.net.URI)1 Formatter (java.util.Formatter)1