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.sourcepit.b2.release.B2ReleaseHelper.java

License:Apache License

private String determineNewMavenVersion(ReleaseDescriptor releaseDescriptor, MavenProject mavenProject,
        boolean release) {
    @SuppressWarnings("unchecked")
    final Map<String, String> versionMap = release ? releaseDescriptor.getReleaseVersions()
            : releaseDescriptor.getDevelopmentVersions();
    String projectId = ArtifactUtils.versionlessKey(mavenProject.getGroupId(), mavenProject.getArtifactId());
    String mavenVersion = versionMap.get(projectId);
    if (mavenVersion == null) {
        final MavenProject moduleProject = determineModuleMavenProject(mavenProject);
        projectId = ArtifactUtils.versionlessKey(moduleProject.getGroupId(), moduleProject.getArtifactId());
        mavenVersion = versionMap.get(projectId);
    }/*from ww w.  ja  v a  2 s  .  co  m*/
    return mavenVersion;
}

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static String getProjectReferenceId(@NotNull MavenProject project) {
    return getProjectReferenceId(project.getGroupId(), project.getArtifactId(), project.getVersion());
}

From source file:org.sourcepit.common.maven.core.MavenProjectUtils.java

License:Apache License

public static org.sourcepit.common.maven.model.MavenProject toMavenProject(
        @NotNull org.apache.maven.project.MavenProject mavenProject) {
    final org.sourcepit.common.maven.model.MavenProject mProject = MavenModelFactory.eINSTANCE
            .createMavenProject();/*  w  ww .  ja v a2  s  . c  o  m*/
    mProject.setGroupId(mavenProject.getGroupId());
    mProject.setArtifactId(mavenProject.getArtifactId());
    mProject.setVersion(mavenProject.getVersion());
    if (mavenProject.getPackaging() != null
            && !ObjectUtils.equals(mProject.getPackaging(), mavenProject.getPackaging())) {
        mProject.setPackaging(mavenProject.getPackaging());
    }
    mProject.setPomFile(mavenProject.getFile());
    mProject.setOutputDirectory(MavenProjectUtils.getOutputDir(mavenProject));
    mProject.setTestOutputDirectory(MavenProjectUtils.getTestOutputDir(mavenProject));
    return mProject;
}

From source file:org.sourcepit.maven.bootstrap.core.AbstractBootstrapper.java

License:Apache License

private Map<String, MavenProject> getProjectMap(List<MavenProject> projects)
        throws org.apache.maven.DuplicateProjectException {
    Map<String, MavenProject> index = new LinkedHashMap<String, MavenProject>();
    Map<String, List<File>> collisions = new LinkedHashMap<String, List<File>>();

    for (MavenProject project : projects) {
        String projectId = ArtifactUtils.key(project.getGroupId(), project.getArtifactId(),
                project.getVersion());/*from   w w w .  j a  v  a2s  .c om*/

        MavenProject collision = index.get(projectId);

        if (collision == null) {
            index.put(projectId, project);
        } else {
            List<File> pomFiles = collisions.get(projectId);

            if (pomFiles == null) {
                pomFiles = new ArrayList<File>(Arrays.asList(collision.getFile(), project.getFile()));
                collisions.put(projectId, pomFiles);
            } else {
                pomFiles.add(project.getFile());
            }
        }
    }

    if (!collisions.isEmpty()) {
        throw new org.apache.maven.DuplicateProjectException("Two or more projects in the reactor"
                + " have the same identifier, please make sure that <groupId>:<artifactId>:<version>"
                + " is unique for each project: " + collisions, collisions);
    }

    return index;
}

From source file:org.sourcepit.tpmp.AbstractTargetPlatformMojo.java

License:Apache License

protected Artifact createPlatformArtifact(MavenProject project) {
    final Artifact platformArtifact = repositorySystem.createArtifactWithClassifier(project.getGroupId(),
            project.getArtifactId(), project.getVersion(), "zip", classifier);
    return platformArtifact;
}

From source file:org.sourcepit.tpmp.AbstractTargetPlatformMojo.java

License:Apache License

protected String getFinalName(MavenProject project) {
    String finalName = project.getBuild().getFinalName();
    if (finalName == null) {
        finalName = project.getArtifactId() + "-" + project.getVersion();
    }//w w  w  .ja v  a2 s  . c  o  m
    return finalName;
}

From source file:org.sourcepit.tpmp.change.tycho.TychoTargetPlatformConfigurationFilesDiscoverer.java

License:Apache License

@Override
public List<File> getTargetPlatformConfigurationFiles(MavenSession session, MavenProject project) {
    final List<File> files = new ArrayList<File>();
    files.add(project.getFile());//w  w  w . jav a 2s .  c o  m

    final TychoProject tychoProject = projectTypes.get(project.getPackaging());
    if (tychoProject != null) {
        if (tychoProject instanceof OsgiBundleProject) {
            files.add(new File(project.getBasedir(), "META-INF/MANIFEST.MF"));
        } else if (tychoProject instanceof EclipseApplicationProject) {
            files.add(new File(project.getBasedir(), project.getArtifactId() + ".product"));
        } else if (tychoProject instanceof EclipseFeatureProject) {
            files.add(new File(project.getBasedir(), Feature.FEATURE_XML));
        } else if (tychoProject instanceof EclipseRepositoryProject) {
            files.addAll(/* ((EclipseRepositoryProject) tychoProject). */getCategoryFiles(project));
            files.addAll(((EclipseRepositoryProject) tychoProject).getProductFiles(project));
        } else if (tychoProject instanceof UpdateSiteProject) {
            files.add(new File(project.getBasedir(), UpdateSite.SITE_XML));
        }
    }

    return files;
}

From source file:org.spdx.maven.stubs.MavenProjectHelperStub.java

License:Apache License

@Override
public void attachArtifact(MavenProject project, String artifactType, File file) {
    String outputFileName = project.getArtifactId() + "." + artifactType;
    File outputFile = new File(getBaseDir(), outputFileName);
    if (outputFile.exists()) {
        outputFile.delete();//from w  ww .j  a va 2 s  .  c  o  m
    }
    try {
        Files.copy(file, outputFile);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.springframework.ide.eclipse.maven.legacy.internal.core.GoogleProjectConfigurator.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w  w  . j  a v  a2 s.  com
 */
@Override
protected void doConfigure(final MavenProject mavenProject, IProject project,
        ProjectConfigurationRequest request, final IProgressMonitor monitor) throws CoreException {

    final IMaven maven = MavenPlugin.getDefault().getMaven();

    configureNature(project, mavenProject, GAE_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {
            try {
                DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest();
                executionRequest.setBaseDirectory(mavenProject.getBasedir());
                executionRequest.setLocalRepository(maven.getLocalRepository());
                executionRequest.setRemoteRepositories(mavenProject.getRemoteArtifactRepositories());
                executionRequest.setPluginArtifactRepositories(mavenProject.getPluginArtifactRepositories());
                executionRequest.setPom(mavenProject.getFile());
                executionRequest.setGoals(GAE_UNPACK_GOAL);

                MavenExecutionResult result = maven.execute(executionRequest, monitor);
                if (result.hasExceptions()) {
                    MavenCorePlugin.getDefault().getLog()
                            .log(new Status(IStatus.ERROR, MavenCorePlugin.NON_LEGACY_PLUGIN_ID,
                                    "Error configuring project", result.getExceptions().get(0)));
                }
            } catch (CoreException e) {
                MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                        MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
            }
        }
    }, monitor);

    if (configureNature(project, mavenProject, GWT_NATURE_ID, true, new NatureCallbackAdapter() {

        @Override
        public void beforeAddingNature() {

            // Get the GWT version from the project pom
            String gwtVersion = null;
            List<Dependency> dependencies = mavenProject.getDependencies();
            for (Dependency dependency : dependencies) {
                if (GWT_GROUP_ID.equals(dependency.getGroupId())
                        && ("gwt-user".equals(dependency.getArtifactId())
                                || "gwt-servlet".equals(dependency.getArtifactId()))) {
                    gwtVersion = dependency.getVersion();
                    break;
                }
            }

            // Check that the pom.xml has GWT dependencies
            if (StringUtils.hasLength(gwtVersion)) {
                try {
                    // Download and install the gwt-dev.jar into the local repository
                    maven.resolve(GWT_GROUP_ID, "gwt-dev", gwtVersion, "jar", null,
                            mavenProject.getRemoteArtifactRepositories(), monitor);
                } catch (CoreException e) {
                    MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                            MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
                }
            }
        }
    }, monitor)) {

        try {
            // Add GWT Web Application configuration parameters
            IEclipsePreferences prefs = SpringCorePreferences
                    .getProjectPreferences(project, "com.google.gdt.eclipse.core").getProjectPreferences();
            prefs.put("warSrcDir", "src/main/webapp");
            prefs.putBoolean("warSrcDirIsOutput", false);

            String artifactId = mavenProject.getArtifactId();
            String version = mavenProject.getVersion();
            IPath location = SpringCoreUtils.getProjectLocation(project);
            if (location != null && artifactId != null && version != null) {
                prefs.put("lastWarOutDir", location.append("target").append(artifactId + "-" + version).toFile()
                        .getAbsolutePath());
            }

            prefs.flush();
        } catch (BackingStoreException e) {
            MavenCorePlugin.getDefault().getLog().log(new Status(IStatus.ERROR,
                    MavenCorePlugin.NON_LEGACY_PLUGIN_ID, "Error configuring project", e));
        }
    }
}

From source file:org.srcdeps.mvn.enforcer.SrcdepsEnforcer.java

License:Apache License

@Override
public void beforeProjectLifecycleExecution(ProjectExecutionEvent event) throws LifecycleExecutionException {
    final MavenProject project = event.getProject();
    log.info("srcdeps enforcer checks for violations in {}:{}", project.getGroupId(), project.getArtifactId());

    final Maven maven = configurationProducer.getConfiguration().getMaven();

    final List<MojoExecution> mojoExecutions = event.getExecutionPlan();
    final List<String> goals = new ArrayList<>(mojoExecutions.size());
    for (MojoExecution mojoExecution : mojoExecutions) {
        MojoDescriptor mojoDescriptor = mojoExecution.getMojoDescriptor();
        goals.add(mojoDescriptor.getFullGoalName());
        goals.add(mojoDescriptor.getGoal());
    }/*from  ww  w . j av  a 2s . co  m*/

    final List<String> profiles = new ArrayList<>();
    final List<Profile> activeProfiles = project.getActiveProfiles();
    for (Profile profile : activeProfiles) {
        final String id = profile.getId();
        profiles.add(id);
    }

    final Properties props = new Properties();
    props.putAll(project.getProperties());
    props.putAll(System.getProperties());

    String[] firstViolation = assertFailWithout(maven.getFailWithout(), goals, profiles, props);
    if (firstViolation == null) {
        firstViolation = assertFailWith(maven.getFailWith(), goals, profiles, props);
    }
    if (firstViolation != null) {
        /* check if there are srcdeps */
        Artifact parent = project.getParentArtifact();
        if (parent != null) {
            assertNotSrcdeps(parent.getGroupId(), parent.getArtifactId(), parent.getVersion(), firstViolation);
        }
        DependencyManagement dm;
        List<Dependency> deps;
        if ((dm = project.getDependencyManagement()) != null && (deps = dm.getDependencies()) != null) {
            assertNotSrcdeps(deps, firstViolation);
        }
        if ((deps = project.getDependencies()) != null) {
            assertNotSrcdeps(deps, firstViolation);
        }
    }
}