feat: some cleanup
This commit is contained in:
parent
3824d11c97
commit
692fae4049
2
.github/workflows/tagged-release.yml
vendored
2
.github/workflows/tagged-release.yml
vendored
@ -18,7 +18,7 @@ jobs:
|
|||||||
repository: 'java-jscript'
|
repository: 'java-jscript'
|
||||||
- name: "Build"
|
- name: "Build"
|
||||||
run: |
|
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"
|
- uses: "marvinpinto/action-automatic-releases@latest"
|
||||||
with:
|
with:
|
||||||
|
10
.gitignore
vendored
10
.gitignore
vendored
@ -1,9 +1,11 @@
|
|||||||
.vscode
|
.vscode
|
||||||
.gradle
|
.gradle
|
||||||
.ignore
|
.ignore
|
||||||
out
|
/out
|
||||||
build
|
/build
|
||||||
bin
|
/bin
|
||||||
dst
|
/dst
|
||||||
/*.js
|
/*.js
|
||||||
!/build.js
|
!/build.js
|
||||||
|
/dead-code
|
||||||
|
/Metadata.java
|
9
build.js
9
build.js
@ -1,9 +1,14 @@
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process');
|
||||||
const fs = require('fs/promises');
|
const fs = require('fs/promises');
|
||||||
const pt = require('path');
|
const pt = require('path');
|
||||||
const conf = require('./meta');
|
|
||||||
const { argv } = require('process');
|
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('refs/tags/')) conf.version = conf.version.substring(10);
|
||||||
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
if (conf.version.startsWith('v')) conf.version = conf.version.substring(1);
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "java-jscript",
|
|
||||||
"author": "TopchetoEU",
|
|
||||||
"javahome": ""
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
package me.topchetoeu.jscript.filesystem;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public interface PermissionsProvider {
|
|
||||||
Permissions perms(Path file);
|
|
||||||
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user