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(CharSequence content, Throwable error);

Source Link

Document

Send a message (and accompanying exception) to the user in the error error level.
The error's stacktrace will be output when this error level is enabled.

Usage

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

License:Open Source License

/**
 * Log given message and throwable at error level
 *
 * @param message/*  w w w  . ja  v  a2s .c  o  m*/
 * @param throwable
 */
protected void error(String message, Throwable throwable) {
    Log log = getLog();
    if (log != null) {
        log.error(message, throwable);
    }
}

From source file:org.primefaces.extensions.optimizerplugin.optimizer.ClosureCompilerOptimizer.java

License:Apache License

private void writeSourceMap(File sourceMapFile, String sourceFileName, SourceMap sourceMap, String outputDir,
        Log log) {
    try {/*from w  w  w.ja  v  a 2  s .c  o  m*/
        FileWriter out = new FileWriter(sourceMapFile);
        sourceMap.appendTo(out, sourceFileName);
        out.flush();
        IOUtil.close(out);
    } catch (Exception e) {
        log.error("Failed to write an JavaScript Source Map file for " + sourceFileName, e);
    }

    // move the file
    moveToSourceMapDir(sourceMapFile, outputDir, log);
}

From source file:org.primefaces.extensions.optimizerplugin.optimizer.ClosureCompilerOptimizer.java

License:Apache License

private void moveToSourceMapDir(File file, String outputDir, Log log) {
    try {//from  www .  ja  v a 2s.  c  o m
        String name = file.getName();
        String target = outputDir + name;
        File targetFile = new File(target);
        Files.createParentDirs(targetFile);
        Files.move(file, targetFile);
    } catch (Exception e) {
        log.error("File " + file + " could not be moved to " + outputDir, e);
    }
}

From source file:org.primefaces.extensions.optimizerplugin.optimizer.ClosureCompilerOptimizer.java

License:Apache License

private void writeSourceMappingURL(File minifiedFile, File sourceMapFile, String sourceMapRoot, Charset cset,
        Log log) {
    try {//from   w  w w. j ava  2s.  c  om
        // write sourceMappingURL
        String smRoot = (sourceMapRoot != null ? sourceMapRoot : "");
        Files.append(System.getProperty("line.separator"), minifiedFile, cset);
        Files.append("//# sourceMappingURL=" + smRoot + sourceMapFile.getName(), minifiedFile, cset);
    } catch (IOException e) {
        log.error("//# sourceMappingURL for the minified file " + minifiedFile + " could not be written", e);
    }
}

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   ww w .j av  a 2s  . co  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.nexus.maven.m2settings.MojoLogger.java

License:Open Source License

@Override
protected void doLog(final Event event) {
    Log mojoLog = getOwner().getLog();
    if (mojoLog == null) {
        log.warn("Mojo.log not configured; owner: {}, event: {}", owner, event);
        return;//from  w  ww.j  a v  a2s.  c  o m
    }

    switch (event.getLevel()) {
    case TRACE:
    case DEBUG:
        mojoLog.debug(event.getMessage(), event.getCause());
        break;
    case INFO:
        mojoLog.info(event.getMessage(), event.getCause());
        break;
    case WARN:
        mojoLog.warn(event.getMessage(), event.getCause());
        break;
    case ERROR:
        mojoLog.error(event.getMessage(), event.getCause());
        break;
    default:
        throw new UnsupportedOperationException();
    }
}

From source file:org.spdx.maven.SpdxProjectInformation.java

License:Apache License

/**
 * Log information on all fields - typically used for debugging
 * @param log/*from  w w  w . j a va 2  s. co m*/
 */
public void logInfo(Log log) {
    log.debug("SPDX Project Name: " + this.getName());
    log.debug("SPDX Document comment: " + this.getDocumentComment());
    log.debug("SPDX Creator comment: " + this.getCreatorComment());
    log.debug("SPDX Description: " + this.getDescription());
    log.debug("SPDX License comment: " + this.getLicenseComment());
    log.debug("SPDX Originator: " + this.getOriginator());
    log.debug("SPDX PackageArchiveFileName: " + this.getPackageArchiveFileName());
    log.debug("SPDX SHA1: " + this.getSha1());
    log.debug("SPDX Short description: " + this.getShortDescription());
    log.debug("SPDX Supplier: " + this.getSupplier());
    log.debug("SPDX Source Info:  " + this.getSourceInfo());
    log.debug("SPDX Version info: " + this.getVersionInfo());
    log.debug("SPDX Concluded license: " + this.getConcludedLicense().toString());
    log.debug("SPDX Declared license: " + this.getDeclaredLicense().toString());
    log.debug("SPDX Download URL: " + this.getDownloadUrl());
    log.debug("SPDX Home page: " + this.getHomePage());
    if (this.documentAnnotations != null && this.documentAnnotations.length > 0) {
        log.debug("Document annotations: ");
        for (Annotation annotation : documentAnnotations) {
            annotation.logInfo(log);
        }
    }
    if (this.packageAnnotations != null && this.packageAnnotations.length > 0) {
        log.debug("Package annotations: ");
        for (Annotation annotation : packageAnnotations) {
            annotation.logInfo(log);
        }
    }
    String[] creators = this.getCreators();
    if (creators != null) {
        for (int i = 0; i < creators.length; i++) {
            log.debug("SPDX Creator: " + creators[i]);
        }
    }
    if (this.externalRefs != null) {
        for (ExternalReference externalReference : externalRefs) {
            ExternalRef externalRef;
            try {
                externalRef = externalReference.getExternalRef();
                StringBuilder externalRefString = new StringBuilder();
                externalRefString.append(externalRef.getReferenceCategory().getTag());
                externalRefString.append(' ');
                try {
                    externalRefString.append(ListedReferenceTypes.getListedReferenceTypes()
                            .getListedReferenceName(externalRef.getReferenceType().getReferenceTypeUri()));
                } catch (InvalidSPDXAnalysisException e) {
                    externalRefString.append("Invalid Reference Type");
                }
                externalRefString.append(' ');
                externalRefString.append(externalRef.getReferenceLocator());
                log.debug("External Ref: " + externalRefString.toString());
            } catch (MojoExecutionException e1) {
                log.error("Invalid external reference", e1);
            }

        }
    }
}

From source file:org.wisdom.maven.node.NPM.java

License:Apache License

/**
 * Utility method to extract the version from a NPM by reading its 'package.json' file.
 *
 * @param npmDirectory the directory in which the NPM is installed
 * @param log          the logger object
 * @return the read version, "0.0.0" if there are not 'package.json' file, {@code null} if this file cannot be
 * read or does not contain the "version" metadata
 *///from w w  w  .j a  va  2  s. c  o m
public static String getVersionFromNPM(File npmDirectory, Log log) {
    File packageFile = new File(npmDirectory, PACKAGE_JSON);
    if (!packageFile.isFile()) {
        return "0.0.0";
    }

    FileReader reader = null;
    try {
        reader = new FileReader(packageFile); //NOSONAR
        JSONObject json = (JSONObject) JSONValue.parseWithException(reader);
        return (String) json.get("version");
    } catch (IOException | ParseException e) {
        log.error("Cannot extract version from " + packageFile.getAbsolutePath(), e);
    } finally {
        IOUtils.closeQuietly(reader);
    }

    return null;
}

From source file:org.wisdom.maven.node.NPM.java

License:Apache License

public static void configureRegistry(NodeManager node, Log log, String npmRegistryUrl) {

    CommandLine cmdLine = new CommandLine(node.getNodeExecutable());
    File npmCli = new File(node.getNodeModulesDirectory(), "npm/bin/npm-cli.js");
    // NPM is launched using the main file, also disable the auto-quoting
    cmdLine.addArgument(npmCli.getAbsolutePath(), false);
    cmdLine.addArgument("config");
    cmdLine.addArgument("set");
    cmdLine.addArgument("registry");
    cmdLine.addArguments(npmRegistryUrl);

    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(0);/*  w w  w.  ja  v a  2  s  . c  o m*/

    PumpStreamHandler streamHandler = new PumpStreamHandler(new LoggedOutputStream(log, false),
            new LoggedOutputStream(log, true));

    executor.setStreamHandler(streamHandler);

    log.info("Configuring npm registry by executing " + cmdLine.toString());

    try {
        executor.execute(cmdLine, extendEnvironmentWithNodeInPath(node));
    } catch (IOException e) {
        log.error("Error during the configuration of NPM registry with the url " + npmRegistryUrl
                + " - check log", e);
    }
}

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

License:Apache License

/**
 * Display the content of the HTTP response.<br/>
 * <b>CAUTION:</b> Calling this method will consume the response content
 * InputStream!/*ww  w .  j av  a2 s. co m*/
 *
 * @param response The HTTP response of which to display the content.
 */
private void debugResponse(final HttpResponse response) {
    final Log logger = getLog();

    logger.debug("Displaying content:");

    BufferedReader br = null;

    try {
        br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        for (String line = br.readLine(); line != null; line = br.readLine()) {
            logger.debug(line);
        }
    } catch (IOException ex) {
        logger.error("Failed displaying content!", ex);
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException ex) {
                logger.warn(ex.getMessage(), ex);
            }
        }
    }
}