Skip to content

Commit

Permalink
Generate derived freeciv files to src/derived
Browse files Browse the repository at this point in the history
Fixes #182

* All files generated by the sync scripts (for freeciv-web) are now
  generated to src/derived, which has .gitignores filtering them
* Additional maven jumping-jacks to build these into the war file
  • Loading branch information
mchenryc committed Aug 19, 2018
1 parent a11c066 commit 8963d20
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 16 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions freeciv-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion freeciv-web/build-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions freeciv-web/build.sh
Original file line number Diff line number Diff line change
@@ -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/"
97 changes: 94 additions & 3 deletions freeciv-web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<timestamp>${maven.build.timestamp}</timestamp>
<derived-webapp.dir>${basedir}/src/derived/webapp</derived-webapp.dir>
<generated-js.dir>${project.build.directory}/generated-sources/javascript</generated-js.dir>
</properties>

<repositories>
Expand Down Expand Up @@ -122,6 +124,36 @@
<finalName>freeciv-web</finalName>
<!-- <pluginManagement> -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M2</version>
<executions>
<execution>
<id>enforce-files-exist</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<files>
<file>${derived-webapp.dir}</file>
</files>
<message>
Files derived from the original freeciv project not found as expected.

Rerun the sync-js-hand.js script.

</message>
</requireFilesExist>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
Expand Down Expand Up @@ -179,21 +211,69 @@
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-generated-webapp-resources</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/${project.build.finalName}</outputDirectory>
<resources>
<resource>
<directory>${derived-webapp.dir}</directory>
<excludes>
<exclude>.gitignore</exclude>
<exclude>README.md</exclude>
<exclude>javascript/*.js</exclude>
<!-- NOT excluding `javascript/2dcavas/*` -->
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>create-generated-javascript-dir</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<mkdir dir="${generated-js.dir}"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>Precompile Handlebars templates</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>handlebars</executable>
<commandlineArgs>src/main/webapp/webclient -e hbs -f src/main/webapp/javascript/hbs-templates.js --knownOnly</commandlineArgs>
<commandlineArgs>src/main/webapp/webclient -e hbs -f ${generated-js.dir}/hbs-templates.js --knownOnly</commandlineArgs>
</configuration>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
Expand Down Expand Up @@ -236,7 +316,19 @@
<jsSourceDir>javascript</jsSourceDir>
<jsFinalFile>webclient.js</jsFinalFile>
<jsSourceFiles>
<!-- order is important: these must be before sources below -->
<jsSourceFile>libs/EventAggregator.js</jsSourceFile>
<jsSourceFile>libs/handlebars.runtime-v4.0.11.js</jsSourceFile>
<!-- these must be listed here, jsSourceIncludes doesn't work -->
<jsSourceFile>../../../derived/webapp/javascript/fc_events.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/freeciv-helpdata.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/packets.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/packhand_gen.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/soundset_spec.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/2dcanvas/tileset_spec_amplio2.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/2dcanvas/tileset_spec_isotrident.js</jsSourceFile>
<jsSourceFile>../../../derived/webapp/javascript/2dcanvas/tileset_spec_trident.js</jsSourceFile>
<jsSourceFile>../../../../target/generated-sources/javascript/hbs-templates.js</jsSourceFile>
</jsSourceFiles>
<jsSourceIncludes>
<jsSourceInclude>*.js</jsSourceInclude>
Expand Down Expand Up @@ -308,7 +400,6 @@
</executions>
</plugin>


<plugin>
<groupId>com.cj.jshintmojo</groupId>
<artifactId>jshint-maven-plugin</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions freeciv-web/src/derived/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore everything
*

# ...Except these
!README.md
!.gitignore
21 changes: 21 additions & 0 deletions freeciv-web/src/derived/README.md
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -1465,4 +1466,4 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ })
/******/ ])
});
;
;
3 changes: 2 additions & 1 deletion scripts/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8963d20

Please sign in to comment.