Skip to content

Commit

Permalink
fixup! maven deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
datYori committed Jun 12, 2024
1 parent 6578a8c commit 3427f66
Showing 1 changed file with 2 additions and 93 deletions.
95 changes: 2 additions & 93 deletions deps/others/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -63,100 +63,9 @@ def updatePom(pomFile: File, newVersion: String): Unit = {
}

// Task to patch dependencies
val patchAndLocalPublish = taskKey[Unit]("Patch dependencies")
val patchDependencies = taskKey[Unit]("Patch dependencies")

patchAndLocalPublish := {
val log = streams.value.log
val updateReport = update.value

updateReport.configurations.flatMap(_.modules).distinct.foreach { module =>
val groupID = module.module.organization
val artifactID = module.module.name
val version = module.module.revision
val scalaVersionSuffixPattern = "_2\\.\\d{1,2}".r
val normalizedArtifactId = scalaVersionSuffixPattern.replaceFirstIn(artifactID, "")
if (moduleNames.contains(normalizedArtifactId)) {
log.info(s"Found module $artifactID:$version")
module.artifacts.find(_._1.extension == "jar").foreach { case (_, jarFile) =>
try {
val pomPath = jarFile.getAbsolutePath.replace(".jar", ".pom")
val pomFile = new File(pomPath)
if (!pomFile.exists()) {
log.error(s"Expected POM file does not exist for $artifactID:$version at $pomPath")
} else {
log.info(s"Found POM file for $artifactID:$version at $pomPath")

val newName = jarFile.getName.replace(".jar", "-rawlabs.jar")
val newJarFile = new File(jarFile.getParent, newName)
Files.copy(jarFile.toPath, newJarFile.toPath, StandardCopyOption.REPLACE_EXISTING)
log.info(s"Patched JAR file created: $newName")

// Handling the manifest
val manifest = new File("manifest.txt")
val bw = new BufferedWriter(new FileWriter(manifest))
try {
bw.write(s"Automatic-Module-Name: ${moduleNames(normalizedArtifactId)}\n")
} finally {
bw.close()
}

// Update the JAR file with the new manifest
val patchCommand = s"jar --update --file ${newJarFile.getAbsolutePath} --manifest=manifest.txt"
val patchExitCode = patchCommand.!
if (patchExitCode == 0) {
log.info(s"JAR file $newName patched successfully with new manifest.")
} else {
log.error(s"Failed to patch JAR file $newName with new manifest.")
}

// Update and publish the POM file
updatePom(pomFile, version)
val copiedPomFile = new File(pomFile.getParent, s"$artifactID-$version-rawlabs.pom")
Files.copy(pomFile.toPath, copiedPomFile.toPath, StandardCopyOption.REPLACE_EXISTING)
log.info(s"Updated POM file for $artifactID with version $version-rawlabs")
val localPublishCommand = s"""mvn install:install-file
|-Dfile=${newJarFile.getAbsolutePath}
|-DpomFile=${copiedPomFile.getAbsolutePath}
|-DgroupId=$groupID
|-DartifactId=$artifactID
|-Dversion=$version-rawlabs
|-Dpackaging=jar""".stripMargin.replaceAll("\n", " ")
val localPublishExitCode = localPublishCommand.!
if (localPublishExitCode == 0) {
log.info(s"Published locally patched JAR $newName with updated POM $artifactID-$version-rawlabs.")
} else {
log.error(s"Failed to publish locally JAR $newName and POM $artifactID-$version-rawlabs.")
}
val publishCommand = s"""mvn deploy:deploy-file
|-Dfile=${newJarFile.getAbsolutePath}
|-DpomFile=${copiedPomFile.getAbsolutePath}
|-DgroupId=$groupID
|-DartifactId=$artifactID
|-Dversion=$version-rawlabs
|-Dpackaging=jar
|-DrepositoryId=githubraw
|-Durl=https://maven.pkg.github.com/raw-labs/raw""".stripMargin.replaceAll("\n", " ")
val publishExitCode = publishCommand.!
if (publishExitCode == 0) {
log.info(s"Published patched JAR $newName with updated POM $artifactID-$version-rawlabs.")
} else {
log.error(s"Failed to run $publishCommand")
log.error(s"Failed to publish JAR $newName and POM $artifactID-$version-rawlabs.")
}
}
} catch {
case e: Exception =>
log.error(s"Error during the patching process for $artifactID:$version: ${e.getMessage}")
}
}
}
}
}

// Task to patch dependencies
val patchAndLocalPublish = taskKey[Unit]("Patch dependencies")

patchAndLocalPublish := {
patchDependencies := {
val log = streams.value.log
val updateReport = update.value

Expand Down

0 comments on commit 3427f66

Please sign in to comment.