Skip to content

Commit

Permalink
Auto-build JS and deploy it (#99)
Browse files Browse the repository at this point in the history
* Run ant gwtc via Travis

* Small fixes to make DineroFrontend compile on GWT

- use lambdas instead of inner classes (main fix);
- other small cosmetic fixes.

* Try to increase the max memory for GWTC

* Try to fix the deploy script

* Fix the deploy script

Fix 2 syntax errors and also update the text output to match the actions actually done by the script.

* Fix the build script

Error caused by cherry-picking.

* Remove superfluous Java 8 check

* Build and update JS code from Travis

* Do not re-build GWT code, and do not cd

* Improvements to the deploy script.

* Commit the newly-created dir from the deploy script

* Fix paths in the deployment script
  • Loading branch information
lupino3 committed Jul 6, 2016
1 parent dccd176 commit 3c3dd7f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 111 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -14,7 +14,7 @@ language: java
python:
- "2.7"
install: "sudo pip install Sphinx==1.1.3 && gradle getLibs"
script: "ant test"
script: "ant test && ant gwtc"
jdk:
- oraclejdk8
after_success: ./utils/update-gh-pages.sh
4 changes: 2 additions & 2 deletions build.xml
Expand Up @@ -70,7 +70,7 @@
<javac srcdir="src/main/java" includes="**" encoding="utf-8"
includeantruntime="false"
destdir="war/WEB-INF/classes"
source="1.7" target="1.7" nowarn="true"
source="${src_java_version}" target="${dst_java_version}" nowarn="true"
debug="true" debuglevel="lines,vars,source">
<classpath refid="project.class.path"/>
</javac>
Expand All @@ -90,7 +90,7 @@
</target>

<target name="gwtc" depends="compileWeb" description="GWT compile to JavaScript (production mode)">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler" maxmemory="256m">
<java failonerror="true" fork="true" classname="com.google.gwt.dev.Compiler" maxmemory="2g">
<classpath>
<pathelement location="src/main/java"/>
<path refid="project.class.path"/>
Expand Down
159 changes: 77 additions & 82 deletions src/main/java/org/edumips64/ui/DineroFrontend.java
Expand Up @@ -31,6 +31,7 @@
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Collections;
import java.util.LinkedList;
import java.util.logging.Logger;
import javax.swing.*;
Expand All @@ -56,10 +57,10 @@ private class StreamReader extends Thread {
private String name;
private LinkedList<String> contents;
private boolean finished = false;
public StreamReader(InputStream stream, String name) {
StreamReader(InputStream stream, String name) {
this.stream = stream;
this.name = name;
this.contents = new LinkedList<String>();
this.contents = new LinkedList<>();
this.finished = false;
}

Expand All @@ -86,13 +87,13 @@ public LinkedList<String> getContents() {
}

// Will always be called after join()
public boolean isFinished() {
boolean isFinished() {
return finished;
}
}

private LinkedList<String> extractSimulationResults(LinkedList<String> stdout) {
LinkedList<String> result = new LinkedList<String>();
LinkedList<String> result = new LinkedList<>();
boolean found = false;

for (String line : stdout) {
Expand Down Expand Up @@ -147,90 +148,84 @@ public void keyReleased(KeyEvent e) {
execute = new JButton("Execute");
execute.setAlignmentX(Component.CENTER_ALIGNMENT);

browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
int val = jfc.showOpenDialog(null);
browse.addActionListener(e -> {
JFileChooser jfc = new JFileChooser();
int val = jfc.showOpenDialog(null);

if (val == JFileChooser.APPROVE_OPTION) {
config.putString("dineroIV", jfc.getSelectedFile().getPath());
path.setText(jfc.getSelectedFile().getPath());
}
if (val == JFileChooser.APPROVE_OPTION) {
config.putString("dineroIV", jfc.getSelectedFile().getPath());
path.setText(jfc.getSelectedFile().getPath());
}
});

execute.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
String dineroPath = path.getText();
String paramString = params.getText();

LinkedList<String> paramsList = new LinkedList<String>();
paramsList.add(dineroPath);

for (String p : paramString.split(" ")) {
paramsList.add(p);
}

// Clean up the JTextArea
result.setText("");

logger.info("Starting the Dinero process.");
Process process = Runtime.getRuntime().exec(paramsList.toArray(new String[0]));

logger.info("Creating and starting reader threads for stdout and stderr");
StreamReader stdoutReader = new StreamReader(process.getInputStream(), "stdout");
StreamReader stderrReader = new StreamReader(process.getErrorStream(), "stderr");
stdoutReader.start();
stderrReader.start();

logger.info("Sending the tracefile to Dinero via stdin");
// Let's send the tracefile to Dinero
PrintWriter dineroIn = new PrintWriter(process.getOutputStream());
dinero.writeTraceData(new LocalWriterAdapter(dineroIn));
dineroIn.flush();
dineroIn.close();

// Well, wait for Dinero to terminate
logger.info("Data sent. Waiting for Dinero to terminate.");
process.waitFor();
logger.info("Dinero terminated.");
stdoutReader.join(10000);
stderrReader.join(10000);
logger.info("Reader threads have been joined. Results: " + stdoutReader.isFinished() + ", " + stderrReader.isFinished());

// Debug info
logger.info("STDOUT: " + stdoutReader.getContents());
logger.info("STDERR: " + stderrReader.getContents());

logger.info("Writing data to the JTextArea..");
LinkedList<String> simulationResults = extractSimulationResults(stdoutReader.getContents());

if (simulationResults.isEmpty()) {
result.append(">> Errors while retrieving the simulation results.");
result.append(">> STDOUT: " + stdoutReader.getContents());
result.append(">> STDERR: " + stderrReader.getContents());
} else {
result.append(">> Dinero path: " + dineroPath + "\n");
result.append(">> Dinero parameters: " + paramString + "\n");
result.append(">> Simulation results:\n");

for (String line : simulationResults) {
result.append(line);
}
execute.addActionListener(e -> {
try {
String dineroPath = path.getText();
String paramString = params.getText();

LinkedList<String> paramsList = new LinkedList<>();
paramsList.add(dineroPath);

Collections.addAll(paramsList, paramString.split(" "));

// Clean up the JTextArea
result.setText("");

logger.info("Starting the Dinero process.");
Process process = Runtime.getRuntime().exec(paramsList.toArray(new String[0]));

logger.info("Creating and starting reader threads for stdout and stderr");
StreamReader stdoutReader = new StreamReader(process.getInputStream(), "stdout");
StreamReader stderrReader = new StreamReader(process.getErrorStream(), "stderr");
stdoutReader.start();
stderrReader.start();

logger.info("Sending the tracefile to Dinero via stdin");
// Let's send the tracefile to Dinero
PrintWriter dineroIn = new PrintWriter(process.getOutputStream());
dinero.writeTraceData(new LocalWriterAdapter(dineroIn));
dineroIn.flush();
dineroIn.close();

// Well, wait for Dinero to terminate
logger.info("Data sent. Waiting for Dinero to terminate.");
process.waitFor();
logger.info("Dinero terminated.");
stdoutReader.join(10000);
stderrReader.join(10000);
logger.info("Reader threads have been joined. Results: " + stdoutReader.isFinished() + ", " + stderrReader.isFinished());

// Debug info
logger.info("STDOUT: " + stdoutReader.getContents());
logger.info("STDERR: " + stderrReader.getContents());

logger.info("Writing data to the JTextArea..");
LinkedList<String> simulationResults = extractSimulationResults(stdoutReader.getContents());

if (simulationResults.isEmpty()) {
result.append(">> Errors while retrieving the simulation results.");
result.append(">> STDOUT: " + stdoutReader.getContents());
result.append(">> STDERR: " + stderrReader.getContents());
} else {
result.append(">> Dinero path: " + dineroPath + "\n");
result.append(">> Dinero parameters: " + paramString + "\n");
result.append(">> Simulation results:\n");

for (String line : simulationResults) {
result.append(line);
}

logger.info("DineroFrontend: all done.");
} catch (InterruptedException ie) {
result.append(">> ERROR: " + ie);
logger.severe("InterruptedException: " + ie);
} catch (java.io.IOException ioe) {
result.append(">> ERROR: " + ioe);
logger.severe("IOException: " + ioe);
} catch (Exception ex) {
result.append(">> ERROR: " + ex);
logger.severe("Exception: " + ex);
}

logger.info("DineroFrontend: all done.");
} catch (InterruptedException ie) {
result.append(">> ERROR: " + ie);
logger.severe("InterruptedException: " + ie);
} catch (IOException ioe) {
result.append(">> ERROR: " + ioe);
logger.severe("IOException: " + ioe);
} catch (Exception ex) {
result.append(">> ERROR: " + ex);
logger.severe("Exception: " + ex);
}
});

Expand Down
56 changes: 30 additions & 26 deletions utils/update-gh-pages.sh
Expand Up @@ -4,40 +4,44 @@
set -e
set -u

if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
if [[ "$JAVA_HOME" == *java-8* ]]; then
echo "Java 8 worker, should update JAR on GitHub pages"
else
echo "Non-java 8 worker. Not updating JAR"
echo "JAVA_HOME=${JAVA_HOME}"
exit 0
fi

GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [ "$GIT_BRANCH" != "master" ]; then
echo "Non-master branch: $GIT_BRANCH. Not updating the JAR."
exit 0
fi
# Debug info.
echo ${PWD}
ls

echo -n "Building JAR.. "
ant latest-jar > /dev/null
cp edumips64-latest.jar $HOME > /dev/null
echo "done."

echo -n "Cloning git repo.. "
cd $HOME
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
GH_PAGES_DIR=${HOME}/gh-pages
echo -n "Cloning gh-pages branch to ${GH_PAGES_DIR}.. "
git config --global user.email "travis@travis-ci.org"
git config --global user.name "Travis"
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/lupino3/edumips64.git gh-pages > /dev/null
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/lupino3/edumips64.git ${GH_PAGES_DIR} > /dev/null
echo "done."

cd gh-pages
mv $HOME/edumips64-latest.jar .
echo "Git branch: $TRAVIS_BRANCH"

# Execute special per-branch actions.
if [ "$TRAVIS_BRANCH" == "master" ]; then
echo -n "Building JAR.. "
ant latest-jar > /dev/null
echo "done."
cp edumips64-latest.jar ${GH_PAGES_DIR}
elif [ "$TRAVIS_BRANCH" == "webui-prototype" ]; then
echo -n "Copying web UI... "
mkdir -p ${GH_PAGES_DIR}/webui
rm -rf ${GH_PAGES_DIR}/webui/*
cp -Rf $HOME/webui/* ${GH_PAGES_DIR}/webui
echo "done."
fi

JS_DIR=${GH_PAGES_DIR}/edumips64/${TRAVIS_BRANCH}
echo "Copying the JS code to ${JS_DIR}."
mkdir -p ${JS_DIR}
cp war/edumips64/* ${JS_DIR}

# Add, commit and push files.
echo -n "Committing JAR.. "
cd ${GH_PAGES_DIR}
echo -n "Committing files.. "
git add -f .
git add -f ${JS_DIR}
git commit -m "Travis build $TRAVIS_BUILD_NUMBER pushed to gh-pages"
git push -fq origin gh-pages > /dev/null
echo "done."
Expand Down

0 comments on commit 3c3dd7f

Please sign in to comment.