001/*
002 * (C) Copyright 2006-2018 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 *     Bogdan Stefanescu
018 *     Damien Metzler (Leroy Merlin, http://www.leroymerlin.fr/)
019 */
020package org.nuxeo.runtime.test.runner;
021
022import java.io.File;
023import java.net.URISyntaxException;
024import java.net.URL;
025import java.util.List;
026import java.util.Properties;
027import java.util.Set;
028
029import org.nuxeo.osgi.OSGiAdapter;
030import org.nuxeo.runtime.model.RuntimeContext;
031import org.nuxeo.runtime.test.WorkingDirectoryConfigurator;
032
033/**
034 * TODO: Move this to org.nuxeo.runtime package
035 *
036 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
037 */
038public interface RuntimeHarness {
039
040    /**
041     * Gets the framework working directory.
042     */
043    File getWorkingDir();
044
045    /**
046     * Resume the runtime
047     */
048    void fireFrameworkStarted() throws Exception;
049
050    /**
051     * Deploys a whole OSGI bundle.
052     * <p>
053     * The lookup is first done on symbolic name, as set in <code>MANIFEST.MF</code> and then falls back to the bundle
054     * url (e.g., <code>nuxeo-platform-search-api</code>) for backwards compatibility.
055     *
056     * @param bundle the symbolic name
057     */
058    void deployBundle(String bundle) throws Exception;
059
060    /**
061     * Undeploys a contribution from a given bundle.
062     * <p>
063     * The path will be relative to the bundle root. Example: <code>
064     * undeployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
065     * </code>
066     *
067     * @param bundle the bundle
068     * @param contrib the contribution
069     */
070    void undeployContrib(String bundle, String contrib) throws Exception;
071
072    /**
073     * @deprecated since 10.1, use {@link #deployContrib(String, String)}
074     */
075    @Deprecated
076    RuntimeContext deployTestContrib(String bundle, URL contrib) throws Exception;
077
078    /**
079     * Deploys an XML contribution from outside a bundle.
080     * <p>
081     * This should be used by tests wiling to deploy test contribution as part of a real bundle.
082     * <p>
083     * The bundle owner is important since the contribution may depend on resources deployed in that bundle.
084     * <p>
085     * Note that the owner bundle MUST be an already deployed bundle.
086     *
087     * @param bundle the bundle that becomes the contribution owner
088     * @param contrib the contribution to deploy as part of the given bundle
089     * @deprecated since 10.1, use {@link #deployContrib(String, String)}
090     */
091    @Deprecated
092    RuntimeContext deployTestContrib(String bundle, String contrib) throws Exception;
093
094    /**
095     * Deploys a contribution from a given bundle.
096     * <p>
097     * The path will be relative to the bundle root. Example: <code>
098     * deployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
099     * </code>
100     * <p>
101     * For compatibility reasons the name of the bundle may be a jar name, but this use is discouraged and deprecated.
102     *
103     * @param bundle the name of the bundle to peek the contrib in
104     * @param contrib the path to contrib in the bundle.
105     */
106    void deployContrib(String bundle, String contrib) throws Exception;
107
108    void start() throws Exception;
109
110    void stop() throws Exception;
111
112    boolean isStarted();
113
114    /**
115     * Deploys a subset of a Bundle defined per the targetExtensions parameter
116     *
117     * @param bundle the name of the component
118     * @param targetExtensions Set of allowed TargetExtensions in the final contribution
119     * @since 9.1
120     */
121    RuntimeContext deployPartial(String bundle, Set<TargetExtensions> targetExtensions) throws Exception;
122
123    void deployFolder(File folder, ClassLoader loader) throws Exception;
124
125    void addWorkingDirectoryConfigurator(WorkingDirectoryConfigurator config);
126
127    /**
128     * Framework properties for variable injections
129     *
130     * @since 5.4.2
131     */
132    Properties getProperties();
133
134    /**
135     * Runtime context for deployment
136     *
137     * @since 5.4.2
138     */
139    RuntimeContext getContext();
140
141    /**
142     * OSGI bridge
143     *
144     * @since 5.4.2
145     */
146    OSGiAdapter getOSGiAdapter();
147
148    /**
149     * @since 5.5
150     */
151    boolean isRestart();
152
153    /**
154     * @since 5.5
155     * @throws Exception
156     */
157    void restart() throws Exception;
158
159    /**
160     * @throws URISyntaxException
161     * @since 5.7
162     */
163    List<String> getClassLoaderFiles() throws URISyntaxException;
164
165}