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

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

Introduction

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

Prototype

void info(Throwable error);

Source Link

Document

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

Usage

From source file:com.alibaba.citrus.maven.eclipse.base.eclipse.writers.rad.RadLibCopier.java

License:Apache License

/**
 * Does the actual copy of the file and logging.
 *
 * @param artifact represents the file to copy.
 * @param destFile file name of destination file.
 * @param log      to use for output./*from  www. j a  v  a2 s .c  o  m*/
 * @throws MojoExecutionException with a message if an error occurs.
 */
private void copyFile(File artifact, File destFile, Log log) throws MojoExecutionException {
    try {
        log.info("Copying " + artifact.getAbsolutePath() + " to " + destFile);
        FileUtils.copyFile(artifact, destFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Error copying artifact from " + artifact + " to " + destFile, e);
    }
}

From source file:com.alibaba.citrus.maven.eclipse.base.ide.IdeUtils.java

License:Apache License

/**
 * Delete a file, handling log messages and exceptions
 *
 * @param f File to be deleted//from w  ww .jav a 2s .co  m
 * @throws MojoExecutionException only if a file exists and can't be deleted
 */
public static void delete(File f, Log log) throws MojoExecutionException {
    if (f.isDirectory()) {
        log.info(Messages.getString("EclipseCleanMojo.deletingDirectory", f.getName())); //$NON-NLS-1$
    } else {
        log.info(Messages.getString("EclipseCleanMojo.deletingFile", f.getName())); //$NON-NLS-1$
    }

    if (f.exists()) {
        if (!f.delete()) {
            try {
                FileUtils.forceDelete(f);
            } catch (IOException e) {
                throw new MojoExecutionException(Messages.getString("EclipseCleanMojo.failedtodelete", //$NON-NLS-1$
                        new Object[] { f.getName(), f.getAbsolutePath() }));
            }
        }
    } else {
        log.debug(Messages.getString("EclipseCleanMojo.nofilefound", f.getName())); //$NON-NLS-1$
    }
}

From source file:com.anuta.internal.YangHelperMojo.java

License:Open Source License

public void executeGoal(OperationType operationType) throws MojoExecutionException, MojoFailureException {

    Log log = getLog();
    if (null != excludes && excludes.length > 0) {
        for (String excl : excludes) {
            log.info("Excluding file " + excl);
        }// w w  w  . j  ava2 s .c o m
    }

    if (!isPyangInstalled()) {
        log.error("Pyang is not installed. Skip conversion.");
        return;
    }

    long startClock = System.currentTimeMillis();

    createResourceCollection();

    List files = new ArrayList();
    try {
        if (directories != null) {
            for (File directory : directories) {
                if (directory.exists() && directory.isDirectory()) {
                    collection.setBaseDir(directory);
                    addCollectionFiles(files);
                }
            }
        } else if (this.sourceDirectory != null && this.sourceDirectory.exists()
                && this.sourceDirectory.isDirectory()) {
            log.info("Using Source Directory." + this.sourceDirectory);
            collection.setBaseDir(this.sourceDirectory);
            addCollectionFiles(files);
        } else {
            log.error("No source directory specified to scan yang files.");
        }
    } catch (IOException e) {
        throw new MojoExecutionException("Unable to find files using includes/excludes", e);
    }

    int numberOfFiles = files.size();

    log.info("Number of files for " + operationType + " " + numberOfFiles);
    if (numberOfFiles > 0) {

        String basedirPath = getBasedirPath();
        Properties hashCache = readFileHashCacheFile();
        ResultCollector resultCollector = new ResultCollector();
        for (int i = 0, n = files.size(); i < n; i++) {
            File file = (File) files.get(i);
            performOperation(file, resultCollector, hashCache, basedirPath);
        }
        log.info("\nOperation            : " + operationType);
        log.info("Number of yang files : " + numberOfFiles);
        log.info("Successful           : " + resultCollector.successCount + " file(s)");
        log.info("Failed               : " + resultCollector.failCount + " file(s)");
        log.info("Skipped              : " + resultCollector.skippedCount + " file(s)\n");
        storeFileHashCache(hashCache);
        long endClock = System.currentTimeMillis();

        log.info("Approximate time taken: " + ((endClock - startClock) / 1000) + "s");
    }
}

From source file:com.anuta.internal.YangHelperMojo.java

License:Open Source License

/**
 *
 * @param file/*from  w  w  w.  j  ava2 s .  co m*/
 * @param resultCollector
 * @param hashCache
 * @param basedirPath
 * @throws IOException
 * @throws BadLocationException
 */
private void doOperation(File file, ResultCollector resultCollector, Properties hashCache, String basedirPath)
        throws IOException, BadLocationException {
    Log log = getLog();
    log.info("Processing file: " + file);

    String code = readFileAsString(file);
    String originalHash = md5hash(code);

    String canonicalPath = file.getCanonicalPath();
    String path = canonicalPath.substring(basedirPath.length());
    if (hashCache != null) {
        String cachedHash = hashCache.getProperty(path);
        if (cachedHash != null && cachedHash.equals(originalHash)) {
            resultCollector.skippedCount++;
            return;
        }
    }

    executeOperation(file, resultCollector, hashCache, log, originalHash, path);

}

From source file:com.atlassian.maven.plugin.clover.internal.AbstractCloverMojo.java

License:Apache License

/**
 * Registers the license file for Clover runtime by setting the <code>clover.license.path</code> system property.
 * If the user has configured the <code>licenseLocation</code> parameter the plugin tries to resolve it first as a
 * resource, then as a URL, and then as a file location on the filesystem.
 *
 * Note: We're defining this method as static because it is also required in the report mojo and reporting mojos
 * and main mojos cannot share anything right now. See http://jira.codehaus.org/browse/MNG-1886.
 *
 * @param project maven project//from  ww  w .  java2s  .c o  m
 * @param resourceManager resource manager
 * @param licenseLocation path to license file
 * @param logger logger
 * @param classloader class loader
 * @param licenseCert license key
 * @throws MojoExecutionException when the license file cannot be found
 */
public static void registerLicenseFile(final MavenProject project, final ResourceManager resourceManager,
        final String licenseLocation, final Log logger, final ClassLoader classloader, final String licenseCert)
        throws MojoExecutionException {

    if (licenseCert != null) {
        logger.debug("Full license supplied. Length: '" + licenseCert.length() + "'. License location: '"
                + licenseLocation + "' will be ignored.");
        System.setProperty(CloverNames.PROP_LICENSE_CERT, licenseCert);
        return;
    }

    if (licenseLocation != null) {
        logger.debug("Using licenseLocation '" + licenseLocation + "'");
        final File licenseFile = getResourceAsFile(project, resourceManager, licenseLocation, logger,
                classloader);
        logger.debug("Using license file [" + licenseFile.getPath() + "]");
        System.setProperty(CloverNames.PROP_LICENSE_PATH, licenseFile.getPath());
    } else {
        logger.info("No 'maven.clover.licenseLocation' configured. Using default license.");
    }
}

From source file:com.baidu.jprotobuf.mojo.PreCompileMojo.java

License:Apache License

/**
 * Execute goal.// ww  w  .j  av a2  s.co  m
 * 
 * @throws MojoExecutionException execution of the main class or one of the threads it generated failed.
 * @throws MojoFailureException something bad happened...
 */
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isSkip()) {
        getLog().info("skipping execute as per configuraion");
        return;
    }
    if (killAfter != -1) {
        getLog().warn("Warning: killAfter is now deprecated. Do you need it ? Please comment on MEXEC-6.");
    }

    arguments = new String[] { outputParentDirectory.getAbsolutePath(), outputDirectory.getAbsolutePath(),
            filterClassPackage };

    if (getLog().isDebugEnabled()) {
        StringBuffer msg = new StringBuffer("Invoking : ");
        msg.append(mainClass);
        msg.append(".main(");
        for (int i = 0; i < arguments.length; i++) {
            if (i > 0) {
                msg.append(", ");
            }
            msg.append(arguments[i]);
        }
        msg.append(")");
        getLog().debug(msg);
    }

    final Log log = getLog();
    IsolatedThreadGroup threadGroup = new IsolatedThreadGroup(mainClass /* name */);
    Thread bootstrapThread = new Thread(threadGroup, new Runnable() {
        public void run() {
            long current = System.currentTimeMillis();
            try {

                Method main = Thread.currentThread().getContextClassLoader().loadClass(mainClass)
                        .getMethod("main", new Class[] { String[].class });
                if (!main.isAccessible()) {
                    getLog().debug("Setting accessibility to true in order to invoke main().");
                    main.setAccessible(true);
                }
                if (!Modifier.isStatic(main.getModifiers())) {
                    throw new MojoExecutionException(
                            "Can't call main(String[])-method because it is not static.");
                }
                main.invoke(null, new Object[] { arguments });
            } catch (NoSuchMethodException e) { // just pass it on
                Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), new Exception(
                        "The specified mainClass doesn't contain a main method with appropriate signature.",
                        e));
            } catch (Exception e) { // just pass it on
                Thread.currentThread().getThreadGroup().uncaughtException(Thread.currentThread(), e);
            } finally {
                log.info("JProtobuf pre compile done time took: " + (System.currentTimeMillis() - current)
                        + "ms");
            }
        }
    }, mainClass + ".main()");
    bootstrapThread.setContextClassLoader(getClassLoader());
    setSystemProperties();

    bootstrapThread.start();
    joinNonDaemonThreads(threadGroup);
    // It's plausible that spontaneously a non-daemon thread might be created as we try and shut down,
    // but it's too late since the termination condition (only daemon threads) has been triggered.
    if (keepAlive) {
        getLog().warn(
                "Warning: keepAlive is now deprecated and obsolete. Do you need it? Please comment on MEXEC-6.");
        waitFor(0);
    }

    if (cleanupDaemonThreads) {

        terminateThreads(threadGroup);

        try {
            threadGroup.destroy();
        } catch (IllegalThreadStateException e) {
            getLog().warn("Couldn't destroy threadgroup " + threadGroup, e);
        }
    }

    if (originalSystemProperties != null) {
        System.setProperties(originalSystemProperties);
    }

    synchronized (threadGroup) {
        if (threadGroup.uncaughtException != null) {
            throw new MojoExecutionException("An exception occured while executing the Java class. "
                    + threadGroup.uncaughtException.getMessage(), threadGroup.uncaughtException);
        }
    }

    registerSourceRoots();
}

From source file:com.beyondj.maven.Zips.java

License:Apache License

/**
 * Zips the directory recursively into the ZIP stream given the starting path and optional filter
 */// ww  w  .  j ava 2 s .  c o m
public static void zipDirectory(Log log, File directory, ZipOutputStream zos, String path, FileFilter filter)
        throws IOException {
    // get a listing of the directory content
    File[] dirList = directory.listFiles();
    byte[] readBuffer = new byte[8192];
    int bytesIn = 0;
    // loop through dirList, and zip the files
    if (dirList != null) {
        for (File f : dirList) {
            if (f.isDirectory()) {
                String prefix = path + f.getName() + "/";
                zos.putNextEntry(new ZipEntry(prefix));
                zipDirectory(log, f, zos, prefix, filter);
            } else {
                String entry = path + f.getName();
                if (filter == null || filter.accept(f)) {
                    FileInputStream fis = new FileInputStream(f);
                    try {
                        ZipEntry anEntry = new ZipEntry(entry);
                        zos.putNextEntry(anEntry);
                        bytesIn = fis.read(readBuffer);
                        while (bytesIn != -1) {
                            zos.write(readBuffer, 0, bytesIn);
                            bytesIn = fis.read(readBuffer);
                        }
                    } finally {
                        fis.close();
                    }
                    log.info("zipping file " + entry);
                }
            }
            zos.closeEntry();
        }
    }
}

From source file:com.buisonje.AutoProxyMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException {

    final Log mojoLog = getLog();

    ProxySelector myProxySelector = null;

    if (isProxyDetectionAlreadyAttempted()) {
        mojoLog.info("Proxy server detection already attempted in this session. Reapplying result(s)...");
        myProxySelector = (ProxySelector) session.getSystemProperties().get(PROXY_SELECTOR_KEY);
    } else {/* w ww .ja v a  2s  . co m*/
        showMavenProxySettings(mojoLog);
        // showCurrentSystemWideProxiesInfo(mojoLog);
        mojoLog.info("Autodetecting system proxy server(s)...");
        myProxySelector = autodetectProxySettings(mojoLog);
        session.getSystemProperties().put(PROXY_DETECTION_TIME_KEY, new Date());
    }

    if (myProxySelector == null) {
        mojoLog.warn("Could not detect proxy server(s) automatically. Falling back to the initial settings...");
    } else {

        session.getSystemProperties().put(PROXY_SELECTOR_KEY, myProxySelector);

        /*
         * NOTE: It seems that Maven either ignores the system-wide
         * (default) {@link ProxySelector} entirely, or doesn't update it
         * with the initial proxy settings until it actually starts
         * downloading something. Either way, replacing the default {@link
         * ProxySelector} might therefore be pointless here. But it
         * shouldn't hurt, either.
         */
        ProxySelector.setDefault(myProxySelector);

        mojoLog.info("Detected available proxy server(s) for HTTP connections:");
        List<Proxy> detectedAvailableProxies = getAvailableProxies(myProxySelector);
        showAvailableProxies(mojoLog, detectedAvailableProxies);
        Proxy firstDetectedAvailableProxy = detectedAvailableProxies.get(0);
        mojoLog.info(
                String.format("Overriding Maven proxy settings with the first detected available proxy (%s)...",
                        firstDetectedAvailableProxy.address().toString()));
        overrideMavenProxySettings(firstDetectedAvailableProxy, mojoLog);
    }
}

From source file:com.buisonje.AutoProxyMojo.java

License:Apache License

/**
 * Override the Maven proxy settings with the first available (actual)
 * Proxy.//w  w w . j a  v a  2s. co  m
 * 
 * @param overridingProxy
 *            The {@link Proxy} to use instead of whatever is configured in
 *            the initial Maven settings (settings.xml).
 */
private void overrideMavenProxySettings(Proxy overridingProxy, Log mojoLog) {

    org.apache.maven.settings.Proxy mavenProxy = settings.getActiveProxy();

    if (mavenProxy.getSourceLevel() == null) {
        /*
         * User level should be enough for overriding the proxy for the
         * Maven goals/commands currently being executed.
         */
        mavenProxy.setSourceLevel(TrackableBase.USER_LEVEL);
    }

    if (Proxy.NO_PROXY.equals(overridingProxy)) {
        mojoLog.info(
                "The detected proxy configuration is a direct connection. Overriding active proxy configured in Maven settings...");
        /*
         * There can be only one active proxy in the Maven settings at a
         * time, so if the currently active one is set to inactive, that
         * should imply a direct connection.
         */
        mavenProxy.setActive(false);
    } else {

        final String nonProxyHosts = mavenProxy.getNonProxyHosts();
        if (nonProxyHosts != null && !nonProxyHosts.isEmpty()) {
            mojoLog.info(
                    "Non-proxy hosts appear to have been specified in settings.xml. Leaving those untouched.");
        }

        mavenProxy.setActive(true);
        mavenProxy.setProtocol(overridingProxy.type().name().toLowerCase());

        SocketAddress overridingProxyAddress = overridingProxy.address();
        if (overridingProxyAddress instanceof InetSocketAddress) {
            InetSocketAddress overridingInetSocketAddress = (InetSocketAddress) overridingProxyAddress;
            mavenProxy.setHost(overridingInetSocketAddress.getHostName());
            mavenProxy.setPort(overridingInetSocketAddress.getPort());
        } else {
            /*
             * Unlikely that the {@link SocketAddress} of the detected
             * {@link java.net.Proxy} would be anything other than its
             * subclass {@link InetSocketAddress}, but just in case, handle
             * it somehow:
             */
            mavenProxy.setHost(overridingProxyAddress.toString());
            mavenProxy.setPort(0);
        }

    }

}

From source file:com.buisonje.AutoProxyMojo.java

License:Apache License

/**
 * @param mojoLog/*from  w w  w  .  ja va 2  s .  com*/
 * @param availableProxies
 */
private void showAvailableProxies(final Log mojoLog, List<Proxy> availableProxies) {
    for (int i = 0; i < availableProxies.size(); i++) {
        final Proxy proxy = availableProxies.get(i);
        mojoLog.info(String.format("Available proxy %d:", i + 1));
        mojoLog.info("  * Proxy type: " + proxy.type().name());
        String proxyAddress = proxy.type() == Type.DIRECT ? "n/a (Direct connection)"
                : proxy.address().toString();
        mojoLog.info("  * Proxy address: " + proxyAddress);
    }
}