use of suite.pkgmanager.action.InstallAction in project suite by stupidsing.
the class PackageManager method install.
public boolean install(String packageFilename) throws IOException {
PackageManifest packageManifest = getPackageManifest(packageFilename);
List<Pair<String, String>> filenameMappings = //
Read.from2(//
packageManifest.getFilenameMappings()).sort(//
(p0, p1) -> p1.t0.length() - p0.t0.length()).toList();
List<InstallAction> installActions = new ArrayList<>();
try (ZipFile zipFile = new ZipFile(packageFilename)) {
installActions.addAll(//
Read.from(//
FileUtil.listZip(zipFile)).map(filename0 -> {
String filename1 = filename0;
for (Pair<String, String> filenameMapping : filenameMappings) {
String[] match;
if ((match = Wildcard.match(filenameMapping.t0, filename1)) != null) {
filename1 = Wildcard.apply(filenameMapping.t1, match);
break;
}
}
return new ExtractFileAction(packageFilename, filename0, filename1);
}).toList());
}
installActions.addAll(//
Read.from(//
packageManifest.getCommands()).map(//
command -> new ExecCommandAction(command.getInstallCommand(), command.getUninstallCommand())).toList());
int progress = 0;
boolean isSuccess = true;
for (; progress < installActions.size(); progress++) try {
installActions.get(progress).act();
} catch (Exception ex) {
log.error("Error during installation", ex);
isSuccess = false;
break;
}
if (isSuccess)
keeper.savePackageMemento(new PackageMemento(packageManifest, installActions));
else
progress = unact(installActions, progress);
return isSuccess;
}
Aggregations