001/*
002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Kevin Leturc <kleturc@nuxeo.com>
018 *
019 */
020package org.nuxeo.runtime.reload;
021
022import java.io.File;
023import java.util.ArrayList;
024import java.util.List;
025import java.util.stream.Stream;
026
027import org.osgi.framework.Bundle;
028
029/**
030 * Result of hot reload operation.
031 *
032 * @since 9.3
033 */
034public class ReloadResult {
035
036    /** Be aware that theses bundles have been uninstalled, some methods may not work. */
037    protected final List<Bundle> undeployedBundles;
038
039    protected final List<Bundle> deployedBundles;
040
041    public ReloadResult() {
042        undeployedBundles = new ArrayList<>();
043        deployedBundles = new ArrayList<>();
044    }
045
046    public List<Bundle> undeployedBundles() {
047        return undeployedBundles;
048    }
049
050    /**
051     * @since 10.3
052     */
053    public Stream<Bundle> undeployedBundlesAsStream() {
054        return undeployedBundles().stream();
055    }
056
057    public List<Bundle> deployedBundles() {
058        return deployedBundles;
059    }
060
061    public Stream<Bundle> deployedBundlesAsStream() {
062        return deployedBundles().stream();
063    }
064
065    public Stream<File> deployedFilesAsStream() {
066        return deployedBundlesAsStream().map(Bundle::getLocation).map(File::new);
067    }
068
069    public ReloadResult merge(ReloadResult result) {
070        undeployedBundles.addAll(result.undeployedBundles);
071        deployedBundles.addAll(result.deployedBundles);
072        return this;
073    }
074
075}