List of usage examples for org.apache.maven.project MavenProject getScm
public Scm getScm()
From source file:net.java.jpatch.maven.ReleaseMojo.java
License:Apache License
/** * Gets the SCM status from the repository. * /*from w ww. j av a 2 s . c o m*/ * @param project the MAVEN project. * * @return the SCM status. * * @throws MojoExecutionException if the method fails. * * TODO: rewrite this method. Exception handling. */ private String scmRevision(MavenProject project) throws MojoExecutionException { String result = null; try { ScmRepository repository = scmManager.makeScmRepository(project.getScm().getConnection()); ChangeLogScmResult scmResult = scmManager.changeLog(repository, new ScmFileSet(project.getBasedir()), null, null, null); if (scmResult != null) { ChangeLogSet log = scmResult.getChangeLog(); if (log != null) { if (log.getChangeSets() != null) { List<ChangeSet> changes = log.getChangeSets(); if (!changes.isEmpty()) { ChangeSet change = changes.get(0); if (!change.getFiles().isEmpty()) { List<ChangeFile> files = change.getFiles(); ChangeFile file = files.get(0); result = file.getRevision(); } else { throw new MojoExecutionException("No revision found! Project: " + project.getId()); } } else { throw new MojoExecutionException( "Missing changes in the repository! Project: " + project.getId()); } } } else { throw new MojoExecutionException("Missing the SCM log! Project: " + project.getId()); } } else { throw new MojoExecutionException("Missing the SCM result! Project: " + project.getId()); } } catch (Exception e) { getLog().error("Error check SCM status for project " + project.getId()); throw new MojoExecutionException("Couldn't configure SCM repository: " + e.getLocalizedMessage(), e); } return result; }
From source file:net.oneandone.maven.plugins.prerelease.core.Descriptor.java
License:Apache License
public static String getSvnUrl(MavenProject project) throws MissingScmTag, MissingDeveloperConnection { Scm scm;/* ww w . java2 s. c om*/ String result; scm = project.getScm(); if (scm == null) { throw new MissingScmTag(); } result = scm.getDeveloperConnection(); if (result == null) { throw new MissingDeveloperConnection(); } return Strings.removeRightOpt(Strings.removeLeft(result, "scm:svn:"), "/"); }
From source file:org.apache.felix.obr.plugin.ResourcesBundle.java
License:Apache License
/** * this method gets information form pom.xml to complete missing data from those given by user. * @param project project information given by maven * @param ebi bundle information extracted from bindex * @return true//from w w w . j a v a 2 s. co m */ public boolean construct(MavenProject project, ExtractBindexInfo ebi) { if (ebi.getPresentationName() != null) { setPresentationName(ebi.getPresentationName()); if (project.getName() != null) { m_logger.debug("pom property override:<presentationname> " + project.getName()); } } else { setPresentationName(project.getName()); } if (ebi.getSymbolicName() != null) { setSymbolicName(ebi.getSymbolicName()); if (project.getArtifactId() != null) { m_logger.debug("pom property override:<symbolicname> " + project.getArtifactId()); } } else { setSymbolicName(project.getArtifactId()); } if (ebi.getVersion() != null) { setVersion(ebi.getVersion()); if (project.getVersion() != null) { m_logger.debug("pom property override:<version> " + project.getVersion()); } } else { setVersion(project.getVersion()); } if (ebi.getId() != null) { setId(ebi.getId()); } if (ebi.getDescription() != null) { setDescription(ebi.getDescription()); if (project.getDescription() != null) { m_logger.debug("pom property override:<description> " + project.getDescription()); } } else { setDescription(project.getDescription()); } if (ebi.getDocumentation() != null) { setDocumentation(ebi.getDocumentation()); if (project.getUrl() != null) { m_logger.debug("pom property override:<documentation> " + project.getUrl()); } } else { setDocumentation(project.getUrl()); } if (ebi.getSource() != null) { setSource(ebi.getSource()); if (project.getScm() != null) { m_logger.debug("pom property override:<source> " + project.getScm()); } } else { String src = null; if (project.getScm() != null) { src = project.getScm().getUrl(); } setSource(src); } if (ebi.getLicense() != null) { setLicense(ebi.getLicense()); String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { if (it.next() != null) { m_logger.debug("pom property override:<license> " + lic); break; } } } else { String lic = null; List l = project.getLicenses(); Iterator it = l.iterator(); while (it.hasNext()) { lic = it.next() + ";"; } setLicense(lic); } // create the first capability (ie : bundle) Capability capability = new Capability(); capability.setName("bundle"); PElement p = new PElement(); p.setN("manifestversion"); p.setV("2"); capability.addP(p); p = new PElement(); p.setN("presentationname"); p.setV(getPresentationName()); capability.addP(p); p = new PElement(); p.setN("symbolicname"); p.setV(getSymbolicName()); capability.addP(p); p = new PElement(); p.setN("version"); p.setT("version"); p.setV(getVersion()); capability.addP(p); addCapability(capability); List capabilities = ebi.getCapabilities(); for (int i = 0; i < capabilities.size(); i++) { addCapability((Capability) capabilities.get(i)); } List requirement = ebi.getRequirement(); for (int i = 0; i < requirement.size(); i++) { addRequire((Require) requirement.get(i)); } // we also add the goupId Category category = new Category(); category.setId(project.getGroupId()); addCategory(category); return true; }
From source file:org.codehaus.continuum.builder.maven.m2.DefaultMavenBuilderHelper.java
License:Apache License
public String getScmUrl(MavenProject project) { return project.getScm().getConnection(); }
From source file:org.codehaus.continuum.builder.maven.m2.DefaultMavenBuilderHelper.java
License:Apache License
protected MavenProject getProject(File file) throws ContinuumException { MavenProject project = null; try {// w w w.j av a2 s . c o m project = projectBuilder.build(file, getRepository()); } catch (ProjectBuildingException e) { throw new ContinuumException("Cannot build maven project from " + file, e); } // ---------------------------------------------------------------------- // Validate the MavenProject using some Continuum rules // ---------------------------------------------------------------------- // Nag email address CiManagement ciManagement = project.getCiManagement(); if (ciManagement == null) { throw new ContinuumException("Missing CiManagement from the project descriptor."); } if (StringUtils.isEmpty(getNagEmailAddress(project))) { throw new ContinuumException("Missing nag email address from the continuous integration info."); } // SCM connection Scm scm = project.getScm(); if (scm == null) { throw new ContinuumException("Missing Scm from the project descriptor."); } String url = scm.getConnection(); if (StringUtils.isEmpty(url)) { throw new ContinuumException("Missing anonymous scm connection url."); } // Version if (StringUtils.isEmpty(project.getVersion())) { throw new ContinuumException("Missing version from the project descriptor."); } return project; }
From source file:org.codehaus.continuum.builder.maven2.Maven2ContinuumBuilder.java
License:Open Source License
public ContinuumProject createProject(File workingDirectory) throws ContinuumException { Maven2ProjectDescriptor descriptor = new Maven2ProjectDescriptor(); // try // {// w w w . ja v a 2s . co m // scm.checkOutProject( project ); // } // catch( ContinuumScmException ex ) // { // throw new ContinuumException( "Error while checking out the project.", ex ); // } MavenProject mavenProject; File pomFile = getPomFile(workingDirectory); mavenProject = mavenTool.getProject(pomFile); List goals = new LinkedList(); goals.add("pom:install"); mavenTool.execute(mavenProject, goals); // ---------------------------------------------------------------------- // Populating the descriptor // ---------------------------------------------------------------------- if (mavenProject.getScm() == null) { throw new ContinuumException("The project descriptor is missing the SCM section."); } if (mavenProject.getCiManagement() == null) { throw new ContinuumException("The project descriptor is missing the CI section."); } Build build = mavenProject.getBuild(); boolean isPom = true; if (build != null) { String sourceDirectory = build.getSourceDirectory(); if (sourceDirectory != null && sourceDirectory.trim().length() > 0) { if (new File(sourceDirectory).isDirectory()) { isPom = false; } } } if (isPom) { descriptor.getGoals().add("pom:install"); } else { descriptor.getGoals().add("clean:clean"); descriptor.getGoals().add("jar:install"); } // descriptor.setName( mavenProject.getName() ); // The public Url takes priority over the developer connection Scm scm = mavenProject.getScm(); String scmUrl = scm.getConnection(); if (StringUtils.isEmpty(scmUrl)) { scmUrl = scm.getDeveloperConnection(); } if (StringUtils.isEmpty(scmUrl)) { throw new ContinuumException("Missing both anonymous and developer scm connection urls."); } // descriptor.setScmUrl( scmUrl ); CiManagement ciManagement = mavenProject.getCiManagement(); String nagEmailAddress = ciManagement.getNagEmailAddress(); if (StringUtils.isEmpty(nagEmailAddress)) { throw new ContinuumException( "Missing nag email address from the ci section of the project descriptor."); } // descriptor.setNagEmailAddress( nagEmailAddress ); String version = mavenProject.getVersion(); if (StringUtils.isEmpty(version)) { throw new ContinuumException("Missing version from the project descriptor."); } // descriptor.setVersion( version ); // ---------------------------------------------------------------------- // Make the project // ---------------------------------------------------------------------- ContinuumProject project = new GenericContinuumProject(); if (StringUtils.isEmpty(mavenProject.getName())) { throw new ContinuumException("The project name cannot be empty."); } project.setName(mavenProject.getName()); project.setScmUrl(scmUrl); project.setNagEmailAddress(nagEmailAddress); project.setVersion(version); project.setDescriptor(descriptor); return project; }
From source file:org.codehaus.continuum.maven.DefaultMavenTool.java
License:Open Source License
public MavenProject getProject(File file) throws ContinuumException { MavenProject project; try {//w w w .ja va 2 s .c o m project = maven.getProject(file); } catch (ProjectBuildingException ex) { throw new ContinuumException("Error while building project.", ex); } // ---------------------------------------------------------------------- // Validate the MavenProject after some Continuum rules // ---------------------------------------------------------------------- // Nag email address CiManagement ciManagement = project.getCiManagement(); if (ciManagement == null) { throw new ContinuumException("Missing CiManagement from the project descriptor."); } if (StringUtils.isEmpty(ciManagement.getNagEmailAddress())) { throw new ContinuumException("Missing nag email address from the continuous integration info."); } // SCM connection Scm scm = project.getScm(); if (scm == null) { throw new ContinuumException("Missing Scm from the project descriptor."); } String url = scm.getConnection(); if (StringUtils.isEmpty(url)) { throw new ContinuumException("Missing anonymous scm connection url."); } // Version if (StringUtils.isEmpty(project.getVersion())) { throw new ContinuumException("Missing version from the project descriptor."); } return project; }
From source file:org.codehaus.mojo.cruisecontrol.CruiseControlModificationSetConfigurer.java
License:Apache License
public static void addModificationSet(XMLWriter writer, MavenProject reactorProject) { writer.startElement("modificationset"); {//from w w w.j ava 2s . c o m String scmUrl = reactorProject.getScm().getConnection(); if (scmUrl.contains((String) scmPrefixes.get("svn"))) { addSvnModificationSet(writer, getRativeScmUrl(scmUrl, (String) scmPrefixes.get("svn"))); } } writer.endElement(); }
From source file:org.debian.dependency.sources.SCMSourceRetrieval.java
License:Apache License
@Override public String getSourceLocation(final Artifact artifact, final MavenSession session) throws SourceRetrievalException { MavenProject project = findProjectRoot(constructProject(artifact, session)); Scm scm = project.getScm(); if (scm == null) { return null; }// ww w . j ava 2 s . c o m if (!StringUtils.isEmpty(scm.getConnection())) { return scm.getConnection(); } return scm.getDeveloperConnection(); }
From source file:org.debian.dependency.sources.SCMSourceRetrieval.java
License:Apache License
private MavenProject findProjectRoot(final MavenProject project) { // if this project doesn't have one, then its parents won't have one either if (project.getScm() == null) { return project; }/*from w ww. j a v a 2 s . c o m*/ for (MavenProject parent = project; parent != null; parent = parent.getParent()) { if (parent.getOriginalModel().getScm() != null) { return parent; } } return project; }