Search in sources :

Example 1 with Error

use of aQute.struct.struct.Error in project bnd by bndtools.

the class Main method _install.

/**
	 * A better way to install
	 */
@Description("Install an artifact from a url, file, or http://www.jpm4j.org")
public void _install(installOptions opts) throws Exception {
    if (!this.options.user() && !jpm.hasAccess()) {
        error("No write acces, might require administrator or root privileges (sudo in *nix)");
        return;
    }
    for (String coordinate : opts._arguments()) {
        logger.debug("install {}", coordinate);
        File file = IO.getFile(base, coordinate);
        if (file.isFile()) {
            coordinate = file.toURI().toString();
            logger.debug("is existing file: {}", coordinate);
        }
        ArtifactData artifact = jpm.getCandidate(coordinate);
        logger.debug("candidate {}", artifact);
        if (artifact == null) {
            if (jpm.isWildcard(coordinate))
                error("no candidate found for %s", coordinate);
            else
                error("no candidate found for %s, you could try %s@* to also see staged and withdrawn revisions", coordinate, coordinate);
        } else {
            if (!opts.ignore()) {
                CommandData cmd = jpm.parseCommandData(artifact);
                updateCommandData(cmd, opts);
                logger.debug("main={}, name={}", cmd.main, cmd.name);
                if (cmd.main != null) {
                    if (cmd.name == null && !artifact.local) {
                        cmd.name = artifact.coordinate.getArtifactId();
                    }
                    List<Error> errors = cmd.validate();
                    if (!errors.isEmpty()) {
                        error("Command not valid");
                        for (Error error : errors) {
                            error("[%s] %s %s %s %s", error.code, error.description, error.path, error.failure, error.value);
                        }
                    } else {
                        String result = jpm.createCommand(cmd, opts.force());
                        if (result != null) {
                            error("[%s] %s", coordinate, result);
                        }
                    }
                } else
                    error("No main class found. Please specify");
            }
        }
    }
}
Also used : Error(aQute.struct.struct.Error) CommandData(aQute.jpm.lib.CommandData) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ArtifactData(aQute.jpm.lib.ArtifactData) Description(aQute.lib.getopt.Description)

Aggregations

ArtifactData (aQute.jpm.lib.ArtifactData)1 CommandData (aQute.jpm.lib.CommandData)1 Description (aQute.lib.getopt.Description)1 Error (aQute.struct.struct.Error)1 File (java.io.File)1 RandomAccessFile (java.io.RandomAccessFile)1