Example usage for org.apache.maven.plugin.logging Log info

List of usage examples for org.apache.maven.plugin.logging Log info

Introduction

In this page you can find the example usage for org.apache.maven.plugin.logging Log info.

Prototype

void info(Throwable error);

Source Link

Document

Send an exception to the user in the info error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

From source file:net.officefloor.maven.StartOfficeBuildingGoal.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    // Ensure have configured values
    ensureNotNull("Must have project", this.project);
    ensureNotNull("Must have plug-in dependencies", this.pluginDependencies);
    ensureNotNull("Must have local repository", this.localRepository);
    ensureNotNull("Must have repository system", this.repositorySystem);
    ensureNotNull("Port not configured for the " + OfficeBuilding.class.getSimpleName(), this.port);

    // Indicate the configuration
    final Log log = this.getLog();
    log.debug(OfficeBuilding.class.getSimpleName() + " configuration:");
    log.debug("\tPort = " + this.port);

    // Create the environment properties
    Properties environment = new Properties();
    environment.putAll(this.project.getProperties());

    // Log the properties
    log.debug("\tProperties:");
    for (String propertyName : environment.stringPropertyNames()) {
        log.debug("\t\t" + propertyName + " = " + environment.getProperty(propertyName));
    }//  w  w  w .j  av a  2 s  .c o  m

    // Obtain the plugin dependency inclusions
    List<Artifact> artifactInclusions = new ArrayList<Artifact>(this.pluginDependencies.size());
    for (PluginDependencyInclusion inclusion : this.dependencyInclusions) {

        // Must match on dependency for inclusion
        Artifact includedDependency = null;
        for (Artifact dependency : this.pluginDependencies) {
            if ((inclusion.groupId.equals(dependency.getGroupId()))
                    && (inclusion.artifactId.equals(dependency.getArtifactId()))
                    && (inclusion.type.equals(dependency.getType())) && ((inclusion.classifier == null)
                            || (inclusion.classifier.equals(dependency.getClassifier())))) {
                // Found the dependency to include
                includedDependency = dependency;
            }
        }

        // Ensure have dependency for inclusion
        if (includedDependency == null) {
            throw newMojoExecutionException("Failed to obtain plug-in dependency " + inclusion.groupId + ":"
                    + inclusion.artifactId + (inclusion.classifier == null ? "" : ":" + inclusion.classifier)
                    + ":" + inclusion.type, null);

        }

        // Include the dependency
        artifactInclusions.add(includedDependency);
    }

    // Obtain the class path for OfficeBuilding
    String classPath = null;
    try {

        // Indicate the remote repositories
        log.debug("\tRemote repositories:");

        // Obtain remote repositories and load to class path factory
        List<RemoteRepository> remoteRepositories = new LinkedList<RemoteRepository>();
        List<String> urls = new LinkedList<String>();
        for (Object object : this.project.getRemoteArtifactRepositories()) {
            ArtifactRepository repository = (ArtifactRepository) object;
            String remoteRepositoryUrl = repository.getUrl();
            remoteRepositories.add(new RemoteRepository(repository.getId(), repository.getLayout().getId(),
                    remoteRepositoryUrl));
            urls.add(remoteRepositoryUrl);

            // Indicate the remote repository
            log.debug("\t\t" + remoteRepositoryUrl);
        }

        // Create the class path factory and add remote repositories
        File localRepositoryDirectory = new File(this.localRepository.getBasedir());
        ClassPathFactory classPathFactory = new ClassPathFactoryImpl(this.plexusContainer,
                this.repositorySystem, localRepositoryDirectory,
                remoteRepositories.toArray(new RemoteRepository[remoteRepositories.size()]));

        // Indicate the class path
        log.debug("\tClass path:");

        // Obtain the class path entries for each included artifact
        List<String> classPathEntries = new LinkedList<String>();
        for (Artifact dependency : artifactInclusions) {

            // Obtain the class path entries for the dependency
            String[] entries = classPathFactory.createArtifactClassPath(dependency.getGroupId(),
                    dependency.getArtifactId(), dependency.getVersion(), dependency.getType(),
                    dependency.getClassifier());

            // Uniquely include the class path entries
            for (String entry : entries) {
                if (classPathEntries.contains(entry)) {
                    continue; // ignore as already included
                }
                classPathEntries.add(entry);

                // Indicate class path entry
                log.debug("\t\t" + entry);
            }
        }

        // Obtain the class path
        classPath = ClassPathFactoryImpl.transformClassPathEntriesToClassPath(
                classPathEntries.toArray(new String[classPathEntries.size()]));

    } catch (Exception ex) {
        throw newMojoExecutionException("Failed obtaining dependencies for launching OfficeBuilding", ex);
    }

    // Create the process configuration
    ProcessConfiguration configuration = new ProcessConfiguration();
    configuration.setAdditionalClassPath(classPath);

    // Write output to file
    configuration.setProcessOutputStreamFactory(new ProcessOutputStreamFactory() {

        @Override
        public OutputStream createStandardProcessOutputStream(String processNamespace, String[] command)
                throws IOException {

            // Log the command
            StringBuilder commandLine = new StringBuilder();
            commandLine.append(OfficeBuilding.class.getSimpleName() + " command line:");
            for (String commandItem : command) {
                commandLine.append(" ");
                commandLine.append(commandItem);
            }
            log.debug(commandLine);

            // Return the output stream
            return this.getOutputStream(processNamespace);
        }

        @Override
        public OutputStream createErrorProcessOutputStream(String processNamespace) throws IOException {
            return this.getOutputStream(processNamespace);
        }

        /**
         * Lazy instantiated {@link OutputStream}.
         */
        private OutputStream outputStream = null;

        /**
         * Obtains the {@link OutputStream}.
         * 
         * @param processNamespace
         *            Process name space.
         * @return {@link OutputStream}.
         * @throws IOException
         *             If fails to obtain the {@link OutputStream}.
         */
        private synchronized OutputStream getOutputStream(String processNamespace) throws IOException {

            // Lazy instantiate the output stream
            if (this.outputStream == null) {

                // Create the output file
                File file = File.createTempFile(processNamespace, ".log");
                this.outputStream = new FileOutputStream(file);

                // Log that outputting to file
                log.info("Logging " + OfficeBuilding.class.getSimpleName() + " output to file "
                        + file.getAbsolutePath());
            }

            // Return the output stream
            return this.outputStream;
        }
    });

    // Start the OfficeBuilding
    try {
        OfficeBuildingManager.spawnOfficeBuilding(null, this.port.intValue(), getKeyStoreFile(),
                KEY_STORE_PASSWORD, USER_NAME, PASSWORD, null, false, environment, null, true, configuration);
    } catch (Throwable ex) {
        // Provide details of the failure
        final String MESSAGE = "Failed starting the " + OfficeBuilding.class.getSimpleName();
        this.getLog().error(MESSAGE + ": " + ex.getMessage() + " [" + ex.getClass().getSimpleName() + "]");
        this.getLog().error("DIAGNOSIS INFORMATION:");
        this.getLog().error("   classpath='" + System.getProperty("java.class.path") + "'");
        this.getLog().error("   additional classpath='" + classPath + "'");

        // Propagate the failure
        throw newMojoExecutionException(MESSAGE, ex);
    }

    // Log started OfficeBuilding
    this.getLog().info("Started " + OfficeBuilding.class.getSimpleName() + " on port " + this.port.intValue());
}

From source file:net.oneandone.maven.plugins.prerelease.core.Archive.java

License:Apache License

/**
 * @param timeout in seconds; -1 to try only once and never wait.
 * @param log may be null/*from   w w  w. j ava2s .  c o  m*/
 */
private void open(int timeout, Log log) throws IOException {
    FileNode file;
    int seconds;

    if (opened) {
        throw new IllegalStateException();
    }
    file = lockFile();
    try {
        seconds = 0;
        while (true) {
            // every time - if someone wiped the primary storage directory
            file.getParent().mkdirsOpt();
            try {
                file.mkfile();
                OnShutdown.get().deleteAtExit(file);
                opened = true;
                file.writeString(Integer.toString(pid()));
                if (log != null) {
                    log.debug("locked for pid " + pid());
                }
                return;
            } catch (MkfileException e) {
                if (seconds > timeout) {
                    if (log != null) {
                        log.warn("Lock timed out after " + seconds + "s.");
                    }
                    throw e;
                }
                if (seconds % 10 == 0) {
                    if (log != null) {
                        log.info("Waiting for " + file + ": " + seconds + "s");
                        log.debug(e);
                    }
                }
                seconds++;
                Thread.sleep(1000);
            }
        }
    } catch (InterruptedException e) {
        if (log != null) {
            log.warn("interrupted");
        }
    }
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public static Prerelease create(Maven maven, Map<String, String> propertyArgs, Log log, Descriptor descriptor,
        Target target) throws Exception {
    Prerelease prerelease;/*from  w  w w .  ja va 2s. com*/
    FileNode tags;
    FileNode checkout;
    String tagname;
    String tagbase;
    int idx;

    log.info("creating un-committed tag ...");
    if (descriptor.svnTag.endsWith("/")) {
        throw new IllegalArgumentException(descriptor.svnTag);
    }
    idx = descriptor.svnTag.lastIndexOf('/');
    if (idx == -1) {
        throw new IllegalArgumentException(descriptor.svnTag);
    }
    tagbase = descriptor.svnTag.substring(0, idx);
    tagname = descriptor.svnTag.substring(idx + 1);
    target.create();
    try {
        tags = target.join("tags");
        checkout = tags.join(tagname);
        log.debug(target.svnLauncher("checkout", "--depth=empty", tagbase, tags.getAbsolute()).exec());
        log.debug(target
                .svnLauncher("copy", "-r" + descriptor.revision, descriptor.svnOrig, checkout.getAbsolute())
                .exec());
        prerelease = new Prerelease(target, checkout, descriptor);
        prerelease.descriptor.save(target);
        Transform.adjustPom(prerelease.checkout.join("pom.xml"), descriptor.previous,
                descriptor.project.version, descriptor.svnOrig, descriptor.svnTag);
        Archive.adjustChangesOpt(prerelease.checkout, prerelease.descriptor.project.version);
        prerelease.create(maven, propertyArgs);
        log.info("created prerelease in " + prerelease.target);
    } catch (Exception e) {
        target.scheduleRemove(log, "create failed: " + e.getMessage());
        throw e;
    }
    return prerelease;
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public void commit(Log log, String commitMessage) throws Failure {

    Launcher launcher;//  w  w  w . java 2s .c om

    log.info("committing tag:");
    launcher = Subversion.launcher(checkout, "commit", "-m", commitMessage);
    log.info(launcher.toString());
    log.info(launcher.exec());
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public void revertCommit(Log log, String by) throws Failure {
    Launcher launcher;/*ww w . j  a  va2 s  .c om*/

    launcher = Subversion.launcher(checkout, "delete",
            "-m reverted promotion of prerelease " + descriptor.revision + " promoted by " + by,
            descriptor.svnTag);
    log.info(launcher.toString());
    log.info(launcher.exec());
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public FileNode prepareOrigCommit(Log log)
        throws IOException, XmlException, SAXException, MojoExecutionException {
    FileNode result;//from   w  w w  . j a  v a2  s  . co  m
    ChangesXml changes;

    result = checkout.getWorld().getTemp().createTempDirectory();
    Subversion.sparseCheckout(log, result, descriptor.svnOrig, "HEAD", true);
    try {
        changes = ChangesXml.load(result);
    } catch (FileNotFoundException e) {
        log.info("no changes.xml to adjust.");
        changes = null;
    }

    Subversion.launcher(result, "lock", "pom.xml");
    if (changes != null) {
        Subversion.launcher(result, "lock", ChangesXml.PATH);
    }

    // make sure the version we've locked is what we will modify:
    // (or in other words: make sure we see possible changes that were committed between checkout and lock)
    Subversion.launcher(result, "up");

    Transform.adjustPom(result.join("pom.xml"), descriptor.previous, descriptor.next, null, null);
    if (changes != null) {
        changes.releaseDate(descriptor.project.version, new Date());
        changes.save();
    }
    // svn up does not fail for none-existing files!
    return result;
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public void check(Log log, Map<String, String> propertyArgs, Maven maven) throws Exception {
    log.info("prerelease checks for " + descriptor.project);
    maven.build(checkout, descriptor.releaseProps(propertyArgs), FilteringMojoExecutor.CHECK, "install");
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

public void promote(Log log, Map<String, String> propertyArgs, String createTagMessage, String revertTagMessage,
        String nextIterationMessage, Maven maven) throws Exception {
    FileNode origCommit;/*  w ww  . j av a  2s  .  c om*/

    check(log, propertyArgs, maven);
    log.info("promoting revision " + descriptor.revision + " to " + descriptor.project);
    origCommit = prepareOrigCommit(log);
    try {
        promoteLocked(log, propertyArgs, createTagMessage, revertTagMessage, nextIterationMessage, origCommit,
                maven);
    } catch (Throwable e) { // CAUTION: catching exceptions is not enough -- in particular, out-of-memory during upload is an error!
        try {
            origUnlock(origCommit);
        } catch (Exception nested) {
            e.addSuppressed(nested);
        }
        throw e;
    }
    origUnlock(origCommit);
    log.info("SUCCESS: released " + descriptor.project);
}

From source file:net.oneandone.maven.plugins.prerelease.core.Prerelease.java

License:Apache License

/** commit before deploy - because if deployment fails, we can reliably revert the commit. */
private void promoteLocked(Log log, Map<String, String> propertyArgs, String commitTagMessage,
        String revertTagMessage, String commitNextMessage, FileNode origCommit, Maven maven) throws Exception {
    FileNode installed;//ww w . j a  va  2  s .co  m

    commit(log, renderMessage(commitTagMessage));
    try {
        maven.deployPrerelease(log, propertyArgs, this);
    } catch (Exception e) {
        log.info("deployment failed - reverting tag");
        revertCommit(log, renderMessage(revertTagMessage));
        target.scheduleRemove(log, "deployment failed (tag has been reverted): " + e.getMessage());
        throw e;
    }

    // local install
    installed = descriptor.project.localRepo(maven);
    installed.deleteTreeOpt();
    artifacts().move(installed);

    try {
        log.info("Update pom and changes ...");
        log.debug(Subversion.launcher(origCommit, "commit", "-m", renderMessage(commitNextMessage)).exec());
        origCommit.deleteTree();
        // Move prerelease directory into REMOVE directory because it's invalid now:
        // tag was committed, and artifacts have been deployed. It's not removed immediately to make
        // distribution file available locally.
        target.scheduleRemove(log, "prerelease has been promoted");
    } catch (Exception e) {
        log.warn("Promote succeeded: your artifacts have been deployed, and your svn tag was created. ");
        log.warn("However, some post-release step failed with this exception:");
        log.warn(e);
        log.warn("Thus, you can use your release, but someone should have a look at this exception.");
    }
}

From source file:net.oneandone.maven.plugins.prerelease.core.Target.java

License:Apache License

public void scheduleRemove(Log log, String message) throws IOException {
    FileNode remove;/*  w w w .  j a v  a 2 s .  c o m*/

    remove = removeDirectory();
    log.info(message + " - moving prerelease to " + remove);
    directory.move(remove);
    remove.join("CAUSE").writeString(message);
    directory = remove;
}