Cleanup some issues with the mod extraction to the memory modlist. Closes #4874 #4875

This commit is contained in:
LexManos 2018-04-14 19:32:45 -07:00
parent a794f1daff
commit 32237f57ef
4 changed files with 33 additions and 16 deletions

View File

@ -163,7 +163,6 @@ public class LibraryManager
Artifact artifact = ret.getLeft(); Artifact artifact = ret.getLeft();
Repository repo = modlist.getRepository() == null ? libraries_dir : modlist.getRepository(); Repository repo = modlist.getRepository() == null ? libraries_dir : modlist.getRepository();
File moved = repo.archive(artifact, file, ret.getRight()); File moved = repo.archive(artifact, file, ret.getRight());
modlist.add(artifact);
processed.add(moved); processed.add(moved);
} }
} }
@ -213,9 +212,9 @@ public class LibraryManager
if (jar.getManifest() == null) if (jar.getManifest() == null)
return null; return null;
JarEntry manfest_entry = jar.getJarEntry(JarFile.MANIFEST_NAME); JarEntry manifest_entry = jar.getJarEntry(JarFile.MANIFEST_NAME);
if (manfest_entry == null) if (manifest_entry == null)
manfest_entry = jar.stream().filter(e -> JarFile.MANIFEST_NAME.equals(e.getName().toUpperCase(Locale.ENGLISH))).findFirst().get(); //We know that getManifest returned non-null so we know there is *some* entry that matches the manifest file. So we dont need to empty check. manifest_entry = jar.stream().filter(e -> JarFile.MANIFEST_NAME.equals(e.getName().toUpperCase(Locale.ENGLISH))).findFirst().get(); //We know that getManifest returned non-null so we know there is *some* entry that matches the manifest file. So we dont need to empty check.
attrs = jar.getManifest().getMainAttributes(); attrs = jar.getManifest().getMainAttributes();
@ -318,14 +317,16 @@ public class LibraryManager
{ {
try try
{ {
String timestamp = meta.getValue(TIMESTAMP); Artifact artifact = readArtifact(modlist.getRepository(), meta);
if (timestamp != null)
timestamp = SnapshotJson.TIMESTAMP.format(new Date(Long.parseLong(timestamp)));
Artifact artifact = new Artifact(modlist.getRepository(), meta.getValue(MAVEN_ARTIFACT), timestamp);
File target = artifact.getFile(); File target = artifact.getFile();
if (target.exists()) if (target.exists())
{
FMLLog.log.debug("Found existing ContainedDep {}({}) from {} extracted to {}, skipping extraction", dep, artifact.toString(), target.getCanonicalPath(), jar.getName()); FMLLog.log.debug("Found existing ContainedDep {}({}) from {} extracted to {}, skipping extraction", dep, artifact.toString(), target.getCanonicalPath(), jar.getName());
if (!ENABLE_AUTO_MOD_MOVEMENT)
{
extractPacked(target, modlist, modDirs); //If we're not building a real list we have to re-build the dep list every run. So search down.
}
}
else else
{ {
FMLLog.log.debug("Extracting ContainedDep {}({}) from {} to {}", dep, artifact.toString(), jar.getName(), target.getCanonicalPath()); FMLLog.log.debug("Extracting ContainedDep {}({}) from {} to {}", dep, artifact.toString(), jar.getName(), target.getCanonicalPath());
@ -367,7 +368,22 @@ public class LibraryManager
} }
} }
return attrs.containsKey(MAVEN_ARTIFACT) ? Pair.of(new Artifact(modlist.getRepository(), attrs.getValue(MAVEN_ARTIFACT), attrs.getValue(TIMESTAMP)), readAll(jar.getInputStream(manfest_entry))) : null; if (attrs.containsKey(MAVEN_ARTIFACT))
{
Artifact artifact = readArtifact(modlist.getRepository(), attrs);
modlist.add(artifact);
return Pair.of(artifact, readAll(jar.getInputStream(manifest_entry)));
}
return null;
}
private static Artifact readArtifact(Repository repo, Attributes meta)
{
String timestamp = meta.getValue(TIMESTAMP);
if (timestamp != null)
timestamp = SnapshotJson.TIMESTAMP.format(new Date(Long.parseLong(timestamp)));
return new Artifact(repo, meta.getValue(MAVEN_ARTIFACT), timestamp);
} }
private static byte[] readAll(InputStream in) throws IOException private static byte[] readAll(InputStream in) throws IOException

View File

@ -90,13 +90,13 @@ public class LinkRepository extends Repository
String key = artifact.toString(); String key = artifact.toString();
File file = artifact_to_file.get(key); File file = artifact_to_file.get(key);
if (file == null || !file.exists()) if (file == null || !file.exists())
return null; return super.resolve(artifact);
return new Artifact(artifact, this, artifact.isSnapshot() ? artifact.getTimestamp() : null); return new Artifact(artifact, this, artifact.isSnapshot() ? artifact.getTimestamp() : null);
} }
@Override @Override
public File getFile(String path) public File getFile(String path)
{ {
return filesystem.containsKey(path) ? super.getFile(path) : filesystem.get(path); return filesystem.containsKey(path) ? filesystem.get(path) : super.getFile(path);
} }
} }

View File

@ -174,6 +174,7 @@ public class ModList
} }
else else
artifacts.add(artifact); artifacts.add(artifact);
art_map.put(artifact.toString(), artifact);
changed = true; changed = true;
} }

View File

@ -40,21 +40,21 @@ import net.minecraftforge.fml.common.FMLLog;
* So we JUST use the timestamp. * So we JUST use the timestamp.
* *
* { * {
* "latest": "yyyymmdd.hhmmss", * "latest": "yyyyMMdd.hhmmss",
* "versions": [ * "versions": [
* { * {
* "md5": "md5 in hex lowercase", * "md5": "md5 in hex lowercase",
* "timestamp": "yyyymmdd.hhmmss" * "timestamp": "yyyyMMdd.hhmmss"
* ] * ]
* } * }
* *
*/ */
public class SnapshotJson implements Comparable<SnapshotJson> public class SnapshotJson implements Comparable<SnapshotJson>
{ {
public static final DateFormat TIMESTAMP = new SimpleDateFormat("yyyymmdd.hhmmss"); public static final DateFormat TIMESTAMP = new SimpleDateFormat("yyyyMMdd.hhmmss");
public static final String META_JSON_FILE = "maven-metadata.json"; public static final String META_JSON_FILE = "maven-metadata.json";
private static final Gson GSON = new GsonBuilder().create(); private static final Gson GSON = new GsonBuilder().create();
private static final Comparator<Entry> SORTER = (o1, o2) -> o2.timestamp.compareTo(o2.timestamp); private static final Comparator<Entry> SORTER = (o1, o2) -> o2.timestamp.compareTo(o1.timestamp);
public static SnapshotJson create(File target) public static SnapshotJson create(File target)
{ {