-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added upload-dependencies mojo to upload chart dependencies
- Loading branch information
Robert Delametter
committed
Feb 21, 2024
1 parent
3e8f8df
commit 1ae4d5c
Showing
10 changed files
with
150 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/main/java/io/kokuwa/maven/helm/AbstractChartDirectoryMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.kokuwa.maven.helm; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.FileVisitOption; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.codehaus.plexus.util.FileUtils; | ||
import org.codehaus.plexus.util.MatchPatterns; | ||
|
||
import lombok.Setter; | ||
|
||
@Setter | ||
public abstract class AbstractChartDirectoryMojo extends AbstractHelmMojo { | ||
|
||
/** | ||
* Root directory of your charts. | ||
* | ||
* @since 1.0 | ||
*/ | ||
@Parameter(property = "helm.chartDirectory", required = true) | ||
protected File chartDirectory; | ||
|
||
/** | ||
* List of chart directories to exclude. | ||
* | ||
* @since 1.0 | ||
*/ | ||
@Parameter(property = "helm.excludes") | ||
protected String[] excludes; | ||
|
||
List<Path> getChartDirectories() throws MojoExecutionException { | ||
|
||
List<String> exclusions = new ArrayList<>(); | ||
if (excludes != null) { | ||
exclusions.addAll(Arrays.asList(excludes)); | ||
} | ||
exclusions.addAll(FileUtils.getDefaultExcludesAsList()); | ||
MatchPatterns exclusionPatterns = MatchPatterns.from(exclusions); | ||
|
||
try (Stream<Path> files = Files.walk(chartDirectory.toPath(), FileVisitOption.FOLLOW_LINKS)) { | ||
List<Path> chartDirectories = files | ||
.filter(p -> p.getFileName().toString().equalsIgnoreCase("chart.yaml")) | ||
.map(Path::getParent) | ||
.filter(p -> !exclusionPatterns.matches(p.toString(), false)) | ||
.sorted(Comparator.reverseOrder()) | ||
.collect(Collectors.toList()); | ||
if (chartDirectories.isEmpty()) { | ||
getLog().warn("No Charts detected - no Chart.yaml files found below " + chartDirectory); | ||
} | ||
return chartDirectories; | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Unable to scan chart directory at " + chartDirectory, e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/io/kokuwa/maven/helm/UploadDependencies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.kokuwa.maven.helm; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.apache.maven.project.MavenProject; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import io.kokuwa.maven.helm.pojo.HelmRepository; | ||
import io.kokuwa.maven.helm.pojo.RepoType; | ||
|
||
@Mojo(name = "upload-dependencies") | ||
public class UploadDependencies extends UploadMojo { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(UploadDependencies.class); | ||
|
||
@Parameter(property = "url", required = true) | ||
private String url; | ||
|
||
@Parameter(property = "id", required = true) | ||
private String id; | ||
|
||
@Parameter(property = "type", required = true) | ||
private RepoType type; | ||
|
||
@Parameter(defaultValue = "${project}", required = true, readonly = true) | ||
private MavenProject project; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException { | ||
String projectPath = project.getBasedir().getAbsolutePath(); | ||
if (!isHelmChart(projectPath)) { | ||
return; | ||
} | ||
uploadRepoStable = createHelmRepository(id, url, type); | ||
uploadRepoSnapshot = createHelmRepository(id, url, type); | ||
outputDirectory = new File(Paths.get(projectPath, "charts").toString()); | ||
if (!outputDirectory.exists()) { | ||
return; | ||
} | ||
try { | ||
super.execute(); | ||
} catch (Exception e) { | ||
logger.info(String.format("%s:%s", e.getMessage(), e.getCause())); | ||
} | ||
} | ||
|
||
private boolean isHelmChart(String path) { | ||
File chartFile = new File(Paths.get(path, "Chart.yaml").toString()); | ||
return chartFile.exists(); | ||
} | ||
|
||
private HelmRepository createHelmRepository(String id, String url, RepoType type) { | ||
HelmRepository repo = new HelmRepository(); | ||
repo.setName(id); | ||
repo.setUrl(url); | ||
repo.setType(type); | ||
return repo; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters