Skip to content

Commit

Permalink
#517: Add config option for artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada committed Mar 25, 2024
1 parent 39b50f8 commit 6e0c171
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,35 @@ private String convertExclude(final Object rawExclude) {
}

private List<Source> convertSources(final Path projectDir, final List<ProjectKeeperRawConfig.Source> rawSources) {
if (rawSources == null) {
return Collections.emptyList();
} else {
final List<Source> sources = new ArrayList<>(rawSources.size());
for (final ProjectKeeperRawConfig.Source rawSource : rawSources) {
final Source source = convertSource(projectDir, rawSource);
sources.add(source);
}
return sources;
}
return Optional.ofNullable(rawSources) //
.orElseGet(Collections::emptyList) //
.stream() //
.map(source -> convertSource(projectDir, source)) //
.toList();
}

private Source convertSource(final Path projectDir, final ProjectKeeperRawConfig.Source rawSource) {
final String rawType = rawSource.getType();
final Set<ProjectKeeperModule> modules = convertModules(rawSource.getModules());
final Path path = convertPath(projectDir, rawSource.getPath());
return Source.builder().path(path).type(convertType(rawType)).modules(modules)
.advertise(rawSource.isAdvertised()).parentPom(parseParentPomProperty(rawSource.getParentPom()))
return Source.builder() //
.path(path) //
.type(convertType(rawType)) //
.modules(modules) //
.advertise(rawSource.isAdvertised()) //
.parentPom(parseParentPomProperty(rawSource.getParentPom())) //
.releaseArtifacts(convertArtifacts(rawSource)) //
.build();
}

private List<Path> convertArtifacts(final ProjectKeeperRawConfig.Source rawSource) {
return Optional.ofNullable(rawSource.getArtifacts()) //
.orElseGet(Collections::emptyList) //
.stream() //
.map(Path::of) //
.toList();
}

private ParentPomRef parseParentPomProperty(final ProjectKeeperRawConfig.ParentPomRef rawParentPomRef) {
if (rawParentPomRef == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static class Source {
private List<String> modules;
private boolean advertise = true;
private ProjectKeeperRawConfig.ParentPomRef parentPom;
private List<String> artifacts;

/**
* Get the source path, e.g. {@code project-keeper/pom.xml}.
Expand Down Expand Up @@ -179,6 +180,16 @@ public ProjectKeeperRawConfig.ParentPomRef getParentPom() {
return parentPom;
}

/**
* Set the list of release artifact paths, relative to to {@link #getPath()}, example:
* {@code target/my-artifact.jar}
*
* @return release artifact paths
*/
public List<String> getArtifacts() {
return artifacts;
}

/**
* Set the path.
*
Expand Down Expand Up @@ -223,6 +234,16 @@ public void setParentPom(final ProjectKeeperRawConfig.ParentPomRef parentPom) {
public void setAdvertise(final boolean advertise) {
this.advertise = advertise;
}

/**
* Set the list of release artifact paths, relative to to {@link #getPath()}, example:
* {@code target/my-artifact.jar}
*
* @param artifacts release artifact paths
*/
public void setArtifacts(final List<String> artifacts) {
this.artifacts = artifacts;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ void read() throws IOException {
artifactId: "my-parent"
version: "1.2.3"
relativePath: "./my-parent.xml"
artifacts:
- "target/file1.jar"
- "target/file-${version}.jar"
build:
runnerOs: custom-runner-os
freeDiskSpace: true
Expand All @@ -74,11 +77,13 @@ void read() throws IOException {
() -> assertThat(source.getModules(), Matchers.containsInAnyOrder(MAVEN_CENTRAL, DEFAULT)),
() -> assertThat(source.getParentPom(),
equalTo(new ParentPomRef("com.example", "my-parent", "1.2.3", "./my-parent.xml"))),
() -> assertThat(source.getReleaseArtifacts(),
contains(Path.of("target/file1.jar"), Path.of("target/file-${version}.jar"))),
() -> assertThat(config.getExcludes(), containsInAnyOrder(
"\\QE-PK-CORE-17: Missing required file: '.github/workflows/broken_links_checker.yml'.\\E",
"E-PK-CORE-18: .*")),
() -> assertThat(config.getLinkReplacements(),
Matchers.contains("http://wrong-url.com|my-dependency.de"))//
Matchers.contains("http://wrong-url.com|my-dependency.de")) //
);
}

Expand All @@ -99,11 +104,12 @@ void readDefaults() throws IOException {
() -> assertThat(source.getPath(), equalTo(this.tempDir.resolve("my-sub-project/pom.xml"))),
() -> assertThat(source.getModules(), Matchers.containsInAnyOrder(DEFAULT)),
() -> assertThat(source.getParentPom(), nullValue()),
() -> assertThat(source.getReleaseArtifacts(), empty()),
() -> assertThat(config.getExcludes(), equalTo(Collections.emptyList())),
() -> assertThat(config.getCiBuildConfig().getRunnerOs(), equalTo("ubuntu-latest")),
() -> assertThat(config.getCiBuildConfig().shouldFreeDiskSpace(), equalTo(false)),
() -> assertThat(config.getCiBuildConfig().getExasolDbVersions(), empty()),
() -> assertThat(config.getLinkReplacements(), equalTo(Collections.emptyList()))//
() -> assertThat(config.getLinkReplacements(), equalTo(Collections.emptyList())) //
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.exasol.projectkeeper.shared.config;

import static java.util.Collections.emptyList;

import java.nio.file.Path;
import java.util.*;

Expand All @@ -14,6 +16,7 @@ public final class Source {
// [impl->dsn~modules~1]
private final Set<ProjectKeeperModule> modules;
private final boolean advertise;
private final List<Path> releaseArtifacts;

/**
* Reference to the parent pom. For maven sources only. {@code null} if not provided.
Expand All @@ -26,6 +29,7 @@ private Source(final SourceBuilder builder) {
this.modules = builder.modules;
this.advertise = builder.advertise;
this.parentPom = builder.parentPom;
this.releaseArtifacts = builder.releaseArtifacts;
}

/** @return Path to the source-project root or build file. Example: {@code my-project/pom.xml} */
Expand Down Expand Up @@ -63,6 +67,11 @@ public ParentPomRef getParentPom() {
return parentPom;
}

/** @return list release artifact paths, relative to to {@link #getPath()} */
public List<Path> getReleaseArtifacts() {
return releaseArtifacts;
}

/** @return a builder for creating new {@link Source} instances */
public static Source.SourceBuilder builder() {
return new Source.SourceBuilder();
Expand All @@ -75,6 +84,7 @@ public static class SourceBuilder {
private Set<ProjectKeeperModule> modules = Collections.emptySet();
private boolean advertise = true;
private ParentPomRef parentPom;
private List<Path> releaseArtifacts = emptyList();

private SourceBuilder() {
// empty by intention
Expand Down Expand Up @@ -125,6 +135,15 @@ public Source.SourceBuilder parentPom(final ParentPomRef parentPom) {
return this;
}

/**
* @param releaseArtifacts list of release artifact paths, relative to to {@link #path(Path)}
* @return {@code this}.
*/
public Source.SourceBuilder releaseArtifacts(final List<Path> releaseArtifacts) {
this.releaseArtifacts = releaseArtifacts;
return this;
}

/** @return a new instance */
public Source build() {
return new Source(this);
Expand All @@ -134,12 +153,12 @@ public Source build() {
@Override
public String toString() {
return "Source [path=" + path + ", type=" + type + ", modules=" + modules + ", advertise=" + advertise
+ ", parentPom=" + parentPom + "]";
+ ", parentPom=" + parentPom + ", releaseArtifacts=" + releaseArtifacts + "]";
}

@Override
public int hashCode() {
return Objects.hash(path, type, modules, advertise, parentPom);
return Objects.hash(path, type, modules, advertise, parentPom, releaseArtifacts);
}

@Override
Expand All @@ -155,6 +174,7 @@ public boolean equals(final Object obj) {
}
final Source other = (Source) obj;
return Objects.equals(path, other.path) && type == other.type && Objects.equals(modules, other.modules)
&& advertise == other.advertise && Objects.equals(parentPom, other.parentPom);
&& advertise == other.advertise && Objects.equals(parentPom, other.parentPom)
&& Objects.equals(releaseArtifacts, other.releaseArtifacts);
}
}

0 comments on commit 6e0c171

Please sign in to comment.