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    public List<Bundle> deployedBundles() {
051        return deployedBundles;
052    }
053
054    public Stream<Bundle> deployedBundlesAsStream() {
055        return deployedBundles().stream();
056    }
057
058    public Stream<File> deployedFilesAsStream() {
059        return deployedBundlesAsStream().map(Bundle::getLocation).map(File::new);
060    }
061
062    public ReloadResult merge(ReloadResult result) {
063        undeployedBundles.addAll(result.undeployedBundles);
064        deployedBundles.addAll(result.deployedBundles);
065        return this;
066    }
067
068}