Search in sources :

Example 46 with Artifact

use of org.apache.archiva.maven2.model.Artifact 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 47 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.

the class InstallationService method housekeep.

public void housekeep(File base) {
    GenericMessageDialogController.withInfoProps("Scan was started", "Scanning " + base.getAbsolutePath()).show();
    ReturningTask<Void> task = () -> {
        final AtomicInteger emptyDirs = new AtomicInteger();
        final AtomicInteger emptyFiles = new AtomicInteger();
        for (Artifact entry : artifactsService.getArtifactsDb()) {
            if (artifactsService.isInstalled(base, entry)) {
                boolean emptyDirFound = true;
                while (emptyDirFound) {
                    emptyDirFound = false;
                    for (File f : FileUtils.listFilesAndDirs(LocalStorageUtil.getSubdirOrFile(base, entry), TrueFileFilter.TRUE, TrueFileFilter.TRUE)) {
                        if (!f.isDirectory()) {
                            if (f.length() == 0) {
                                emptyFiles.incrementAndGet();
                                FileUtils.deleteQuietly(f);
                                emptyDirFound = true;
                            }
                        } else {
                            if (f.list().length == 0 || f.getName().toUpperCase().equals("__MACOSX")) {
                                emptyDirs.incrementAndGet();
                                FileUtils.deleteQuietly(f);
                                emptyDirFound = true;
                            }
                        }
                    }
                }
            }
        }
        GenericMessageDialogController.withInfoProps("Housekeeping finished", "Removed " + emptyFiles.get() + " empty files and " + emptyDirs.get() + " dirs", true).showAndWait();
        return null;
    };
    ExecutorUtil.executeAsyncWithRetry(task, 3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) File(java.io.File) Support.isRemoteArtifact(se.light.assembly64.Support.isRemoteArtifact) Artifact(se.light.assembly64.model.Artifact)

Example 48 with Artifact

use of org.apache.archiva.maven2.model.Artifact 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)

Example 49 with Artifact

use of org.apache.archiva.maven2.model.Artifact in project assembly64fx by freabemania.

the class Scheduler method addToQueue.

public void addToQueue(Integer installation, Artifact entry) {
    File location = UserService.getInstance().getLocation(installation).asFile();
    Optional<LocationAndArtifactToInstall> itemPossiblyAlreadyInList = workQueue.stream().filter(item -> item.getArtifact().getName().equals(entry.getName())).findFirst();
    LocationAndInstallationStatus tmp = LocationAndInstallationStatus.builder().location(location).id(installation).build();
    if (itemPossiblyAlreadyInList.isPresent()) {
        LOGGER.info("Adding " + entry.getName() + " " + installation + " to already in queue");
        ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
        itemPossiblyAlreadyInList.get().addLocationAndInstallationStatus(tmp);
    } else if (currentlyInstalling.containsKey(entry.getName())) {
        LOGGER.info("Adding " + entry.getName() + " to current worker");
        ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(tmp, entry));
        currentlyInstalling.get(entry.getName()).addLocationAndInstallationStatus(tmp);
    } else {
        Optional<Artifact> first = artifactsService.getArtifactsDb().stream().filter(item -> item.isMarkedForUpdate() || item.isUpdating()).findFirst();
        LocationAndInstallationStatus locationAndInstallation = LocationAndInstallationStatus.builder().location(location).id(installation).build();
        if (!first.isPresent()) {
            ProgressControlWrapper.getInstance().resetThreadIdMapping();
            ProgressControlWrapper.getInstance().setProgressSteps(countNofItems(locationAndInstallation, entry));
        } else {
            ProgressControlWrapper.getInstance().addProgressSteps(countNofItems(locationAndInstallation, entry));
        }
        entry.setMarkedForUpdate(true);
        // Main.resolveFXMain().refreshTree();
        Support.refreshTree();
        workQueue.offer(LocationAndArtifactToInstall.builder().artifact(entry).locationsAndInstallationStatus(LocationAndInstallationStatus.builder().location(location).id(installation).build()).build());
    }
}
Also used : LocationAndArtifactToInstall(se.light.assembly64.model.LocationAndArtifactToInstall) ArtifactDelta(se.light.assembly64.model.ArtifactDelta) LoggerFactory(org.slf4j.LoggerFactory) PoisonPill(se.light.assembly64.model.PoisonPill) HashMap(java.util.HashMap) PathService(se.light.assembly64.service.PathService) ArrayList(java.util.ArrayList) Support.getVersionAsInteger(se.light.assembly64.Support.getVersionAsInteger) ArtifactType(se.light.assembly64.model.ArtifactType) Map(java.util.Map) CancelableTask(se.light.assembly64.model.CancelableTask) Support.getExecutor(se.light.assembly64.Support.getExecutor) Logger(org.slf4j.Logger) BlockingQueue(java.util.concurrent.BlockingQueue) Artifact(se.light.assembly64.model.Artifact) ArtifactsService(se.light.assembly64.service.ArtifactsService) LocalStorageUtil(se.light.assembly64.util.LocalStorageUtil) File(java.io.File) UserService(se.light.assembly64.service.UserService) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ProgressControlWrapper(se.light.assembly64.fx.ProgressControlWrapper) List(java.util.List) LocationAndArtifactToInstall(se.light.assembly64.model.LocationAndArtifactToInstall) SettingsController(se.light.assembly64.fx.SettingsController) Optional(java.util.Optional) InstallationService(se.light.assembly64.service.InstallationService) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) Optional(java.util.Optional) LocationAndInstallationStatus(se.light.assembly64.model.LocationAndInstallationStatus) File(java.io.File)

Aggregations

Artifact (org.apache.archiva.maven2.model.Artifact)37 Test (org.junit.Test)29 ArrayList (java.util.ArrayList)14 SearchService (org.apache.archiva.rest.api.services.SearchService)14 BrowseService (org.apache.archiva.rest.api.services.BrowseService)11 Path (java.nio.file.Path)10 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)9 Artifact (se.light.assembly64.model.Artifact)9 List (java.util.List)8 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)8 File (java.io.File)7 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 LoggerFactory (org.slf4j.LoggerFactory)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5