Java Code Examples for org.apache.maven.plugin.logging.Log#isWarnEnabled()

The following examples show how to use org.apache.maven.plugin.logging.Log#isWarnEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MavenLogHandler.java    From jaxb2-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the JUL Level matching the supplied Maven Log.
 *
 * @param mavenLog A non-null Maven Log.
 * @return The Corresponding JUL Level.
 */
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;
}
 
Example 2
Source File: Hyperjaxb3Mojo.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Sets up the verbose and debug mode depending on mvn logging level, and
 * sets up hyperjaxb logging.
 */
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);
}
 
Example 3
Source File: Utils.java    From dsl-compiler-client with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static String parseSettings(String[] value, Log log) throws MojoExecutionException {
	if (value == null || value.length == 0) return null;
	StringBuilder sb = new StringBuilder();
	for (String setting : value) {
		Settings.Option option = settingsOptionFrom(setting);
		if (option == null) {
			if (setting == null || setting.length() == 0 || setting.contains(" ")) {
				throw new MojoExecutionException("Invalid option passed as argument: " + setting);
			}
			if (log.isWarnEnabled()) {
				log.warn("Unrecognizable option: " + setting + ". Will try to pass it anyway.");
			}
		}
		sb.append(setting);
		sb.append(",");
	}
	return sb.length() > 0 ? sb.substring(0, sb.length() - 1) : null;
}
 
Example 4
Source File: AbstractFilter.java    From jaxb2-maven-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@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();
}
 
Example 5
Source File: AntTaskUtils.java    From was-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static void addBuildListener(Log logger, Project antProject, DefaultLogger listener) {
  if (logger.isDebugEnabled()) {
    listener.setMessageOutputLevel(Project.MSG_DEBUG);
  } else if (logger.isInfoEnabled()) {
    listener.setMessageOutputLevel(Project.MSG_INFO);
  } else if (logger.isWarnEnabled()) {
    listener.setMessageOutputLevel(Project.MSG_WARN);
  } else if (logger.isErrorEnabled()) {
    listener.setMessageOutputLevel(Project.MSG_ERR);
  } else {
    listener.setMessageOutputLevel(Project.MSG_VERBOSE);
  }
  antProject.addBuildListener(listener);
}
 
Example 6
Source File: XsdGeneratorHelper.java    From jaxb2-maven-plugin with Apache License 2.0 4 votes vote down vote up
/**
 * Inserts XML documentation annotations into all generated XSD files found
 * within the supplied outputDir.
 *
 * @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 String encoding,
                                             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, encoding);
        }

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

    // All done.
    return processedXSDs;
}