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.codspire.mojo.artifactlookup.ArtifactLookupMojo.java

License:Apache License

/**
 * Searches the local artifacts specified through "artifactLocation" in
 * "remoteArtifactRepositories" or "repositoryUrl" and generates the search
 * results.// w  ww  .java2 s . c o m
 * 
 */
protected void lookupArtifacts() {
    Log log = getLog();

    validateRemoteArtifactRepositories();
    validateArtifactLocation();

    List<String> remoteArtifactRepositoriesURL = getRemoteArtifactRepositoriesURL();

    log.info(artifactLocation.getAbsolutePath() + " is file = " + artifactLocation.isFile());

    if (log.isDebugEnabled()) {
        log.debug("Remote Artifact Repositories");
        log.debug((remoteArtifactRepositories != null) ? remoteArtifactRepositories.toString()
                : "remoteArtifactRepositories is null");
    }

    LookupForDependency lookupForDependency = new LookupForDependency(artifactLocation, recursive,
            remoteArtifactRepositoriesURL, outputDirectory, log);
    lookupForDependency.process();
}

From source file:com.cognifide.maven.plugins.crx.CrxPackageAbstractMojo.java

License:Apache License

/**
 * Returns true if the current project is located at the Execution Root Directory (where mvn was launched)
 *//*from  w  ww  . j a  va2s.  c om*/
protected boolean isThisTheExecutionRoot() {
    Log log = this.getLog();
    log.debug("Root Folder: " + mavenSession.getExecutionRootDirectory());
    log.debug("Current Folder: " + basedir);
    boolean result = mavenSession.getExecutionRootDirectory().equalsIgnoreCase(basedir.toString());
    if (result) {
        log.debug("This is the execution root.");
    } else {
        log.debug("This is NOT the execution root.");
    }

    return result;
}

From source file:com.collaborne.jsonschema.validator.plugin.ValidateMojo.java

License:Apache License

@VisibleForTesting
protected void log(String filename, ProcessingMessage message) {
    // FIXME: #getMessage() is ok, but ideally we also need the other key/value pairs.
    //        Doing that would require knowing that "message" is the one holding the message
    //        itself.
    StringBuilder logMessageBuilder = new StringBuilder();
    logMessageBuilder.append(filename);//from  w  ww . j ava  2s . com
    logMessageBuilder.append(": ");
    logMessageBuilder.append(message.getMessage());
    String logMessage = logMessageBuilder.toString();

    Log log = getLog();

    switch (message.getLogLevel()) {
    case NONE:
        // XXX: Do nothing?
        break;
    case DEBUG:
        log.debug(logMessage);
        break;
    case INFO:
        log.info(logMessage);
        break;
    case WARNING:
        log.warn(logMessage);
        break;
    case ERROR:
    case FATAL:
        log.error(logMessage);
        break;
    }
}

From source file:com.edugility.h2.maven.plugin.AbstractH2Mojo.java

License:Open Source License

/**
 * Returns a {@link ProcessBuilder} that can be used and reused to
 * spawn new fully configured H2 TCP servers.
 *
 * <p>This method never returns {@code null}.</p>
 *
 * <h2>Design Notes</h2>/*from   w w w .  ja v a2s. com*/
 *
 * <p>At the moment, the implementation of this method returns a new
 * {@link ProcessBuilder} in all cases, but this behavior should not
 * be relied upon.</p>
 *
 * @return a {@link ProcessBuilder}; never {@code null}
 */
protected ProcessBuilder getServerSpawner() {
    final List<String> args = this.getServerArguments();
    assert args != null;

    // A spawned server should never run as a daemon.
    args.remove("-tcpDaemon");
    args.remove("-pgDaemon");
    args.remove("-webDaemon");

    int argumentIndex = 0;

    File java = this.getJava();
    if (java == null) {
        java = new File(new File(new File(System.getProperty("java.home")), "bin"), "java");
    }
    args.add(argumentIndex++, java.getAbsolutePath());

    final String[] javaOptions = this.getJavaOptions();
    if (javaOptions != null && javaOptions.length > 0) {
        for (final String option : javaOptions) {
            if (option != null && !option.trim().isEmpty()) {
                args.add(argumentIndex++, option);
            }
        }
    }

    args.add(argumentIndex++, "-cp");
    final File fileLocation = this.getH2();
    assert fileLocation != null;
    args.add(argumentIndex++, fileLocation.getAbsolutePath());

    args.add(argumentIndex++, Server.class.getName());

    final Log log = this.getLog();
    if (log != null && log.isDebugEnabled()) {
        log.debug("Process arguments: " + args);
    }
    return new ProcessBuilder(args);
}

From source file:com.edugility.jaxb.maven.plugin.GenerateXmlAdapterMojo.java

License:Open Source License

/**
 * Reads the {@linkplain #getImplementations() implementations map}
 * and generates the appropriate {@link XmlAdapter} source code in
 * the {@linkplain #getDirectory() specified directory}.
 *
 * @exception MojoExecutionException if an error occurs
 *///  w  w w . j ava  2 s . c om
@Override
public void execute() throws MojoExecutionException {
    final Log log = this.getLog();

    XmlAdapterGenerator generator = this.getXmlAdapterGenerator();
    if (generator == null) {
        generator = new XmlAdapterGenerator();
    }

    File directory = this.getDirectory();
    if (directory == null) {
        directory = generator.getDirectory();
        if (directory == null) {
            throw new MojoExecutionException("No directory set", new IllegalStateException("No directory set"));
        }
    } else if (!directory.exists()) {
        if (!directory.mkdirs()) {
            throw new MojoExecutionException(String.format("Could not create directory path %s", directory),
                    new IOException(String.format("Could not create directory path %s", directory)));
        }
    }
    assert directory.isDirectory();
    assert directory.canWrite();

    generator.setDirectory(directory);

    final Map<String, String> implementations = this.getImplementations();
    if (implementations != null && !implementations.isEmpty()) {
        final Set<Entry<String, String>> entrySet = implementations.entrySet();
        if (entrySet != null && !entrySet.isEmpty()) {
            final String xmlAdapterPackage = this.getXmlAdapterPackage();
            for (final Entry<String, String> entry : entrySet) {
                if (entry != null) {
                    String interfaceName = entry.getKey();
                    if (interfaceName != null) {
                        interfaceName = interfaceName.trim();
                        if (!interfaceName.isEmpty()) {
                            String className = entry.getValue();
                            if (className != null) {
                                className = className.trim();
                                if (!className.isEmpty()) {
                                    try {
                                        final File file = generator.generate(xmlAdapterPackage, interfaceName,
                                                className);
                                        if (log != null && log.isDebugEnabled()) {
                                            log.debug(String.format(
                                                    "Generated %s in package %s, adapting %s to %s", file,
                                                    xmlAdapterPackage, interfaceName, className));
                                        }
                                    } catch (final IOException kaboom) {
                                        throw new MojoExecutionException(
                                                "Encountered an IOException during XMLAdapter generation",
                                                kaboom);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

}

From source file:com.edugility.jpa.maven.plugin.AbstractJPAMojo.java

License:Open Source License

/**
 * Scans the supplied {@link Set} of {@link URL}s and as a
 * convenience returns the supplied {@link AnnotationDB} that
 * contains the scanned annotation information.
 *
 * <p>This method may return {@code null} if the supplied {@code db}
 * is {@code null}.</p>/*  w  w  w. j av a 2  s. c  om*/
 *
 * @param db the {@link AnnotationDB} used to {@linkplain
 * org.scannotation.AnnotationDB#scanArchives(URL[]) perform the
 * scan}; if {@code null} then no scanning operation will take place
 *
 * @param urls the {@link Set} of {@link URL}s to scan; if {@code
 * null}, then no scanning operation will take place
 *
 * @return the {@code db} parameter
 *
 * @exception IOException if an error occurs during scanning
 *
 * @see org.scannotation.AnnotationDB#scanArchives(URL[])
 */
private final AnnotationDB scan(AnnotationDB db, final Set<URL> urls) throws IOException {
    if (db != null && urls != null && !urls.isEmpty()) {
        final Log log = this.getLog();
        if (log != null && log.isDebugEnabled()) {
            log.debug("Scanning the following URLs: " + urls);
        }
        db.clear();
        db.scanArchives(urls.toArray(new URL[urls.size()]));
    }
    return db;
}

From source file:com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo.java

License:Open Source License

/**
 * Validates and "absolutizes" the supplied {@link File} and returns
 * the corrected version.//from www .  j a va2 s  .c om
 *
 * <p>The return value of this method is guaranteed to be a {@link
 * File} that is:</p>
 *
 * <ul>
 *
 * <li>non-{@code null}</li>
 *
 * <li>{@linkplain File#isAbsolute() absolute}</li>
 *
 * <li>existent and {@linkplain File#canWrite() writable} or
 * non-existent and {@linkplain File#getParentFile() parented} by a
 * directory that is existent and writable</li>
 *
 * </ul>
 *
 * <p>If the supplied {@link File} is a relative {@link File}, then
 * it will be made absolute by prepending it with the following
 * platform-neutral path: <tt>${{@link Build#getDirectory()
 * project.build.directory}}/generated-test-sources/jpa-maven-plugin/</tt></p>
 *
 * @param outputFile the {@link File} to validate
 *
 * @return the "absolutized" and validated value of the {@code
 * outputFile} parameter; never {@code null}
 *
 * @exception FileException if the supplied {@code outputFile} did
 * not pass validation
 */
final File initializeOutputFile(File outputFile) throws FileException {
    if (outputFile == null) {
        final File projectBuildDirectory = new File(this.getProjectBuildDirectoryName());
        final File outputDirectory = new File(projectBuildDirectory, DEFAULT_SUBDIR_PREFIX);
        this.validateOutputDirectory(outputDirectory);
        outputFile = new File(outputDirectory, DEFAULT_OUTPUT_FILENAME);
    } else {
        if (!outputFile.isAbsolute()) {
            final File projectBuildDirectory = new File(this.getProjectBuildDirectoryName());
            final File outputDirectory = new File(projectBuildDirectory, DEFAULT_SUBDIR_PREFIX);
            this.validateOutputDirectory(outputDirectory);
            outputFile = new File(outputDirectory, outputFile.getPath());
        }
        if (outputFile.isDirectory()) {
            final File outputDirectory = outputFile;
            this.validateOutputDirectory(outputDirectory);
            outputFile = new File(outputDirectory, DEFAULT_OUTPUT_FILENAME);
        } else if (outputFile.exists()) {
            if (!outputFile.isFile()) {
                throw new NotNormalFileException(outputFile);
            } else if (!outputFile.canWrite()) {
                throw new NotWritableFileException(outputFile);
            } else {
                this.validateOutputDirectory(outputFile.getParentFile());
            }
        } else {
            this.validateOutputDirectory(outputFile.getParentFile());
        }
    }
    assert outputFile != null;
    assert outputFile.isAbsolute();
    final Log log = this.getLog();
    if (log != null && log.isDebugEnabled()) {
        log.debug(String.format("Output file initialized to %s", outputFile));
    }
    return outputFile;
}

From source file:com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo.java

License:Open Source License

/**
 * Executes this mojo./*from w  w w . j  a v a  2s  .  c  o m*/
 *
 * @exception MojoExecutionException if this mojo could not be executed
 *
 * @exception MojoFailureException if the build should fail
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Log log = this.getLog();
    if (log == null) {
        throw new MojoExecutionException("this.getLog() == null");
    }

    try {
        this.initialize();
    } catch (final DependencyResolutionRequiredException kaboom) {
        throw new MojoExecutionException(String.format(
                "Dependencies of the current Maven project could not be downloaded during initialization of the jpa-maven-plugin."),
                kaboom);
    } catch (final NotWritableDirectoryException kaboom) {
        throw new MojoExecutionException(String.format(
                "The output directory path, %s, exists and is a directory, but the current user, %s, cannot write to it.",
                kaboom.getFile(), System.getProperty("user.name")), kaboom);
    } catch (final NotWritableFileException kaboom) {
        throw new MojoExecutionException(String.format(
                "The outputFile specified, %s, is a regular file, but cannot be written to by Maven running as user %s.  The outputFile parameter must designate either an existing, writable file or a non-existent file.",
                outputFile, System.getProperty("user.name")), kaboom);
    } catch (final NotNormalFileException kaboom) {
        throw new MojoExecutionException(String.format(
                "The outputFile specified, %s, is not a directory, but is also not a normal file.  The outputFile parameter must deisgnate either an existing, writable, normal file or a non-existent file.",
                outputFile), kaboom);
    } catch (final NotDirectoryException kaboom) {
        throw new MojoExecutionException(String.format(
                "The output directory path, %s, exists but is not a directory.", kaboom.getFile()), kaboom);
    } catch (final PathCreationFailedException kaboom) {
        throw new MojoExecutionException(
                String.format("Some portion of the output directory path, %s, could not be created.",
                        kaboom.getFile()),
                kaboom);
    } catch (final FileException other) {
        throw new MojoExecutionException("An unexpected FileException occurred during initialization.", other);
    }

    // Scan the test classpath for Entity, MappedSuperclass, IdClass,
    // Embeddable, etc. annotations.
    final AnnotationDB db;
    AnnotationDB tempDb = null;
    try {
        tempDb = this.scan();
    } catch (final IOException kaboom) {
        throw new MojoExecutionException(
                "Execution failed because an IOException was encountered during URL scanning.", kaboom);
    } finally {
        db = tempDb;
        tempDb = null;
    }
    assert db != null;

    if (log.isDebugEnabled()) {
        log.debug("Annotation index:");
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw);
        db.outputAnnotationIndex(pw);
        log.debug(sw.toString());
        try {
            sw.close();
        } catch (final IOException ignored) {
            // ignored on purpose
        }
        pw.close();
    }

    final Properties properties = new Properties();

    // Having scanned the classpaths, get the "index", which is a Map
    // of classnames indexed by annotation classnames.
    final Map<String, Set<String>> ai = db.getAnnotationIndex();
    if (ai == null) {
        if (log.isWarnEnabled()) {
            log.warn("After scanning for Entities, a null annotation index was returned by the AnnotationDB.");
        }
    } else if (ai.isEmpty()) {
        if (log.isWarnEnabled()) {
            log.warn("After scanning for Entities, no annotated Entities were found.");
        }
    } else {

        final Map<String, Set<String>> propertyNameIndex = new HashMap<String, Set<String>>();

        // For each of the annotations we are interested in, do some
        // work on the classes that sport those annotations.
        for (final String jpaAnnotation : JPA_ANNOTATIONS) {

            // Find all classnames annotated with that annotation
            // (e.g. @Entity, @MappedSuperclass, etc.).
            final Set<String> annotatedClassNames = ai.get(jpaAnnotation);

            if (annotatedClassNames != null && !annotatedClassNames.isEmpty()) {

                for (final String annotatedClassName : annotatedClassNames) {
                    assert annotatedClassName != null;

                    // For every classname we find, see which property name it
                    // is going to be assigned to.  For example, we might be
                    // configured so that com.foobar.* get assigned to the
                    // foobarClassnames property.
                    final String propertyName = this.determinePropertyName(annotatedClassName);
                    assert propertyName != null;

                    Set<String> relevantClassNames = propertyNameIndex.get(propertyName);
                    if (relevantClassNames == null) {
                        relevantClassNames = new TreeSet<String>();
                        propertyNameIndex.put(propertyName, relevantClassNames);
                    }
                    assert relevantClassNames != null;

                    // Add the annotated class to the set of other annotated
                    // classnames stored under that property.
                    relevantClassNames.add(annotatedClassName);

                }
            }
        }

        final Set<Entry<String, Set<String>>> entrySet = propertyNameIndex.entrySet();
        assert entrySet != null;

        if (!entrySet.isEmpty()) {

            final String firstItemPrefix = this.getFirstItemPrefix();
            final String prefix = this.getPrefix();
            final String suffix = this.getSuffix();
            final String lastItemSuffix = this.getLastItemSuffix();

            for (final Entry<String, Set<String>> entry : entrySet) {
                assert entry != null;

                // For every entry indexing a set of classes under a property
                // name, stringify the set of classnames into a single
                // StringBuilder.  Index that stringified set under the
                // property name.  This Properties will be the contents of our file.

                final StringBuilder sb = new StringBuilder();

                final String propertyName = entry.getKey();
                assert propertyName != null;

                final Set<String> classNames = entry.getValue();
                assert classNames != null;
                assert !classNames.isEmpty();

                final Iterator<String> classNamesIterator = classNames.iterator();
                assert classNamesIterator != null;
                assert classNamesIterator.hasNext();

                while (classNamesIterator.hasNext()) {
                    sb.append(this.decorate(classNamesIterator.next(),
                            sb.length() <= 0 ? firstItemPrefix : prefix,
                            classNamesIterator.hasNext() ? suffix : lastItemSuffix));
                }

                properties.setProperty(propertyName, sb.toString());

            }
        }

    }

    if (log.isDebugEnabled()) {
        final Enumeration<?> propertyNames = properties.propertyNames();
        if (propertyNames != null) {
            while (propertyNames.hasMoreElements()) {
                final Object nextElement = propertyNames.nextElement();
                if (nextElement != null) {
                    final String key = nextElement.toString();
                    assert key != null;
                    final String value = properties.getProperty(key);
                    log.debug(String.format("%s = %s", key, value));
                }
            }
        }
    }

    final MavenProject project = this.getProject();
    if (project != null) {
        final Properties projectProperties = project.getProperties();
        if (projectProperties != null) {
            @SuppressWarnings("unchecked")
            final Enumeration<String> propertyNames = (Enumeration<String>) properties.propertyNames();
            if (propertyNames != null && propertyNames.hasMoreElements()) {
                while (propertyNames.hasMoreElements()) {
                    final String propertyName = propertyNames.nextElement();
                    if (propertyName != null) {
                        projectProperties.setProperty(propertyName, properties.getProperty(propertyName));
                    }
                }
            }
        }
    }

    if (this.getUseOutputFile()) {
        final File outputFile = this.getOutputFile();
        if (outputFile != null) {
            assert outputFile.exists() ? outputFile.isFile() : true;
            assert outputFile.getParentFile() != null;
            assert outputFile.getParentFile().isDirectory();
            assert outputFile.getParentFile().canWrite();
            assert !outputFile.exists() ? outputFile.getParentFile().canWrite() : true;

            // Prepare to write.  Get the character encoding, accounting for
            // possible null return values from an overridden getEncoding()
            // method.
            String encoding = this.getEncoding();
            if (encoding == null) {
                encoding = "";
            } else {
                encoding = encoding.trim();
            }
            if (encoding.isEmpty()) {
                encoding = "UTF8";
            }

            // Set up the Writer to point to the outputFile and have the
            // Properties store itself there.
            Writer writer = null;
            try {
                writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), encoding));
                properties.store(writer, "Generated by " + this.getClass().getName());
                writer.flush();
            } catch (final IOException kaboom) {
                throw new MojoExecutionException(String.format(
                        "While attempting to write to the outputFile parameter (%s), an IOException was encountered.",
                        outputFile), kaboom);
            } finally {
                if (writer != null) {
                    try {
                        writer.close();
                    } catch (final IOException ignore) {
                        // ignored on purpose
                    }
                }
            }
        }
    }
}

From source file:com.edugility.jpa.maven.plugin.ListEntityClassnamesMojo.java

License:Open Source License

/**
 * Returns the appropriate property name given a {@linkplain Class#getName() class name}.
 *
 * <p>If the supplied {@code className} is {@code null} or consists
 * solely of {@linkplain Character#isWhitespace(char) whitespace},
 * then the {@linkplain #getDefaultPropertyName() default property
 * name} is returned.<p>/* ww  w. j  ava  2  s . c  o  m*/
 *
 * <p>Otherwise, a property name is 
 */
public String determinePropertyName(String className) {
    String propertyName = this.getDefaultPropertyName();
    if (className != null) {
        className = className.trim();
        if (!className.isEmpty()) {
            final Log log = this.getLog();
            assert log != null;

            // Find the class' package name.  Extract "com.foobar" from
            // "com.foobar.Foo".
            final int index = Math.max(0, className.lastIndexOf('.'));
            String packageName = className.substring(0, index);
            assert packageName != null;
            if (log.isDebugEnabled()) {
                log.debug("Package: " + packageName);
            }

            final Map<String, String> propertyNames = this.getPropertyNames();
            if (propertyNames == null) {
                if (log.isWarnEnabled()) {
                    log.warn(String.format(
                            "Property names were never initialized; assigning default property name (%s) to class name %s.",
                            propertyName, className));
                }
            } else if (propertyNames.isEmpty()) {
                if (log.isWarnEnabled()) {
                    log.warn(String.format(
                            "Property names were initialized to the empty set; assigning default property name (%s) to class name %s.",
                            propertyName, className));
                }
            } else {
                propertyName = propertyNames.get(packageName);
                while (propertyName == null && packageName != null && !packageName.isEmpty()) {
                    final int dotIndex = Math.max(0, packageName.lastIndexOf('.'));
                    packageName = packageName.substring(0, dotIndex);
                    if (log.isDebugEnabled()) {
                        log.debug("Package: " + packageName);
                    }
                    propertyName = propertyNames.get(packageName);
                }
            }
            if (log.isDebugEnabled()) {
                log.debug("propertyName: " + propertyName);
            }
        }
    }
    if (propertyName == null) {
        propertyName = DEFAULT_DEFAULT_PROPERTY_NAME;
    }
    return propertyName;
}

From source file:com.edugility.liquibase.maven.AssembleChangeLogMojo.java

License:Open Source License

/**
 * Given an {@link Iterable} of {@link Artifact}s, and given a
 * non-{@code null}, non-empty return value from the {@link
 * #getChangeLogResourceNames()} method, this method returns a
 * {@link Collection} of {@link URL}s representing changelog
 * {@linkplain ClassLoader#getResources(String) resources found}
 * among the supplied {@link Artifact}s.
 *
 * @param artifacts an {@link Iterable} of {@link Artifact}s; may be
 * {@code null}//from ww w. j  ava 2  s.  com
 *
 * @return a {@link Collection} of {@link URL}s representing
 * changelog resources found among the supplied {@link Artifact}s
 *
 * @exception IOException if an input/output error occurs such as
 * the kind that might be thrown by the {@link
 * ClassLoader#getResources(String)} method
 *
 * @see #getChangeLogResourceNames()
 *
 * @see ClassLoader#getResources(String)
 */
public Collection<? extends URL> getChangeLogResources(final Iterable<? extends Artifact> artifacts)
        throws IOException {
    final Log log = this.getLog();
    Collection<URL> returnValue = null;
    final ClassLoader loader = this.toClassLoader(artifacts);
    if (loader != null) {
        final Iterable<String> changeLogResourceNames = this.getChangeLogResourceNames();
        if (log != null && log.isDebugEnabled()) {
            log.debug(String.format("Change log resource names: %s", changeLogResourceNames));
        }
        if (changeLogResourceNames == null) {
            throw new IllegalStateException("this.getChangeLogResourceNames()",
                    new NullPointerException("this.getChangeLogResourceNames()"));
        }
        returnValue = new ArrayList<URL>();
        for (final String name : changeLogResourceNames) {
            if (name != null) {
                final Enumeration<URL> urls = loader.getResources(name);
                if (urls != null) {
                    returnValue.addAll(Collections.list(urls));
                }
            }
        }
    }
    if (returnValue == null) {
        returnValue = Collections.emptySet();
    }
    return returnValue;
}