diff --git a/.github/workflows/tagged-release.yml b/.github/workflows/tagged-release.yml index 484fcf5..3ab534c 100644 --- a/.github/workflows/tagged-release.yml +++ b/.github/workflows/tagged-release.yml @@ -18,7 +18,7 @@ jobs: repository: 'java-jscript' - name: "Build" run: | - ls -R; cd java-jscript; node ./build.js release ${{ github.ref }} + cd java-jscript; node ./build.js release ${{ github.ref }} - uses: "marvinpinto/action-automatic-releases@latest" with: diff --git a/.gitignore b/.gitignore index 9e46f3f..87e4e4d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,11 @@ .vscode .gradle .ignore -out -build -bin -dst +/out +/build +/bin +/dst /*.js -!/build.js \ No newline at end of file +!/build.js +/dead-code +/Metadata.java \ No newline at end of file diff --git a/build.js b/build.js index 754eea5..20a1f23 100644 --- a/build.js +++ b/build.js @@ -1,9 +1,14 @@ const { spawn } = require('child_process'); const fs = require('fs/promises'); const pt = require('path'); -const conf = require('./meta'); const { argv } = require('process'); -conf.version ??= argv[3]; + +const conf = { + name: "java-jscript", + author: "TopchetoEU", + javahome: "", + version: argv[3] +}; if (conf.version.startsWith('refs/tags/')) conf.version = conf.version.substring(10); if (conf.version.startsWith('v')) conf.version = conf.version.substring(1); diff --git a/meta.json b/meta.json deleted file mode 100644 index fb3c57f..0000000 --- a/meta.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "java-jscript", - "author": "TopchetoEU", - "javahome": "" -} \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/filesystem/File.java b/src/me/topchetoeu/jscript/filesystem/File.java deleted file mode 100644 index 1f57cee..0000000 --- a/src/me/topchetoeu/jscript/filesystem/File.java +++ /dev/null @@ -1,22 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; - -public interface File { - int read(byte[] buff) throws IOException; - void write(byte[] buff) throws IOException; - long tell() throws IOException; - void seek(long offset, int pos) throws IOException; - void close() throws IOException; - Permissions perms(); - - default String readToString() throws IOException { - seek(0, 2); - long len = tell(); - if (len < 0) return null; - seek(0, 0); - byte[] res = new byte[(int)len]; - if (read(res) < 0) return null; - return new String(res); - } -} \ No newline at end of file diff --git a/src/me/topchetoeu/jscript/filesystem/Filesystem.java b/src/me/topchetoeu/jscript/filesystem/Filesystem.java deleted file mode 100644 index 8986220..0000000 --- a/src/me/topchetoeu/jscript/filesystem/Filesystem.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; -import java.nio.file.Path; - -public interface Filesystem extends PermissionsProvider { - public static enum EntryType { - NONE, - FILE, - FOLDER, - } - - File open(Path path) throws IOException; - EntryType type(Path path); - boolean mkdir(Path path); - boolean rm(Path path) throws IOException; -} diff --git a/src/me/topchetoeu/jscript/filesystem/InaccessibleFile.java b/src/me/topchetoeu/jscript/filesystem/InaccessibleFile.java deleted file mode 100644 index e2e9b74..0000000 --- a/src/me/topchetoeu/jscript/filesystem/InaccessibleFile.java +++ /dev/null @@ -1,27 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; - -public class InaccessibleFile implements File { - @Override - public int read(byte[] buff) throws IOException { - return -1; - } - @Override - public void write(byte[] buff) throws IOException { - } - @Override - public long tell() throws IOException { - return -1; - } - @Override - public void seek(long offset, int pos) throws IOException { - } - @Override - public void close() throws IOException { - } - @Override - public Permissions perms() { - return Permissions.NONE; - } -} diff --git a/src/me/topchetoeu/jscript/filesystem/MemoryFile.java b/src/me/topchetoeu/jscript/filesystem/MemoryFile.java deleted file mode 100644 index 0f3a7da..0000000 --- a/src/me/topchetoeu/jscript/filesystem/MemoryFile.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; - -public class MemoryFile implements File { - public byte[] data; - private int ptr = 0; - - @Override - public void close() { - data = null; - ptr = -1; - } - - @Override - public int read(byte[] buff) throws IOException { - if (data == null) return -1; - if (ptr == data.length) return -1; - int n = Math.min(buff.length, data.length - ptr); - System.arraycopy(data, ptr, buff, 0, n); - return n; - } - - @Override - public void seek(long offset, int pos) throws IOException { - if (data == null) return; - if (pos == 0) ptr = (int)offset; - else if (pos == 1) ptr += (int)offset; - else ptr = data.length - (int)offset; - - ptr = (int)Math.max(Math.min(ptr, data.length), 0); - } - - @Override - public long tell() throws IOException { - if (data == null) return -1; - return ptr; - } - - @Override - public void write(byte[] buff) throws IOException { } - @Override - public Permissions perms() { - if (data == null) return Permissions.NONE; - else return Permissions.READ; - } - - public MemoryFile(byte[] data) { - this.data = data; - } -} diff --git a/src/me/topchetoeu/jscript/filesystem/Permissions.java b/src/me/topchetoeu/jscript/filesystem/Permissions.java deleted file mode 100644 index c9112ad..0000000 --- a/src/me/topchetoeu/jscript/filesystem/Permissions.java +++ /dev/null @@ -1,17 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -public enum Permissions { - NONE("", false, false), - READ("r", true, false), - READ_WRITE("rw", true, true); - - public final String readMode; - public final boolean readable; - public final boolean writable; - - private Permissions(String mode, boolean r, boolean w) { - this.readMode = mode; - this.readable = r; - this.writable = w; - } -} diff --git a/src/me/topchetoeu/jscript/filesystem/PermissionsProvider.java b/src/me/topchetoeu/jscript/filesystem/PermissionsProvider.java deleted file mode 100644 index 06998c0..0000000 --- a/src/me/topchetoeu/jscript/filesystem/PermissionsProvider.java +++ /dev/null @@ -1,7 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.nio.file.Path; - -public interface PermissionsProvider { - Permissions perms(Path file); -} diff --git a/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java b/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java deleted file mode 100644 index 9b88a18..0000000 --- a/src/me/topchetoeu/jscript/filesystem/PhysicalFile.java +++ /dev/null @@ -1,53 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.file.Path; - -public class PhysicalFile implements File { - private RandomAccessFile file; - private Permissions perms; - - @Override - public int read(byte[] buff) throws IOException { - if (!perms.readable) return -1; - return file.read(buff); - } - @Override - public void write(byte[] buff) throws IOException { - if (!perms.writable) return; - file.write(buff); - } - @Override - public long tell() throws IOException { - if (!perms.readable) return -1; - return file.getFilePointer(); - } - @Override - public void seek(long offset, int pos) throws IOException { - if (!perms.readable) return; - if (pos == 0) file.seek(offset); - else if (pos == 1) file.seek(tell() + offset); - else file.seek(file.length() + offset); - } - @Override - public void close() throws IOException { - if (!perms.readable) return; - file.close(); - file = null; - perms = Permissions.NONE; - } - @Override - public Permissions perms() { - return perms; - } - - public PhysicalFile(Path path, Permissions perms) throws IOException { - if (!path.toFile().canWrite() && perms.writable) perms = Permissions.READ; - if (!path.toFile().canRead() && perms.readable) perms = Permissions.NONE; - - this.perms = perms; - if (perms == Permissions.NONE) this.file = null; - else this.file = new RandomAccessFile(path.toString(), perms.readMode); - } -} diff --git a/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java b/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java deleted file mode 100644 index 043b7b7..0000000 --- a/src/me/topchetoeu/jscript/filesystem/PhysicalFilesystem.java +++ /dev/null @@ -1,75 +0,0 @@ -package me.topchetoeu.jscript.filesystem; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.stream.Collectors; - -public class PhysicalFilesystem implements Filesystem { - public final Path root; - public final PermissionsProvider perms; - - private static Path joinPaths(Path root, Path file) { - if (file.isAbsolute()) file = file.getRoot().relativize(file); - file = file.normalize(); - - while (true) { - if (file.startsWith("..")) file = file.subpath(1, file.getNameCount()); - else if (file.startsWith(".")) file = file.subpath(1, file.getNameCount()); - else break; - } - - return Path.of(root.toString(), file.toString()); - } - - @Override - public boolean mkdir(Path path) { - if (!perms(path).writable) return false; - path = joinPaths(root, path); - return path.toFile().mkdirs(); - } - @Override - public File open(Path path) throws IOException { - var perms = perms(path); - if (perms == Permissions.NONE) return new InaccessibleFile(); - path = joinPaths(root, path); - - if (path.toFile().isDirectory()) { - return new MemoryFile(String.join("\n", Files.list(path).map(Path::toString).collect(Collectors.toList())).getBytes()); - } - else if (path.toFile().isFile()) { - return new PhysicalFile(path, perms); - } - else return new InaccessibleFile(); - } - @Override - public boolean rm(Path path) { - if (!perms(path).writable) return false; - return joinPaths(root, path).toFile().delete(); - } - @Override - public EntryType type(Path path) { - if (!perms(path).readable) return EntryType.NONE; - path = joinPaths(root, path); - - if (!path.toFile().exists()) return EntryType.NONE; - if (path.toFile().isFile()) return EntryType.FILE; - else return EntryType.FOLDER; - - } - @Override - public Permissions perms(Path path) { - path = joinPaths(root, path); - var res = perms.perms(path); - - if (!path.toFile().canWrite() && res.writable) res = Permissions.READ; - if (!path.toFile().canRead() && res.readable) res = Permissions.NONE; - - return res; - } - - public PhysicalFilesystem(Path root, PermissionsProvider perms) { - this.root = root; - this.perms = perms; - } -}