Skip to content

Commit

Permalink
#517: Add custom artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Mar 25, 2024
1 parent 6e0c171 commit 061ed05
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .project-keeper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ sources:
version: "${revision}"
relativePath: "../parent-pom/pom.xml"
advertise: false
artifacts:
# [itest->dsn~customize-release-artifacts-custom~0]
- target/project-keeper-shared-model-classes-${version}.jar
- type: maven
path: project-keeper/pom.xml
modules:
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ This allows adding project-specific release artifacts like `.js` extensions.
Covers:
* [`dsn~customize-release-artifacts~0`](#customize-release-artifacts)

-Needs: impl, utest, itest
Needs: impl, utest

### Customize Build Process
`dsn~customize-build-process~0`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private String getAdditionalReleaseTags() {
}

private String getReleaseArtifacts() {
return Stream.of(sourceReleaseArtifacts(), errorCodeReports()) //
return Stream.of(sourceReleaseArtifacts(), errorCodeReports(), customArtifacts()) //
.flatMap(Function.identity()) //
.map(Path::toString).collect(joining("\n"));
}
Expand All @@ -125,6 +125,22 @@ private Stream<Path> errorCodeReports() {
.map(source -> this.projectDir.resolve("target/error_code_report.json"));
}

// [impl->dsn~customize-release-artifacts-custom~0]
private Stream<Path> customArtifacts() {
return config.getSources().stream().flatMap(this::customArtifacts);
}

private Stream<Path> customArtifacts(final Source source) {
final Path sourcePath = projectDir.resolve(source.getPath()).getParent();
return source.getReleaseArtifacts().stream() //
.map(this::replaceVersionPlaceholder) //
.map(sourcePath::resolve);
}

private Path replaceVersionPlaceholder(final Path path) {
return Path.of(path.toString().replace("${version}", this.projectVersion));
}

private String extractReleaseNotes(final ChangesFile changesFile) {
final List<String> lines = new ArrayList<>();
lines.addAll(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package com.exasol.projectkeeper.github;

import static java.util.Arrays.asList;
import static java.util.stream.Collectors.joining;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.exception.UncheckedException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

Expand Down Expand Up @@ -75,43 +80,70 @@ void releaseNotes() {
@Test
void releaseArtifactsNoMavenSource() {
publish(ProjectKeeperConfig.builder(), ChangesFile.builder());
verify(this.publisherMock).publish("release-artifacts", "");
verifyReleaseArtifacts();
}

@Test
void releaseArtifactsMavenSourceWithoutArtifact() {
publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), AnalyzedMavenSource.builder().build());
verify(this.publisherMock).publish("release-artifacts", "");
verifyReleaseArtifacts();
}

// [utest->dsn~customize-release-artifacts-hard-coded~0]
@Test
void releaseArtifactsErrorCodeReport() {
publish(ProjectKeeperConfig.builder(), ChangesFile.builder(),
AnalyzedMavenSource.builder().isRootProject(true).build());
verify(this.publisherMock).publish("release-artifacts",
this.projectDir.resolve("target/error_code_report.json").toString());
verifyReleaseArtifacts("target/error_code_report.json");
}

@Test
void releaseArtifactsMavenSourceWithArtifact() {
publish(ProjectKeeperConfig.builder(), ChangesFile.builder(), AnalyzedMavenSource.builder()
.path(this.projectDir.resolve("project-dir/pom.xml")).releaseArtifactName("my-project.jar").build());
verify(this.publisherMock).publish("release-artifacts",
this.projectDir.resolve("project-dir/target/my-project.jar").toString());
verifyReleaseArtifacts("project-dir/target/my-project.jar");
}

// [utest->dsn~customize-release-artifacts-custom~0]
@ParameterizedTest
@CsvSource({ "pom.xml, target/custom.jar, target/custom.jar", //
"go.mod, build/executable, build/executable", //
"package.json, build/ext.js, build/ext.js", //
"subModule/go.mod, build/executable, subModule/build/executable", //
"pom.xml, target/custom-$version.jar, target/custom-$version.jar",
"pom.xml, target/custom-${version}.jar, target/custom-1.2.3.jar",
"subModule/pom.xml, target/custom-${version}.jar, subModule/target/custom-1.2.3.jar" })
void releaseArtifactCustom(final String sourcePath, final String artifactPath, final String expectedPath) {
publish(ProjectKeeperConfig.builder().sources(List.of(
Source.builder().path(Path.of(sourcePath)).releaseArtifacts(List.of(Path.of(artifactPath))).build())),
ChangesFile.builder());
verifyReleaseArtifacts(expectedPath);
}

@Test
void releaseArtifactsMultipleArtifact() {
publish(ProjectKeeperConfig.builder(), ChangesFile.builder(),
publish(ProjectKeeperConfig.builder()
.sources(List.of(
Source.builder().path(Path.of("pom.xml"))
.releaseArtifacts(List.of(Path.of("target/custom-${version}.jar"))).build(),
Source.builder().path(Path.of("subModule/package.json"))
.releaseArtifacts(List.of(Path.of("build/custom-extension.js"))).build())),
ChangesFile.builder(),
AnalyzedMavenSource.builder().path(this.projectDir.resolve("pom.xml"))
.releaseArtifactName("my-project1.jar").isRootProject(true).build(),
AnalyzedMavenSource.builder().path(this.projectDir.resolve("module1/pom.xml"))
.releaseArtifactName("my-project2.jar").build());
verify(this.publisherMock).publish("release-artifacts",
this.projectDir.resolve("target/my-project1.jar").toString() + "\n"
+ this.projectDir.resolve("module1/target/my-project2.jar").toString() + "\n"
+ this.projectDir.resolve("target/error_code_report.json").toString());
verifyReleaseArtifacts("target/my-project1.jar", "module1/target/my-project2.jar",
"target/error_code_report.json", "target/custom-" + PROJECT_VERSION + ".jar",
"subModule/build/custom-extension.js");
}

private void verifyReleaseArtifacts(final String... expectedPaths) {
final String expected = Arrays.stream(expectedPaths) //
.map(path -> this.projectDir.resolve(path)) //
.map(Path::toString) //
.collect(joining("\n"));
verify(this.publisherMock).publish("release-artifacts", expected);
}

@Test
Expand Down

0 comments on commit 061ed05

Please sign in to comment.