-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include buildtool support for bundling reachability metadata into jar…
… files (#322) * Add DirectoryConfiguration.copy method Update `DirectoryConfiguration` with a new `copy` method that can be used to copy matadata files into `META-INF/native-image` directories. The `DirectoryConfiguration` class now has group, artifact and version information so that it can write files into the appropriate folder. The `copy` method will also write a `reachability-metadata.properties` file that indicates if the 'override' property was set on the metadata. * Add `add-metadata-hints` goal to Maven Plugin Update the maven plugin with a new `add-metadata-hints` goal that can be used to bundle hints obtained from the metadata repository into the jar. * Add `ReachabilityMetadataCopyTask` to Gradle Plugin Update the gradle plugin with a new `ReachabilityMetadataCopyTask` class that can be used to copy hints obtained from the metadata repository. * Refactor common code in NativeImagePlugin Refactor the `configureJvmReachabilityConfigurationDirectories` and `configureJvmReachabilityExcludeConfigArgs` to use a common method since they share the same logic.
- Loading branch information
Showing
22 changed files
with
1,191 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...chability-metadata/src/test/java/org/graalvm/reachability/DirectoryConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* The Universal Permissive License (UPL), Version 1.0 | ||
* | ||
* Subject to the condition set forth below, permission is hereby granted to any | ||
* person obtaining a copy of this software, associated documentation and/or | ||
* data (collectively the "Software"), free of charge and under any and all | ||
* copyright rights in the Software, and any and all patent rights owned or | ||
* freely licensable by each licensor hereunder covering either (i) the | ||
* unmodified Software as contributed to or provided by such licensor, or (ii) | ||
* the Larger Works (as defined below), to deal in both | ||
* | ||
* (a) the Software, and | ||
* | ||
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
* one is included with the Software each a "Larger Work" to which the Software | ||
* is contributed by such licensors), | ||
* | ||
* without restriction, including without limitation the rights to copy, create | ||
* derivative works of, display, perform, and distribute the Software and make, | ||
* use, sell, offer for sale, import, export, have made, and have sold the | ||
* Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
* either these or other terms. | ||
* | ||
* This license is subject to the following condition: | ||
* | ||
* The above copyright notice and either this complete permission notice or at a | ||
* minimum a reference to the UPL must be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.graalvm.reachability; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Arrays; | ||
import java.util.Properties; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
class DirectoryConfigurationTest { | ||
|
||
@TempDir | ||
Path temp; | ||
|
||
@Test | ||
void copyCopiesFiles() throws IOException { | ||
Path directory = temp.resolve("source/com.example.group/artifact/123"); | ||
Path target = temp.resolve("target"); | ||
createJsonFiles(directory); | ||
DirectoryConfiguration configuration = new DirectoryConfiguration("com.example.group", "artifact", "123", directory, false); | ||
DirectoryConfiguration.copy(Arrays.asList(configuration), target); | ||
assertTrue(Files.exists(target.resolve("META-INF/native-image/com.example.group/artifact/123/reflect-config.json"))); | ||
assertTrue(Files.exists(target.resolve("META-INF/native-image/com.example.group/artifact/123/other.json"))); | ||
assertFalse(Files.exists(target.resolve("META-INF/native-image/com.example.group/artifact/123/index.json"))); | ||
assertFalse(Files.exists(target.resolve("META-INF/native-image/com.example.group/artifact/123/reachability-metadata.properties"))); | ||
} | ||
|
||
@Test | ||
void copyWhenHasOverrideGeneratesMetadataRepositoryProperties() throws IOException { | ||
Path directory = temp.resolve("source/com.example.group/artifact/123"); | ||
Path target = temp.resolve("target"); | ||
createJsonFiles(directory); | ||
DirectoryConfiguration configuration = new DirectoryConfiguration("com.example.group", "artifact", "123", directory, true); | ||
DirectoryConfiguration.copy(Arrays.asList(configuration), target); | ||
Path propertiesFile = target.resolve("META-INF/native-image/com.example.group/artifact/123/reachability-metadata.properties"); | ||
Properties properties = new Properties(); | ||
properties.load(new FileInputStream(propertiesFile.toFile())); | ||
assertEquals("true", properties.getProperty("override")); | ||
} | ||
|
||
private void createJsonFiles(Path directory) throws IOException { | ||
Files.createDirectories(directory); | ||
byte[] json = "{}".getBytes(); | ||
Files.copy(new ByteArrayInputStream(json), directory.resolve("index.json")); | ||
Files.copy(new ByteArrayInputStream(json), directory.resolve("reflect-config.json")); | ||
Files.copy(new ByteArrayInputStream(json), directory.resolve("other.json")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.