Created
September 3, 2014 15:22
-
-
Save schnell18/551dbc967a4bffda7c94 to your computer and use it in GitHub Desktop.
Vanilla GWT project bootstrap script. Creates gradle build script with gwt-gradle-plugin enabled, host html, index html, .gitignore, gwt module xml, entry point class, web.xml etc. This version allows GWT version selection and it can be used on existing project as it never overwrites existing target file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################################### | |
## ## | |
## function definitions ## | |
## ## | |
#################################################################### | |
function gen_gitignore() { | |
# .gitignore | |
cat << EOF > .gitignore | |
# temporary and log files | |
*~ | |
*.swp | |
*.swo | |
*.log | |
logs | |
# IDE project meta directories and files | |
*.iml | |
*.ipr | |
*.iws | |
.project | |
.classpath | |
.settings | |
.idea | |
bin | |
# build tool meta directories and files | |
.gradle | |
build | |
local.properties | |
# GWT compile output directory | |
war | |
EOF | |
} | |
# entry point class | |
function gen_entry_point_class() { | |
cat << EOF > $1 | |
package ${rootPkg}.client; | |
import com.google.gwt.core.client.EntryPoint; | |
public class ${gwtModule} implements EntryPoint { | |
@Override | |
public void onModuleLoad() { | |
// TODO: implement the entry point here | |
} | |
} | |
EOF | |
} | |
# production gwt module xml | |
function gen_gwt_module_xml() { | |
cat << EOF > $1 | |
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" | |
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd"> | |
<module rename-to="${gwtModule}"> | |
<!-- Inherit the core Web Toolkit stuff. --> | |
<inherits name='com.google.gwt.user.User'/> | |
<!-- Specify the app entry point class. --> | |
<entry-point class='${rootPkg}.client.${gwtModule}'/> | |
<!-- Specify the application specific style sheet. --> | |
<stylesheet src='${gwtModule}.css' /> | |
<source path="client"/> | |
<source path="shared"/> | |
</module> | |
EOF | |
} | |
# Development gwt module xml | |
function gen_gwt_module_xml_dev() { | |
cat << EOF > $1 | |
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" | |
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd"> | |
<module rename-to="${gwtModule}"> | |
<!-- Inherit the core Web Toolkit stuff. --> | |
<inherits name='${rootPkg}.${gwtModule}'/> | |
<set-property name="user.agent" value="safari"/> | |
<set-property name="locale" value="default"/> | |
</module> | |
EOF | |
} | |
# app css | |
function gen_app_css() { | |
cat << EOF > $1 | |
/* TODO: add application specific css here */ | |
EOF | |
} | |
# index.html | |
function gen_index_html() { | |
cat << EOF > $1 | |
<!doctype html> | |
<html> | |
<head> | |
<!-- forward to the GWT Host html --> | |
<meta http-equiv="refresh" content="0;url=${gwtModule}/${gwtModule}.html"> | |
</head> | |
</html> | |
EOF | |
} | |
# host html | |
function gen_host_html() { | |
cat << EOF > $1 | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> | |
<!-- --> | |
<!-- Any title is fine --> | |
<!-- --> | |
<title>Application</title> | |
</head> | |
<!-- --> | |
<!-- The body can have arbitrary html, or --> | |
<!-- you can leave the body empty if you want --> | |
<!-- to create a completely dynamic UI. --> | |
<!-- --> | |
<body> | |
<!-- --> | |
<!-- This script loads your compiled module. --> | |
<!-- If you add any GWT meta tags, they must --> | |
<!-- be added before this line. --> | |
<!-- --> | |
<script type="text/javascript" language="javascript" src="${gwtModule}.nocache.js"></script> | |
<!-- OPTIONAL: include this if you want history support --> | |
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe> | |
</body> | |
</html> | |
EOF | |
} | |
# web.xml | |
function gen_web_xml() { | |
cat << EOF > $1 | |
<!DOCTYPE web-app PUBLIC | |
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" | |
"http://java.sun.com/dtd/web-app_2_3.dtd" > | |
<web-app> | |
<display-name>${gwtModule}</display-name> | |
<welcome-file-list> | |
<welcome-file>index.html</welcome-file> | |
</welcome-file-list> | |
</web-app> | |
EOF | |
} | |
# gradle build script | |
function gen_gradle_build_script() { | |
cat << EOF > $1 | |
apply plugin: 'eclipse' | |
apply plugin: 'idea' | |
apply plugin: 'war' | |
buildscript { | |
repositories { | |
maven { | |
url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' | |
} | |
mavenCentral() | |
} | |
dependencies { | |
classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.4' | |
} | |
} | |
apply plugin: 'gwt' | |
repositories { | |
mavenCentral() | |
jcenter() | |
} | |
dependencies { | |
providedCompile 'com.google.gwt:gwt-dev:${gwtVersion}' | |
providedCompile 'com.google.gwt:gwt-user:${gwtVersion}' | |
testCompile 'junit:junit:4.9' | |
} | |
task gwtDevDebug(type: de.richsource.gradle.plugins.gwt.GwtDev) { | |
setDebug(true) | |
setWar(file('build/war')) | |
} | |
task wrapper(type: Wrapper) { | |
gradleVersion = '2.0' | |
} | |
war { | |
baseName = '${gwtModule}' | |
compileJava { | |
options.encoding = "UTF-8" | |
} | |
} | |
gwt { | |
gwtVersion = '${gwtVersion}' | |
minHeapSize = '512M' | |
maxHeapSize = '1024M' | |
logLevel = 'INFO' | |
modules '${rootPkg}.${gwtModule}' | |
devModules '${rootPkg}.${gwtModule}Dev' | |
devWar = file('build/war') | |
dev { | |
startupUrl = "${gwtModule}/${gwtModule}.html" | |
} | |
superDev { | |
noPrecompile = true | |
} | |
compiler { | |
enableClosureCompiler = true; | |
disableClassMetadata = true; | |
disableCastChecking = true; | |
} | |
} | |
/* vim: set ai nu nobk expandtab sw=4 ts=4 tw=72 syntax=groovy : */ | |
EOF | |
} | |
#################################################################### | |
## ## | |
## Main block ## | |
## ## | |
#################################################################### | |
projDir=$1 | |
rootPkg=$2 | |
gwtModule=$3 | |
gwtVersion=$4 | |
rootPkgPath=${rootPkg//\./\//} | |
if [[ -z ${gwtVersion} ]]; then | |
gwtVersion="2.6.1" | |
fi | |
[ -d $projDir ] || mkdir $projDir | |
cd $projDir | |
dir="src/main/java/${rootPkgPath}/client" | |
[ -d $dir ] || mkdir -p $dir | |
dir="src/main/java/${rootPkgPath}/shared" | |
[ -d $dir ] || mkdir -p $dir | |
dir="src/main/java/${rootPkgPath}/public" | |
[ -d $dir ] || mkdir -p $dir | |
dir="src/main/webapp/WEB-INF" | |
[ -d $dir ] || mkdir -p $dir | |
file=".gitignore" | |
[ -f $file ] || gen_gitignore $file | |
file="src/main/java/${rootPkgPath}/client/${gwtModule}.java" | |
[ -f $file ] || gen_entry_point_class $file | |
file="src/main/java/${rootPkgPath}/${gwtModule}.gwt.xml" | |
[ -f $file ] || gen_gwt_module_xml $file | |
file="src/main/java/${rootPkgPath}/${gwtModule}Dev.gwt.xml" | |
[ -f $file ] || gen_gwt_module_xml_dev $file | |
file="src/main/java/${rootPkgPath}/public/${gwtModule}.css" | |
[ -f $file ] || gen_app_css $file | |
file="src/main/java/${rootPkgPath}/public/${gwtModule}.html" | |
[ -f $file ] || gen_host_html $file | |
file="src/main/webapp/index.html" | |
[ -f $file ] || gen_index_html $file | |
file="src/main/webapp/WEB-INF/web.xml" | |
[ -f $file ] || gen_web_xml $file | |
file="build.gradle" | |
[ -f $file ] || gen_gradle_build_script $file | |
# vim: set ai nu nobk expandtab sw=4 ts=4 tw=72 syntax=sh : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment