Skip to content

Commit

Permalink
Merge pull request #73 from ppalaga/i72
Browse files Browse the repository at this point in the history
 CachingProjectBuilder ignored
  • Loading branch information
ppalaga authored Sep 29, 2020
2 parents b0e6dfc + 16a93e4 commit 8e831e8
Show file tree
Hide file tree
Showing 27 changed files with 933 additions and 66 deletions.
16 changes: 16 additions & 0 deletions build/publish-on-sdkman.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ public ClientLayout(Path mvndPropertiesPath, Path mavenHome, Path userDir, Path
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
Expand Down
8 changes: 4 additions & 4 deletions common/src/main/java/org/jboss/fuse/mvnd/common/Layout.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 13 additions & 2 deletions common/src/main/java/org/jboss/fuse/mvnd/common/ServerMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ public static void main(String[] args) throws Exception {
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 -> {
Expand All @@ -56,6 +66,7 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
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();
}
}
Expand Down
17 changes: 17 additions & 0 deletions daemon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 9 additions & 9 deletions daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -106,8 +106,8 @@ public Server(String uid) throws IOException {
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);
}
}

Expand Down
41 changes: 37 additions & 4 deletions daemon/src/main/provisio/maven-distro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
Expand Down
141 changes: 141 additions & 0 deletions daemon/src/test/java/org/jboss/fuse/mvnd/dist/DistroIT.java
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);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
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;

Expand Down Expand Up @@ -68,9 +69,7 @@ void cleanInstall() throws IOException, InterruptedException {
{
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,
Expand Down
Loading

0 comments on commit 8e831e8

Please sign in to comment.