Skip to content
Merged
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
111 changes: 72 additions & 39 deletions plugin/src/main/java/org/docstr/gwt/AbstractBaseTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.stream.Collectors;
import javax.inject.Inject;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileCollection;
Expand Down Expand Up @@ -84,6 +85,9 @@ public abstract class AbstractBaseTask extends JavaExec {
@PathSensitive(PathSensitivity.RELATIVE)
@Optional
private final ConfigurableFileCollection extraSourceDirs;
@InputFiles
@PathSensitive(PathSensitivity.RELATIVE)
private final ConfigurableFileCollection gwtDevRuntimeClasspath;

/**
* Constructs a new GwtCompileTask.
Expand All @@ -110,38 +114,14 @@ public AbstractBaseTask(ObjectFactory objects) {
incremental = objects.property(Boolean.class);
modules = objects.listProperty(String.class);
extraSourceDirs = objects.fileCollection();
gwtDevRuntimeClasspath = objects.fileCollection();
}

@Override
public void exec() {
// Retrieve the main source set
SourceSetContainer sourceSets = getProject().getExtensions()
.getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME);

// Collect all source paths
Set<File> allMainSourcePaths = mainSourceSet.getAllSource().getSrcDirs();
FileCollection outputClasspath = mainSourceSet.getOutput().getClassesDirs()
.plus(getProject().files(mainSourceSet.getOutput().getResourcesDir()));

// Include extra source directories if specified
FileCollection allSourcePaths = getProject().files(allMainSourcePaths);
if (!getExtraSourceDirs().isEmpty()) {
allSourcePaths = allSourcePaths.plus(getExtraSourceDirs());
}

// Ensure the classpath includes compiled classes, resources, and source files
classpath(
allSourcePaths,
outputClasspath,
getProject().getConfigurations().getByName(GwtPlugin.GWT_DEV_RUNTIME_CLASSPATH_CONFIGURATION_NAME)
);

// Log the classpath
Logger log = getProject().getLogger();
getClasspath().getFiles().forEach(file -> log.debug("classpath: {}", file));

/**
* Configure task arguments during configuration phase.
* This method should be called from task configuration actions to set up all arguments.
*/
public void configureArgs() {
if (getLogLevel().isPresent()) {
args("-logLevel", getLogLevel().get());
}
Expand All @@ -155,14 +135,6 @@ public void exec() {
}

if (!isCodeServerTask() && getWar().isPresent()) {
// Ensure the war directory exists
if (!getWar().get().getAsFile().exists()) {
boolean mkdirs = getWar().get().getAsFile().mkdirs();
if (!mkdirs) {
throw new GradleException(
"Failed to create war directory: " + getWar().get().getAsFile());
}
}
args("-war", getWar().get().getAsFile().getPath());
}

Expand Down Expand Up @@ -231,8 +203,24 @@ public void exec() {
}

getModules().get().forEach(this::args);
}

@Override
public void exec() {
// Ensure the war directory exists before executing
if (!isCodeServerTask() && getWar().isPresent()) {
if (!getWar().get().getAsFile().exists()) {
boolean mkdirs = getWar().get().getAsFile().mkdirs();
if (!mkdirs) {
throw new GradleException(
"Failed to create war directory: " + getWar().get().getAsFile());
}
}
}

// Logging just below visibility. Can turn up access to this package, or log the JavaExec task.
// Log the classpath and args
Logger log = getLogger();
getClasspath().getFiles().forEach(file -> log.debug("classpath: {}", file));
log.info("classpath: {}", getClasspath().getAsPath());
log.info("allJvmArgs: {}", getAllJvmArgs().stream().map(arg -> "\"" + arg + "\"").collect(Collectors.joining(", ")));
log.info("main: {}", getMainClass().get());
Expand Down Expand Up @@ -416,4 +404,49 @@ public final ListProperty<String> getModules() {
public final ConfigurableFileCollection getExtraSourceDirs() {
return extraSourceDirs;
}

/**
* The GWT dev runtime classpath
*
* @return The GWT dev runtime classpath
*/
public final ConfigurableFileCollection getGwtDevRuntimeClasspath() {
return gwtDevRuntimeClasspath;
}

/**
* Configures the classpath for this task during configuration phase.
* This method should be called from task configuration actions to avoid Configuration Cache issues.
*
* @param project The project to get source sets and configurations from
*/
public void configureClasspath(Project project) {
SourceSetContainer sourceSets = project.getExtensions()
.getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME);

// Collect all source paths
FileCollection mainSourcePaths = project.files(mainSourceSet.getAllSource().getSrcDirs());
FileCollection outputClasspath = mainSourceSet.getOutput().getClassesDirs()
.plus(project.files(mainSourceSet.getOutput().getResourcesDir()));

// Include extra source directories if specified
FileCollection allSourcePaths = mainSourcePaths;
if (!getExtraSourceDirs().isEmpty()) {
allSourcePaths = allSourcePaths.plus(getExtraSourceDirs());
}

// Set up the GWT dev runtime classpath
getGwtDevRuntimeClasspath().from(
project.getConfigurations().getByName(GwtPlugin.GWT_DEV_RUNTIME_CLASSPATH_CONFIGURATION_NAME)
);

// Ensure the classpath includes compiled classes, resources, and source files
classpath(
allSourcePaths,
outputClasspath,
getGwtDevRuntimeClasspath()
);
}
}
5 changes: 5 additions & 0 deletions plugin/src/main/java/org/docstr/gwt/GwtCompileConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ public void execute(GwtCompileTask task) {
throw new GradleException(
"gwtCompile failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
}

// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
task.configureClasspath(project);
task.configureArgs();
task.configureCompileArgs();
}

/**
Expand Down
14 changes: 10 additions & 4 deletions plugin/src/main/java/org/docstr/gwt/GwtCompileTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ public GwtCompileTask(ObjectFactory objects) {
// Set GWT compiler as the main class
getMainClass().set(COMPILER_CLASS);

// This task will depend on the compileJava task automatically
// This task will depend on the compileJava and processResources tasks automatically
dependsOn(getProject().getTasks().withType(JavaCompile.class)
.matching(task ->
!task.getName().toLowerCase().contains("test")));
dependsOn(getProject().getTasks().named("processResources"));
}

/**
Expand Down Expand Up @@ -224,8 +225,10 @@ public DirectoryProperty getSaveSourceOutput() {
return saveSourceOutput;
}

@Override
public void exec() {
/**
* Configure task-specific arguments during configuration phase.
*/
public void configureCompileArgs() {
if (getClosureFormattedOutput().isPresent()) {
if (getClosureFormattedOutput().get()) {
args("-XclosureFormattedOutput");
Expand Down Expand Up @@ -308,8 +311,11 @@ public void exec() {
args("-saveSourceOutput",
getSaveSourceOutput().get().getAsFile().getPath());
}
}

getProject().getLogger()
@Override
public void exec() {
getLogger()
.info("inputs: {}", getInputs().getFiles().getAsPath());
super.exec();
}
Expand Down
6 changes: 6 additions & 0 deletions plugin/src/main/java/org/docstr/gwt/GwtDevModeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;

/**
* Configures the GWT dev mode task.
Expand All @@ -35,6 +36,7 @@ public GwtDevModeConfig(GwtPluginExtension extension) {

@Override
public void execute(GwtDevModeTask task) {
Project project = task.getProject();
if (extension.getDevMode().getMinHeapSize().isPresent()) {
task.setMinHeapSize(extension.getDevMode().getMinHeapSize().get());
} else {
Expand Down Expand Up @@ -173,5 +175,9 @@ public void execute(GwtDevModeTask task) {
throw new GradleException(
"gwtDevMode failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
}

// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
task.configureClasspath(project);
task.configureArgs();
}
}
6 changes: 6 additions & 0 deletions plugin/src/main/java/org/docstr/gwt/GwtSuperDevConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;

/**
* Configures the GWT super dev task.
Expand All @@ -36,6 +37,7 @@ public GwtSuperDevConfig(GwtPluginExtension extension) {

@Override
public void execute(GwtSuperDevTask task) {
Project project = task.getProject();
if (extension.getSuperDev().getMinHeapSize().isPresent()) {
task.setMinHeapSize(extension.getSuperDev().getMinHeapSize().get());
} else {
Expand Down Expand Up @@ -157,5 +159,9 @@ public void execute(GwtSuperDevTask task) {
throw new GradleException(
"gwtSuperDev failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
}

// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
task.configureClasspath(project);
task.configureArgs();
}
}