mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
various tweaks for Classpath compatibility
This commit is contained in:
parent
4fca1d64ba
commit
20ea82ec2e
@ -1,4 +1,4 @@
|
|||||||
/* Copyright (c) 2008, Avian Contributors
|
/* Copyright (c) 2008-2009, Avian Contributors
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
for any purpose with or without fee is hereby granted, provided
|
for any purpose with or without fee is hereby granted, provided
|
||||||
@ -11,7 +11,6 @@
|
|||||||
package java.net;
|
package java.net;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public final class URL {
|
public final class URL {
|
||||||
@ -73,7 +72,7 @@ public final class URL {
|
|||||||
throws MalformedURLException
|
throws MalformedURLException
|
||||||
{
|
{
|
||||||
if ("resource".equals(protocol)) {
|
if ("resource".equals(protocol)) {
|
||||||
return new ResourceHandler();
|
return new avian.resource.Handler();
|
||||||
} else {
|
} else {
|
||||||
throw new MalformedURLException("unknown protocol: " + protocol);
|
throw new MalformedURLException("unknown protocol: " + protocol);
|
||||||
}
|
}
|
||||||
@ -88,87 +87,4 @@ public final class URL {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
this.ref = ref;
|
this.ref = ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ResourceHandler extends URLStreamHandler {
|
|
||||||
protected URLConnection openConnection(URL url) {
|
|
||||||
return new ResourceConnection(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ResourceConnection extends URLConnection {
|
|
||||||
public ResourceConnection(URL url) {
|
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getContentLength() {
|
|
||||||
return ResourceInputStream.getContentLength(url.getFile());
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputStream getInputStream() throws IOException {
|
|
||||||
return new ResourceInputStream(url.getFile());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class ResourceInputStream extends InputStream {
|
|
||||||
private long peer;
|
|
||||||
private int position;
|
|
||||||
|
|
||||||
public ResourceInputStream(String path) throws IOException {
|
|
||||||
peer = open(path);
|
|
||||||
if (peer == 0) {
|
|
||||||
throw new FileNotFoundException(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static native int getContentLength(String path);
|
|
||||||
|
|
||||||
private static native long open(String path) throws IOException;
|
|
||||||
|
|
||||||
private static native int read(long peer, int position) throws IOException;
|
|
||||||
|
|
||||||
private static native int read(long peer, int position,
|
|
||||||
byte[] b, int offset, int length)
|
|
||||||
throws IOException;
|
|
||||||
|
|
||||||
public static native void close(long peer) throws IOException;
|
|
||||||
|
|
||||||
public int read() throws IOException {
|
|
||||||
if (peer != 0) {
|
|
||||||
int c = read(peer, position);
|
|
||||||
if (c >= 0) {
|
|
||||||
++ position;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
} else {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int read(byte[] b, int offset, int length) throws IOException {
|
|
||||||
if (peer != 0) {
|
|
||||||
if (b == null) {
|
|
||||||
throw new NullPointerException();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (offset < 0 || offset + length > b.length) {
|
|
||||||
throw new ArrayIndexOutOfBoundsException();
|
|
||||||
}
|
|
||||||
|
|
||||||
int c = read(peer, position, b, offset, length);
|
|
||||||
if (c >= 0) {
|
|
||||||
position += c;
|
|
||||||
}
|
|
||||||
return c;
|
|
||||||
} else {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() throws IOException {
|
|
||||||
if (peer != 0) {
|
|
||||||
close(peer);
|
|
||||||
peer = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
6
makefile
6
makefile
@ -46,6 +46,7 @@ endif
|
|||||||
ifdef gnu
|
ifdef gnu
|
||||||
options := $(options)-gnu
|
options := $(options)-gnu
|
||||||
gnu-sources = $(src)/gnu.cpp
|
gnu-sources = $(src)/gnu.cpp
|
||||||
|
gnu-jar = $(gnu)/share/classpath/glibj.zip
|
||||||
gnu-libraries = \
|
gnu-libraries = \
|
||||||
$(gnu)/lib/classpath/libjavaio.a \
|
$(gnu)/lib/classpath/libjavaio.a \
|
||||||
$(gnu)/lib/classpath/libjavalang.a \
|
$(gnu)/lib/classpath/libjavalang.a \
|
||||||
@ -346,6 +347,7 @@ gnu-blacklist = \
|
|||||||
|
|
||||||
gnu-overrides = \
|
gnu-overrides = \
|
||||||
avian/*.class \
|
avian/*.class \
|
||||||
|
avian/resource/*.class \
|
||||||
java/lang/Class.class \
|
java/lang/Class.class \
|
||||||
java/lang/Enum.class \
|
java/lang/Enum.class \
|
||||||
java/lang/InheritableThreadLocal.class \
|
java/lang/InheritableThreadLocal.class \
|
||||||
@ -443,7 +445,7 @@ $(native-build)/type-generator.o: \
|
|||||||
$(classpath-build)/%.class: $(classpath)/%.java
|
$(classpath-build)/%.class: $(classpath)/%.java
|
||||||
@echo $(<)
|
@echo $(<)
|
||||||
|
|
||||||
$(classpath-dep): $(classpath-sources)
|
$(classpath-dep): $(classpath-sources) $(gnu-jar)
|
||||||
@echo "compiling classpath classes"
|
@echo "compiling classpath classes"
|
||||||
@mkdir -p $(avian-classpath-build)
|
@mkdir -p $(avian-classpath-build)
|
||||||
$(javac) -d $(avian-classpath-build) \
|
$(javac) -d $(avian-classpath-build) \
|
||||||
@ -457,7 +459,7 @@ ifdef gnu
|
|||||||
@mkdir -p $(classpath-build)
|
@mkdir -p $(classpath-build)
|
||||||
(wd=$$(pwd) && \
|
(wd=$$(pwd) && \
|
||||||
cd $(classpath-build) && \
|
cd $(classpath-build) && \
|
||||||
$(jar) xf $(gnu)/share/classpath/glibj.zip && \
|
$(jar) xf $(gnu-jar) && \
|
||||||
rm $(gnu-blacklist) && \
|
rm $(gnu-blacklist) && \
|
||||||
jar xf "$$($(native-path) "$${wd}/$(build)/overrides.jar")")
|
jar xf "$$($(native-path) "$${wd}/$(build)/overrides.jar")")
|
||||||
endif
|
endif
|
||||||
|
@ -846,7 +846,7 @@ Avian_java_lang_Thread_enumerate
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT int64_t JNICALL
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
Avian_java_net_URL_00024ResourceInputStream_getContentLength
|
Avian_avian_resource_Handler_00024ResourceInputStream_getContentLength
|
||||||
(Thread* t, object, uintptr_t* arguments)
|
(Thread* t, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
object path = reinterpret_cast<object>(*arguments);
|
object path = reinterpret_cast<object>(*arguments);
|
||||||
@ -866,7 +866,7 @@ Avian_java_net_URL_00024ResourceInputStream_getContentLength
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT int64_t JNICALL
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
Avian_java_net_URL_00024ResourceInputStream_open
|
Avian_avian_resource_Handler_00024ResourceInputStream_open
|
||||||
(Thread* t, object, uintptr_t* arguments)
|
(Thread* t, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
object path = reinterpret_cast<object>(*arguments);
|
object path = reinterpret_cast<object>(*arguments);
|
||||||
@ -883,7 +883,7 @@ Avian_java_net_URL_00024ResourceInputStream_open
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT int64_t JNICALL
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
Avian_java_net_URL_00024ResourceInputStream_read__JI
|
Avian_avian_resource_Handler_00024ResourceInputStream_read__JI
|
||||||
(Thread*, object, uintptr_t* arguments)
|
(Thread*, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
int64_t peer; memcpy(&peer, arguments, 8);
|
int64_t peer; memcpy(&peer, arguments, 8);
|
||||||
@ -898,7 +898,7 @@ Avian_java_net_URL_00024ResourceInputStream_read__JI
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT int64_t JNICALL
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
Avian_java_net_URL_00024ResourceInputStream_read__JI_3BII
|
Avian_avian_resource_Handler_00024ResourceInputStream_read__JI_3BII
|
||||||
(Thread* t, object, uintptr_t* arguments)
|
(Thread* t, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
int64_t peer; memcpy(&peer, arguments, 8);
|
int64_t peer; memcpy(&peer, arguments, 8);
|
||||||
@ -923,7 +923,7 @@ Avian_java_net_URL_00024ResourceInputStream_read__JI_3BII
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL
|
extern "C" JNIEXPORT void JNICALL
|
||||||
Avian_java_net_URL_00024ResourceInputStream_close
|
Avian_avian_resource_Handler_00024ResourceInputStream_close
|
||||||
(Thread*, object, uintptr_t* arguments)
|
(Thread*, object, uintptr_t* arguments)
|
||||||
{
|
{
|
||||||
int64_t peer; memcpy(&peer, arguments, 8);
|
int64_t peer; memcpy(&peer, arguments, 8);
|
||||||
|
20
src/gnu.cpp
20
src/gnu.cpp
@ -52,8 +52,7 @@ Avian_gnu_classpath_VMSystemProperties_preInit
|
|||||||
|
|
||||||
setProperty(t, method, properties, "java.vm.name", "Avian");
|
setProperty(t, method, properties, "java.vm.name", "Avian");
|
||||||
|
|
||||||
setProperty(t, method, properties, "java.lang.classpath",
|
setProperty(t, method, properties, "java.protocol.handler.pkgs", "avian");
|
||||||
t->m->finder->path());
|
|
||||||
|
|
||||||
setProperty(t, method, properties, "file.encoding", "ASCII");
|
setProperty(t, method, properties, "file.encoding", "ASCII");
|
||||||
|
|
||||||
@ -77,6 +76,9 @@ Avian_gnu_classpath_VMSystemProperties_preInit
|
|||||||
|
|
||||||
setProperty(t, method, properties, "user.home",
|
setProperty(t, method, properties, "user.home",
|
||||||
_wgetenv(L"USERPROFILE"), "%ls");
|
_wgetenv(L"USERPROFILE"), "%ls");
|
||||||
|
|
||||||
|
GetCurrentDirectory(MAX_PATH, buffer);
|
||||||
|
setProperty(t, method, properties, "user.dir", buffer);
|
||||||
#else
|
#else
|
||||||
# define FILE_SEPARATOR "/"
|
# define FILE_SEPARATOR "/"
|
||||||
|
|
||||||
@ -90,6 +92,7 @@ Avian_gnu_classpath_VMSystemProperties_preInit
|
|||||||
# endif
|
# endif
|
||||||
setProperty(t, method, properties, "java.io.tmpdir", "/tmp");
|
setProperty(t, method, properties, "java.io.tmpdir", "/tmp");
|
||||||
setProperty(t, method, properties, "user.home", getenv("HOME"));
|
setProperty(t, method, properties, "user.home", getenv("HOME"));
|
||||||
|
setProperty(t, method, properties, "user.dir", getenv("PWD"));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,3 +282,16 @@ Avian_java_lang_VMClassLoader_loadClass
|
|||||||
|
|
||||||
return Avian_avian_SystemClassLoader_findClass(t, 0, args);
|
return Avian_avian_SystemClassLoader_findClass(t, 0, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
|
Avian_avian_SystemClassLoader_findLoadedClass
|
||||||
|
(Thread*, object, uintptr_t*);
|
||||||
|
|
||||||
|
extern "C" JNIEXPORT int64_t JNICALL
|
||||||
|
Avian_java_lang_VMClassLoader_findLoadedClass
|
||||||
|
(Thread* t, object, uintptr_t* arguments)
|
||||||
|
{
|
||||||
|
uintptr_t args[] = { 0, arguments[1] };
|
||||||
|
|
||||||
|
return Avian_avian_SystemClassLoader_findLoadedClass(t, 0, args);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user