mirror of
https://github.com/corda/corda.git
synced 2025-04-27 06:19:54 +00:00
convert classpath paths to absolute paths
This is necessary because some apps expect CodeSource.getLocation() to return URL containing an absolute path.
This commit is contained in:
parent
272789cf16
commit
ab8e6cdc80
@ -22,6 +22,39 @@ class Allocator {
|
|||||||
virtual void free(const void* p, unsigned size) = 0;
|
virtual void free(const void* p, unsigned size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline const char*
|
||||||
|
append(Allocator* allocator, const char* a, const char* b, const char* c)
|
||||||
|
{
|
||||||
|
unsigned al = strlen(a);
|
||||||
|
unsigned bl = strlen(b);
|
||||||
|
unsigned cl = strlen(c);
|
||||||
|
char* p = static_cast<char*>(allocator->allocate((al + bl + cl) + 1));
|
||||||
|
memcpy(p, a, al);
|
||||||
|
memcpy(p + al, b, bl);
|
||||||
|
memcpy(p + al + bl, c, cl + 1);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char*
|
||||||
|
append(Allocator* allocator, const char* a, const char* b)
|
||||||
|
{
|
||||||
|
unsigned al = strlen(a);
|
||||||
|
unsigned bl = strlen(b);
|
||||||
|
char* p = static_cast<char*>(allocator->allocate((al + bl) + 1));
|
||||||
|
memcpy(p, a, al);
|
||||||
|
memcpy(p + al, b, bl + 1);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char*
|
||||||
|
copy(Allocator* allocator, const char* a)
|
||||||
|
{
|
||||||
|
unsigned al = strlen(a);
|
||||||
|
char* p = static_cast<char*>(allocator->allocate(al + 1));
|
||||||
|
memcpy(p, a, al + 1);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace vm
|
} // namespace vm
|
||||||
|
|
||||||
#endif//ALLOCATOR_H
|
#endif//ALLOCATOR_H
|
||||||
|
@ -19,39 +19,6 @@ namespace {
|
|||||||
|
|
||||||
const bool DebugFind = false;
|
const bool DebugFind = false;
|
||||||
|
|
||||||
const char*
|
|
||||||
append(Allocator* allocator, const char* a, const char* b, const char* c)
|
|
||||||
{
|
|
||||||
unsigned al = strlen(a);
|
|
||||||
unsigned bl = strlen(b);
|
|
||||||
unsigned cl = strlen(c);
|
|
||||||
char* p = static_cast<char*>(allocator->allocate((al + bl + cl) + 1));
|
|
||||||
memcpy(p, a, al);
|
|
||||||
memcpy(p + al, b, bl);
|
|
||||||
memcpy(p + al + bl, c, cl + 1);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
append(Allocator* allocator, const char* a, const char* b)
|
|
||||||
{
|
|
||||||
unsigned al = strlen(a);
|
|
||||||
unsigned bl = strlen(b);
|
|
||||||
char* p = static_cast<char*>(allocator->allocate((al + bl) + 1));
|
|
||||||
memcpy(p, a, al);
|
|
||||||
memcpy(p + al, b, bl + 1);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char*
|
|
||||||
copy(Allocator* allocator, const char* a)
|
|
||||||
{
|
|
||||||
unsigned al = strlen(a);
|
|
||||||
char* p = static_cast<char*>(allocator->allocate(al + 1));
|
|
||||||
memcpy(p, a, al + 1);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Element {
|
class Element {
|
||||||
public:
|
public:
|
||||||
class Iterator {
|
class Iterator {
|
||||||
@ -136,9 +103,12 @@ class DirectoryElement: public Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DirectoryElement(System* s, Allocator* allocator, const char* name):
|
DirectoryElement(System* s, Allocator* allocator, const char* name):
|
||||||
s(s), allocator(allocator), name(name),
|
s(s),
|
||||||
urlPrefix_(append(allocator, "file:", name, "/")),
|
allocator(allocator),
|
||||||
sourceUrl_(append(allocator, "file:", name))
|
originalName(name),
|
||||||
|
name(s->toAbsolutePath(allocator, name)),
|
||||||
|
urlPrefix_(append(allocator, "file:", this->name, "/")),
|
||||||
|
sourceUrl_(append(allocator, "file:", this->name))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
virtual Element::Iterator* iterator() {
|
virtual Element::Iterator* iterator() {
|
||||||
@ -181,6 +151,7 @@ class DirectoryElement: public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose() {
|
virtual void dispose() {
|
||||||
|
allocator->free(originalName, strlen(originalName) + 1);
|
||||||
allocator->free(name, strlen(name) + 1);
|
allocator->free(name, strlen(name) + 1);
|
||||||
allocator->free(urlPrefix_, strlen(urlPrefix_) + 1);
|
allocator->free(urlPrefix_, strlen(urlPrefix_) + 1);
|
||||||
allocator->free(sourceUrl_, strlen(sourceUrl_) + 1);
|
allocator->free(sourceUrl_, strlen(sourceUrl_) + 1);
|
||||||
@ -189,6 +160,7 @@ class DirectoryElement: public Element {
|
|||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Allocator* allocator;
|
||||||
|
const char* originalName;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* urlPrefix_;
|
const char* urlPrefix_;
|
||||||
const char* sourceUrl_;
|
const char* sourceUrl_;
|
||||||
@ -454,10 +426,17 @@ class JarElement: public Element {
|
|||||||
unsigned position;
|
unsigned position;
|
||||||
};
|
};
|
||||||
|
|
||||||
JarElement(System* s, Allocator* allocator, const char* name):
|
JarElement(System* s, Allocator* allocator, const char* name,
|
||||||
s(s), allocator(allocator), name(name),
|
bool canonicalizePath = true):
|
||||||
urlPrefix_(name ? append(allocator, "jar:file:", name, "!/") : 0),
|
s(s),
|
||||||
sourceUrl_(name ? append(allocator, "file:", name) : 0),
|
allocator(allocator),
|
||||||
|
originalName(name),
|
||||||
|
name(name and canonicalizePath
|
||||||
|
? s->toAbsolutePath(allocator, name) : name),
|
||||||
|
urlPrefix_(this->name
|
||||||
|
? append(allocator, "jar:file:", this->name, "!/") : 0),
|
||||||
|
sourceUrl_(this->name
|
||||||
|
? append(allocator, "file:", this->name) : 0),
|
||||||
region(0), index(0)
|
region(0), index(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@ -530,6 +509,9 @@ class JarElement: public Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void dispose(unsigned size) {
|
virtual void dispose(unsigned size) {
|
||||||
|
if (originalName != name) {
|
||||||
|
allocator->free(originalName, strlen(originalName) + 1);
|
||||||
|
}
|
||||||
allocator->free(name, strlen(name) + 1);
|
allocator->free(name, strlen(name) + 1);
|
||||||
allocator->free(urlPrefix_, strlen(urlPrefix_) + 1);
|
allocator->free(urlPrefix_, strlen(urlPrefix_) + 1);
|
||||||
allocator->free(sourceUrl_, strlen(sourceUrl_) + 1);
|
allocator->free(sourceUrl_, strlen(sourceUrl_) + 1);
|
||||||
@ -544,6 +526,7 @@ class JarElement: public Element {
|
|||||||
|
|
||||||
System* s;
|
System* s;
|
||||||
Allocator* allocator;
|
Allocator* allocator;
|
||||||
|
const char* originalName;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* urlPrefix_;
|
const char* urlPrefix_;
|
||||||
const char* sourceUrl_;
|
const char* sourceUrl_;
|
||||||
@ -555,7 +538,7 @@ class BuiltinElement: public JarElement {
|
|||||||
public:
|
public:
|
||||||
BuiltinElement(System* s, Allocator* allocator, const char* name,
|
BuiltinElement(System* s, Allocator* allocator, const char* name,
|
||||||
const char* libraryName):
|
const char* libraryName):
|
||||||
JarElement(s, allocator, name),
|
JarElement(s, allocator, name, false),
|
||||||
libraryName(libraryName ? copy(allocator, libraryName) : 0)
|
libraryName(libraryName ? copy(allocator, libraryName) : 0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
@ -776,6 +776,15 @@ class MySystem: public System {
|
|||||||
return SO_SUFFIX;
|
return SO_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const char* toAbsolutePath(Allocator* allocator, const char* name) {
|
||||||
|
if (name[0] == '/') {
|
||||||
|
return copy(allocator, name);
|
||||||
|
} else {
|
||||||
|
char buffer[PATH_MAX];
|
||||||
|
return append(allocator, getcwd(buffer, PATH_MAX), "/", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual Status load(System::Library** lib,
|
virtual Status load(System::Library** lib,
|
||||||
const char* name)
|
const char* name)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#define SYSTEM_H
|
#define SYSTEM_H
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "allocator.h"
|
||||||
|
|
||||||
namespace vm {
|
namespace vm {
|
||||||
|
|
||||||
@ -140,6 +141,8 @@ class System {
|
|||||||
virtual Status load(Library**, const char* name) = 0;
|
virtual Status load(Library**, const char* name) = 0;
|
||||||
virtual char pathSeparator() = 0;
|
virtual char pathSeparator() = 0;
|
||||||
virtual char fileSeparator() = 0;
|
virtual char fileSeparator() = 0;
|
||||||
|
virtual const char* toAbsolutePath(Allocator* allocator,
|
||||||
|
const char* name) = 0;
|
||||||
virtual int64_t now() = 0;
|
virtual int64_t now() = 0;
|
||||||
virtual void yield() = 0;
|
virtual void yield() = 0;
|
||||||
virtual void exit(int code) = 0;
|
virtual void exit(int code) = 0;
|
||||||
|
@ -752,6 +752,20 @@ class MySystem: public System {
|
|||||||
return SO_SUFFIX;
|
return SO_SUFFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual const char* toAbsolutePath(Allocator* allocator, const char* name) {
|
||||||
|
if (strncmp(name, "//", 2) == 0
|
||||||
|
or strncmp(name, "\\\\", 2) == 0
|
||||||
|
or strncmp(name + 1, ":/", 2) == 0
|
||||||
|
or strncmp(name + 1, ":\\", 2) == 0)
|
||||||
|
{
|
||||||
|
return copy(allocator, name);
|
||||||
|
} else {
|
||||||
|
TCHAR buffer[MAX_PATH];
|
||||||
|
GetCurrentDirectory(MAX_PATH, buffer);
|
||||||
|
return append(allocator, buffer, "\\", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual Status load(System::Library** lib,
|
virtual Status load(System::Library** lib,
|
||||||
const char* name)
|
const char* name)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user