Skip to content

Commit

Permalink
set up basic support for copying files from the java.home directory t…
Browse files Browse the repository at this point in the history
…o the build output
  • Loading branch information
kkriske committed Aug 2, 2023
1 parent 0775f08 commit 1b24a1d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2023, 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 @@ -47,6 +47,8 @@ enum ArtifactType {
JDK_LIBRARY("jdk_libraries"),
/* For all library shims for the JDK needed at run-time. */
JDK_LIBRARY_SHIM(JDK_LIBRARY.getJsonKey()), // distinction should not be important to users.
/* For all configuration files from java.home needed at run-time */
JDK_CONFIG_FILE("jdk_config"),

/* Language home artifacts for Truffle languages needed at run-time. */
LANGUAGE_HOME("language_home"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright (c) 2023, 2023, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.svm.hosted.jdk;

import com.oracle.svm.core.BuildArtifacts;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.util.VMError;
import org.graalvm.nativeimage.ImageSingletons;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

public final class JDKConfigFiles {

public static JDKConfigFiles singleton() {
return ImageSingletons.lookup(JDKConfigFiles.class);
}

final Set<String> configFiles = Collections.newSetFromMap(new ConcurrentHashMap<>());

JDKConfigFiles() {
}

public void register(String configFile) {
if (configFile.startsWith("/")) {
configFiles.add(configFile.substring(1));
} else {
configFiles.add(configFile);
}
}
}

@AutomaticallyRegisteredFeature
final class JDKConfigFilesFeature implements InternalFeature {
@Override
public void afterRegistration(AfterRegistrationAccess access) {
ImageSingletons.add(JDKConfigFiles.class, new JDKConfigFiles());
}

@Override
public void afterImageWrite(AfterImageWriteAccess access) {
Path jdkHomeDir = Path.of(System.getProperty("java.home")).normalize();
for (String configFile : new TreeSet<>(JDKConfigFiles.singleton().configFiles)) {
Path jdkConfigPath = jdkHomeDir.resolve(configFile).normalize();
VMError.guarantee(jdkConfigPath.startsWith(jdkHomeDir));
Path imageConfigPath = access.getImagePath().resolveSibling(configFile);
try {
Files.createDirectories(imageConfigPath);
Files.copy(jdkConfigPath, imageConfigPath, REPLACE_EXISTING);
BuildArtifacts.singleton().add(BuildArtifacts.ArtifactType.JDK_CONFIG_FILE, imageConfigPath);
} catch (IOException e) {
VMError.shouldNotReachHere(e);
}
}
}
}

0 comments on commit 1b24a1d

Please sign in to comment.