Merge pull request #73 from ppalaga/i72

CachingProjectBuilder ignored
This commit is contained in:
Peter Palaga
2020-09-29 12:57:13 +02:00
committed by GitHub
27 changed files with 933 additions and 66 deletions

View File

@@ -1,4 +1,20 @@
#!/usr/bin/env bash
#
# 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.
#
set -e
#set -x

View File

@@ -88,6 +88,15 @@ public class ClientLayout extends Layout {
this.logbackConfigurationPath = logbackConfigurationPath;
}
/**
* @param newUserDir where to change the current directory to
* @return a new {@link ClientLayout} with {@code userDir} set to the given {@code newUserDir}
*/
public ClientLayout cd(Path newUserDir) {
return new ClientLayout(mvndPropertiesPath, mavenHome, newUserDir, multiModuleProjectDirectory, javaHome,
localMavenRepository, settings, logbackConfigurationPath);
}
/**
* @return absolute normalized path to local Maven repository or {@code null} if the server is supposed to use the
* default

View File

@@ -27,10 +27,10 @@ public class Layout {
private static Layout ENV_INSTANCE;
private final Path mavenHome;
private final Path userDir;
private final Path multiModuleProjectDirectory;
private final Path mvndPropertiesPath;
protected final Path mavenHome;
protected final Path userDir;
protected final Path multiModuleProjectDirectory;
protected final Path mvndPropertiesPath;
public Layout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path multiModuleProjectDirectory) {
super();

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

View File

@@ -26,6 +26,7 @@ import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientLayout;
import org.jboss.fuse.mvnd.client.ClientOutput;
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
import org.jboss.fuse.mvnd.junit.TestUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@@ -68,9 +69,7 @@ public class ModuleAndPluginNativeIT {
{
final Path mojoPath = layout.multiModuleProjectDirectory()
.resolve("plugin/src/main/java/org/jboss/fuse/mvnd/test/module/plugin/mojo/HelloMojo.java");
String mojoSource = new String(Files.readAllBytes(mojoPath), StandardCharsets.UTF_8);
mojoSource = mojoSource.replace("\"Hello\".getBytes", "\"Hi\".getBytes");
Files.write(mojoPath, mojoSource.getBytes(StandardCharsets.UTF_8));
TestUtils.replace(mojoPath, "\"Hello\".getBytes", "\"Hi\".getBytes");
final ClientOutput output = Mockito.mock(ClientOutput.class);
client.execute(output,

View File

@@ -0,0 +1,80 @@
/*
* 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.it;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import javax.inject.Inject;
import org.assertj.core.api.Assertions;
import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientOutput;
import org.jboss.fuse.mvnd.junit.ClientFactory;
import org.jboss.fuse.mvnd.junit.MvndNativeTest;
import org.jboss.fuse.mvnd.junit.TestLayout;
import org.jboss.fuse.mvnd.junit.TestRegistry;
import org.jboss.fuse.mvnd.junit.TestUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@MvndNativeTest(projectDir = "src/test/projects/upgrades-in-bom")
public class UpgradesInBomNativeIT {
@Inject
TestLayout layout;
@Inject
TestRegistry registry;
@Inject
ClientFactory clientFactory;
@Test
void upgrade() throws IOException, InterruptedException {
/* Install the dependencies */
for (String artifactDir : Arrays.asList("project/hello-0.0.1", "project/hello-0.0.2-SNAPSHOT")) {
final Client cl = clientFactory.newClient(layout.cd(layout.getTestDir().resolve(artifactDir)));
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
registry.killAll();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(0);
/* Build the initial state of the test project */
final Path parentDir = layout.getTestDir().resolve("project/parent");
final Client cl = clientFactory.newClient(layout.cd(parentDir));
{
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
/* Upgrade the dependency */
final Path parentPomPath = parentDir.resolve("pom.xml");
TestUtils.replace(parentPomPath, "<hello.version>0.0.1</hello.version>",
"<hello.version>0.0.2-SNAPSHOT</hello.version>");
/* Adapt the caller */
final Path useHelloPath = parentDir
.resolve("module/src/main/java/org/jboss/fuse/mvnd/test/upgrades/bom/module/UseHello.java");
TestUtils.replace(useHelloPath, "new Hello().sayHello()", "new Hello().sayWisdom()");
{
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.it;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import javax.inject.Inject;
import org.assertj.core.api.Assertions;
import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientOutput;
import org.jboss.fuse.mvnd.junit.ClientFactory;
import org.jboss.fuse.mvnd.junit.MvndTest;
import org.jboss.fuse.mvnd.junit.TestLayout;
import org.jboss.fuse.mvnd.junit.TestRegistry;
import org.jboss.fuse.mvnd.junit.TestUtils;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
@MvndTest(projectDir = "src/test/projects/upgrades-in-bom")
public class UpgradesInBomTest {
@Inject
TestLayout layout;
@Inject
TestRegistry registry;
@Inject
ClientFactory clientFactory;
@Test
void upgrade() throws IOException, InterruptedException {
/* Install the dependencies */
for (String artifactDir : Arrays.asList("project/hello-0.0.1", "project/hello-0.0.2-SNAPSHOT")) {
final Client cl = clientFactory.newClient(layout.cd(layout.getTestDir().resolve(artifactDir)));
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
registry.killAll();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(0);
/* Build the initial state of the test project */
final Path parentDir = layout.getTestDir().resolve("project/parent");
final Client cl = clientFactory.newClient(layout.cd(parentDir));
{
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
/* Upgrade the dependency */
final Path parentPomPath = parentDir.resolve("pom.xml");
TestUtils.replace(parentPomPath, "<hello.version>0.0.1</hello.version>",
"<hello.version>0.0.2-SNAPSHOT</hello.version>");
/* Adapt the caller */
final Path useHelloPath = parentDir
.resolve("module/src/main/java/org/jboss/fuse/mvnd/test/upgrades/bom/module/UseHello.java");
TestUtils.replace(useHelloPath, "new Hello().sayHello()", "new Hello().sayWisdom()");
{
final ClientOutput output = Mockito.mock(ClientOutput.class);
cl.execute(output, "clean", "install", "-e").assertSuccess();
}
Assertions.assertThat(registry.getAll().size()).isEqualTo(1);
}
}

View File

@@ -0,0 +1,23 @@
/*
* 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.junit;
import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientLayout;
public interface ClientFactory {
Client newClient(ClientLayout layout);
}

View File

@@ -22,18 +22,16 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.stream.Stream;
import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.ClientLayout;
import org.jboss.fuse.mvnd.client.DefaultClient;
import org.jboss.fuse.mvnd.common.BuildProperties;
import org.jboss.fuse.mvnd.common.DaemonInfo;
import org.jboss.fuse.mvnd.common.DaemonRegistry;
import org.jboss.fuse.mvnd.common.Environment;
import org.jboss.fuse.mvnd.common.Layout;
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
@@ -92,26 +90,15 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
javax.inject.Inject inject = f.getAnnotation(javax.inject.Inject.class);
if (inject != null) {
f.setAccessible(true);
if (f.getType() == DaemonRegistry.class) {
if (DaemonRegistry.class.isAssignableFrom(f.getType())) {
f.set(testInstance, resource.registry);
} else if (Layout.class.isAssignableFrom(f.getType())) {
f.set(testInstance, resource.layout);
} else if (f.getType() == Client.class) {
if (resource.isNative) {
final Path mvndNativeExecutablePath = resource.layout.mavenHome().resolve(
System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows")
? "bin/mvnd.exe"
: "bin/mvnd")
.toAbsolutePath().normalize();
if (!Files.isRegularFile(mvndNativeExecutablePath)) {
throw new IllegalStateException("mvnd executable does not exist: " + mvndNativeExecutablePath);
}
f.set(testInstance,
new NativeTestClient(resource.layout, mvndNativeExecutablePath, resource.timeoutMs));
} else {
f.set(testInstance, new DefaultClient(() -> resource.layout, BuildProperties.getInstance()));
}
} else if (f.getType() == NativeTestClient.class) {
f.set(testInstance, newClient(resource.isNative, resource.layout, resource.timeoutMs));
} else if (f.getType() == ClientFactory.class) {
final ClientFactory cf = customLayout -> newClient(resource.isNative, customLayout, resource.timeoutMs);
f.set(testInstance, cf);
}
}
}
@@ -119,6 +106,22 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
}
}
Client newClient(boolean isNative, ClientLayout layout, long timeoutMs) {
if (isNative) {
final Path mvndNativeExecutablePath = layout.mavenHome().resolve(
System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("windows")
? "bin/mvnd.exe"
: "bin/mvnd")
.toAbsolutePath().normalize();
if (!Files.isRegularFile(mvndNativeExecutablePath)) {
throw new IllegalStateException("mvnd executable does not exist: " + mvndNativeExecutablePath);
}
return new NativeTestClient(layout, mvndNativeExecutablePath, timeoutMs);
} else {
return new DefaultClient(() -> layout, BuildProperties.getInstance());
}
}
@Override
public void afterAll(ExtensionContext context) throws Exception {
final Store store = context.getRoot().getStore(ExtensionContext.Namespace.GLOBAL);
@@ -131,7 +134,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
static class MvndResource implements ExtensionContext.Store.CloseableResource {
private final TestLayout layout;
private final DaemonRegistry registry;
private final TestRegistry registry;
private final boolean isNative;
private final long timeoutMs;
@@ -195,7 +198,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
localMavenRepository, settingsPath,
mvndHome.resolve("conf/logging/logback.xml"));
final DaemonRegistry registry = new DaemonRegistry(layout.registry());
final TestRegistry registry = new TestRegistry(layout.registry());
return new MvndResource(layout, registry, isNative, timeoutMs);
}
@@ -234,7 +237,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
return settingsPath;
}
public MvndResource(TestLayout layout, DaemonRegistry registry, boolean isNative, long timeoutMs) {
public MvndResource(TestLayout layout, TestRegistry registry, boolean isNative, long timeoutMs) {
super();
this.layout = layout;
this.registry = registry;
@@ -244,25 +247,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
@Override
public void close() throws Exception {
List<DaemonInfo> daemons;
final int timeout = 5000;
final long deadline = System.currentTimeMillis() + timeout;
while (!(daemons = registry.getAll()).isEmpty()) {
for (DaemonInfo di : daemons) {
try {
new ProcessImpl(di.getPid()).destroy();
} catch (IOException t) {
System.out.println("Daemon " + di.getUid() + ": " + t.getMessage());
} catch (Exception t) {
System.out.println("Daemon " + di.getUid() + ": " + t);
} finally {
registry.remove(di.getUid());
}
}
if (deadline < System.currentTimeMillis() && !registry.getAll().isEmpty()) {
throw new RuntimeException("Could not stop all mvnd daemons within " + timeout + " ms");
}
}
registry.killAll();
}
}

View File

@@ -0,0 +1,53 @@
/*
* 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.junit;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import org.jboss.fuse.mvnd.common.DaemonInfo;
import org.jboss.fuse.mvnd.common.DaemonRegistry;
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
public class TestRegistry extends DaemonRegistry {
public TestRegistry(Path registryFile) {
super(registryFile);
}
public void killAll() {
List<DaemonInfo> daemons;
final int timeout = 5000;
final long deadline = System.currentTimeMillis() + timeout;
while (!(daemons = getAll()).isEmpty()) {
for (DaemonInfo di : daemons) {
try {
new ProcessImpl(di.getPid()).destroy();
} catch (IOException t) {
System.out.println("Daemon " + di.getUid() + ": " + t.getMessage());
} catch (Exception t) {
System.out.println("Daemon " + di.getUid() + ": " + t);
} finally {
remove(di.getUid());
}
}
if (deadline < System.currentTimeMillis() && !getAll().isEmpty()) {
throw new RuntimeException("Could not stop all mvnd daemons within " + timeout + " ms");
}
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* 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.junit;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
public class TestUtils {
public static void replace(Path path, String find, String replacement) {
try {
final String originalSrc = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
final String newSrc = originalSrc.replace(find, replacement);
if (originalSrc.equals(newSrc)) {
throw new IllegalStateException("[" + find + "] not found in " + path);
}
Files.write(path, newSrc.getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
throw new RuntimeException("Could not read or write " + path, e);
}
}
}

View File

@@ -30,7 +30,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>

View File

@@ -30,7 +30,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>

View File

@@ -30,7 +30,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>

View File

@@ -0,0 +1,71 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-hello</artifactId>
<version>0.0.1</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -0,0 +1,24 @@
/*
* 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.test.upgrades.bom.hello;
public class Hello {
public String sayHello() {
return "Hello";
}
}

View File

@@ -0,0 +1,71 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-hello</artifactId>
<version>0.0.2-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -0,0 +1,24 @@
/*
* 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.test.upgrades.bom.hello;
public class Hello {
public int sayWisdom() {
return 42;
}
}

View File

@@ -0,0 +1,41 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>upgrades-in-bom-bom</artifactId>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-hello</artifactId>
<version>${hello.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

View File

@@ -0,0 +1,49 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>upgrades-in-bom-module</artifactId>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-bom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-hello</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,26 @@
/*
* 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.test.upgrades.bom.module;
import org.jboss.fuse.mvnd.test.upgrades.bom.hello.Hello;
public class UseHello {
public void use() {
System.out.println(new Hello().sayHello());
}
}

View File

@@ -0,0 +1,77 @@
<!--
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.
-->
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.fuse.mvnd.test.upgrades-in-bom</groupId>
<artifactId>upgrades-in-bom-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<hello.version>0.0.1</hello.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven-clean-plugin.version>2.5</maven-clean-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-install-plugin.version>2.4</maven-install-plugin.version>
<maven-resources-plugin.version>2.6</maven-resources-plugin.version>
<maven-surefire-plugin.version>3.0.0-M4</maven-surefire-plugin.version>
</properties>
<modules>
<module>bom</module>
<module>module</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${maven-install-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>