-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from ppalaga/i72
CachingProjectBuilder ignored
- Loading branch information
Showing
27 changed files
with
933 additions
and
66 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
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
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
141 changes: 141 additions & 0 deletions
141
daemon/src/test/java/org/jboss/fuse/mvnd/dist/DistroIT.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,141 @@ | ||
/* | ||
* Copyright 2019 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.fuse.mvnd.dist; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DistroIT { | ||
|
||
/** | ||
* Asserts that we do not have the same libs in lib/ext and in lib or boot directories. | ||
*/ | ||
@Test | ||
void noDuplicateJars() { | ||
final Path mavenHome = Paths.get(System.getProperty("mvnd.home")); | ||
Set<Avc> mavenLibs = streamJars(mavenHome, "lib", "boot").collect(Collectors.toCollection(TreeSet::new)); | ||
Assertions.assertFalse(mavenLibs.isEmpty()); | ||
final List<Avc> mvndJars = streamJars(mavenHome, "lib/ext").collect(Collectors.toList()); | ||
Assertions.assertFalse(mvndJars.isEmpty()); | ||
|
||
final List<Avc> dups = mvndJars.stream() | ||
.filter(avc -> mavenLibs.stream().anyMatch(mvnAvc -> mvnAvc.sameArtifactId(avc))) | ||
.collect(Collectors.toList()); | ||
|
||
final String msg = mavenHome.resolve("lib/ext") + " contains duplicates available in " + mavenHome.resolve("lib") | ||
+ " or " + mavenHome.resolve("lib"); | ||
Assertions.assertEquals(new ArrayList<String>(), dups, msg); | ||
} | ||
|
||
@Test | ||
void avcOf() { | ||
assertAvcOf("foo-bar-1.2.3.jar", "foo-bar", "1.2.3", null); | ||
assertAvcOf("foo_bar-1.2.3-classifier.jar", "foo_bar", "1.2.3", "classifier"); | ||
} | ||
|
||
void assertAvcOf(String jarName, String artifactId, String version, String classifier) { | ||
Avc avc = Avc.of(jarName); | ||
Assertions.assertEquals(artifactId, avc.artifactId, "artifactId in " + jarName); | ||
Assertions.assertEquals(version, avc.version, "version in " + jarName); | ||
Assertions.assertEquals(classifier, avc.classifier, "classifier in " + jarName); | ||
} | ||
|
||
private static Stream<Avc> streamJars(Path mavenHome, String... dirs) { | ||
return Stream.of(dirs) | ||
.map(mavenHome::resolve) | ||
.flatMap((Path p) -> { | ||
try { | ||
return Files.list(p); | ||
} catch (java.io.IOException e) { | ||
throw new RuntimeException("Could not list " + p, e); | ||
} | ||
}) | ||
.filter(p -> p.getFileName().toString().endsWith(".jar")) | ||
.filter(Files::isRegularFile) | ||
.map(Path::getFileName) | ||
.map(Path::toString) | ||
.map(Avc::of); | ||
} | ||
|
||
static class Avc implements Comparable<Avc> { | ||
|
||
private static final Pattern JAR_NAME_PATTERN = Pattern.compile("^(.*)(?:-([0-9]+(?:\\.[0-9]+)*))(?:-(.*))?.jar$"); | ||
|
||
public static Avc of(String jarName) { | ||
final Matcher m = JAR_NAME_PATTERN.matcher(jarName); | ||
if (m.find()) { | ||
return new Avc(m.group(1), m.group(2), m.group(3), jarName); | ||
} else { | ||
throw new IllegalStateException("Jar name " + jarName + " does not match " + JAR_NAME_PATTERN.pattern()); | ||
} | ||
} | ||
|
||
private final String artifactId; | ||
private final String version; | ||
private final String classifier; | ||
private final String jarName; | ||
|
||
public Avc(String artifactId, String version, String classifier, String jarName) { | ||
this.artifactId = artifactId; | ||
this.version = version; | ||
this.classifier = classifier; | ||
this.jarName = jarName; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return jarName; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return jarName.hashCode(); | ||
} | ||
|
||
public boolean sameArtifactId(Avc other) { | ||
return this.artifactId.equals(other.artifactId); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) | ||
return true; | ||
if (obj == null) | ||
return false; | ||
if (getClass() != obj.getClass()) | ||
return false; | ||
Avc other = (Avc) obj; | ||
return this.jarName.equals(other.jarName); | ||
} | ||
|
||
@Override | ||
public int compareTo(Avc other) { | ||
return this.jarName.compareTo(other.jarName); | ||
} | ||
|
||
} | ||
} |
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
Oops, something went wrong.