forked from spring-projects/spring-boot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only add native-image argfile when excludes are uses
Closes spring-projectsgh-33363
- Loading branch information
1 parent
cfaade9
commit 44a83a8
Showing
5 changed files
with
106 additions
and
22 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
52 changes: 52 additions & 0 deletions
52
...ot-loader-tools/src/main/java/org/springframework/boot/loader/tools/NativeImageUtils.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,52 @@ | ||
/* | ||
* Copyright 2012-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.loader.tools; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Utilities for working with GraalVM native images. | ||
* | ||
* @author Moritz Halbritter | ||
* @since 3.0.0 | ||
*/ | ||
public final class NativeImageUtils { | ||
|
||
private NativeImageUtils() { | ||
} | ||
|
||
/** | ||
* Creates the arguments passed to native-image for the exclusion of reachability | ||
* metadata. | ||
* @param excludes dependencies for which the reachability metadata should be excluded | ||
* @return arguments for native-image | ||
*/ | ||
public static List<String> createExcludeConfigArguments(Iterable<String> excludes) { | ||
List<String> args = new ArrayList<>(); | ||
for (String exclude : excludes) { | ||
int lastSlash = exclude.lastIndexOf('/'); | ||
String jar = (lastSlash != -1) ? exclude.substring(lastSlash + 1) : exclude; | ||
args.add("--exclude-config"); | ||
args.add(Pattern.quote(jar)); | ||
args.add("^/META-INF/native-image/.*"); | ||
} | ||
return args; | ||
} | ||
|
||
} |
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
41 changes: 41 additions & 0 deletions
41
...ader-tools/src/test/java/org/springframework/boot/loader/tools/NativeImageUtilsTests.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,41 @@ | ||
/* | ||
* Copyright 2012-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.boot.loader.tools; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for @{link NativeImageUtils}. | ||
* | ||
* @author Moritz Halbritter | ||
*/ | ||
class NativeImageUtilsTests { | ||
|
||
@Test | ||
void shouldCreateExcludeConfigArguments() { | ||
List<String> arguments = NativeImageUtils | ||
.createExcludeConfigArguments(List.of("path/to/dependency-1.jar", "dependency-2.jar")); | ||
assertThat(arguments).containsExactly("--exclude-config", "\\Qdependency-1.jar\\E", | ||
"^/META-INF/native-image/.*", "--exclude-config", "\\Qdependency-2.jar\\E", | ||
"^/META-INF/native-image/.*"); | ||
} | ||
|
||
} |