Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I417 #450

Merged
merged 8 commits into from
Aug 31, 2021
Merged

I417 #450

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ name: GitHub Actions
on: [push, pull_request]

env:
GRAALVM_VERSION: '21.1.0.java16'
GRAALVM_VERSION: '20.3.0.java11'

jobs:

linux-jdk16:
linux-jdk11:
runs-on: ubuntu-18.04
steps:

Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
name: mvnd-linux-amd64.zip
path: dist/target/mvnd-*.zip

windows-jdk16:
windows-jdk11:
runs-on: windows-2019
steps:

Expand Down Expand Up @@ -128,7 +128,7 @@ jobs:
name: mvnd-windows-amd64.zip
path: dist/target/mvnd-*.zip

darwin-jdk16:
darwin-jdk11:
runs-on: macos-10.15
steps:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ name: GitHub Actions
on: [push, pull_request]

env:
GRAALVM_VERSION: '20.3.0.java11'
GRAALVM_VERSION: '21.1.0.java16'

jobs:

Expand Down
4 changes: 2 additions & 2 deletions build-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<name>Maven Daemon - Documentation Maven Plugin</name>

<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>

<roaster.version>2.22.2.Final</roaster.version>
<maven.plugin-tools.version>3.6.0</maven.plugin-tools.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import javax.security.sasl.SaslClientFactory;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand Down Expand Up @@ -124,7 +123,7 @@ public boolean hasMoreElements() {
}

public Object nextElement() {
return (SaslClientFactory) it.next();
return it.next();
}
};
}
Expand Down
73 changes: 61 additions & 12 deletions client/src/main/java/org/mvndaemon/mvnd/client/DaemonConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
package org.mvndaemon.mvnd.client;

import java.io.File;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.io.IOException;
import java.net.SocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.file.Files;
Expand All @@ -32,6 +31,7 @@
import java.util.Optional;
import java.util.Properties;
import java.util.Random;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
Expand All @@ -49,6 +49,7 @@
import org.mvndaemon.mvnd.common.MavenDaemon;
import org.mvndaemon.mvnd.common.Message;
import org.mvndaemon.mvnd.common.Os;
import org.mvndaemon.mvnd.common.SocketFamily;
import org.mvndaemon.mvnd.common.logging.ClientOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -371,6 +372,10 @@ private Process startDaemonProcess(String daemonId) {
Environment.MVND_ID.addCommandLineOption(args, daemonId);
Environment.MVND_DAEMON_STORAGE.addCommandLineOption(args, parameters.daemonStorage().toString());
Environment.MVND_REGISTRY.addCommandLineOption(args, parameters.registry().toString());
Environment.MVND_SOCKET_FAMILY.addCommandLineOption(args,
parameters.socketFamily().orElseGet(
() -> getJavaVersion() >= 16.0f ? SocketFamily.unix : SocketFamily.inet)
.toString());
parameters.discriminatingCommandLineOptions(args);
args.add(MavenDaemon.class.getName());
command = String.join(" ", args);
Expand All @@ -394,6 +399,31 @@ private Process startDaemonProcess(String daemonId) {
}
}

private float getJavaVersion() {
try {
final String java = Os.current().isUnixLike() ? "bin/java" : "bin\\java.exe";
Path javaExec = parameters.javaHome().resolve(java);
List<String> args = new ArrayList<>();
args.add(javaExec.toString());
args.add("-version");
Process process = new ProcessBuilder()
.directory(parameters.mvndHome().toFile())
.command(args)
.start();
process.waitFor();
Scanner sc = new Scanner(process.getErrorStream());
sc.next();
sc.next();
String version = sc.next();
LOGGER.warn("JAVA VERSION: " + version);
int is = version.charAt(0) == '"' ? 1 : 0;
int ie = version.indexOf('.', version.indexOf('.', is));
return Float.parseFloat(version.substring(is, ie));
} catch (Exception e) {
throw new IllegalStateException("Unable to detect java version", e);
}
}

private DaemonClientConnection connectToDaemonWithId(String daemon, boolean newDaemon)
throws DaemonException.ConnectException {
// Look for 'our' daemon among the busy daemons - a daemon will start in busy state so that nobody else will
Expand Down Expand Up @@ -444,18 +474,37 @@ public boolean maybeStaleAddress(Exception failure) {
}
}

public DaemonConnection connect(int port, byte[] token) throws DaemonException.ConnectException {
InetSocketAddress address = new InetSocketAddress(InetAddress.getLoopbackAddress(), port);
public DaemonConnection connect(String str, byte[] token) throws DaemonException.ConnectException {
SocketAddress address = SocketFamily.fromString(str);
try {
LOGGER.debug("Trying to connect to address {}.", address);
SocketChannel socketChannel = SocketChannel.open();
Socket socket = socketChannel.socket();
socket.connect(address, CONNECT_TIMEOUT);
if (socket.getLocalSocketAddress().equals(socket.getRemoteSocketAddress())) {
socketChannel.close();
throw new DaemonException.ConnectException(String.format("Socket connected to itself on %s.", address));
SocketFamily family = SocketFamily.familyOf(address);
SocketChannel socketChannel = family.openSocket();
socketChannel.configureBlocking(false);
boolean connected = socketChannel.connect(address);
if (!connected) {
long t0 = System.nanoTime();
long t1 = t0 + TimeUnit.MICROSECONDS.toNanos(CONNECT_TIMEOUT);
while (!connected && t0 < t1) {
Thread.sleep(10);
connected = socketChannel.finishConnect();
if (!connected) {
t0 = System.nanoTime();
}
}
if (!connected) {
throw new IOException("Timeout");
}
}
LOGGER.debug("Connected to address {}.", socket.getRemoteSocketAddress());
socketChannel.configureBlocking(true);

// Socket socket = socketChannel.socket();
// socket.connect(address, CONNECT_TIMEOUT);
// if (socket.getLocalSocketAddress().equals(socket.getRemoteSocketAddress())) {
// socketChannel.close();
// throw new DaemonException.ConnectException(String.format("Socket connected to itself on %s.", address));
// }
LOGGER.debug("Connected to address {}.", socketChannel.getRemoteAddress());

ByteBuffer tokenBuffer = ByteBuffer.wrap(token);
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.mvndaemon.mvnd.common.BuildProperties;
import org.mvndaemon.mvnd.common.Environment;
import org.mvndaemon.mvnd.common.Os;
import org.mvndaemon.mvnd.common.SocketFamily;
import org.mvndaemon.mvnd.common.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -323,6 +324,10 @@ public Duration purgeLogPeriod() {
return property(Environment.MVND_LOG_PURGE_PERIOD).orFail().asDuration();
}

public Optional<SocketFamily> socketFamily() {
return property(Environment.MVND_SOCKET_FAMILY).asOptional().map(SocketFamily::valueOf);
}

public static String findDefaultMultimoduleProjectDirectory(Path pwd) {
Path dir = pwd;
do {
Expand Down
138 changes: 128 additions & 10 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,135 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>jdk11-15</id>
<activation>
<jdk>[11,15)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>jdk11</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<release>11</release>
<multiReleaseOutput>true</multiReleaseOutput>
<compileSourceRoots>
<root>${project.basedir}/src/main/java11</root>
</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>jdk16+</id>
<activation>
<jdk>[16,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>jdk11</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<release>11</release>
<multiReleaseOutput>true</multiReleaseOutput>
<compileSourceRoots>
<root>${project.basedir}/src/main/java11</root>
</compileSourceRoots>
</configuration>
</execution>
<execution>
<id>jdk16</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>-XDignore.symbol.file</arg>
</compilerArgs>
<release>16</release>
<multiReleaseOutput>true</multiReleaseOutput>
<compileSourceRoots>
<root>${project.basedir}/src/main/java16</root>
</compileSourceRoots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Loading