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.nio.file.Path;
024import java.nio.file.Paths;
025import java.util.ArrayList;
026import java.util.Arrays;
027import java.util.List;
028import java.util.Objects;
029
030/**
031 * The reload actions to perform when reloading the Nuxeo server.
032 *
033 * @since 9.3
034 */
035public class ReloadContext {
036
037    protected final List<String> bundlesNamesToUndeploy;
038
039    protected final List<File> bundlesToDeploy;
040
041    /** The bundle destination relative path, it will be computed from runtime home (usually nxserver). */
042    protected final Path bundlesDestination;
043
044    public ReloadContext() {
045        this("bundles");
046    }
047
048    /**
049     * Constructor which takes the destination as argument. The given path must be relative to nxserver directory.
050     */
051    public ReloadContext(String bundlesDestination) {
052        this(Paths.get(bundlesDestination));
053    }
054
055    /**
056     * Constructor which takes the destination as argument. The given path must be relative to nxserver directory.
057     */
058    public ReloadContext(Path bundlesDestination) {
059        bundlesNamesToUndeploy = new ArrayList<>();
060        bundlesToDeploy = new ArrayList<>();
061        this.bundlesDestination = Objects.requireNonNull(bundlesDestination, "Bundles destination must not be null");
062    }
063
064    public ReloadContext undeploy(List<String> bundleNames) {
065        bundlesNamesToUndeploy.addAll(bundleNames);
066        return this;
067    }
068
069    public ReloadContext undeploy(String... bundleNames) {
070        return undeploy(Arrays.asList(bundleNames));
071    }
072
073    public ReloadContext deploy(List<File> bundleFiles) {
074        bundlesToDeploy.addAll(bundleFiles);
075        return this;
076    }
077
078    public ReloadContext deploy(File... bundleFiles) {
079        return deploy(Arrays.asList(bundleFiles));
080    }
081
082}