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

#104 Support multiple launchers (entry points) #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions core/src/main/java/org/moditect/commands/CreateRuntimeImage.java
Expand Up @@ -37,19 +37,25 @@ public class CreateRuntimeImage {
private final List<String> modules;
private final Path outputDirectory;
private boolean ignoreSigningInformation;
private final String launcher;
private final List<String> launchers = new ArrayList<>();
private final Log log;
private final Integer compression;
private final boolean stripDebug;
private final List<String> excludeResourcesPatterns;

public CreateRuntimeImage(Set<Path> modulePath, List<String> modules, String launcherName, String launcherModule,
public CreateRuntimeImage(Set<Path> modulePath, List<String> modules, List<String> launcherNames, List<String> launcherModules,
Path outputDirectory, Integer compression, boolean stripDebug, boolean ignoreSigningInformation, List<String> excludeResourcesPatterns, Log log) {
this.modulePath = ( modulePath != null ? modulePath : Collections.emptySet() );
this.modules = getModules( modules );
this.outputDirectory = outputDirectory;
this.ignoreSigningInformation = ignoreSigningInformation;
this.launcher = launcherName != null && launcherModule != null ? launcherName + "=" + launcherModule : null;

if (launcherNames != null && launcherModules != null) {
for (int i=0; i < launcherNames.size() && i < launcherModules.size(); i++) {
this.launchers.add(launcherNames.get(i) + "=" + launcherModules.get(i));
}
}

this.compression = compression;
this.stripDebug = stripDebug;
this.excludeResourcesPatterns = excludeResourcesPatterns;
Expand Down Expand Up @@ -87,7 +93,7 @@ private void runJlink() throws AssertionError {
command.add( "--output" );
command.add( outputDirectory.toString() );

if ( launcher != null ) {
for (String launcher : launchers) {
command.add( "--launcher" );
command.add( launcher );
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ public class CreateRuntimeImageMojo extends AbstractMojo {
private List<String> modules;

@Parameter
private Launcher launcher;
private List<Launcher> launchers;

@Parameter
private Integer compression;
Expand Down Expand Up @@ -98,12 +98,24 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.collect( Collectors.toSet() );

effectiveModulePath.add( jmodsDir );

List<String> launcherNames = launchers.stream().map(Launcher::getName).collect(Collectors.toList());

List<String> launcherModules = launchers.stream().map(l -> {
StringBuilder sb = new StringBuilder(l.getModule());
String mainClass = l.getMainClass();
if (mainClass != null) {
sb.append("/");
sb.append(mainClass);
}
return sb.toString();
}).collect(Collectors.toList());

new CreateRuntimeImage(
effectiveModulePath,
modules,
launcher != null ? launcher.getName() : null,
launcher != null ? launcher.getModule() : null,
launcherNames,
launcherModules,
outputDirectory.toPath(),
compression,
stripDebug,
Expand Down
Expand Up @@ -22,22 +22,31 @@
*/
public class Launcher {

private String name;
private String mainClass;
private String module;
private String name;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
public String getMainClass() {
return mainClass;
}

public String getModule() {
return module;
}

public String getName() {
return name;
}

public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}

public void setModule(String module) {
this.module = module;
}

public void setName(String name) {
this.name = name;
}
}