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

Fixed problem with duplicate modules while generating module-info (#113) #160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 6 additions & 14 deletions core/src/main/java/org/moditect/commands/GenerateModuleInfo.java
Expand Up @@ -344,28 +344,20 @@ private Map<String, Boolean> generateModuleInfo() throws AssertionError {
command.add( workingDirectory.toString() );

if ( !dependencies.isEmpty() ) {
StringBuilder modules = new StringBuilder();
StringBuilder modulePath = new StringBuilder();
boolean isFirst = true;
List<String> modules = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use a Set instead of List.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A Set might reorder the modules and introduce a new undefined order. I would rather not risk this with my limited knowledge of this project.
If you don't agree and/or have more insights, please feel free to improve it further.

List<String> modulePath = new ArrayList<>();

for ( DependencyDescriptor dependency : dependencies ) {
if ( isFirst ) {
isFirst = false;
}
else {
modules.append( "," );
modulePath.append( File.pathSeparator );
}
String moduleName = DependencyDescriptor.getAutoModuleNameFromInputJar(dependency.getPath(), dependency.getAssignedModuleName());
modules.append( moduleName );
modules.add( moduleName );
optionalityPerModule.put( moduleName, dependency.isOptional() );
modulePath.append( dependency.getPath() );
modulePath.add( dependency.getPath().toString() );
}

command.add( "--add-modules" );
command.add( modules.toString() );
command.add( modules.stream().distinct().collect( Collectors.joining( "," ) ) );
command.add( "--module-path" );
command.add( modulePath.toString() );
command.add( modulePath.stream().distinct().collect( Collectors.joining( File.pathSeparator ) ) );
}

command.addAll( jdepsExtraArgs );
Expand Down