Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
61 changed files
with
2,535 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
modules/engines/engine-graalium/execution-dirigible-web/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>engine-graalium</artifactId> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>engine-graalium-execution-dirigible-web</artifactId> | ||
<name>Engine - Graalium - Execution - Dirigible - Web</name> | ||
|
||
<properties> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<license.skip>true</license.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>dirigible-api-facade-http</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>engine-graalium-execution-dirigible</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.chrisvest</groupId> | ||
<artifactId>stormpot</artifactId> | ||
<version>3.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>dirigible-engine-javascript</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
33 changes: 33 additions & 0 deletions
33
...-web/src/main/java/org/eclipse/dirigible/graalium/web/dirigible/GraaliumJSWebHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.eclipse.dirigible.graalium.web.dirigible; | ||
|
||
import org.eclipse.dirigible.engine.js.service.JSWebHandler; | ||
import org.eclipse.dirigible.graalium.core.dirigible.DirigibleJSCodeRunner; | ||
import org.eclipse.dirigible.graalium.core.dirigible.modules.DirigibleSourceProvider; | ||
import org.eclipse.dirigible.api.v3.http.HttpRequestFacade; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public class GraaliumJSWebHandler implements JSWebHandler { | ||
|
||
private final DirigibleSourceProvider dirigibleSourceProvider = new DirigibleSourceProvider(); | ||
|
||
@Override | ||
public void handleJSRequest(String projectName, String projectFilePath, String projectFilePathParam) { | ||
try { | ||
if (HttpRequestFacade.isValid()) { | ||
HttpRequestFacade.setAttribute(HttpRequestFacade.ATTRIBUTE_REST_RESOURCE_PATH, projectFilePathParam); | ||
} | ||
|
||
String maybeJSCode = dirigibleSourceProvider.getSource(projectName, projectFilePath); | ||
if (maybeJSCode == null) { | ||
throw new IOException("JS source for project name '" + projectName + "' and file name '" + projectFilePath + " could not be found"); | ||
} | ||
|
||
Path jsCodePath = dirigibleSourceProvider.getAbsoluteSourcePath(projectName, projectFilePath); | ||
new DirigibleJSCodeRunner().run(jsCodePath); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...-web/src/main/java/org/eclipse/dirigible/graalium/web/dirigible/GraaliumJSWebService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.eclipse.dirigible.graalium.web.dirigible; | ||
|
||
import javax.ws.rs.*; | ||
import javax.ws.rs.core.Response; | ||
|
||
@Path("/js") | ||
public class GraaliumJSWebService { | ||
private static final String HTTP_PATH_MATCHER = "/{projectName}/{projectFilePath:.*\\.js|.*\\.mjs}"; | ||
private static final String HTTP_PATH_WITH_PARAM_MATCHER = "/{projectName}/{projectFilePath:.*\\.js|.*\\.mjs}/{projectFilePathParam}"; | ||
private final GraaliumJSWebHandler requestHandler = new GraaliumJSWebHandler(); | ||
|
||
@GET | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response get( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@GET | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response get( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
@POST | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response post( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@POST | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response post( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
@PUT | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response put( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@PUT | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response put( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
@PATCH | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response patch( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@PATCH | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response patch( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
@DELETE | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response delete( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@DELETE | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response delete( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
@HEAD | ||
@Path(HTTP_PATH_MATCHER) | ||
public Response head( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath | ||
) { | ||
return executeJavaScript(projectName, projectFilePath); | ||
} | ||
|
||
@HEAD | ||
@Path(HTTP_PATH_WITH_PARAM_MATCHER) | ||
public Response head( | ||
@PathParam("projectName") String projectName, | ||
@PathParam("projectFilePath") String projectFilePath, | ||
@PathParam("projectFilePathParam") String projectFilePathParam | ||
) { | ||
return executeJavaScript(projectName, projectFilePath, projectFilePathParam); | ||
} | ||
|
||
private Response executeJavaScript(String projectName, String projectFilePath) { | ||
return executeJavaScript(projectName, projectFilePath, ""); | ||
} | ||
|
||
private Response executeJavaScript(String projectName, String projectFilePath, String projectFilePathParam) { | ||
requestHandler.handleJSRequest(projectName, projectFilePath, projectFilePathParam); | ||
return Response.ok().build(); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
modules/engines/engine-graalium/execution-dirigible/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>engine-graalium</artifactId> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>engine-graalium-execution-dirigible</artifactId> | ||
<name>Engine - Graalium - Execution - Dirigible</name> | ||
|
||
<properties> | ||
<license.skip>true</license.skip> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>dirigible-commons-api</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>dirigible-repository-api</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.9.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.dirigible</groupId> | ||
<artifactId>engine-graalium-execution</artifactId> | ||
<version>7.0.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>4.11</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
61 changes: 61 additions & 0 deletions
61
...le/src/main/java/org/eclipse/dirigible/graalium/core/dirigible/DirigibleJSCodeRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.eclipse.dirigible.graalium.core.dirigible; | ||
|
||
import org.eclipse.dirigible.commons.config.Configuration; | ||
import org.eclipse.dirigible.commons.config.StaticObjects; | ||
import org.eclipse.dirigible.repository.api.IRepository; | ||
import org.eclipse.dirigible.repository.api.IRepositoryStructure; | ||
import org.eclipse.dirigible.graalium.core.dirigible.globals.DirigibleContextGlobalObject; | ||
import org.eclipse.dirigible.graalium.core.dirigible.globals.DirigibleEngineTypeGlobalObject; | ||
import org.eclipse.dirigible.graalium.core.dirigible.modules.DirigibleModuleResolver; | ||
import org.eclipse.dirigible.graalium.core.dirigible.polyfills.RequirePolyfill; | ||
import org.eclipse.dirigible.graalium.core.javascript.GraalJSCodeRunner; | ||
import org.eclipse.dirigible.graalium.core.javascript.JSCodeRunner; | ||
import org.graalvm.polyglot.Source; | ||
import org.graalvm.polyglot.Value; | ||
|
||
import java.nio.file.Path; | ||
import java.util.HashMap; | ||
|
||
public class DirigibleJSCodeRunner implements JSCodeRunner<Source, Value> { | ||
|
||
private final JSCodeRunner<Source, Value> codeRunner; | ||
|
||
public DirigibleJSCodeRunner() { | ||
var workingDirectoryPath = getDirigibleWorkingDirectory(); | ||
var cachePath = workingDirectoryPath.resolve("caches"); | ||
var coreModulesESMProxiesCachePath = cachePath.resolve("core-modules-proxies-cache"); | ||
|
||
codeRunner = GraalJSCodeRunner.newBuilder(workingDirectoryPath, cachePath) | ||
.addJSPolyfill(new RequirePolyfill()) | ||
.addGlobalObject(new DirigibleContextGlobalObject(new HashMap<>())) | ||
.addGlobalObject(new DirigibleEngineTypeGlobalObject()) | ||
.addModuleResolver(new DirigibleModuleResolver(coreModulesESMProxiesCachePath)) | ||
.waitForDebugger(DirigibleJSCodeRunner::shouldEnableDebug) | ||
.build(); | ||
} | ||
|
||
private static boolean shouldEnableDebug() { | ||
return Configuration.get("DIRIGIBLE_GRAALIUM_ENABLE_DEBUG", Boolean.FALSE.toString()).equals(Boolean.TRUE.toString()); | ||
} | ||
|
||
private Path getDirigibleWorkingDirectory() { | ||
var repository = (IRepository) StaticObjects.get(StaticObjects.REPOSITORY); | ||
String publicRegistryPath = repository.getInternalResourcePath(IRepositoryStructure.PATH_REGISTRY_PUBLIC); | ||
return Path.of(publicRegistryPath); | ||
} | ||
|
||
@Override | ||
public Value run(Path codeFilePath) { | ||
return codeRunner.run(codeFilePath); | ||
} | ||
|
||
@Override | ||
public Value run(Source codeSource) { | ||
return codeRunner.run(codeSource); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
codeRunner.close(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...a/org/eclipse/dirigible/graalium/core/dirigible/globals/DirigibleContextGlobalObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.eclipse.dirigible.graalium.core.dirigible.globals; | ||
|
||
import org.eclipse.dirigible.graalium.core.graal.globals.JSGlobalObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DirigibleContextGlobalObject implements JSGlobalObject { | ||
|
||
private final Map<Object, Object> dirigibleContextValue; | ||
|
||
public DirigibleContextGlobalObject(Map<Object, Object> dirigibleContextValue) { | ||
this.dirigibleContextValue = dirigibleContextValue != null ? dirigibleContextValue : new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "__context"; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return dirigibleContextValue; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rg/eclipse/dirigible/graalium/core/dirigible/globals/DirigibleEngineTypeGlobalObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.eclipse.dirigible.graalium.core.dirigible.globals; | ||
|
||
import org.eclipse.dirigible.graalium.core.graal.globals.JSGlobalObject; | ||
|
||
public class DirigibleEngineTypeGlobalObject implements JSGlobalObject { | ||
@Override | ||
public String getName() { | ||
return "__engine"; | ||
} | ||
|
||
@Override | ||
public Object getValue() { | ||
return "graalium"; | ||
} | ||
} |
Oops, something went wrong.