List of usage examples for org.apache.maven.plugin.logging Log isInfoEnabled
boolean isInfoEnabled();
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 av a2 s. c om*/ 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.jav a 2 s . c o 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); } } }
From source file:solutions.tal.tools.maven.plugins.exec.ProcessExecutor.java
License:Apache License
void execute(File workingDir, final Log mavenLog) throws MojoExecutionException { validate();/*from w w w .jav a 2 s .c om*/ final List<String> arguments = new ArrayList<>(); arguments.add(executable); if (systemPropertyArgs != null) { arguments.addAll(systemPropertyArgs); } arguments.addAll(args); if (mavenLog.isInfoEnabled()) { mavenLog.info("Command line arguments:\n" + arguments); mavenLog.info("With environment variables:\n" + environmentVariables); } final ProcessBuilder pb = new ProcessBuilder(); pb.command(arguments); pb.directory(workingDir); pb.environment().putAll(environmentVariables); pb.redirectErrorStream(true); if (outputFile != null) { pb.redirectOutput(outputFile); } else { pb.inheritIO(); } try { process = pb.start(); } catch (IOException e) { throw new MojoExecutionException("Error starting process", e); } }
From source file:uk.org.raje.maven.plugin.msbuild.LoggingHandler.java
License:Apache License
/** * Set the Maven logger that will output the messages generated by the Java logger specified in {@link * LoggingHandler#LoggingHandler(name)}. * @param log the Maven logger that will output the messages generated by the Java logger *//*from w w w . j a va 2 s . c om*/ public void setLog(Log log) { this.mavenLogger = log; //Match the log level of the Java logger with that set in the Maven logger if (log.isDebugEnabled()) { javaLogger.setLevel(Level.FINE); } else if (log.isInfoEnabled()) { javaLogger.setLevel(Level.INFO); } else if (log.isWarnEnabled()) { javaLogger.setLevel(Level.WARNING); } else { javaLogger.setLevel(Level.SEVERE); } }