Skip to content

Commit

Permalink
Restore the ability to read source-namespace-only mapping files (#121)
Browse files Browse the repository at this point in the history
This isn't spec-compliant, but is used for [mod-provided Javadocs](FabricMC/fabric-loom#627) in Loom and has some valid use cases. Once #94 is ready, this should log a warning.
  • Loading branch information
NebelNidas authored Jan 7, 2025
1 parent 34f7fa4 commit 6a1de98
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- Restore the ability to read source-namespace-only mapping files, even if not spec-compliant

## [0.7.0] - 2025-01-01
- Added IntelliJ IDEA migration map reader and writer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ private static void read(ColumnFileReader reader, String sourceNs, String target
dstNamespaces = new ArrayList<>();
String dstNamespace;

while ((dstNamespace = reader.nextCol()) != null) {
if (dstNamespace.isEmpty()) throw new IOException("empty destination namespace in TSRG v2 header");
while (!reader.isAtEol()) {
dstNamespace = reader.nextCol();
if (dstNamespace == null || dstNamespace.isEmpty()) throw new IOException("empty destination namespace in TSRG v2 header");
dstNamespaces.add(dstNamespace);
}

if (dstNamespaces.isEmpty()) throw new IOException("no destination namespaces in TSRG v2 header");
reader.nextLine(0);
} else {
if (sourceNs == null || sourceNs.isEmpty()) throw new IllegalArgumentException("provided source namespace must not be null or empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ private static void read(ColumnFileReader reader, MappingVisitor visitor) throws
List<String> dstNamespaces = new ArrayList<>();
String dstNamespace;

while ((dstNamespace = reader.nextCol()) != null) {
if (dstNamespace.isEmpty()) throw new IOException("empty destination namespace in Tiny v1 header");
while (!reader.isAtEol()) {
dstNamespace = reader.nextCol();
if (dstNamespace == null || dstNamespace.isEmpty()) throw new IOException("empty destination namespace in Tiny v1 header");
dstNamespaces.add(dstNamespace);
}

int dstNsCount = dstNamespaces.size();
if (dstNsCount == 0) throw new IOException("no destination namespaces in Tiny v1 header");

Set<MappingFlag> flags = visitor.getFlags();
MappingVisitor parentVisitor = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ private static void read(ColumnFileReader reader, MappingVisitor visitor) throws
List<String> dstNamespaces = new ArrayList<>();
String dstNamespace;

while ((dstNamespace = reader.nextCol()) != null) {
if (dstNamespace.isEmpty()) throw new IOException("empty destination namespace in Tiny v2 header");
while (!reader.isAtEol()) {
dstNamespace = reader.nextCol();
if (dstNamespace == null || dstNamespace.isEmpty()) throw new IOException("empty destination namespace in Tiny v2 header");
dstNamespaces.add(dstNamespace);
}

int dstNsCount = dstNamespaces.size();
if (dstNsCount == 0) throw new IOException("no destination namespaces in Tiny v2 header");
boolean readerMarked = false;

if (visitor.getFlags().contains(MappingFlag.NEEDS_MULTIPLE_PASSES)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void emptyTinyFile() throws Exception {
assertThrows(IOException.class, () -> Tiny1FileReader.read(new StringReader(header0), target));
assertThrows(IOException.class, () -> Tiny1FileReader.read(new StringReader(header1), target));
assertThrows(IOException.class, () -> Tiny1FileReader.read(new StringReader(header2), target));
assertThrows(IOException.class, () -> Tiny1FileReader.read(new StringReader(header3), target));
Tiny1FileReader.read(new StringReader(header3), target);
assertThrows(IOException.class, () -> Tiny1FileReader.read(new StringReader(header4), target));
Tiny1FileReader.read(new StringReader(header5), target);
}
Expand All @@ -80,7 +80,7 @@ public void emptyTinyV2File() throws Exception {
assertThrows(IOException.class, () -> Tiny2FileReader.read(new StringReader(header0), target));
assertThrows(IOException.class, () -> Tiny2FileReader.read(new StringReader(header1), target));
assertThrows(IOException.class, () -> Tiny2FileReader.read(new StringReader(header2), target));
assertThrows(IOException.class, () -> Tiny2FileReader.read(new StringReader(header3), target));
Tiny2FileReader.read(new StringReader(header3), target);
assertThrows(IOException.class, () -> Tiny2FileReader.read(new StringReader(header4), target));
Tiny2FileReader.read(new StringReader(header5), target);
}
Expand Down Expand Up @@ -113,7 +113,7 @@ public void emptyTsrgFile() throws Exception {
instantiateTree();
assertThrows(IOException.class, () -> TsrgFileReader.read(new StringReader(header1), target));
assertThrows(IOException.class, () -> TsrgFileReader.read(new StringReader(header2), target));
assertThrows(IOException.class, () -> TsrgFileReader.read(new StringReader(header3), target));
TsrgFileReader.read(new StringReader(header3), target);
assertThrows(IOException.class, () -> TsrgFileReader.read(new StringReader(header4), target));
TsrgFileReader.read(new StringReader(header5), target);
}
Expand Down

0 comments on commit 6a1de98

Please sign in to comment.