Skip to content

Commit cb61940

Browse files
authored
Add support for override flag (#296)
* Fix FileUtilsTest * Remove unused imports in FileUtils * Add support for override flag This commit adds support for overriding reachability metadata when the override flag is set to true, designed to be used with oracle/graalvm-reachability-metadata#51. It is implemented by adding the required --exclude-config build arguments. Closes #268 * Fix NativeImagePlugin.addExcludeConfigArg and related documentation * Remove unused import * Fix functional tests
1 parent e10ec8a commit cb61940

File tree

21 files changed

+236
-102
lines changed

21 files changed

+236
-102
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package org.graalvm.reachability;
42+
43+
import java.nio.file.Path;
44+
45+
public class DirectoryConfiguration {
46+
47+
private final Path directory;
48+
49+
private final boolean override;
50+
51+
public DirectoryConfiguration(Path directory, boolean override) {
52+
this.directory = directory;
53+
this.override = override;
54+
}
55+
56+
public Path getDirectory() {
57+
return directory;
58+
}
59+
60+
public boolean isOverride() {
61+
return override;
62+
}
63+
}

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/GraalVMReachabilityMetadataRepository.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
*/
4141
package org.graalvm.reachability;
4242

43-
import java.nio.file.Path;
4443
import java.util.Collection;
4544
import java.util.Set;
4645
import java.util.function.Consumer;
@@ -63,29 +62,29 @@ public interface GraalVMReachabilityMetadataRepository {
6362
* example if a configuration directory isn't available for a
6463
* particular artifact version.
6564
* @param queryBuilder the query builder
66-
* @return the set of configuration directories matching the query
65+
* @return the set of configuration matching the query
6766
*/
68-
Set<Path> findConfigurationDirectoriesFor(Consumer<? super Query> queryBuilder);
67+
Set<DirectoryConfiguration> findConfigurationsFor(Consumer<? super Query> queryBuilder);
6968

7069
/**
7170
* Returns a list of configuration directories for the specified artifact.
7271
* There may be more than one configuration directory for a given artifact,
7372
* but the list may also be empty if the repository doesn't contain any.
7473
* Never null.
7574
* @param gavCoordinates the artifact GAV coordinates (group:artifact:version)
76-
* @return a list of configuration directories
75+
* @return a list of configuration
7776
*/
78-
default Set<Path> findConfigurationDirectoriesFor(String gavCoordinates) {
79-
return findConfigurationDirectoriesFor(q -> q.forArtifacts(gavCoordinates));
77+
default Set<DirectoryConfiguration> findConfigurationsFor(String gavCoordinates) {
78+
return findConfigurationsFor(q -> q.forArtifacts(gavCoordinates));
8079
}
8180

8281
/**
8382
* Returns the set of configuration directories for all the modules supplied
8483
* as an argument.
8584
* @param modules the list of modules
86-
* @return the set of configuration directories
85+
* @return the set of configuration
8786
*/
88-
default Set<Path> findConfigurationDirectoriesFor(Collection<String> modules) {
89-
return findConfigurationDirectoriesFor(q -> q.forArtifacts(modules));
87+
default Set<DirectoryConfiguration> findConfigurationsFor(Collection<String> modules) {
88+
return findConfigurationsFor(q -> q.forArtifacts(modules));
9089
}
9190
}

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/internal/FileSystemRepository.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*/
4141
package org.graalvm.reachability.internal;
4242

43+
import org.graalvm.reachability.DirectoryConfiguration;
4344
import org.graalvm.reachability.GraalVMReachabilityMetadataRepository;
4445
import org.graalvm.reachability.Query;
4546
import org.graalvm.reachability.internal.index.artifacts.SingleModuleJsonVersionToConfigDirectoryIndex;
@@ -90,7 +91,7 @@ public static boolean isSupportedArchiveFormat(String path) {
9091
}
9192

9293
@Override
93-
public Set<Path> findConfigurationDirectoriesFor(Consumer<? super Query> queryBuilder) {
94+
public Set<DirectoryConfiguration> findConfigurationsFor(Consumer<? super Query> queryBuilder) {
9495
DefaultQuery query = new DefaultQuery();
9596
queryBuilder.accept(query);
9697
return query.getArtifacts()
@@ -106,25 +107,25 @@ public Set<Path> findConfigurationDirectoriesFor(Consumer<? super Query> queryBu
106107
if (artifactQuery.getForcedConfig().isPresent()) {
107108
String configVersion = artifactQuery.getForcedConfig().get();
108109
logger.log(groupId, artifactId, version, "Configuration is forced to version " + configVersion);
109-
return index.findForcedConfiguration(configVersion);
110+
return index.findConfiguration(groupId, artifactId, configVersion);
110111
}
111-
Optional<Path> configurationDirectory = index.findConfigurationDirectory(groupId, artifactId, version);
112-
if (!configurationDirectory.isPresent() && artifactQuery.isUseLatestVersion()) {
112+
Optional<DirectoryConfiguration> configuration = index.findConfiguration(groupId, artifactId, version);
113+
if (!configuration.isPresent() && artifactQuery.isUseLatestVersion()) {
113114
logger.log(groupId, artifactId, version, "Configuration directory not found. Trying latest version.");
114-
configurationDirectory = index.findLatestConfigurationFor(groupId, artifactId);
115-
if (!configurationDirectory.isPresent()) {
115+
configuration = index.findLatestConfigurationFor(groupId, artifactId);
116+
if (!configuration.isPresent()) {
116117
logger.log(groupId, artifactId, version, "Latest version not found!");
117118
}
118119
}
119-
Optional<Path> finalConfigurationDirectory = configurationDirectory;
120+
Optional<DirectoryConfiguration> finalConfigurationDirectory = configuration;
120121
logger.log(groupId, artifactId, version, () -> {
121122
if (finalConfigurationDirectory.isPresent()) {
122-
Path path = finalConfigurationDirectory.get();
123+
Path path = finalConfigurationDirectory.get().getDirectory();
123124
return "Configuration directory is " + rootDirectory.relativize(path);
124125
}
125126
return "missing.";
126127
});
127-
return configurationDirectory;
128+
return configuration;
128129
})
129130
.filter(Optional::isPresent)
130131
.map(Optional::get);

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/internal/index/artifacts/Artifact.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@ public class Artifact {
5252
private final Set<String> versions;
5353
private final String directory;
5454
private final boolean latest;
55+
private final boolean override;
5556

5657
@JsonCreator
5758
public Artifact(@JsonProperty("module") String module,
5859
@JsonProperty("tested-versions") Set<String> versions,
5960
@JsonProperty("metadata-version") String directory,
60-
@JsonProperty(value = "latest", defaultValue = "false") boolean latest) {
61+
@JsonProperty(value = "latest", defaultValue = "false") boolean latest,
62+
@JsonProperty(value = "override", defaultValue = "false") boolean override) {
6163
this.module = module;
6264
this.versions = versions;
6365
this.directory = directory;
6466
this.latest = latest;
67+
this.override = override;
6568
}
6669

6770
public String getModule() {
@@ -79,4 +82,8 @@ public String getDirectory() {
7982
public boolean isLatest() {
8083
return latest;
8184
}
85+
86+
public boolean isOverride() {
87+
return override;
88+
}
8289
}

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/internal/index/artifacts/SingleModuleJsonVersionToConfigDirectoryIndex.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import com.fasterxml.jackson.databind.ObjectMapper;
4444
import com.fasterxml.jackson.databind.type.TypeFactory;
45+
import org.graalvm.reachability.DirectoryConfiguration;
4546
import org.graalvm.reachability.internal.UncheckedIOException;
4647

4748
import java.io.BufferedReader;
@@ -80,12 +81,6 @@ private Map<String, List<Artifact>> parseIndexFile(Path rootPath) {
8081

8182
}
8283

83-
@Override
84-
public Optional<Path> findForcedConfiguration(String version) {
85-
Path configDir = moduleRoot.resolve(version);
86-
return Files.isDirectory(configDir) ? Optional.of(configDir) : Optional.empty();
87-
}
88-
8984
/**
9085
* Returns the configuration directory for the requested artifact.
9186
*
@@ -95,7 +90,7 @@ public Optional<Path> findForcedConfiguration(String version) {
9590
* @return a configuration directory, or empty if no configuration directory is available
9691
*/
9792
@Override
98-
public Optional<Path> findConfigurationDirectory(String groupId, String artifactId, String version) {
93+
public Optional<DirectoryConfiguration> findConfiguration(String groupId, String artifactId, String version) {
9994
return findConfigurationFor(groupId, artifactId, artifact -> artifact.getVersions().contains(version));
10095
}
10196

@@ -107,11 +102,11 @@ public Optional<Path> findConfigurationDirectory(String groupId, String artifact
107102
* @return a configuration directory, or empty if no configuration directory is available
108103
*/
109104
@Override
110-
public Optional<Path> findLatestConfigurationFor(String groupId, String artifactId) {
105+
public Optional<DirectoryConfiguration> findLatestConfigurationFor(String groupId, String artifactId) {
111106
return findConfigurationFor(groupId, artifactId, Artifact::isLatest);
112107
}
113108

114-
private Optional<Path> findConfigurationFor(String groupId, String artifactId, Predicate<? super Artifact> predicate) {
109+
private Optional<DirectoryConfiguration> findConfigurationFor(String groupId, String artifactId, Predicate<? super Artifact> predicate) {
115110
String module = groupId + ":" + artifactId;
116111
List<Artifact> artifacts = index.get(module);
117112
if (artifacts == null) {
@@ -121,6 +116,7 @@ private Optional<Path> findConfigurationFor(String groupId, String artifactId, P
121116
.filter(artifact -> artifact.getModule().equals(module))
122117
.filter(predicate)
123118
.findFirst()
124-
.map(artifact -> moduleRoot.resolve(artifact.getDirectory()));
119+
.map(artifact -> new DirectoryConfiguration(moduleRoot.resolve(artifact.getDirectory()), artifact.isOverride()));
125120
}
121+
126122
}

common/graalvm-reachability-metadata/src/main/java/org/graalvm/reachability/internal/index/artifacts/VersionToConfigDirectoryIndex.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,33 +40,26 @@
4040
*/
4141
package org.graalvm.reachability.internal.index.artifacts;
4242

43-
import java.nio.file.Path;
4443
import java.util.Optional;
4544

46-
public interface VersionToConfigDirectoryIndex {
45+
import org.graalvm.reachability.DirectoryConfiguration;
4746

48-
/**
49-
* Returns the specified configuration directory version, ignoring
50-
* any existing configuration.
51-
* @param version the requested version
52-
* @return the configuration directory
53-
*/
54-
Optional<Path> findForcedConfiguration(String version);
47+
public interface VersionToConfigDirectoryIndex {
5548

5649
/**
57-
* Returns the configuration directory for the requested artifact.
50+
* Returns the configuration for the requested artifact.
5851
* @param groupId the group ID of the artifact
5952
* @param artifactId the artifact ID of the artifact
6053
* @param version the version of the artifact
61-
* @return a configuration directory, or empty if no configuration directory is available
54+
* @return a configuration, or empty if no configuration directory is available
6255
*/
63-
Optional<Path> findConfigurationDirectory(String groupId, String artifactId, String version);
56+
Optional<DirectoryConfiguration> findConfiguration(String groupId, String artifactId, String version);
6457

6558
/**
66-
* Returns the latest configuration directory for the requested artifact.
59+
* Returns the latest configuration for the requested artifact.
6760
* @param groupId the group ID of the artifact
6861
* @param artifactId the artifact ID of the artifact
69-
* @return a configuration directory, or empty if no configuration directory is available
62+
* @return a configuration, or empty if no configuration directory is available
7063
*/
71-
Optional<Path> findLatestConfigurationFor(String groupId, String artifactId);
64+
Optional<DirectoryConfiguration> findLatestConfigurationFor(String groupId, String artifactId);
7265
}

common/graalvm-reachability-metadata/src/test/java/org/graalvm/reachability/internal/FileSystemRepositoryTest.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
package org.graalvm.reachability.internal;
4343

44+
import org.graalvm.reachability.DirectoryConfiguration;
4445
import org.graalvm.reachability.Query;
4546
import org.junit.jupiter.api.Test;
4647

@@ -51,6 +52,8 @@
5152
import java.util.function.Consumer;
5253

5354
import static org.junit.jupiter.api.Assertions.assertEquals;
55+
import static org.junit.jupiter.api.Assertions.assertFalse;
56+
import static org.junit.jupiter.api.Assertions.assertTrue;
5457

5558
class FileSystemRepositoryTest {
5659
private FileSystemRepository repository;
@@ -65,9 +68,11 @@ void testRepo1() {
6568

6669
// then:
6770
result.hasSinglePath("org/foo/1.0");
71+
result.hasNoOverride();
6872

6973
// when:
7074
lookup("org:foo:1.1");
75+
result.hasOverride();
7176

7277
// then:
7378
result.hasSinglePath("org/foo/1.1");
@@ -87,6 +92,7 @@ void testRepo2() {
8792

8893
// then:
8994
result.hasSinglePath("org/foo/1.1");
95+
result.hasNoOverride();
9096
}
9197

9298
@Test
@@ -166,11 +172,11 @@ void canUseLatestConfigDir() {
166172
}
167173

168174
private void lookup(Consumer<? super Query> builder) {
169-
result = new Result(repository.findConfigurationDirectoriesFor(builder), repoPath);
175+
result = new Result(repository.findConfigurationsFor(builder), repoPath);
170176
}
171177

172178
private void lookup(String gav) {
173-
result = new Result(repository.findConfigurationDirectoriesFor(gav), repoPath);
179+
result = new Result(repository.findConfigurationsFor(gav), repoPath);
174180
}
175181

176182
private void withRepo(String id) {
@@ -184,20 +190,32 @@ private void withRepo(String id) {
184190

185191
private static final class Result {
186192
private final Path repoPath;
187-
private final Set<Path> configDirs;
193+
private final Set<DirectoryConfiguration> configs;
188194

189-
private Result(Set<Path> configDirs, Path repoPath) {
190-
this.configDirs = configDirs;
195+
private Result(Set<DirectoryConfiguration> configs, Path repoPath) {
196+
this.configs = configs;
191197
this.repoPath = repoPath;
192198
}
193199

194200
public void isEmpty() {
195-
assertEquals(0, configDirs.size());
201+
assertEquals(0, configs.size());
196202
}
197203

198204
public void hasSinglePath(String path) {
199-
assertEquals(1, configDirs.size());
200-
assertEquals(repoPath.resolve(path), configDirs.iterator().next());
205+
assertEquals(1, configs.size());
206+
assertEquals(repoPath.resolve(path), configs.iterator().next().getDirectory());
207+
}
208+
209+
public void hasOverride() {
210+
for (DirectoryConfiguration config : configs) {
211+
assertTrue(config.isOverride());
212+
}
213+
}
214+
215+
public void hasNoOverride() {
216+
for (DirectoryConfiguration config : configs) {
217+
assertFalse(config.isOverride());
218+
}
201219
}
202220
}
203221
}

0 commit comments

Comments
 (0)