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

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

Introduction

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

Prototype

void debug(Throwable error);

Source Link

Document

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

Usage

From source file:org.eclipse.acceleo.maven.launcher.compatibility.AcceleoLauncherMojo.java

License:Open Source License

/**
 * {@inheritDoc}//from www .  j  a v  a 2 s. co  m
 * 
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    Log log = getLog();
    log.info("Acceleo maven stand alone generation...");

    log.info("Starting generator class loading...");

    URLClassLoader newLoader = null;
    try {
        List<?> runtimeClasspathElements = project.getRuntimeClasspathElements();
        List<?> compileClasspathElements = project.getCompileClasspathElements();
        URL[] runtimeUrls = new URL[runtimeClasspathElements.size() + compileClasspathElements.size()];
        int i = 0;
        for (Object object : runtimeClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the runtime dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        for (Object object : compileClasspathElements) {
            if (object instanceof String) {
                String str = (String) object;
                log.debug("Adding the compilation dependency " + str
                        + " to the classloader for the package resolution");
                runtimeUrls[i] = new File(str).toURI().toURL();
                i++;
            } else {
                log.debug("Runtime classpath entry is not a string: " + object);
            }
        }
        newLoader = new URLClassLoader(runtimeUrls, Thread.currentThread().getContextClassLoader());
    } catch (DependencyResolutionRequiredException e) {
        log.error(e);
    } catch (MalformedURLException e) {
        log.error(e);
    }

    try {
        if (newLoader != null) {
            final Class<?> generatorClazz = Class.forName(generatorClass, true, newLoader);

            log.info("Starting the generation sequence for the generator '" + generatorClass + "'...");
            final Method mainMethod = generatorClazz.getMethod("main", String[].class);

            List<String> arguments = new ArrayList<String>(parameters.size() + 2);
            log.info("Model: '" + model + "'");
            arguments.add(model);
            log.info("Output folder: '" + outputFolder + "'");
            arguments.add(outputFolder);
            for (String parameter : parameters) {
                log.info("Parameter: '" + parameter + "'");
                arguments.add(parameter);
            }

            log.info("Invoking generator.");
            mainMethod.invoke(null, (Object) arguments.toArray(new String[arguments.size()]));

            log.info("Generation completed.");
        }
    } catch (ClassNotFoundException e) {
        log.error(e);
    } catch (SecurityException e) {
        log.error(e);
    } catch (NoSuchMethodException e) {
        log.error(e);
    } catch (IllegalAccessException e) {
        log.error(e);
    } catch (IllegalArgumentException e) {
        log.error(e);
    } catch (InvocationTargetException e) {
        log.error(e);
    }

}

From source file:org.eclipse.scada.build.helper.DefaultPomHelper.java

License:Open Source License

@Override
public Set<MavenProject> expandProjects(final Collection<MavenProject> projects, final Log log,
        final MavenSession session) {
    try {//  w  w w .  j  av a 2s.  c o m
        final Set<MavenProject> result = new HashSet<MavenProject>();

        final Queue<MavenProject> queue = new LinkedList<MavenProject>(projects);
        while (!queue.isEmpty()) {
            final MavenProject project = queue.poll();
            log.debug("Checking project: " + project);
            if (project.getFile() == null) {
                log.info("Skipping non-local project: " + project);
                continue;
            }
            if (!result.add(project)) {
                // if the project was already in our result, there is no need to process twice
                continue;
            }
            // add all children to the queue
            queue.addAll(loadChildren(project, log, session));
            if (hasLocalParent(project)) {
                // if we have a parent, add the parent as well
                queue.add(project.getParent());
            }
        }
        return result;
    } catch (final Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:org.eclipse.scada.build.helper.DefaultPomHelper.java

License:Open Source License

private Collection<MavenProject> loadChildren(final MavenProject project, final Log log,
        final MavenSession session) throws Exception {
    final Set<MavenProject> result = new HashSet<MavenProject>();

    log.debug("Loading children for: " + project);

    log.debug("Base dir: " + project.getBasedir());

    if (project.getBasedir() == null) {
        log.debug("Don't have a base dir");
        // if we don't have a base dir, we cannot change anything
        return result;
    }//from   w w  w  . jav a 2s.c om

    for (final String module : getModules(project)) {
        File file = new File(project.getBasedir(), module);
        if (file.isDirectory()) {
            file = new File(file, "pom.xml");
        }
        log.debug("Looking up: " + file);
        result.add(loadProject(file, session));
    }

    return result;
}

From source file:org.eclipse.xtend.maven.AbstractXtendCompilerMojo.java

License:Open Source License

protected void compile(String classPath, List<String> sourcePaths, String outputPath)
        throws MojoExecutionException {
    XtendBatchCompiler compiler = getBatchCompiler();
    Log log = getLog();
    compiler.setResourceSetProvider(new MavenProjectResourceSetProvider(project));
    Iterable<String> filtered = filter(sourcePaths, FILE_EXISTS);
    if (Iterables.isEmpty(filtered)) {
        String dir = Iterables.toString(sourcePaths);
        log.info("skip compiling sources because the configured directory '" + dir + "' does not exist.");
        return;//from w w w  .  j  a va  2 s.c  om
    }
    String baseDir = project.getBasedir().getAbsolutePath();
    log.debug("Set Java Compliance Level: " + javaSourceVersion);
    compiler.setJavaSourceVersion(javaSourceVersion);
    log.debug("Set generateSyntheticSuppressWarnings: " + generateSyntheticSuppressWarnings);
    compiler.setGenerateSyntheticSuppressWarnings(generateSyntheticSuppressWarnings);
    log.debug("Set generateGeneratedAnnotation: " + generateGeneratedAnnotation);
    compiler.setGenerateGeneratedAnnotation(generateGeneratedAnnotation);
    log.debug("Set includeDateInGeneratedAnnotation: " + includeDateInGeneratedAnnotation);
    compiler.setIncludeDateInGeneratedAnnotation(includeDateInGeneratedAnnotation);
    log.debug("Set generatedAnnotationComment: " + generatedAnnotationComment);
    compiler.setGeneratedAnnotationComment(generatedAnnotationComment);
    log.debug("Set baseDir: " + baseDir);
    compiler.setBasePath(baseDir);
    log.debug("Set temp directory: " + getTempDirectory());
    compiler.setTempDirectory(getTempDirectory());
    log.debug("Set DeleteTempDirectory: " + false);
    compiler.setDeleteTempDirectory(false);
    log.debug("Set classpath: " + classPath);
    compiler.setClassPath(classPath);
    String bootClassPath = getBootClassPath();
    log.debug("Set bootClasspath: " + bootClassPath);
    compiler.setBootClassPath(bootClassPath);
    log.debug("Set source path: " + concat(File.pathSeparator, newArrayList(filtered)));
    compiler.setSourcePath(concat(File.pathSeparator, newArrayList(filtered)));
    log.debug("Set output path: " + outputPath);
    compiler.setOutputPath(outputPath);
    log.debug("Set encoding: " + encoding);
    compiler.setFileEncoding(encoding);
    log.debug("Set writeTraceFiles: " + writeTraceFiles);
    compiler.setWriteTraceFiles(writeTraceFiles);
    if (!compiler.compile()) {
        String dir = concat(File.pathSeparator, newArrayList(filtered));
        throw new MojoExecutionException("Error compiling xtend sources in '" + dir + "'.");
    }
}

From source file:org.elasticsearch.enforcer.rules.BannedAttachedArtifacts.java

License:Apache License

public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    List<Pattern> excludedPatterns = new ArrayList<Pattern>(excludes.size());
    for (String exclude : excludes) {
        excludedPatterns.add(Pattern.compile(exclude));
    }/*from   w w w.  j  a  v  a  2s.  com*/

    try {
        MavenProject project = (MavenProject) helper.evaluate("${project}");
        List<Artifact> artifactList = project.getAttachedArtifacts();
        for (Artifact artifact : artifactList) {
            String artifactFileName = artifact.getFile().getName();
            log.debug("evaluating artifact [" + artifactFileName + "]");
            for (Pattern pattern : excludedPatterns) {
                if (pattern.matcher(artifactFileName).matches()) {
                    throw new EnforcerRuleException("found banned attached artifact: artifact ["
                            + artifactFileName + "] matched exclude pattern [" + pattern.toString() + "]");
                }
            }
        }

    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup expression", e);
    }

}

From source file:org.eluder.coveralls.maven.plugin.logging.JobLogger.java

License:Open Source License

@Override
public void log(final Log log) {
    StringBuilder starting = new StringBuilder("Starting Coveralls job");
    if (job.getServiceName() != null) {
        starting.append(" for " + job.getServiceName());
        if (job.getServiceJobId() != null) {
            starting.append(" (" + job.getServiceJobId() + ")");
        } else if (job.getServiceBuildNumber() != null) {
            starting.append(" (" + job.getServiceBuildNumber());
            if (job.getServiceBuildUrl() != null) {
                starting.append(" / " + job.getServiceBuildUrl());
            }//from  w  w  w .ja va  2 s.c  o  m
            starting.append(")");
        }
    }
    if (job.isDryRun()) {
        starting.append(" in dry run mode");
    }
    log.info(starting.toString());

    if (job.getRepoToken() != null) {
        log.info("Using repository token <secret>");
    }

    if (job.getGit() != null) {
        String commit = job.getGit().getHead().getId();
        String branch = (job.getBranch() != null ? job.getBranch() : job.getGit().getBranch());
        log.info("Git commit " + commit.substring(0, ABBREV) + " in " + branch);
    }

    if (log.isDebugEnabled()) {
        try {
            log.debug("Complete Job description:\n" + jsonMapper.writeValueAsString(job));
        } catch (JsonProcessingException ex) {
            throw new RuntimeException(ex);
        }
    }
}

From source file:org.everit.osgi.dev.maven.util.PluginUtil.java

License:Apache License

/**
 * Sends a command to a socket and returns a response. This function works based on line breaks.
 *
 * @param command//from  w w  w  .j  a v a  2  s  .  c  o m
 *          The command to send.
 * @param socket
 *          The socket to send the command to.
 * @param serverName
 *          The name of the server.
 * @param log
 *          The logger where debug information will be written.
 * @return The response from the server.
 * @throws IOException
 *           if there is a problem in the connection.
 */
public static String sendCommandToSocket(final String command, final Socket socket, final String serverName,
        final Log log) throws IOException {
    log.debug("Sending command to " + serverName + ": " + command);
    InputStream inputStream = socket.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Charset.defaultCharset()));
    OutputStream outputStream = socket.getOutputStream();
    outputStream.write((command + "\n").getBytes(Charset.defaultCharset()));
    outputStream.flush();
    String response = reader.readLine();
    log.debug("Got response from " + serverName + ": " + response);
    return response;
}

From source file:org.evosuite.maven.util.EvoSuiteRunner.java

License:Open Source License

private void handleProcessOutput(final Process process, final Log logger) {

    Thread reader = new Thread() {
        @Override/* w w  w.ja v a2 s.c om*/
        public void run() {
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

                while (!this.isInterrupted()) {
                    String line = in.readLine();
                    if (line != null && !line.isEmpty()) {
                        logger.info(line);
                    }
                }
            } catch (Exception e) {
                logger.debug("Exception while reading spawn process output: " + e.toString());
            }
        }
    };

    reader.start();
    logger.debug("Started thread to read spawn process output");
}

From source file:org.forgerock.opendj.maven.doc.Utils.java

License:CDDL license

/**
 * Logs what is on the classpath for debugging.
 * @param classLoader   The ClassLoader with the classpath.
 * @param log           The Maven plugin log in which to write debug messages.
 *//*from www  .ja va  2  s .c  om*/
static void debugClassPathElements(ClassLoader classLoader, Log log) {
    if (null == classLoader) {
        return;
    }
    log.debug("--------------------");
    log.debug(classLoader.toString());
    if (classLoader instanceof URLClassLoader) {
        final URLClassLoader ucl = (URLClassLoader) classLoader;
        int i = 0;
        for (URL url : ucl.getURLs()) {
            log.debug("url[" + (i++) + "]=" + url);
        }
    }
    debugClassPathElements(classLoader.getParent(), log);
}

From source file:org.gdms.maven.sql.AbstractGenerateSql.java

License:Open Source License

protected void doExecute(File sqlScriptsDirectory, File outputDirectory)
        throws MojoExecutionException, MojoFailureException {
    MavenLogAppender.startPluginLog(this);

    try {// w w  w .j a v  a2  s .  com
        final String inputPath = sqlScriptsDirectory.getAbsolutePath();

        getLog().info(String.format("Processing folder %s", inputPath));
        if (!sqlScriptsDirectory.exists()) {
            // nothing to do, no valid input directory
            getLog().warn("Directory does not exist! Nothing to do.");
            return;
        }

        Collection<File> fil = FileUtils.listFiles(sqlScriptsDirectory, new String[] { "sql" }, true);

        int size = fil.size();
        if (size == 0) {
            // nothing to do, no files...
            getLog().warn("Found 0 sql files! Nothing to do.");
        } else {
            // be sure the output dir exists
            if (!outputDirectory.exists()) {
                outputDirectory.mkdirs();
            }

            List<File> changedFiles = new ArrayList<File>();

            for (File ff : fil) {
                File tff = getTargetFile(inputPath, outputDirectory, ff);
                if (!tff.exists() || FileUtils.isFileNewer(ff, tff)) {
                    changedFiles.add(ff);
                }
            }

            if (changedFiles.isEmpty()) {
                getLog().info("Nothing to compile - all compiled scripts are up to date");
            } else if (changedFiles.size() != size) {
                getLog().info(String.format("Compiling %d changed sql files out of %d to %s",
                        changedFiles.size(), size, outputDirectory.getAbsolutePath()));
            } else {
                getLog().info(
                        String.format("Compiling %d sql files to %s", size, outputDirectory.getAbsolutePath()));
            }

            Properties props = DataSourceFactory.getDefaultProperties();

            if (engineProperties != null) {
                props = new Properties(props);
                for (String k : engineProperties.stringPropertyNames()) {
                    props.setProperty(k, engineProperties.getProperty(k));
                }
            }

            if (getLog().isDebugEnabled()) {
                // display properties
                Log log = getLog();
                log.debug("Engine invocation properties:");
                if (engineProperties == null) {
                    log.debug("No custom properties. Using Default:");
                } else {
                    log.debug("Custom properties:");
                    printProperties(engineProperties);
                    log.debug("Merged with default properties:");
                }
                printProperties(props);
            }

            int errors = 0;

            for (File ff : changedFiles) {
                if (getLog().isDebugEnabled()) {
                    getLog().debug("Parsing script " + ff.getAbsolutePath());
                }
                SQLScript s;
                try {
                    s = Engine.parseScript(ff, props);
                } catch (Exception e) {
                    if (errors == 0) {
                        getLog().info("---------------------------------------");
                        getLog().error("COMPILATION ERROR :");
                        getLog().info("---------------------------------------");
                    }
                    errors++;
                    getLog().error(e.getLocalizedMessage());
                    getLog().info(String.format("location:  %s", ff.getAbsolutePath()));
                    if (e instanceof ParseException) {
                        ParseException p = (ParseException) e;
                        getLog().info(p.getLocation().prettyPrint());
                    }
                    getLog().debug(e);
                    getLog().info("---------------------------------------");
                    continue;
                }
                File targetFile = getTargetFile(inputPath, outputDirectory, ff);

                // create parent directory. Might not exist
                targetFile.getParentFile().mkdirs();

                // delete existing compiled script
                if (targetFile.exists()) {
                    targetFile.delete();
                }

                try {
                    s.save(new FileOutputStream(targetFile));
                } catch (IOException ex) {
                    // this is not good, let's abort
                    throw new MojoExecutionException(
                            String.format("Error while saving to '%s'", targetFile.getAbsolutePath()), ex);
                }
            }

            if (errors != 0) {
                getLog().info(String.format("%d errors", errors));
                String errorStr;
                if (errors == 1) {
                    errorStr = "There was 1 SQL build error!";
                } else {
                    errorStr = String.format("There were %d SQL build errors!", errors);
                }
                throw new MojoFailureException(errorStr + " See above for more details.");
            }
        }
    } finally {
        MavenLogAppender.endPluginLog(this);
    }
}