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

Dev mode debug #802

Merged
merged 1 commit into from
Mar 14, 2023
Merged
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
40 changes: 28 additions & 12 deletions src/main/groovy/io/openliberty/tools/gradle/tasks/DevTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class DevTask extends AbstractFeatureTask {
private static final boolean DEFAULT_KEEP_TEMP_DOCKERFILE = false;
private static final boolean DEFAULT_GENERATE_FEATURES = false;

// Debug port for BuildLauncher tasks launched from DevTask as parent JVM
// (parent defaults to '5005')
private Integer childDebugPort = null; // cache
private static final int DEFAULT_CHILD_DEBUG_PORT = 6006;

protected final String CONTAINER_PROPERTY_ARG = '-P'+CONTAINER_PROPERTY+'=true';

private Boolean hotTests;
Expand All @@ -98,6 +103,7 @@ class DevTask extends AbstractFeatureTask {

private Boolean skipTests;


@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 +1089,20 @@ 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();

// Instantiate util before any child gradle tasks launched so it can help find available port if needed
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 @@ -1145,18 +1165,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 +1304,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(DEFAULT_CHILD_DEBUG_PORT, true)
logger.warn("Launch JVM with debug port = " + childDebugPort.toString() + ". The child daemon JVM will initially launch in a suspended state and require a debugger to be attached to proceed.")
}
buildLauncher.addArguments("-Dorg.gradle.debug.port=" + Integer.toString(childDebugPort))
}
buildLauncher.run();
}

Expand Down