Skip to content

Commit

Permalink
Merge branch 'release/2.15.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
pvorb committed Mar 6, 2024
2 parents 757efd9 + b75cd3f commit dcece97
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 42 deletions.
26 changes: 10 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

<groupId>com.deviceinsight.helm</groupId>
<artifactId>helm-maven-plugin</artifactId>
<version>2.14.0</version>
<version>2.15.0</version>
<packaging>maven-plugin</packaging>

<name>Helm Maven Plugin</name>
<description>A Maven Plugin for Helm Charts</description>
<url>https://github.com/deviceinsight/helm-maven-plugin</url>

<properties>
<kotlin.version>1.8.22</kotlin.version>
<kotlin.version>1.9.10</kotlin.version>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<maven.version>3.9.0</maven.version>
<maven-project.version>2.2.1</maven-project.version>
<maven.version>3.9.6</maven.version>
<maven-plugin.version>3.11.0</maven-plugin.version>

<jackson-bom.version>2.15.2</jackson-bom.version>
<jackson-bom.version>2.15.3</jackson-bom.version>
<httpclient.version>4.5.14</httpclient.version>
<plexus-sec-dispatcher.version>1.4</plexus-sec-dispatcher.version>

<junit.jupiter.version>5.10.0</junit.jupiter.version>
<assertj-core.version>3.24.2</assertj-core.version>

<dokka-maven-plugin.version>1.8.20</dokka-maven-plugin.version>
<dokka-maven-plugin.version>1.9.10</dokka-maven-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
<gitflow-maven-plugin.version>1.20.0</gitflow-maven-plugin.version>
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${maven.version}</version>
<version>${maven-plugin.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -86,12 +86,6 @@
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>${maven-project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
Expand Down Expand Up @@ -162,7 +156,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${maven.version}</version>
<version>${maven-plugin.version}</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
<goalPrefix>helm</goalPrefix>
Expand Down Expand Up @@ -285,7 +279,7 @@
</roles>
</developer>
<developer>
<id>dwi-di</id>
<id>d-rk</id>
<name>Dirk Wilden</name>
<email>[email protected]</email>
<roles>
Expand Down
68 changes: 42 additions & 26 deletions src/main/kotlin/com/deviceinsight/helm/ResolveHelmMojo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
package com.deviceinsight.helm

import com.deviceinsight.helm.util.PlatformDetector
import org.apache.maven.artifact.Artifact
import org.apache.maven.artifact.repository.ArtifactRepository
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest
import org.apache.maven.artifact.resolver.ArtifactResolutionResult
import org.apache.maven.plugins.annotations.Component
import org.apache.maven.plugins.annotations.LifecyclePhase
import org.apache.maven.plugins.annotations.Mojo
import org.apache.maven.plugins.annotations.Parameter
import org.apache.maven.repository.RepositorySystem
import org.eclipse.aether.RepositorySystem
import org.eclipse.aether.RepositorySystemSession
import org.eclipse.aether.artifact.Artifact
import org.eclipse.aether.artifact.DefaultArtifact
import org.eclipse.aether.repository.RemoteRepository
import org.eclipse.aether.resolution.ArtifactRequest
import java.io.File
import java.net.HttpURLConnection
import java.net.URI
import java.net.URL
Expand All @@ -51,52 +53,66 @@ open class ResolveHelmMojo : AbstractHelmMojo() {
@Parameter(property = "helmDownloadUrl", defaultValue = "https://get.helm.sh/")
private lateinit var helmDownloadUrl: URI

@Parameter(readonly = true, required = true, defaultValue = "\${localRepository}")
private lateinit var localRepository: ArtifactRepository
@Parameter(readonly = true, required = true, defaultValue = "\${repositorySystemSession}")
private lateinit var repositorySession: RepositorySystemSession

@Parameter(readonly = true, required = true, defaultValue = "\${project.remoteArtifactRepositories}")
private lateinit var remoteRepositories: List<ArtifactRepository>
@Parameter(readonly = true, required = true, defaultValue = "\${project.remoteProjectRepositories}")
private lateinit var remoteRepositories: List<RemoteRepository>

@Component
private lateinit var repositorySystem: RepositorySystem

protected lateinit var helm : String
protected lateinit var helm: String

protected fun resolveHelmBinary(): String {

val platformIdentifier = PlatformDetector.detectHelmReleasePlatformIdentifier()
val helmArtifact: Artifact =
repositorySystem.createArtifactWithClassifier(helmGroupId, helmArtifactId, helmVersion, "binary",
platformIdentifier)
val helmArtifact: Artifact = DefaultArtifact(helmGroupId, helmArtifactId, platformIdentifier, "binary", helmVersion)

val request = ArtifactResolutionRequest()
request.artifact = helmArtifact
request.isResolveTransitively = false
request.localRepository = localRepository
request.remoteRepositories = remoteRepositories
var resolvedArtifact = findArtifact(helmArtifact)

val resolutionResult: ArtifactResolutionResult = repositorySystem.resolve(request)

if (!resolutionResult.isSuccess) {
if (resolvedArtifact == null) {
log.info("Artifact not found in remote repositories")
downloadAndInstallHelm(helmArtifact, platformIdentifier)
resolvedArtifact = downloadAndInstallHelm(helmArtifact, platformIdentifier)
}

helmArtifact.file.setExecutable(true)
resolvedArtifact.file.setExecutable(true)

return resolvedArtifact.file.absolutePath
}

private fun findArtifact(helmArtifact: Artifact): Artifact? {

return helmArtifact.file.absolutePath
try {
val request = ArtifactRequest()
request.setArtifact(helmArtifact)
request.setRepositories(remoteRepositories)
val resolutionResult = repositorySystem.resolveArtifact(repositorySession, request)

return if (resolutionResult.isResolved) {
resolutionResult.artifact
} else {
null
}

} catch (e: Exception) {
log.debug("failed to resolve artifact: ${e.message}")
return null
}
}

private fun downloadAndInstallHelm(artifact: Artifact, platformIdentifier: String) {
private fun downloadAndInstallHelm(artifact: Artifact, platformIdentifier: String): Artifact {

val fileName = "helm-v$helmVersion-$platformIdentifier"

val targetFile = artifact.file.toPath()
val artifactPath = repositorySession.localRepositoryManager.getPathForLocalArtifact(artifact)
val targetFile = File(repositorySession.localRepository.basedir, artifactPath).toPath()
Files.createDirectories(targetFile.parent)

val url = helmDownloadUrl.resolve("./$fileName.zip").toURL()

downloadFileAndExtractBinary(url, targetFile)
return artifact.setFile(targetFile.toFile())
}

private fun downloadFileAndExtractBinary(url: URL, destination: Path) {
Expand Down

0 comments on commit dcece97

Please sign in to comment.