Search in sources :

Example 1 with ExecCommandAction

use of suite.pkgmanager.action.ExecCommandAction 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;
}
Also used : ExecCommandAction(suite.pkgmanager.action.ExecCommandAction) Read(suite.streamlet.Read) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) InstallAction(suite.pkgmanager.action.InstallAction) ArrayList(java.util.ArrayList) Wildcard(suite.parser.Wildcard) Pair(suite.adt.pair.Pair) List(java.util.List) ExtractFileAction(suite.pkgmanager.action.ExtractFileAction) FileUtil(suite.os.FileUtil) ZipFile(java.util.zip.ZipFile) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) InputStream(java.io.InputStream) InstallAction(suite.pkgmanager.action.InstallAction) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ExtractFileAction(suite.pkgmanager.action.ExtractFileAction) ZipFile(java.util.zip.ZipFile) ExecCommandAction(suite.pkgmanager.action.ExecCommandAction) Pair(suite.adt.pair.Pair)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ZipFile (java.util.zip.ZipFile)1 Log (org.apache.commons.logging.Log)1 LogFactory (org.apache.commons.logging.LogFactory)1 Pair (suite.adt.pair.Pair)1 FileUtil (suite.os.FileUtil)1 Wildcard (suite.parser.Wildcard)1 ExecCommandAction (suite.pkgmanager.action.ExecCommandAction)1 ExtractFileAction (suite.pkgmanager.action.ExtractFileAction)1 InstallAction (suite.pkgmanager.action.InstallAction)1 Read (suite.streamlet.Read)1