Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
74 changes: 35 additions & 39 deletions plugin/src/main/java/org/docstr/gwt/AbstractBaseTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,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 +113,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 +134,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 +202,24 @@ public void exec() {
}

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

// Logging just below visibility. Can turn up access to this package, or log the JavaExec task.
@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());
}
}
}

// 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 +403,13 @@ 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;
}
}
33 changes: 33 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,39 @@ 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 during configuration phase to avoid Configuration Cache issues
SourceSetContainer sourceSets = project.getExtensions()
.getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME);

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

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

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

// Ensure the classpath includes compiled classes, resources, and source files
task.classpath(
allSourcePaths,
outputClasspath,
task.getGwtDevRuntimeClasspath()
);

// Configure all arguments during configuration phase for Configuration Cache compatibility
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
37 changes: 37 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,10 @@

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

/**
* Configures the GWT dev mode task.
Expand Down Expand Up @@ -173,5 +177,38 @@ 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 during configuration phase to avoid Configuration Cache issues
Project project = task.getProject();
SourceSetContainer sourceSets = project.getExtensions()
.getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME);

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

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

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

// Ensure the classpath includes compiled classes, resources, and source files
task.classpath(
allSourcePaths,
outputClasspath,
task.getGwtDevRuntimeClasspath()
);

// Configure all arguments during configuration phase for Configuration Cache compatibility
task.configureArgs();
}
}
37 changes: 37 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,10 @@

import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.Project;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;

/**
* Configures the GWT super dev task.
Expand Down Expand Up @@ -157,5 +161,38 @@ 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 during configuration phase to avoid Configuration Cache issues
Project project = task.getProject();
SourceSetContainer sourceSets = project.getExtensions()
.getByType(SourceSetContainer.class);
SourceSet mainSourceSet = sourceSets.getByName(
SourceSet.MAIN_SOURCE_SET_NAME);

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

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

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

// Ensure the classpath includes compiled classes, resources, and source files
task.classpath(
allSourcePaths,
outputClasspath,
task.getGwtDevRuntimeClasspath()
);

// Configure all arguments during configuration phase for Configuration Cache compatibility
task.configureArgs();
}
}