Skip to content

Commit

Permalink
try port 6006 then find available port for child debug
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Kurz <[email protected]>
  • Loading branch information
scottkurz committed Mar 11, 2023
1 parent 5fe8aa1 commit d9e184a
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class DevTask extends AbstractFeatureTask {
@Optional
@Input
DevTaskUtil util = null;

// Default DevMode argument values
// DevMode uses CLI Arguments if provided, otherwise it uses ServerExtension properties if one exists, fallback to default value if neither are provided.
private static final int DEFAULT_VERIFY_TIMEOUT = 30;
Expand All @@ -98,6 +98,9 @@ class DevTask extends AbstractFeatureTask {

private Boolean skipTests;

// Debug port for BuildLauncher tasks launched from DevTask as parent JVM
private Integer childDebugPort;

@Option(option = 'skipTests', description = 'If this option is enabled, do not run any tests in dev mode. The default value is false.')
void setSkipTests(boolean skipTests) {
this.skipTests = skipTests;
Expand Down Expand Up @@ -1083,6 +1086,23 @@ class DevTask extends AbstractFeatureTask {
final ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS,
new ArrayBlockingQueue<Runnable>(1, true));



String localMavenRepoForFeatureUtility = new File(new File(System.getProperty("user.home"), ".m2"), "repository");

File buildFile = project.getBuildFile();

this.util = new DevTaskUtil(project.buildDir, serverInstallDir, getUserDir(project, serverInstallDir),
serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getRootDir(),
resourceDirs, hotTests.booleanValue(), skipTests.booleanValue(), artifactId, serverStartTimeout.intValue(),
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), dockerfile, dockerBuildContext, dockerRunOpts,
dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility,
getPackagingType(), buildFile, generateFeatures.booleanValue()
);



ProjectConnection gradleConnection = initGradleProjectConnection();
BuildLauncher gradleBuildLauncher = gradleConnection.newBuild();
try {
Expand Down Expand Up @@ -1128,6 +1148,10 @@ class DevTask extends AbstractFeatureTask {
}
}
}




if (!container) {
addLibertyRuntimeProperties(gradleBuildLauncher);
runGradleTask(gradleBuildLauncher, 'libertyCreate');
Expand All @@ -1145,18 +1169,6 @@ class DevTask extends AbstractFeatureTask {
gradleConnection.close();
}

String localMavenRepoForFeatureUtility = new File(new File(System.getProperty("user.home"), ".m2"), "repository");

File buildFile = project.getBuildFile();

util = new DevTaskUtil(project.buildDir, serverInstallDir, getUserDir(project, serverInstallDir),
serverDirectory, sourceDirectory, testSourceDirectory, configDirectory, project.getRootDir(),
resourceDirs, hotTests.booleanValue(), skipTests.booleanValue(), artifactId, serverStartTimeout.intValue(),
verifyAppStartTimeout.intValue(), verifyAppStartTimeout.intValue(), compileWait.doubleValue(),
libertyDebug.booleanValue(), pollingTest.booleanValue(), container.booleanValue(), dockerfile, dockerBuildContext, dockerRunOpts,
dockerBuildTimeout, skipDefaultPorts.booleanValue(), keepTempDockerfile.booleanValue(), localMavenRepoForFeatureUtility,
getPackagingType(), buildFile, generateFeatures.booleanValue()
);

util.addShutdownHook(executor);

Expand Down Expand Up @@ -1296,6 +1308,14 @@ class DevTask extends AbstractFeatureTask {
if (logger.isEnabled(LogLevel.DEBUG)) {
buildLauncher.addArguments("--debug");
}

if (Boolean.getBoolean("org.gradle.debug")) {
if (this.childDebugPort == null) {
childDebugPort = this.util.findAvailablePort(6006, true)
logger.warn("Launch using JVM with debug port = " + childDebugPort.toString() + ", which will be suspended and require a debugger to be attached the first time the daemon JVM is started.")
}
buildLauncher.addArguments("-Dorg.gradle.debug.port=" + Integer.toString(childDebugPort))
}
buildLauncher.run();
}

Expand Down

0 comments on commit d9e184a

Please sign in to comment.