-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
219 additions
and
16 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
shared/src/main/java/eu/maveniverse/maven/toolbox/shared/ArtifactSink.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,28 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.shared; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import org.eclipse.aether.artifact.Artifact; | ||
|
||
/** | ||
* Construction to accept collection of artifacts, for example like a filesystem directory. | ||
*/ | ||
public interface ArtifactSink { | ||
default void accept(Collection<Artifact> artifacts) throws IOException { | ||
requireNonNull(artifacts, "artifacts"); | ||
for (Artifact artifact : artifacts) { | ||
accept(artifact); | ||
} | ||
} | ||
|
||
void accept(Artifact artifact) throws IOException; | ||
} |
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
56 changes: 56 additions & 0 deletions
56
shared/src/test/java/eu/maveniverse/maven/toolbox/shared/DirectorySinkTest.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,56 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.shared; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
public class DirectorySinkTest { | ||
@Test | ||
void smoke(@TempDir Path source, @TempDir Path target) throws IOException { | ||
DirectorySink sink = DirectorySink.flat(new NullOutput(), target); | ||
Path a1 = source.resolve("a1"); | ||
Path a2 = source.resolve("a2"); | ||
Files.writeString(a1, "one", StandardCharsets.UTF_8); | ||
Files.writeString(a2, "two", StandardCharsets.UTF_8); | ||
sink.accept(Arrays.asList( | ||
new DefaultArtifact("g:a1:1").setFile(a1.toFile()), | ||
new DefaultArtifact("g:a2:1").setFile(a2.toFile()))); | ||
|
||
Path a1target = target.resolve("a1-1.jar"); | ||
Path a2target = target.resolve("a2-1.jar"); | ||
assertTrue(Files.isRegularFile(a1target)); | ||
assertEquals(Files.readString(a1target, StandardCharsets.UTF_8), "one"); | ||
assertTrue(Files.isRegularFile(a2target)); | ||
assertEquals(Files.readString(a2target, StandardCharsets.UTF_8), "two"); | ||
} | ||
|
||
@Test | ||
void sameA(@TempDir Path source, @TempDir Path target) throws IOException { | ||
DirectorySink sink = DirectorySink.flat(new NullOutput(), target); | ||
Path a1 = source.resolve("a1"); | ||
Path a2 = source.resolve("a2"); | ||
Files.writeString(a1, "one", StandardCharsets.UTF_8); | ||
Files.writeString(a2, "two", StandardCharsets.UTF_8); | ||
assertThrows( | ||
IOException.class, | ||
() -> sink.accept(Arrays.asList( | ||
new DefaultArtifact("g1:a1:1").setFile(a1.toFile()), | ||
new DefaultArtifact("g2:a1:1").setFile(a2.toFile())))); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
shared/src/test/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMapperTest.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,34 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.shared.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ArtifactMapperTest { | ||
@Test | ||
void identity() { | ||
DefaultArtifact a = new DefaultArtifact("a:b:c"); | ||
Artifact other = ArtifactMapper.identity().map(a); | ||
assertEquals(a, other); | ||
} | ||
|
||
@Test | ||
void allOfThemComposed() { | ||
Artifact mapped = ArtifactMapper.compose( | ||
ArtifactMapper.identity(), | ||
ArtifactMapper.baseVersion(), | ||
ArtifactMapper.omitClassifier(), | ||
ArtifactMapper.rename("g1", "a1", null)) | ||
.map(new DefaultArtifact("g:a:jar:classifier:1.0-20240322.090900-12")); | ||
assertEquals(new DefaultArtifact("g1:a1:1.0-SNAPSHOT"), mapped); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
shared/src/test/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactMatcherTest.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,63 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.shared.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Mapper that maps artifact to artifact. | ||
*/ | ||
public class ArtifactMatcherTest { | ||
private final Artifact artifact = new DefaultArtifact("g:a:v"); | ||
|
||
@Test | ||
void any() { | ||
assertTrue(ArtifactMatcher.any().test(artifact)); | ||
assertTrue(ArtifactMatcher.artifact("*").test(artifact)); | ||
} | ||
|
||
@Test | ||
void unique() { | ||
ArtifactMatcher matcher = ArtifactMatcher.unique(); | ||
assertTrue(matcher.test(artifact)); | ||
assertFalse(matcher.test(artifact)); | ||
} | ||
|
||
@Test | ||
void composedAnd() { | ||
assertTrue(ArtifactMatcher.and( | ||
ArtifactMatcher.artifact("g:*:*"), | ||
ArtifactMatcher.artifact("*:a:*"), | ||
ArtifactMatcher.artifact("*:*:v")) | ||
.test(artifact)); | ||
} | ||
|
||
@Test | ||
void composedOr() { | ||
assertTrue(ArtifactMatcher.or( | ||
ArtifactMatcher.artifact("foo:*:*"), | ||
ArtifactMatcher.artifact("*:foo:*"), | ||
ArtifactMatcher.artifact("*:*:v")) | ||
.test(artifact)); | ||
} | ||
|
||
@Test | ||
void startsWith() { | ||
assertTrue(ArtifactMatcher.artifact("g*:a*:v*").test(artifact)); | ||
} | ||
|
||
@Test | ||
void endsWith() { | ||
assertTrue(ArtifactMatcher.artifact("*g:*a:*v").test(artifact)); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ed/src/test/java/eu/maveniverse/maven/toolbox/shared/internal/ArtifactNameMapperTest.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,25 @@ | ||
/* | ||
* Copyright (c) 2023-2024 Maveniverse Org. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
package eu.maveniverse.maven.toolbox.shared.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.aether.artifact.Artifact; | ||
import org.eclipse.aether.artifact.DefaultArtifact; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ArtifactNameMapperTest { | ||
private final Artifact artifact = new DefaultArtifact("g:a:v"); | ||
|
||
@Test | ||
void compose() { | ||
ArtifactNameMapper mapper = | ||
ArtifactNameMapper.compose(ArtifactNameMapper.prefix("foo/"), ArtifactNameMapper.ACVE()); | ||
assertEquals(mapper.map(artifact), "foo/a-v.jar"); | ||
} | ||
} |