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.umakantpatil.FileDownloader.java

License:Apache License

/**
 * Downloads, copies and untars PHP Code Sniffer.
 *
 * Example URL of a download package is//from  w  ww.j av  a2s .  c om
 * http://download.pear.php.net/package/PHP_CodeSniffer-2.4.0.tgz
 *
 * @param phpCodeSnifferDownloadPath Path where to download PHP CodeSniffer
 * @param phpCodeSnifferVersion      Which version to download.
 * @param logger                Logger class to log the details for debugging.
 *
 * @since 0.0.1
 * @throws DownloadFailed If version provided is not available on the website.
 *                        Or any IO Exception is thrown.
 */
public String get(String phpCodeSnifferDownloadPath, String phpCodeSnifferVersion, Log logger)
        throws DownloadFailed {
    InputStream is = null;
    FileOutputStream fos = null;
    String ds = File.separator;
    // System's temp directory.
    String tempDir = System.getProperty("java.io.tmpdir");
    // Where to download sniffer temporary.
    String tempSniff = tempDir + ds + "PHPCodeSniffer" + phpCodeSnifferVersion;
    // Where to untar the downloaded sniffer.
    String tempUntaredSniff = tempDir + ds + "PHPCodeSniffer-untar-" + phpCodeSnifferVersion;

    String downloadPath = "http://download.pear.php.net/package/PHP_CodeSniffer-" + phpCodeSnifferVersion
            + ".tgz";
    logger.info("Downloading PHP CodeSniffer from " + downloadPath);

    try {
        logger.debug("Dowmloading PHP CodeSniffer at " + tempSniff);
        URL url;
        url = new URL(downloadPath);
        URLConnection urlConn = url.openConnection();
        is = urlConn.getInputStream();
        fos = new FileOutputStream(tempSniff);
        byte[] buffer = new byte[4096];
        int len;

        while ((len = is.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }

        if (is != null) {
            is.close();
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        throw new DownloadFailed(
                "Provided version of PHP CodeSniffer is wrong or check your internet connection. details: "
                        + e.getMessage());
    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (Exception e) {
            // TODO:: Catch right exceptions, not all.
        }
    }

    try {
        Archiver archiver = ArchiverFactory.createArchiver("tar", "gz");
        archiver.extract(new File(tempSniff), new File(tempUntaredSniff));
        logger.debug("Temporary untar directory is " + tempUntaredSniff);
        String tempSniffFolder = tempUntaredSniff + ds + "PHP_CodeSniffer-" + phpCodeSnifferVersion;
        File srcDir = new File(tempSniffFolder);
        File destDir = new File(phpCodeSnifferDownloadPath);
        recursiveCopy(srcDir, destDir);
        logger.debug("Copying PHP CodeSniffer from " + srcDir.getAbsolutePath());
        logger.debug("Copying PHP CodeSniffer to " + destDir.getAbsolutePath());
        File f = new File(phpCodeSnifferDownloadPath + ds + phpCodeSnifferVersion);
        f.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return phpCodeSnifferDownloadPath;
}

From source file:com.umakantpatil.PHPCodeSnifferChecksMojo.java

License:Apache License

/**
 * Execute the PHP CodeSniffer checks.//w  ww. j  a  v a 2s . c  om
 *
 * Below is the sample command to run PHP CodeSniffer.
 * <php-binary> -d memory_limit=<512M> -f <phpcs>/scripts/phpcs -- <-sp> --standard=<src/test/checks/general-ruleset.xml> <src/main>
 *
 * @see org.apache.maven.plugin.Mojo#execute()
 * @throws MojoExecutionException If configuration is not provided.
 * @throws MojoFailureException If tests are not passed.
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    String ds = File.separator;
    Log logger = getLog();
    if (phpCodeSnifferPath == null && phpCodeSnifferPathDownloaded == null) {
        throw new MojoExecutionException(
                "Please provide path to installed PHP CodeSniffer or path to download PHP CodeSniffer.");
    }
    if (phpBinary == null) {
        throw new MojoExecutionException("Please provide binary php path.");
    }
    if (pathToCode == null) {
        throw new MojoExecutionException("Please provide path to code.");
    }
    if (phpCodeSnifferPathDownloaded != null) {
        phpCodeSnifferPath = phpCodeSnifferPathDownloaded;
    }
    logger.info("PHP CodeSniffer is stored at " + phpCodeSnifferPath);
    logger.info("Running checks against " + pathToCode);
    if (standard != null) {
        logger.info("Selected standard it " + standard);
    }
    logger.info("Memory limit is " + memoryLimit);
    String command = "";
    command += phpBinary + " ";
    command += "-d " + memoryLimit + " ";
    command += "-f " + phpCodeSnifferPath + ds + "scripts" + ds + "phpcs -- -sp ";
    if (standard != null) {
        command += "--standard=" + standard + " ";
    }
    command += pathToCode;
    logger.info("Final command to run " + command);
    try {
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(command);
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
        @SuppressWarnings("unused")
        BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));

        String s = null;
        while ((s = stdInput.readLine()) != null) {
            logger.info(s);
        }
        int exitValue = proc.waitFor();
        if (exitValue == 1) {
            throw new MojoFailureException("Fix the above errors.");
        }
    } catch (InterruptedException e) {
        throw new MojoFailureException("Error while executing the sniff checks.");
    } catch (IOException e) {
        throw new MojoFailureException("Error while executing the sniff checks.");
    }
}

From source file:com.umakantpatil.PHPCodeSnifferDownloaderMojo.java

License:Apache License

/**
 * Checks if PHP CodeSniffer version exists at the path.
 *
 * @since 0.0.2/*from  w  w  w. j  a v  a2  s.c om*/
 * @return Boolean If PHP CodeSniffer Exists.
 */
protected boolean checkIfPhpCodeSnifferExists() {
    String phpSniffPath = pathToPHPCodeSniffer();
    File f = new File(phpSniffPath + File.separator + phpCodeSnifferVersion);
    Log logger = getLog();
    logger.debug("Checking if file exists at " + f.getAbsolutePath());
    if (f.exists()) {
        logger.info("PHP CodeSniffer " + phpCodeSnifferVersion + " already exists.");
        return true;
    }
    return false;
}

From source file:com.webguys.maven.plugin.st.Controller.java

License:Open Source License

private Class findControllerClass(ProjectDependenciesResolver dependenciesResolver,
        ExecutionEnvironment executionEnvironment, Log log) throws MojoExecutionException,
        ClassNotFoundException, MalformedURLException, ArtifactResolutionException, ArtifactNotFoundException {
    try {/* w w  w. ja  va  2s  . c  om*/
        return this.loadController(executionEnvironment.getMavenProject(),
                executionEnvironment.getMavenSession(), dependenciesResolver);
    } catch (ClassNotFoundException e) {
        if (this.compile) {
            log.info(String.format("Unable to find the class: %s.  Attempting to compile it...",
                    this.className));
            return this.compileAndLoadController(log, dependenciesResolver, executionEnvironment);
        } else {
            throw new MojoExecutionException(
                    String.format("The class %s is not in the classpath, and compilation is not enabled.",
                            this.className),
                    e);
        }
    }
}

From source file:com.webguys.maven.plugin.st.Controller.java

License:Open Source License

private void executeCompilerPlugin(ExecutionEnvironment executionEnvironment, Log log)
        throws MojoExecutionException {
    String path = this.className.replace(".", File.separator) + ".java";
    log.info(String.format("Compiling %s...", path));

    executeMojo(/*www.  j a  v a 2 s  . c om*/
            plugin(groupId("org.apache.maven.plugins"), artifactId("maven-compiler-plugin"),
                    version(compilerVersion)),
            goal("compile"),
            configuration(element(name("source"), sourceVersion), element(name("target"), targetVersion),
                    element(name("includes"), element("include", path))),
            executionEnvironment);
}

From source file:com.webguys.maven.plugin.st.Controller.java

License:Open Source License

private Object invoke(Class controllerClass, Method method, Log log)
        throws InstantiationException, IllegalAccessException, InvocationTargetException {
    Object controller = null;//w  ww . j  av a  2 s .c om
    if (!Modifier.isStatic(method.getModifiers())) {
        controller = controllerClass.newInstance();
    }

    log.info(String.format("Invoking controller: %s.%s()", controllerClass.getName(), method.getName()));
    return method.invoke(controller);
}

From source file:com.webguys.maven.plugin.st.Template.java

License:Open Source License

private void prepareCompilerSourceRoot(File file, MavenProject project, Log log) {
    String path = file.getPath();
    if (file.getName().endsWith("java") && path.contains("generated-sources")) {
        int index = path.indexOf("generated-sources") + 18;
        index = path.indexOf(File.separator, index);
        String sourceRoot = path.substring(0, index);
        log.info("Adding compile source root: " + sourceRoot);
        project.addCompileSourceRoot(sourceRoot);
    }//from ww w .  j av a2s  .  co  m
}

From source file:com.wibidata.maven.plugins.hbase.MiniHBaseClusterSingleton.java

License:Apache License

/**
 * Starts the HBase cluster and blocks until it is ready.
 *
 * @param log The maven log./*from   w  w w.  j a  va2s .  c  om*/
 * @param alsoStartMapReduce Whether to also start a mini MapReduce cluster.
 * @param conf Hadoop configuration for the cluster.
 * @throws IOException If there is an error.
 */
public void startAndWaitUntilReady(Log log, boolean alsoStartMapReduce, Configuration conf) throws IOException {
    mCluster = new MiniHBaseCluster(log, alsoStartMapReduce, conf);
    mThread = new MiniHBaseClusterThread(log, mCluster);

    log.info("Starting new thread...");
    mThread.start();

    // Wait for the cluster to be ready.
    log.info("Waiting for cluster to be ready...");
    while (!mThread.isClusterReady()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            log.info("Still waiting...");
        }
    }
    log.info("Finished waiting for HBase cluster thread.");
}

From source file:com.wibidata.maven.plugins.hbase.MiniHBaseClusterSingleton.java

License:Apache License

/**
 * Stops the HBase cluster and blocks until is has been shutdown completely.
 *
 * @param log The maven log./*from  w w w  .j  av a2 s.c  o  m*/
 */
public void stop(Log log) {
    if (null == mCluster) {
        log.error("Attempted to stop a cluster, but no cluster was ever started in this process.");
        return;
    }

    log.info("Stopping the HBase cluster thread...");
    mThread.stopClusterGracefully();
    while (mThread.isAlive()) {
        try {
            mThread.join();
        } catch (InterruptedException e) {
            log.debug("HBase cluster thread interrupted.");
        }
    }
    log.info("HBase cluster thread stopped.");
}

From source file:cool.arch.iconfist.enforcer.ClassPackageMembershipRule.java

License:Apache License

/**
 * {@inheritDoc}/*from   w w  w .ja v a  2s.c  om*/
 * @param helper Rule helper
 */
@Override
public void execute(final EnforcerRuleHelper helper) throws EnforcerRuleException {
    final Log log = helper.getLog();

    try {
        final String target = (String) helper.evaluate("${project.build.directory}");
        final String artifactIdPrefix = (String) helper.evaluate("${stack.artifactId.prefix}");
        final String packaging = (String) helper.evaluate("${project.packaging}");
        final String groupId = (String) helper.evaluate("${project.groupId}");
        final String artifactId = (String) helper.evaluate("${project.artifactId}");

        if (artifactIdPrefix == null || artifactIdPrefix.isEmpty()) {
            throw new EnforcerRuleException("stack.artifactId.prefix must be defined.");
        }

        if (!artifactId.startsWith(artifactIdPrefix)) {
            throw new EnforcerRuleException(
                    MessageFormat.format("ArtifactId {0} must start with {1}.", artifactId, artifactIdPrefix));
        }

        switch (packaging) {
        case "jar":
        case "war":
        case "ear":
            attemptProcessClasses(log, groupId, artifactId, target, artifactIdPrefix);
            break;

        default:
            log.info(MessageFormat.format("Not an applicable project type '{0}'. Skipping rule checks for {1}.",
                    packaging, this.getClass().getSimpleName()));
            break;
        }
    } catch (final ExpressionEvaluationException e) {
        throw new EnforcerRuleException(
                MessageFormat.format("Unable to lookup an expression: {0}", e.getLocalizedMessage()), e);
    } catch (final IOException e) {
        throw new EnforcerRuleException("Error attempting to locate .class files.", e);
    }
}