Skip to content

Commit 81527e0

Browse files
committed
Add support for automatic module names in ignore filter.
1 parent b6414c7 commit 81527e0

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

bs-dev/src/main/java/net/minecraftforge/bootstrap/dev/BootstrapDevClasspathFixer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ private boolean processIgnore(List<Path[]> classpath) {
343343
for (var itr = classpath.iterator(); itr.hasNext(); ) {
344344
var paths = itr.next();
345345
var module = Util.findModuleName(paths);
346+
347+
if (module == null)
348+
module = Util.findAutomaticModuleName(paths);
349+
346350
if (module != null && toIgnore.contains(module.name())) {
347351
itr.remove();
348352
ret = true;

bs-dev/src/main/java/net/minecraftforge/bootstrap/dev/Util.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
import java.util.jar.Manifest;
1919
import java.util.zip.ZipEntry;
2020
import java.util.zip.ZipInputStream;
21+
2122
import java.util.jar.Attributes.Name;
23+
import java.util.regex.Pattern;
2224
import java.util.jar.JarFile;
2325

2426
class Util {
@@ -262,4 +264,59 @@ private static List<Path> findAllClassPathEntries() {
262264
return sneak(e);
263265
}
264266
}
267+
268+
public static ModuleVersion findAutomaticModuleName(Path[] paths) {
269+
if (paths.length != 1 || paths[0].getFileName() == null)
270+
return null;
271+
272+
var name = paths[0].getFileName().toString();
273+
if (!name.endsWith(".jar"))
274+
return null;
275+
276+
String version = null;
277+
var matcher = Patterns.DASH_VERSION.matcher(name);
278+
if (matcher.find()) {
279+
int start = matcher.start();
280+
281+
// attempt to parse the tail as a version string
282+
try {
283+
String tail = name.substring(start + 1);
284+
ModuleDescriptor.Version.parse(tail);
285+
version = tail;
286+
} catch (IllegalArgumentException ignore) { }
287+
288+
name = name.substring(0, start);
289+
}
290+
291+
return new ModuleVersion(cleanModuleName(name), version, null);
292+
}
293+
294+
// Stolen from jdk.internal.module.ModulePath
295+
private static class Patterns {
296+
static final Pattern DASH_VERSION = Pattern.compile("-(\\d+(\\.|$))");
297+
static final Pattern NON_ALPHANUM = Pattern.compile("[^A-Za-z0-9]");
298+
static final Pattern REPEATING_DOTS = Pattern.compile("(\\.)(\\1)+");
299+
static final Pattern LEADING_DOTS = Pattern.compile("^\\.");
300+
static final Pattern TRAILING_DOTS = Pattern.compile("\\.$");
301+
}
302+
303+
// Stolen from jdk.internal.module.ModulePath
304+
private static String cleanModuleName(String mn) {
305+
// replace non-alphanumeric
306+
mn = Patterns.NON_ALPHANUM.matcher(mn).replaceAll(".");
307+
308+
// collapse repeating dots
309+
mn = Patterns.REPEATING_DOTS.matcher(mn).replaceAll(".");
310+
311+
// drop leading dots
312+
if (!mn.isEmpty() && mn.charAt(0) == '.')
313+
mn = Patterns.LEADING_DOTS.matcher(mn).replaceAll("");
314+
315+
// drop trailing dots
316+
int len = mn.length();
317+
if (len > 0 && mn.charAt(len-1) == '.')
318+
mn = Patterns.TRAILING_DOTS.matcher(mn).replaceAll("");
319+
320+
return mn;
321+
}
265322
}

0 commit comments

Comments
 (0)