mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-10-15 06:40:54 +00:00
This commit is contained in:
@@ -23,8 +23,10 @@ import static org.mvndaemon.mvnd.common.DaemonState.Canceled;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.ServerSocketChannel;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -122,7 +124,7 @@ public class DaemonConnector {
|
|||||||
final String daemonId = newId();
|
final String daemonId = newId();
|
||||||
String message = handleStopEvents(daemonId, idleDaemons, busyDaemons);
|
String message = handleStopEvents(daemonId, idleDaemons, busyDaemons);
|
||||||
output.accept(Message.buildStatus(message));
|
output.accept(Message.buildStatus(message));
|
||||||
return startDaemon(daemonId);
|
return startDaemon(daemonId, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DaemonClientConnection connectNoDaemon() {
|
private DaemonClientConnection connectNoDaemon() {
|
||||||
@@ -297,8 +299,8 @@ public class DaemonConnector {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DaemonClientConnection startDaemon(String daemonId) {
|
public DaemonClientConnection startDaemon(String daemonId, ClientOutput output) {
|
||||||
final Process process = startDaemonProcess(daemonId);
|
final Process process = startDaemonProcess(daemonId, output);
|
||||||
LOGGER.debug("Started Maven daemon {}", daemonId);
|
LOGGER.debug("Started Maven daemon {}", daemonId);
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
do {
|
do {
|
||||||
@@ -321,7 +323,7 @@ public class DaemonConnector {
|
|||||||
return String.format("%08x", new Random().nextInt());
|
return String.format("%08x", new Random().nextInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Process startDaemonProcess(String daemonId) {
|
private Process startDaemonProcess(String daemonId, ClientOutput output) {
|
||||||
final Path mvndHome = parameters.mvndHome();
|
final Path mvndHome = parameters.mvndHome();
|
||||||
final Path workingDir = parameters.userDir();
|
final Path workingDir = parameters.userDir();
|
||||||
String command = "";
|
String command = "";
|
||||||
@@ -354,7 +356,32 @@ public class DaemonConnector {
|
|||||||
args.add("-javaagent:" + mvndAgentPath);
|
args.add("-javaagent:" + mvndAgentPath);
|
||||||
// debug options
|
// debug options
|
||||||
if (parameters.property(Environment.MVND_DEBUG).asBoolean()) {
|
if (parameters.property(Environment.MVND_DEBUG).asBoolean()) {
|
||||||
args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000");
|
String address =
|
||||||
|
parameters.property(Environment.MVND_DEBUG_ADDRESS).asString();
|
||||||
|
String host;
|
||||||
|
String port;
|
||||||
|
int column = address.indexOf(':');
|
||||||
|
if (column >= 0) {
|
||||||
|
host = address.substring(0, column);
|
||||||
|
port = address.substring(column + 1);
|
||||||
|
} else {
|
||||||
|
host = "localhost";
|
||||||
|
port = address;
|
||||||
|
}
|
||||||
|
if (!port.matches("[0-9]+")) {
|
||||||
|
throw new IllegalArgumentException("Wrong debug address syntax: " + address);
|
||||||
|
}
|
||||||
|
int iPort = Integer.parseInt(port);
|
||||||
|
if (iPort == 0) {
|
||||||
|
try (ServerSocketChannel channel = SocketFamily.inet.openServerSocket()) {
|
||||||
|
iPort = ((InetSocketAddress) channel.getLocalAddress()).getPort();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Unable to find a free debug port", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
address = host + ":" + iPort;
|
||||||
|
output.accept(Message.buildStatus("Daemon listening for debugger on address: " + address));
|
||||||
|
args.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + address);
|
||||||
}
|
}
|
||||||
// jvm args
|
// jvm args
|
||||||
String jvmArgs = parameters.jvmArgs();
|
String jvmArgs = parameters.jvmArgs();
|
||||||
|
@@ -169,6 +169,13 @@ public enum Environment {
|
|||||||
* not passed to the daemon.
|
* not passed to the daemon.
|
||||||
*/
|
*/
|
||||||
MVND_DEBUG("mvnd.debug", null, Boolean.FALSE, OptionType.BOOLEAN, Flags.DISCRIMINATING),
|
MVND_DEBUG("mvnd.debug", null, Boolean.FALSE, OptionType.BOOLEAN, Flags.DISCRIMINATING),
|
||||||
|
/**
|
||||||
|
* The tcp address used to launch the debug mode. Defaults to <code>8000</code>, which is similar to
|
||||||
|
* <code>localhost:8000</code>. In order to remote debug from a different computer, you need to allow
|
||||||
|
* remote connections using <code>*:8000</code> for example. Use a port with a value of <code>0</code>
|
||||||
|
* to have <code>mvnd</code> to choose one.
|
||||||
|
*/
|
||||||
|
MVND_DEBUG_ADDRESS("mvnd.debug.address", null, "8000", OptionType.STRING, Flags.DISCRIMINATING),
|
||||||
/**
|
/**
|
||||||
* A time period after which an unused daemon will terminate by itself.
|
* A time period after which an unused daemon will terminate by itself.
|
||||||
*/
|
*/
|
||||||
|
@@ -218,7 +218,7 @@ _mvnd()
|
|||||||
|
|
||||||
local mvnd_opts="-1"
|
local mvnd_opts="-1"
|
||||||
local mvnd_long_opts="--color|--completion|--purge|--serial|--status|--stop"
|
local mvnd_long_opts="--color|--completion|--purge|--serial|--status|--stop"
|
||||||
local mvnd_properties="-Djava.home|-Djdk.java.options|-Dmaven.multiModuleProjectDirectory|-Dmaven.repo.local|-Dmaven.settings|-Dmvnd.buildTime|-Dmvnd.builder|-Dmvnd.daemonStorage|-Dmvnd.debug|-Dmvnd.duplicateDaemonGracePeriod|-Dmvnd.enableAssertions|-Dmvnd.expirationCheckDelay|-Dmvnd.home|-Dmvnd.idleTimeout|-Dmvnd.jvmArgs|-Dmvnd.keepAlive|-Dmvnd.logPurgePeriod|-Dmvnd.logback|-Dmvnd.maxHeapSize|-Dmvnd.maxLostKeepAlive|-Dmvnd.minHeapSize|-Dmvnd.minThreads|-Dmvnd.noBuffering|-Dmvnd.noDaemon|-Dmvnd.pluginRealmEvictPattern|-Dmvnd.propertiesPath|-Dmvnd.registry|-Dmvnd.rollingWindowSize|-Dmvnd.serial|-Dmvnd.socketFamily|-Dmvnd.threadStackSize|-Dmvnd.threads|-Dstyle.color|-Duser.dir|-Duser.home"
|
local mvnd_properties="-Djava.home|-Djdk.java.options|-Dmaven.multiModuleProjectDirectory|-Dmaven.repo.local|-Dmaven.settings|-Dmvnd.buildTime|-Dmvnd.builder|-Dmvnd.daemonStorage|-Dmvnd.debug|-Dmvnd.debug.address|-Dmvnd.duplicateDaemonGracePeriod|-Dmvnd.enableAssertions|-Dmvnd.expirationCheckDelay|-Dmvnd.home|-Dmvnd.idleTimeout|-Dmvnd.jvmArgs|-Dmvnd.keepAlive|-Dmvnd.logPurgePeriod|-Dmvnd.logback|-Dmvnd.maxHeapSize|-Dmvnd.maxLostKeepAlive|-Dmvnd.minHeapSize|-Dmvnd.minThreads|-Dmvnd.noBuffering|-Dmvnd.noDaemon|-Dmvnd.pluginRealmEvictPattern|-Dmvnd.propertiesPath|-Dmvnd.registry|-Dmvnd.rollingWindowSize|-Dmvnd.serial|-Dmvnd.socketFamily|-Dmvnd.threadStackSize|-Dmvnd.threads|-Dstyle.color|-Duser.dir|-Duser.home"
|
||||||
local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X|${mvnd_opts}"
|
local opts="-am|-amd|-B|-C|-c|-cpu|-D|-e|-emp|-ep|-f|-fae|-ff|-fn|-gs|-h|-l|-N|-npr|-npu|-nsu|-o|-P|-pl|-q|-rf|-s|-T|-t|-U|-up|-V|-v|-X|${mvnd_opts}"
|
||||||
local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-version|--version|--debug|${mvnd_long_opts}"
|
local long_opts="--also-make|--also-make-dependents|--batch-mode|--strict-checksums|--lax-checksums|--check-plugin-updates|--define|--errors|--encrypt-master-password|--encrypt-password|--file|--fail-at-end|--fail-fast|--fail-never|--global-settings|--help|--log-file|--non-recursive|--no-plugin-registry|--no-plugin-updates|--no-snapshot-updates|--offline|--activate-profiles|--projects|--quiet|--resume-from|--settings|--threads|--toolchains|--update-snapshots|--update-plugins|--show-version|--version|--debug|${mvnd_long_opts}"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user