Skip to content

Commit

Permalink
Replace getMetaDataFileContent with getMetaData
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Dec 12, 2024
1 parent 86eaff0 commit 0c9494b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule

if (publishesMetaDataFile) {
publishWithWriter(metaDataFile) { Writer writer ->
writer << getMetaDataFileContent()
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer()
metadataWriter.write(writer, getMetaData([]))
}
}

Expand Down Expand Up @@ -144,42 +145,22 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule
}
allVersions << version
publishWithWriter(rootMavenMetaData) { Writer writer ->
// Create Maven Metadata
Metadata metadata = new Metadata()
metadata.groupId = groupId
metadata.artifactId = artifactId

Versioning versioning = new Versioning()
versioning.versions = allVersions.unique().sort()
versioning.latest = versioning.versions.last()
versioning.release = versioning.versions.last()
versioning.lastUpdated = updateFormat.format(publishTimestamp)

if (uniqueSnapshots && version.endsWith("-SNAPSHOT")) {
Snapshot snapshot = new Snapshot()
snapshot.timestamp = timestampFormat.format(publishTimestamp)
snapshot.buildNumber = publishCount
versioning.snapshot = snapshot
}

metadata.versioning = versioning

// Write the metadata to the file
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer()
metadataWriter.write(writer, metadata)
metadataWriter.write(writer, getMetaData(allVersions))
}
}

String getMetaDataFileContent() {
// Similar to updateRootMavenMetaData but for the artifact's own metadata file
StringWriter writer = new StringWriter()
// Create Maven Metadata
/**
* Similar to updateRootMavenMetaData but for the artifact's own metadata file
*/
Metadata getMetaData(List<String> versions) {
Metadata metadata = new Metadata()
metadata.groupId = groupId
metadata.artifactId = artifactId
metadata.version = version

Versioning versioning = new Versioning()
versioning.versions = versions
versioning.lastUpdated = updateFormat.format(publishTimestamp)
if (uniqueSnapshots && version.endsWith("-SNAPSHOT")) {
Snapshot snapshot = new Snapshot()
Expand All @@ -188,11 +169,7 @@ abstract class AbstractMavenModule extends AbstractModule implements MavenModule
versioning.snapshot = snapshot
}
metadata.versioning = versioning

// Write the metadata to the string
MetadataXpp3Writer metadataWriter = new MetadataXpp3Writer()
metadataWriter.write(writer, metadata)
return writer.toString()
return metadata
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.github.jengelman.gradle.plugins.shadow.util.repo.maven
import org.apache.maven.artifact.repository.metadata.Metadata
import org.apache.maven.artifact.repository.metadata.Snapshot
import org.apache.maven.artifact.repository.metadata.Versioning
import org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer
import org.jetbrains.annotations.NotNull

class MavenFileModule extends AbstractMavenModule {
Expand All @@ -17,22 +16,21 @@ class MavenFileModule extends AbstractMavenModule {
}

@Override
String getMetaDataFileContent() {
Metadata getMetaData(List<String> versions) {
Metadata metadata = new Metadata()
metadata.groupId = groupId
metadata.artifactId = artifactId
metadata.version = version

Versioning versioning = new Versioning()
versioning.versions = versions
versioning.snapshot = new Snapshot()
versioning.snapshot.timestamp = timestampFormat.format(publishTimestamp)
versioning.snapshot.buildNumber = publishCount
versioning.lastUpdated = updateFormat.format(publishTimestamp)
metadata.versioning = versioning

StringWriter writer = new StringWriter()
new MetadataXpp3Writer().write(writer, metadata)
return writer.toString()
return metadata
}

@Override
Expand Down

0 comments on commit 0c9494b

Please sign in to comment.