Skip to content

Commit 3d97c4b

Browse files
committed
Initial GWT Plugin implementation
1 parent ecdbacb commit 3d97c4b

18 files changed

+904
-0
lines changed

examples/gwt/war/build.gradle

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import io.freefair.gradle.plugins.gwt.tasks.AbstractGwtTask
2+
3+
plugins {
4+
id "io.freefair.gwt-war"
5+
id "war"
6+
}
7+
8+
gwt {
9+
modules.add("io.freefair.example.Example")
10+
}
11+
12+
dependencies {
13+
gwtClasspath "org.gwtproject:gwt-user:2.12.1"
14+
gwtClasspath project(":code-generator:generator")
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<module>
2+
<inherits name="com.google.gwt.user.User" />
3+
</module>

examples/settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ include 'plantuml'
4646
include ":mjml"
4747

4848
include ":okhttp"
49+
50+
include ":gwt:war"

gwt-plugin/build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id "maven-publish"
3+
id "java-gradle-plugin"
4+
id "com.gradle.plugin-publish"
5+
}
6+
7+
dependencies {
8+
9+
compileOnly 'org.gwtproject:gwt-dev:2.12.1'
10+
11+
}
12+
13+
gradlePlugin {
14+
plugins {
15+
gwt {
16+
id = "io.freefair.gwt"
17+
implementationClass = "io.freefair.gradle.plugins.gwt.GwtPlugin"
18+
displayName = "GWT Plugin"
19+
description = "GWT Plugin"
20+
tags.set(['gwt'])
21+
}
22+
gwtBase {
23+
id = "io.freefair.gwt-base"
24+
implementationClass = "io.freefair.gradle.plugins.gwt.GwtBasePlugin"
25+
displayName = "GWT Base Plugin"
26+
description = "GWT Plugin"
27+
tags.set(['gwt'])
28+
}
29+
gwtWar {
30+
id = "io.freefair.gwt-war"
31+
implementationClass = "io.freefair.gradle.plugins.gwt.GwtWarPlugin"
32+
displayName = "GWT War Plugin"
33+
description = "GWT Plugin"
34+
tags.set(['gwt'])
35+
}
36+
gwtWebjar {
37+
id = "io.freefair.gwt-webjar"
38+
implementationClass = "io.freefair.gradle.plugins.gwt.GwtWebJarPlugin"
39+
displayName = "GWT WebJar Plugin"
40+
description = "GWT Plugin"
41+
tags.set(['gwt'])
42+
}
43+
}
44+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package io.freefair.gradle.plugins.gwt;
2+
3+
import org.gradle.api.file.DirectoryProperty;
4+
import org.gradle.api.provider.ListProperty;
5+
import org.gradle.api.provider.MapProperty;
6+
import org.gradle.api.provider.Property;
7+
import org.gradle.api.tasks.Console;
8+
import org.gradle.api.tasks.Input;
9+
import org.gradle.api.tasks.Optional;
10+
import org.gradle.api.tasks.OutputDirectory;
11+
12+
/**
13+
* @author Lars Grefer
14+
*/
15+
public interface CommonGwtToolOptions {
16+
17+
@Console
18+
Property<String> getLogLevel();
19+
20+
@Optional
21+
@Input
22+
Property<Boolean> getFailOnError();
23+
24+
@Optional
25+
@OutputDirectory
26+
DirectoryProperty getWorkDir();
27+
28+
@Optional
29+
@Input
30+
Property<String> getStyle();
31+
32+
/**
33+
* Set the values of a property in the form of propertyName=value1[,value2...].
34+
*/
35+
@Optional
36+
@Input
37+
MapProperty<String, String> getSetProperty();
38+
39+
@Optional
40+
@Input
41+
Property<Boolean> getIncremental();
42+
43+
@Optional
44+
@Input
45+
Property<String> getSourceLevel();
46+
47+
/**
48+
* Generate exports for JsInterop purposes. If no -includeJsInteropExport/-excludeJsInteropExport provided, generates all exports. (defaults to OFF)
49+
*/
50+
@Optional
51+
@Input
52+
Property<Boolean> getGenerateJsInteropExports();
53+
54+
/**
55+
* Include members and classes while generating JsInterop exports. Flag could be set multiple times to expand the pattern. (The flag has only effect if exporting is enabled via -generateJsInteropExports)
56+
*/
57+
@Optional
58+
@Input
59+
ListProperty<String> getIncludeJsInteropExports();
60+
61+
/**
62+
* Include/exclude members and classes while generating JsInterop exports. Flag could be set multiple times to expand the pattern. (The flag has only effect if exporting is enabled via -generateJsInteropExports)
63+
*/
64+
@Optional
65+
@Input
66+
ListProperty<String> getExcludeJsInteropExports();
67+
68+
/**
69+
* @return EXPERIMENTAL: Specifies method display name mode for chrome devtools: NONE, ONLY_METHOD_NAME, ABBREVIATED or FULL (defaults to NONE)
70+
*/
71+
@Optional
72+
@Input
73+
Property<String> getXmethodNameDisplayMode();
74+
75+
/**
76+
* The GWT modules that the code server should compile. (Example: com.example.MyApp)
77+
*/
78+
@Input
79+
ListProperty<String> getModule();
80+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.freefair.gradle.plugins.gwt;
2+
3+
import io.freefair.gradle.plugins.gwt.tasks.AbstractGwtTask;
4+
import io.freefair.gradle.plugins.gwt.tasks.GwtCodeServerTask;
5+
import io.freefair.gradle.plugins.gwt.tasks.GwtCompileTask;
6+
import io.freefair.gradle.plugins.gwt.tasks.GwtDevModeTask;
7+
import org.gradle.api.Plugin;
8+
import org.gradle.api.Project;
9+
import org.gradle.api.artifacts.Configuration;
10+
import org.gradle.api.attributes.DocsType;
11+
import org.gradle.api.attributes.VerificationType;
12+
import org.gradle.api.plugins.JavaPlugin;
13+
import org.gradle.api.plugins.JavaPluginExtension;
14+
import org.gradle.api.tasks.SourceSet;
15+
import org.gradle.api.tasks.TaskProvider;
16+
import org.gradle.api.tasks.compile.AbstractCompile;
17+
import org.gradle.api.tasks.compile.JavaCompile;
18+
19+
/**
20+
* @author Lars Grefer
21+
*/
22+
public class GwtBasePlugin implements Plugin<Project> {
23+
24+
@Override
25+
public void apply(Project project) {
26+
27+
project.getPlugins().apply(JavaPlugin.class);
28+
29+
Configuration gwtDev = project.getConfigurations().create("gwtDev");
30+
31+
Configuration gwtClasspath = project.getConfigurations().create("gwtClasspath");
32+
33+
Configuration gwtSources = project.getConfigurations().create("gwtSources");
34+
gwtSources.extendsFrom(gwtClasspath);
35+
36+
gwtSources.getAttributes().attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, project.getObjects().named(VerificationType.class, VerificationType.MAIN_SOURCES));
37+
gwtSources.getAttributes().attribute(DocsType.DOCS_TYPE_ATTRIBUTE, project.getObjects().named(DocsType.class, DocsType.SOURCES));
38+
39+
GwtExtension gwtExtension = project.getExtensions().create("gwt", GwtExtension.class);
40+
41+
project.afterEvaluate(p -> {
42+
gwtDev.defaultDependencies(ds -> {
43+
ds.add(project.getDependencies().create("org.gwtproject:gwt-dev:" + gwtExtension.getToolVersion().get()));
44+
});
45+
});
46+
47+
project.getTasks().withType(AbstractGwtTask.class, gwtTask -> {
48+
gwtTask.setGroup("gwt");
49+
50+
gwtTask.getGwtClasspath().from(gwtDev);
51+
gwtTask.getGwtClasspath().from(gwtClasspath);
52+
JavaPluginExtension pluginExtension = project.getExtensions().getByType(JavaPluginExtension.class);
53+
SourceSet main = pluginExtension.getSourceSets().getByName("main");
54+
gwtTask.getGwtClasspath().from(main.getAllJava().getSourceDirectories());
55+
56+
gwtTask.getWorkDir().set(gwtTask.getTemporaryDir());
57+
58+
gwtTask.getModule().convention(gwtExtension.getModules());
59+
60+
gwtTask.getSourceLevel().convention(project.getTasks().named("compileJava", JavaCompile.class).map(AbstractCompile::getSourceCompatibility));
61+
});
62+
63+
TaskProvider<GwtCompileTask> gwtCompileTaskProvider = project.getTasks().register("gwtCompile", GwtCompileTask.class, gwtCompile -> {
64+
gwtCompile.getWar().convention(project.getLayout().getBuildDirectory().dir("gwt/compile/war"));
65+
gwtCompile.getDeploy().convention(project.getLayout().getBuildDirectory().dir("gwt/compile/deploy"));
66+
gwtCompile.getExtra().convention(project.getLayout().getBuildDirectory().dir("gwt/compile/extra"));
67+
68+
gwtCompile.getGwtClasspath().from(gwtSources);
69+
});
70+
71+
TaskProvider<GwtDevModeTask> gwtDevModeTaskProvider = project.getTasks().register("gwtDevMode", GwtDevModeTask.class, gwtDevMode -> {
72+
gwtDevMode.getWar().convention(project.getLayout().getBuildDirectory().dir("gwt/dev-mode/war"));
73+
gwtDevMode.getDeploy().convention(project.getLayout().getBuildDirectory().dir("gwt/dev-mode/deploy"));
74+
gwtDevMode.getExtra().convention(project.getLayout().getBuildDirectory().dir("gwt/dev-mode/extra"));
75+
});
76+
77+
project.getTasks().register("gwtCodeServer", GwtCodeServerTask.class, gwtCodeServer -> {
78+
gwtCodeServer.getLauncherDir().convention(project.getLayout().getBuildDirectory().dir("gwt/code-server"));
79+
});
80+
81+
}
82+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package io.freefair.gradle.plugins.gwt;
2+
3+
import org.gradle.api.file.DirectoryProperty;
4+
import org.gradle.api.provider.Property;
5+
import org.gradle.api.tasks.*;
6+
7+
/**
8+
* @author Lars Grefer
9+
*/
10+
public interface GwtCodeServerOptions extends CommonGwtToolOptions {
11+
12+
/**
13+
* Allows -src flags to reference missing directories. (defaults to OFF)
14+
*/
15+
@Optional
16+
@Input
17+
Property<Boolean> getAllowMissingSrc();
18+
19+
/**
20+
* Exits after compiling the modules. The exit code will be 0 if the compile succeeded. (defaults to OFF)
21+
*/
22+
@Optional
23+
@Input
24+
Property<Boolean> getCompileTest();
25+
26+
/**
27+
* The number of times to recompile (after the first one) during a compile test.
28+
*/
29+
@Optional
30+
@Input
31+
Property<Integer> getCompileTestRecompiles();
32+
33+
/**
34+
* Precompile modules. (defaults to ON)
35+
*/
36+
@Optional
37+
@Input
38+
Property<Boolean> getPrecompile();
39+
40+
/**
41+
* The port where the code server will run.
42+
*/
43+
@Optional
44+
@Input
45+
Property<Integer> getPort();
46+
47+
/**
48+
* A directory containing GWT source to be prepended to the classpath for compiling.
49+
*/
50+
@Optional
51+
@InputDirectory
52+
DirectoryProperty getSrc();
53+
54+
/**
55+
* An output directory where files for launching Super Dev Mode will be written. (Optional.)
56+
*/
57+
@Optional
58+
@OutputDirectory
59+
DirectoryProperty getLauncherDir();
60+
61+
/**
62+
* Specifies the bind address for the code server and web server (defaults to 127.0.0.1)
63+
*/
64+
@Optional
65+
@Input
66+
Property<String> getBindAddress();
67+
68+
/**
69+
* EXPERIMENTAL: Enables Javascript output suitable for post-compilation by Closure Compiler (defaults to OFF)
70+
*/
71+
@Optional
72+
@Input
73+
Property<Boolean> getXclosureFormattedOutput();
74+
75+
76+
77+
}

0 commit comments

Comments
 (0)