org.apache.maven.model.Scm Java Examples

The following examples show how to use org.apache.maven.model.Scm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SCMManifestCustomizer.java    From vertx-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> getEntries(AbstractVertxMojo mojo, MavenProject project) {
    Map<String, String> attributes = new HashMap<>();

    Scm scm = project.getScm();
    // TODO this should be in the archive.
    if (mojo.skipScmMetadata() || scm == null) {
        return attributes;
    }

    String connectionUrl = addAttributesFromProject(attributes, scm);

    if (mojo.getScmManager() != null && connectionUrl != null) {
        try {
            addAttributeFromScmManager(mojo, attributes, connectionUrl, project.getBasedir());
        } catch (Exception e) {
            mojo.getLog().warn("Error while getting SCM Metadata `" + e.getMessage() + "`");
            mojo.getLog().warn("SCM metadata ignored");
            mojo.getLog().debug(e);
        }
    }
    return attributes;
}
 
Example #2
Source File: LocationAwareMavenXpp3Writer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void writeScm(Scm scm, String tagName, XmlSerializer serializer)
        throws java.io.IOException {
    serializer.startTag(NAMESPACE, tagName);
    flush(serializer);
    StringBuffer b = b(serializer);
    int start = b.length();
    if (scm.getConnection() != null) {
        writeValue(serializer, "connection", scm.getConnection(), scm);
    }
    if (scm.getDeveloperConnection() != null) {
        writeValue(serializer, "developerConnection", scm.getDeveloperConnection(), scm);
    }
    if ((scm.getTag() != null) && !scm.getTag().equals("HEAD")) {
        writeValue(serializer, "tag", scm.getTag(), scm);
    }
    if (scm.getUrl() != null) {
        writeValue(serializer, "url", scm.getUrl(), scm);
    }
    serializer.endTag(NAMESPACE, tagName).flush();
    logLocation(scm, "", start, b.length());
}
 
Example #3
Source File: MkdocsGitHubPagesDeployMojo.java    From siddhi with Apache License 2.0 6 votes vote down vote up
private void deployDocumentation(MavenProject rootMavenProject, String docGenBasePath) {
    // Creating the credential provider fot Git
    String scmUsername = System.getenv(Constants.SYSTEM_PROPERTY_SCM_USERNAME_KEY);
    String scmPassword = System.getenv(Constants.SYSTEM_PROPERTY_SCM_PASSWORD_KEY);

    if (scmUsername == null && scmPassword == null) {
        getLog().info("SCM_USERNAME and SCM_PASSWORD not defined!");
    }
    String url = null;
    Scm scm = rootMavenProject.getScm();
    if (scm != null) {
        url = scm.getUrl();
    }
    // Deploying documentation
    DocumentationUtils.updateDocumentationOnGitHub(docGenBasePath, mkdocsConfigFile, readmeFile,
            mavenProject.getVersion(), getLog());
    DocumentationUtils.deployMkdocsOnGitHubPages(mavenProject.getVersion(),
            rootMavenProject.getBasedir(), url, scmUsername, scmPassword, getLog());
}
 
Example #4
Source File: SetScmTagMojo.java    From versions-maven-plugin with Apache License 2.0 6 votes vote down vote up
@Override
protected void update(ModifiedPomXMLEventReader pom) throws MojoExecutionException, MojoFailureException, XMLStreamException, ArtifactMetadataRetrievalException
{
    try
    {
        Model model = PomHelper.getRawModel( pom );
        Scm scm = model.getScm();
        if (scm == null)
        {
            throw new MojoFailureException( "No <scm> was present" );
        }
        getLog().info( "Updating from tag " + scm.getTag() + " > " + newTag );

        boolean success = PomHelper.setProjectValue(pom, "/project/scm/tag", newTag );
        if ( !success )
        {
            throw new MojoFailureException( "Could not update the SCM tag" );
        }
    }
    catch ( IOException e )
    {
        throw new MojoExecutionException( e.getMessage(), e );
    }
}
 
Example #5
Source File: MavenScmUtilTest.java    From unleash-maven-plugin with Eclipse Public License 1.0 6 votes vote down vote up
@Test
@UseDataProvider("calcProviderName")
public void testCalcProviderName(String devConnection, String connection, String expectedProviderName) {
  MavenProject p = new MavenProject();
  p.setScm(new Scm());
  p.getScm().setDeveloperConnection(devConnection);
  p.getScm().setConnection(connection);

  Optional<String> providerName = MavenScmUtil.calcProviderName(p);
  if (expectedProviderName == null) {
    Assert.assertFalse(providerName.isPresent());
  } else {
    Assert.assertTrue(providerName.isPresent());
    Assert.assertEquals(expectedProviderName, providerName.get());
  }
}
 
Example #6
Source File: BaseMojo.java    From multi-module-maven-release-plugin with MIT License 6 votes vote down vote up
protected static String getRemoteUrlOrNullIfNoneSet(Scm originalScm, Scm actualScm) throws ValidationException {
    if (originalScm == null) {
        // No scm was specified, so don't inherit from any parent poms as they are probably used in different git repos
        return null;
    }

    // There is an SCM specified, so the actual SCM with derived values is used in case (so that variables etc are interpolated)
    String remote = actualScm.getDeveloperConnection();
    if (remote == null) {
        remote = actualScm.getConnection();
    }
    if (remote == null) {
        return null;
    }
    return GitHelper.scmUrlToRemote(remote);
}
 
Example #7
Source File: Maven2RepositoryStorage.java    From archiva with Apache License 2.0 5 votes vote down vote up
private org.apache.archiva.metadata.model.Scm convertScm(Scm scm) {
    org.apache.archiva.metadata.model.Scm newScm = null;
    if (scm != null) {
        newScm = new org.apache.archiva.metadata.model.Scm();
        newScm.setConnection(scm.getConnection());
        newScm.setDeveloperConnection(scm.getDeveloperConnection());
        newScm.setUrl(scm.getUrl());
    }
    return newScm;
}
 
Example #8
Source File: SCMManifestCustomizer.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private static String addAttributesFromProject(Map<String, String> attributes, Scm scm) {
    String connectionUrl = scm.getConnection() == null ? scm.getDeveloperConnection() : scm.getConnection();
    if (scm.getUrl() != null) {
        attributes.put(ExtraManifestKeys.SCM_URL.header(), scm.getUrl());
    }

    if (scm.getTag() != null) {
        attributes.put(ExtraManifestKeys.SCM_TAG.header(), scm.getTag());
    }
    return connectionUrl;
}
 
Example #9
Source File: SCMManifestCustomizerTest.java    From vertx-maven-plugin with Apache License 2.0 5 votes vote down vote up
private MavenProject createProjectWithScm() {
    MavenProject project = createProject();
    Scm scm = new Scm();
    scm.setUrl("https://github.com/openshiftio");
    scm.setConnection("scm:git:https://github.com/openshiftio/booster-parent.git");
    scm.setDeveloperConnection("scm:git:git:@github.com:openshiftio/booster-parent.git");
    scm.setTag("HEAD");
    project.setScm(scm);
    return project;
}
 
Example #10
Source File: CheckoutAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Scm getScm() {
    Iterator<? extends MavenProject> prj = result.allInstances().iterator();
    if (!prj.hasNext()) {
        return null;
    }
    MavenProject project = prj.next();
    return project.getScm();
}
 
Example #11
Source File: AbstractDevOpsCommand.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected String getOrFindGitUrl(UIExecutionContext context, String gitUrlText) {
    if (Strings.isNullOrBlank(gitUrlText)) {
        final Project project = getSelectedProject(context);
        if (project != null) {
            Resource<?> root = project.getRoot();
            if (root != null) {
                try {
                    Resource<?> gitFolder = root.getChild(".git");
                    if (gitFolder != null) {
                        Resource<?> config = gitFolder.getChild("config");
                        if (config != null) {
                            String configText = config.getContents();
                            gitUrlText = GitHelpers.extractGitUrl(configText);
                        }
                    }
                } catch (Exception e) {
                    log.debug("Ignoring missing git folders: " + e, e);
                }
            }
        }
    }
    if (Strings.isNullOrBlank(gitUrlText)) {
        Model mavenModel = getMavenModel(context);
        if (mavenModel != null) {
            Scm scm = mavenModel.getScm();
            if (scm != null) {
                String connection = scm.getConnection();
                if (Strings.isNotBlank(connection)) {
                    gitUrlText = connection;
                }
            }
        }
    }
    if (Strings.isNullOrBlank(gitUrlText)) {
        throw new IllegalArgumentException("Could not find git URL");
    }
    return gitUrlText;
}
 
Example #12
Source File: HelmMojo.java    From jkube with Eclipse Public License 2.0 5 votes vote down vote up
private static List<String> sourcesFromProject(MavenProject mavenProject) {
  return Optional.ofNullable(mavenProject)
      .map(MavenProject::getScm)
      .map(Scm::getUrl)
      .map(Collections::singletonList)
      .orElse(Collections.emptyList());
}
 
Example #13
Source File: DevVersionUtil.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
public void revertScmSettings(MavenProject projectToRevert, Document document) {
  Scm scm = this.metadata.getCachedScmSettings(projectToRevert);
  if (scm != null) {
    this.log.debug("\t\tReversion of SCM connection tags");
    Document originalPOM = this.metadata.getCachedOriginalPOM(projectToRevert);

    Node scmNode = PomUtil.getOrCreateScmNode(document, false);
    Node originalScmNode = PomUtil.getOrCreateScmNode(originalPOM, false);

    if (scmNode != null) {
      Optional<String> connection = PomUtil.getChildNodeTextContent(originalScmNode,
          PomUtil.NODE_NAME_SCM_CONNECTION);
      if (connection.isPresent()) {
        PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION, connection.get(), false);
      }

      Optional<String> devConnection = PomUtil.getChildNodeTextContent(originalScmNode,
          PomUtil.NODE_NAME_SCM_DEV_CONNECTION);
      if (devConnection.isPresent()) {
        PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION, devConnection.get(), false);
      }

      Optional<String> url = PomUtil.getChildNodeTextContent(originalScmNode, PomUtil.NODE_NAME_SCM_URL);
      if (url.isPresent()) {
        PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL, url.get(), false);
      }

      if (scm.getTag() != null) {
        PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_TAG, scm.getTag(), false);
      } else {
        PomUtil.deleteNode(scmNode, PomUtil.NODE_NAME_SCM_TAG);
      }
    }
  }
}
 
Example #14
Source File: MavenScmUtil.java    From unleash-maven-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Derives the name of the required SCM provider from the given Maven project by analyzing the scm connection strings
 * of the project.
 * 
 * @param project the project from which the SCM provider is retrieved.
 * @return the name of the required SCM provider.
 */
public static Optional<String> calcProviderName(MavenProject project) {
  String providerName = null;

  Scm scm = project.getScm();
  if (scm != null) {
    // takes the developer connection first or the connection url if devConnection is empty or null
    String connection = StringUtils.trimToNull(scm.getDeveloperConnection());
    connection = connection != null ? connection : StringUtils.trimToNull(scm.getConnection());

    // scm url format description: https://maven.apache.org/scm/scm-url-format.html
    if (connection != null) {
      // cuts the substring "scm:" at the beginning
      connection = connection.substring(4);

      // as stated in the scm url format description, the provider delimiter may be a colon (:) or a pipe (|) if
      // colons are used otherwise (e.g. for windows paths)

      // svn:http://... -> svn:http://...
      // svn|http://... -> svn
      // svn:http://xyz|... -> svn:http://xyz
      int nextPipe = connection.indexOf('|');
      if (nextPipe > -1) {
        connection = connection.substring(0, nextPipe);
      }

      // svn -> svn
      // svn:http... -> svn
      int nextColon = connection.indexOf(':');
      if (nextColon > -1) {
        providerName = connection.substring(0, nextColon);
      } else {
        providerName = connection;
      }
    }
  }

  return Optional.fromNullable(providerName);
}
 
Example #15
Source File: TagScm.java    From unleash-maven-plugin with Eclipse Public License 1.0 4 votes vote down vote up
private void updateScmConnections(String scmTagName) throws MojoFailureException {
  for (MavenProject p : this.reactorProjects) {
    Scm scm = p.getModel().getScm();
    if (scm != null) {
      this.log.debug("\tUpdating SCM connection tags in POM of module '" + ProjectToString.INSTANCE.apply(p) + "'");

      Optional<Document> parsedPOM = PomUtil.parsePOM(p);
      if (parsedPOM.isPresent()) {
        this.cachedPOMs.put(ProjectToCoordinates.EMPTY_VERSION.apply(p), parsedPOM.get());

        try {
          // parse again to not modify the cached object
          Document document = PomUtil.parsePOM(p).get();
          Node scmNode = PomUtil.getOrCreateScmNode(document, false);

          if (scmNode != null) {
            Optional<String> connection = PomUtil.getChildNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION);
            if (connection.isPresent()) {
              PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_CONNECTION,
                  this.scmProvider.calculateTagConnectionString(connection.get(), scmTagName), false);
            }

            Optional<String> devConnection = PomUtil.getChildNodeTextContent(scmNode,
                PomUtil.NODE_NAME_SCM_DEV_CONNECTION);
            if (devConnection.isPresent()) {
              PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_DEV_CONNECTION,
                  this.scmProvider.calculateTagConnectionString(devConnection.get(), scmTagName), false);
            }

            Optional<String> url = PomUtil.getChildNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL);
            if (url.isPresent()) {
              PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_URL,
                  this.scmProvider.calculateTagConnectionString(url.get(), scmTagName), false);
            }

            if (!this.scmProvider.isTagInfoIncludedInConnection()) {
              PomUtil.setNodeTextContent(scmNode, PomUtil.NODE_NAME_SCM_TAG, scmTagName, true);
            }
            PomUtil.writePOM(document, p);
          }
        } catch (Throwable t) {
          throw new MojoFailureException("Could not update scm information for release.", t);
        }
      }
    }
  }
}
 
Example #16
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void set( Model model, Scm value )
{
    model.setScm( value );
}
 
Example #17
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Scm get( Model model )
{
    return model.getScm();
}
 
Example #18
Source File: ScmRenderer.java    From maven-confluence-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void renderBody() {
    Scm scm = model.getScm();
    if (scm == null || StringUtils.isEmpty(anonymousConnection)
            && StringUtils.isEmpty(devConnection)
            && StringUtils.isEmpty(scm.getUrl())) {
        startSection(getTitle());

        paragraph(getI18nString("noscm"));

        endSection();

        return;
    }
    
    // fix issue #141
    startSection( "Source Control Management");

    ScmRepository anonymousRepository = getScmRepository(anonymousConnection);
    ScmRepository devRepository = getScmRepository(devConnection);

    // Overview section
    renderOverviewSection(anonymousRepository, devRepository);

    // Web access section
    renderWebAccessSection(webAccessUrl);

    // Anonymous access section if needed
    renderAnonymousAccessSection(anonymousRepository);

    // Developer access section
    renderDeveloperAccessSection(devRepository);

    // Access from behind a firewall section if needed
    renderAccessBehindFirewallSection(devRepository);

    // Access through a proxy section if needed
    renderAccessThroughProxySection(anonymousRepository, devRepository);
    
    endSection();
}
 
Example #19
Source File: ReleaseMetadata.java    From unleash-maven-plugin with Eclipse Public License 1.0 4 votes vote down vote up
public Scm getCachedScmSettings(MavenProject p) {
  return this.cachedScmSettings.get(ProjectToCoordinates.EMPTY_VERSION.apply(p));
}
 
Example #20
Source File: SCMManifestCustomizer.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Map<String, String> getEntries(PackageMojo mojo, MavenProject project) {
    Map<String, String> attributes = new HashMap<>();

    if (mojo.isSkipScmMetadata()) {
        return attributes;
    }

    //Add SCM Metadata only when <scm> is configured in the pom.xml
    if (project.getScm() != null) {
        Scm scm = project.getScm();
        String connectionUrl = scm.getConnection() == null ? scm.getDeveloperConnection() : scm.getConnection();

        if (scm.getUrl() != null) {
            attributes.put("Scm-Url", scm.getUrl());
        }

        if (scm.getTag() != null) {
            attributes.put("Scm-Tag", scm.getTag());
        }
        if (mojo.getScmManager() != null && connectionUrl != null) {
            try {
                //SCM metadata
                File baseDir = project.getBasedir();
                ScmSpy scmSpy = new ScmSpy(mojo.getScmManager());

                Map<String, String> scmChangeLogMap = scmSpy.getChangeLog(connectionUrl, baseDir);

                if (!scmChangeLogMap.isEmpty()) {
                    attributes.put("Scm-Type",
                        scmChangeLogMap.get(ExtraManifestKeys.scmType.name()));
                    attributes.put("Scm-Revision",
                        scmChangeLogMap.get(ExtraManifestKeys.scmRevision.name()));
                    attributes.put("Last-Commit-Timestamp",
                        scmChangeLogMap.get(ExtraManifestKeys.lastCommitTimestamp.name()));
                    attributes.put("Author",
                        scmChangeLogMap.get(ExtraManifestKeys.author.name()));
                }

            } catch (Exception e) {
                mojo.getLog().warn("Error while getting SCM Metadata `" + e.getMessage() + "`");
                mojo.getLog().warn("SCM metadata ignored");
                mojo.getLog().debug(e);
            }
        }
    }
    return attributes;
}
 
Example #21
Source File: HelmMojoTest.java    From jkube with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void executeInternalWithNoConfigShouldInitConfigWithDefaultValuesAndGenerate(
    @Mocked Scm scm, @Mocked Developer developer) throws Exception {

  // Given
  assertThat(helmMojo.helm, nullValue());
  new Expectations() {{
    mavenProject.getProperties();
    result = new Properties();
    mavenProject.getBuild().getOutputDirectory();
    result = "target/classes";
    mavenProject.getBuild().getDirectory();
    result = "target";
    mavenProject.getArtifactId();
    result = "artifact-id";
    mavenProject.getVersion();
    result = "1337";
    mavenProject.getDescription();
    result = "A description from Maven";
    mavenProject.getUrl();
    result = "https://project.url";
    mavenProject.getScm();
    result = scm;
    scm.getUrl();
    result = "https://scm.url";
    mavenProject.getDevelopers();
    result = Arrays.asList(developer, developer);
    developer.getName();
    result = "John"; result = "John"; result = null;
    developer.getEmail();
    result = "[email protected]"; result = null;
  }};
  // When
  helmMojo.executeInternal();
  // Then
  assertThat(helmMojo.helm, notNullValue());
  assertThat(helmMojo.helm.getChart(), is("artifact-id"));
  assertThat(helmMojo.helm.getChartExtension(), is("tar.gz"));
  assertThat(helmMojo.helm.getVersion(), is("1337"));
  assertThat(helmMojo.helm.getDescription(), is("A description from Maven"));
  assertThat(helmMojo.helm.getHome(), is("https://project.url"));
  assertThat(helmMojo.helm.getSources(), contains("https://scm.url"));
  assertThat(helmMojo.helm.getMaintainers(), contains(
      new Maintainer("John", "[email protected]")
  ));
  assertThat(helmMojo.helm.getIcon(), nullValue());
  assertThat(helmMojo.helm.getAdditionalFiles(), empty());
  assertThat(helmMojo.helm.getTemplates(), empty());
  assertThat(helmMojo.helm.getTypes(), contains(HelmConfig.HelmType.KUBERNETES));
  assertThat(helmMojo.helm.getSourceDir(), is("target/classes/META-INF/jkube/"));
  assertThat(helmMojo.helm.getOutputDir(), is("target/jkube/helm/artifact-id"));
  assertThat(helmMojo.helm.getTarballOutputDir(), is("target"));
  new Verifications() {{
    HelmService.generateHelmCharts(null, helmMojo.helm);
    times = 1;
  }};
}