Skip to content

Commit

Permalink
Add getExecutableURL method to ProcessPropertiesSupport
Browse files Browse the repository at this point in the history
Signed-off-by: Lazar Mitrović <[email protected]>
  • Loading branch information
lazar-mitrovic committed Oct 5, 2021
1 parent 14de16e commit 8099bdb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@
*/
package org.graalvm.nativeimage.impl;

import java.net.URL;
import java.nio.file.Path;

import org.graalvm.nativeimage.c.function.CEntryPointLiteral;

public interface ProcessPropertiesSupport {
default String getExecutableName() {
return "java";
String getExecutableName();

default URL getExecutableURL() {
return null;
}

long getProcessID();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,7 +27,23 @@

import org.graalvm.nativeimage.impl.ProcessPropertiesSupport;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

public abstract class BaseProcessPropertiesSupport implements ProcessPropertiesSupport {

@Override
public URL getExecutableURL() {
try {
return new File(getExecutableName()).toURI().toURL();
} catch (MalformedURLException ex) {
// This should not really happen; the file is cannonicalized, absolute, so it should
// always have file:// URL.
return null;
}
}

@Override
public int getArgumentVectorBlockSize() {
return JavaMainWrapper.getCRuntimeArgumentBlockLength();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -26,7 +26,6 @@

//Checkstyle: allow reflection

import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.annotation.Annotation;
Expand All @@ -43,7 +42,6 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
Expand All @@ -58,10 +56,11 @@
import org.graalvm.compiler.core.common.NumUtil;
import org.graalvm.compiler.core.common.SuppressFBWarnings;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.ProcessProperties;
import org.graalvm.nativeimage.c.function.CFunctionPointer;
import org.graalvm.nativeimage.impl.ProcessPropertiesSupport;
import org.graalvm.util.DirectAnnotationAccess;

import com.oracle.svm.core.RuntimeAssertionsSupport;
Expand Down Expand Up @@ -336,16 +335,12 @@ public void setModule(Object module) {
java.security.Permissions perms = new java.security.Permissions();
perms.add(SecurityConstants.ALL_PERMISSION);
CodeSource cs;
try {
// Try to use executable image's name as code source for the class.
// The file location can be used by Java code to determine its location on disk, similar
// to argv[0].
cs = new CodeSource(new File(ProcessProperties.getExecutableName()).toURI().toURL(), (Certificate[]) null);
} catch (MalformedURLException ex) {
// This should not really happen; the file is cannonicalized, absolute, so it should
// always have file:// URL.
cs = null;
}

// Try to use executable image's name as code source for the class.
// The file location can be used by Java code to determine its location on disk, similar
// to argv[0].
cs = new CodeSource(ImageSingletons.lookup(ProcessPropertiesSupport.class).getExecutableURL(), (Certificate[]) null);

return new java.security.ProtectionDomain(cs, perms);
});

Expand Down

0 comments on commit 8099bdb

Please sign in to comment.