Java Code Examples for org.apache.maven.artifact.repository.metadata.Metadata#setArtifactId()

The following examples show how to use org.apache.maven.artifact.repository.metadata.Metadata#setArtifactId() . 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: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Metadata a(final String groupId,
                   final String artifactId,
                   final String lastUpdated,
                   final String latest,
                   final String release,
                   final String... versions)
{
  final Metadata m = new Metadata();
  m.setGroupId(groupId);
  m.setArtifactId(artifactId);
  m.setVersioning(new Versioning());
  final Versioning mv = m.getVersioning();
  if (!Strings.isNullOrEmpty(lastUpdated)) {
    mv.setLastUpdated(lastUpdated);
  }
  if (!Strings.isNullOrEmpty(latest)) {
    mv.setLatest(latest);
  }
  if (!Strings.isNullOrEmpty(release)) {
    mv.setRelease(release);
  }
  mv.getVersions().addAll(Arrays.asList(versions));
  return m;
}
 
Example 2
Source File: MavenMetadataGenerator.java    From artifactory-resource with Apache License 2.0 5 votes vote down vote up
private void writeMetadata(File folder, List<MavenCoordinates> coordinates, boolean generateChecksums) {
	List<SnapshotVersion> snapshotVersions = getSnapshotVersionMetadata(coordinates);
	if (!snapshotVersions.isEmpty()) {
		Metadata metadata = new Metadata();
		Versioning versioning = new Versioning();
		versioning.setSnapshotVersions(snapshotVersions);
		metadata.setVersioning(versioning);
		metadata.setGroupId(coordinates.get(0).getGroupId());
		metadata.setArtifactId(coordinates.get(0).getArtifactId());
		metadata.setVersion(coordinates.get(0).getVersion());
		writeMetadataFile(metadata, new File(folder, "maven-metadata.xml"), generateChecksums);
	}
}
 
Example 3
Source File: RepositoryMetadataMerger.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Merges the "source" on top of "target" and returns the "target", the instances are mutated.
 */
private Metadata merge(final Metadata target, final Metadata source) {
  // sanity checks
  if (Strings.isNullOrEmpty(source.getGroupId())) {
    source.setGroupId(target.getGroupId());
  }
  if (Strings.isNullOrEmpty(source.getArtifactId())) {
    source.setArtifactId(target.getArtifactId());
  }

  // version differs: we do it "both ways" if set at all
  if (Strings.isNullOrEmpty(target.getVersion())) {
    target.setVersion(source.getVersion());
  }
  if (Strings.isNullOrEmpty(source.getVersion())) {
    source.setVersion(target.getVersion());
  }
  checkArgument(
      Objects.equals(nullOrEmptyStringFilter(target.getGroupId()), nullOrEmptyStringFilter(source.getGroupId())),
      "GroupId mismatch: %s vs %s", target.getGroupId(), source.getGroupId());
  checkArgument(
      Objects
          .equals(nullOrEmptyStringFilter(target.getArtifactId()), nullOrEmptyStringFilter(source.getArtifactId())),
      "ArtifactId mismatch: %s vs %s", target.getArtifactId(), source.getArtifactId());

  String targetVersion = nullOrEmptyStringFilter(target.getVersion());
  String sourceVersion = nullOrEmptyStringFilter(source.getVersion());

  // As per NEXUS-13085 allow this and log for support in case the resulting merge leads to downstream problems
  if (!Objects.equals(targetVersion, sourceVersion)) {
    log.warn("Merging with version mismatch for GA={}:{}, {} vs {}", target.getGroupId(), target.getArtifactId(),
        targetVersion, sourceVersion);
  }

  mergePlugins(target, source);
  mergeVersioning(target, source);
  return target;
}
 
Example 4
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Metadata v(final String groupId,
                   final String artifactId,
                   final String versionPrefix,
                   final String timestamp,
                   final int buildNumber)
{
  final Metadata m = new Metadata();
  m.setGroupId(groupId);
  m.setArtifactId(artifactId);
  m.setVersion(versionPrefix + "-SNAPSHOT");
  m.setVersioning(new Versioning());
  final Versioning mv = m.getVersioning();
  mv.setLastUpdated(timestamp.replace(".", ""));
  final Snapshot snapshot = new Snapshot();
  snapshot.setTimestamp(timestamp);
  snapshot.setBuildNumber(buildNumber);
  mv.setSnapshot(snapshot);
  final SnapshotVersion pom = new SnapshotVersion();
  pom.setExtension("pom");
  pom.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
  pom.setUpdated(timestamp);
  mv.getSnapshotVersions().add(pom);

  final SnapshotVersion jar = new SnapshotVersion();
  jar.setExtension("jar");
  jar.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
  jar.setUpdated(timestamp);
  mv.getSnapshotVersions().add(jar);

  final SnapshotVersion sources = new SnapshotVersion();
  sources.setExtension("jar");
  sources.setClassifier("sources");
  sources.setVersion(versionPrefix + "-" + timestamp + "-" + buildNumber);
  sources.setUpdated(timestamp);
  mv.getSnapshotVersions().add(sources);

  return m;
}