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

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

Introduction

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

Prototype

boolean isWarnEnabled();

Source Link

Usage

From source file:org.codehaus.mojo.cobertura.integration.LogLevel.java

License:Apache License

/**
 * Simple conversion method extracting the LogLevel matching the level
 * assigned to the supplied Log.//from   w  ww.j a  va  2s .  c  o  m
 *
 * @param mavenLog The non-null Log instance.
 * @return The LogLevel matching the existing level of the supplied mavenLog.
 */
public static LogLevel getMatchingLevel(final Log mavenLog) {

    // Check sanity
    Validate.notNull(mavenLog, "Cannot handle null mavenLog argument.");

    LogLevel toReturn;
    if (mavenLog.isDebugEnabled()) {
        toReturn = LogLevel.DEBUG;
    } else if (mavenLog.isInfoEnabled()) {
        toReturn = LogLevel.INFO;
    } else if (mavenLog.isWarnEnabled()) {
        toReturn = LogLevel.WARNING;
    } else {
        toReturn = LogLevel.ERROR;
    }

    // All done.
    return toReturn;
}

From source file:org.codehaus.mojo.jaxb2.schemageneration.XsdGeneratorHelper.java

License:Apache License

/**
 * Inserts XML documentation annotations into all generated XSD files found
 * within the supplied outputDir.//from  w w w .  jav a  2 s .  c o  m
 *
 * @param log       A Maven Log.
 * @param outputDir The outputDir, where generated XSD files are found.
 * @param docs      The SearchableDocumentation for the source files within the compilation unit.
 * @param renderer  The JavaDocRenderer used to convert JavaDoc annotations into XML documentation annotations.
 * @return The number of processed XSDs.
 */
public static int insertJavaDocAsAnnotations(final Log log, final File outputDir,
        final SearchableDocumentation docs, final JavaDocRenderer renderer) {

    // Check sanity
    Validate.notNull(docs, "docs");
    Validate.notNull(log, "log");
    Validate.notNull(outputDir, "outputDir");
    Validate.isTrue(outputDir.isDirectory(), "'outputDir' must be a Directory.");
    Validate.notNull(renderer, "renderer");

    int processedXSDs = 0;
    final List<File> foundFiles = new ArrayList<File>();
    addRecursively(foundFiles, RECURSIVE_XSD_FILTER, outputDir);

    if (foundFiles.size() > 0) {

        // Create the processors.
        final XsdAnnotationProcessor classProcessor = new XsdAnnotationProcessor(docs, renderer);
        final XsdEnumerationAnnotationProcessor enumProcessor = new XsdEnumerationAnnotationProcessor(docs,
                renderer);

        for (File current : foundFiles) {

            // Create an XSD document from the current File.
            final Document generatedSchemaFileDocument = parseXmlToDocument(current);

            // Replace all namespace prefixes within the provided document.
            process(generatedSchemaFileDocument.getFirstChild(), true, classProcessor);
            processedXSDs++;

            // Overwrite the vanilla file.
            savePrettyPrintedDocument(generatedSchemaFileDocument, current);
        }

    } else {
        if (log.isWarnEnabled()) {
            log.warn("Found no generated 'vanilla' XSD files to process under ["
                    + FileSystemUtilities.getCanonicalPath(outputDir) + "]. Aborting processing.");
        }
    }

    // All done.
    return processedXSDs;
}

From source file:org.codehaus.mojo.jaxb2.shared.environment.logging.MavenLogHandler.java

License:Apache License

/**
 * Retrieves the JUL Level matching the supplied Maven Log.
 *
 * @param mavenLog A non-null Maven Log.
 * @return The Corresponding JUL Level.//  w  w w  .  ja  va 2 s . co m
 */
public static Level getJavaUtilLoggingLevelFor(final Log mavenLog) {

    // Check sanity
    Validate.notNull(mavenLog, "mavenLog");

    Level toReturn = Level.SEVERE;

    if (mavenLog.isDebugEnabled()) {
        toReturn = Level.FINER;
    } else if (mavenLog.isInfoEnabled()) {
        toReturn = Level.INFO;
    } else if (mavenLog.isWarnEnabled()) {
        toReturn = Level.WARNING;
    }

    // All Done.
    return toReturn;
}

From source file:org.codehaus.mojo.jaxb2.shared.filters.AbstractFilter.java

License:Apache License

/**
 * {@inheritDoc}//from  ww w . j  a  va 2  s.  c o m
 */
@Override
public final void initialize(final Log log) {

    // Check sanity
    Validate.notNull(log, "log");

    // Assign internal state
    this.log = log;

    if (delayedLogMessages.size() > 0) {
        for (DelayedLogMessage current : delayedLogMessages) {
            if (current.logLevel.equalsIgnoreCase("warn") && log.isWarnEnabled()) {
                log.warn(current.message);
            } else if (current.logLevel.equals("info") && log.isInfoEnabled()) {
                log.info(current.message);
            } else if (log.isDebugEnabled()) {
                log.debug(current.message);
            }
        }

        delayedLogMessages.clear();
    }

    // Delegate
    onInitialize();
}

From source file:org.izpack.mojo.IzPackNewMojo.java

License:Open Source License

private Handler createLogHandler() {
    final ConsoleHandler consoleHandler = new ConsoleHandler();
    consoleHandler.setFormatter(new MavenStyleLogFormatter());
    Log log = getLog();
    Level level = Level.OFF;
    if (log.isDebugEnabled()) {
        level = Level.FINE;//from   www.  j  a v a2  s  .  co  m
    } else if (log.isInfoEnabled()) {
        level = Level.INFO;
    } else if (log.isWarnEnabled()) {
        level = Level.WARNING;
    } else if (log.isErrorEnabled()) {
        level = Level.SEVERE;
    }
    consoleHandler.setLevel(level);
    return consoleHandler;
}

From source file:org.jvnet.hyperjaxb3.maven2.Hyperjaxb3Mojo.java

License:Apache License

/**
 * Sets up the verbose and debug mode depending on mvn logging level, and
 * sets up hyperjaxb logging./*from  ww w .j  a  va  2 s .c  o  m*/
 */
protected void setupLogging() {
    super.setupLogging();

    final Logger rootLogger = LogManager.getRootLogger();
    rootLogger.addAppender(new NullAppender());
    final Logger logger = LogManager.getLogger("org.jvnet.hyperjaxb3");

    final Log log = getLog();
    logger.addAppender(new Appender(getLog(), new PatternLayout("%m%n        %c%n")));

    if (this.getDebug()) {
        log.debug("Logger level set to [debug].");
        logger.setLevel(Level.DEBUG);
    } else if (this.getVerbose())
        logger.setLevel(Level.INFO);
    else if (log.isWarnEnabled())
        logger.setLevel(Level.WARN);
    else
        logger.setLevel(Level.ERROR);
}

From source file:org.lazydoc.plugin.LazyDocMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    String logLevel = log.isDebugEnabled() ? "DEBUG"
            : log.isWarnEnabled() ? "WARN" : log.isInfoEnabled() ? "INFO" : "ERROR";
    log.info("Log level is " + logLevel);
    log.debug(config.toString());/*from  w  w w . j  av a  2s  .co m*/
    try {
        ClassLoader classLoader = getClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        Class<?> lazyDocClass = classLoader.loadClass("org.lazydoc.LazyDoc");
        Class<?> lazyDocConfigClass = classLoader.loadClass("org.lazydoc.config.Config");
        Class<?> lazyDocPrinterConfigClass = classLoader.loadClass("org.lazydoc.config.PrinterConfig");
        Object lazydocConfig = lazyDocConfigClass.newInstance();
        BeanUtils.copyProperties(lazydocConfig, config);
        List lazyDocPrinterConfigs = new ArrayList();
        if (printerConfigs != null) {
            for (PrinterConfig printerConfig : printerConfigs) {
                Object lazydocPrinterConfig = lazyDocPrinterConfigClass.newInstance();
                BeanUtils.copyProperties(lazydocPrinterConfig, printerConfig);
                lazyDocPrinterConfigs.add(lazydocPrinterConfig);
            }
        }
        lazyDocClass.getDeclaredMethod("document", lazyDocConfigClass, List.class, String.class)
                .invoke(lazyDocClass.newInstance(), lazydocConfig, lazyDocPrinterConfigs, logLevel);
    } catch (Exception e) {
        getLog().error("Error parsing for documentation.", e);
        throw new MojoFailureException("Error parsing for documentation." + e.getMessage());
    }
}

From source file:org.sonatype.maven.mojo.logback.LogbackUtils.java

License:Open Source License

/**
 * Syncs the passed in logback logger with the passed in Mojo Log level.
 *///from  w w w  .  j a va2s.co m
public static void syncLogLevelWithMaven(Logger logger, Log log) {
    if (log.isDebugEnabled()) {
        syncLogLevelWithLevel(logger, Level.DEBUG);
    } else if (log.isInfoEnabled()) {
        syncLogLevelWithLevel(logger, Level.INFO);
    } else if (log.isWarnEnabled()) {
        syncLogLevelWithLevel(logger, Level.WARN);
    } else {
        syncLogLevelWithLevel(logger, Level.ERROR);
    }
}

From source file:org.sonatype.nexus.maven.m2settings.MojoLogger.java

License:Open Source License

@Override
protected boolean isEnabled(final Level level) {
    Log mojoLog = getOwner().getLog();
    if (mojoLog == null) {
        log.warn("Mojo.log not configured; owner: {}", owner);
        return false;
    }//from w  w  w  . ja v  a 2 s. c  o  m

    switch (level) {
    case ALL:
    case TRACE:
    case DEBUG:
        return mojoLog.isDebugEnabled();
    case INFO:
        return mojoLog.isInfoEnabled();
    case WARN:
        return mojoLog.isWarnEnabled();
    case ERROR:
        return mojoLog.isErrorEnabled();
    default:
        return false;
    }
}

From source file:org.teatrove.maven.plugins.teacompiler.TeaCompilerMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {

    final Log logger = getLog();

    // Create the Helper for the Context Class Builder
    ContextClassBuilderHelper helper = new DefaultContextClassBuilderHelper(session,
            new TeaCompilerExpressionEvaluator(session, translator, project), logger, container,
            this.getClass().getClassLoader(), rootPackage);

    // Merge the contexts
    final Class<?> contextClass;
    try {// w  w  w . j  a  v  a2  s  .c  om
        if (this.context == null) {
            if (contextClassBuilder == null) {
                throw new MojoExecutionException(
                        "Either context or contextClassBuilder parameter is required.");
            }
            contextClass = contextClassBuilder.getContextClass(helper);
        } else {
            contextClass = Class.forName(this.context);
        }
    } catch (ContextClassBuilderException e) {
        throw new MojoExecutionException("Unable to find or create the Context.", e);
    } catch (ClassNotFoundException e) {
        throw new MojoExecutionException("Unable to load the Context.", e);
    }

    final File realOutputDirectory = new File(outputDirectory, rootPackage.replace('.', File.separatorChar));

    realOutputDirectory.mkdirs();

    if (sourceDirectories == null || sourceDirectories.length == 0) {
        sourceDirectories = new File[] { defaultSourceDirectory };
    } else {
        // Filter out any that don't exist
        List<File> existing = new ArrayList<File>(sourceDirectories.length);
        for (File sourceDirectory : sourceDirectories) {
            if (sourceDirectory.exists()) {
                existing.add(sourceDirectory);
            } else if (logger.isDebugEnabled()) {
                logger.debug("Removing source directory because it does not exist. [" + sourceDirectory + "].");
            }
        }
        sourceDirectories = existing.toArray(new File[existing.size()]);
    }

    final Compiler compiler = new Compiler(rootPackage, realOutputDirectory, encoding, 0);

    for (File sourceDirectory : sourceDirectories) {
        compiler.addCompilationProvider(new FileCompilationProvider(sourceDirectory));
    }

    compiler.setClassLoader(contextClass.getClassLoader());
    compiler.setRuntimeContext(contextClass);
    compiler.setForceCompile(force);
    compiler.addCompileListener(new CompileListener() {
        public void compileError(CompileEvent e) {
            logger.error(e.getDetailedMessage());
        }

        public void compileWarning(CompileEvent e) {
            logger.warn(e.getDetailedMessage());
        }
    });
    compiler.setExceptionGuardianEnabled(guardian);

    final String[] names;
    try {
        if (includes == null || includes.length == 0) {
            names = compiler.compileAll(true);
        } else {
            names = compiler.compile(includes);
        }
    } catch (IOException e) {
        throw new MojoExecutionException("I/O error while compiling templates.", e);
    }

    final int errorCount = compiler.getErrorCount();
    if (errorCount > 0) {
        String msg = errorCount + " error" + (errorCount != 1 ? "s" : "");
        if (failOnError) {
            throw new MojoFailureException(msg);
        } else if (logger.isWarnEnabled()) {
            logger.warn(msg);
        }
    }

    final int warningCount = compiler.getWarningCount();
    if (warningCount > 0) {
        String msg = warningCount + " warning" + (warningCount != 1 ? "s" : "");
        if (failOnWarning) {
            throw new MojoFailureException(msg);
        } else if (logger.isWarnEnabled()) {
            logger.warn(msg);
        }
    }

    if (logger.isInfoEnabled()) {
        logger.info("Compiled the following templates:");
        Arrays.sort(names);
        for (String name : names) {
            logger.info(name);
        }
    }
}