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:com.igormaznitsa.mvngolang.cvs.AbstractRepo.java

License:Apache License

public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder,
        @Nonnull @MustNotContainNull final String... args) {
    final List<String> cli = new ArrayList<String>();
    cli.add(GetUtils.findFirstNonNull(customCommand, this.command));
    for (final String s : args) {
        cli.add(s);/*from  ww w . jav  a2  s . c o  m*/
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Executing repo command : " + cli);
    }

    final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    final ProcessExecutor executor = new ProcessExecutor(cli);

    int result = -1;

    try {
        final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream)
                .redirectOutput(outStream).executeNoTimeout();
        result = processResult.getExitValue();

        if (logger.isDebugEnabled()) {
            logger.debug("Exec.out.........................................");
            logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset()));
            logger.debug(".................................................");
        }

        if (result != 0) {
            logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset()));
        }

    } catch (Exception ex) {
        logger.error("Unexpected error", ex);
    }

    return result;
}

From source file:com.kaaprotech.satu.mojo.SatuMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    final Log log = getLog();

    if (log.isDebugEnabled()) {
        for (String e : excludes) {
            log.debug("SATU: Exclude: " + e);
        }// w  w w  .  j a va 2  s  . com

        for (String e : includes) {
            log.debug("SATU: Include: " + e);
        }

        log.debug("SATU: Output: " + outputDirectory);
    }

    if (!sourceDirectory.isDirectory()) {
        log.info("SATU: Root source directory doesn't exist " + sourceDirectory.getAbsolutePath());
        return;
    }

    log.info("SATU: Processing root source directory " + sourceDirectory.getAbsolutePath());

    log.debug("Output root directory is " + outputDirectory.getAbsolutePath());

    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();
    }

    final List<File> satuModelFiles;
    try {
        satuModelFiles = getSatuModelDefinitionFiles();
    } catch (InclusionScanException e) {
        log.error(e);
        throw new MojoExecutionException("Error occured finding the Satu model definition files", e);
    }

    log.info("Compiling " + satuModelFiles.size() + " Satu model definition files to "
            + outputDirectory.getAbsolutePath());

    final SatuToJava generator = new SatuToJava(outputDirectory.getAbsolutePath());

    Exception exception = null;
    for (File file : satuModelFiles) {
        try {
            generator.generate(file.getPath(), encoding, jsonCompatible);
        } catch (Exception e) {
            if (exception == null) {
                exception = e;
            }
            log.error("Failed to generate code for Satu model definition " + file.getPath(), e);
        }
    }

    if (exception != null) {
        throw new MojoExecutionException("Error occured generating code for Sata model definition files",
                exception);
    }

    if (project != null) {
        project.addCompileSourceRoot(outputDirectory.getPath());
    }
}

From source file:com.monday_consulting.maven.plugins.fsm.util.PrototypeXml.java

License:Apache License

public PrototypeXml(final Log log, final File prototypeXml) throws XmlPullParserException, IOException {
    this.dependencyJointList = new ArrayList<PrototypeXml.DependencyJoint>();
    this.log = log;
    this.prototypeDom = Xpp3DomBuilder.build(new XmlStreamReader(prototypeXml));
    if (log.isDebugEnabled())
        this.log.debug("Getting dependency-joints\nDependency-Joints to fill:");

    for (final Xpp3Dom xpp3Dom : new Xpp3DomIterator(prototypeDom)) {
        if (xpp3Dom.getName().equals("dependencies")) {
            if (xpp3Dom.getValue().equals("")) {
                log.error(//from  ww w  . jav  a  2  s.  com
                        "Prototype-Xml-Error:\nTried to retrieve dependency-joint, but because its value was empty, no connection to a module can be made");
            }
            dependencyJointList.add(new DependencyJoint(xpp3Dom.getValue(), xpp3Dom));
            if (log.isDebugEnabled())
                log.debug("\t" + xpp3Dom.getValue());
        }
    }
}

From source file:com.puresoltechnologies.maven.plugins.license.AbstractValidationMojo.java

/**
 * Loads the artifact recursively.//from  w ww  .  j  a va2s.  c o m
 * 
 * @param artifact
 * @param recursive
 *            specified whether all dependencies should be loaded
 *            recursively.
 * @param skipTestScope
 *            specified whether to skip test scoped artifacts or not.
 * @return A {@link DependencyTree} object is returned.
 * @throws MojoExecutionException
 *             is thrown if anything unexpected goes wrong.
 */
private DependencyTree loadArtifacts(int depth, DependencyTree parentDependencyTree, Artifact artifact,
        boolean recursive, boolean skipTestScope, boolean skipProvidedScope, boolean skipOptionals)
        throws MojoExecutionException {
    Log log = getLog();
    MavenProject parentArtifactProject;
    try {
        parentArtifactProject = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories,
                localRepository);
    } catch (ProjectBuildingException e) {
        log.warn("Could not load artifacts recursively. For artifact '" + ArtifactUtilities.toString(artifact)
                + "' the project creation failed.", e);
        return null;
    }
    @SuppressWarnings("unchecked")
    List<Dependency> dependencies = parentArtifactProject.getDependencies();
    @SuppressWarnings("unchecked")
    List<License> licenses = parentArtifactProject.getLicenses();
    DependencyTree dependencyTree = new DependencyTree(artifact, licenses);
    if (parentDependencyTree != null) {
        parentDependencyTree.addDependency(dependencyTree);
    }
    if ((dependencies != null) && ((recursive) || (artifact == mavenProject.getArtifact()))) {
        for (Dependency dependency : dependencies) {
            StringBuffer buffer = new StringBuffer();
            if (log.isDebugEnabled()) {
                for (int i = 0; i < depth; i++) {
                    buffer.append("    ");
                }
                buffer.append("\\-> ");
                log.debug(buffer.toString() + ArtifactUtilities.toString(dependency));
            }
            if (skipTestScope && Artifact.SCOPE_TEST.equals(dependency.getScope())) {
                if (log.isDebugEnabled()) {
                    log.debug(buffer.toString() + " >> test scope is skipped");
                }
                continue;
            }
            if (skipProvidedScope && Artifact.SCOPE_PROVIDED.equals(dependency.getScope())) {
                if (log.isDebugEnabled()) {
                    log.debug(buffer.toString() + " >> provided scope is skipped");
                }
                continue;
            }
            if (skipOptionals && dependency.isOptional()) {
                if (log.isDebugEnabled()) {
                    log.debug(buffer.toString() + " >> optional is skipped");
                }
                continue;
            }
            if (hasCycle(dependencyTree, dependency)) {
                if (log.isDebugEnabled()) {
                    log.debug(buffer.toString() + " >> cylce found and needs to be skipped");
                }
                continue;
            }
            Artifact dependencyArtifact = DependencyUtilities.buildArtifact(artifact, dependency);
            loadArtifacts(depth + 1, dependencyTree, dependencyArtifact, recursive, skipTestScope,
                    skipProvidedScope, skipOptionals);
        }
    }
    return dependencyTree;
}

From source file:com.qq.tars.maven.util.ArchiveEntryUtils.java

License:Open Source License

public static void chmod(final File file, final int mode, final Log logger, boolean useJvmChmod)
        throws ArchiverException {
    if (!Os.isFamily(Os.FAMILY_UNIX)) {
        return;/*from  ww  w. j a va  2  s  .  c  o m*/
    }

    final String m = Integer.toOctalString(mode & 0xfff);

    if (useJvmChmod && !jvmFilePermAvailable) {
        logger.info("chmod it's not possible where your current jvm");
        useJvmChmod = false;
    }

    if (useJvmChmod && jvmFilePermAvailable) {
        applyPermissionsWithJvm(file, m, logger);
        return;
    }

    try {
        final Commandline commandline = new Commandline();

        commandline.setWorkingDirectory(file.getParentFile().getAbsolutePath());

        if (logger.isDebugEnabled()) {
            logger.debug(file + ": mode " + Integer.toOctalString(mode) + ", chmod " + m);
        }

        commandline.setExecutable("chmod");

        commandline.createArg().setValue(m);

        final String path = file.getAbsolutePath();

        commandline.createArg().setValue(path);

        final CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();

        final CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();

        final int exitCode = CommandLineUtils.executeCommandLine(commandline, stderr, stdout);

        if (exitCode != 0) {
            logger.warn("-------------------------------");
            logger.warn("Standard error:");
            logger.warn("-------------------------------");
            logger.warn(stderr.getOutput());
            logger.warn("-------------------------------");
            logger.warn("Standard output:");
            logger.warn("-------------------------------");
            logger.warn(stdout.getOutput());
            logger.warn("-------------------------------");

            throw new ArchiverException("chmod exit code was: " + exitCode);
        }
    } catch (final CommandLineException e) {
        throw new ArchiverException("Error while executing chmod.", e);
    }

}

From source file:com.rabbitstewdio.build.maven.tomcat.ClasspathServlet.java

License:Apache License

public ClasspathServlet(ClassLoader projectClassLoader, Log log) {
    super(log);/*  w ww  .j a  v a 2  s.  co  m*/
    this.projectClassLoader = projectClassLoader;

    if (log.isDebugEnabled()) {
        log.debug("Begin Logging Classloader for " + projectClassLoader);
        ClassLoader cl = projectClassLoader;
        while (cl.getParent() != null && cl.getParent() != cl) {
            if (cl instanceof URLClassLoader) {
                URLClassLoader ucl = (URLClassLoader) cl;
                for (URL url : ucl.getURLs()) {
                    log.info("  => " + url);
                }
            }
            log.debug("-> " + cl);
            cl = cl.getParent();
        }
        log.debug("Finished Logging Classloader for " + projectClassLoader);
    }
}

From source file:com.relativitas.maven.plugins.formatter.FormatterMojo.java

License:Apache License

/**
 * Format individual file./*  www . j a v a2 s.  c o m*/
 * 
 * @param file
 * @param rc
 * @param hashCache
 * @param basedirPath
 * @throws IOException
 * @throws BadLocationException
 */
private void doFormatFile(File file, ResultCollector rc, Properties hashCache)
        throws IOException, BadLocationException {
    Log log = getLog();
    String code = readFileAsString(file);
    String originalHash = md5hash(code);

    String canonicalPath = file.getCanonicalPath();
    String path = canonicalPath.substring(getBasedirPath().length());
    String cachedHash = hashCache.getProperty(path);
    if (cachedHash != null && cachedHash.equals(originalHash)) {
        rc.skippedCount++;
        log.debug(file.getAbsolutePath() + " is already formatted.");
        return;
    }

    String lineSeparator = getLineEnding(code);

    TextEdit te = null;
    try {
        te = getCodeFormatter().format(CodeFormatter.K_COMPILATION_UNIT + CodeFormatter.F_INCLUDE_COMMENTS,
                code, 0, code.length(), 0, lineSeparator);
    } catch (RuntimeException formatFailed) {
        log.debug("Formatting of " + file.getAbsolutePath() + " failed", formatFailed);
    } catch (MojoExecutionException e) {
        log.debug("Formatting of " + file.getAbsolutePath() + " failed", e);
    }
    if (te == null) {
        rc.skippedCount++;
        log.debug(file.getAbsolutePath()
                + " cannot be formatted. Possible cause is unmatched source/target/compliance version.");
        return;
    }

    IDocument doc = new Document(code);
    te.apply(doc);
    String formattedCode = doc.get();
    String formattedHash = md5hash(formattedCode);
    if (cachedHash == null || !cachedHash.equals(formattedHash)) {
        hashCache.setProperty(path, formattedHash);
        rc.hashUpdatedCount++;
        if (log.isDebugEnabled()) {
            log.debug("Adding hash code to cachedHash for path " + path + ":" + formattedHash);
        }
    }
    if (originalHash.equals(formattedHash)) {
        rc.skippedCount++;
        log.debug("Equal hash code for " + path + ". Not writing result to file.");
        return;
    }

    writeStringToFile(formattedCode, file);
    rc.successCount++;
}

From source file:com.sap.prd.mobile.ios.mios.LoggerMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Logger logger = LogManager.getLogManager().getLogger(AbstractXCodeMojo.class.getPackage().getName());

    if (logger == null) {
        getLog().error("Cannot setup logging infrastructure. Logger '"
                + AbstractXCodeMojo.class.getPackage().getName() + "' was null.");
    } else if (logger instanceof XCodePluginLogger) {
        XCodePluginLogger _logger = ((XCodePluginLogger) logger);
        Log mavenLogger = getLog();
        _logger.setLog(mavenLogger);/*  w  ww.  ja  va  2s  .c  o  m*/
        if (mavenLogger.isDebugEnabled()) {
            _logger.setLevel(Level.ALL);
        } else {
            _logger.setLevel(Level.INFO);
        }

        getLog().debug("Logging infrastructure has been setup.");
    } else {
        getLog().warn("Cannot setup logging infrastructure. Logger '"
                + AbstractXCodeMojo.class.getPackage().getName() + "' is not an instance of '"
                + XCodePluginLogger.class.getName() + "' It was found to be a '" + logger.getClass().getName()
                + "'. Will use reasonable defaults.");

        if (XCodePluginLogger.class.getName().equals(logger.getClass().getName())) {
            getLog().warn("ClassLoader of current logger is: " + logger.getClass().getClassLoader()
                    + ". ClassLoder of " + XCodePluginLogger.class.getName() + " is "
                    + XCodePluginLogger.class.getClassLoader() + ".");
        }
    }
}

From source file:com.sri.vt.majic.util.clean.Cleaner.java

License:Apache License

/**
 * Creates a new cleaner.//from  ww w  .  j  a  v a  2s .com
 * 
 * @param log The logger to use, may be <code>null</code> to disable logging.
 * @param verbose Whether to perform verbose logging.
 */
public Cleaner(final Log log, boolean verbose) {
    logDebug = (log == null || !log.isDebugEnabled()) ? null : new Logger() {
        public void log(CharSequence message) {
            log.debug(message);
        }
    };

    logInfo = (log == null || !log.isInfoEnabled()) ? null : new Logger() {
        public void log(CharSequence message) {
            log.info(message);
        }
    };

    logWarn = (log == null || !log.isWarnEnabled()) ? null : new Logger() {
        public void log(CharSequence message) {
            log.warn(message);
        }
    };

    logVerbose = verbose ? logInfo : logDebug;
}

From source file:com.xebia.os.maven.couchdocsplugin.UpdateCouchDocsMojo.java

License:Apache License

private void dumpConfig() {
    final Log log = getLog();
    if (log.isDebugEnabled()) {
        log.debug("Using configuration:");
        log.debug("  couchUrl        : " + couchUrl);
        log.debug("  baseDir         : " + baseDir);
        log.debug("  unknownDatabases: " + unknownDatabases);
        log.debug("  existingDocs    : " + existingDocs);
        log.debug("  failOnError     : " + failOnError);
    }/*from w  w  w .j  ava2  s. c o m*/
}