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.glassfish.maven.plugin.command.AsadminCommand.java

License:Open Source License

public void execute(ProcessBuilder processBuilder) throws MojoExecutionException, MojoFailureException {
    List<String> commandLine = new ArrayList<String>(getParameters());
    File binDir = new File(sharedContext.getGlassfishDirectory(), "bin");
    File asadmin = new File(binDir, "asadmin");

    // bnevins 9/13/11 -- the install may have both asadmin and asadmin.bat
    // if we are on Windows - then prefer the .bat file and explicitly set it.
    // o/w windows will attempt running the UNIX script which is trouble!
    // http://java.net/jira/browse/MAVEN_GLASSFISH_PLUGIN-5
    if (System.getProperty("os.name").contains("indows")) {
        File asadminBat = new File(binDir, "asadmin.bat");
        if (asadminBat.exists()) {
            asadmin = asadminBat;//  w ww .j  av  a2 s  .  c  o  m
        }
    }

    commandLine.addAll(0, Arrays.asList(asadmin.getAbsolutePath(), getName(),
            "--echo=" + sharedContext.isEcho(), "--terse=" + sharedContext.isTerse()));

    Log log = sharedContext.getLog();
    log.debug(commandLine.toString());
    processBuilder.command(commandLine);
    try {
        int exitValue;
        Process process = processBuilder.start();
        processOut = process.getInputStream();
        processErr = process.getErrorStream();
        BufferedReader outReader = new BufferedReader(new InputStreamReader(processOut));
        do {
            try {
                exitValue = process.exitValue();
                break;
            } catch (IllegalThreadStateException e) {
                Thread.sleep(PROCESS_LOOP_SLEEP_MILLIS);
            } finally {
                while (outReader.ready()) {
                    log.info(outReader.readLine());
                }
            }
        } while (true);
        if (exitValue != EXIT_SUCCESS) {
            BufferedReader errorReader = new BufferedReader(new InputStreamReader(processErr));
            while (errorReader.ready()) {
                log.error(errorReader.readLine());
            }
            String errorMessage = getErrorMessage();
            log.error(errorMessage);
            log.error(
                    "For more detail on what might be causing the problem try running maven with the --debug option ");
            log.error("or setting the maven-glassfish-plugin \"echo\" property to \"true\".");
            throw new MojoFailureException(errorMessage);
        }
    } catch (IOException e) {
        throw new MojoExecutionException(getErrorMessage() + " IOException: " + e.getMessage());
    } catch (InterruptedException e) {
        throw new MojoExecutionException(getErrorMessage() + " Process was interrupted: " + e.getMessage());
    }
}

From source file:org.grouplens.lenskit.eval.maven.MavenLogAppender.java

License:Open Source License

@Override
protected void append(E event) {
    Log log = mavenLogger.get();
    if (log == null) {
        return;/*ww  w.  j  a v a 2  s . c  om*/
    }

    String fmt = layout.doLayout(event);
    Level lvl = event.getLevel();
    if (lvl.isGreaterOrEqual(Level.ERROR)) {
        log.error(fmt);
    } else if (lvl.isGreaterOrEqual(Level.WARN)) {
        log.warn(fmt);
    } else if (lvl.isGreaterOrEqual(Level.INFO)) {
        log.info(fmt);
    } else {
        log.debug(fmt);
    }
}

From source file:org.hardisonbrewing.maven.core.cli.LogStreamConsumer.java

License:Open Source License

@Override
public void consumeLine(String line) {

    Log log = JoJoMojo.getMojo().getLog();

    switch (level) {
    case LEVEL_INFO:
        log.info(line);//  w  w w .  j  a v a  2  s . c  o m
        break;
    case LEVEL_WARN:
        log.warn(line);
        break;
    case LEVEL_ERROR:
        log.error(line);
        break;
    default:
        log.debug(line);
    }
}

From source file:org.impalaframework.maven.plugin.CopyModulesMojo.java

License:Apache License

public void execute() throws MojoExecutionException {

    final Log logger = getLog();

    if (isImpalaHost()) {

        moduleStagingDirectory = MojoUtils.getModuleStagingDirectory(getLog(), project, moduleStagingDirectory);

        if (logger.isDebugEnabled()) {
            logger.debug("Maven projects: " + dependencies);
            logger.debug("Current project: " + project);
        }// w  w  w .  j  a  va 2 s.c o  m

        File targetDirectory = getTargetDirectory();
        File stagingDirectory = new File(moduleStagingDirectory);

        try {
            if (logger.isDebugEnabled()) {
                logger.debug("Staging directory " + stagingDirectory.getCanonicalPath());
            }
            FileUtils.forceMkdir(targetDirectory);
        } catch (IOException e) {
            throw new MojoExecutionException(e.getMessage(), e);
        }

        if (logger.isInfoEnabled()) {
            logger.info("Copying files from staging directory: " + stagingDirectory);
        }

        final File[] listFiles = stagingDirectory.listFiles();

        if (listFiles != null) {
            for (File moduleFile : listFiles) {

                final String targetFileName = moduleFile.getName();

                MojoUtils.copyFile(moduleFile, targetDirectory, targetFileName);
                if (logger.isInfoEnabled()) {
                    logger.info("Copying from from staging directory: " + moduleFile);
                }
            }
        }
    }
}

From source file:org.impalaframework.maven.plugin.MojoUtils.java

License:Apache License

public static boolean checkConditionFromPropertyAndPackaging(MavenProject project, String propertyName,
        String packagingName, Log log) {

    final Properties properties = project.getProperties();
    String moduleJarProperty = properties.getProperty(propertyName);

    if (moduleJarProperty != null && moduleJarProperty.length() > 0) {
        final boolean parseBoolean = Boolean.parseBoolean(moduleJarProperty);
        if (!parseBoolean) {
            log.debug("Not supporting " + project.getArtifactId() + " as it has set the '" + propertyName
                    + "' property to false");
            return false;
        }//from   w  w  w  .java2s.co m

        return parseBoolean;
    }

    final boolean isJar = packagingName.equals(project.getPackaging());

    if (!isJar) {
        log.debug("Not supporting " + project.getArtifactId() + " as it does not use '" + packagingName
                + "' packaging");
        return false;
    }

    return true;
}

From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java

License:Open Source License

public static Map<String, Map<String, Artifact>> findPackageUses(List<String> packageNames,
        Set<Artifact> artifacts, MavenProject project, File buildOutputDirectory, boolean searchInDependencies,
        Log log) {
    final Map<String, Map<String, Artifact>> packageResults = new TreeMap<String, Map<String, Artifact>>();

    log.info("Scanning project build directory...");

    if (buildOutputDirectory.exists()) {
        findPackageUsesInDirectory(packageNames, project, log, packageResults, buildOutputDirectory);
    }// w  w  w . ja v  a  2  s . com

    if (!searchInDependencies) {
        return packageResults;
    }

    log.info("Scanning project dependencies...");

    for (Artifact artifact : artifacts) {
        if (artifact.isOptional()) {
            log.debug("Processing optional dependency " + artifact + "...");
        }
        if (artifact.getType().equals("pom")) {
            log.warn("Skipping POM artifact " + artifact);
            continue;
        }
        if (!artifact.getType().equals("jar")) {
            log.warn("Found non JAR artifact " + artifact);
        }
        findPackageUsesInArtifact(packageNames, project, log, packageResults, artifact);
    }
    return packageResults;
}

From source file:org.jahia.utils.maven.plugin.osgi.FindPackageUsesMojo.java

License:Open Source License

private static Set<String> findClassesThatUsePackage(File jarFile, String packageName, MavenProject project,
        Log log) {
    Set<String> classesThatHaveDependency = new TreeSet<String>();
    JarInputStream jarInputStream = null;
    if (jarFile == null) {
        log.warn("File is null !");
        return classesThatHaveDependency;
    }//  w  w w .j a  v a2 s.  com
    if (!jarFile.exists()) {
        log.warn("File " + jarFile + " does not exist !");
        return classesThatHaveDependency;
    }
    log.debug("Scanning JAR " + jarFile + "...");
    try {
        classesThatHaveDependency = ClassDependencyTracker.findDependencyInJar(jarFile, packageName,
                project.getTestClasspathElements());
    } catch (IOException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } catch (DependencyResolutionRequiredException e) {
        e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
    } finally {
        IOUtils.closeQuietly(jarInputStream);
    }
    return classesThatHaveDependency;
}

From source file:org.jahia.utils.maven.plugin.support.MavenAetherHelperUtils.java

License:Open Source License

public static boolean doesJarHavePackageName(File jarFile, String packageName, Log log) {
    JarInputStream jarInputStream = null;
    if (jarFile == null) {
        log.warn("File is null !");
        return false;
    }//from w  ww .  jav  a  2 s  . c  o  m
    if (!jarFile.exists()) {
        log.warn("File " + jarFile + " does not exist !");
        return false;
    }
    log.debug("Scanning JAR " + jarFile + "...");
    try {
        jarInputStream = new JarInputStream(new FileInputStream(jarFile));
        JarEntry jarEntry = null;
        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
            String jarPackageName = jarEntry.getName().replaceAll("/", ".");
            if (jarPackageName.endsWith(".")) {
                jarPackageName = jarPackageName.substring(0, jarPackageName.length() - 1);
            }
            if (jarPackageName.equals(packageName)) {
                return true;
            }
        }
    } catch (IOException e) {
        log.error(e);
        ;
    } finally {
        IOUtils.closeQuietly(jarInputStream);
    }
    return false;
}

From source file:org.jahia.utils.maven.plugin.support.MavenAetherHelperUtils.java

License:Open Source License

public static Set<PackageInfo> getJarPackages(File jarFile, boolean optionalJar, String version,
        ParsingContext parsingContext, Log log) {
    JarInputStream jarInputStream = null;
    Set<PackageInfo> packageInfos = new LinkedHashSet<PackageInfo>();
    if (jarFile == null) {
        log.warn("File is null !");
        return packageInfos;
    }/*from   www. j av  a  2 s  . c  o m*/
    if (!jarFile.exists()) {
        log.warn("File " + jarFile + " does not exist !");
        return packageInfos;
    }
    log.debug("Scanning JAR " + jarFile + "...");
    try {
        jarInputStream = new JarInputStream(new FileInputStream(jarFile));
        JarEntry jarEntry = null;
        while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
            String jarPackageName = jarEntry.getName().replaceAll("/", ".");
            if (jarPackageName.endsWith(".")) {
                jarPackageName = jarPackageName.substring(0, jarPackageName.length() - 1);
            }
            if (jarPackageName.startsWith("META-INF") || jarPackageName.startsWith("WEB-INF")
                    || jarPackageName.startsWith("OSGI-INF")) {
                continue;
            }
            packageInfos.addAll(PackageUtils.getPackagesFromClass(jarPackageName, optionalJar, version,
                    jarFile.getCanonicalPath(), parsingContext));
        }
    } catch (IOException e) {
        log.error(e);
        ;
    } finally {
        IOUtils.closeQuietly(jarInputStream);
    }
    return packageInfos;
}

From source file:org.jasig.maven.legal.PackageLegalMojo.java

License:Apache License

/**
 * Copy a file to the specified directory
 */// ww w .ja va 2 s. co m
protected void copyLegalFile(ResourceFinder resourceFinder, String legalFile, File targetOutputDir,
        String outputFileName) throws MojoFailureException {
    final Log logger = this.getLog();

    final URL resourceUrl;
    try {
        resourceUrl = resourceFinder.findResource(legalFile);
    } catch (MojoFailureException e) {
        throw new MojoFailureException("Could not find required " + outputFileName + " file: " + legalFile, e);
    }

    final File destFile = new File(targetOutputDir, outputFileName);
    try {
        FileUtils.copyStreamToFile(new URLInputStreamFacade(resourceUrl), destFile);
    } catch (IOException e) {
        throw new MojoFailureException("Failed to copy '" + resourceUrl + "' to '" + destFile + "'", e);
    }

    logger.debug("Copied '" + resourceUrl + "' to '" + destFile + "'");
}