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

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

Introduction

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

Prototype

boolean isDebugEnabled();

Source Link

Usage

From source file:org.codehaus.mojo.license.LicenseMap.java

License:Open Source License

public SortedSet<MavenProject> getUnsafeDependencies() {

    Log log = getLog();
    // get unsafe dependencies (says with no license)
    SortedSet<MavenProject> unsafeDependencies = get(getUnknownLicenseMessage());

    if (log.isDebugEnabled()) {
        if (CollectionUtils.isEmpty(unsafeDependencies)) {
            log.debug("There is no dependency with no license from poms.");
        } else {/*from   ww w.  ja  v a 2s .c  om*/
            log.debug("There is " + unsafeDependencies.size() + " dependencies with no license from poms : ");
            for (MavenProject dep : unsafeDependencies) {

                // no license found for the dependency
                log.debug(" - " + ArtifactHelper.getArtifactId(dep.getArtifact()));
            }
        }
    }

    return unsafeDependencies;
}

From source file:org.codehaus.mojo.pomtools.wrapper.reflection.BeanFields.java

License:Apache License

public BeanFields(String fieldFullName, Object objectToInspect) {
    this.fieldFullName = fieldFullName;

    PomToolsPluginContext context = PomToolsPluginContext.getInstance();

    Log log = context.getLog();

    PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(objectToInspect);

    for (int i = 0; i < descriptors.length; i++) {
        PropertyDescriptor pd = descriptors[i];

        FieldConfiguration config = context
                .getFieldConfiguration(ModelHelper.buildFullName(fieldFullName, pd.getName()));
        if (pd.getWriteMethod() != null && (config == null || !config.isIgnore())) {
            if (log.isDebugEnabled()) {
                log.debug("Property: " + ModelHelper.buildFullName(fieldFullName, pd.getName()) + " => "
                        + pd.getPropertyType().getName());
            }/*w  ww  .  j a v a2s  .c om*/

            if (pd.getPropertyType().equals(String.class)) {
                add(new StringField(fieldFullName, pd.getName()));
            } else if (pd.getPropertyType().equals(boolean.class)) {
                add(new BooleanField(fieldFullName, pd.getName()));
            } else if (pd.getPropertyType().equals(List.class)) {
                addListField(pd, objectToInspect);
            } else if (pd.getPropertyType().equals(Properties.class)) {
                add(new PropertiesBeanField(fieldFullName, pd.getName()));
            } else {
                add(new CompositeField(fieldFullName, pd.getName(), pd.getPropertyType()));
            }
        }
    }

}

From source file:org.codehaus.mojo.rpm.RPMHelper.java

License:Apache License

/**
 * Gets the default host vendor for system by executing <i>rpm -E %{_host_vendor}</i>.
 *//*from   www. j av  a  2  s. c  o m*/
public String getHostVendor() throws MojoExecutionException {
    final Log log = mojo.getLog();

    final Commandline cl = new Commandline();
    cl.setExecutable("rpm");
    cl.addArguments(new String[] { "-E", "%{_host_vendor}" });

    final StringStreamConsumer stdout = new StringStreamConsumer();
    final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log);
    try {
        if (log.isDebugEnabled()) {
            log.debug("About to execute \'" + cl.toString() + "\'");
        }

        int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
        if (result != 0) {
            throw new MojoExecutionException("RPM query for default vendor returned: \'" + result
                    + "\' executing \'" + cl.toString() + "\'");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Unable to query for default vendor from RPM", e);
    }

    return stdout.getOutput().trim();
}

From source file:org.codehaus.mojo.rpm.RPMHelper.java

License:Apache License

/**
 * Run the external command to build the package.
 * <p>//from  ww w. j  a  v  a2  s.c om
 * Uses the following attributes from the {@link #mojo}:
 * <ul>
 * <li>{@link AbstractRPMMojo#getBuildroot() build root}</li>
 * <li>{@link AbstractRPMMojo#getKeyname() key name}</li>
 * <li>{@link AbstractRPMMojo#getKeyPassphrase() key passphrase}</li>
 * <li>{@link AbstractRPMMojo#getName() name}</li>
 * <li>{@link AbstractRPMMojo#getRPMFile() rpm file}</li>
 * <li>{@link AbstractRPMMojo#getTargetArch() target arch}</li>
 * <li>{@link AbstractRPMMojo#getTargetOS() target OS}</li>
 * <li>{@link AbstractRPMMojo#getTargetVendor() target vendor}</li>
 * <li>{@link AbstractRPMMojo#getWorkarea() workarea}</li>
 * </ul>
 * </p>
 *
 * @throws MojoExecutionException if an error occurs
 */
public void buildPackage() throws MojoExecutionException {
    final File workarea = mojo.getWorkarea();
    final File f = new File(workarea, "SPECS");

    final Commandline cl = new Commandline();
    cl.setExecutable("rpmbuild");
    cl.setWorkingDirectory(f.getAbsolutePath());
    cl.createArg().setValue(mojo.getRpmbuildStage());
    cl.createArg().setValue("--target");
    cl.createArg().setValue(mojo.getTargetArch() + '-' + mojo.getTargetVendor() + '-' + mojo.getTargetOS());
    cl.createArg().setValue("--buildroot");
    cl.createArg().setValue(FileHelper.toUnixPath(mojo.getRPMBuildroot()));
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_topdir " + FileHelper.toUnixPath(workarea));

    // Don't assume default values for rpm path macros
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_build_name_fmt %%{ARCH}/%%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm");
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_builddir %{_topdir}/BUILD");
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_rpmdir %{_topdir}/RPMS");
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_sourcedir %{_topdir}/SOURCES");
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_specdir %{_topdir}/SPECS");
    cl.createArg().setValue("--define");
    cl.createArg().setValue("_srcrpmdir %{_topdir}/SRPMS");

    // maintain passive behavior for keyPassphrase not being present
    final String keyname = mojo.getKeyname();
    final File keypath = mojo.getKeypath();
    final Passphrase keyPassphrase = mojo.getKeyPassphrase();
    if (keyname != null && keyPassphrase == null) {
        cl.createArg().setValue("--define");
        cl.createArg().setValue("_gpg_name " + keyname);
        if (keypath != null) {
            cl.createArg().setValue("--define");
            cl.createArg().setValue("_gpg_path " + keypath);
        }
        cl.createArg().setValue("--sign");
    }

    cl.createArg().setValue(mojo.getName() + ".spec");

    final Log log = mojo.getLog();

    final StreamConsumer stdout = new LogStreamConsumer(LogStreamConsumer.INFO, log);
    final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log);
    try {
        if (log.isDebugEnabled()) {
            log.debug("About to execute \'" + cl.toString() + "\'");
        }

        int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
        if (result != 0) {
            throw new MojoExecutionException(
                    "RPM build execution returned: \'" + result + "\' executing \'" + cl.toString() + "\'");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Unable to build the RPM", e);
    }

    // now if the passphrase has been provided and we want to try and sign automatically
    if (keyname != null && keyPassphrase != null) {
        RPMSigner signer = new RPMSigner(keypath, keyname, keyPassphrase.getPassphrase(), log);

        try {
            signer.sign(mojo.getRPMFile());
        } catch (Exception e) {
            throw new MojoExecutionException("Unable to sign RPM", e);
        }
    }
}

From source file:org.codehaus.mojo.rpm.RPMHelper.java

License:Apache License

/**
 * Evaluates the <i>macro</i> by executing <code>rpm --eval %<i>macro</i></code>.
 *
 * @param macro The macro to evaluate./*from w w  w . ja  v  a2s  .  c o  m*/
 * @return The result of rpm --eval.
 * @throws MojoExecutionException
 * @since 2.1-alpha-1
 */
public String evaluateMacro(String macro) throws MojoExecutionException {
    final Commandline cl = new Commandline();
    cl.setExecutable("rpm");
    cl.createArg().setValue("--eval");
    cl.createArg().setValue('%' + macro);

    final Log log = mojo.getLog();

    final StringStreamConsumer stdout = new StringStreamConsumer();
    final StreamConsumer stderr = new LogStreamConsumer(LogStreamConsumer.INFO, log);
    try {
        if (log.isDebugEnabled()) {
            log.debug("About to execute \'" + cl.toString() + "\'");
        }

        int result = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
        if (result != 0) {
            throw new MojoExecutionException(
                    "rpm --eval returned: \'" + result + "\' executing \'" + cl.toString() + "\'");
        }
    } catch (CommandLineException e) {
        throw new MojoExecutionException("Unable to evaluate macro: " + macro, e);
    }

    return stdout.getOutput().trim();
}

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

License:Apache License

/**
 * Outputs a debug message with a list of modules.
 *
 * @param logger  The logger to log to./* w ww. j  a va 2  s. c o m*/
 * @param message The message to display.
 * @param modules The modules to append to the message.
 */
public static void debugModules(Log logger, String message, Collection modules) {
    Iterator i;
    if (logger.isDebugEnabled()) {
        logger.debug(message);
        if (modules.isEmpty()) {
            logger.debug("None.");
        } else {
            i = modules.iterator();
            while (i.hasNext()) {
                logger.debug("  " + i.next());
            }
        }

    }
}

From source file:org.codehaus.mojo.versions.utils.WagonUtils.java

License:Apache License

/**
 * Convenience method to create a wagon.
 *
 * @param serverId     The serverId to use if the wagonManager needs help.
 * @param url          The url to create a wagon for.
 * @param wagonManager The wgaon manager to use.
 * @param settings     The settings to use.
 * @param logger       The logger to use.
 * @return The wagon to connect to the url.
 * @throws org.apache.maven.wagon.UnsupportedProtocolException
 *          if the protocol is not supported.
 * @throws org.apache.maven.artifact.manager.WagonConfigurationException
 *          if the wagon cannot be configured.
 * @throws org.apache.maven.wagon.ConnectionException
 *          If the connection cannot be established.
 * @throws org.apache.maven.wagon.authentication.AuthenticationException
 *          If the connection cannot be authenticated.
 *///from w  ww.jav a 2  s  .  c  om
public static Wagon createWagon(String serverId, String url, WagonManager wagonManager, Settings settings,
        Log logger) throws UnsupportedProtocolException, WagonConfigurationException, ConnectionException,
        AuthenticationException {
    Repository repository = new Repository(serverId, url);
    Wagon wagon = wagonManager.getWagon(repository);

    if (logger.isDebugEnabled()) {
        Debug debug = new Debug();
        wagon.addSessionListener(debug);
        wagon.addTransferListener(debug);
    }

    ProxyInfo proxyInfo = getProxyInfo(settings);
    if (proxyInfo != null) {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()), proxyInfo);
    } else {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()));
    }
    return wagon;
}

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;//from   w w w . j  av  a2 s.c  o  m
    }

    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);/* w ww  . j  a v a2 s .c om*/
        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.wagon.shared.WagonUtils.java

License:Apache License

/**
 * Convenient method to create a wagon/*from   w  w w  . j  a v a  2 s  .  c om*/
 * 
 * @param id
 * @param url
 * @param wagonManager
 * @param settings
 * @param logger
 * @return
 * @throws MojoExecutionException
 */
public static Wagon createWagon(String id, String url, WagonManager wagonManager, Settings settings, Log logger)
        throws WagonException, UnsupportedProtocolException, WagonConfigurationException {
    Wagon wagon = null;

    final Repository repository = new Repository(id, url);

    wagon = wagonManager.getWagon(repository);

    if (logger.isDebugEnabled()) {
        Debug debug = new Debug();
        wagon.addSessionListener(debug);
        wagon.addTransferListener(debug);
    }

    ProxyInfo proxyInfo = getProxyInfo(settings);
    if (proxyInfo != null) {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()), proxyInfo);
    } else {
        wagon.connect(repository, wagonManager.getAuthenticationInfo(repository.getId()));
    }

    return wagon;
}