diff --git a/.gitignore b/.gitignore index 1c48c8f83..79dc0eb93 100644 --- a/.gitignore +++ b/.gitignore @@ -74,10 +74,6 @@ resin* freeciv-web.project models.zip freeciv-web/src/main/webapp/build.txt -freeciv-web/src/main/webapp/man -freeciv-web/src/main/webapp/sounds -freeciv-web/src/main/webapp/tileset -freeciv-web/src/main/webapp/images/flags */__pycache__/* logs/ tests/screenshot*.png diff --git a/freeciv-web/README.md b/freeciv-web/README.md index ece0b8bcb..e619dade8 100644 --- a/freeciv-web/README.md +++ b/freeciv-web/README.md @@ -5,6 +5,17 @@ This is the Freeciv web application, which consists of the Java servlets and filters for running the web client, JSP templates, javascript code and other web content. +Derived Sources +=============== + +Freeciv-web uses packet definitions, tilesets, and other resources +derived from the original freeciv project, keeping these up to date by +generating them during install from freeciv source. + +Scripts to generate these files are in `$freeciv-web/scripts` and they +are generated to `$freeciv-web/freeciv-web/src/derived`. See the +README.md in those directories for more info. + Tomcat 8 + nginx setup ================================ Freeciv-web supports the Tomcat 8 application server for hosting the Java web application. diff --git a/freeciv-web/build-js.sh b/freeciv-web/build-js.sh index be713ae0c..6101144ae 100755 --- a/freeciv-web/build-js.sh +++ b/freeciv-web/build-js.sh @@ -7,7 +7,11 @@ FCW_DEST=/var/lib/tomcat8/webapps/freeciv-web rm -rf target/freeciv-web/javascript/webclient.min.js.map rm -rf target/freeciv-web/javascript/webgl/libs/webgl-client.min.js.map -mvn compile && cp target/freeciv-web/javascript/webclient.* "${FCW_DEST}"/javascript/ && cp target/freeciv-web/javascript/webgl/libs/webgl-client* "${FCW_DEST}"/javascript/webgl/libs/ +mvn compile && \ +echo "Copying target/javascript/webclient.* to ${FCW_DEST}/javascript" && \ + cp target/freeciv-web/javascript/webclient.* "${FCW_DEST}"/javascript/ && \ +echo target/freeciv-web/javascript/webgl/libs/webgl-client* "${FCW_DEST}"/javascript/webgl/libs && \ + cp target/freeciv-web/javascript/webgl/libs/webgl-client* "${FCW_DEST}"/javascript/webgl/libs/ # update timestamp to clear browser cache. sed -i.bak -e "s/ts=\"/ts=\"1/" -e "s/\?ts=/\?ts=1/" "${FCW_DEST}"/webclient/index.jsp diff --git a/freeciv-web/build.sh b/freeciv-web/build.sh index ff49b9472..68ce347b5 100755 --- a/freeciv-web/build.sh +++ b/freeciv-web/build.sh @@ -1,21 +1,26 @@ #!/bin/bash # builds Freeciv-web and copies the war file to Tomcat. +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" + TOMCATDIR="/var/lib/tomcat8" -ROOTDIR="$(pwd)/.." +WEBAPP_DIR="${DIR}/target/freeciv-web" # Creating build.txt info file REVTMP="$(git rev-parse HEAD 2>/dev/null)" if test "x$REVTMP" != "x" ; then # This is build from git repository. - echo "This build is from freeciv-web commit: $REVTMP" > ${ROOTDIR}/freeciv-web/src/main/webapp/build.txt + mkdir -p "${WEBAPP_DIR}" + echo "This build is from freeciv-web commit: $REVTMP" > "${WEBAPP_DIR}/build.txt" if ! test $(git diff | wc -l) -eq 0 ; then - echo "It had local modifications." >> ${ROOTDIR}/freeciv-web/src/main/webapp/build.txt + echo "It had local modifications." >> "${WEBAPP_DIR}/build.txt" fi - date >> ${ROOTDIR}/freeciv-web/src/main/webapp/build.txt + date >> "${WEBAPP_DIR}/build.txt" else - rm -f ${ROOTDIR}/freeciv-web/src/main/webapp/build.txt + rm -f "${WEBAPP_DIR}/build.txt" fi echo "maven package" -mvn flyway:migrate package && cp target/freeciv-web.war "${TOMCATDIR}/webapps/" +mvn -B flyway:migrate package && \ +echo "Copying target/freeciv-web.war to ${TOMCATDIR}/webapps" && \ + cp target/freeciv-web.war "${TOMCATDIR}/webapps/" diff --git a/freeciv-web/pom.xml b/freeciv-web/pom.xml index 3f8a0c198..8451871f8 100644 --- a/freeciv-web/pom.xml +++ b/freeciv-web/pom.xml @@ -13,6 +13,8 @@ UTF-8 ${maven.build.timestamp} + ${basedir}/src/derived/webapp + ${project.build.directory}/generated-sources/javascript @@ -122,6 +124,36 @@ freeciv-web + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M2 + + + enforce-files-exist + + enforce + + + + + + ${derived-webapp.dir} + + +Files derived from the original freeciv project not found as expected. + +Rerun the sync-js-hand.js script. + + + + + true + + + + + org.flywaydb flyway-maven-plugin @@ -179,6 +211,54 @@ + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + + copy-generated-webapp-resources + generate-sources + + copy-resources + + + ${project.build.directory}/${project.build.finalName} + + + ${derived-webapp.dir} + + .gitignore + README.md + javascript/*.js + + + + + + + + + + + org.apache.maven.plugins + maven-antrun-plugin + 1.8 + + + create-generated-javascript-dir + generate-sources + + run + + + + + + + + + org.codehaus.mojo exec-maven-plugin @@ -186,14 +266,14 @@ Precompile Handlebars templates + generate-sources exec handlebars - src/main/webapp/webclient -e hbs -f src/main/webapp/javascript/hbs-templates.js --knownOnly + src/main/webapp/webclient -e hbs -f ${generated-js.dir}/hbs-templates.js --knownOnly - generate-sources @@ -236,7 +316,19 @@ javascript webclient.js + libs/EventAggregator.js + libs/handlebars.runtime-v4.0.11.js + + ../../../derived/webapp/javascript/fc_events.js + ../../../derived/webapp/javascript/freeciv-helpdata.js + ../../../derived/webapp/javascript/packets.js + ../../../derived/webapp/javascript/packhand_gen.js + ../../../derived/webapp/javascript/soundset_spec.js + ../../../derived/webapp/javascript/2dcanvas/tileset_spec_amplio2.js + ../../../derived/webapp/javascript/2dcanvas/tileset_spec_isotrident.js + ../../../derived/webapp/javascript/2dcanvas/tileset_spec_trident.js + ../../../../target/generated-sources/javascript/hbs-templates.js *.js @@ -308,7 +400,6 @@ - com.cj.jshintmojo jshint-maven-plugin diff --git a/freeciv-web/src/derived/.gitignore b/freeciv-web/src/derived/.gitignore new file mode 100755 index 000000000..8e7c00b78 --- /dev/null +++ b/freeciv-web/src/derived/.gitignore @@ -0,0 +1,6 @@ +# Ignore everything +* + +# ...Except these +!README.md +!.gitignore diff --git a/freeciv-web/src/derived/README.md b/freeciv-web/src/derived/README.md new file mode 100755 index 000000000..c2f77ac85 --- /dev/null +++ b/freeciv-web/src/derived/README.md @@ -0,0 +1,21 @@ +# Freeciv Derived Sources + +This directory is for files derived from the `freeciv` project. It will +be empty on initial checkout. Running the `freeciv-web` project install +scripts will generate files here during the "Synchronizing Freeciv" +process. + +Files generated here should be restricted to resources specifically +derived from Freeciv, e.g. network protocol definitions, images/tilesets +that are copied, etc. + +Such files are generated here, instead of within `target` dir, so that +cleaning the maven project does not delete them - as the files are +generated outside of maven, maven should not delete them during its +standard `clean` phase. + +**ONLY** This README.md and a .gitignore file should ever be committed +under this directory. + +To regenerate files in this directory, run the script: +`${FREECIV_WEB}\scripts\sync-js-hand.sh`. diff --git a/freeciv-web/src/main/webapp/javascript/libs/handlebars.runtime-v4.0.11.js b/freeciv-web/src/main/webapp/javascript/libs/handlebars.runtime-v4.0.11.js index b893147c3..93cca6123 100644 --- a/freeciv-web/src/main/webapp/javascript/libs/handlebars.runtime-v4.0.11.js +++ b/freeciv-web/src/main/webapp/javascript/libs/handlebars.runtime-v4.0.11.js @@ -24,6 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +; // ensure concatenation does not cause this to be interpreted as an argument list (function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); @@ -1465,4 +1466,4 @@ return /******/ (function(modules) { // webpackBootstrap /***/ }) /******/ ]) }); -; \ No newline at end of file +; diff --git a/scripts/install/install.sh b/scripts/install/install.sh index 755934b80..97387f879 100755 --- a/scripts/install/install.sh +++ b/scripts/install/install.sh @@ -305,8 +305,9 @@ cd "${basedir}"/scripts/migration mig_scripts=([0-9]*) echo "${mig_scripts[-1]}" > checkpoint +mkdir -p "${basedir}/freeciv-web/src/derived/webapp" && \ "${basedir}"/scripts/sync-js-hand.sh -f "${basedir}/freeciv/freeciv" \ - -o "${basedir}/freeciv-web/src/main/webapp" \ + -o "${basedir}/freeciv-web/src/derived/webapp" \ -d "${TOMCAT_HOME}/webapps/data" || handle_error 6 "Failed to synchronize freeciv project" cd "${basedir}"/freeciv-web && ./build.sh