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

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

Introduction

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

Prototype

public String getArtifactId() 

Source Link

Usage

From source file:org.srcdeps.mvn.plugin.SrcdepsInitMojo.java

License:Apache License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    super.execute();

    org.srcdeps.core.GavSet.Builder gavSetBuilder = GavSet.builder() //
            .includes(includes) //
            .excludes(excludes);//  w  w  w.  ja v a2 s. c  o  m
    if (excludeSnapshots) {
        gavSetBuilder.excludeSnapshots();
    }
    this.gavSet = gavSetBuilder.build();

    log.info("Using includes and excludes [{}]", gavSet);

    log.info("Supported SCMs: {}", scms);

    if (skip || !multiModuleRootDir.equals(session.getCurrentProject().getBasedir())) {
        log.info(getClass().getSimpleName() + " skipped");
    } else {

        Configuration.Builder config = Configuration.builder() //
                .configModelVersion(Configuration.getLatestConfigModelVersion()).commentBefore("") //
                .commentBefore("srcdeps.yaml - the srcdeps configuration file") //
                .commentBefore("") //
                .commentBefore(
                        "The full srcdeps.yaml reference can be found under https://github.com/srcdeps/srcdeps-core/tree/master/doc/srcdeps.yaml") //
                .commentBefore("") //
                .commentBefore("This file was generated by the following command:") //
                .commentBefore("") //
                .commentBefore("    mvn org.srcdeps.mvn:srcdeps-maven-plugin:init") //
                .commentBefore("") //
        ;

        ScmRepositoryIndex index = new ScmRepositoryIndex(session, repoSession, repositorySystem,
                projectBuilder, scms);
        log.debug("Going over [{}] reactor projects", reactorProjects.size());
        /* first add the reactor projects to seenGas so that they get ignored */
        for (MavenProject project : reactorProjects) {
            index.ignoreGav(project.getGroupId(), project.getArtifactId(), project.getVersion());
        }

        for (MavenProject project : reactorProjects) {

            final List<Dependency> dependencies = project.getDependencies();

            log.info("Project [{}] has [{}] dependencies", project.getArtifactId(),
                    dependencies == null ? 0 : dependencies.size());

            if (dependencies != null) {
                for (Dependency dependency : dependencies) {

                    final String g = dependency.getGroupId();
                    final String a = dependency.getArtifactId();
                    final String v = dependency.getVersion();
                    if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) {
                        /* Ignore system scope */
                        index.addGav(g, a, v, failOnUnresolvable);
                    }
                }
            }

            final DependencyManagement dependencyManagement = project.getDependencyManagement();
            if (dependencyManagement != null) {
                final List<Dependency> managedDeps = dependencyManagement.getDependencies();
                if (managedDeps != null) {
                    for (Dependency dependency : managedDeps) {
                        final String g = dependency.getGroupId();
                        final String a = dependency.getArtifactId();
                        final String v = dependency.getVersion();
                        if (!"system".equals(dependency.getScope()) && gavSet.contains(g, a, v)) {
                            /* Ignore system scope */
                            index.addGav(g, a, v, false);
                        }
                    }
                }
            }

            MavenProject parent = project.getParent();
            if (parent != null) {
                final String g = parent.getGroupId();
                final String a = parent.getArtifactId();
                final String v = parent.getVersion();
                if (gavSet.contains(g, a, v)) {
                    index.addGav(g, a, v, failOnUnresolvable);
                }
            }
        }

        Map<String, Builder> repos = index.createSortedScmRepositoryMap();
        if (repos.size() == 0) {
            /* add some dummy repo so that we do not write an empty srcdeps.yaml file */
            ScmRepository.Builder dummyRepo = ScmRepository.builder() //
                    .commentBefore(
                            "FIXME: srcdeps-maven-plugin could not authomatically identify any SCM URLs for dependencies in this project") //
                    .commentBefore(
                            "       and has added this dummy repository only as a starting point for you to proceed manually") //
                    .id("org.my-group") //
                    .selector("org.my-group") //
                    .url("git:https://github.com/my-org/my-project.git") //
            ;
            repos.put(dummyRepo.getName(), dummyRepo);
        }

        config //
                .repositories(repos) //
                .accept(new OverrideVisitor(System.getProperties())) //
                .accept(new DefaultsAndInheritanceVisitor()) //
        ;

        final Path srcdepsYamlPath = multiModuleRootDir.toPath().resolve("srcdeps.yaml");
        try {
            YamlWriterConfiguration yamlWriterConfiguration = YamlWriterConfiguration.builder().build();
            try (Writer out = Files.newBufferedWriter(srcdepsYamlPath, Charset.forName(encoding))) {
                config.accept(new YamlWriterVisitor(out, yamlWriterConfiguration));
            }
        } catch (IOException e) {
            throw new MojoExecutionException(String.format("Could not write [%s]", srcdepsYamlPath), e);
        }
    }

}

From source file:org.talend.components.api.service.internal.ComponentServiceImpl.java

License:Open Source License

public Set<Dependency> getArtifactsDependencies(MavenProject project, MavenBooter booter,
        String... excludedScopes)
        throws DependencyCollectionException, org.eclipse.aether.resolution.DependencyResolutionException {
    DefaultArtifact pomArtifact = new DefaultArtifact(project.getGroupId(), project.getArtifactId(),
            project.getPackaging(), null, project.getVersion());
    // check the cache if we already have computed the dependencies for this pom.
    if (dependenciesCache.containsKey(pomArtifact)) {
        return dependenciesCache.get(pomArtifact);
    }/*from   w  w  w  . j  a v  a 2 s  . co m*/
    RepositorySystem repoSystem = booter.newRepositorySystem();
    DefaultRepositorySystemSession repoSession = booter.newRepositorySystemSession(repoSystem);
    DependencySelector depFilter = new AndDependencySelector(
            new ScopeDependencySelector(null, Arrays.asList(excludedScopes)), new OptionalDependencySelector(),
            new ExclusionDependencySelector());
    repoSession.setDependencySelector(depFilter);

    List<RemoteRepository> remoteRepos = booter.getRemoteRepositoriesWithAuthentification(repoSystem,
            repoSession);

    CollectRequest collectRequest = new CollectRequest(new Dependency(pomArtifact, "runtime"), remoteRepos);
    // collectRequest.setRequestContext(scope);
    CollectResult collectResult = repoSystem.collectDependencies(repoSession, collectRequest);
    DependencyNode root = collectResult.getRoot();
    Set<Dependency> ret = new HashSet<>();
    ret.add(root.getDependency());
    flattenDeps(root, ret);
    dependenciesCache.put(pomArtifact, ret);
    return ret;
}

From source file:org.topdesk.maven.tracker.MavenCli.java

License:Apache License

private int execute(CliRequest cliRequest) {
    MavenExecutionResult result = maven.execute(cliRequest.request);

    if (result.hasExceptions()) {
        ExceptionHandler handler = new DefaultExceptionHandler();

        Map<String, String> references = new LinkedHashMap<String, String>();

        MavenProject project = null;

        for (Throwable exception : result.getExceptions()) {
            ExceptionSummary summary = handler.handleException(exception);

            logSummary(summary, references, "", cliRequest.showErrors);

            if (project == null && exception instanceof LifecycleExecutionException) {
                project = ((LifecycleExecutionException) exception).getProject();
            }/*  w  w w  .java  2  s  .  co  m*/
        }

        logger.error("");

        if (!cliRequest.showErrors) {
            logger.error("To see the full stack trace of the errors, re-run Maven with the -e switch.");
        }
        if (!logger.isDebugEnabled()) {
            logger.error("Re-run Maven using the -X switch to enable full debug logging.");
        }

        if (!references.isEmpty()) {
            logger.error("");
            logger.error("For more information about the errors and possible solutions"
                    + ", please read the following articles:");

            for (Map.Entry<String, String> entry : references.entrySet()) {
                logger.error(entry.getValue() + " " + entry.getKey());
            }
        }

        if (project != null && !project.equals(result.getTopologicallySortedProjects().get(0))) {
            logger.error("");
            logger.error("After correcting the problems, you can resume the build with the command");
            logger.error("  mvn <goals> -rf :" + project.getArtifactId());
        }

        if (MavenExecutionRequest.REACTOR_FAIL_NEVER.equals(cliRequest.request.getReactorFailureBehavior())) {
            logger.info("Build failures were ignored.");

            return 0;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

From source file:org.universAAL.support.directives.checks.DependencyManagementCheckFix.java

License:Apache License

private Map<DependencyID, String> getActualVersions(MavenProject mavenProject2) {
    TreeMap<DependencyID, String> versionMap = new TreeMap<DependencyID, String>();
    boolean containsSubPOMProjects = includesPOMSubProjects(mavenProject2);
    for (MavenProject mavenProject : reactorProjects) {
        if (mavenProject.getVersion() != null
                && (!mavenProject.getPackaging().equals("pom") || containsSubPOMProjects)) {
            // Check if its a pom, add it if not!
            versionMap.put(new DependencyID(mavenProject.getGroupId(), mavenProject.getArtifactId()),
                    mavenProject.getVersion());
            getLog().debug("added to ActualVersions: " + mavenProject.getGroupId() + ":"
                    + mavenProject.getArtifactId() + ":" + mavenProject.getVersion());
        }/*from w  ww .j a  v  a  2 s.c om*/
    }
    return versionMap;
}

From source file:org.universAAL.support.directives.checks.MavenCoordinateCheck.java

License:Apache License

/** {@inheritDoc} */
public boolean check(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {

    String artifactIdMatchString = mavenProject.getProperties().getProperty(ARTIFACT_ID_MATCH_PROP,
            DEFAULT_MATCH);/*from w  w w . jav  a 2  s  .  co m*/
    String groupIdMatchString = mavenProject.getProperties().getProperty(GROUP_ID_MATCH_PROP, DEFAULT_MATCH);
    String nameMatchString = mavenProject.getProperties().getProperty(NAME_MATCH_PROP, DEFAULT_MATCH);
    String versionMatchString = mavenProject.getProperties().getProperty(VERSION_MATCH_PROP, DEFAULT_MATCH);

    Pattern pAId = Pattern.compile(artifactIdMatchString);
    Pattern pGId = Pattern.compile(groupIdMatchString);
    Pattern pVer = Pattern.compile(versionMatchString);
    Pattern pNam = Pattern.compile(nameMatchString);

    Matcher mAId = pAId.matcher(mavenProject.getArtifactId());
    Matcher mGId = pGId.matcher(mavenProject.getGroupId());
    Matcher mVer = pVer.matcher(mavenProject.getVersion());
    Matcher mNam = pNam.matcher(mavenProject.getName());

    StringBuffer message = new StringBuffer();

    if (!mAId.find()) {
        message.append("ArtifactId: " + mavenProject.getArtifactId() + DOES_NOT_MATCH_CONVENTION
                + artifactIdMatchString + "\n");
    }
    if (!mGId.find()) {
        message.append("GroupId: " + mavenProject.getGroupId() + DOES_NOT_MATCH_CONVENTION + groupIdMatchString
                + "\n");
    }
    if (!mVer.find()) {
        message.append("Version: " + mavenProject.getVersion() + DOES_NOT_MATCH_CONVENTION + versionMatchString
                + "\n");
    }
    if (!mNam.find()) {
        message.append("Artifact Name: " + mavenProject.getName() + DOES_NOT_MATCH_CONVENTION + nameMatchString
                + "\n");
    }

    if (message.length() > 0) {
        throw new MojoFailureException(message.toString());
    }
    Model pomFileModel = null;
    try {
        pomFileModel = PomWriter.readPOMFile(mavenProject);
    } catch (Exception e) {
    }

    if (!mavenProject.getPackaging().equals("pom") && pomFileModel != null
            && (pomFileModel.getProperties().containsKey(ARTIFACT_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(GROUP_ID_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(VERSION_MATCH_PROP)
                    || pomFileModel.getProperties().containsKey(NAME_MATCH_PROP))) {
        throw new MojoFailureException("This project has declared naming conventions when it shoudln't.\n"
                + "This is probably an attempt to skip this directive, SHAME ON YOU!");
    }

    return true;
}

From source file:org.universAAL.support.directives.checks.ParentGForgePropertyCheck.java

License:Apache License

public static boolean isParentRootPOM(MavenProject mavenProject2) {
    MavenProject parent = mavenProject2.getParent();
    if (parent == null)
        return false;
    String parentID = parent.getArtifactId();
    return (parent.getGroupId().equals(UAAL_GID) && parentID.endsWith(UAAL_AID));
}

From source file:org.universAAL.support.directives.mojos.CheckReportMojo.java

License:Apache License

/**
 * @param sink/*  w  w w.  java 2 s  . c o  m*/
 * @param loc 
 */
private void renderModulesTable(Sink sink, Locale loc) {
    for (MavenProject mp : reactorProjects) {

        for (int i = 0; i < checks.length; i++) {
            if (!mp.equals(project)) {
                boolean passed;
                AbstractMojoExecutionException ex = null;
                try {
                    passed = checks[i].check(mp, getLog());
                } catch (MojoExecutionException e) {
                    passed = false;
                    ex = e;
                } catch (MojoFailureException e) {
                    passed = false;
                    ex = e;
                } catch (Exception e) {
                    passed = false;
                    ex = new MojoExecutionException("Unexpected Exception", e);
                }
                // IF passed, do nothing if failed write row.
                if (!passed) {
                    sink.tableRow();
                    sink.tableCell();
                    //                  sink.text(mp.getGroupId() + ":" + mp.getArtifactId());
                    sink.text(mp.getArtifactId());
                    sink.tableCell_();
                    writeRow(checks[i], passed, ex, sink, loc);
                    sink.tableRow_();
                    FailedModules.add(mp);
                }
            }
        }
    }
}

From source file:org.universAAL.support.directives.procedures.Tag.java

License:Apache License

/** {@inheritDoc} */
public void execute(MavenProject mavenProject, Log log) throws MojoExecutionException, MojoFailureException {
    if (baseURL == null) {
        baseURL = mavenProject.getScm().getDeveloperConnection();
    }//from ww  w  .  j  a  v  a 2 s .  c  o  m
    String tagUrl = getTagURL(mavenProject);
    log.info("Tagging: " + baseURL + "  ->  " + tagUrl);
    if (tagRemoteHead) {
        if (!performTag(baseURL, tagUrl, "Automatic tag of " + mavenProject.getArtifactId() + " version: "
                + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    } else {
        if (!performWCTag(mavenProject.getBasedir(), tagUrl, "Automatic tag of " + mavenProject.getArtifactId()
                + " version: " + mavenProject.getVersion())) {
            throw new MojoExecutionException(NOT_TAGGED);
        }
    }
}

From source file:org.universAAL.support.directives.procedures.Tag.java

License:Apache License

/**
 * parses the scm url to generate an appropiate tag URL, in concordance to
 * T2.3 Directives//  w  ww  .j a va2s .c  om
 * 
 * @return
 */
public static String getTagURL(MavenProject mavenProject) {
    String scmUrl = mavenProject.getScm().getDeveloperConnection();
    scmUrl = scmUrl.replace("scm:", "").replace("svn:", "");
    String tagUrl = scmUrl.split("trunk")[0];
    tagUrl += "tags/";
    if (AbstractCheckMojo.isSnapshot(mavenProject)) {
        tagUrl += "SNAPSHOT/" + mavenProject.getArtifactId() + "-" + mavenProject.getVersion();
    } else {
        tagUrl += mavenProject.getVersion() + scmUrl.split("trunk")[1];
    }
    return tagUrl;
}

From source file:org.universaal.tools.buildserviceapplication.actions.CreateLaunchConfigurationFile.java

License:Apache License

public MavenProject getSelectedMavenProject() {
    for (int i = 0; i < BuildAction.buildedProjects.size(); i++) {
        MavenProject project = BuildAction.buildedProjects.get(i);
        if (project.getArtifactId().equals(BuildAction.getSelectedProjectName())
                && project.getBasedir().toString().equals(BuildAction.getSelectedProjectPath())) {
            return project;
        }//from   w  w  w  . j a v  a2 s.  c  o  m
    }
    return null;
}