Skip to content

Commit 80ed1ce

Browse files
committed
Include most Flap patches to MRAPI
1 parent d5605e1 commit 80ed1ce

3 files changed

Lines changed: 40 additions & 94 deletions

File tree

src/main/java/io/github/fabriccompatibilitylayers/modremappingapi/impl/context/MappingsRegistryInstance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void addModMappings(Path path) {
135135
FileUtils.listPathContent(path)
136136
.stream()
137137
.filter(file -> file.endsWith(".class"))
138-
.map(file -> file.replace(".class", ""))
138+
.map(file -> file.replaceFirst(".class$", ""))
139139
.forEach(cl -> mappingBuilder.addMapping(cl, (cl.contains("/") ? "" : this.defaultPackage) + cl));
140140
} catch (IOException e) {
141141
throw new RuntimeException(e);
Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.fabriccompatibilitylayers.modremappingapi.impl.remapper.minecraft;
22

3+
import fr.catcore.modremapperapi.utils.Constants;
34
import net.fabricmc.loader.api.FabricLoader;
4-
import net.fabricmc.loader.api.ObjectShare;
55
import net.fabricmc.loader.impl.launch.FabricLauncherBase;
66
import org.jetbrains.annotations.ApiStatus;
77
import org.jetbrains.annotations.NotNull;
@@ -10,59 +10,50 @@
1010
import java.io.IOException;
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
13-
import java.util.ArrayList;
14-
import java.util.Arrays;
15-
import java.util.List;
16-
import java.util.Optional;
13+
import java.util.*;
14+
import java.util.stream.Collectors;
1715

1816
@ApiStatus.Internal
1917
public class ClasspathUtils {
20-
public static List<Path> getRemapClasspath() throws IOException {
18+
public static Set<Path> getRemapClasspath() throws IOException {
2119
var remapClasspathFile = System.getProperty("fabric.remapClasspathFile");
2220

2321
if (remapClasspathFile == null) {
24-
System.out.println("remapClasspathFile is null! Falling back to ObjectShare.");
22+
Constants.MAIN_LOGGER.info("remapClasspathFile is null! Falling back to ObjectShare.");
2523
return getClassPathFromObjectShare();
2624
}
2725

2826
var content = Files.readString(Path.of(remapClasspathFile));
2927

3028
return Arrays.stream(content.split(File.pathSeparator))
3129
.map(Path::of)
32-
.toList();
30+
.collect(Collectors.toSet());
3331
}
3432

35-
public static @NotNull List<Path> getClassPathFromObjectShare() {
33+
public static @NotNull Set<Path> getClassPathFromObjectShare() {
3634
var share = FabricLoader.getInstance().getObjectShare();
3735
var inputs = share.get("fabric-loader:inputGameJars");
38-
var list = new ArrayList<Path>();
36+
var completeClasspath = new HashSet<Path>();
3937

4038
var oldJar = FabricLoader.getInstance().getObjectShare().get("fabric-loader:inputGameJar");
4139
var classPaths = FabricLauncherBase.getLauncher().getClassPath();
4240

43-
if (inputs instanceof List<?> inputsList) {
44-
var paths = (List<Path>) inputsList;
41+
if (inputs instanceof Collection<?> inputsList) {
42+
var paths = (Collection<Path>) inputsList;
43+
completeClasspath.addAll(paths);
44+
}
4545

46-
if (oldJar instanceof Path oldJarPath) {
47-
if (paths.get(0).toString().equals(oldJarPath.toString())) {
48-
list.addAll(paths);
49-
} else {
50-
list.add(oldJarPath);
51-
}
52-
} else {
53-
list.addAll(paths);
54-
}
55-
} else if (oldJar instanceof Path oldJarPath) {
56-
list.add(oldJarPath);
46+
if (oldJar instanceof Path oldJarPath) {
47+
completeClasspath.add(oldJarPath);
5748
}
5849

59-
list.addAll(classPaths);
50+
completeClasspath.addAll(classPaths);
6051

6152
Optional.ofNullable(share.get("fabric-loader:inputRealmsJar"))
6253
.filter(Path.class::isInstance)
6354
.map(Path.class::cast)
64-
.ifPresent(list::add);
55+
.ifPresent(completeClasspath::add);
6556

66-
return list;
57+
return completeClasspath;
6758
}
6859
}

src/main/java/io/github/fabriccompatibilitylayers/modremappingapi/impl/utils/FileUtils.java

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.nio.file.attribute.BasicFileAttributes;
1212
import java.nio.file.SimpleFileVisitor;
1313
import java.util.*;
14+
import java.util.stream.Collectors;
1415
import java.util.zip.ZipEntry;
1516
import java.util.zip.ZipInputStream;
1617
import java.util.zip.ZipOutputStream;
@@ -97,32 +98,16 @@ public static List<String> listZipContent(Path path) throws IOException {
9798
return files;
9899
}
99100

100-
@ApiStatus.Internal
101-
public static List<String> listDirectoryContent(File[] files) {
102-
List<String> list = new ArrayList<>();
103-
104-
for (File file : files) {
105-
if (file.isDirectory()) {
106-
String name = file.getName();
107-
108-
for (String fileName : listDirectoryContent(file.listFiles())) {
109-
list.add(name + "/" + fileName);
110-
}
111-
} else if (file.isFile()) {
112-
list.add(file.getName());
113-
}
114-
}
115-
116-
return list;
117-
}
118-
101+
/**
102+
* @author moehreag
103+
*/
119104
@ApiStatus.Internal
120105
public static List<String> listPathContent(Path path) throws IOException {
121-
File file = path.toFile();
122-
123-
if (file.isDirectory()) {
124-
return listDirectoryContent(file.listFiles());
125-
} else if (file.isFile()) {
106+
if (Files.isDirectory(path)) {
107+
try (var s = Files.walk(path)) {
108+
return s.map(Path::toString).collect(Collectors.toCollection(ArrayList::new));
109+
}
110+
} else if (Files.isRegularFile(path)) {
126111
return listZipContent(path);
127112
}
128113

@@ -152,52 +137,22 @@ public static void emptyDir(Path dir) {
152137
}
153138
}
154139

140+
/**
141+
* @author moehreag
142+
*/
155143
@ApiStatus.Internal
156-
public static void zipFolder(Path input, Path output) throws IOException {
157-
try (var zout = new ZipOutputStream(Files.newOutputStream(output))) {
158-
var fileToZip = input.toFile();
159-
zipFile(fileToZip, fileToZip.getName(), zout, true);
160-
}
161-
}
162-
163-
private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut, boolean root) throws IOException {
164-
if (fileToZip.isHidden()) {
165-
return;
166-
}
167-
168-
if (fileToZip.isDirectory()) {
169-
if (!root) {
170-
if (fileName.endsWith("/")) {
171-
zipOut.putNextEntry(new ZipEntry(fileName));
172-
zipOut.closeEntry();
173-
} else {
174-
zipOut.putNextEntry(new ZipEntry(fileName + "/"));
175-
zipOut.closeEntry();
176-
}
177-
}
178-
179-
var children = fileToZip.listFiles();
180-
if (children != null) {
181-
for (File childFile : children) {
182-
zipFile(childFile, (root ? "" : fileName + "/") + childFile.getName(), zipOut, false);
144+
public static void zipFolder(Path in, Path out) throws IOException {
145+
try (var outFs = FileSystems.newFileSystem(out)) {
146+
Files.walkFileTree(in, new SimpleFileVisitor<>(){
147+
@Override
148+
public @NotNull FileVisitResult visitFile(@NotNull Path file, @NotNull BasicFileAttributes attrs) throws IOException {
149+
var outPath = outFs.getPath(in.relativize(file).toString());
150+
Files.createDirectories(outPath.getParent());
151+
Files.copy(file, outPath);
152+
return super.visitFile(file, attrs);
183153
}
184-
}
185-
return;
186-
}
187-
188-
var zipEntry = new ZipEntry(fileName);
189-
zipOut.putNextEntry(zipEntry);
190-
191-
try (var fis = Files.newInputStream(fileToZip.toPath())) {
192-
var bytes = new byte[1024];
193-
int length;
194-
195-
while ((length = fis.read(bytes)) >= 0) {
196-
zipOut.write(bytes, 0, length);
197-
}
154+
});
198155
}
199-
200-
zipOut.closeEntry();
201156
}
202157

203158
/* Define ZIP File System Properties in Map */

0 commit comments

Comments
 (0)