Search in sources :

Example 1 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method unpackDynamic.

private void unpackDynamic(File content, LocationAndInstallationStatus location, Artifact entry, ArtifactDelta delta) throws Exception {
    CancelableTask cancelTask = CancelableTask.of();
    LocalStorageUtil.createDir(pathService.getTmpDynFolder());
    unzipService.extractZip(content, pathService.getTmpDynFolder(), entry);
    if (cancelTask.isCancelled()) {
        return;
    }
    File[] files = LocalStorageUtil.getSubdirOrFile(pathService.getTmpDynFolder(), entry.getFolder()).listFiles();
    File base = LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getPrefix() + "/" + entry.getFolder());
    Optional<File> releaseLogFile = Arrays.stream(files).filter(item -> item.getName().equals("releaselog.json")).findFirst();
    List<ReleaseInfo> releaseInfoList = null;
    List<ReleaseInfo> matchedReleaseInfoList = new ArrayList<>();
    if (releaseLogFile.isPresent()) {
        releaseInfoList = Support.readList(ReleaseInfo.class, releaseLogFile.get()).stream().collect(Collectors.toList());
        for (ReleaseInfo item : releaseInfoList) {
            String p = item.getPath();
            int start = p.indexOf("/", p.indexOf("/") + 1);
            item.setPath(entry.getPrefix() + "/" + entry.getFolder() + "/" + p.substring(start + 1));
            item.setStrippedPath(entry.getFolder() + "/" + p.substring(start + 1));
        }
    }
    for (File f : files) {
        if (f.isDirectory()) {
            String dirname = f.getName().toUpperCase();
            char firstChar = dirname.charAt(0);
            boolean isDigit = Character.isDigit(firstChar);
            boolean isAlpha = Character.isAlphabetic(firstChar);
            String target = findDestination(firstChar, dirname, base);
            if (target != null) {
                File t = null;
                if (isDigit) {
                    t = new File(base.getAbsolutePath() + "/0-9/" + target + "/" + f.getName());
                } else if (isAlpha) {
                    t = new File(base.getAbsolutePath() + "/" + String.valueOf(firstChar) + "/" + target + "/" + f.getName());
                } else {
                    t = new File(base.getAbsolutePath() + "/___MISC___/" + target + "/" + f.getName());
                }
                FileUtils.forceMkdir(t);
                FileUtils.copyDirectory(f, t);
                if (releaseInfoList != null) {
                    ReleaseInfo matchedReleaseInfo = null;
                    for (ReleaseInfo item : releaseInfoList) {
                        File[] subdirs = f.listFiles(File::isDirectory);
                        for (File dir : subdirs) {
                            if (dir.getPath().contains(item.getStrippedPath())) {
                                matchedReleaseInfo = item;
                                break;
                            }
                        }
                    }
                    if (matchedReleaseInfo != null) {
                        matchedReleaseInfo.setPath(t.getAbsolutePath().substring(base.getAbsolutePath().length() + 1));
                        matchedReleaseInfoList.add(matchedReleaseInfo);
                    }
                }
                ProgressControlWrapper.getInstance().setProgressLabel("Moved " + f.getName() + " to " + t.getAbsolutePath());
                if (cancelTask.isCancelled()) {
                    break;
                }
            } else {
                LOGGER.info("Unable to install " + dirname);
            }
        }
    }
    ProgressControlWrapper.getInstance().increaseProgress();
    if (releaseLogFile.isPresent()) {
        File t = new File(base.getAbsolutePath() + "/releaselog.json");
        LOGGER.info("Flushing rebuildt releaselog.json to " + t.getAbsolutePath());
        Support.flush(matchedReleaseInfoList, t);
    }
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) ArrayList(java.util.ArrayList) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Example 2 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method resolveLatestInstalledByLocation.

public Set<LatestInstalledItemInfo> resolveLatestInstalledByLocation(LocationAndInstallationStatus location) {
    String key = location.getLocation().getPath();
    if (recentlyInstalled.containsKey(key)) {
        return recentlyInstalled.get(key);
    } else {
        List<LatestInstalledItemInfo> items = Support.readList(LatestInstalledItemInfo.class, resolvedLatestInstallationsFile(location));
        int size = items.size();
        items.removeIf(item -> ChronoUnit.DAYS.between(item.toLocalDate(), LocalDate.now()) > 3);
        int sizeAfterCheck = items.size();
        if (size != sizeAfterCheck) {
            flush(items, resolvedLatestInstallationsFile(location));
        }
        Set<LatestInstalledItemInfo> set = new HashSet<>(items);
        recentlyInstalled.put(key, set);
        return set;
    }
}
Also used : LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) HashSet(java.util.HashSet)

Example 3 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class Scheduler method countNofItems.

private int countNofItems(LocationAndInstallationStatus location, Artifact entry) {
    try {
        if (entry.getType() == ArtifactType.REMOTE) {
            String latestInstalled = artifactsService.getLatestVersion(artifactsService.resolveDB(location, entry));
            if (artifactsService.isInstalled(location, entry)) {
                int installedVersion = getVersionAsInteger(latestInstalled);
                int ticks = 0;
                for (ArtifactDelta delta : entry.getDeltas()) {
                    if (installedVersion < getVersionAsInteger(delta.getVersion())) {
                        ticks = ticks + 2;
                    } else {
                    }
                }
                return ticks;
            } else {
                return 2;
            }
        } else {
            return 1;
        }
    } catch (Exception e) {
        LOGGER.error("Error when counting", e);
        return 1;
    }
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta)

Example 4 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method addToLatestInstalled.

public void addToLatestInstalled(LocationAndInstallationStatus location, Artifact entry) {
    Set<LatestInstalledItemInfo> latestItems = resolveLatestInstalledByLocation(location);
    Optional<LatestInstalledItemInfo> foundItem = latestItems.stream().filter(item -> item.getId().equals(entry.getName())).findFirst();
    LatestInstalledItemInfo updatedItem = LatestInstalledItemInfo.builder().id(entry.getName()).date(getTodayDateAsBasicIsoString()).build();
    if (foundItem.isPresent()) {
        latestItems.remove(foundItem.get());
    }
    latestItems.add(updatedItem);
    flush(latestItems, resolvedLatestInstallationsFile(location));
}
Also used : ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo)

Example 5 with LocationAndInstallationStatus

use of se.light.assembly64.model.LocationAndInstallationStatus in project assembly64fx by freabemania.

the class InstallationService method installDelta.

private void installDelta(LocationAndInstallationStatus location, Artifact entry) throws Exception {
    LOGGER.info("Updating " + entry.getName());
    if (entry.isCreateDelta()) {
        Integer latestUpdated = getVersionAsInteger(artifactsService.getLatestVersion(artifactsService.resolveDB(location, entry)));
        List<ArtifactDelta> entries = entry.getDeltas().stream().filter(item -> {
            return getVersionAsInteger(item.getVersion()) > latestUpdated;
        }).collect(Collectors.toList());
        CancelableTask cancelTask = CancelableTask.of();
        for (ArtifactDelta e : entries) {
            if (cancelTask.isRunning()) {
                if (entry.isDynamicImport()) {
                    File file = installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion(), true, true);
                    unpackDynamic(file, location, entry, e);
                    if (!cancelTask.isCancelled()) {
                        updateDb(location, entry, e.getVersion());
                    } else {
                        break;
                    }
                } else {
                    installEntry(location, entry, entry.getBaseDir() + "/delta", e.getFile(), e.getVersion());
                }
            } else {
                ProgressControlWrapper.getInstance().setProgressLabel("Cancelling");
                return;
            }
        }
    } else {
        ProgressControlWrapper.getInstance().setProgressLabel("Will delete current folder " + entry.getName() + ", please wait...");
        FileUtils.deleteQuietly(LocalStorageUtil.getSubdirOrFile(location.getLocation(), entry.getAbsoluteInstallationPath()));
        ProgressControlWrapper.getInstance().setProgressLabel("Installing new version");
        installEntry(location, entry, entry.getBaseDir(), entry.getFile(), entry.getVersion());
    }
}
Also used : Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArtifactDelta(se.light.assembly64.model.ArtifactDelta) ReturningTask(se.light.assembly64.model.ReturningTask) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LatestInstalledItemInfo(se.light.assembly64.model.LatestInstalledItemInfo) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ProgressDBController(se.light.assembly64.fx.ProgressDBController) GuiUtils(se.light.assembly64.util.GuiUtils) Map(java.util.Map) Support(se.light.assembly64.Support) Support.flush(se.light.assembly64.Support.flush) CancelableTask(se.light.assembly64.model.CancelableTask) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) Support.getObjectMapper(se.light.assembly64.Support.getObjectMapper) ContentEntry(se.light.assembly64.model.ContentEntry) GenericMessageDialogController(se.light.assembly64.fx.GenericMessageDialogController) Analytics(se.light.assembly64.Analytics) Logger(org.slf4j.Logger) ExecutorUtil(se.light.assembly64.util.ExecutorUtil) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Artifact(se.light.assembly64.model.Artifact) Collectors(java.util.stream.Collectors) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) ReleaseInfo(se.light.assembly64.model.ReleaseInfo) Platform(javafx.application.Platform) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) SearchResultItem(se.light.assembly64.model.SearchResultItem) NullWindowOwner(se.light.assembly64.fx.NullWindowOwner) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) DOWNLOAD_STATUS(se.light.assembly64.service.FTPService.DOWNLOAD_STATUS) ProgressMessageBox(se.light.assembly64.ProgressMessageBox) FILE_ACTION(se.light.assembly64.Support.FILE_ACTION) Support.getTodayDateAsBasicIsoString(se.light.assembly64.Support.getTodayDateAsBasicIsoString) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) ArtifactDelta(se.light.assembly64.model.ArtifactDelta) File(java.io.File) CancelableTask(se.light.assembly64.model.CancelableTask)

Aggregations

File (java.io.File)6 CancelableTask (se.light.assembly64.model.CancelableTask)6 ArtifactDelta (se.light.assembly64.model.ArtifactDelta)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Map (java.util.Map)4 Optional (java.util.Optional)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Support.getTodayDateAsBasicIsoString (se.light.assembly64.Support.getTodayDateAsBasicIsoString)4 Support.getVersionAsInteger (se.light.assembly64.Support.getVersionAsInteger)4 ProgressControlWrapper (se.light.assembly64.fx.ProgressControlWrapper)4 Artifact (se.light.assembly64.model.Artifact)4 ArtifactType (se.light.assembly64.model.ArtifactType)4 LocalDate (java.time.LocalDate)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3 ChronoUnit (java.time.temporal.ChronoUnit)3