Skip to content

Commit 5a072ab

Browse files
committed
Extract methods: packageToPath / pathToPackage
Split out of #207
1 parent 8c47ca0 commit 5a072ab

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/main/java/org/gradlex/javamodule/moduleinfo/ExtraJavaModuleInfoTransform.java

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ private byte[] copyAndExtractProviders(
390390
String packagePath =
391391
i > 0 ? mrJarMatcher.matches() ? mrJarMatcher.group(1) : entryName.substring(0, i) : "";
392392

393-
if (!removedPackages.contains(packagePath.replace('/', '.'))) {
393+
if (!removedPackages.contains(pathToPackage(packagePath))) {
394394
if (entryName.endsWith(".class") && !packagePath.isEmpty()) {
395395
packages.add(packagePath);
396396
}
@@ -462,6 +462,24 @@ public void visitEnd() {
462462
return classWriter.toByteArray();
463463
}
464464

465+
/**
466+
* Convert a Java package name to a path
467+
* @param packageName The package name
468+
* @return The package name converted to a path
469+
*/
470+
private static String packageToPath(String packageName) {
471+
return packageName.replace('.', '/');
472+
}
473+
474+
/**
475+
* Convert a path to a Java package name
476+
* @param path The path
477+
* @return The path converted to a package name
478+
*/
479+
private static String pathToPackage(String path) {
480+
return path.replace('/', '.');
481+
}
482+
465483
private void addModuleInfoEntires(
466484
ModuleInfo moduleInfo,
467485
Map<String, List<String>> providers,
@@ -473,13 +491,13 @@ private void addModuleInfoEntires(
473491
for (Map.Entry<String, Set<String>> entry : moduleInfo.exports.entrySet()) {
474492
String packageName = entry.getKey();
475493
Set<String> modules = entry.getValue();
476-
moduleVisitor.visitExport(packageName.replace('.', '/'), 0, modules.toArray(new String[0]));
494+
moduleVisitor.visitExport(packageToPath(packageName), 0, modules.toArray(new String[0]));
477495
}
478496

479497
for (Map.Entry<String, Set<String>> entry : moduleInfo.opens.entrySet()) {
480498
String packageName = entry.getKey();
481499
Set<String> modules = entry.getValue();
482-
moduleVisitor.visitOpen(packageName.replace('.', '/'), 0, modules.toArray(new String[0]));
500+
moduleVisitor.visitOpen(packageToPath(packageName), 0, modules.toArray(new String[0]));
483501
}
484502

485503
if (moduleInfo.requireAllDefinedDependencies) {
@@ -524,7 +542,7 @@ private void addModuleInfoEntires(
524542
moduleVisitor.visitRequire(requireName, Opcodes.ACC_STATIC_PHASE | Opcodes.ACC_TRANSITIVE, null);
525543
}
526544
for (String usesName : moduleInfo.uses) {
527-
moduleVisitor.visitUse(usesName.replace('.', '/'));
545+
moduleVisitor.visitUse(packageToPath(usesName));
528546
}
529547
for (Map.Entry<String, List<String>> entry : providers.entrySet()) {
530548
String name = entry.getKey();
@@ -539,9 +557,9 @@ private void addModuleInfoEntires(
539557
}
540558
if (!implementations.isEmpty()) {
541559
moduleVisitor.visitProvide(
542-
name.replace('.', '/'),
560+
packageToPath(name),
543561
implementations.stream()
544-
.map(impl -> impl.replace('.', '/'))
562+
.map(ExtraJavaModuleInfoTransform::packageToPath)
545563
.toArray(String[]::new));
546564
}
547565
}

0 commit comments

Comments
 (0)