Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Java CI

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Cache Maven packages
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build with Maven
run: mvn --batch-mode --update-snapshots verify
- run: mkdir staging && cp target/*.jar staging
- uses: actions/upload-artifact@v2
with:
name: Package
path: staging
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/node
/out
/node_modules/
/test/*.class
/package-lock.json
/.nyc_output/
/coverage/
/.idea
*.iml
/target
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"name": "java-deserialization",
"version": "0.1.0",
"description": "Parse Java object serialization format using pure JavaScript",
"main": "src/index.js",
"main": "src/main/node/index.js",
"scripts": {
"test": "nyc --reporter=html --reporter=text-summary mocha test/*.js",
"gentest": "cd test && javac *.java && java GenerateTestCases > generated.js && npm test"
"built": "echo 'build here'",
"lint": "echo 'no linting setup yet'",
"test": "nyc --reporter=html --reporter=text-summary mocha src/test/node/*.js",
"gentest": "java -classpath target/classes io.github.gagern.nodeJavaDeserialization.GenerateTestCases > src/test/node/generated.js && npm test",
"package": "echo 'make publishable artifact here'"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -37,6 +40,6 @@
"long": "^4.0.0"
},
"engines": {
"node": ">=10.0.0"
"node": ">=18.0.0"
}
}
125 changes: 125 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?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>


<groupId>io.github.gagern</groupId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>nodeJavaDeserialization</artifactId>
<packaging>jar</packaging>

<properties>
<frontend-maven-plugin.version>1.13.4</frontend-maven-plugin.version>
<node.version>v20.12.1</node.version>
<npm.version>10.5.0</npm.version>

<!-- min version eight for now -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<npmVersion>${npm.version}</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm lint</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run lint</arguments>
</configuration>
</execution>
<execution>
<id>npm gentest</id>
<goals>
<goal>npm</goal>
</goals>
<phase>test-compile</phase>
<configuration>
<arguments>run gentest</arguments>
</configuration>
</execution>
<execution>
<id>npm test</id>
<goals>
<goal>npm</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>run test</arguments>
</configuration>
</execution>
<!-- <execution>-->
<!-- <id>storybook</id>-->
<!-- <goals>-->
<!-- <goal>npm</goal>-->
<!-- </goals>-->
<!-- <phase>storybook</phase>-->
<!-- <configuration>-->
<!-- <arguments>run storybook</arguments>-->
<!-- </configuration>-->
<!-- </execution>-->

<!-- <execution>-->
<!-- <id>npm integration</id>-->
<!-- <goals>-->
<!-- <goal>npm</goal>-->
<!-- </goals>-->
<!-- <phase>integration-test</phase>-->
<!-- <configuration>-->
<!-- <arguments>run test:e2e</arguments>-->
<!-- </configuration>-->
<!-- </execution>-->
<execution>
<id>npm package</id>
<goals>
<goal>npm</goal>
</goals>
<phase>package</phase>
<configuration>
<arguments>run package</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package io.github.gagern.nodeJavaDeserialization;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
Expand All @@ -10,15 +12,16 @@ class GenerateTestCases {

public static void main(String[] args) throws Exception {
System.out.print
("'use strict';\n" +
("//This is a generated file from GeneratedTestCases.java\n" +
"'use strict';\n" +
"\n" +
"const chai = require('chai');\n" +
"const expect = chai.expect;\n" +
"const zlib = require('zlib');\n" +
"const javaDeserialization = require('../');\n" +
"const javaDeserialization = require('../../main/node');\n" +
"\n" +
"// Register a classdata parser for the CompletelyCustomFormat test.\n" +
"javaDeserialization.registerClassDataParser('CompletelyCustomFormat', '0000000000000001', cls => ({}));\n" +
"// Register a classdata parser for the io.github.gagern.nodeJavaDeserialization.CompletelyCustomFormat test.\n" +
"javaDeserialization.registerClassDataParser('io.github.gagern.nodeJavaDeserialization.CompletelyCustomFormat', '0000000000000001', cls => ({}));\n" +
"\n" +
"function testCase(b64data, checks) {\n" +
" return function() {\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package io.github.gagern.nodeJavaDeserialization;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package io.github.gagern.nodeJavaDeserialization;

import java.io.Serializable;
import java.util.HashMap;

Expand Down Expand Up @@ -196,23 +198,23 @@ public void nulls() throws Exception {

@SerializationTestCase public void inheritedField() throws Exception {
writeObject(new DerivedClassWithAnotherField());
checkStrictEqual("itm.class.name", "'DerivedClassWithAnotherField'");
checkStrictEqual("itm.class.super.name", "'BaseClassWithField'");
checkStrictEqual("itm.class.name", "'io.github.gagern.nodeJavaDeserialization.DerivedClassWithAnotherField'");
checkStrictEqual("itm.class.super.name", "'io.github.gagern.nodeJavaDeserialization.BaseClassWithField'");
checkStrictEqual("itm.class.super.super", "null");
checkStrictEqual("itm.extends.DerivedClassWithAnotherField.bar", "234");
checkStrictEqual("itm.extends.DerivedClassWithAnotherField.foo", "undefined");
checkStrictEqual("itm.extends.BaseClassWithField.foo", "123");
checkStrictEqual("itm.extends['io.github.gagern.nodeJavaDeserialization.DerivedClassWithAnotherField'].bar", "234");
checkStrictEqual("itm.extends['io.github.gagern.nodeJavaDeserialization.DerivedClassWithAnotherField'].foo", "undefined");
checkStrictEqual("itm.extends['io.github.gagern.nodeJavaDeserialization.BaseClassWithField'].foo", "123");
checkStrictEqual("itm.bar", "234");
checkStrictEqual("itm.foo", "123");
}

@SerializationTestCase public void duplicateField() throws Exception {
writeObject(new DerivedClassWithSameField());
checkStrictEqual("itm.class.name", "'DerivedClassWithSameField'");
checkStrictEqual("itm.class.super.name", "'BaseClassWithField'");
checkStrictEqual("itm.class.name", "'io.github.gagern.nodeJavaDeserialization.DerivedClassWithSameField'");
checkStrictEqual("itm.class.super.name", "'io.github.gagern.nodeJavaDeserialization.BaseClassWithField'");
checkStrictEqual("itm.class.super.super", "null");
checkStrictEqual("itm.extends.DerivedClassWithSameField.foo", "345");
checkStrictEqual("itm.extends.BaseClassWithField.foo", "123");
checkStrictEqual("itm.extends['io.github.gagern.nodeJavaDeserialization.DerivedClassWithSameField'].foo", "345");
checkStrictEqual("itm.extends['io.github.gagern.nodeJavaDeserialization.BaseClassWithField'].foo", "123");
checkStrictEqual("itm.foo", "345");
}

Expand Down Expand Up @@ -260,7 +262,7 @@ public void enums() throws Exception {
checkInstanceof("one", "String");
checkLooseEqual("one", "'ONE'");
checkNotStrictEqual("one", "'ONE'");
checkStrictEqual("one.class.name", "'SomeEnum'");
checkStrictEqual("one.class.name", "'io.github.gagern.nodeJavaDeserialization.SomeEnum'");
checkThat("one.class.isEnum");
checkStrictEqual("one.class.super.name", "'java.lang.Enum'");
checkStrictEqual("one.class.super.super", "null");
Expand Down Expand Up @@ -410,7 +412,7 @@ public void enumMap() throws Exception {
checkStrictEqual("itm.obj.THREE", "'baz'");
checkStrictEqual("itm.obj.ONE.value", "123");
checkKeys("itm.obj", "'ONE', 'THREE'");
checkStrictEqual("itm.keyType.name", "'SomeEnum'");
checkStrictEqual("itm.keyType.name", "'io.github.gagern.nodeJavaDeserialization.SomeEnum'");
checkThat("itm.keyType.isEnum");
checkInstanceof("itm.map", "Map");
checkStrictEqual("itm.map.get(three)", "'baz'");
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions test/failures.js → src/test/node/failures.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

const expect = require('chai').expect;
const javaDeserialization = require('../');
const javaDeserialization = require('../../main/node');

const STREAM_MAGIC = "aced";
const STREAM_VERSION = "0005";
Expand Down Expand Up @@ -147,17 +147,17 @@ describe("Failure scenarios", function() {
expect(parsing(template1({flags: 0})))
.to.throw("Don't know how to deserialize class with flags 0x0");
});

it("version 1 external", function() {
expect(parsing(template1({flags: SC_EXTERNALIZABLE})))
.to.throw("Can't parse version 1 external content");
});

it("unknown primitive", function() {
expect(parsing(template1({fieldType: "Q"})))
.to.throw("Don't know how to read field of type 'Q'");
});

it("bad classDesc", function() {
expect(parsing(template1({classDesc: TC_OBJECT})))
.to.throw("Object not allowed here");
Expand Down
Loading