org.apache.maven.artifact.repository.metadata.Metadata Java Examples

The following examples show how to use org.apache.maven.artifact.repository.metadata.Metadata. 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: RepositoryMetadataMerger.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Merges the contents of passed in metadata.
 */
public void merge(final OutputStream outputStream,
                  final MavenPath mavenPath,
                  final Map<Repository, Content> contents)
{
  log.debug("Merge metadata for {}", mavenPath.getPath());
  List<Envelope> metadatas = new ArrayList<>(contents.size());
  try {
    for (Map.Entry<Repository, Content> entry : contents.entrySet()) {
      addReadMetadata(mavenPath, metadatas, entry);
    }

    final Metadata mergedMetadata = merge(metadatas);
    if (mergedMetadata == null) {
      return;
    }
    MavenModels.writeMetadata(outputStream, mergedMetadata);
  }
  catch (IOException e) {
    log.error("Unable to merge {}", mavenPath, e);
  }
}
 
Example #3
Source File: OrientMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Writes passed in metadata as XML.
 */
public static void write(final Repository repository, final MavenPath mavenPath, final Metadata metadata)
    throws IOException
{
  MavenFacet mavenFacet = repository.facet(MavenFacet.class);
  final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  MavenModels.writeMetadata(buffer, metadata);
  mavenFacet.put(mavenPath, new BytesPayload(buffer.toByteArray(),
      MavenMimeRulesSource.METADATA_TYPE));
  final Map<HashAlgorithm, HashCode> hashCodes = mavenFacet.get(mavenPath).getAttributes()
      .require(Content.CONTENT_HASH_CODES_MAP, Content.T_CONTENT_HASH_CODES_MAP);
  checkState(hashCodes != null, "hashCodes");
  for (HashType hashType : HashType.values()) {
    MavenPath checksumPath = mavenPath.hash(hashType);
    HashCode hashCode = hashCodes.get(hashType.getHashAlgorithm());
    checkState(hashCode != null, "hashCode: type=%s", hashType);
    mavenFacet.put(checksumPath, new StringPayload(hashCode.toString(), Constants.CHECKSUM_CONTENT_TYPE));
  }
}
 
Example #4
Source File: RepositoryMetadataMerger.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void addReadMetadata(final MavenPath mavenPath,
                             final List<Envelope> metadatas,
                             final Entry<Repository, Content> entry) throws IOException
{
  final String origin = entry.getKey().getName() + " @ " + mavenPath.getPath();
  try {
    final Metadata metadata = MavenModels.readMetadata(entry.getValue().openInputStream());
    if (metadata == null) {
      log.debug("Corrupted repository metadata: {}, source: {}", origin, entry.getValue());
      return;
    }
    metadatas.add(new Envelope(origin, metadata));
  }
  catch (IOException e) {
    log.debug("Error downloading repository metadata: {}, source: {}", origin, entry.getValue());
    throw new IOException("Error downloading repository metadata for " + origin + ": " + e.getMessage(), e);
  }
}
 
Example #5
Source File: RepositoryMetadataMerger.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Merges "right" plugins into "left", the instances are mutated.
 */
private void mergePlugins(final Metadata left, final Metadata right) {
  nullElementFilter(left.getPlugins());
  nullElementFilter(right.getPlugins());
  for (Plugin plugin : right.getPlugins()) {
    boolean found = false;
    for (Plugin preExisting : left.getPlugins()) {
      if (Objects.equals(preExisting.getArtifactId(), plugin.getArtifactId())
          && Objects.equals(preExisting.getPrefix(), plugin.getPrefix())) {
        found = true;
        preExisting.setName(plugin.getName());
        break;
      }
    }
    if (!found) {
      Plugin newPlugin = new Plugin();
      newPlugin.setArtifactId(plugin.getArtifactId());
      newPlugin.setPrefix(plugin.getPrefix());
      newPlugin.setName(plugin.getName());
      left.addPlugin(newPlugin);
    }
  }
}
 
Example #6
Source File: OrientMetadataUpdater.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Writes/overwrites metadata, replacing existing one, if any.
 */
@VisibleForTesting
void replace(final MavenPath mavenPath, final Maven2Metadata metadata) {
  try {
    TransactionalStoreBlob.operation.throwing(IOException.class).call(() -> {
      checkNotNull(mavenPath);
      checkNotNull(metadata);

      final Metadata oldMetadata = OrientMetadataUtils.read(repository, mavenPath);
      if (oldMetadata == null) {
        // old does not exists, just write it
        write(mavenPath, toMetadata(metadata));
      }
      else {
        final Metadata updated = toMetadata(metadata);
        writeIfUnchanged(mavenPath, oldMetadata, updated);
      }
      return null;
    });
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #7
Source File: MavenFacetImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void rebuildMetadata(final Blob metadataBlob) throws IOException {
  Metadata metadata = MavenModels.readMetadata(metadataBlob.getInputStream());

  // avoid triggering nested rebuilds as the rebuilder will already do that if necessary
  rebuilding.set(TRUE);
  try {
    metadataRebuilder.rebuildInTransaction(
        getRepository(),
        false,
        false,
        metadata.getGroupId(),
        metadata.getArtifactId(),
        metadata.getVersion()
    );
  }
  finally {
    rebuilding.remove();
  }
}
 
Example #8
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void groupLevelMd() throws Exception {
  final Metadata m1 = g("foo");
  final Metadata m2 = g("foo", "bar");
  final Metadata m3 = g("baz");

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
  );
  assertThat(m, notNullValue());
  assertThat(m.getModelVersion(), equalTo("1.1.0"));
  assertThat(m.getPlugins(), hasSize(3));
  final List<String> prefixes = Lists.newArrayList(Iterables.transform(m.getPlugins(), new Function<Plugin, String>()
  {
    @Override
    public String apply(final Plugin input) {
      return input.getArtifactId();
    }
  }));
  assertThat(prefixes, containsInAnyOrder("foo-maven-plugin", "bar-maven-plugin", "baz-maven-plugin"));
}
 
Example #9
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void artifactLevelMd() throws Exception {
  final Metadata m1 = a("org.foo", "some-project", "20150324121500", "1.0.1", "1.0.1", "1.0.0", "1.0.1");
  final Metadata m2 = a("org.foo", "some-project", "20150324121700", "1.0.2", "1.0.2", "1.0.2");
  final Metadata m3 = a("org.foo", "some-project", "20150324121600", "1.1.0-SNAPSHOT", null, "1.1.0-SNAPSHOT");

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
  );
  assertThat(m, notNullValue());
  assertThat(m.getModelVersion(), equalTo("1.1.0"));
  assertThat(m.getGroupId(), equalTo("org.foo"));
  assertThat(m.getArtifactId(), equalTo("some-project"));
  assertThat(m.getVersioning().getLastUpdated(), equalTo("20150324121700"));
  assertThat(m.getVersioning().getSnapshot(), nullValue());
  assertThat(m.getVersioning().getRelease(), equalTo("1.0.2"));
  assertThat(m.getVersioning().getLatest(), equalTo("1.1.0-SNAPSHOT"));
  assertThat(m.getVersioning().getVersions(), contains("1.0.0", "1.0.1", "1.0.2", "1.1.0-SNAPSHOT"));
}
 
Example #10
Source File: MavenMetadataContentValidator.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
public void validate(final String path, final InputStream mavenMetadata) {
  try {
    Metadata metadata = MavenModels.readMetadata(mavenMetadata);

    if (metadata == null) {
      throw new InvalidContentException("Metadata at path " + path + " is not a valid maven-metadata.xml");
    }

    // maven-metadata.xml files for plugins do not contain groupId and therefore cannot be validated
    if (isNotEmpty(metadata.getGroupId())) {
      validatePath(path, metadata);
    }
    else {
      log.debug("No groupId found in maven-metadata.xml therefore skipping validation");
    }
  }
  catch (IOException e) {
    log.warn("Unable to read maven-metadata.xml at path {}", path, e );
    
    throw new InvalidContentException("Unable to read maven-metadata.xml reason: " + e.getMessage());
  }
}
 
Example #11
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void versionLevelMd() throws Exception {
  final Metadata m1 = v("org.foo", "some-project", "1.0.0", "20150324.121500", 3);
  final Metadata m2 = v("org.foo", "some-project", "1.0.0", "20150323.121500", 2);
  final Metadata m3 = v("org.foo", "some-project", "1.0.0", "20150322.121500", 1);

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
  );
  assertThat(m, notNullValue());
  assertThat(m.getModelVersion(), equalTo("1.1.0"));
  assertThat(m.getGroupId(), equalTo("org.foo"));
  assertThat(m.getArtifactId(), equalTo("some-project"));
  assertThat(m.getVersioning().getLastUpdated(), equalTo("20150324121500"));
  assertThat(m.getVersioning().getSnapshot(), notNullValue());
  assertThat(m.getVersioning().getSnapshot().getTimestamp(), equalTo("20150324.121500"));
  assertThat(m.getVersioning().getSnapshot().getBuildNumber(), equalTo(3));
}
 
Example #12
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * NEXUS-13085
 * Some maven-metadata.xml files are contrary to the present spec 
 * (http://maven.apache.org/ref/3.3.9/maven-repository-metadata/repository-metadata.html) and contain a 'version' 
 * element for non-SNAPSHOT artifacts, allowing for lax validation.
 */
@Test
public void allowVersionInArtifactLevelMetadata() {
  Metadata m1 = a("org.foo", "some-project", "20150324121500", "1.0.0","1.0.0", "1.0.0");
  m1.setVersion("1.0.0");
  Metadata m2 = a("org.foo", "some-project", "20150324121501", "1.0.1","1.0.1", "1.0.1");
  m2.setVersion("1.0.1");

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2))
  );
  assertThat(m.getVersion(), is(m1.getVersion())); // target version is left intact, no attempt to merge
  assertThat(m.getVersioning().getRelease(), is(m2.getVersion()));
  assertThat(m.getVersioning().getLastUpdated(), is(m2.getVersioning().getLastUpdated()));
  assertThat(m.getVersioning().getVersions(), contains("1.0.0", "1.0.1"));
}
 
Example #13
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void handleNullSnapshotTimestamps() {
  Metadata m1 = v("org.foo", "some-project", "1.0.0", "20150322.121500", 1);
  m1.getVersioning().getSnapshot().setTimestamp(null);
  Metadata m2 = v("org.foo", "some-project", "1.0.0", "20150323.121500", 2);

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2))
  );
  assertThat(m, notNullValue());
  assertThat(m.getModelVersion(), equalTo("1.1.0"));
  assertThat(m.getGroupId(), equalTo("org.foo"));
  assertThat(m.getArtifactId(), equalTo("some-project"));
  assertThat(m.getVersioning().getLastUpdated(), equalTo("20150323121500"));
  assertThat(m.getVersioning().getSnapshot(), notNullValue());
  assertThat(m.getVersioning().getSnapshot().getTimestamp(), equalTo("20150323.121500"));
  assertThat(m.getVersioning().getSnapshot().getBuildNumber(), equalTo(2));
}
 
Example #14
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;
}
 
Example #15
Source File: MavenMetadataGenerator.java    From artifactory-resource with Apache License 2.0 5 votes vote down vote up
private void writeMetadataFile(Metadata metadata, File file, boolean generateChecksums) {
	try {
		MetadataXpp3Writer writer = new MetadataXpp3Writer();
		try (FileOutputStream outputStream = new FileOutputStream(file)) {
			writer.write(outputStream, metadata);
		}
		Checksum.generateChecksumFiles(file);
	}
	catch (IOException ex) {
		throw new IllegalStateException(ex);
	}
}
 
Example #16
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private Metadata g(final String... pluginNames)
{
  final Metadata m = new Metadata();
  for (String pluginName : pluginNames) {
    m.addPlugin(plugin(pluginName));
  }
  return m;
}
 
Example #17
Source File: RepositoryMetadataMergerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void mixedLevelMd() throws Exception {
  final Metadata m1 = a("org.foo", "some-project", "20150324121500", "1.0.1", "1.0.1", "1.0.0", "1.0.1");
  final Metadata m2 = g("foo", "bar");
  final Metadata m3 = v("org.foo", "some-project", "1.1.0", "20150322.121500", 3);

  final Metadata m = merger.merge(
      ImmutableList.of(new Envelope("1", m1), new Envelope("2", m2), new Envelope("3", m3))
  );
  assertThat(m, notNullValue());
  assertThat(m.getModelVersion(), equalTo("1.1.0"));
  assertThat(m.getGroupId(), equalTo("org.foo"));
  assertThat(m.getArtifactId(), equalTo("some-project"));
  assertThat(m.getVersion(), equalTo("1.1.0-SNAPSHOT"));
  assertThat(m.getVersioning().getLastUpdated(), equalTo("20150324121500"));
  assertThat(m.getVersioning().getSnapshot(), notNullValue());
  assertThat(m.getVersioning().getSnapshot().getTimestamp(), equalTo("20150322.121500"));
  assertThat(m.getVersioning().getSnapshot().getBuildNumber(), equalTo(3));
  assertThat(m.getVersioning().getRelease(), equalTo("1.0.1"));
  assertThat(m.getVersioning().getLatest(), equalTo("1.0.1"));
  assertThat(m.getVersioning().getVersions(), contains("1.0.0", "1.0.1"));
  assertThat(m.getPlugins(), hasSize(2));
  final List<String> prefixes = Lists.newArrayList(Iterables.transform(m.getPlugins(), new Function<Plugin, String>()
  {
    @Override
    public String apply(final Plugin input) {
      return input.getArtifactId();
    }
  }));
  assertThat(prefixes, containsInAnyOrder("foo-maven-plugin", "bar-maven-plugin"));
}
 
Example #18
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 #19
Source File: RepositoryMetadataMerger.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Test metadata for equality.  Note timestamp is not considered.
 */
public boolean metadataEquals(final Metadata md1, final Metadata md2) {
  checkNotNull(md1);
  checkNotNull(md2);
  return
    Objects.equals(md1.getGroupId(), md2.getGroupId()) && // NOSONAR
    Objects.equals(md1.getArtifactId(), md2.getArtifactId()) &&
    Objects.equals(md1.getVersion(), md2.getVersion()) &&
    versioningEquals(md1.getVersioning(), md2.getVersioning()) &&
    pluginsEquals(md1.getPlugins(), md2.getPlugins()); // NOSONAR
}
 
Example #20
Source File: VersioningCalculatorTest.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
private byte[] setupMetadataVersions( final String... versions )
    throws IOException
{
    final Metadata md = new Metadata();
    final Versioning v = new Versioning();
    md.setVersioning( v );
    v.setVersions( Arrays.asList( versions ) );

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new MetadataXpp3Writer().write( baos, md );

    return baos.toByteArray();
}
 
Example #21
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 #22
Source File: OrientMetadataUpdater.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void writeIfUnchanged(final MavenPath mavenPath, final Metadata oldMetadata, final Metadata newMetadata)
    throws IOException
{
  if (repositoryMetadataMerger.metadataEquals(oldMetadata, newMetadata)) {
    log.info("metadata for {} hasn't changed, skipping", mavenPath);
  }
  else {
    write(mavenPath, newMetadata);
  }
}
 
Example #23
Source File: MavenTestHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public Metadata parseMetadata(final InputStream is) throws Exception {
  try {
    assertThat(is, notNullValue());
    return reader.read(is);
  }
  finally {
    IOUtils.closeQuietly(is);
  }
}
 
Example #24
Source File: OrientMetadataUpdater.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Writes/updates metadata, merges existing one, if any.
 */
@VisibleForTesting
void update(final MavenPath mavenPath, final Maven2Metadata metadata) {
  try {
    TransactionalStoreBlob.operation.throwing(IOException.class).call(() -> {
      checkNotNull(mavenPath);
      checkNotNull(metadata);

      final Metadata oldMetadata = OrientMetadataUtils.read(repository, mavenPath);
      if (oldMetadata == null) {
        // old does not exists, just write it
        write(mavenPath, toMetadata(metadata));
      }
      else {
        final Metadata updated = repositoryMetadataMerger.merge(
            ImmutableList.of(
                new Envelope(repository.getName() + ":" + mavenPath.getPath(), oldMetadata),
                new Envelope("new:" + mavenPath.getPath(), toMetadata(metadata))
            )
        );
        writeIfUnchanged(mavenPath, oldMetadata, updated);
      }
      return null;
    });
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #25
Source File: OrientMetadataUtils.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reads content stored at given path as {@link Metadata}. Returns null if the content does not exist.
 */
@Nullable
public static Metadata read(final Repository repository, final MavenPath mavenPath) throws IOException {
  final Content content = repository.facet(MavenFacet.class).get(mavenPath);
  if (content == null) {
    return null;
  }
  else {
    Metadata metadata = MavenModels.readMetadata(content.openInputStream());
    if (metadata == null) {
      log.warn("Corrupted metadata {} @ {}", repository.getName(), mavenPath.getPath());
    }
    return metadata;
  }
}
 
Example #26
Source File: MavenModels.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Parses input into {@link Metadata}, returns {@code null} if input not parsable. Passed in {@link InputStream} is
 * closed always on return.
 */
@Nullable
public static Metadata readMetadata(final InputStream inputStream) throws IOException {
  try (InputStream is = inputStream) {
    return METADATA_READER.read(is, false);
  }
  catch (XmlPullParserException e) {
    log.debug("Could not parse XML into Metadata", e);
    return null;
  }
}
 
Example #27
Source File: MavenMetadataContentValidator.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private String getMetadataVersion(final Metadata metadata) {
  if (metadata.getVersion() != null && metadata.getVersion().contains("-SNAPSHOT")) {
    log.debug("maven-metadata.xml contains a SNAPSHOT version ({}) therefore the version is expected to be part of " +
            "the path", metadata.getVersion());

    return metadata.getVersion();
  }
  else {
    log.debug("maven-metadata.xml version ({}) is either null or not a SNAPSHOT therefore not expected in the path",
        metadata.getVersion());
    
    return null;
  }
}
 
Example #28
Source File: MavenModels.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Writes out {@link Metadata} into {@link OutputStream}. The stream is not closed on return.
 */
public static void writeMetadata(final OutputStream outputStream, final Metadata metadata)
    throws IOException
{
  METADATA_WRITER.write(outputStream, metadata);
}
 
Example #29
Source File: GroupRepositoryMetadata.java    From takari-lifecycle with Eclipse Public License 1.0 4 votes vote down vote up
public GroupRepositoryMetadata(String groupId) {
  super(new Metadata());
  this.groupId = groupId;
}
 
Example #30
Source File: MavenITSupport.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
protected Metadata parseMetadata(final InputStream is) throws Exception {
  assertThat(is, notNullValue());
  return mavenTestHelper.parseMetadata(is);
}