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

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

Introduction

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

Prototype

boolean isInfoEnabled();

Source Link

Usage

From source file:org.codehaus.mojo.jaxb2.AbstractJaxbMojo.java

License:Apache License

/**
 * {@inheritDoc}/*from w  ww .j  ava  2s .c  o  m*/
 */
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {

    // 0) Get the log and its relevant level
    final Log log = getLog();
    final boolean isDebugEnabled = log.isDebugEnabled();
    final boolean isInfoEnabled = log.isInfoEnabled();

    // 1) Should we skip execution?
    if (shouldExecutionBeSkipped()) {

        if (isDebugEnabled) {
            log.debug("Skipping execution, as instructed.");
        }
        return;
    }

    // 2) Printout relevant version information.
    if (isDebugEnabled) {
        logPluginAndJaxbDependencyInfo();
    }

    // 3) Are generated files stale?
    if (isReGenerationRequired()) {

        if (performExecution()) {

            // As instructed by the performExecution() method, update
            // the timestamp of the stale File.
            updateStaleFileTimestamp();

            // Hack to support M2E
            buildContext.refresh(getOutputDirectory());

        } else if (isInfoEnabled) {
            log.info("Not updating staleFile timestamp as instructed.");
        }
    } else if (isInfoEnabled) {
        log.info("No changes detected in schema or binding files - skipping JAXB generation.");
    }

    // 4) If the output directories exist, add them to the MavenProject's source directories
    if (getOutputDirectory().exists() && getOutputDirectory().isDirectory()) {

        final String canonicalPathToOutputDirectory = FileSystemUtilities
                .getCanonicalPath(getOutputDirectory());

        if (log.isDebugEnabled()) {
            log.debug("Adding existing JAXB outputDirectory [" + canonicalPathToOutputDirectory
                    + "] to Maven's sources.");
        }

        // Add the output Directory.
        getProject().addCompileSourceRoot(canonicalPathToOutputDirectory);
    }
}

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 .  j a  v  a  2  s.c  om*/
 */
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.FileSystemUtilities.java

License:Apache License

/**
 * Filters files found either in the sources paths (or in the standardDirectory if no explicit sources are given),
 * and retrieves a List holding those files that do not match any of the supplied Java Regular Expression
 * excludePatterns./*from   w ww.  j a  va 2  s .com*/
 *
 * @param baseDir             The non-null basedir Directory.
 * @param sources             The sources which should be either absolute or relative (to the given baseDir)
 *                            paths to files or to directories that should be searched recursively for files.
 * @param standardDirectory   If no sources are given, revert to searching all files under this standard directory.
 *                            This is the path appended to the baseDir to reach a directory.
 * @param log                 A non-null Maven Log for logging any operations performed.
 * @param fileTypeDescription A human-readable short description of what kind of files are searched for, such as
 *                            "xsdSources" or "xjbSources".
 * @param excludeFilters      An optional List of Filters used to identify files which should be excluded from
 *                            the result.
 * @return All files under the supplied sources (or standardDirectory, if no explicit sources are given) which
 * do not match the supplied Java Regular excludePatterns.
 */
@SuppressWarnings("CheckStyle")
public static List<File> filterFiles(final File baseDir, final List<String> sources,
        final String standardDirectory, final Log log, final String fileTypeDescription,
        final List<Filter<File>> excludeFilters) {

    // Check sanity
    Validate.notNull(baseDir, "baseDir");
    Validate.notNull(log, "log");
    Validate.notEmpty(standardDirectory, "standardDirectory");
    Validate.notEmpty(fileTypeDescription, "fileTypeDescription");

    // No sources provided? Fallback to the standard (which should be a relative path).
    List<String> effectiveSources = sources;
    if (sources == null || sources.isEmpty()) {
        effectiveSources = new ArrayList<String>();

        final File tmp = new File(standardDirectory);
        final File rootDirectory = tmp.isAbsolute() ? tmp : new File(baseDir, standardDirectory);
        effectiveSources.add(FileSystemUtilities.getCanonicalPath(rootDirectory));
    }

    // First, remove the non-existent sources.
    List<File> existingSources = new ArrayList<File>();
    for (String current : effectiveSources) {

        final File existingFile = FileSystemUtilities.getExistingFile(current, baseDir);
        if (existingFile != null) {
            existingSources.add(existingFile);

            if (log.isDebugEnabled()) {
                log.debug("Accepted configured " + fileTypeDescription + " ["
                        + FileSystemUtilities.getCanonicalFile(existingFile) + "]");
            }
        } else {
            if (log.isInfoEnabled()) {
                log.info("Ignored given or default " + fileTypeDescription + " [" + current
                        + "], since it is not an existent file or directory.");
            }
        }
    }

    if (log.isDebugEnabled() && existingSources.size() > 0) {

        final int size = existingSources.size();

        log.debug(" [" + size + " existing " + fileTypeDescription + "] ...");
        for (int i = 0; i < size; i++) {
            log.debug("   " + (i + 1) + "/" + size + ": " + existingSources.get(i));
        }
        log.debug(" ... End [" + size + " existing " + fileTypeDescription + "]");
    }

    // All Done.
    return FileSystemUtilities.resolveRecursively(existingSources, excludeFilters, log);
}

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

License:Apache License

/**
 * {@inheritDoc}//from w ww. j a  v a2 s . c  om
 */
@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.impalaframework.maven.plugin.CopyModulesMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    final Log logger = getLog();

    if (isImpalaHost()) {

        moduleStagingDirectory = MojoUtils.getModuleStagingDirectory(getLog(), project, moduleStagingDirectory);

        if (logger.isDebugEnabled()) {
            logger.debug("Maven projects: " + dependencies);
            logger.debug("Current project: " + project);
        }//from  w  ww  . ja  v  a2 s  .co m

        File targetDirectory = getTargetDirectory();
        File stagingDirectory = new File(moduleStagingDirectory);

        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Staging directory " + stagingDirectory.getCanonicalPath());
            }
            FileUtils.forceMkdir(targetDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }

        if (logger.isInfoEnabled()) {
            logger.info("Copying files from staging directory: " + stagingDirectory);
        }

        final File[] listFiles = stagingDirectory.listFiles();

        if (listFiles != null) {
            for (File moduleFile : listFiles) {

                final String targetFileName = moduleFile.getName();

                MojoUtils.copyFile(moduleFile, targetDirectory, targetFileName);
                if (logger.isInfoEnabled()) {
                    logger.info("Copying from from staging directory: " + moduleFile);
                }
            }
        }
    }
}

From source file:org.impalaframework.maven.plugin.StageModuleMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    final Log log = getLog();

    boolean isImpalaModule = isImpalaModule();

    if (isImpalaModule) {

        //copying module to staging directory

        moduleStagingDirectory = MojoUtils.getModuleStagingDirectory(getLog(), project, moduleStagingDirectory);

        final File file = project.getArtifact().getFile();

        if (log.isInfoEnabled()) {
            log.info("Copying file " + file.getAbsolutePath() + " to module staging directory: "
                    + moduleStagingDirectory);
        }//from   ww w.  j av a2s.c  o  m

        final File targetDirectory = new File(moduleStagingDirectory);
        try {
            FileUtils.forceMkdir(targetDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }
        MojoUtils.copyFile(file, targetDirectory, file.getName());
    }
}

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  w  w w. j  a va  2s .c o 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.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  a  v  a  2s  . c  o 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.mule.devkit.maven.AbstractGitHubMojo.java

License:Open Source License

/**
 * Is info logging enabled?//from   ww w .j  a v  a 2 s.c o m
 *
 * @return true if enabled, false otherwise
 */
protected boolean isInfo() {
    Log log = getLog();
    return log != null ? log.isInfoEnabled() : false;
}

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 www  . j ava 2 s. c  o  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);
    }
}