Skip to content

Commit

Permalink
Plugins can now register routes
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueWinter committed May 7, 2024
1 parent b45ec53 commit 14e61c4
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 16 deletions.
9 changes: 7 additions & 2 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SimofaProject</artifactId>
<groupId>dev.truewinter.simofa</groupId>
<version>0.1.2</version>
<version>0.1.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -23,7 +23,7 @@
<dependency>
<groupId>dev.truewinter</groupId>
<artifactId>PluginManager</artifactId>
<version>0.0.6</version>
<version>0.0.7</version>
<!--<scope>system</scope>
<systemPath>${basedir}/../../PluginManager/target/PluginManager-0.0.5.jar</systemPath>-->
</dependency>
Expand All @@ -42,6 +42,11 @@
<artifactId>slf4j-simple</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>5.4.2</version>
</dependency>
</dependencies>

<build>
Expand Down
9 changes: 9 additions & 0 deletions api/src/main/java/dev/truewinter/simofa/api/SimofaAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package dev.truewinter.simofa.api;

import dev.truewinter.PluginManager.Plugin;
import io.javalin.http.Handler;
import io.javalin.http.HandlerType;

import java.sql.SQLException;
import java.util.List;

Expand Down Expand Up @@ -65,4 +69,9 @@ public interface SimofaAPI {
* to match the passed DeploymentServer.
*/
void editDeploymentServer(DeploymentServer deploymentServer) throws SQLException;

/**
* Registers a route at /c/{plugin_name}/{path}
*/
void registerRoute(Plugin<SimofaAPI> plugin, HandlerType method, String path, Handler handler);
}
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>dev.truewinter.simofa</groupId>
<artifactId>SimofaProject</artifactId>
<version>0.1.2</version>
<version>0.1.3</version>
</parent>

<groupId>dev.truewinter.simofa.common</groupId>
Expand Down
2 changes: 1 addition & 1 deletion deploy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>dev.truewinter.simofa</groupId>
<artifactId>SimofaProject</artifactId>
<version>0.1.2</version>
<version>0.1.3</version>
</parent>

<groupId>dev.truewinter</groupId>
Expand Down
2 changes: 1 addition & 1 deletion officialplugins/deploymentservermonitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SimofaProject</artifactId>
<groupId>dev.truewinter.simofa</groupId>
<version>0.1.2</version>
<version>0.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion officialplugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SimofaProject</artifactId>
<groupId>dev.truewinter.simofa</groupId>
<version>0.1.2</version>
<version>0.1.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion officialplugins/pushover/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>SimofaProject</artifactId>
<groupId>dev.truewinter.simofa</groupId>
<version>0.1.2</version>
<version>0.1.3</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>SimofaProject</artifactId>
<packaging>pom</packaging>
<!-- Do not manually modify the version. Use versions:set instead -->
<version>0.1.2</version>
<version>0.1.3</version>

<modules>
<module>simofa</module>
Expand Down
7 changes: 1 addition & 6 deletions simofa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@
<parent>
<groupId>dev.truewinter.simofa</groupId>
<artifactId>SimofaProject</artifactId>
<version>0.1.2</version>
<version>0.1.3</version>
</parent>

<groupId>dev.truewinter</groupId>
<artifactId>Simofa</artifactId>
<version>${parent.version}</version>

<dependencies>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>5.4.2</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin-rendering</artifactId>
Expand Down
12 changes: 11 additions & 1 deletion simofa/src/main/java/dev/truewinter/simofa/API.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package dev.truewinter.simofa;

import dev.truewinter.PluginManager.Plugin;
import dev.truewinter.simofa.api.DeploymentServer;
import dev.truewinter.simofa.api.SimofaAPI;
import dev.truewinter.simofa.api.Website;
import dev.truewinter.simofa.api.WebsiteBuild;
import dev.truewinter.simofa.database.Database;
import io.javalin.http.Handler;
import io.javalin.http.HandlerType;

import java.sql.SQLException;
import java.util.List;

public class API implements SimofaAPI {
private final Database database;
private final WebServer server;

protected API(Database database) {
protected API(Database database, WebServer server) {
this.database = database;
this.server = server;
}

@Override
Expand Down Expand Up @@ -78,4 +83,9 @@ public void addDeploymentServer(DeploymentServer deploymentServer) throws SQLExc
public void editDeploymentServer(DeploymentServer deploymentServer) throws SQLException {
database.getDeploymentServerDatabase().editDeploymentServer(deploymentServer);
}

@Override
public void registerRoute(Plugin<SimofaAPI> plugin, HandlerType method, String path, Handler handler) {
server.registerRoute(method, String.format("/c/%s/%s", plugin.getName(), path), handler);
}
}
2 changes: 1 addition & 1 deletion simofa/src/main/java/dev/truewinter/simofa/Simofa.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void main(String[] args) throws Exception {
logger.info("Initialized build queue manager");

logger.info("Loading plugins");
pluginManager = SimofaPluginManager.getInstance(new API(database));
pluginManager = SimofaPluginManager.getInstance(new API(database, webServer));
pluginManager.getPluginManager().loadPlugins(Util.getPluginJars());
logger.info("Loaded plugins");

Expand Down
10 changes: 10 additions & 0 deletions simofa/src/main/java/dev/truewinter/simofa/WebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import dev.truewinter.simofa.routes.Route;
import dev.truewinter.simofa.routes.webhook.GithubWebhookRoute;
import io.javalin.Javalin;
import io.javalin.http.Handler;
import io.javalin.http.HandlerType;
import io.javalin.http.Header;
import io.javalin.http.staticfiles.Location;
import io.javalin.rendering.template.JavalinPebble;
Expand Down Expand Up @@ -144,6 +146,14 @@ public void run() {
}
}

public void registerRoute(HandlerType method, String path, Handler handler) {
if (server == null) {
throw new IllegalStateException("Web server not started yet");
}

server.addHandler(method, path, handler);
}

public void stopServer() {
if (server != null) {
server.stop();
Expand Down

0 comments on commit 14e61c4

Please sign in to comment.