Example usage for org.apache.maven.project MavenProject getGroupId

List of usage examples for org.apache.maven.project MavenProject getGroupId

Introduction

In this page you can find the example usage for org.apache.maven.project MavenProject getGroupId.

Prototype

public String getGroupId() 

Source Link

Usage

From source file:se.jguru.nazgul.tools.codestyle.enforcer.rules.RestrictImplDependencies.java

License:Apache License

/**
 * Delegate method, implemented by concrete subclasses.
 *
 * @param project The active MavenProject.
 * @param helper  The EnforcerRuleHelper instance, from which the MavenProject has been retrieved.
 * @throws RuleFailureException If the enforcer rule was not satisfied.
 *//*w w  w  . j a  v  a2 s .  c  o  m*/
@SuppressWarnings({ "unchecked" })
@Override
protected void performValidation(final MavenProject project, final EnforcerRuleHelper helper)
        throws RuleFailureException {

    // Acquire the ProjectType
    final ProjectType projectType;
    try {
        projectType = ProjectType.getProjectType(project);
    } catch (IllegalArgumentException e) {
        throw new RuleFailureException("Incorrect project definition for " + project, e);
    }

    // Don't evaluate for ignored project types.
    if (IGNORED_PROJECT_TYPES.contains(projectType)) {
        return;
    }

    // Don't evaluate if told not to.
    if (matches(project.getGroupId(), dontEvaluateGroupIds)) {

        // Log somewhat
        helper.getLog().debug("Ignored [" + project.getGroupId() + ":" + project.getArtifactId()
                + "] since its groupId was excluded from enforcement.");
        return;

    }

    // Don't evaluate if not told to.
    if (!matches(project.getGroupId(), evaluateGroupIds)) {

        // Log somewhat
        helper.getLog().debug("Ignored [" + project.getGroupId() + ":" + project.getArtifactId()
                + "] since its groupId was not included in enforcement.");
        return;
    }

    // Acquire all project dependencies.
    for (final Artifact current : ((Set<Artifact>) project.getDependencyArtifacts())) {

        // Don't evaluate for test-scope dependencies.
        if (Artifact.SCOPE_TEST.equalsIgnoreCase(current.getScope())) {
            continue;
        }

        // Should this Artifact be evaluated?
        final boolean isIncludedInEvaluation = matches(current.getGroupId(), evaluateGroupIds);
        final boolean isNotExplicitlyExcludedFromEvaluation = !matches(current.getGroupId(),
                dontEvaluateGroupIds);
        if (isIncludedInEvaluation && isNotExplicitlyExcludedFromEvaluation) {

            final ProjectType artifactProjectType = ProjectType.getProjectType(current);
            final String prefix = "Don't use " + artifactProjectType + " dependencies ";

            if (artifactProjectType == ProjectType.IMPLEMENTATION) {
                throw new RuleFailureException(prefix + "outside of application projects.", current);
            }

            if (artifactProjectType == ProjectType.TEST) {
                throw new RuleFailureException(prefix + "in compile scope for non-test artifacts.", current);
            }

            if (artifactProjectType == ProjectType.JEE_APPLICATION
                    || artifactProjectType == ProjectType.PROOF_OF_CONCEPT) {
                throw new RuleFailureException(prefix + "in bundles.", current);
            }
        }
    }
}

From source file:uk.ac.ox.oucs.plugins.DiscoverMojo.java

License:Apache License

protected void deployAndDependents(Set<Artifact> artifacts)
        throws MojoExecutionException, MojoFailureException {
    loadCachedImplentations();//from   w  w w .j  a  v a2  s  . c o m
    try {
        toDeploy.addAll(artifacts);
        do {
            ArtifactResolutionResult arr = customResolver.resolveTransitively(artifacts, project.getArtifact(),
                    localRepository, remoteRepositories, customMetadataSource, null);
            Set<Artifact> resolvedArtifacts = arr.getArtifacts();

            Set<ResolutionNode> arrRes = arr.getArtifactResolutionNodes();

            for (ResolutionNode node : arrRes) {
                getLog().info(node.getArtifact().getArtifactId());
                for (String artifactId : (List<String>) node.getDependencyTrail()) {
                    getLog().info("  +" + artifactId);
                }
            }

            Set<Artifact> artifactsToFind = new HashSet<Artifact>();

            for (Artifact artifact : resolvedArtifacts) {
                if (needsImplementation(artifact)) {
                    getLog().debug("Needed : " + artifact.toString() + " " + artifact.getDependencyTrail());
                    artifactsToFind.add(artifact);
                } else {
                    getLog().debug("Ignored : " + artifact.toString() + " " + artifact.getDependencyTrail());
                }

            }

            artifacts = new HashSet<Artifact>();
            for (Artifact artifact : artifactsToFind) {
                String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId();
                if (!checkedArtifacts.contains(artifactKey)) {
                    toDeploy.add(artifact);
                    MavenProject project = findImplementation(artifact);
                    if (project != null) {
                        getLog().info("Found implementation: " + artifactKey + " to " + project.getGroupId()
                                + ":" + project.getArtifactId() + ":" + project.getVersion());
                        Set<Artifact> projectArtifacts = project.createArtifacts(customArtifactFactory, null,
                                null);
                        //artifacts.addAll(projectArtifacts);
                        if (shouldExpand(project)) {

                            toDeploy.addAll(projectArtifacts);
                        }
                        artifacts.add(project.getArtifact());
                        toDeploy.add(project.getArtifact());

                    } else {
                        getLog().info("Unresolved implementation: " + artifactKey);

                    }
                    checkedArtifacts.add(artifactKey);
                }
            }
        } while (artifacts.size() > 0);
    } catch (InvalidDependencyVersionException e1) {
        throw new MojoExecutionException("Failed to create artifacts", e1);
    } catch (ArtifactResolutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ArtifactNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        saveCachedImplmentations();
    }

    addToDependencies();

}