Skip to content

Commit

Permalink
Add stripNativeCommands configuration property
Browse files Browse the repository at this point in the history
  • Loading branch information
iherasymenko committed Nov 26, 2023
1 parent cfe45e4 commit c33171b
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ jlinkApplication {
excludeResources = ['/**/com/example/demo/DemoApplication.class']
includeLocales = ['en-CA']
stripJavaDebugAttributes = true
stripNativeCommands = true
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void apply(Project project) {
task.getExcludeResources().convention(jlinkApplication.getExcludeResources());
task.getIncludeLocales().convention(jlinkApplication.getIncludeLocales());
task.getStripJavaDebugAttributes().convention(jlinkApplication.getStripJavaDebugAttributes());
task.getStripNativeCommands().convention(jlinkApplication.getStripNativeCommands());
};

TaskProvider<JlinkImageTask> imageTask = tasks.register("image", JlinkImageTask.class, task -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ public abstract class JlinkApplicationPluginExtension {

public abstract Property<Boolean> getStripJavaDebugAttributes();

public abstract Property<Boolean> getStripNativeCommands();

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ public JlinkImageTask() {
@Optional
public abstract Property<Boolean> getStripJavaDebugAttributes();

@Input
@Optional
public abstract Property<Boolean> getStripNativeCommands();

@Inject
protected abstract FileSystemOperations getFileSystemOperations();

Expand Down Expand Up @@ -208,6 +212,9 @@ public void execute() throws IOException {
if (getStripJavaDebugAttributes().getOrElse(false)) {
args.add("--strip-java-debug-attributes");
}
if (getStripNativeCommands().getOrElse(false)) {
args.add("--strip-native-commands");
}
getFileSystemOperations().delete(spec -> spec.delete(getOutputFolder().get()));
invokeJlink(args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2023 Ihor Herasymenko.
*
* 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
*
* http://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 com.github.iherasymenko.jlink.test;

import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.assertj.core.api.Assertions.assertThat;

class StripNativeCommandsPluginFunctionalTest extends AbstractTestBase {

@Test
void can_strip_native_commands() throws IOException {
build.buildFile = """
plugins {
id 'java'
id 'com.github.iherasymenko.jlink'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(System.getenv().getOrDefault('TESTING_AGAINST_JDK', '21'))
vendor = JvmVendorSpec.AZUL
}
}
jlinkApplication {
mainClass = 'com.example.demo.DemoApplication'
mainModule = 'demo.main'
stripNativeCommands = true
}
""";
build.settingsFile = """
rootProject.name = 'demo'
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
""";
build.mainClass = """
package com.example.demo;
public class DemoApplication {
public static void main(String[] args) {
}
}
""";
build.moduleInfo = """
module demo.main {
}
""";

build.runner("image").build();

assertThat(build.projectDir.resolve("build/image/bin")).doesNotExist();
}

}

0 comments on commit c33171b

Please sign in to comment.