diff options
Diffstat (limited to 'language-web')
3 files changed, 31 insertions, 42 deletions
diff --git a/language-web/build.gradle b/language-web/build.gradle index e04af7cb..e00b88d8 100644 --- a/language-web/build.gradle +++ b/language-web/build.gradle | |||
@@ -1,3 +1,5 @@ | |||
1 | apply from: "${rootDir}/gradle/xtext-common.gradle" | ||
2 | |||
1 | dependencies { | 3 | dependencies { |
2 | compile project(':language') | 4 | compile project(':language') |
3 | compile project(':language-ide') | 5 | compile project(':language-ide') |
@@ -94,9 +96,7 @@ task webpackServe(type: NpmTask) { | |||
94 | } | 96 | } |
95 | 97 | ||
96 | eclipse { | 98 | eclipse { |
97 | project { | 99 | project.file.whenMerged { |
98 | file.whenMerged { | 100 | natures.remove('org.eclipse.wst.common.modulecore.ModuleCoreNature') |
99 | natures.remove('org.eclipse.wst.common.modulecore.ModuleCoreNature') | ||
100 | } | ||
101 | } | 101 | } |
102 | } | 102 | } |
diff --git a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java index 5de708f0..337df54b 100644 --- a/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java +++ b/language-web/src/main/java/org/eclipse/viatra/solver/language/web/ProblemServlet.java | |||
@@ -3,9 +3,9 @@ | |||
3 | */ | 3 | */ |
4 | package org.eclipse.viatra.solver.language.web; | 4 | package org.eclipse.viatra.solver.language.web; |
5 | 5 | ||
6 | import com.google.inject.Injector; | ||
7 | import javax.servlet.ServletException; | 6 | import javax.servlet.ServletException; |
8 | import javax.servlet.annotation.WebServlet; | 7 | import javax.servlet.annotation.WebServlet; |
8 | |||
9 | import org.eclipse.xtext.util.DisposableRegistry; | 9 | import org.eclipse.xtext.util.DisposableRegistry; |
10 | import org.eclipse.xtext.web.servlet.XtextServlet; | 10 | import org.eclipse.xtext.web.servlet.XtextServlet; |
11 | 11 | ||
@@ -17,14 +17,18 @@ public class ProblemServlet extends XtextServlet { | |||
17 | 17 | ||
18 | private static final long serialVersionUID = 1L; | 18 | private static final long serialVersionUID = 1L; |
19 | 19 | ||
20 | DisposableRegistry disposableRegistry; | 20 | // Xtext requires a mutable servlet instance field. |
21 | @SuppressWarnings("squid:S2226") | ||
22 | private DisposableRegistry disposableRegistry; | ||
21 | 23 | ||
24 | @Override | ||
22 | public void init() throws ServletException { | 25 | public void init() throws ServletException { |
23 | super.init(); | 26 | super.init(); |
24 | Injector injector = new ProblemWebSetup().createInjectorAndDoEMFRegistration(); | 27 | var injector = new ProblemWebSetup().createInjectorAndDoEMFRegistration(); |
25 | this.disposableRegistry = injector.getInstance(DisposableRegistry.class); | 28 | this.disposableRegistry = injector.getInstance(DisposableRegistry.class); |
26 | } | 29 | } |
27 | 30 | ||
31 | @Override | ||
28 | public void destroy() { | 32 | public void destroy() { |
29 | if (disposableRegistry != null) { | 33 | if (disposableRegistry != null) { |
30 | disposableRegistry.dispose(); | 34 | disposableRegistry.dispose(); |
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 efa6b034..2c0413df 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 | |||
@@ -7,7 +7,6 @@ import java.io.IOException; | |||
7 | import java.net.InetSocketAddress; | 7 | import java.net.InetSocketAddress; |
8 | import java.net.URI; | 8 | import java.net.URI; |
9 | import java.net.URISyntaxException; | 9 | import java.net.URISyntaxException; |
10 | import java.net.URL; | ||
11 | 10 | ||
12 | import org.eclipse.jetty.annotations.AnnotationConfiguration; | 11 | import org.eclipse.jetty.annotations.AnnotationConfiguration; |
13 | import org.eclipse.jetty.server.Server; | 12 | import org.eclipse.jetty.server.Server; |
@@ -24,9 +23,9 @@ public class ServerLauncher { | |||
24 | 23 | ||
25 | private final Server server; | 24 | private final Server server; |
26 | 25 | ||
27 | public ServerLauncher(InetSocketAddress bindAddress, Resource baseResource) throws IOException, URISyntaxException { | 26 | public ServerLauncher(InetSocketAddress bindAddress, Resource baseResource) { |
28 | server = new Server(bindAddress); | 27 | server = new Server(bindAddress); |
29 | WebAppContext ctx = new WebAppContext(); | 28 | var ctx = new WebAppContext(); |
30 | ctx.setBaseResource(baseResource); | 29 | ctx.setBaseResource(baseResource); |
31 | ctx.setWelcomeFiles(new String[] { "index.html" }); | 30 | ctx.setWelcomeFiles(new String[] { "index.html" }); |
32 | ctx.setContextPath("/"); | 31 | ctx.setContextPath("/"); |
@@ -40,27 +39,13 @@ public class ServerLauncher { | |||
40 | public void start() throws Exception { | 39 | public void start() throws Exception { |
41 | server.start(); | 40 | server.start(); |
42 | LOG.info("Server started " + server.getURI() + "..."); | 41 | LOG.info("Server started " + server.getURI() + "..."); |
43 | new Thread() { | 42 | LOG.info("Press enter to stop the server..."); |
44 | public void run() { | 43 | int key = System.in.read(); |
45 | try { | 44 | if (key != -1) { |
46 | LOG.info("Press enter to stop the server..."); | 45 | server.stop(); |
47 | int key = System.in.read(); | 46 | } else { |
48 | if (key != -1) { | 47 | LOG.warn( |
49 | server.stop(); | 48 | "Console input is not available. In order to stop the server, you need to cancel process manually."); |
50 | } else { | ||
51 | LOG.warn( | ||
52 | "Console input is not available. In order to stop the server, you need to cancel process manually."); | ||
53 | } | ||
54 | } catch (Exception e) { | ||
55 | LOG.warn(e); | ||
56 | System.exit(-1); | ||
57 | } | ||
58 | } | ||
59 | }.start(); | ||
60 | try { | ||
61 | server.join(); | ||
62 | } catch (InterruptedException e) { | ||
63 | LOG.info(e); | ||
64 | } | 49 | } |
65 | } | 50 | } |
66 | 51 | ||
@@ -75,34 +60,34 @@ public class ServerLauncher { | |||
75 | if (baseResourceOverride != null) { | 60 | if (baseResourceOverride != null) { |
76 | return Resource.newResource(baseResourceOverride); | 61 | return Resource.newResource(baseResourceOverride); |
77 | } | 62 | } |
78 | URL indexUrlInJar = ServerLauncher.class.getResource("/webapp/index.html"); | 63 | var indexUrlInJar = ServerLauncher.class.getResource("/webapp/index.html"); |
79 | if (indexUrlInJar == null) { | 64 | if (indexUrlInJar == null) { |
80 | throw new RuntimeException("Cannot find pacakged web assets"); | 65 | throw new IOException("Cannot find pacakged web assets"); |
81 | } | 66 | } |
82 | URI webRootUri = URI.create(indexUrlInJar.toURI().toASCIIString().replaceFirst("/index.html$", "/")); | 67 | var webRootUri = URI.create(indexUrlInJar.toURI().toASCIIString().replaceFirst("/index.html$", "/")); |
83 | return Resource.newResource(webRootUri); | 68 | return Resource.newResource(webRootUri); |
84 | } | 69 | } |
85 | 70 | ||
86 | public static void main(String[] args) { | 71 | public static void main(String[] args) { |
87 | String listenAddress = System.getenv("LISTEN_ADDRESS"); | 72 | var listenAddress = System.getenv("LISTEN_ADDRESS"); |
88 | if (listenAddress == null) { | 73 | if (listenAddress == null) { |
89 | listenAddress = "localhost"; | 74 | listenAddress = "localhost"; |
90 | } | 75 | } |
91 | int port = 1312; | 76 | var port = 1312; |
92 | String portStr = System.getenv("LISTEN_PORT"); | 77 | var portStr = System.getenv("LISTEN_PORT"); |
93 | if (portStr != null) { | 78 | if (portStr != null) { |
94 | try { | 79 | try { |
95 | port = Integer.parseInt(portStr); | 80 | port = Integer.parseInt(portStr); |
96 | } catch (NumberFormatException e) { | 81 | } catch (NumberFormatException e) { |
97 | LOG.warn(e); | 82 | LOG.warn(e); |
98 | System.exit(-1); | 83 | System.exit(1); |
99 | } | 84 | } |
100 | } | 85 | } |
101 | String baseResourceOverride = System.getenv("BASE_RESOURCE"); | 86 | var baseResourceOverride = System.getenv("BASE_RESOURCE"); |
102 | try { | 87 | try { |
103 | InetSocketAddress bindAddress = getBindAddress(listenAddress, port); | 88 | var bindAddress = getBindAddress(listenAddress, port); |
104 | Resource baseResource = getBaseResource(baseResourceOverride); | 89 | var baseResource = getBaseResource(baseResourceOverride); |
105 | ServerLauncher serverLauncher = new ServerLauncher(bindAddress, baseResource); | 90 | var serverLauncher = new ServerLauncher(bindAddress, baseResource); |
106 | serverLauncher.start(); | 91 | serverLauncher.start(); |
107 | } catch (Exception exception) { | 92 | } catch (Exception exception) { |
108 | LOG.warn(exception); | 93 | LOG.warn(exception); |