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:org.jboss.maven.plugins.qstools.checkers.ArtifactIdNameChecker.java

License:Apache License

@Override
public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession,
        List<MavenProject> reactorProjects, Log log) throws QSToolsException {

    Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>();

    try {// ww  w. j  a va2 s . co  m
        if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) {
            checkerMessage = "This checker is ignored for this groupId in config file.";
        } else {
            Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId());
            List<ArtifactIdNameUtil.PomInformation> pomsWithInvalidArtifactIds = artifactIdNameUtil
                    .findAllIncorrectArtifactIdNames(reactorProjects, rules);

            for (ArtifactIdNameUtil.PomInformation pi : pomsWithInvalidArtifactIds) {
                String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator).replace("\\",
                        "\\\\");
                String fileAsString = pi.getProject().getFile().getAbsolutePath().replace(rootDirectory, "");
                if (results.get(fileAsString) == null) {
                    results.put(fileAsString, new ArrayList<Violation>());
                }
                String msg = "Project with the following artifactId [%s] doesn't match the required format. It should be: [%s]";
                results.get(fileAsString).add(new Violation(getClass(), pi.getLine(),
                        String.format(msg, pi.getActualArtifactId(), pi.getExpectedArtifactId())));
                violationsQtd++;
            }
            if (getCheckerMessage() != null) {
                log.info("--> Checker Message: " + getCheckerMessage());
            }

            if (violationsQtd > 0) {
                log.info("There are " + violationsQtd + " checkers violations");
            }

        }

        return results;
    } catch (Exception e) {
        throw new QSToolsException(e);
    }
}

From source file:org.jboss.maven.plugins.qstools.checkers.JavaEncondingChecker.java

License:Apache License

@Override
public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession,
        List<MavenProject> reactorProjects, Log log) throws QSToolsException {
    Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>();
    try {/*from   w w w  . j  av  a  2  s.  c om*/
        if (configurationProvider.getQuickstartsRules(project.getGroupId()).isCheckerIgnored(this.getClass())) {
            checkerMessage = "This checker is ignored for this groupId in config file.";
        } else {
            // get all files to process
            List<File> sourceFiles = FileUtils.getFiles(project.getBasedir(), "**/*.java", "");
            for (File source : sourceFiles) {
                FileInputStream fis = null;
                try {
                    // Read file content as byte array (no encoding)
                    fis = new FileInputStream(source);
                    byte[] buf = new byte[4096];
                    int nread;
                    while ((nread = fis.read(buf)) > 0 && !encodingDetector.isDone()) {
                        encodingDetector.handleData(buf, 0, nread);
                    }
                    encodingDetector.dataEnd();

                    // report if not utf-8
                    String encoding = encodingDetector.getDetectedCharset();
                    if (encoding != null && !encoding.equalsIgnoreCase("UTF-8")) {
                        // Get relative path based on maven work dir
                        String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator)
                                .replace("\\", "\\\\");
                        String fileAsString = source.getAbsolutePath().replace(rootDirectory, "");
                        if (results.get(fileAsString) == null) {
                            results.put(fileAsString, new ArrayList<Violation>());
                        }
                        results.get(fileAsString).add(new Violation(getClass(), 0,
                                "This file contains a non UTF-8 characters. It was detected as " + encoding));
                        violationsQtd++;
                    }
                } finally {
                    encodingDetector.reset();
                    if (fis != null) {
                        fis.close();
                    }
                }
            }
            if (getCheckerMessage() != null) {
                log.info("--> Checker Message: " + getCheckerMessage());
            }
            if (violationsQtd > 0) {
                log.info("There are " + violationsQtd + " checkers violations");
            }
        }
    } catch (Exception e) {
        throw new QSToolsException(e);
    }
    return results;

}

From source file:org.jboss.maven.plugins.qstools.checkers.SamePropertyValueChecker.java

License:Apache License

@Override
public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession,
        List<MavenProject> reactorProjects, Log log) throws QSToolsException {
    Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>();
    Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId());
    try {/*from  w ww  .  jav  a  2  s .  c o m*/
        if (rules.isCheckerIgnored(this.getClass())) {
            checkerMessage = "This checker is ignored for this groupId in config file.";
        } else {
            // iterate over all reactor projects to iterate on all declared properties
            for (MavenProject mavenProject : reactorProjects) {
                Document doc = PositionalXMLReader.readXML(new FileInputStream(mavenProject.getFile()));
                NodeList propertiesNodes = (NodeList) xPath.evaluate("/project/properties/*", doc,
                        XPathConstants.NODESET);
                // find all declared properties
                for (int x = 0; x < propertiesNodes.getLength(); x++) {
                    Node property = propertiesNodes.item(x);
                    String propertyName = property.getNodeName();
                    String propertyValue = property.getTextContent();

                    // skip ignored property
                    if (rules.getIgnoredDifferentValuesProperties().contains(propertyName)) {
                        continue;
                    }

                    if (projectProperties.get(propertyName) == null) {
                        projectProperties.put(propertyName, propertyValue);
                    } else if (projectProperties.get(propertyName) != null
                            && !projectProperties.get(propertyName).equals(propertyValue)) {
                        // The property was used but with an different value
                        int lineNumber = (Integer) property
                                .getUserData(PositionalXMLReader.BEGIN_LINE_NUMBER_KEY_NAME);
                        String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator)
                                .replace("\\", "\\\\");
                        String fileAsString = mavenProject.getFile().getAbsolutePath().replace(rootDirectory,
                                "");
                        if (results.get(fileAsString) == null) {
                            results.put(fileAsString, new ArrayList<Violation>());
                        }
                        String msg = "Property [%s] was declared with a value [%s] that differ from previous value [%s]";
                        results.get(fileAsString).add(new Violation(getClass(), lineNumber, String.format(msg,
                                propertyName, propertyValue, projectProperties.get(propertyName))));
                        violationsQtd++;
                    }
                }
            }
            if (getCheckerMessage() != null) {
                log.info("--> Checker Message: " + getCheckerMessage());
            }
            if (violationsQtd > 0) {
                log.info("There are " + violationsQtd + " checkers violations");
            }
        }

    } catch (Exception e) {
        throw new QSToolsException(e);
    }
    return results;
}

From source file:org.jboss.maven.plugins.qstools.checkers.UnusedPropertiesChecker.java

License:Apache License

@Override
public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession,
        List<MavenProject> reactorProjects, Log log) throws QSToolsException {
    Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>();
    Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId());
    if (rules.isCheckerIgnored(this.getClass())) {
        checkerMessage = "This checker is ignored for this groupId in config file.";
    } else {//from   w  w  w .  j a va  2s  .  c  o m
        try {

            List<UnusedPropertiesUtil.PomInformation> unusedPropertyInfo = unusedPropertiesUtil
                    .findUnusedProperties(reactorProjects, rules);

            // Construct a violation for each unused property
            for (UnusedPropertiesUtil.PomInformation pi : unusedPropertyInfo) {
                // Get relative path based on maven work dir
                String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator).replace("\\",
                        "\\\\");
                String fileAsString = pi.getProject().getFile().getAbsolutePath().replace(rootDirectory, "");
                if (results.get(fileAsString) == null) {
                    results.put(fileAsString, new ArrayList<Violation>());
                }
                String msg = "Property [%s] was declared but was never used";
                results.get(fileAsString)
                        .add(new Violation(getClass(), pi.getLine(), String.format(msg, pi.getProperty())));
                violationsQtd++;
            }
            if (getCheckerMessage() != null) {
                log.info("--> Checker Message: " + getCheckerMessage());
            }
            if (violationsQtd > 0) {
                log.info("There are " + violationsQtd + " checkers violations");
            }
        } catch (Exception e) {
            throw new QSToolsException(e);
        }
    }
    return results;
}

From source file:org.jboss.maven.plugins.qstools.checkers.ValidXMLSchemaChecker.java

License:Apache License

@Override
public Map<String, List<Violation>> check(MavenProject project, MavenSession mavenSession,
        List<MavenProject> reactorProjects, Log log) throws QSToolsException {
    log.info("--> This Checker can take several minutes to run");
    this.log = log;
    Map<String, List<Violation>> results = new TreeMap<String, List<Violation>>();
    Rules rules = configurationProvider.getQuickstartsRules(project.getGroupId());
    try {/* w  ww . j a v a  2  s  .  c  o m*/
        if (rules.isCheckerIgnored(this.getClass())) {
            checkerMessage = "This checker is ignored for this groupId in config file.";
        } else {
            // get all xml to process but excludes hidden files and /target and /bin folders
            List<File> xmlFiles = FileUtils.getFiles(project.getBasedir(), "**/*.xml", rules.getExcludes());
            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            Schema schema = schemaFactory.newSchema();
            for (File xml : xmlFiles) {
                // Get relative path based on maven work dir
                String rootDirectory = (mavenSession.getExecutionRootDirectory() + File.separator).replace("\\",
                        "\\\\");
                String fileAsString = xml.getAbsolutePath().replace(rootDirectory, "");
                Validator validator = schema.newValidator();
                validator.setResourceResolver(new URLBasedResourceResolver(xml));
                validator.setErrorHandler(new XMLErrorHandler(fileAsString, results));

                log.info("Validating " + fileAsString);
                try {
                    validator.validate(new StreamSource(new BufferedInputStream(new FileInputStream(xml))));
                } catch (SAXException e) {
                    // validator.validate can throw a SAXException coming from the ErrorHandler
                    addViolation(fileAsString, 0, e.getMessage(), results);
                }
            }
            if (getCheckerMessage() != null) {
                log.info("--> Checker Message: " + getCheckerMessage());
            }
            if (violationsQtd > 0) {
                log.info("There are " + violationsQtd + " checkers violations");
            }
        }
    } catch (Exception e) {
        throw new QSToolsException(e);
    }
    return results;

}

From source file:org.jboss.tools.releng.NoSnapshotsAllowed.java

License:Open Source License

public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();

    try {//w w w .j  a v  a2s .  co m
        // get the various expressions out of the helper.
        MavenProject project = (MavenProject) helper.evaluate("${project}");

        //            MavenSession session = (MavenSession) helper.evaluate( "${session}" );
        String target = (String) helper.evaluate("${project.build.directory}");
        String artifactId = (String) helper.evaluate("${project.artifactId}");

        // defaults if not set
        if (includePattern == null || includePattern.equals("")) {
            includePattern = ".*";
        }
        if (excludePattern == null || excludePattern.equals("")) {
            excludePattern = "";
        }

        log.debug("Search for properties matching " + SNAPSHOT + "...");

        Properties projProps = project.getProperties();
        Enumeration<?> e = projProps.propertyNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            // fetch from parent pom if not passed into the rule config
            if (buildAlias == null && key.equals("BUILD_ALIAS")) {
                buildAlias = projProps.getProperty(key);
                if (buildAlias.matches(buildAliasSearch)) {
                    log.info("Found buildAlias = " + buildAlias + " (for buildAliasSearch = " + buildAliasSearch
                            + ")");
                } else {
                    log.debug("Found buildAlias = " + buildAlias + " (for buildAliasSearch = "
                            + buildAliasSearch + ")");
                }
            } else if (key.matches(includePattern)
                    && (excludePattern.equals("") || !key.matches(excludePattern))
                    && projProps.getProperty(key).indexOf(SNAPSHOT) > -1) {
                log.error("Found property " + key + " = " + projProps.getProperty(key));
                snapshotKey = key;
                //                } else {
                //                    log.debug("Property: "+ key + " = " + projProps.getProperty(key));
            }
        }

        //            // retrieve any component out of the session directly
        //            ArtifactResolver resolver = (ArtifactResolver) helper.getComponent( ArtifactResolver.class );
        //            RuntimeInformation rti = (RuntimeInformation) helper.getComponent( RuntimeInformation.class );
        //            log.debug( "Retrieved Session: " + session );
        //            log.debug( "Retrieved Resolver: " + resolver );
        //            log.debug( "Retrieved RuntimeInfo: " + rti );

        log.debug("Retrieved Target Folder: " + target);
        log.debug("Retrieved ArtifactId: " + artifactId);
        log.debug("Retrieved Project: " + project);
        log.debug("Retrieved Project Version: " + project.getVersion());

        if (buildAlias.matches(buildAliasSearch) && snapshotKey != null) {
            throw new EnforcerRuleException("\nWhen buildAlias (" + buildAlias + ") matches /"
                    + buildAliasSearch + "/, cannot include " + SNAPSHOT + " dependencies.\n");
        }
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    }
}

From source file:org.jboss.ws.plugins.tools.AbstractWsConsumeMojo.java

License:Open Source License

public void execute() throws MojoExecutionException {
    Log log = getLog();
    if (wsdls == null) {
        getLog().info("No wsdl URL / file specified, nothing to do.");
        return;/*from ww  w. j a  v  a  2  s.c o  m*/
    }

    if (verbose) {
        log.info("Classpath:");
        for (String s : getClasspathElements()) {
            log.info(" " + s);
        }
    }

    ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
    try {
        URLClassLoader loader = getMavenClasspathAwareClassLoader();
        Thread.currentThread().setContextClassLoader(loader);

        WSContractConsumerParams params = new WSContractConsumerParams();
        params.setAdditionalCompilerClassPath(new LinkedList<String>(getClasspathElements()));
        params.setBindingFiles(bindingFiles);
        params.setCatalog(catalog);
        params.setAdditionalHeaders(additionalHeaders);
        params.setExtension(extension);
        params.setGenerateSource(generateSource);
        params.setLoader(loader);
        params.setNoCompile(noCompile);
        params.setOutputDirectory(getOutputDirectory());
        params.setSourceDirectory(sourceDirectory);
        params.setTarget(target);
        params.setTargetPackage(targetPackage);
        params.setWsdlLocation(wsdlLocation);
        params.setEncoding(encoding);
        params.setArgLine(argLine);
        params.setFork(fork);

        File manifestOnlyJar = createJar(getClasspathElements(), "");
        params.setManifestOnlyJar(manifestOnlyJar);

        WSContractDelegate delegate = new WSContractDelegate(getLog());

        for (String wsdl : wsdls) {
            try {
                delegate.runConsumer(params, wsdl);
            } catch (MalformedURLException mue) {
                log.error("Skipping invalid wsdl reference: " + wsdl);
            } catch (Exception e) {
                throw new MojoExecutionException("Error while running wsconsume", e);
            }
        }
        updateProjectSourceRoots();
    } catch (java.io.IOException ioe) {
        throw new MojoExecutionException("Error while running wsconsume", ioe);
    } finally {
        Thread.currentThread().setContextClassLoader(origLoader);
    }
}

From source file:org.jboss.ws.plugins.tools.AbstractWsProvideMojo.java

License:Open Source License

public void execute() throws MojoExecutionException {
    Log log = getLog();
    if (endpointClass == null) {
        getLog().info("No service endpoint implementation class specified, nothing to do.");
        return;//from   w  w w  .  jav a 2 s  . c  om
    }

    if (verbose) {
        log.info("Classpath:");
        for (String s : getClasspathElements()) {
            log.info(" " + s);
        }
    }

    ClassLoader origLoader = Thread.currentThread().getContextClassLoader();
    URLClassLoader loader = getMavenClasspathAwareClassLoader();
    Thread.currentThread().setContextClassLoader(loader);
    try {
        WSContractProviderParams params = new WSContractProviderParams();
        params.setEndpointClass(endpointClass);
        params.setExtension(extension);
        params.setGenerateSource(generateSource);
        params.setGenerateWsdl(generateWsdl);
        params.setLoader(loader);
        params.setOutputDirectory(getOutputDirectory());
        params.setResourceDirectory(resourceDirectory);
        params.setSourceDirectory(sourceDirectory);
        params.setFork(fork);
        params.setArgLine(argLine);
        params.setPortSoapAddress(portSoapAddress);

        File manifestOnlyJar = createJar(getClasspathElements(), endpointClass);
        params.setManifestOnlyJar(manifestOnlyJar);

        WSContractDelegate delegate = new WSContractDelegate(getLog());
        delegate.runProvider(params);

        updateProjectSourceRoots();
    } catch (Exception e) {
        throw new MojoExecutionException("Error while running wsprovide", e);
    } finally {
        Thread.currentThread().setContextClassLoader(origLoader);
    }
}

From source file:org.jetbrains.kotlin.maven.KotlinCompileMojoBase.java

License:Apache License

protected void configureBaseCompilerArguments(Log log, K2JVMCompilerArguments arguments, String module,
        List<String> sources, List<String> classpath, String output) throws MojoExecutionException {
    // don't include runtime, it should be in maven dependencies
    arguments.noStdlib = true;//from  w w  w .  j  ava 2 s .com

    final ArrayList<String> classpathList = new ArrayList<String>();

    if (module != null) {
        log.info("Compiling Kotlin module " + module);
        arguments.setModule(module);
    } else {
        if (sources.size() <= 0)
            throw new MojoExecutionException("No source roots to compile");

        arguments.setSourceDirs(sources);
        log.info("Compiling Kotlin sources from " + arguments.getSourceDirs());

        // TODO: Move it compiler
        classpathList.addAll(sources);
    }

    classpathList.addAll(classpath);

    if (classpathList.remove(output)) {
        log.debug("Removed target directory from compiler classpath (" + output + ")");
    }

    //        final String runtime = getRuntimeFromClassPath(classpath);
    //        if (runtime != null) {
    //            log.debug("Removed Kotlin runtime from compiler classpath (" + runtime + ")");
    //            classpathList.remove(runtime);
    //        }

    if (classpathList.size() > 0) {
        final String classPathString = Joiner.on(File.pathSeparator).join(classpathList);
        log.info("Classpath: " + classPathString);
        arguments.setClasspath(classPathString);
    }

    log.info("Classes directory is " + output);
    arguments.setOutputDir(output);

    arguments.noJdkAnnotations = true;
    arguments.annotations = getFullAnnotationsPath(log, annotationPaths);
    log.info("Using kotlin annotations from " + arguments.annotations);
}

From source file:org.jetbrains.kotlin.maven.KotlinCompileMojoBase.java

License:Apache License

protected String getFullAnnotationsPath(Log log, List<String> annotations) {
    String jdkAnnotation = getJdkAnnotations().getPath();

    List<String> list = new ArrayList<String>();
    if (jdkAnnotation != null && jdkAnnotation.length() > 0) {
        list.add(jdkAnnotation);/*  w  w w .j a  va 2  s.c o  m*/
    }
    if (annotations != null) {
        for (String annotationPath : annotations) {
            if (new File(annotationPath).exists()) {
                list.add(annotationPath);
            } else {
                log.info("annotation path " + annotationPath + " does not exist");
            }
        }
    }
    return join(list, File.pathSeparator);
}