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

[MJLINK-87] Inline one line utility methods #226

Merged
merged 5 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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
}

Expand All @@ -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);
}

Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Loading