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.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());//w  ww.  ja  v a  2s  .  c om
    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.mobicents.maven.plugin.utils.ProjectUtils.java

License:Open Source License

/**
 * Gets a project for the given <code>pom</code>.
 *
 * @param pom the pom from which to build the project.
 * @return the built project.//  ww w .  ja  v  a2 s . c om
 * @throws ProjectBuildingException
 */
public static synchronized MavenProject getProject(final MavenProjectBuilder projectBuilder,
        final MavenSession session, final File pom, final Log logger) throws ProjectBuildingException {
    // - first attempt to get a project from the cache
    MavenProject project = (MavenProject) projectCache.get(pom);
    if (project == null) {
        // - next attempt to get the existing project from the session
        project = getProjectFromSession(session, pom);
        if (project == null) {
            // - if we didn't find it in the session, create it
            try {
                project = projectBuilder.build(pom, session.getLocalRepository(),
                        new DefaultProfileManager(session.getContainer()));
                projectCache.put(pom, project);
            } catch (Exception ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Failed to build project from pom: " + pom, ex);
                }
            }
        }
    }
    return project;
}

From source file:org.mule.devkit.maven.AbstractGitHubMojo.java

License:Open Source License

/**
 * Is debug logging enabled?/*from  w ww  .ja  va 2s  . c o  m*/
 *
 * @return true if enabled, false otherwise
 */
protected boolean isDebug() {
    Log log = getLog();
    return log != null ? log.isDebugEnabled() : false;
}

From source file:org.richfaces.cdk.rd.mojo.ResourceDependencyMojo.java

License:Open Source License

public ComponentsHandler findComponents(File webSourceDir, Map<String, Components> components,
        String[] includes, String[] excludes) throws Exception {

    if (includes == null) {
        includes = PluginUtils.DEFAULT_PROCESS_INCLUDES;
    }//from w  w  w .  ja  va2  s. c o  m

    if (excludes == null) {
        excludes = new String[0];
    }

    DirectoryScanner scanner = new DirectoryScanner();
    scanner.setBasedir(webSourceDir);
    scanner.setIncludes(includes);
    scanner.setExcludes(excludes);
    scanner.addDefaultExcludes();
    getLog().info("search *.xhtml files");
    scanner.scan();

    String[] collectedFiles = scanner.getIncludedFiles();

    for (String collectedFile : collectedFiles) {
        getLog().info(collectedFile + " found");
    }

    ComponentsHandler handler = new ComponentsHandler(getLog());
    handler.setComponents(components);
    handler.setScriptIncludes(scriptIncludes);
    handler.setScriptExcludes(scriptExcludes);
    handler.setStyleIncludes(styleIncludes);
    handler.setStyleExcludes(styleExcludes);
    handler.setComponentIncludes(componentIncludes);
    handler.setComponentExcludes(componentExcludes);
    handler.setNamespaceIncludes(namespaceIncludes);
    handler.setNamespaceExcludes(namespaceExcludes);

    SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
    saxParserFactory.setNamespaceAware(true);

    Log log = getLog();
    for (String processFile : collectedFiles) {
        SAXParser saxParser = saxParserFactory.newSAXParser();
        File file = new File(webSourceDir, processFile);
        if (file.exists()) {

            if (log.isDebugEnabled()) {
                log.debug("start process file: " + file.getPath());
            }

            try {
                saxParser.parse(file, handler);
            } catch (Exception e) {
                if (log.isDebugEnabled()) {
                    log.error("Error process file: " + file.getPath() + "\n" + e.getMessage(), e);
                } else {
                    log.error("Error process file: " + file.getPath() + "\n" + e.getMessage());
                }
            }
        }
    }

    return handler;
}

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 v  a2s  . 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.maven.polyglot.plugin.ExecuteMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    Model model = project.getModel();/*from  ww  w  .  j  a  v a  2 s .c  o  m*/

    if (log.isDebugEnabled()) {
        log.debug("Executing task '" + taskId + "' for model: " + model.getId());
    }

    assert manager != null;
    List<ExecuteTask> tasks = manager.getTasks(model);
    // if there are no tasks that means we run in proper maven and 
    // have to load the nativePom to setup the ExecuteManager
    if (tasks.size() == 0 && nativePom != null) {
        // TODO avoid parsing the nativePom for each task
        tasks = manager.getTasks(modelFromNativePom(log));
    }

    ExecuteContext ctx = new ExecuteContext() {
        @Override
        public MavenProject getProject() {
            return project;
        }

        @Override
        public File basedir() {
            return project.getBasedir();
        }

        @Override
        public Log log() {
            return getLog();
        }
    };

    for (ExecuteTask task : tasks) {
        if (taskId.equals(task.getId())) {
            log.debug("Executing task: " + task.getId());

            try {
                task.execute(ctx);
                return;
            } catch (Exception e) {
                throw new MojoExecutionException(e.getMessage(), e);
            }
        }
    }

    throw new MojoFailureException("Unable to find task for id: " + taskId);
}

From source file:org.sonatype.maven.polyglot.plugin.ExecuteMojo.java

License:Open Source License

protected Model modelFromNativePom(Log log) throws MojoExecutionException, MojoFailureException {
    Map<String, ModelSource> options = new HashMap<String, ModelSource>();
    options.put(ModelProcessor.SOURCE, new FileModelSource(nativePom));

    assert modelManager != null;
    try {/*w ww . j a  v  a  2 s  . c  om*/
        ModelReader reader = modelManager.getReaderFor(options);
        if (reader == null) {
            throw new MojoExecutionException("no model reader found for " + nativePom);
        }
        if (log.isDebugEnabled()) {
            log.debug("Parsing native pom " + nativePom);
        }
        return reader.read(nativePom, options);
    } catch (IOException e) {
        throw new MojoFailureException("error parsing " + nativePom, e);
    }
}

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;
    }// ww w  . j ava2  s  . co  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.sonatype.nexus.maven.staging.ProgressMonitorImpl.java

License:Open Source License

public ProgressMonitorImpl(final Log log) {
    int level = Logger.LEVEL_INFO;
    if (log.isDebugEnabled()) {
        level = Logger.LEVEL_DEBUG;
    }/*from  w  w  w  .  j av a  2  s  .com*/
    this.logger = new ConsoleLogger(level, getClass().getName());
}

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 ww  .  jav a 2  s  .co  m
        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);
        }
    }
}