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.boretti.drools.integration.drools5.DroolsClassProcessor.java

License:Open Source License

public static void postProcess(Log log, File inputDirectory, String extension, File reportDirectory,
        String reportFile, String[] includes, String[] excludes) throws MojoExecutionException {
    DroolsGoalExecutionLogs dgel = new DroolsGoalExecutionLogs();
    DirectoryScanner scanner = new DirectoryScanner();
    if (!inputDirectory.exists()) {
        log.warn("Skipping not existing directory " + inputDirectory);
        return;/*from  w w  w .  j  a  va2  s .c  o  m*/
    }
    scanner.setBasedir(inputDirectory);
    if (includes == null || includes.length == 0) {
        scanner.setIncludes(new String[] { "**/*" + extension, "*" + extension });
    } else {
        log.info("Included files are " + Arrays.toString(includes));
        scanner.setIncludes(includes);
    }
    if (excludes != null && excludes.length != 0) {
        log.info("Excluded files are " + Arrays.toString(excludes));
        scanner.setExcludes(excludes);
    }
    log.info("Files must ends with " + extension + " to be processed");
    scanner.scan();
    for (String file : scanner.getIncludedFiles()) {
        if (!file.endsWith(extension))
            continue;
        File sfile = new File(inputDirectory, file);
        DroolsClassProcessor.ClassProcessor(log, sfile, dgel);
    }
    try {
        dgel.writeMeToFile(new File(reportDirectory, reportFile));
    } catch (IOException e) {
        log.error("Unable to write report :" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    } catch (JAXBException e) {
        log.error("Unable to write report :" + e.getMessage(), e);
        throw new MojoExecutionException("" + e.getMessage(), e);
    }
}

From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java

License:Open Source License

/**
 * Launch the android emulator and start the simulator after.
 *
 * @param projectName The project name.//  w ww.  j  ava 2  s  .c o  m
 * @param tiProjectDirectory The directory containing the titanium project files.
 * @param appId The Titanium application id.
 * <p>Must use the <code>com.company.name</code> format and not containing -.</p>
 * @param androidAPI The API to use to build the application.
 * @param androidDeviceAPI The API the android emulator should use.
 * @param androidDeviceSkin The skin of the android emulator to use.
 * @param androidDeviceWait The interval between the emulator launch and the simulator launch.
 * In milliseconds.
 * @param log The Maven logger
 * @throws MojoFailureException When the builder process return an error.
 * @throws MojoExecutionException When an error occurs during the call.
 * @throws IOException  When an error occurs during the call.
 * @throws InterruptedException  When an error occurs during the call.
 */
public void launchOnAndroidEmulator(String projectName, File tiProjectDirectory, String appId,
        String androidAPI, String androidDeviceAPI, String androidDeviceSkin, Long androidDeviceWait, Log log)
        throws MojoFailureException, MojoExecutionException, IOException, InterruptedException {
    if (TitaniumUtils.createAvd(androidSdk, androidDeviceAPI, androidDeviceSkin, log)) {
        log.info("AVD created for " + androidDeviceAPI + " " + androidDeviceSkin);
    }
    boolean isEmulatorRunning = false;
    try {
        isEmulatorRunning = TitaniumUtils.isAndroidEmulatorRunning(androidSdk);
    } catch (Throwable t) {
        log.error("Unable to retrieve launched emulators", t);
    }
    if (!isEmulatorRunning) {
        log.info("Launching emulator");
        ProcessBuilder emulatorBuilder = createAndroidBuilderProcess("emulator", projectName,
                tiProjectDirectory.getAbsolutePath(), appId, androidDeviceAPI, androidDeviceSkin);
        AndroidEmulatorThread emulatorThread = new AndroidEmulatorThread(emulatorBuilder, log);
        emulatorThread.start();
        log.info("Waiting for emulator start (" + androidDeviceWait + " ms.)");

        Thread.sleep(androidDeviceWait);
    } else {
        log.info("Skipping emulator launching.");
    }
    log.info("Launching simulator");
    ProcessBuilder simulatorBuilder = createAndroidBuilderProcess("simulator", projectName,
            tiProjectDirectory.getAbsolutePath(), appId, androidAPI, androidDeviceSkin);
    //simulatorBuilder.redirectErrorStream(true);
    Process simulator = simulatorBuilder.start();
    logProcess(simulator, log, null, true);
    log.info("Waiting for simulator end");
    simulator.waitFor();
    log.info("done");
    if (simulator.exitValue() != 0) {
        throw new MojoFailureException("The titanium builder failed");
    }
}

From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java

License:Open Source License

/**
 * <p>Read a line from the reader and log it to the specified logger.</p>
 * <p>This method doesn't block while no data is available.
 * If no data is present when the method is called, nothing is outputed to the log</p>
 * @param log The logger to use to log the message.
 * @param reader The reader from which a line should be read.
 * @param defaultLogLevel The default log level to use to log message when the
 * log level is not present in the parsed line.
 * @return the log level used to log the line.
 *///from   w  ww. jav  a2 s  .com
public static String logProcessLine(Log log, BufferedReader reader, String defaultLogLevel) {
    try {
        defaultLogLevel = readAndAppendLine(reader, log, null, defaultLogLevel);
    } catch (IOException ioe) {
        log.error("Error while processing input", ioe);
    }
    return defaultLogLevel;
}

From source file:org.codehaus.mojo.javascript.titanium.TitaniumBuilder.java

License:Open Source License

/**
 * <p>Log the process to the specified logger.</p>
 * @param p The process to log.// www  .  j  a  v a 2 s. c  om
 * @param log The logger where the message should be outputted.
 * @param builder A StringBuilder where each line will be appended.
 * May be null.
 * @param skipErrStream true if the error stream should not be logged.
 */
public static void logProcess(Process p, Log log, StringBuilder builder, boolean skipErrStream) {
    BufferedReader inReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader errReader = new BufferedReader(new InputStreamReader(p.getErrorStream()));

    String defaultInLevel = null;
    String defaultErrLevel = null;
    try {
        while (isProcessRunning(p)) {
            defaultInLevel = readAndAppendLine(inReader, log, builder, defaultInLevel);
            if (!skipErrStream) {
                defaultErrLevel = readAndAppendLine(errReader, log, builder, defaultErrLevel);
            }
        }
        readAndAppendLine(inReader, log, builder, defaultInLevel);
        if (!skipErrStream) {
            readAndAppendLine(errReader, log, builder, defaultErrLevel);
        }
    } catch (IOException ioe) {
        log.error("Error while processing builder input", ioe);
    }
}

From source file:org.codehaus.mojo.jaxb2.shared.environment.logging.MavenLogHandler.java

License:Apache License

/**
 * Creates a new MavenLogHandler which adapts a {@link Handler} to emit log messages onto a Maven Log.
 *
 * @param log                       The Maven Log to emit log messages to.
 * @param prefix                    An optional prefix used to prefix any log message.
 * @param encoding                  The encoding which should be used.
 * @param acceptedLogRecordPrefixes A non-null list of prefixes holding LogRecord logger names for
 *                                  permitted/accepted LogRecords.
 *///from w w w .j  av a2  s . c  om
public MavenLogHandler(final Log log, final String prefix, final String encoding,
        final String[] acceptedLogRecordPrefixes) {

    // Check sanity
    Validate.notNull(log, "log");
    Validate.notNull(prefix, "prefix");
    Validate.notEmpty(encoding, "encoding");

    // Assign internal state
    this.log = log;
    this.prefix = prefix.isEmpty() ? "" : "[" + prefix + "]: ";

    setFormatter(new SimpleFormatter());
    setLevel(getJavaUtilLoggingLevelFor(log));
    try {
        setEncoding(encoding);
    } catch (UnsupportedEncodingException e) {
        log.error("Could not use encoding '" + encoding + "'", e);
    }

    if (acceptedLogRecordPrefixes != null && acceptedLogRecordPrefixes.length > 0) {
        setFilter(getLoggingFilter(acceptedLogRecordPrefixes));
    }
}

From source file:org.codehaus.mojo.tomcat.EmbeddedRegistry.java

License:Apache License

/**
 * Reports the exception. If a log is given (typically when called from within a Mojo) the
 * message will be printed to the log. Otherwise it will be printed to StdErr.
 * /*from www  .j av  a2s  .co m*/
 * @param log the log to write the message to; null to write to stderr
 * @param e exception which shall be reported
 * @param message message which shall be reported
 */
private void error(final Log log, final LifecycleException e, final String message) {
    if (log == null) {
        System.err.println("ERROR: " + message);
        e.printStackTrace();
    } else {
        log.error(message, e);
    }
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Lookup and return the content of the README.md file for this plugin.
 *
 * @param project project//from ww w  .  j ava  2 s.co  m
 * @param log log
 * @return content of REDME.md file or null if not found
 */
protected static String getReadme(MavenProject project, Log log) {
    File readmePath = new File(project.getBasedir(), "README.md");
    if (readmePath.exists()) {
        log.debug("README.md file has been found: '" + readmePath.getAbsolutePath() + "'");
        try {
            StringBuilder builder = new StringBuilder();
            LineNumberReader fileReader = new LineNumberReader(new FileReader(readmePath));
            String line;
            while ((line = fileReader.readLine()) != null) {
                builder.append(line);
                builder.append("\n");
            }
            log.info("File README.md with " + builder.length() + " characters has been attached to project '"
                    + project.getName() + "'");
            return builder.toString();
        } catch (IOException ex) {
            log.error("Error while reading README.md file", ex);
        }
    }
    return null;
}

From source file:org.gephi.maven.MetadataUtils.java

License:Apache License

/**
 * Use local Git repository configuration to lookup the sourcecode URL.
 *
 * @param project project//from www  .j  a  va 2  s  .  c o m
 * @param log log
 * @return source code url or null
 */
protected static String getSourceCodeUrlFromGit(MavenProject project, Log log) {
    File gitPath = new File(project.getBasedir(), ".git");
    if (gitPath.exists() && gitPath.isDirectory()) {
        File gitPathConfig = new File(gitPath, "config");
        if (gitPathConfig.exists() && gitPathConfig.isFile()) {
            log.debug("Git config gile located at '" + gitPathConfig.getAbsolutePath() + "'");
            try {
                BufferedReader fileReader = new BufferedReader(new FileReader(gitPathConfig));

                Pattern pattern = Pattern.compile("\\s*url = (.*)");
                String line, url = null;
                while ((line = fileReader.readLine()) != null) {
                    Matcher m = pattern.matcher(line);
                    if (m.matches()) {
                        url = m.group(1);
                        break;
                    }
                }
                fileReader.close();

                if (url != null) {
                    log.debug("URL found in .git/config: '" + url + "'");
                    if (url.startsWith("http://")) {
                        return url;
                    } else if (url.startsWith("git@")) {
                        Pattern gitPattern = Pattern.compile("git@([^:]*):([^.]*).git");
                        Matcher gitMatcher = gitPattern.matcher(url);
                        if (gitMatcher.matches()) {
                            String res = "http://" + gitMatcher.group(1) + "/" + gitMatcher.group(2);
                            log.debug("Rewrote URL to '" + res + "'");
                            return res;
                        }
                    } else {
                        log.debug("Couldn't find a pattern in the git URL: " + url);
                    }
                }
            } catch (IOException e) {
                log.error("Error while reading Git config", e);
            }
        }
    } else {
        log.debug("The .git folder couldn't be found at '" + gitPath.getAbsolutePath() + "'");
    }
    return null;
}

From source file:org.gephi.maven.ScreenshotUtils.java

License:Apache License

protected static List<Image> copyScreenshots(MavenProject mavenProject, File outputFolder, String urlPrefix,
        Log log) throws MojoExecutionException {
    File folder = new File(mavenProject.getBasedir(), "src/img");
    if (folder.exists()) {
        log.debug("Folder '" + folder.getAbsolutePath() + "' exists");

        // List images in folder
        File[] files = folder.listFiles(new FilenameFilter() {
            @Override/*from w ww  . j a  va 2  s  . c o m*/
            public boolean accept(File dir, String name) {
                return !name.startsWith(".") && (name.endsWith(".png") || name.endsWith(".jpg")
                        || name.endsWith(".jpeg") || name.endsWith(".gif")) && !name.contains(THUMBNAIL_SUFFIX);
            }
        });

        // Sort files alphabetically
        Arrays.sort(files, new Comparator<File>() {
            @Override
            public int compare(File f1, File f2) {
                return f1.getName().compareTo(f2.getName());
            }
        });
        log.debug(files.length + " images found in source folder");

        // Create dest folder
        if (outputFolder.mkdirs()) {
            log.debug("Output folder '" + outputFolder.getAbsolutePath() + "' was created");
        }

        List<Image> images = new ArrayList<Image>();
        for (File file : files) {
            if (file.getName().contains(" ")) {
                throw new MojoExecutionException("Image file '" + file.getAbsolutePath()
                        + "' contains spaces. Please rename image and try again");
            }
            // Read original file and copy to dest folder
            String fileName = file.getName().substring(0, file.getName().lastIndexOf(".")) + ".png";
            File imageDestFile = new File(outputFolder, fileName);
            try {
                Thumbnails.of(file).outputFormat("png").outputQuality(0.90).resizer(Resizers.NULL).scale(1.0)
                        .toFile(imageDestFile);
            } catch (IOException ex) {
                log.error("Can't copy image file from '" + file.getAbsolutePath() + "' to '"
                        + imageDestFile.getAbsolutePath() + "'", ex);
            }

            Image image = new Image();
            image.image = urlPrefix + fileName;
            images.add(image);

            // Thumbnail path
            String thumFileName = file.getName().substring(0, file.getName().lastIndexOf("."))
                    + THUMBNAIL_SUFFIX + ".png";
            File thumbFile = new File(outputFolder, thumFileName);
            if (!thumbFile.exists()) {
                // Thumbnail creation
                try {
                    Thumbnails.of(file).outputFormat("png").outputQuality(0.90).size(140, 140)
                            .crop(Positions.CENTER).toFile(thumbFile);
                    log.debug("Created thumbnail in file '" + thumbFile.getAbsolutePath() + "'");
                    image.thumbnail = urlPrefix + thumFileName;
                } catch (IOException ex) {
                    log.error("Can't create thumbnail for image file '" + file.getAbsolutePath() + "'", ex);
                }
            }

            log.info("Attached image '" + file.getName() + "' to plugin " + mavenProject.getName());
        }
        return images;
    } else {
        log.debug("Folder '" + folder.getAbsolutePath() + "' was not found");
    }
    return null;
}

From source file:org.jboss.provisioning.wildfly.build.ModuleXmlVersionResolver.java

License:Apache License

public static void convertModules(Path source, Path target, Map<String, Artifact> artifacts, Log log)
        throws IOException {
    if (Files.isDirectory(source)) {
        Files.createDirectories(target);
    } else {/*from   ww  w .  j  a va 2 s.  co m*/
        Files.createDirectories(target.getParent());
    }
    Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
            new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                        throws IOException {
                    final Path targetDir = target.resolve(source.relativize(dir));
                    try {
                        Files.copy(dir, targetDir);
                    } catch (FileAlreadyExistsException e) {
                        if (!Files.isDirectory(targetDir)) {
                            throw e;
                        }
                    }
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                    try {
                        if ("module.xml".equals(file.getFileName().toString())) {
                            convertModule(file, target.resolve(source.relativize(file)), artifacts, log);
                        } else {
                            Files.copy(file, target.resolve(source.relativize(file)));
                        }
                    } catch (XMLStreamException ex) {
                        log.error("Error reading " + file, ex);
                    }
                    return FileVisitResult.CONTINUE;
                }
            });
}