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

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

Introduction

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

Prototype

void error(Throwable error);

Source Link

Document

Send an exception to the user in the error error level.
The stack trace for this exception will be output when this error level is enabled.

Usage

From source file:com.cybernostics.jsp2thymeleaf.maven.JSPConvertMojo.java

License:Apache License

public void execute() throws MojoExecutionException

{
    final Log log = getLog();
    log.info("includes:" + Arrays.toString(getIncludes()));
    log.info("outputDirectory = " + outputDirectory.getAbsolutePath());
    log.info("srcDirectory = " + srcDirectory.getAbsolutePath());
    log.info("updateLinks = " + updateLinks);
    log.info("taglib scripts folder " + converterScriptDirectory.toString());
    JSP2ThymeleafConfiguration config = JSP2ThymeleafConfiguration.getBuilder().withIncludes(includes)
            .withExcludes(excludes).withSrcFolder(srcDirectory.toString())
            .withDestFolder(outputDirectory.toString())
            .withConverterScripts(scriptsInFolder(converterScriptDirectory)).build();
    JSP2Thymeleaf jSP2Thymeleaf = new JSP2Thymeleaf(config);
    try {/*from  ww w.  j  a va 2 s  . c o  m*/
        final List<JSP2ThymeLeafException> exceptions = jSP2Thymeleaf.run();
        if (exceptions.isEmpty()) {
            log.info("JSP2Thymeleaf converted all files successfully.");
        } else {
            log.error("JSP2Thymeleaf had errors:");
            for (JSP2ThymeLeafException exception : exceptions) {
                log.error(exception.getMessage());
            }
            throw new MojoExecutionException("Failed to convert all files");
        }
    } catch (MojoExecutionException exception) {
        throw exception;
    } catch (Throwable t) {
        log.error(t);
        throw t;
    }
}

From source file:com.ejwa.mavengitdepplugin.model.POM.java

License:Open Source License

@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public static POM getProjectPOM(Log log) {
    final POM pom;

    try {//  w w w  .j a  va 2 s  . co  m
        pom = new POM(new File("pom.xml"));
    } catch (Exception ex) {
        log.error(ex);
        throw new IllegalStateException("Failed to process POM file.");
    }

    return pom;
}

From source file:com.github.bmaggi.conditional.validation.ValidationMojo.java

License:Apache License

public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    log.debug("There are " + conditions.size() + "conditions");
    for (Condition condition : conditions) {
        log.debug("Evaluate (Condition type): " + condition.toString() + " (" + condition.getClass() + ")");
        if (!(condition).evaluate()) {
            String message = condition.getMessage();
            if (LEVEL.ERROR == condition.getLevel()) {
                log.error(" Condition failed" + message);
                throw new MojoExecutionException("A condition with a level ERROR failed");
            } else {
                log.warn("Condition failed" + message);
            }/*from   ww w  . j  a  va2  s.  c  o  m*/
        }
    }
}

From source file:com.github.maven_nar.NarUtil.java

License:Apache License

public static int runCommand(final String cmd, final String[] args, final File workingDirectory,
        final String[] env, final Log log) throws MojoExecutionException, MojoFailureException {
    if (log.isInfoEnabled()) {
        final StringBuilder argLine = new StringBuilder();
        if (args != null) {
            for (final String arg : args) {
                argLine.append(" " + arg);
            }// w w  w.  j  av a  2s. com
        }
        if (workingDirectory != null) {
            log.info("+ cd " + workingDirectory.getAbsolutePath());
        }
        log.info("+ " + cmd + argLine);
    }
    return runCommand(cmd, args, workingDirectory, env, new TextStream() {
        @Override
        public void println(final String text) {
            log.info(text);
        }
    }, new TextStream() {
        @Override
        public void println(final String text) {
            log.error(text);
        }

    }, new TextStream() {
        @Override
        public void println(final String text) {
            log.debug(text);
        }
    }, log);
}

From source file:com.github.mikkoi.maven.plugins.enforcer.rule.charsetencoding.CharacterSetEncodingRule.java

License:Apache License

/**
 * @param helper EnforcerRuleHelper// w  ww . j a v a  2s  . c  om
 * @throws EnforcerRuleException Throws when error
 */
public void execute(@Nonnull final EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    try {
        // get the various expressions out of the helper.
        String basedir = helper.evaluate("${project.basedir}").toString();

        log.debug("Retrieved Basedir: " + basedir);
        log.debug("requireEncoding: " + (requireEncoding == null ? "null" : requireEncoding));
        log.debug("directory: " + (directory == null ? "null" : directory));
        log.debug("includeRegex: " + (includeRegex == null ? "null" : includeRegex));
        log.debug("excludeRegex: " + (excludeRegex == null ? "null" : excludeRegex));

        if (this.getRequireEncoding() == null || this.getRequireEncoding().trim().length() == 0) {
            final String sourceEncoding = (String) helper.evaluate("${project.build.sourceEncoding}");
            log.info(
                    "No parameter 'requiredEncoding' set. Defaults to property 'project.build.sourceEncoding'.");
            if (sourceEncoding != null && sourceEncoding.trim().length() > 0) {
                this.setRequireEncoding(sourceEncoding);
            } else {
                throw new EnforcerRuleException(
                        "Missing parameter 'requireEncoding' and property 'project.build.sourceEncoding'.");
            }
        }
        try {
            Charset.forName(this.getRequireEncoding()); //  Charset names are not case-sensitive
        } catch (IllegalCharsetNameException e) {
            throw new EnforcerRuleException("Illegal value (illegal character set name) '" + requireEncoding
                    + "' for parameter 'requireEncoding'.");
        } catch (UnsupportedCharsetException e) {
            throw new EnforcerRuleException("Illegal value (not supported character set) '" + requireEncoding
                    + "' for parameter 'requireEncoding'.");
        } catch (IllegalArgumentException e) {
            throw new EnforcerRuleException(
                    "Illegal value (empty) '" + requireEncoding + "' for parameter 'requireEncoding'.");
        }
        if (this.getDirectory() == null || this.getDirectory().trim().length() == 0) {
            log.info("No parameter 'directory' set. Defaults to '" + DIRECTORY_DEFAULT + "'.");
            this.setDirectory(DIRECTORY_DEFAULT);
        }
        if (this.getIncludeRegex() == null || this.getIncludeRegex().trim().length() == 0) {
            log.info("No parameter 'includeRegex' set. Defaults to '" + INCLUDE_REGEX_DEFAULT + "'.");
            this.setIncludeRegex(INCLUDE_REGEX_DEFAULT);
        }
        if (this.getExcludeRegex() == null || this.getExcludeRegex().trim().length() == 0) {
            log.info("No parameter 'excludeRegex' set. Defaults to '" + EXCLUDE_REGEX_DEFAULT + "'.");
            this.setExcludeRegex(EXCLUDE_REGEX_DEFAULT);
        }
        log.debug("requireEncoding: " + this.getRequireEncoding());
        log.debug("directory: " + this.getDirectory());
        log.debug("includeRegex: " + this.getIncludeRegex());
        log.debug("excludeRegex: " + this.getExcludeRegex());

        // Check the existence of the wanted directory:
        final Path dir = Paths.get(basedir, getDirectory());
        log.debug("Get files in dir '" + dir.toString() + "'.");
        if (!dir.toFile().exists()) {
            throw new EnforcerRuleException("Directory '" + dir.toString() + "' not found."
                    + " Specified by parameter 'directory' (value: '" + this.getDirectory() + "')!");
        }

        // Put all files into this collection:
        Collection<FileResult> allFiles = getFileResults(log, dir);

        // Copy faulty files to another list.
        log.debug("Moving possible faulty files (faulty encoding) to another list.");
        for (FileResult res : allFiles) {
            log.debug("Checking if file '" + res.getPath().toString() + "' has encoding '" + requireEncoding
                    + "'.");
            boolean hasCorrectEncoding = true;
            try (FileInputStream fileInputStream = new FileInputStream(res.getPath().toFile())) {
                byte[] bytes = ByteStreams.toByteArray(fileInputStream);
                Charset charset = Charset.forName(this.getRequireEncoding());
                CharsetDecoder decoder = charset.newDecoder();
                ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
                decoder.decode(byteBuffer);
            } catch (CharacterCodingException e) {
                hasCorrectEncoding = false;
            } catch (IOException e) {
                e.printStackTrace();
                log.error(e.getMessage());
                hasCorrectEncoding = false;
            }
            if (!hasCorrectEncoding) {
                log.debug("Moving faulty file: " + res.getPath());
                FileResult faultyFile = new FileResult.Builder(res.getPath())
                        .lastModified(res.getLastModified()).build();
                faultyFiles.add(faultyFile);
            } else {
                log.debug("Has correct encoding. Not moving to faulty files list.");
            }
        }
        log.debug("All faulty files moved.");

        // Report
        if (!faultyFiles.isEmpty()) {
            final StringBuilder builder = new StringBuilder();
            builder.append("Wrong encoding in following files:");
            builder.append(System.getProperty("line.separator"));
            for (FileResult res : faultyFiles) {
                builder.append(res.getPath());
                builder.append(System.getProperty("line.separator"));
            }
            throw new EnforcerRuleException(builder.toString());
        }
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    }
}

From source file:com.github.mikkoi.maven.plugins.enforcer.rule.charsetencoding.CharacterSetEncodingRule.java

License:Apache License

@Nonnull
private Collection<FileResult> getFileResults(final Log log, final Path dir) {
    Collection<FileResult> allFiles = new ArrayList<>();
    FileVisitor<Path> fileVisitor = new GetEncodingsFileVisitor(log,
            this.getIncludeRegex() != null ? this.getIncludeRegex() : INCLUDE_REGEX_DEFAULT,
            this.getExcludeRegex() != null ? this.getExcludeRegex() : EXCLUDE_REGEX_DEFAULT, allFiles);
    try {/*from w ww .j a v a2s  .c om*/
        Set<FileVisitOption> visitOptions = new LinkedHashSet<>();
        visitOptions.add(FileVisitOption.FOLLOW_LINKS);
        Files.walkFileTree(dir, visitOptions, Integer.MAX_VALUE, fileVisitor);
    } catch (Exception e) {
        log.error(e.getCause() + e.getMessage());
    }
    return allFiles;
}

From source file:com.github.zhve.ideaplugin.Util.java

License:Apache License

public static void deleteFileOrDirectory(Log log, File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            // clean directory
            File[] files = file.listFiles();
            if (files != null) {
                for (File f : files)
                    deleteFileOrDirectory(log, f);
            }/*w  ww. j av a2s .  c o m*/
        }
        // delete file or empty directory
        if (file.delete())
            log.info(" " + file.getAbsolutePath());
        else
            log.error(file.getAbsolutePath());
    } else {
        log.info(" " + file.getAbsolutePath());
    }
}

From source file:com.google.code.rptm.CheckSourceDistMojo.java

License:Apache License

private void check(NamedNode node, ScmUtil scmUtil, File dir) throws MojoExecutionException {
    Log log = getLog();
    FilenameMatcher ignore;//from ww w  .  j  av a  2 s.c o  m
    try {
        ignore = scmUtil.getIgnoredEntries(dir);
    } catch (ScmException ex) {
        throw new MojoExecutionException("Unable to get ignore list for " + dir);
    }
    if (log.isDebugEnabled()) {
        log.debug("=================");
        log.debug("Archive entry: " + node.getName());
        log.debug("Directory: " + dir);
        log.debug("Ignore list: " + ignore);
    }
    for (NamedNode child : node.getChildren()) {
        File file = new File(dir, child.getName());
        if (ignore.matches(child.getName())) {
            log.error("Source distribution contains entry that is ignored in SCM: " + file);
        } else if (file.isDirectory()) {
            check(child, scmUtil, file);
        }
    }
}

From source file:com.googlecode.t7mp.PreConditions.java

License:Apache License

static void checkConfiguredTomcatVersion(Log log, String tomcatVersion) throws MojoExecutionException {
    if (!tomcatVersion.startsWith("7.") && !tomcatVersion.startsWith("6.")) {
        log.info("");
        log.info("");
        log.error("======================= MAVEN-T7-PLUGIN ==================");
        log.error("This plugin supports only Version 7 or 6 of Tomcat. You configured: " + tomcatVersion
                + ". Cancel the Build.");
        log.error("===========================================================");
        log.info("");
        log.info("");
        throw new MojoExecutionException(
                "This plugin supports only Version 7 or 6 of Tomcat. You configured " + tomcatVersion);
    }/*from www .  j  av a  2 s . co  m*/
}

From source file:com.igormaznitsa.mvngolang.cvs.AbstractRepo.java

License:Apache License

public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder,
        @Nonnull @MustNotContainNull final String... args) {
    final List<String> cli = new ArrayList<String>();
    cli.add(GetUtils.findFirstNonNull(customCommand, this.command));
    for (final String s : args) {
        cli.add(s);//from www  . j a v a 2  s. c o m
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Executing repo command : " + cli);
    }

    final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    final ProcessExecutor executor = new ProcessExecutor(cli);

    int result = -1;

    try {
        final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream)
                .redirectOutput(outStream).executeNoTimeout();
        result = processResult.getExitValue();

        if (logger.isDebugEnabled()) {
            logger.debug("Exec.out.........................................");
            logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset()));
            logger.debug(".................................................");
        }

        if (result != 0) {
            logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset()));
        }

    } catch (Exception ex) {
        logger.error("Unexpected error", ex);
    }

    return result;
}