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:com.googlecode.cmakemavenproject.CompileMojo.java

License:Apache License

@Override
@SuppressWarnings("NP_UNWRITTEN_FIELD")
public void execute() throws MojoExecutionException, MojoFailureException {
    try {//from www . j ava2 s . c  o m
        if (!projectDirectory.exists())
            throw new MojoExecutionException(projectDirectory.getAbsolutePath() + " does not exist");
        if (!projectDirectory.isDirectory())
            throw new MojoExecutionException(projectDirectory.getAbsolutePath() + " must be a directory");

        File cmakeFile = new File(project.getBuild().getDirectory(), "dependency/cmake/bin/cmake");
        ProcessBuilder processBuilder = new ProcessBuilder(cmakeFile.getAbsolutePath(), "--build",
                projectDirectory.getPath());
        if (target != null)
            Collections.addAll(processBuilder.command(), "--target", target);
        if (config != null)
            Collections.addAll(processBuilder.command(), "--config", config);
        if (options != null)
            processBuilder.command().addAll(options);

        Map<String, String> env = processBuilder.environment();

        if (environmentVariables != null)
            env.putAll(environmentVariables);
        Log log = getLog();
        if (log.isDebugEnabled()) {
            log.debug("projectDirectory: " + projectDirectory);
            log.debug("target: " + target);
            log.debug("config: " + config);
            log.debug("environment: " + processBuilder.environment());
            log.debug("command-line: " + processBuilder.command());
        }
        int returnCode = Mojos.waitFor(processBuilder);
        if (returnCode != 0)
            throw new MojoExecutionException("Return code: " + returnCode);
    } catch (InterruptedException e) {
        throw new MojoExecutionException("", e);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    }
}

From source file:com.googlecode.cmakemavenproject.GenerateMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {
    try {/*from  www  .  ja  v  a 2s  . c o  m*/
        PluginDescriptor pluginDescriptor = (PluginDescriptor) getPluginContext().get("pluginDescriptor");
        String groupId = pluginDescriptor.getGroupId();
        String version = pluginDescriptor.getVersion();
        String classifier = getClassifier();
        if (!targetPath.exists() && !targetPath.mkdirs())
            throw new MojoExecutionException("Cannot create " + targetPath.getAbsolutePath());

        if (classifier == null) {
            String os = System.getProperty("os.name");
            String arch = System.getProperty("os.arch");
            if (os.toLowerCase().startsWith("windows"))
                classifier = "windows";
            else if (os.toLowerCase().startsWith("linux"))
                if (arch.equals("x86_64") || arch.equals("amd64"))
                    classifier = "linux64";
                else if (arch.equals("i386"))
                    classifier = "linux32";
                else
                    throw new MojoExecutionException("Unsupported Linux arch: " + arch);
            else if (os.toLowerCase().startsWith("mac"))
                if (arch.equals("x86_64"))
                    classifier = "mac64";
                else
                    throw new MojoExecutionException("Unsupported Mac arch: " + arch);
            else
                throw new MojoExecutionException("Unsupported os.name: " + os);
        }
        File cmakeDir = new File(project.getBuild().getDirectory(), "dependency/cmake");
        String binariesArtifact = "cmake-binaries";

        Element groupIdElement = new Element("groupId", groupId);
        Element artifactIdElement = new Element("artifactId", binariesArtifact);
        Element versionElement = new Element("version", version);
        Element classifierElement = new Element("classifier", classifier);
        Element outputDirectoryElement = new Element("outputDirectory", cmakeDir.getAbsolutePath());
        Element artifactItemElement = new Element("artifactItem", groupIdElement, artifactIdElement,
                versionElement, classifierElement, outputDirectoryElement);
        Element artifactItemsItem = new Element("artifactItems", artifactItemElement);
        Xpp3Dom configuration = MojoExecutor.configuration(artifactItemsItem);
        ExecutionEnvironment environment = MojoExecutor.executionEnvironment(project, session, pluginManager);
        Plugin dependencyPlugin = MojoExecutor.plugin("org.apache.maven.plugins", "maven-dependency-plugin",
                "2.8");
        MojoExecutor.executeMojo(dependencyPlugin, "unpack", configuration, environment);

        ProcessBuilder processBuilder = new ProcessBuilder(new File(cmakeDir, "bin/cmake").getAbsolutePath(),
                "-G", generator).directory(targetPath);
        if (options != null)
            processBuilder.command().addAll(options);
        processBuilder.command().add(sourcePath.getAbsolutePath());
        Map<String, String> env = processBuilder.environment();

        if (environmentVariables != null)
            env.putAll(environmentVariables);
        Log log = getLog();
        if (log.isDebugEnabled()) {
            log.debug("sourcePath: " + sourcePath);
            log.debug("targetPath: " + targetPath);
            log.debug("environment: " + processBuilder.environment());
            log.debug("command-line: " + processBuilder.command());
        }
        int returnCode = Mojos.waitFor(processBuilder);
        if (returnCode != 0)
            throw new MojoExecutionException("Return code: " + returnCode);
    } catch (InterruptedException e) {
        throw new MojoExecutionException("", e);
    } catch (IOException e) {
        throw new MojoExecutionException("", e);
    }
}

From source file:com.googlecode.jsonschema2pojo.maven.ProjectClasspath.java

License:Apache License

/**
 * Provides a class loader that can be used to load classes from this
 * project classpath.// ww w  . j a  v  a 2 s .c o  m
 * 
 * @param parent
 *            a classloader which should be used as the parent of the newly
 *            created classloader.
 * @param log
 *            object to which details of the found/loaded classpath elements
 *            can be logged.
 * 
 * @return a classloader that can be used to load any class that is
 *         contained in the set of artifacts that this project classpath is
 *         based on.
 * @throws DependencyResolutionRequiredException
 *             if maven encounters a problem resolving project dependencies
 */
public ClassLoader getClassLoader(MavenProject project, final ClassLoader parent, Log log)
        throws DependencyResolutionRequiredException {

    @SuppressWarnings("unchecked")
    List<String> classpathElements = project.getCompileClasspathElements();

    final List<URL> classpathUrls = new ArrayList<URL>(classpathElements.size());

    for (String classpathElement : classpathElements) {

        try {
            log.debug("Adding project artifact to classpath: " + classpathElement);
            classpathUrls.add(new File(classpathElement).toURI().toURL());
        } catch (MalformedURLException e) {
            log.debug("Unable to use classpath entry as it could not be understood as a valid URL: "
                    + classpathElement, e);
        }

    }

    return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
        @Override
        public ClassLoader run() {
            return new URLClassLoader(classpathUrls.toArray(new URL[classpathUrls.size()]), parent);
        }
    });

}

From source file:com.googlecode.ounit.maven.MojoData.java

License:Open Source License

public List<File> getStudentTestDirectories() {
    Log log = getLog();
    List<File> dirs = new ArrayList<File>(2);

    String[] repDirs = { getSurefireDirectory(), getFailsafeDirectory() };
    for (String d : repDirs) {
        File f = new File(d);
        if (f.isDirectory()) {
            log.debug("Looking for student test results in " + d);
            dirs.add(f);/*w ww .  j a v a2s  .c  o  m*/
        }
    }
    return dirs;
}

From source file:com.googlecode.ounit.maven.MojoData.java

License:Open Source License

public List<File> getTeacherTestDirectories() {
    Log log = getLog();
    List<File> dirs = new ArrayList<File>(1);

    String[] repDirs = { getTeacherDirectory() };
    for (String d : repDirs) {
        File f = new File(d);
        if (f.isDirectory()) {
            log.debug("Looking for teacher test results in " + d);
            dirs.add(f);//w  w w. ja va  2 s  .  co  m
        }
    }
    return dirs;
}

From source file:com.googlecode.t7mp.steps.deployment.FindVersionPredicate.java

License:Apache License

public FindVersionPredicate(Collection<AbstractArtifact> noVersionArtifacts, Log log) {
    this.log = log;
    for (AbstractArtifact artifact : noVersionArtifacts) {
        String key = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getType() + ":"
                + artifact.getClassifier();
        log.debug("put key [" + key + "] to map for artifact [" + artifact + "]");
        searchMap.put(key, artifact);//from   ww w  .  ja  va  2  s .  c om
    }
}

From source file:com.googlecode.t7mp.steps.resources.CreateTomcatDirectoryStep.java

License:Apache License

@Override
public void execute(Context context) {
    final Log log = context.getLog();
    final File createdDirectory = new File(context.getMojo().getCatalinaBase(), directory);
    boolean created = createdDirectory.mkdirs();
    if (created) {
        log.debug("directory " + createdDirectory.getAbsolutePath() + " created");
    } else {//from w  w  w . ja  va 2s  .  com
        log.warn("could not create " + createdDirectory.getAbsolutePath() + ", maybe it exist.");
    }
}

From source file:com.googlecode.t7mp.steps.resources.SetSystemPropertiesStep.java

License:Apache License

@Override
public void execute(Context context) {
    final String catalinaBasPath = context.getMojo().getCatalinaBase().getAbsolutePath();
    final Log log = context.getLog();
    System.setProperty("catalina.home", catalinaBasPath);
    log.debug("set systemproperty key: catalina.home to value " + catalinaBasPath);
    System.setProperty("catalina.base", catalinaBasPath);
    log.debug("set systemproperty key: catalina.base to value " + catalinaBasPath);
    Map<String, String> properties = context.getMojo().getSystemProperties();
    for (String key : properties.keySet()) {
        String value = replaceCatalinas(properties.get(key));
        System.setProperty(key, value);
        log.debug("set systemproperty key: " + key + " to value: " + System.getProperty(key));
    }//from  w  w w.j a va  2  s.  com
}

From source file:com.igormaznitsa.mvngolang.cvs.AbstractRepo.java

License:Apache License

public int execute(@Nullable String customCommand, @Nonnull final Log logger, @Nonnull final File cvsFolder,
        @Nonnull @MustNotContainNull final String... args) {
    final List<String> cli = new ArrayList<String>();
    cli.add(GetUtils.findFirstNonNull(customCommand, this.command));
    for (final String s : args) {
        cli.add(s);/*from  w w  w  .  j  a  va  2 s . co  m*/
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Executing repo command : " + cli);
    }

    final ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();

    final ProcessExecutor executor = new ProcessExecutor(cli);

    int result = -1;

    try {
        final ProcessResult processResult = executor.directory(cvsFolder).redirectError(errorStream)
                .redirectOutput(outStream).executeNoTimeout();
        result = processResult.getExitValue();

        if (logger.isDebugEnabled()) {
            logger.debug("Exec.out.........................................");
            logger.debug(new String(errorStream.toByteArray(), Charset.defaultCharset()));
            logger.debug(".................................................");
        }

        if (result != 0) {
            logger.error(new String(errorStream.toByteArray(), Charset.defaultCharset()));
        }

    } catch (Exception ex) {
        logger.error("Unexpected error", ex);
    }

    return result;
}

From source file:com.igormaznitsa.mvngolang.utils.UnpackUtils.java

License:Apache License

public static int unpackFileToFolder(@Nonnull final Log logger, @Nullable final String folder,
        @Nonnull final File archiveFile, @Nonnull final File destinationFolder, final boolean makeAllExecutable)
        throws IOException {
    final String normalizedName = archiveFile.getName().toLowerCase(Locale.ENGLISH);

    final ArchEntryGetter entryGetter;

    boolean modeZipFile = false;

    final ZipFile theZipFile;
    final ArchiveInputStream archInputStream;
    if (normalizedName.endsWith(".zip")) {
        logger.debug("Detected ZIP archive");

        modeZipFile = true;//from w w  w.  j a  va 2s .  c  om

        theZipFile = new ZipFile(archiveFile);
        archInputStream = null;
        entryGetter = new ArchEntryGetter() {
            private final Enumeration<ZipArchiveEntry> iterator = theZipFile.getEntries();

            @Override
            @Nullable
            public ArchiveEntry getNextEntry() throws IOException {
                ArchiveEntry result = null;
                if (this.iterator.hasMoreElements()) {
                    result = this.iterator.nextElement();
                }
                return result;
            }
        };
    } else {
        theZipFile = null;
        final InputStream in = new BufferedInputStream(new FileInputStream(archiveFile));
        try {
            if (normalizedName.endsWith(".tar.gz")) {
                logger.debug("Detected TAR.GZ archive");
                archInputStream = new TarArchiveInputStream(new GZIPInputStream(in));

                entryGetter = new ArchEntryGetter() {
                    @Override
                    @Nullable
                    public ArchiveEntry getNextEntry() throws IOException {
                        return ((TarArchiveInputStream) archInputStream).getNextTarEntry();
                    }
                };

            } else {
                logger.debug("Detected OTHER archive");
                archInputStream = ARCHIVE_STREAM_FACTORY.createArchiveInputStream(in);
                logger.debug("Created archive stream : " + archInputStream.getClass().getName());

                entryGetter = new ArchEntryGetter() {
                    @Override
                    @Nullable
                    public ArchiveEntry getNextEntry() throws IOException {
                        return archInputStream.getNextEntry();
                    }
                };
            }

        } catch (ArchiveException ex) {
            IOUtils.closeQuietly(in);
            throw new IOException("Can't recognize or read archive file : " + archiveFile, ex);
        } catch (CantReadArchiveEntryException ex) {
            IOUtils.closeQuietly(in);
            throw new IOException("Can't read entry from archive file : " + archiveFile, ex);
        }
    }

    try {

        final String normalizedFolder = folder == null ? null : FilenameUtils.normalize(folder, true) + '/';

        int unpackedFilesCounter = 0;
        while (true) {
            final ArchiveEntry entry = entryGetter.getNextEntry();
            if (entry == null) {
                break;
            }
            final String normalizedPath = FilenameUtils.normalize(entry.getName(), true);

            logger.debug("Detected archive entry : " + normalizedPath);

            if (normalizedFolder == null || normalizedPath.startsWith(normalizedFolder)) {
                final File targetFile = new File(destinationFolder, normalizedFolder == null ? normalizedPath
                        : normalizedPath.substring(normalizedFolder.length()));
                if (entry.isDirectory()) {
                    logger.debug("Folder : " + normalizedPath);
                    if (!targetFile.exists() && !targetFile.mkdirs()) {
                        throw new IOException("Can't create folder " + targetFile);
                    }
                } else {
                    final File parent = targetFile.getParentFile();

                    if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
                        throw new IOException("Can't create folder : " + parent);
                    }

                    final FileOutputStream fos = new FileOutputStream(targetFile);

                    try {
                        if (modeZipFile) {
                            logger.debug("Unpacking ZIP entry : " + normalizedPath);

                            final InputStream zipEntryInStream = theZipFile
                                    .getInputStream((ZipArchiveEntry) entry);
                            try {
                                if (IOUtils.copy(zipEntryInStream, fos) != entry.getSize()) {
                                    throw new IOException(
                                            "Can't unpack file, illegal unpacked length : " + entry.getName());
                                }
                            } finally {
                                IOUtils.closeQuietly(zipEntryInStream);
                            }
                        } else {
                            logger.debug("Unpacking archive entry : " + normalizedPath);

                            if (!archInputStream.canReadEntryData(entry)) {
                                throw new IOException("Can't read archive entry data : " + normalizedPath);
                            }
                            if (IOUtils.copy(archInputStream, fos) != entry.getSize()) {
                                throw new IOException(
                                        "Can't unpack file, illegal unpacked length : " + entry.getName());
                            }
                        }
                    } finally {
                        fos.close();
                    }

                    if (makeAllExecutable) {
                        try {
                            targetFile.setExecutable(true, true);
                        } catch (SecurityException ex) {
                            throw new IOException("Can't make file executable : " + targetFile, ex);
                        }
                    }
                    unpackedFilesCounter++;
                }
            } else {
                logger.debug("Archive entry " + normalizedPath + " ignored");
            }
        }
        return unpackedFilesCounter;
    } finally {
        IOUtils.closeQuietly(theZipFile);
        IOUtils.closeQuietly(archInputStream);
    }
}