List of usage examples for org.apache.maven.project MavenProject getDistributionManagement
public DistributionManagement getDistributionManagement()
From source file:org.guvnor.m2repo.backend.server.repositories.DistributionManagementArtifactRepository.java
License:Apache License
private DistributionManagement getDistributionManagement(final String pomXML, final MavenEmbedder embedder) { final InputStream is = new ByteArrayInputStream(pomXML.getBytes(Charset.forName("UTF-8"))); MavenProject project = null; try {/*from w ww. jav a 2 s. co m*/ project = embedder.readProject(is); } catch (ProjectBuildingException e) { logger.error("Unable to build Maven project from POM", e); throw new RuntimeException(e); } catch (MavenEmbedderException e) { logger.error("Unable to build Maven project from POM", e); throw new RuntimeException(e); } finally { try { is.close(); } catch (IOException ioe) { //Swallow } } return project.getDistributionManagement(); }
From source file:org.objectstyle.woproject.maven2.javamonitor.JavaMonitorDeployMojo.java
License:Open Source License
/** * Generates the site structure using the project hiearchy (project and its * modules) or using the distributionManagement elements from the pom.xml. * * @param project/*w ww . j ava 2 s.c om*/ * @param ignoreMissingSiteUrl * @return the structure relative path * @throws MojoFailureException * if any */ protected static String getStructure(MavenProject project, boolean ignoreMissingSiteUrl) throws MojoFailureException { if (project.getDistributionManagement() == null) { String hierarchy = project.getArtifactId(); MavenProject parent = project.getParent(); while (parent != null) { hierarchy = parent.getArtifactId() + "/" + hierarchy; parent = parent.getParent(); } return hierarchy; } Site site = project.getDistributionManagement().getSite(); if (site == null) { if (!ignoreMissingSiteUrl) { throw new MojoFailureException( "Missing site information in the distribution management element in the project: '" + project.getName() + "'."); } return null; } if (StringUtils.isEmpty(site.getUrl())) { if (!ignoreMissingSiteUrl) { throw new MojoFailureException("The URL in the site is missing in the project descriptor."); } return null; } Repository repository = new Repository(site.getId(), site.getUrl()); StringBuffer hierarchy = new StringBuffer(1024); hierarchy.append(repository.getHost()); if (!StringUtils.isEmpty(repository.getBasedir())) { if (!repository.getBasedir().startsWith("/")) { hierarchy.append('/'); } hierarchy.append(repository.getBasedir()); } return hierarchy.toString().replaceAll("[\\:\\?\\*]", ""); }
From source file:org.ops4j.pax.construct.project.ImportBundleMojo.java
License:Apache License
/** * Resolve the Maven project for the given artifact, handling when a POM cannot be found in the repository * /* w w w. ja v a2 s . co m*/ * @param pomGroupId project group id * @param pomArtifactId project artifact id * @param pomVersion project version * @return resolved Maven project */ private MavenProject buildMavenProject(String pomGroupId, String pomArtifactId, String pomVersion) { Artifact pomArtifact = m_factory.createProjectArtifact(pomGroupId, pomArtifactId, pomVersion); MavenProject project; try { project = m_projectBuilder.buildFromRepository(pomArtifact, m_remoteRepos, m_localRepo); } catch (ProjectBuildingException e) { getLog().warn("Problem resolving project " + pomArtifact.getId()); return null; } /* * look to see if this is a local project (if so then set the POM location) */ Pom localPom = DirUtils.findPom(targetDirectory, pomGroupId + ':' + pomArtifactId); if (localPom != null) { project.setFile(localPom.getFile()); } /* * Repair stubs (ie. when a POM couldn't be found in the various repositories) */ DistributionManagement dm = project.getDistributionManagement(); if (dm != null && "generated".equals(dm.getStatus())) { if (localPom != null) { // local project, use values from the local POM project.setPackaging(localPom.getPackaging()); project.setName(localPom.getId()); } else { // remote project - assume it creates a jarfile (so we can test later for OSGi metadata) Artifact jar = m_factory.createBuildArtifact(pomGroupId, pomArtifactId, pomVersion, "jar"); project.setArtifact(jar); project.setPackaging("jar"); project.setName(jar.getId()); } } return project; }
From source file:org.sonatype.nexus.plugin.discovery.DefaultNexusDiscovery.java
License:Open Source License
private void collectForDiscovery(final Settings settings, final MavenProject project, final List<NexusConnectionInfo> candidates, final List<ServerMapping> serverMap, final Map<String, Server> serversById) throws NexusDiscoveryException { if (project != null && project.getDistributionManagement() != null && project.getArtifact() != null) { DistributionManagement distMgmt = project.getDistributionManagement(); DeploymentRepository repo = distMgmt.getRepository(); if (project.getArtifact().isSnapshot() && distMgmt.getSnapshotRepository() != null) { repo = distMgmt.getSnapshotRepository(); }//from ww w.ja v a 2s . co m if (repo != null) { String id = repo.getId(); String url = repo.getUrl(); addCandidate(id, url, repo.getName(), serversById, candidates, serverMap); } } if (settings != null && settings.getMirrors() != null) { for (Mirror mirror : settings.getMirrors()) { addCandidate(mirror.getId(), mirror.getUrl(), mirror.getName(), serversById, candidates, serverMap); } } if (project != null) { if (project.getModel().getRepositories() != null) { for (Repository repo : project.getModel().getRepositories()) { addCandidate(repo.getId(), repo.getUrl(), repo.getName(), serversById, candidates, serverMap); } } if (project.getModel().getProfiles() != null) { for (Profile profile : project.getModel().getProfiles()) { for (Repository repo : profile.getRepositories()) { addCandidate(repo.getId(), repo.getUrl(), repo.getName(), serversById, candidates, serverMap); } } } } if (settings != null && settings.getProfiles() != null) { for (org.apache.maven.settings.Profile profile : settings.getProfiles()) { if (profile != null && profile.getRepositories() != null) { for (org.apache.maven.settings.Repository repo : profile.getRepositories()) { addCandidate(repo.getId(), repo.getUrl(), repo.getName(), serversById, candidates, serverMap); } } } } }