Skip to content

Commit

Permalink
[MJLINK-87] Inline one line utility methods (#226)
Browse files Browse the repository at this point in the history
* Inline one line utility
elharo authored Dec 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2bcbcea commit 52bbccc
Showing 3 changed files with 6 additions and 64 deletions.
Original file line number Diff line number Diff line change
@@ -39,7 +39,6 @@

import java.io.File;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -57,7 +56,7 @@
public abstract class AbstractJLinkMojo extends AbstractMojo {
/**
* <p>
* Specify the requirements for this jdk toolchain. This overrules the toolchain selected by the
* Specify the requirements for this JDK toolchain. This overrules the toolchain selected by the
* maven-toolchain-plugin.
* </p>
* <strong>note:</strong> requires at least Maven 3.3.1
@@ -193,24 +192,4 @@ protected StringBuilder convertSeparatedModulePathToPlatformSeparatedModulePath(
}
return sb;
}

/**
* Convert a list into a string which is separated by the platform path separator.
*
* @param modulePaths the list of elements
* @return the string which contains the elements separated by {@link File#pathSeparatorChar}.
*/
protected String getPlatformDependSeparateList(Collection<String> modulePaths) {
return String.join(Character.toString(File.pathSeparatorChar), modulePaths);
}

/**
* Convert a list of modules into a comma separated string.
*
* @param modules the list of modules
* @return the string with the module list which is separated by {@code ,}
*/
protected String getCommaSeparatedList(Collection<String> modules) {
return String.join(",", modules);
}
}
10 changes: 5 additions & 5 deletions src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java
Original file line number Diff line number Diff line change
@@ -705,7 +705,7 @@ protected List<String> createJlinkArgs(Collection<String> pathsOfModules, Collec
if (pathsOfModules != null && !pathsOfModules.isEmpty()) {
// @formatter:off
jlinkArgs.add("--module-path");
jlinkArgs.add(getPlatformDependSeparateList(pathsOfModules).replace("\\", "\\\\"));
jlinkArgs.add(String.join(File.pathSeparator, pathsOfModules).replace("\\", "\\\\"));
// @formatter:off
}

@@ -719,23 +719,23 @@ protected List<String> createJlinkArgs(Collection<String> pathsOfModules, Collec

if (hasLimitModules()) {
jlinkArgs.add("--limit-modules");
String sb = getCommaSeparatedList(limitModules);
String sb = String.join(",", limitModules);
jlinkArgs.add(sb);
}

if (!modulesToAdd.isEmpty()) {
jlinkArgs.add("--add-modules");
// This must be name of the module and *NOT* the name of the
// file! Can we somehow pre check this information to fail early?
String sb = getCommaSeparatedList(modulesToAdd);
String sb = String.join(",", modulesToAdd);
jlinkArgs.add(sb.replace("\\", "\\\\"));
}

if (hasIncludeLocales()) {
jlinkArgs.add("--add-modules");
jlinkArgs.add("jdk.localedata");
jlinkArgs.add("--include-locales");
String sb = getCommaSeparatedList(includeLocales);
String sb = String.join(",", includeLocales);
jlinkArgs.add(sb);
}

@@ -757,7 +757,7 @@ protected List<String> createJlinkArgs(Collection<String> pathsOfModules, Collec
// NOTE: suggestProviders is a terminal JlinkTask, so must be at the end!
if (hasSuggestProviders()) {
jlinkArgs.add("--suggest-providers");
String sb = getCommaSeparatedList(suggestProviders);
String sb = String.join(",", suggestProviders);
jlinkArgs.add(sb);
}

Original file line number Diff line number Diff line change
@@ -38,8 +38,6 @@
*/

import java.io.File;
import java.util.Arrays;
import java.util.Collections;

import org.apache.maven.plugin.logging.Log;
import org.junit.jupiter.api.BeforeEach;
@@ -91,39 +89,4 @@ public void convertUsingMultipleDelimitersShouldReturnTwoCharactersSeparatedByPa
StringBuilder result = mojoMock.convertSeparatedModulePathToPlatformSeparatedModulePath("x:a::");
assertThat(result).hasToString("x" + File.pathSeparatorChar + "a");
}

@Test
@DisplayName("getPlatformDependSeparateList() should return a single character")
public void getPlatformDependSeparateListShouldReturnASingleCharacter() {
String result = mojoMock.getPlatformDependSeparateList(Collections.singletonList("A"));
assertThat(result).isEqualTo("A");
}

@Test
@DisplayName("getPlatformDependSeparateList() should return two characters separated")
public void getPlatformDependSeparateListShouldReturnTwoCharactersSeparated() {
String result = mojoMock.getPlatformDependSeparateList(Arrays.asList("A", "B"));
assertThat(result).isEqualTo("A" + File.pathSeparatorChar + "B");
}

@Test
@DisplayName("getPlatformDependSeparateList() should return three characters separated")
public void getPlatformDependSeparateListShouldReturnThreeCharactersSeparated() {
String result = mojoMock.getPlatformDependSeparateList(Arrays.asList("A", "B", "C"));
assertThat(result).isEqualTo("A" + File.pathSeparatorChar + "B" + File.pathSeparatorChar + "C");
}

@Test
@DisplayName("getCommaSeparatedList() should return a single character")
public void getCommaSeparatedListShouldReturnASingleCharacter() {
String result = mojoMock.getCommaSeparatedList(Collections.singletonList("A"));
assertThat(result).isEqualTo("A");
}

@Test
@DisplayName("getCommaSeparatedList() should return two characters separated by comma")
public void getCommaSeparatedListShouldReturnTwoCharactersSeparatedByComma() {
String result = mojoMock.getCommaSeparatedList(Arrays.asList("A", "B"));
assertThat(result).isEqualTo("A,B");
}
}

0 comments on commit 52bbccc

Please sign in to comment.