-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add package.json js-plugins support (#4389)
In support of #4405
- Loading branch information
1 parent
acebb6f
commit 87ee5ec
Showing
24 changed files
with
708 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ plugins { | |
} | ||
|
||
description = 'The Deephaven plugin interface' | ||
|
||
Classpaths.inheritImmutables(project) |
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
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,18 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.plugin.js; | ||
|
||
import io.deephaven.plugin.Plugin; | ||
|
||
/** | ||
* A js plugin is a {@link Plugin} that allows adding javascript code under the server's URL path "js-plugins/". See | ||
* <a href="https://github.com/deephaven/deephaven-plugins#js-plugins">deephaven-plugins#js-plugins</a> for more details | ||
* about the underlying construction for js plugins. | ||
* | ||
* @see JsPluginPackagePath | ||
* @see JsPluginManifestPath | ||
*/ | ||
public interface JsPlugin extends Plugin { | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
plugin/src/main/java/io/deephaven/plugin/js/JsPluginBase.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 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.plugin.js; | ||
|
||
import io.deephaven.plugin.Plugin; | ||
import io.deephaven.plugin.PluginBase; | ||
|
||
public abstract class JsPluginBase extends PluginBase implements JsPlugin { | ||
|
||
@Override | ||
public final <T, V extends Plugin.Visitor<T>> T walk(V visitor) { | ||
return visitor.visit(this); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
plugin/src/main/java/io/deephaven/plugin/js/JsPluginManifestPath.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,58 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.plugin.js; | ||
|
||
import io.deephaven.annotations.SimpleStyle; | ||
import org.immutables.value.Value.Immutable; | ||
import org.immutables.value.Value.Parameter; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* A manifest-based js plugin sourced from a {@value MANIFEST_JSON} file. | ||
*/ | ||
@Immutable | ||
@SimpleStyle | ||
public abstract class JsPluginManifestPath extends JsPluginBase { | ||
|
||
public static final String MANIFEST_JSON = "manifest.json"; | ||
|
||
/** | ||
* Creates a manifest-based js plugin from {@code manifestRoot}. | ||
* | ||
* @param manifestRoot the manifest root directory path | ||
* @return the manifest-based js plugin | ||
*/ | ||
public static JsPluginManifestPath of(Path manifestRoot) { | ||
return ImmutableJsPluginManifestPath.of(manifestRoot); | ||
} | ||
|
||
/** | ||
* The manifest root path directory path. | ||
* | ||
* @return the manifest root directory path | ||
*/ | ||
@Parameter | ||
public abstract Path path(); | ||
|
||
/** | ||
* The {@value MANIFEST_JSON} file path, relative to {@link #path()}. Equivalent to | ||
* {@code path().resolve(MANIFEST_JSON)}. | ||
* | ||
* @return the manifest json file path | ||
*/ | ||
public final Path manifestJson() { | ||
return path().resolve(MANIFEST_JSON); | ||
} | ||
|
||
/** | ||
* Equivalent to {@code JsPluginPackagePath.of(path().resolve(name))}. | ||
* | ||
* @param name the package name | ||
* @return the package path | ||
*/ | ||
public final JsPluginPackagePath packagePath(String name) { | ||
return JsPluginPackagePath.of(path().resolve(name)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
plugin/src/main/java/io/deephaven/plugin/js/JsPluginPackagePath.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,46 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.plugin.js; | ||
|
||
import io.deephaven.annotations.SimpleStyle; | ||
import org.immutables.value.Value.Immutable; | ||
import org.immutables.value.Value.Parameter; | ||
|
||
import java.nio.file.Path; | ||
|
||
/** | ||
* A package-based js plugin sourced from a {@value PACKAGE_JSON} file. | ||
*/ | ||
@Immutable | ||
@SimpleStyle | ||
public abstract class JsPluginPackagePath extends JsPluginBase { | ||
public static final String PACKAGE_JSON = "package.json"; | ||
|
||
/** | ||
* Creates a package-based js plugin from {@code packageRoot}. | ||
* | ||
* @param packageRoot the package root directory path | ||
* @return the package-based js plugin | ||
*/ | ||
public static JsPluginPackagePath of(Path packageRoot) { | ||
return ImmutableJsPluginPackagePath.of(packageRoot); | ||
} | ||
|
||
/** | ||
* The package root directory path. | ||
* | ||
* @return the package root directory path | ||
*/ | ||
@Parameter | ||
public abstract Path path(); | ||
|
||
/** | ||
* The {@value PACKAGE_JSON} file path. Equivalent to {@code path().resolve(PACKAGE_JSON)}. | ||
* | ||
* @return the package json file path | ||
*/ | ||
public final Path packageJson() { | ||
return path().resolve(PACKAGE_JSON); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
server/jetty/src/main/java/io/deephaven/server/jetty/CopyHelper.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,44 @@ | ||
/** | ||
* Copyright (c) 2016-2023 Deephaven Data Labs and Patent Pending | ||
*/ | ||
package io.deephaven.server.jetty; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.FileVisitResult; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.SimpleFileVisitor; | ||
import java.nio.file.StandardCopyOption; | ||
import java.nio.file.attribute.BasicFileAttributes; | ||
import java.util.Objects; | ||
|
||
class CopyHelper { | ||
static void copyRecursive(Path src, Path dst) throws IOException { | ||
Files.createDirectories(dst.getParent()); | ||
Files.walkFileTree(src, new CopyRecursiveVisitor(src, dst)); | ||
} | ||
|
||
private static class CopyRecursiveVisitor extends SimpleFileVisitor<Path> { | ||
private final Path src; | ||
private final Path dst; | ||
|
||
public CopyRecursiveVisitor(Path src, Path dst) { | ||
this.src = Objects.requireNonNull(src); | ||
this.dst = Objects.requireNonNull(dst); | ||
} | ||
|
||
@Override | ||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { | ||
// Note: toString() necessary for src/dst that don't share the same root FS | ||
Files.copy(dir, dst.resolve(src.relativize(dir).toString()), StandardCopyOption.COPY_ATTRIBUTES); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
|
||
@Override | ||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { | ||
// Note: toString() necessary for src/dst that don't share the same root FS | ||
Files.copy(file, dst.resolve(src.relativize(file).toString()), StandardCopyOption.COPY_ATTRIBUTES); | ||
return FileVisitResult.CONTINUE; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.