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:org.codehaus.mojo.sonar.ServerMetadata.java

License:Open Source License

public void logSettings(Log log) throws MojoExecutionException {
    try {//from   w ww. j  av  a 2 s . c  o m
        log.info("Sonar version: " + getVersion());

    } catch (IOException e) {
        throw new MojoExecutionException(
                "Sonar server can not be reached at " + url + ". Please check the parameter 'sonar.host.url'.");
    }
}

From source file:org.codehaus.mojo.unix.maven.MojoHelper.java

License:Open Source License

public static <UP extends UnixPackage<UP, PP>, PP extends UnixPackage.PreparedPackage> Execution create(
        Map platforms, String platformType, String formatType, MavenProjectWrapper project, boolean debug,
        boolean attachedMode, F<UP, UP> validateMojoSettingsAndApplyFormatSpecificSettingsToPackage,
        PackagingMojoParameters mojoParameters, final Log log)
        throws MojoFailureException, MojoExecutionException {
    PackagingFormat<UP> format = PackagingFormat.lookup(formatType);

    if (format == null) {
        throw new MojoFailureException("INTERNAL ERROR: could not find format: '" + formatType + "'.");
    }//from  ww  w .  j av  a  2s.c o m

    UnixPlatform platform = (UnixPlatform) platforms.get(platformType);

    if (platform == null) {
        throw new MojoFailureException("INTERNAL ERROR: could not find platform: '" + platformType + "'.");
    }

    /*
    // TODO: This is using a private Maven API that might change. Perhaps use some reflection magic here.
    String timestamp = snapshotTransformation.getDeploymentTimestamp();
    */

    // This chunk replaces the above getDeploymentTimestamp. However, it not ensure that all files get the
    // same timestamp. Need to look into how this is done with Maven 3
    DateFormat utcDateFormatter = new SimpleDateFormat("yyyyMMdd.HHmmss");
    utcDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
    String timestamp = utcDateFormatter.format(new Date());

    LocalFs buildDirectory = new LocalFs(project.buildDirectory);

    PackageVersion version = PackageVersion.packageVersion(project.version, timestamp,
            project.artifact.isSnapshot(), mojoParameters.revision);

    List<P3<UP, Package, List<AssemblyOperation>>> packages = nil();

    for (Package pakke : validatePackages(mojoParameters.packages, attachedMode)) {
        try {
            String name = "unix/root-" + formatType + pakke.classifier.map(dashString).orSome("");

            LocalFs packageRoot = buildDirectory.resolve(name);
            packageRoot.mkdir();

            PackageParameters parameters = calculatePackageParameters(project, version, platform,
                    mojoParameters, pakke);

            UP unixPackage = format.start(log).parameters(parameters).setVersion(version). // TODO: This should go away
                    workingDirectory(packageRoot).debug(debug).basedir(project.basedir);

            // -----------------------------------------------------------------------
            // Let the implementation add its metadata
            // -----------------------------------------------------------------------

            unixPackage = validateMojoSettingsAndApplyFormatSpecificSettingsToPackage.f(unixPackage);

            // TODO: here the logic should be different if many packages are to be created.
            // Example: name should be taken from mojoParameters if there is only a single package, if not
            //          it should come from the Pakke object. This should also be validated, at least for
            //          name

            List<AssemblyOperation> assemblyOperations = createAssemblyOperations(project, parameters,
                    unixPackage, project.basedir, buildDirectory, mojoParameters.assembly, pakke.assembly);

            // -----------------------------------------------------------------------
            // Dump the execution
            // -----------------------------------------------------------------------

            if (debug) {
                log.info("=======================================================================");
                log.info("Package parameters: " + parameters.id);
                log.info("Default file attributes: ");
                log.info(" File      : " + parameters.defaultFileAttributes);
                log.info(" Directory : " + parameters.defaultDirectoryAttributes);

                log.info("Assembly operations: ");
                for (AssemblyOperation operation : assemblyOperations) {
                    operation.streamTo(new AbstractLineStreamWriter() {
                        protected void onLine(String line) {
                            log.info(line);
                        }
                    });
                }
            }

            packages = packages.cons(p(unixPackage, pakke, assemblyOperations));
        } catch (UnknownArtifactException e) {
            Map map = new TreeMap<String, Artifact>(e.artifactMap);

            // TODO: Do not log here, throw a CouldNotFindArtifactException with the map as an argument
            log.warn("Could not find artifact:" + e.artifact);
            log.warn("Available artifacts:");
            for (Object o : map.keySet()) {
                log.warn(o.toString());
            }

            throw new MojoFailureException(
                    "Unable to find artifact: '" + e.artifact + "'. See log for available artifacts.");
        } catch (MissingSettingException e) {
            String msg = "Missing required setting '" + e.getSetting() + "'";
            if (!pakke.classifier.isNone()) {
                msg += ", for '" + pakke.classifier.some() + "'";
            }
            msg += ", format '" + formatType + "'.";
            throw new MojoFailureException(msg);
        } catch (IOException e) {
            throw new MojoExecutionException("Error creating package "
                    + (pakke.classifier.isSome() ? "classifier '" + pakke.classifier + "'" : "") + ", format '"
                    + formatType + "'.", e);
        }
    }

    return new Execution<UP>(packages, project, formatType, attachedMode);
}

From source file:org.codehaus.mojo.versions.api.PomHelper.java

License:Apache License

/**
 * Finds the local root of the specified project.
 *
 * @param project              The project to find the local root for.
 * @param localRepository      the local repo.
 * @param globalProfileManager the global profile manager.
 * @param logger               The logger to log to.
 * @return The local root (note this may be the project passed as an argument).
 *///from  w  w  w  .  j av a  2 s . c  om
public static MavenProject getLocalRoot(MavenProjectBuilder builder, MavenProject project,
        ArtifactRepository localRepository, ProfileManager globalProfileManager, Log logger) {
    logger.info("Searching for local aggregator root...");
    while (true) {
        final File parentDir = project.getBasedir().getParentFile();
        if (parentDir.isDirectory()) {
            logger.debug("Checking to see if " + parentDir + " is an aggregator parent");
            File parent = new File(parentDir, "pom.xml");
            if (parent.isFile()) {
                try {
                    final MavenProject parentProject = builder.build(parent, localRepository,
                            globalProfileManager);
                    if (getAllChildModules(parentProject, logger).contains(project.getBasedir().getName())) {
                        logger.debug(parentDir + " is an aggregator parent");
                        project = parentProject;
                        continue;
                    } else {
                        logger.debug(parentDir + " is not an aggregator parent");
                    }
                } catch (ProjectBuildingException e) {
                    logger.warn(e);
                }
            }
        }
        logger.debug("Local aggregation root is " + project.getBasedir());
        return project;
    }
}

From source file:org.codehaus.mojo.visibroker.AbstractVisiBrokerMojo.java

License:Apache License

protected static void executeCommandline(Commandline cl, Log logger) throws MojoExecutionException {
    int ok;//www  .ja v  a  2  s  .  co  m

    try {
        DefaultConsumer stdout = new DefaultConsumer();

        DefaultConsumer stderr = stdout;

        logger.info(cl.toString());

        ok = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
    } catch (CommandLineException ecx) {
        throw new MojoExecutionException("Error executing command line", ecx);
    }

    if (ok != 0) {
        throw new MojoExecutionException("Error executing command line. Exit code:" + ok);
    }
}

From source file:org.codehaus.mojo.wagon.shared.DefaultMavenRepoMerger.java

License:Apache License

private void mergeMetadata(File existingMetadata, Log logger) throws IOException, XmlPullParserException {

    Writer stagedMetadataWriter = null;
    Reader existingMetadataReader = null;
    Reader stagedMetadataReader = null;
    File stagedMetadataFile = null;

    try {/*from  w  w  w. ja v a 2 s  . com*/
        MetadataXpp3Reader xppReader = new MetadataXpp3Reader();
        MetadataXpp3Writer xppWriter = new MetadataXpp3Writer();

        // Existing Metadata in target stage
        existingMetadataReader = new FileReader(existingMetadata);
        Metadata existing = xppReader.read(existingMetadataReader);

        // Staged Metadata
        stagedMetadataFile = new File(existingMetadata.getParentFile(), MAVEN_METADATA);
        stagedMetadataReader = new FileReader(stagedMetadataFile);
        Metadata staged = xppReader.read(stagedMetadataReader);

        // Merge and write back to staged metadata to replace the remote one
        existing.merge(staged);

        stagedMetadataWriter = new FileWriter(stagedMetadataFile);
        xppWriter.write(stagedMetadataWriter, existing);

        logger.info("Merging metadata file: " + stagedMetadataFile);

    } finally {
        IOUtil.close(stagedMetadataWriter);
        IOUtil.close(stagedMetadataReader);
        IOUtil.close(existingMetadataReader);

        existingMetadata.delete();
    }

    // Mark all metadata as in-process and regenerate the checksums as they will be different
    // after the merger

    try {
        File newMd5 = new File(stagedMetadataFile.getParentFile(), MAVEN_METADATA + ".md5");
        FileUtils.fileWrite(newMd5.getAbsolutePath(), checksum(stagedMetadataFile, MD5));

        File newSha1 = new File(stagedMetadataFile.getParentFile(), MAVEN_METADATA + ".sha1");
        FileUtils.fileWrite(newSha1.getAbsolutePath(), checksum(stagedMetadataFile, SHA1));
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }

    // We have the new merged copy so we're good

}

From source file:org.codehaus.mojo.wagon.shared.DefaultWagonDownload.java

License:Apache License

public List getFileList(Wagon wagon, WagonFileSet fileSet, Log logger) throws WagonException {
    logger.info("Scanning remote file system: " + wagon.getRepository().getUrl() + " ...");

    WagonDirectoryScanner dirScan = new WagonDirectoryScanner();
    dirScan.setWagon(wagon);//from   w w  w .  j  a v  a  2s  . c om
    dirScan.setExcludes(fileSet.getExcludes());
    dirScan.setIncludes(fileSet.getIncludes());
    dirScan.setCaseSensitive(fileSet.isCaseSensitive());
    dirScan.setDirectory(fileSet.getDirectory());
    if (fileSet.isUseDefaultExcludes()) {
        dirScan.addDefaultExcludes();
    }

    dirScan.scan();

    return dirScan.getFilesIncluded();
}

From source file:org.codehaus.mojo.wagon.shared.DefaultWagonDownload.java

License:Apache License

public void download(Wagon wagon, WagonFileSet remoteFileSet, Log logger) throws WagonException {
    List fileList = this.getFileList(wagon, remoteFileSet, logger);

    String url = wagon.getRepository().getUrl() + "/";

    if (fileList.size() == 0) {
        logger.info("Nothing to download.");
        return;/*from w  w  w .j a v  a2s. co m*/
    }

    for (Iterator iterator = fileList.iterator(); iterator.hasNext();) {
        String remoteFile = (String) iterator.next();

        File destination = new File(remoteFileSet.getDownloadDirectory() + "/" + remoteFile);

        if (!StringUtils.isBlank(remoteFileSet.getDirectory())) {
            remoteFile = remoteFileSet.getDirectory() + "/" + remoteFile;
        }

        logger.info("Downloading " + url + remoteFile + " to " + destination + " ...");

        wagon.get(remoteFile, destination);
    }
}

From source file:org.codehaus.mojo.wagon.shared.DefaultWagonUpload.java

License:Apache License

public void upload(Wagon wagon, FileSet fileset, Log logger) throws WagonException {

    FileSetManager fileSetManager = new FileSetManager(logger, logger.isDebugEnabled());

    String[] files = fileSetManager.getIncludedFiles(fileset);

    String url = wagon.getRepository().getUrl() + "/";

    if (files.length == 0) {
        logger.info("Nothing to upload.");
        return;//www  .  j  ava 2  s  . c  om
    }

    for (int i = 0; i < files.length; ++i) {
        String relativeDestPath = StringUtils.replace(files[i], "\\", "/");

        if (!StringUtils.isBlank(fileset.getOutputDirectory())) {
            relativeDestPath = fileset.getOutputDirectory() + "/" + relativeDestPath;
        }

        File source = new File(fileset.getDirectory(), files[i]);

        logger.info("Uploading " + source + " to " + url + relativeDestPath + " ...");

        wagon.put(source, relativeDestPath);
    }

}

From source file:org.codehaus.mojo.wagon.shared.DefaultWagonUpload.java

License:Apache License

public void upload(Wagon wagon, FileSet fileset, boolean optimize, Log logger)
        throws WagonException, IOException {
    if (!optimize) {
        upload(wagon, fileset, logger);//from  w  w w .j  av a  2s .c  o  m
        return;
    }

    if (!(wagon instanceof CommandExecutor)) {
        throw new UnsupportedProtocolException(
                "Wagon " + wagon.getRepository().getProtocol() + " does not support optimize upload");
    }

    logger.info("Uploading " + fileset);

    File zipFile;
    zipFile = File.createTempFile("wagon", ".zip");

    try {
        FileSetManager fileSetManager = new FileSetManager(logger, logger.isDebugEnabled());
        String[] files = fileSetManager.getIncludedFiles(fileset);

        if (files.length == 0) {
            logger.info("Nothing to upload.");
            return;
        }

        logger.info("Creating " + zipFile + " ...");
        createZip(files, zipFile, fileset.getDirectory());

        String remoteFile = zipFile.getName();
        String remoteDir = fileset.getOutputDirectory();
        if (!StringUtils.isBlank(remoteDir)) {
            remoteFile = remoteDir + "/" + remoteFile;
        }

        logger.info(
                "Uploading " + zipFile + " to " + wagon.getRepository().getUrl() + "/" + remoteFile + " ...");
        wagon.put(zipFile, remoteFile);

        // We use the super quiet option here as all the noise seems to kill/stall the connection
        String command = "unzip -o -qq -d " + remoteDir + " " + remoteFile;

        try {
            logger.info("Remote: " + command);
            ((CommandExecutor) wagon).executeCommand(command);
        } finally {
            command = "rm -f " + remoteFile;
            logger.info("Remote: " + command);

            ((CommandExecutor) wagon).executeCommand(command);
        }

    } finally {
        zipFile.delete();
    }

}

From source file:org.codehaus.mojo.webstart.generator.AbstractGenerator.java

License:Apache License

protected AbstractGenerator(Log log, GeneratorTechnicalConfig config, C extraConfig) {

    this.log = log;
    this.config = config;
    this.extraConfig = extraConfig;

    Properties props = new Properties();

    String inputFileTemplatePath = config.getInputFileTemplatePath();

    if (inputFileTemplatePath != null) {
        props.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM_CLASS,
                "org.apache.velocity.runtime.log.NullLogSystem");
        props.setProperty("file.resource.loader.path", config.getResourceLoaderPath().getAbsolutePath());

        initVelocity(props);//from  ww  w  .ja  v  a  2 s. c o  m

        if (!engine.templateExists(inputFileTemplatePath)) {
            log.warn("Warning, template not found. Will probably fail.");
        }
    } else {
        log.info("No template specified Using default one.");

        inputFileTemplatePath = config.getDefaultTemplateResourceName();

        String webstartJarURL = config.getWebstartJarURL();
        log.debug("***** Webstart JAR URL: " + webstartJarURL);

        props = new Properties();
        props.setProperty("resource.loader", "jar");
        props.setProperty("jar.resource.loader.description",
                "Jar resource loader for default webstart templates");
        props.setProperty("jar.resource.loader.class",
                "org.apache.velocity.runtime.resource.loader.JarResourceLoader");
        props.setProperty("jar.resource.loader.path", webstartJarURL);

        initVelocity(props);

        if (!engine.templateExists(inputFileTemplatePath)) {
            log.error("Inbuilt template not found!! " + config.getDefaultTemplateResourceName()
                    + " Will probably fail.");
        }
    }

    try {
        this.velocityTemplate = engine.getTemplate(inputFileTemplatePath, config.getEncoding());
    } catch (Exception e) {
        IllegalArgumentException iae = new IllegalArgumentException(
                "Could not load the template file from '" + inputFileTemplatePath + "'");
        iae.initCause(e);
        throw iae;
    }
}