CachingProjectBuilder ignored #72

This commit is contained in:
Peter Palaga
2020-09-29 09:47:07 +02:00
parent 9c1b63eb16
commit 16a93e4a3a
5 changed files with 217 additions and 15 deletions

View File

@@ -28,11 +28,21 @@ public class ServerMain {
final String uidStr = Environment.DAEMON_UID.systemProperty().orFail().asString();
final Path mavenHome = Environment.MVND_HOME.systemProperty().orFail().asPath();
URL[] classpath = Stream.concat(
Stream.concat(Files.list(mavenHome.resolve("lib/ext")),
Files.list(mavenHome.resolve("lib")))
/* jars */
Stream.of("lib/ext", "lib", "boot")
.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),
/* resources */
Stream.of(mavenHome.resolve("conf"), mavenHome.resolve("conf/logging")))
.map(Path::normalize)
.map(Path::toUri)
.map(uri -> {
@@ -56,6 +66,7 @@ public class ServerMain {
Thread.currentThread().setContextClassLoader(loader);
Class<?> clazz = loader.loadClass("org.jboss.fuse.mvnd.daemon.Server");
try (AutoCloseable server = (AutoCloseable) clazz.getConstructor(String.class).newInstance(uidStr)) {
System.out.println("server = " + server);
((Runnable) server).run();
}
}

View File

@@ -92,6 +92,23 @@
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<mvnd.home>${project.basedir}/target/maven-distro/mvnd-${project.version}-${os.detected.name}-${os.detected.arch}</mvnd.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.takari.maven.plugins</groupId>
<artifactId>takari-lifecycle-plugin</artifactId>

View File

@@ -69,15 +69,15 @@ public class Server implements AutoCloseable, Runnable {
public static final int CANCEL_TIMEOUT = 10 * 1000;
public static final int DEFAULT_IDLE_TIMEOUT = (int) TimeUnit.HOURS.toMillis(3);
private String uid;
private ServerSocketChannel socket;
private DaemonMavenCli cli;
private DaemonInfo info;
private DaemonRegistry registry;
private final String uid;
private final ServerSocketChannel socket;
private final DaemonMavenCli cli;
private volatile DaemonInfo info;
private final DaemonRegistry registry;
private final Layout layout;
private ScheduledExecutorService executor;
private DaemonExpirationStrategy strategy;
private final ScheduledExecutorService executor;
private final DaemonExpirationStrategy strategy;
private final Lock expirationLock = new ReentrantLock();
private final Lock stateLock = new ReentrantLock();
private final Condition condition = stateLock.newCondition();
@@ -106,8 +106,8 @@ public class Server implements AutoCloseable, Runnable {
idleTimeout, Locale.getDefault().toLanguageTag(), opts,
Busy, cur, cur);
registry.store(info);
} catch (Throwable t) {
LOGGER.error("Error initializing daemon: " + t, t);
} catch (Exception e) {
throw new RuntimeException("Could not initialize " + Server.class.getName(), e);
}
}

View File

@@ -20,13 +20,46 @@
<artifactSet to="mvnd-${project.version}-${os.detected.name}-${os.detected.arch}">
<artifact id="org.apache.maven:apache-maven:tar.gz:bin">
<unpack useRoot="false"
excludes="lib/slf4j*,conf/logging/*,lib/maven-slf4j-provider*,bin/mvn*"/>
excludes="lib/slf4j*,conf/logging/*,lib/maven-slf4j-provider*,bin/mvn*,lib/jansi-*.jar,lib/jansi-native/*"/>
</artifact>
</artifactSet>
<artifactSet to="mvnd-${project.version}-${os.detected.name}-${os.detected.arch}/lib">
<artifact id="org.apache.maven:maven-embedder"/>
<artifactSet to="ext" ref="runtime.classpath"/>
<artifactSet to="mvnd-${project.version}-${os.detected.name}-${os.detected.arch}/lib/ext">
<artifact id="org.jboss.fuse.mvnd:mvnd-daemon:${project.version}">
<exclusion id="org.codehaus.plexus:plexus-classworlds"/>
<exclusion id="*:cdi-api"/>
<exclusion id="*:commons-cli"/>
<exclusion id="*:commons-io"/>
<exclusion id="*:commons-lang3"/>
<exclusion id="*:guava"/>
<exclusion id="*:guice"/>
<exclusion id="*:javax.inject"/>
<exclusion id="*:jcl-over-slf4j"/>
<exclusion id="*:jsr250-api"/>
<exclusion id="*:maven-artifact"/>
<exclusion id="*:maven-builder-support"/>
<exclusion id="*:maven-core"/>
<exclusion id="*:maven-embedder"/>
<exclusion id="*:maven-model"/>
<exclusion id="*:maven-model-builder"/>
<exclusion id="*:maven-plugin-api"/>
<exclusion id="*:maven-repository-metadata"/>
<exclusion id="*:maven-resolver-api"/>
<exclusion id="*:maven-resolver-impl"/>
<exclusion id="*:maven-resolver-provider"/>
<exclusion id="*:maven-resolver-spi"/>
<exclusion id="*:maven-resolver-util"/>
<exclusion id="*:maven-settings"/>
<exclusion id="*:maven-settings-builder"/>
<exclusion id="*:maven-shared-utils"/>
<exclusion id="*:org.eclipse.sisu.inject"/>
<exclusion id="*:org.eclipse.sisu.plexus"/>
<exclusion id="*:plexus-cipher"/>
<exclusion id="*:plexus-component-annotations"/>
<exclusion id="*:plexus-interpolation"/>
<exclusion id="*:plexus-sec-dispatcher"/>
<exclusion id="*:plexus-utils"/>
</artifact>
</artifactSet>
<fileSet to="mvnd-${project.version}-${os.detected.name}-${os.detected.arch}">

View File

@@ -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);
}
}
}