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.yuanheng.cookcc.maven.JavacTask.java

License:Apache License

public void execute(Log log, Compiler compiler, CompilerConfiguration config, String javaSrcDir,
        String cookccPath) throws MojoExecutionException {
    File file = new File(m_src);
    if (!file.isFile()) {
        throw new MojoExecutionException("File " + m_src + " does not exist.");
    }/*w w  w  .  j a  v  a2 s  .  c  o  m*/
    try {
        for (Option option : m_options) {
            if (option.arg == null)
                config.addCompilerCustomArgument("-A" + option.opt, null);
            else
                config.addCompilerCustomArgument("-A" + option.opt + "=" + option.arg, null);
        }
        HashSet<File> set = new HashSet<File>();
        m_src.replace('/', File.separatorChar);
        log.info("CookCC is processing " + m_src);
        set.add(new File(m_src));
        config.setSourceFiles(set);

        String[] args = compiler.createCommandLine(config);
        String msg = "javac";
        for (String arg : args)
            msg += " " + arg;
        log.debug(msg);
        log.debug("Using compiler: " + compiler.getClass());

        CompilerResult result = compiler.performCompile(config);
        log.debug("Success: " + result.isSuccess());

        boolean hasError = false;
        StringBuilder errorMessages = new StringBuilder();
        errorMessages.append(
                "CookCC reported an error.  Please use mvn -X clean cookcc:run to display the full javac command to execute cookcc and reproduce the error message.\n");

        log.debug("CompilerMessages: " + result.getCompilerMessages().size());
        for (CompilerMessage message : result.getCompilerMessages()) {
            CompilerMessage.Kind kind = message.getKind();
            switch (kind) {
            case WARNING:
                log.warn(message.toString());
                break;
            case ERROR:
                log.error(message.toString());
                errorMessages.append(message.getMessage()).append('\n');
                hasError = true;
                break;
            default:
                log.info(kind + ": " + message.toString());
                break;
            }
        }
        if (hasError || !result.isSuccess())
            throw new MojoExecutionException(errorMessages.toString());
    } catch (CompilerException ex) {
        throw new MojoExecutionException("Error compiling code", ex);
    }
}

From source file:org.yuanheng.cookcc.maven.XccTask.java

License:Apache License

public void execute(Log log, Compiler compiler, CompilerConfiguration config, String javaSrcDir,
        String cookccPath) throws MojoExecutionException {
    File file = new File(m_src);
    if (!file.isFile()) {
        throw new MojoExecutionException("File " + m_src + " does not exist.");
    }//from ww w  .j  a  v a2s.c o  m

    // Build arguments
    ArrayList<String> arguments = new ArrayList<String>();
    for (Option option : m_options) {
        arguments.add("-" + option.opt);
        if (option.arg != null) {
            arguments.add(option.arg);
        }
    }

    arguments.add("-d");
    arguments.add(javaSrcDir);

    arguments.add(m_src);
    String[] args = arguments.toArray(new String[arguments.size()]);

    String msg = "java -jar " + cookccPath;
    for (String arg : arguments)
        msg += " " + arg;
    log.debug(msg);

    // Load the jar
    File cookccJar = new File(cookccPath);
    if (!cookccJar.exists()) {
        throw new MojoExecutionException("Failed to load " + cookccPath);
    }
    URLClassLoader cl = null;
    try {
        cl = new URLClassLoader(new URL[] { cookccJar.toURI().toURL() });
        Class<?> c = cl.loadClass("org.yuanheng.cookcc.Main");
        Method method = c.getMethod("main", String[].class);
        method.invoke(null, new Object[] { args });
    } catch (Exception ex) {
        try {
            if (cl != null)
                cl.close();
        } catch (IOException ex2) {
        }
        throw new MojoExecutionException("Error executing CookCC", ex);
    }

    try {
        cl.close();
    } catch (IOException ex) {
    }
}

From source file:pl.allegro.tdr.gruntmaven.archive.TarUtil.java

License:Apache License

public static void untar(File source, File target, Log logger) {
    TarInputStream tarInput = null;//from   w  ww  .  j  a va  2 s.c o  m
    TarEntry entry;
    OutputStream output = null;

    try {
        tarInput = new TarInputStream(new FileInputStream(source));

        entry = tarInput.getNextEntry();
        while (entry != null) {
            File outputFile = new File(target.getCanonicalPath() + File.separator + entry.getName());
            if (entry.isDirectory()) {
                logger.debug("creating dir at: " + outputFile.getCanonicalPath());
                outputFile.mkdirs();
            } else {
                logger.debug("creating file at: " + outputFile.getCanonicalPath());
                output = new FileOutputStream(outputFile);
                IOUtil.copy(tarInput, output);
                output.flush();
                output.close();
            }

            entry = tarInput.getNextEntry();
        }
    } catch (IOException exception) {
        throw new IllegalStateException(exception);
    } finally {
        IOUtil.close(tarInput);
        IOUtil.close(output);
    }
}

From source file:schemacrawler.tools.integration.maven.SchemaCrawlerMojo.java

License:Open Source License

private Path executeSchemaCrawler() throws Exception {
    final Log logger = getLog();

    final SchemaCrawlerOptions schemaCrawlerOptions = createSchemaCrawlerOptions();
    final ConnectionOptions connectionOptions = createConnectionOptions();
    final Config additionalConfiguration = createAdditionalConfiguration();
    final Path outputFile = Files.createTempFile("schemacrawler.report.", ".data");
    final OutputOptions outputOptions = createOutputOptions(outputFile);

    final Executable executable = new SchemaCrawlerExecutable(command);
    executable.setOutputOptions(outputOptions);
    executable.setSchemaCrawlerOptions(schemaCrawlerOptions);
    executable.setAdditionalConfiguration(additionalConfiguration);

    logger.debug(ObjectToString.toString(executable));
    final Connection connection = connectionOptions.getConnection();
    executable.execute(connection);//w  w  w.j a  v  a2  s  .co m

    return outputFile;
}

From source file:schemacrawler.tools.integration.maven.SchemaCrawlerMojo.java

License:Open Source License

/**
 * The JDBC driver classpath comes from the configuration of the
 * SchemaCrawler plugin. The current classloader needs to be "fixed"
 * to include the JDBC driver in the classpath.
 *
 * @throws MavenReportException//from  ww  w  .j a v a  2s  .  c  o m
 */
private void fixClassPath() throws MavenReportException {

    final Log logger = getLog();

    try {
        final List<URL> jdbcJarUrls = new ArrayList<URL>();
        for (final Object artifact : project.getArtifacts()) {
            jdbcJarUrls.add(((Artifact) artifact).getFile().toURI().toURL());
        }
        for (final Artifact artifact : pluginArtifacts) {
            jdbcJarUrls.add(artifact.getFile().toURI().toURL());
        }
        logger.debug("SchemaCrawler - Maven Plugin: classpath: " + jdbcJarUrls);

        final Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", new Class[] { URL.class });
        addUrlMethod.setAccessible(true);

        final URLClassLoader classLoader = (URLClassLoader) getClass().getClassLoader();

        for (final URL jdbcJarUrl : jdbcJarUrls) {
            addUrlMethod.invoke(classLoader, jdbcJarUrl);
        }

        logger.info("Fixed SchemaCrawler classpath: " + Arrays.asList(classLoader.getURLs()));

    } catch (final Exception e) {
        throw new MavenReportException("Error fixing classpath", e);
    }
}

From source file:ua.tifoha.maven.MergerMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log logger = getLog();
    Pattern pattern = Pattern.compile(".+\\.properties");
    Predicate<Path> propertiesPredicate = path -> pattern.matcher(path.toString()).matches();
    Path buildPath = buildDirectory.toPath();
    logger.debug("read directory:" + buildPath);
    try {//from www  .  j  a  va 2s.  c  o  m
        Map<Path, List<Path>> propGroups = Files.walk(buildPath).filter(propertiesPredicate)
                .collect(Collectors.groupingBy(MergerMojo::getBasePath));

        for (Map.Entry<Path, List<Path>> pathListEntry : propGroups.entrySet()) {
            Path mainProperty = pathListEntry.getKey();
            logger.debug("processing property file:" + mainProperty);
            Properties properties = new Properties();
            pathListEntry.getValue().stream()
                    .filter(path -> isTemplateProperties(path.getFileName().toString()))
                    .peek(path -> logger.debug("applying templete:" + path)).map(MergerMojo::loadProperties)
                    .forEach(properties::putAll);

            if (Files.exists(mainProperty)) {
                logger.debug("applying main file:" + mainProperty);
                properties.putAll(loadProperties(mainProperty));
            }

            pathListEntry.getValue().stream().filter(path -> isLocalProperties(path.getFileName().toString()))
                    .peek(path -> logger.debug("applying local properties:" + path))
                    .map(MergerMojo::loadProperties).forEach(properties::putAll);

            try (OutputStream outputStream = Files.newOutputStream(mainProperty)) {
                properties.store(outputStream, "Generated by 'property-merger-maven-plugin'");
            }

            if (deleteSourceFiles) {
                pathListEntry.getValue().stream().filter((path) -> !mainProperty.equals(path)).forEach(path -> {
                    try {
                        Files.deleteIfExists(path);
                    } catch (IOException e) {
                        logger.warn("Cannot delete file: " + path);
                    }
                });
            }
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot process file", e);
    }
}

From source file:uk.co.exemel.disco.transformations.Main.java

License:Apache License

/**
 * @param args//from w  ww. ja  v a  2 s.c o  m
 */
public static void main(String[] args) throws Exception {

    Transformations transform = new DiscoTransformations();
    IDLReader reader = new IDLReader();
    Log log = new SystemStreamLog();

    File idd = new File("src\\main\\resources\\BaselineService.xml");
    InterceptingResolver resolver = new InterceptingResolver();

    Document iddDoc = XmlUtil.parse(idd, resolver);

    File ext = new File("src\\main\\resources\\BaselineService-Extensions.xml");
    Document extDoc = null;
    if (ext.exists()) {
        extDoc = XmlUtil.parse(ext, resolver);
    }

    reader.init(iddDoc, extDoc, "BaselineService", "com.betfair.baseline", ".", "/target/generated-sources",
            log, new Service().getOutputDir(), true, true);

    // First let's mangle the document if need be.
    if (transform.getManglers() != null) {
        log.debug("mangling IDL using " + transform.getManglers().size() + " pre validations");
        for (DocumentMangler m : transform.getManglers()) {
            log.debug(m.getName());
            reader.mangle(m);
        }
        log.debug(reader.serialize());
    }

    for (Validator v : transform.getPreValidations()) {
        reader.validate(v);
    }
    log.debug(reader.serialize());
    reader.runMerge(transform.getTransformations());

    reader.writeResult();

}

From source file:uk.org.raje.maven.plugin.msbuild.MojoHelper.java

License:Apache License

/**
 * Validates the path to a command-line tool.
 * @param toolPath the configured tool path from the POM
 * @param toolName the name of the tool, used for logging messages
 * @param logger a Log to write messages to
 * @throws FileNotFoundException if the tool cannot be found
 *///from   www  .  j  av  a2s  .  co m
public static void validateToolPath(File toolPath, String toolName, Log logger) throws FileNotFoundException {
    logger.debug("Validating path for " + toolName);

    if (toolPath == null) {
        logger.error("Missing " + toolName + " path");
        throw new FileNotFoundException();
    }

    if (!toolPath.exists() || !toolPath.isFile()) {
        logger.error("Could not find " + toolName + " at " + toolPath);
        throw new FileNotFoundException(toolPath.getAbsolutePath());
    }

    logger.debug("Found " + toolName + " at " + toolPath);
}

From source file:uk.org.raje.maven.plugin.msbuild.MSBuildCleanMojo.java

License:Apache License

private void cleanReports(File projectFile, String reportDirectory, String toolName, Log log)
        throws MojoFailureException {
    final DirectoryScanner directoryScanner = new DirectoryScanner();
    directoryScanner.setIncludes(new String[] { "**\\" + reportDirectory });
    directoryScanner.setBasedir(projectFile.getParentFile());
    directoryScanner.scan();/*w  ww . java  2s.co  m*/

    log.info("Cleaning up " + toolName + " reports");

    for (String directoryName : directoryScanner.getIncludedDirectories()) {
        final File directory = new File(projectFile.getParentFile(), directoryName);
        log.debug("Deleting directory " + directory);

        try {
            FileUtils.deleteDirectory(directory);
        } catch (IOException ioe) {
            log.error("Failed to delete directory " + directory);
            throw new MojoFailureException(ioe.getMessage(), ioe);
        }
    }

    log.info(toolName + " report clean-up complete");
}

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

License:Apache License

/**
 * Tell if a session is older than an hour.
 *
 * @param client HTTP client for which to attempt deducing if the session has
 *               expired.//  w  w w  .ja v a  2 s.c  om
 *
 * @return String The resource server for the session if the session hasn't
 *         expired. Null otherwise.
 */
private String getResourceServer(InnerHttpClient client) {
    Log logger = getLog();

    // Cookie 'oid' expiry date is supposed to be in 2 years in the future from
    // the date of creation of the cookie.
    final Calendar cal = GregorianCalendar.getInstance();
    cal.add(Calendar.YEAR, 2);
    cal.add(Calendar.HOUR, -1);

    final Date futureDate = cal.getTime();

    if (logger.isDebugEnabled()) {
        logger.debug("Future date: " + futureDate);
    }

    String resourceServer = null;

    for (Cookie cookie : client.getCookieStore().getCookies()) {
        final String name = cookie.getName();

        if ("oid".equals(name)) {
            final Date expiryDate = cookie.getExpiryDate();

            if (logger.isDebugEnabled()) {
                logger.debug("Expiry date: " + expiryDate);
            }

            if (futureDate.before(expiryDate)) {
                resourceServer = "https://" + cookie.getDomain();
            }

            break;
        }
    }

    return resourceServer;
}