Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Mar 24, 2024
1 parent e9f5eac commit 4a1ab6a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ default void accept(Collection<Artifact> artifacts) throws IOException {
for (Artifact artifact : artifacts) {
accept(artifact);
}
} catch (IOException e) {
} catch (Exception e) {
cleanup(e);
throw e;
}
}

void accept(Artifact artifact) throws IOException;

default void cleanup(IOException e) {}
default void cleanup(Exception e) {}

default void close() throws Exception {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,24 @@ public final class DirectorySink implements ArtifactSink {
*/
public static DirectorySink flat(Output output, Path path) throws IOException {
return new DirectorySink(
output, path, Mode.COPY, ArtifactMatcher.unique(), a -> a, ArtifactNameMapper.GACE(), false);
output, path, Mode.COPY, ArtifactMatcher.unique(), false, a -> a, ArtifactNameMapper.GACE(), false);
}

/**
* Creates "repository" directory sink, that accepts all artifacts and copies them out having filenames as
* a "remote repository" (usable as file based remote repository, or can be published via HTTP). It also
* prevents overwrite (what you usually want). This repository may ve handy for testing, but does not serve
* as interchangeable solution of installing or deploying artifacts for real.
* Creates "repository" directory sink, that accepts all non-snapshot artifacts and copies them out having
* filenames as a "remote repository" (usable as file based remote repository, or can be published via HTTP). It
* also prevents overwrite (what you usually want). This repository may be handy for testing, but does not serve
* as interchangeable solution of installing or deploying artifacts for real. This sink accepts release artifacts
* only, and fails with snapshot ones, as this is not equivalent to deploy them (no timestamped version is
* created).
*/
public static DirectorySink repository(Output output, Path path) throws IOException {
return new DirectorySink(
output,
path,
Mode.COPY,
ArtifactMatcher.unique(),
ArtifactMatcher.and(ArtifactMatcher.not(ArtifactMatcher.snapshot()), ArtifactMatcher.unique()),
true,
a -> a,
ArtifactNameMapper.repositoryDefault(File.separator),
false);
Expand All @@ -66,6 +69,7 @@ public enum Mode {
private final boolean directoryCreated;
private final Mode mode;
private final Predicate<Artifact> artifactMatcher;
private final boolean failIfUnmatched;
private final Function<Artifact, Artifact> artifactMapper;
private final Function<Artifact, String> artifactNameMapper;
private final boolean allowOverwrite;
Expand All @@ -90,6 +94,7 @@ private DirectorySink(
Path directory,
Mode mode,
ArtifactMatcher artifactMatcher,
boolean failIfUnmatched,
ArtifactMapper artifactMapper,
ArtifactNameMapper artifactNameMapper,
boolean allowOverwrite)
Expand All @@ -108,6 +113,7 @@ private DirectorySink(
}

this.artifactMatcher = requireNonNull(artifactMatcher, "artifactMatcher");
this.failIfUnmatched = failIfUnmatched;
this.artifactMapper = requireNonNull(artifactMapper, "artifactMapper");
this.artifactNameMapper = requireNonNull(artifactNameMapper, "artifactNameMapper");
this.allowOverwrite = allowOverwrite;
Expand Down Expand Up @@ -154,12 +160,16 @@ public void accept(Artifact artifact) throws IOException {
throw new IllegalArgumentException("unknown mode");
}
} else {
output.verbose(" not matched");
if (failIfUnmatched) {
throw new IllegalArgumentException("not matched");
} else {
output.verbose(" not matched");
}
}
}

@Override
public void cleanup(IOException e) {
public void cleanup(Exception e) {
output.error("Cleaning up: {}", directory);
writtenPaths.forEach(p -> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void accept(Artifact artifact) throws IOException {
}

@Override
public void cleanup(IOException e) {
public void cleanup(Exception e) {
sinks.values().forEach(a -> a.cleanup(e));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void accept(Artifact artifact) {
}

@Override
public void cleanup(IOException e) {
public void cleanup(Exception e) {
perform.set(false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ static ArtifactMatcher any() {
return artifact("*");
}

static ArtifactMatcher snapshot() {
return new ArtifactMatcher() {
@Override
public boolean test(Artifact artifact) {
return artifact.isSnapshot();
}
};
}

static ArtifactMatcher unique() {
return uniqueBy(ArtifactNameMapper.GACEVKey());
}
Expand Down

0 comments on commit 4a1ab6a

Please sign in to comment.