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

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

Introduction

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

Prototype

boolean isErrorEnabled();

Source Link

Usage

From source file:apparat.embedding.maven.MavenLogAdapter.java

License:Open Source License

/**
 * Maps the level of a given Maven log to a corresponding
 * Apparat log level.//from   w w  w  .  j  a  v  a 2s.  c  o  m
 *
 * @param log The current Maven log.
 * @return The corresponding Apparat log level.
 */
public static LogLevel mapLevelOf(final org.apache.maven.plugin.logging.Log log) {
    //
    // We return an instance of a Scala case object here.
    //

    if (log.isDebugEnabled()) {
        return Debug$.MODULE$;
    } else if (log.isInfoEnabled()) {
        return Info$.MODULE$;
    } else if (log.isWarnEnabled()) {
        return Warning$.MODULE$;
    } else if (log.isErrorEnabled()) {
        return Error$.MODULE$;
    } else {
        return Off$.MODULE$;
    }
}

From source file:com.github.jrh3k5.flume.mojo.plugin.plexus.MojoLogger.java

License:Apache License

/**
 * Determine a {@link Logger} level based on the configuration of the given
 * {@link Log}.//from   w  w w  . ja va 2 s  .co  m
 * 
 * @param log
 *            The {@link Log} to determine the logger level.
 * @return A {@link Logger} level corresponding to the log level in the
 *         given {@link Log}.
 */
private static int determineThreshold(Log log) {
    if (log.isDebugEnabled()) {
        return Logger.LEVEL_DEBUG;
    } else if (log.isInfoEnabled()) {
        return Logger.LEVEL_INFO;
    } else if (log.isWarnEnabled()) {
        return Logger.LEVEL_WARN;
    } else if (log.isErrorEnabled()) {
        return Logger.LEVEL_ERROR;
    } else {
        return Logger.LEVEL_DISABLED;
    }
}

From source file:com.hubrick.raml.mojo.SpringWebValidatorMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final JCodeModel codeModel = generateCodeModel();

    final Map<String, File> classFileIndex = mavenProject.getCompileSourceRoots().stream()
            .flatMap(sourceRoot -> {//  w  ww.ja  v  a2s .  c  o m
                final DirectoryScanner directoryScanner = new DirectoryScanner();
                directoryScanner.setBasedir(sourceRoot);
                directoryScanner.setIncludes(new String[] { "**/*.java" });
                directoryScanner.scan();
                return Arrays.stream(directoryScanner.getIncludedFiles()).map(filePath -> {
                    final String className = JavaNames.classNameOfPath(filePath);
                    return Pair.with(className, new File(sourceRoot, filePath));
                });
            }).collect(toMap(Pair::getValue0, Pair::getValue1));

    final Collection<ValidationUnit> validationUnits = StreamSupport
            .stream(Spliterators.spliteratorUnknownSize(codeModel.packages(),
                    Spliterator.DISTINCT | Spliterator.NONNULL), false)
            .flatMap(pkg -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(pkg.classes(),
                    Spliterator.DISTINCT | Spliterator.NONNULL), false))
            .map(klass -> new ValidationUnit(klass, Optional.ofNullable(classFileIndex.get(klass.fullName()))))
            .collect(toList());

    if (!validationUnits.isEmpty()) {

        final GenericScanner generatedSourceScanner = new GenericScanner(() -> {
            final Iterator<String> i = validationUnits.stream()
                    .map(validationUnit -> validationUnit.getGeneratedSourceFile().getPath()).iterator();

            return () -> i;
        });

        final List<String> includes = Optional.of(this.includes).filter(i -> !i.isEmpty())
                .orElse(Collections.singletonList("**/*"));
        generatedSourceScanner.setIncludes(includes.toArray(new String[includes.size()]));
        generatedSourceScanner.setExcludes(excludes.toArray(new String[excludes.size()]));
        generatedSourceScanner.scan();

        final Set<String> generatedSourceFiles = Sets.newHashSet(generatedSourceScanner.getIncludedFiles());

        getLog().info(
                "Generated source files: " + generatedSourceFiles.stream().collect(joining(", ", "[", "]")));

        final List<ValidationUnit> includedValidationUnits = validationUnits.stream()
                .filter(validationUnit -> generatedSourceFiles
                        .contains(validationUnit.getGeneratedSourceFile().getPath()))
                .collect(toList());

        validateMissingSources(includedValidationUnits);

        if (!includedValidationUnits.isEmpty()) {

            final InMemoryCodeWriter inMemoryCodeWriter = new InMemoryCodeWriter();
            try {
                codeModel.build(inMemoryCodeWriter);
            } catch (IOException e) {
                throw new RuntimeException("Couldn't build generated sources", e);
            }

            final Map<String, List<String>> fileValidationMessages = includedValidationUnits.stream().map(t -> {
                checkState(inMemoryCodeWriter.countainsFile(t.getGeneratedSourceFile()),
                        "%s is not part of generated code", t.getGeneratedSourceFile());

                final String sourceFilePath = t.getGeneratedSourceFile().getPath();
                final byte[] sourceFileContent;
                try {
                    sourceFileContent = Files.readAllBytes(t.getSourceFile().get().toPath());
                } catch (IOException e) {
                    throw new RuntimeException(
                            "Failed reading source file: " + t.getSourceFile().get().getParent());
                }
                final List<String> messages = validateFile(sourceFileContent,
                        inMemoryCodeWriter.getSource(new File(sourceFilePath)));
                return Pair.with(sourceFilePath, messages);
            }).filter(e -> !e.getValue1().isEmpty()).collect(toMap(Pair::getValue0, Pair::getValue1));

            if (!fileValidationMessages.isEmpty()) {
                final List<String> longMessage = Stream
                        .concat(Stream.of("REST controller source code validation failed"),
                                fileValidationMessages.entrySet().stream().flatMap(
                                        e -> Stream.concat(Stream.of(e.getKey() + ":"), e.getValue().stream())))
                        .collect(toList());

                final Log log = getLog();
                if (log.isErrorEnabled()) {
                    longMessage.forEach(log::error);
                }

                throw new MojoFailureException(null, "REST controller source code validation failed",
                        longMessage.stream().collect(joining(System.lineSeparator())));
            }
        } else {
            getLog().info("Nothing to validate");
        }
    }
}

From source file:org.acmsl.queryj.tools.maven.CommonsLoggingMavenLogAdapter.java

License:Open Source License

/**
 * Checks whether the error level is enabled.
 * @param mavenLog the underlying {@link Log}.
 * @return {@code true} in such case.//from   w  w  w .  j a  v  a  2 s.  c  om
 */
protected boolean isErrorEnabled(@NotNull final Log mavenLog) {
    return mavenLog.isErrorEnabled();
}

From source file:org.acmsl.queryj.tools.maven.CommonsLoggingMavenLogAdapter.java

License:Open Source License

/**
 * Checks whether the debug level is enabled.
 * @param mavenLog the underlying {@link Log}.
 * @return {@code true} in such case.//from  w  w  w .  j  a va2  s. co  m
 */
protected boolean isFatalEnabled(@NotNull final Log mavenLog) {
    return mavenLog.isErrorEnabled();
}

From source file:org.codehaus.mojo.apt.LogUtils.java

License:Open Source License

public static boolean isEnabled(Log log, int level) {
    boolean enabled;

    if (level == LEVEL_DEBUG) {
        enabled = log.isDebugEnabled();/*  w ww .ja  v a 2s.  co m*/
    } else if (level == LEVEL_INFO) {
        enabled = log.isInfoEnabled();
    } else if (level == LEVEL_WARN) {
        enabled = log.isWarnEnabled();
    } else if (level == LEVEL_ERROR) {
        enabled = log.isErrorEnabled();
    } else {
        throw new IllegalArgumentException("Unknown log level: " + level);
    }

    return enabled;
}

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  ww.  j  ava2s .  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.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;
    }/*  w w w  .  j  av  a2 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:vitkin.sfdc.mojo.wsdl.WsdlDownloadlMojo.java

License:Apache License

/**
 * Log in to a Salesforce authorization server.
 *
 * @param client HTTP client.//  w w w  . ja  va 2 s .co  m
 *
 * @return Redirection URL if successful.
 *
 * @throws MojoExecutionException
 */
private String logIn(final DefaultHttpClient client) throws MojoExecutionException {
    final Log logger = getLog();

    final String authorizationServer = useSandbox ? SANDBOX_AUTHORIZATION_SERVER
            : DEV_PROD_AUTHORIZATION_SERVER;

    logger.info("Logging in as " + username + " at authorization server at " + authorizationServer + "...");

    // Send a post request to the login URI.
    final HttpPost loginRequest = new HttpPost(authorizationServer);

    // The request body must contain these 2 values.
    final List<BasicNameValuePair> parametersBody = new ArrayList<BasicNameValuePair>();

    parametersBody.add(new BasicNameValuePair("un", username));
    parametersBody.add(new BasicNameValuePair("pw", password));

    loginRequest.setEntity(new UrlEncodedFormEntity(parametersBody, Consts.UTF_8));

    final String location;

    try {
        final HttpResponse response = client.execute(loginRequest);

        if (logger.isErrorEnabled()) {
            debugResponse(response);
        } else {
            // Low level resources should be released before initiating a new request
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                // Do not need the rest
                loginRequest.abort();
            }
        }

        final int code = response.getStatusLine().getStatusCode();

        if (code != HttpStatus.SC_MOVED_TEMPORARILY) {
            // No redirection. That means we're not logged in.
            throw new MojoExecutionException(
                    "Cannot log in! Wrong credentials or need for activation for the current IP.");
        }

        location = response.getFirstHeader("Location").getValue();

    } catch (IOException ex) {
        throw new MojoExecutionException("Cannot log in!", ex);
    }

    return location;
}

From source file:vitkin.sfdc.mojo.wsdl.WsdlDownloadlMojo.java

License:Apache License

/**
 * Execute an HTTP redirection to set additional cookies related to the
 * resource server session.// www  .ja va2  s .  c o  m
 *
 * @param client      The HTTP client to use for that redirection.
 * @param redirectUrl The URL to redirect to.
 *
 * @return The base URL of the resource server.
 *
 * @throws MojoExecutionException
 */
private String redirect(HttpClient client, String redirectUrl) throws MojoExecutionException {
    final Log logger = getLog();

    final String resourceServer = redirectUrl.substring(0, redirectUrl.indexOf('/', 8));

    if (redirectUrl.startsWith(resourceServer + "/_nc_external/identity/ic/ICRequired")) {
        throw new MojoExecutionException(
                "Need activation. Open the below URL with a browser from the same public IP:\n" + redirectUrl);
    }

    logger.info("Accessing resource server at " + redirectUrl);

    final HttpGet redirectRequest = new HttpGet(redirectUrl);

    try {
        final HttpResponse response = client.execute(redirectRequest);

        if (logger.isErrorEnabled()) {
            debugResponse(response);
        } else {
            final HttpEntity entity = response.getEntity();

            if (entity != null) {
                // Do not need the rest
                redirectRequest.abort();
            }
        }
    } catch (IOException ex) {
        throw new MojoExecutionException("Cannot access resource server!", ex);
    }

    return resourceServer;
}