Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementations of JpackageOperation, JmodOperation and JlinkOperation #45

Merged
merged 27 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
547b20a
Draft implementations of JpackageOperation, JmodOperation and JlinkOp…
ethauvin Aug 1, 2024
683f5df
Fixed test imports
ethauvin Aug 1, 2024
7fcbccd
Install limbd0 on Ubuntu
ethauvin Aug 1, 2024
0aa93b7
Install limbd0 on Ubuntu with sudo
ethauvin Aug 1, 2024
d69956c
Revert install limbd0 on Ubuntu
ethauvin Aug 1, 2024
0ad964e
Cleaned up and improved tests
ethauvin Aug 2, 2024
0028448
Fixed handling of @filename in all tools
ethauvin Aug 2, 2024
e2cc7a6
Improved @filename options parsing
ethauvin Aug 3, 2024
b94b23a
Clear command line arguments on execution
ethauvin Aug 3, 2024
0204cdf
Added functional tests for jlink and jmod
ethauvin Aug 3, 2024
c38594a
Foce added jlink build directory
ethauvin Aug 3, 2024
8118f42
Use System.out and System.out instead of StringWriter
ethauvin Aug 3, 2024
94225df
Improved @filename support
ethauvin Aug 3, 2024
f6aa525
Normalized tool arguments setup and processing
ethauvin Aug 3, 2024
7a946b1
Capture and check stdout in tests
ethauvin Aug 3, 2024
d029bb9
Fixed version parsing in tests
ethauvin Aug 3, 2024
91640e6
Fixed copyright
ethauvin Aug 3, 2024
1d615a5
More operation options cleanups
ethauvin Aug 3, 2024
7507589
Tests cleanup
ethauvin Aug 3, 2024
e32e174
Added support for Java 20-21 specific options
ethauvin Aug 4, 2024
62a3240
Cleanups
ethauvin Aug 4, 2024
a06ce8e
Renamed fileOptions to cmdFiles
ethauvin Aug 5, 2024
d42d2d6
Added a command line tokenizer
ethauvin Aug 5, 2024
d72e6eb
Truncate jmod ISO date to seconds
ethauvin Aug 5, 2024
0382444
Added more command files tests
ethauvin Aug 5, 2024
c59d61f
Added command file and test for Windows
ethauvin Aug 5, 2024
3bd17e2
Improved command line tokenizer
ethauvin Aug 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions classes/META-INF/MANIFEST.MF
ethauvin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Created-By: 17.0.12 (Eclipse Adoptium)

Binary file added classes/dev/mccue/tree/Tree.class
Binary file not shown.
Binary file added classes/module-info.class
Binary file not shown.
146 changes: 146 additions & 0 deletions src/main/java/rife/bld/operations/AbstractToolProviderOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright 2024 Erik C. Thauvin (https://erik.thauvin.net/)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.operations;

import rife.bld.operations.exceptions.ExitStatusException;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.spi.ToolProvider;

/**
* Provides common features for tool providers.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.0.2
*/
public abstract class AbstractToolProviderOperation<T extends AbstractToolProviderOperation<T>>
extends AbstractOperation<AbstractToolProviderOperation<T>> {
private final List<String> toolArgs_ = new ArrayList<>();
private final String toolName_;

/**
* Provides the name of the tool.
*
* @param toolName the tool name
*/
public AbstractToolProviderOperation(String toolName) {
toolName_ = toolName;
}

/**
* Runs an instance of the tool.
* <p>
* On success, command line arguments are automatically cleared.
*
* @throws Exception if an error occurred
*/
@Override
public void execute() throws Exception {
if (toolArgs_.isEmpty()) {
System.err.println("No " + toolName_ + " command line arguments specified.");
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
}

var tool = ToolProvider.findFirst(toolName_).orElseThrow(() ->
new IllegalStateException("No " + toolName_ + " tool found."));

var status = tool.run(System.out, System.err, toolArgs_.toArray(new String[0]));
if (status != 0) {
System.out.println(tool.name() + ' ' + String.join(" ", toolArgs_));
}

ExitStatusException.throwOnFailure(status);

toolArgs_.clear();
}

/**
* Adds arguments to pass to the tool.
*
* @param arg one or more argument
* @return this operation
*/
@SuppressWarnings("unchecked")
public T toolArgs(String... arg) {
toolArgs(List.of(arg));
return (T) this;
}

/**
* Adds arguments to pass to the tool.
*
* @param args the argument-value pairs to add
* @return this operation
*/
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
protected T toolArgs(Map<String, String> args) {
args.forEach((k, v) -> {
toolArgs_.add(k);
if (v != null && !v.isEmpty()) {
toolArgs_.add(v);
}
});
return (T) this;
}

/**
* Adds arguments to pass to the tool.
*
* @param args the argument to add
* @return this operation
*/
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
public T toolArgs(List<String> args) {
toolArgs_.addAll(args);
return (T) this;
}

/**
* Returns the tool's arguments.
*
* @return the arguments
*/
public List<String> toolArgs() {
return toolArgs_;
}

/**
* Parses arguments to pass to the tool from the given files.
*
* @param files the list of files
* @return this operation instance
* @throws FileNotFoundException if a file cannot be found
*/
@SuppressWarnings({"unchecked", "UnusedReturnValue"})
public T toolArgsFromFile(List<String> files) throws FileNotFoundException {
var list = new ArrayList<String>();

for (var option : files) {
try (var scanner = new Scanner(new File(option))) {
while (scanner.hasNext()) {
var splitLine = scanner.nextLine().split("--");
for (String args : splitLine) {
if (!args.isBlank()) {
var splitArgs = args.split(" ", 2);
list.add("--" + splitArgs[0]);
if (splitArgs.length > 1 && !splitArgs[1].isBlank()) {
list.add(splitArgs[1]);
}
}
}
}
}
}

toolArgs(list);

return (T) this;
}
}
88 changes: 88 additions & 0 deletions src/main/java/rife/bld/operations/JlinkOperation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2024 Erik C. Thauvin (https://erik.thauvin.net/)
* Licensed under the Apache License, Version 2.0 (the "License")
*/
package rife.bld.operations;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
* Create run-time images using the jlink tool.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 2.0.2
*/
public class JlinkOperation extends AbstractToolProviderOperation<JlinkOperation> {
private final List<String> disabledPlugins_ = new ArrayList<>();
private final JlinkOptions jlinkOptions_ = new JlinkOptions();
private final List<String> fileOptions_ = new ArrayList<>();

public JlinkOperation() {
super("jlink");
}

/**
* Disable the plugin mentioned.
*
* @param plugin the plugin name
* @return this map of options
*/
public JlinkOperation disablePlugin(String... plugin) {
disabledPlugins_.addAll(List.of(plugin));
return this;
}

@Override
public void execute() throws Exception {
toolArgsFromFile(fileOptions_);
disabledPlugins_.forEach(plugin -> toolArgs("--disable-plugin", plugin));
toolArgs(jlinkOptions_);
super.execute();
}

/**
* Retrieves the list of options for the jlink tool.
* <p>
* This is a modifiable list that can be retrieved and changed.
*
* @return the map of jlink options
*/
public JlinkOptions jlinkOptions() {
return jlinkOptions_;
}

/**
* Provides a list of options to provide to the jlink tool.
* <p>
* A copy will be created to allow this list to be independently modifiable.
*
* @param options the argument-value pairs
* @return this operation instance
*/
public JlinkOperation jlinkOptions(Map<String, String> options) {
jlinkOptions_.putAll(options);
return this;
}

/**
* Read options and/or mode from a file.
*
* @param file one or more file
* @return this operation instance
*/
public JlinkOperation fileOptions(String... file) {
fileOptions_.addAll(List.of(file));
return this;
}

/**
* Retrieves the list of files containing options or mode.
*
* @return the list of files
*/
public List<String> fileOptions() {
return fileOptions_;
}
}
Loading
Loading