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

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

Introduction

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

Prototype

void warn(Throwable error);

Source Link

Document

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

Usage

From source file:com.synedge.enforcer.EnforceImportRelease.java

License:Apache License

public void execute(EnforcerRuleHelper helper) throws EnforcerRuleException {
    Log log = helper.getLog();
    log.info("Entering enforcer");
    try {/* w ww  .ja  va 2  s .c om*/
        // get the various expressions out of the helper.
        MavenProject project = (MavenProject) helper.evaluate("${project}");
        if (project == null) {
            throw new EnforcerRuleException("There is no project");
        }
        if (onlyWhenRelease && project.getArtifact().isSnapshot()) {
            log.warn("Project is SNAPSHOT, not validating");
            return;
        }
        if (project.getDependencyManagement() == null) {
            log.info("No dependency management found. All ok");
            return;
        }
        if (project.getDependencyManagement().getDependencies() == null) {
            log.info("No dependency management dependencies found. All ok");
            return;
        }

        helper.getLog().debug("Getting POM, parse and check it");
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        //Using factory get an instance of document builder
        DocumentBuilder db = dbf.newDocumentBuilder();

        //parse using builder to get DOM representation of the XML file
        Document doc = db.parse(project.getFile().getAbsolutePath());
        XPathFactory xPathfactory = XPathFactory.newInstance();
        XPath xpath = xPathfactory.newXPath();
        XPathExpression expr = xpath.compile(
                "/*[local-name()='project']/*[local-name()='dependencyManagement']/*[local-name()='dependencies']/*[local-name()='dependency']/*[local-name()='scope' and text()='import']/../*[local-name()='version']");
        NodeList nl = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
        for (int i = 0; i < nl.getLength(); i++) {
            Node version = nl.item(i);
            if (version.getTextContent().contains("-SNAPSHOT")) {
                throw new EnforcerRuleException("Found an artifact in the import scope containing SNAPSHOT!");
            }
        }
        helper.getLog().debug("Checked them all");
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    } catch (ParserConfigurationException e) {
        throw new EnforcerRuleException("Unable to parse POM", e);
    } catch (SAXException e) {
        throw new EnforcerRuleException("Unable to parse POM", e);
    } catch (IOException e) {
        throw new EnforcerRuleException("Unable to parse POM", e);
    } catch (XPathExpressionException e) {
        throw new EnforcerRuleException("Internal error in XPath parser", e);
    }
}

From source file:com.taobao.android.JassitMojo.java

License:Apache License

public void execute() throws MojoExecutionException {
    Log log = getLog();
    log.warn("kee start execution ......");

    try {/* w w w  .j  a va 2  s  . c o  m*/
        doExec(log);
    } catch (Throwable e) {
        throw new MojoExecutionException("failed to execute kee-jassist", e);
    }
}

From source file:com.taobao.android.JassitMojo.java

License:Apache License

private void printInfo(Log log) {
    printArtifacts(project.getArtifacts(), log, "");
    log.warn(String.format("kee: PROJ=%s, FILE=%s, BUILD.DIR=%s, BUUILD.OUTPUT=%s", project.getName(),
            project.getFile(), project.getBuild().getDirectory(), project.getBuild().getOutputDirectory()));

    printArtifacts(project.getCompileArtifacts(), log, "COMPILE");
}

From source file:com.taobao.android.JassitMojo.java

License:Apache License

private static void printArtifacts(Collection<Artifact> artifacts, Log log, String prefix) {
    for (Artifact artifact : artifacts) {
        File artFile = artifact.getFile();
        String name = artFile.getName();
        log.warn(String.format("kee: %s_ARTIFACT=%s, FILE=%s", prefix, name, artFile));
    }//from   w  w w .  j a  v a  2s.  c  o  m
}

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

License:Apache License

private void attemptProcessClasses(final Log log, final String groupId, final String artifactId,
        final String target, final String artifactIdPrefix) throws IOException, EnforcerRuleException {
    final String unprefixedArtifactId = artifactId.substring(artifactIdPrefix.length());

    final StringBuilder requiredPackage = new StringBuilder(groupId).append(".")
            .append(unprefixedArtifactId.replace("-", "."));

    final ClassFinder fileVisitor = new ClassFinder(requiredPackage.toString());

    final File targetFolder = new File(target);

    if (!targetFolder.exists()) {
        targetFolder.mkdirs();//from  w ww .  ja v a2s. c om
    }

    final Path root = Paths.get(target);

    log.debug(MessageFormat.format("Attempting to search: {0}", root.toString()));

    Files.walkFileTree(root, fileVisitor);

    if (!fileVisitor.getRejectedClassNames().isEmpty()) {
        final String message = buildError(requiredPackage.toString(), fileVisitor.getRejectedClassNames());

        if (warnOnly) {
            log.warn(message);
        } else {
            throw new EnforcerRuleException(message);
        }
    }
}

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

License:Apache License

private void attemptProcessClasses(final Log log, final String sourceDirectoryRoot, final String groupId,
        final String artifactId, final String artifactIdPrefix) throws IOException, EnforcerRuleException {
    final File srcDirectory = new File(sourceDirectoryRoot);

    if (!srcDirectory.exists()) {
        return;//from w ww.jav  a2 s  .c o  m
    }

    final DirectoryFinder fileVisitor = new DirectoryFinder();
    final String unprefixedArtifactId = artifactId.substring(artifactIdPrefix.length());

    final StringBuilder requiredPackage = new StringBuilder(groupId).append(".")
            .append(unprefixedArtifactId.replace("-", "/"));

    final Path root = Paths.get(sourceDirectoryRoot + File.separatorChar
            + requiredPackage.toString().replace('.', File.separatorChar));

    log.debug(MessageFormat.format("Attempting to search: {0}", root.toString()));

    Files.walkFileTree(root, fileVisitor);

    if (!fileVisitor.getRejectedPackages().isEmpty()) {
        final String message = buildError(fileVisitor.getRejectedPackages());

        if (warnOnly) {
            log.warn(message);
        } else {
            throw new EnforcerRuleException(message);
        }
    }
}

From source file:croche.maven.plugin.jira.ReleaseMultipleJiraVersionsMojo.java

License:Apache License

/**
 * {@inheritDoc}//w  w  w.jav a 2  s .c  o  m
 * @see croche.maven.plugin.jira.AbstractJiraMojo#doExecute(com.atlassian.jira.rpc.soap.client.JiraSoapService, java.lang.String)
 */
@Override
public void doExecute(JiraSoapService jiraService, String loginToken) throws Exception {

    boolean isBranch = this.scmConnection != null && this.scmConnection.contains("branches");

    Log log = getLog();
    log.info("ReleaseMultipleJiraVersionsMojo current projectVersion: " + this.projectVersion
            + ", scmConnection: " + this.scmConnection);
    JiraVersionManager versionManager = new JiraVersionManager(jiraService, loginToken, getLog());

    if (this.jiraVersionSpecs == null || this.jiraVersionSpecs.length == 0) {
        log.warn(
                "ReleaseMultipleJiraVersionsMojo not releasing jira versions as no versions were configured in the configuration.");
    } else if (this.projectVersion.contains("SNAPSHOT")) {
        log.info("ReleaseMultipleJiraVersionsMojo not releasing jira versions as projectVersion: "
                + this.projectVersion + " is a snapshot but will create any existing versions if necessary");
        for (JiraVersionSpec versionSpec : this.jiraVersionSpecs) {
            versionManager.optionallyCreateVersion(versionSpec);
        }
    } else {

        for (JiraVersionSpec versionSpec : this.jiraVersionSpecs) {
            versionManager.releaseVersion(versionSpec, isBranch);
        }

    }

}

From source file:de.adorsys.cmer.InheritedDependencyScopeOverridden.java

License:Apache License

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

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

        StringBuilder overriddenDeps = new StringBuilder();
        StringBuilder pseudoOverriddenDeps = new StringBuilder();

        List<MyDependency> inheritedDependencies = getComparableList(
                project.getDependencyManagement().getDependencies());
        List<MyDependency> declaredDependencies = getComparableList(
                project.getOriginalModel().getDependencies());

        for (MyDependency dependency : declaredDependencies) {
            if (null != dependency.getScope()) {
                Dependency effectiveDependency = inheritedDependencies
                        .get(inheritedDependencies.indexOf(dependency)).getRawDependency();
                String output = effectiveDependency.getManagementKey() + ": " + effectiveDependency.getScope()
                        + " --> " + dependency.getScope() + "\n";

                if (effectiveDependency.getScope() != null
                        ? effectiveDependency.getScope().equals(dependency.getScope())
                        : dependency.getScope() == null) {
                    pseudoOverriddenDeps.append(output);
                } else {
                    overriddenDeps.append(output);
                }
            }
        }

        if (overriddenDeps.length() != 0 | pseudoOverriddenDeps.length() != 0) {
            String warningString = "This depenencies override the inherited scope:\n"
                    + "------------------------------------------------------\n";
            if (pseudoOverriddenDeps.length() != 0) {
                throw new EnforcerRuleException(warningString + overriddenDeps
                        + "\nThis depenencies override the inherited scope with the already defined scope value.\n"
                        + "This dependencies should be corrected:\n"
                        + "---------------------------------------------\n" + pseudoOverriddenDeps + "\n");
            }
            log.warn(warningString + overriddenDeps.toString());
        }
    } catch (ExpressionEvaluationException e) {
        throw new EnforcerRuleException("Unable to lookup an expression " + e.getLocalizedMessage(), e);
    }
}

From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java

License:Apache License

/**
 * Drops a mysql database./*from  w  w w .ja v  a  2s  . c o  m*/
 * 
 * @param magentoDbUser
 * @param magentoDbPasswd
 * @param magentoDbHost
 * @param magentoDbPort
 * @param magentoDbName
 * @param logger
 * @throws MojoExecutionException
 */
public static void dropMagentoDb(String magentoDbUser, String magentoDbPasswd, String magentoDbHost,
        String magentoDbPort, String magentoDbName, Log logger) throws MojoExecutionException {

    try {
        logger.info("Dropping database " + magentoDbName + "..");
        String query = "DROP DATABASE `" + magentoDbName + "`";
        executeRawSql(query, magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort, logger);
    } catch (Exception e) {
        if (e.getMessage().startsWith("ERROR 1008")) {
            logger.warn("..Database does not exist!");
        } else {
            throw new MojoExecutionException("Error while dropping database: " + e.getMessage(), e);
        }
    }
}

From source file:de.bbe_consulting.mavento.helper.MagentoSqlUtil.java

License:Apache License

/**
 * Drop, truncate or partially delete sql tables.
 * //  ww  w.jav  a2  s.  c om
 * @param tableNames
 * @param whereCondidtion
 * @param dropTables
 * @param magentoDbUser
 * @param magentoDbPasswd
 * @param magentoDbHost
 * @param magentoDbPort
 * @param magentoDbName
 * @param logger
 * @throws MojoExecutionException
 */
public static void dropSqlTables(ArrayList<String> tableNames, String whereCondidtion, boolean dropTables,
        String magentoDbUser, String magentoDbPasswd, String magentoDbHost, String magentoDbPort,
        String magentoDbName, Log logger) throws MojoExecutionException {

    String query = "";
    String action = "";
    if (dropTables) {
        query = "DROP TABLE ";
        for (String tableName : tableNames) {
            query += "`" + tableName + "`, ";
        }
        query = query.substring(0, query.length() - 2);
        query += ";";
        action = "Dropping tables " + tableNames.toString() + " in ";
    } else if (whereCondidtion != null && !whereCondidtion.isEmpty()) {
        for (String tableName : tableNames) {
            query += "DELETE FROM `" + tableName + "` WHERE " + whereCondidtion + "; ";
        }
        action = "Deleting from tables " + tableNames.toString() + " where " + whereCondidtion + " in ";
    } else {
        for (String tableName : tableNames) {
            query += "TRUNCATE `" + tableName + "`; ";
        }
        action = "Truncating tables " + tableNames.toString() + " in ";
    }

    try {
        logger.info(action + magentoDbName + "..");
        executeRawSql(query, magentoDbUser, magentoDbPasswd, magentoDbHost, magentoDbPort, magentoDbName,
                logger);
    } catch (Exception e) {
        if (e.getMessage().startsWith("ERROR 1008")) {
            logger.warn("..Database does not exist!");
        } else {
            throw new MojoExecutionException("Error while truncating/dropping tables: " + e.getMessage(), e);
        }
    }
}