001/*
002 * (C) Copyright 2006-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 *     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    RuntimeContext deployTestContrib(String bundle, URL contrib) throws Exception;
073
074    /**
075     * Deploys an XML contribution from outside a bundle.
076     * <p>
077     * This should be used by tests wiling to deploy test contribution as part of a real bundle.
078     * <p>
079     * The bundle owner is important since the contribution may depend on resources deployed in that bundle.
080     * <p>
081     * Note that the owner bundle MUST be an already deployed bundle.
082     *
083     * @param bundle the bundle that becomes the contribution owner
084     * @param contrib the contribution to deploy as part of the given bundle
085     */
086    RuntimeContext deployTestContrib(String bundle, String contrib) throws Exception;
087
088    /**
089     * Deploys a contribution from a given bundle.
090     * <p>
091     * The path will be relative to the bundle root. Example: <code>
092     * deployContrib("org.nuxeo.ecm.core", "OSGI-INF/CoreExtensions.xml")
093     * </code>
094     * <p>
095     * For compatibility reasons the name of the bundle may be a jar name, but this use is discouraged and deprecated.
096     *
097     * @param bundle the name of the bundle to peek the contrib in
098     * @param contrib the path to contrib in the bundle.
099     */
100    void deployContrib(String bundle, String contrib) throws Exception;
101
102    void start() throws Exception;
103
104    void stop() throws Exception;
105
106    boolean isStarted();
107
108    /**
109     * Deploys a subset of a Bundle defined per the targetExtensions parameter
110     *
111     * @param bundle the name of the component
112     * @param targetExtensions Set of allowed TargetExtensions in the final contribution
113     * @since 9.1
114     */
115    RuntimeContext deployPartial(String bundle, Set<TargetExtensions> targetExtensions) throws Exception;
116
117    void deployFolder(File folder, ClassLoader loader) throws Exception;
118
119    void addWorkingDirectoryConfigurator(WorkingDirectoryConfigurator config);
120
121    /**
122     * Framework properties for variable injections
123     *
124     * @since 5.4.2
125     */
126    Properties getProperties();
127
128    /**
129     * Runtime context for deployment
130     *
131     * @since 5.4.2
132     */
133    RuntimeContext getContext();
134
135    /**
136     * OSGI bridge
137     *
138     * @since 5.4.2
139     */
140    OSGiAdapter getOSGiAdapter();
141
142    /**
143     * @since 5.5
144     */
145    boolean isRestart();
146
147    /**
148     * @since 5.5
149     * @throws Exception
150     */
151    void restart() throws Exception;
152
153    /**
154     * @throws URISyntaxException
155     * @since 5.7
156     */
157    List<String> getClassLoaderFiles() throws URISyntaxException;
158
159}