aboutsummaryrefslogtreecommitdiffstats
path: root/language-web
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-06-29 18:29:13 +0200
committerLibravatar Kristóf Marussy <marussy@mit.bme.hu>2021-06-29 18:31:07 +0200
commitad35e53fa23be5312f1e4b8d830a73e8ade1f08c (patch)
treeb48aeb3034358e0a02a6d17221428522ad879b77 /language-web
parentRemove Xtext generated Javascript file (diff)
downloadrefinery-ad35e53fa23be5312f1e4b8d830a73e8ade1f08c.tar.gz
refinery-ad35e53fa23be5312f1e4b8d830a73e8ade1f08c.tar.zst
refinery-ad35e53fa23be5312f1e4b8d830a73e8ade1f08c.zip
Generate all files on build
Diffstat (limited to 'language-web')
-rw-r--r--language-web/build.gradle77
-rw-r--r--language-web/package.json5
-rw-r--r--language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java105
-rw-r--r--language-web/webpack.config.js3
4 files changed, 144 insertions, 46 deletions
diff --git a/language-web/build.gradle b/language-web/build.gradle
index 3e0008da..ff0f9e9c 100644
--- a/language-web/build.gradle
+++ b/language-web/build.gradle
@@ -1,31 +1,76 @@
1plugins {
2 id 'war'
3}
4
5dependencies { 1dependencies {
6 compile project(':language') 2 compile project(':language')
7 compile project(':language-ide') 3 compile project(':language-ide')
8 compile "org.eclipse.xtext:org.eclipse.xtext.xbase.web:${xtextVersion}" 4 compile "org.eclipse.xtext:org.eclipse.xtext.xbase.web:${xtextVersion}"
9 compile "org.eclipse.xtext:org.eclipse.xtext.web.servlet:${xtextVersion}" 5 compile "org.eclipse.xtext:org.eclipse.xtext.web.servlet:${xtextVersion}"
10 compile "org.eclipse.xtend:org.eclipse.xtend.lib:${xtextVersion}" 6 compile "org.eclipse.xtend:org.eclipse.xtend.lib:${xtextVersion}"
11 compile "org.webjars:requirejs:2.3.6" 7 compile "org.eclipse.jetty:jetty-server:9.4.42.v20210604"
12 compile "org.webjars:requirejs-text:2.0.15" 8 compile "org.eclipse.jetty:jetty-annotations:9.4.42.v20210604"
13 compile "org.webjars:jquery:3.6.0" 9 compile "org.slf4j:slf4j-simple:1.7.31"
14 // CodeMirror 5.53.0 and later is incompatible with Xtext due to 10}
15 // https://github.com/codemirror/CodeMirror/commit/b2d26b4ccb1d0994ae84d18ad8b84018de176da9#commitcomment-41525744 11
16 compile "org.webjars.npm:codemirror:5.52.2" 12def webpackOutputDir = "${buildDir}/webpack"
17 providedCompile "org.eclipse.jetty:jetty-annotations:9.4.42.v20210604" 13def productionResources = "${webpackOutputDir}/production"
18 providedCompile "org.eclipse.jetty:jetty-rewrite:9.4.42.v20210604" 14def mainClass = 'org.eclipse.viatra.solver.language.web.ServerLauncher'
19 providedCompile "org.slf4j:slf4j-simple:1.7.31" 15
16apply plugin: 'com.moowork.node'
17
18for (environment in ['production', 'development']) {
19 def taskName = 'webpack' + environment.substring(0, 1).toUpperCase() + environment.substring(1);
20 task(taskName, type: NpmTask) {
21 dependsOn ':language:generateXtext'
22 inputs.dir 'src/main/css'
23 inputs.dir 'src/main/html'
24 inputs.dir 'src/main/js'
25 inputs.dir "${buildDir}/generated/sources/xtext/js"
26 inputs.file 'webpack.config.js'
27 outputs.dir "${webpackOutputDir}/${environment}"
28 args = ['run', 'build']
29 setEnvironment NODE_ENV: environment
30 }
31}
32
33apply plugin: 'application'
34mainClassName = mainClass
35distZip.enabled = false
36
37jar {
38 dependsOn webpackProduction
39 from(productionResources) {
40 into 'webapp'
41 }
42}
43
44apply plugin: 'com.github.johnrengelman.shadow'
45shadowDistZip.enabled = false
46
47shadowJar {
48 dependsOn webpackProduction
49 from(project.convention.getPlugin(JavaPluginConvention).sourceSets.main.output)
50 configurations = [project.configurations.runtime]
51 exclude('META-INF/INDEX.LIST', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA','schema/*',
52 '.options', '.api_description', '*.profile', 'about.*', 'about_*.html', 'about_files/*',
53 'plugin.xml', 'systembundle.properties', 'profile.list', 'META-INF/resources/xtext/**')
54 append('plugin.properties')
55 from(productionResources) {
56 into 'webapp'
57 }
20} 58}
21 59
22task jettyRun(type:JavaExec) { 60task jettyRun(type: JavaExec) {
23 dependsOn(sourceSets.main.runtimeClasspath) 61 dependsOn webpackDevelopment
62 dependsOn sourceSets.main.runtimeClasspath
24 classpath = sourceSets.main.runtimeClasspath.filter{it.exists()} 63 classpath = sourceSets.main.runtimeClasspath.filter{it.exists()}
25 main = 'org.eclipse.viatra.solver.language.web.ServerLauncher' 64 main = mainClass
26 standardInput = System.in 65 standardInput = System.in
27 group = 'run' 66 group = 'run'
28 description = 'Starts an example Jetty server with your language' 67 description = 'Starts an example Jetty server with your language'
68 environment(
69 DEV_MODE: 'true',
70 LISTEN_ADDRESS: 'localhost',
71 LISTEN_PORT: '1313',
72 BASE_RESOURCE: "${webpackOutputDir}/development"
73 )
29} 74}
30 75
31eclipse { 76eclipse {
diff --git a/language-web/package.json b/language-web/package.json
index c503b306..f75aeced 100644
--- a/language-web/package.json
+++ b/language-web/package.json
@@ -1,10 +1,11 @@
1{ 1{
2 "name": "language-web", 2 "name": "language-web",
3 "version": "0.1.0", 3 "version": "1.0.0",
4 "description": "Web frontend for VIATRA-Generator", 4 "description": "Web frontend for VIATRA-Generator",
5 "main": "index.js", 5 "main": "index.js",
6 "scripts": { 6 "scripts": {
7 "test": "echo \"Error: no test specified\" && exit 1" 7 "test": "echo \"Error: no test specified\" && exit 1",
8 "build": "webpack"
8 }, 9 },
9 "repository": { 10 "repository": {
10 "type": "git", 11 "type": "git",
diff --git a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java
index d0b2562a..7127d7d5 100644
--- a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java
+++ b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ServerLauncher.java
@@ -3,55 +3,106 @@
3 */ 3 */
4package org.eclipse.viatra.solver.language.web; 4package org.eclipse.viatra.solver.language.web;
5 5
6import java.io.IOException;
6import java.net.InetSocketAddress; 7import java.net.InetSocketAddress;
8import java.net.URI;
9import java.net.URISyntaxException;
10import java.net.URL;
11
7import org.eclipse.jetty.annotations.AnnotationConfiguration; 12import org.eclipse.jetty.annotations.AnnotationConfiguration;
8import org.eclipse.jetty.server.Server; 13import org.eclipse.jetty.server.Server;
9import org.eclipse.jetty.util.log.Slf4jLog; 14import org.eclipse.jetty.util.log.Slf4jLog;
15import org.eclipse.jetty.util.resource.Resource;
10import org.eclipse.jetty.webapp.Configuration; 16import org.eclipse.jetty.webapp.Configuration;
11import org.eclipse.jetty.webapp.MetaInfConfiguration; 17import org.eclipse.jetty.webapp.MetaInfConfiguration;
12import org.eclipse.jetty.webapp.WebAppContext; 18import org.eclipse.jetty.webapp.WebAppContext;
13import org.eclipse.jetty.webapp.WebInfConfiguration; 19import org.eclipse.jetty.webapp.WebInfConfiguration;
14import org.eclipse.jetty.webapp.WebXmlConfiguration; 20import org.eclipse.jetty.webapp.WebXmlConfiguration;
15 21
16/**
17 * This program starts an HTTP server for testing the web integration of your
18 * DSL. Just execute it and point a web browser to http://localhost:8080/
19 */
20public class ServerLauncher { 22public class ServerLauncher {
21 public static void main(String[] args) { 23 private static final Slf4jLog LOG = new Slf4jLog(ServerLauncher.class.getName());
22 Server server = new Server(new InetSocketAddress("localhost", 1313)); 24
25 private final Server server;
26
27 public ServerLauncher(InetSocketAddress bindAddress, Resource baseResource) throws IOException, URISyntaxException {
28 server = new Server(bindAddress);
23 WebAppContext ctx = new WebAppContext(); 29 WebAppContext ctx = new WebAppContext();
24 ctx.setResourceBase("src/main/webapp"); 30 ctx.setBaseResource(baseResource);
25 ctx.setWelcomeFiles(new String[] { "index.html" }); 31 ctx.setWelcomeFiles(new String[] { "index.html" });
26 ctx.setContextPath("/"); 32 ctx.setContextPath("/");
27 ctx.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebXmlConfiguration(), 33 ctx.setConfigurations(new Configuration[] { new AnnotationConfiguration(), new WebXmlConfiguration(),
28 new WebInfConfiguration(), new MetaInfConfiguration() }); 34 new WebInfConfiguration(), new MetaInfConfiguration() });
29 ctx.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/language-web/.*,.*\\.jar"); 35 ctx.setAttribute(WebInfConfiguration.CONTAINER_JAR_PATTERN, ".*/build/classes/.*,.*\\.jar");
30 ctx.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false"); 36 ctx.setInitParameter("org.eclipse.jetty.servlet.Default.useFileMappedBuffer", "false");
31 server.setHandler(ctx); 37 server.setHandler(ctx);
32 Slf4jLog log = new Slf4jLog(ServerLauncher.class.getName()); 38 }
33 try { 39
34 server.start(); 40 public void start() throws Exception {
35 log.info("Server started " + server.getURI() + "..."); 41 server.start();
36 new Thread() { 42 LOG.info("Server started " + server.getURI() + "...");
37 public void run() { 43 new Thread() {
38 try { 44 public void run() {
39 log.info("Press enter to stop the server..."); 45 try {
40 int key = System.in.read(); 46 LOG.info("Press enter to stop the server...");
41 if (key != -1) { 47 int key = System.in.read();
42 server.stop(); 48 if (key != -1) {
43 } else { 49 server.stop();
44 log.warn( 50 } else {
45 "Console input is not available. In order to stop the server, you need to cancel process manually."); 51 LOG.warn(
46 } 52 "Console input is not available. In order to stop the server, you need to cancel process manually.");
47 } catch (Exception e) {
48 log.warn(e);
49 } 53 }
54 } catch (Exception e) {
55 LOG.warn(e);
56 System.exit(-1);
50 } 57 }
51 }.start(); 58 }
59 }.start();
60 try {
52 server.join(); 61 server.join();
62 } catch (InterruptedException e) {
63 LOG.info(e);
64 }
65 }
66
67 private static InetSocketAddress getBindAddress(String listenAddress, int port) {
68 if (listenAddress == null) {
69 return new InetSocketAddress(port);
70 }
71 return new InetSocketAddress(listenAddress, port);
72 }
73
74 private static Resource getBaseResource(String baseResourceOverride) throws IOException, URISyntaxException {
75 if (baseResourceOverride != null) {
76 return Resource.newResource(baseResourceOverride);
77 }
78 URL indexUrlInJar = ServerLauncher.class.getResource("/webapp/index.html");
79 if (indexUrlInJar == null) {
80 throw new RuntimeException("Cannot find pacakged web assets");
81 }
82 URI webRootUri = URI.create(indexUrlInJar.toURI().toASCIIString().replaceFirst("/index.html$", "/"));
83 return Resource.newResource(webRootUri);
84 }
85
86 public static void main(String[] args) {
87 String listenAddress = System.getenv("LiSTEN_ADDRESS");
88 int port = 8080;
89 String portStr = System.getenv("LISTEN_PORT");
90 if (portStr != null) {
91 try {
92 port = Integer.parseInt(portStr);
93 } catch (NumberFormatException e) {
94 LOG.warn(e);
95 System.exit(-1);
96 }
97 }
98 String baseResourceOverride = System.getenv("BASE_RESOURCE");
99 try {
100 InetSocketAddress bindAddress = getBindAddress(listenAddress, port);
101 Resource baseResource = getBaseResource(baseResourceOverride);
102 ServerLauncher serverLauncher = new ServerLauncher(bindAddress, baseResource);
103 serverLauncher.start();
53 } catch (Exception exception) { 104 } catch (Exception exception) {
54 log.warn(exception.getMessage()); 105 LOG.warn(exception);
55 System.exit(1); 106 System.exit(1);
56 } 107 }
57 } 108 }
diff --git a/language-web/webpack.config.js b/language-web/webpack.config.js
index bd999a85..ec07d4cf 100644
--- a/language-web/webpack.config.js
+++ b/language-web/webpack.config.js
@@ -4,12 +4,13 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
4const MiniCssExtractPlugin = require("mini-css-extract-plugin"); 4const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5 5
6const devMode = process.env.NODE_ENV !== 'production'; 6const devMode = process.env.NODE_ENV !== 'production';
7const outputPath = path.resolve(__dirname, 'build/webpack', devMode ? 'development' : 'production');
7 8
8module.exports = { 9module.exports = {
9 mode: devMode ? 'development' : 'production', 10 mode: devMode ? 'development' : 'production',
10 entry: './src/main/js', 11 entry: './src/main/js',
11 output: { 12 output: {
12 path: path.resolve(__dirname, 'src/main/webapp'), 13 path: outputPath,
13 publicPath: '/', 14 publicPath: '/',
14 filename: devMode ? '[name].js' : '[contenthash].js', 15 filename: devMode ? '[name].js' : '[contenthash].js',
15 chunkFilename: devMode ? '[id].js' : '[contenthash].js', 16 chunkFilename: devMode ? '[id].js' : '[contenthash].js',