001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (http://nuxeo.com/) and contributors.
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 *     bstefanescu
018 */
019package org.nuxeo.runtime.test.runner.distrib;
020
021import org.nuxeo.runtime.test.runner.SimpleFeature;
022
023/**
024 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
025 */
026public class DistributionFeature extends SimpleFeature {
027
028    // protected NuxeoDistribution distrib;
029    // protected NuxeoApp app;
030    //
031    // @Override
032    // public void initialize(FeaturesRunner runner) throws Exception {
033    // distrib = FeaturesRunner.getScanner().getFirstAnnotation(runner.getTargetTestClass(), NuxeoDistribution.class);
034    // if (distrib == null) {
035    // throw new
036    // IllegalArgumentException("No distribution specified. Use @NuxeoDistribution on your class to specify the distribution to be used");
037    // }
038    //
039    // }
040    //
041    // @Override
042    // public void start(FeaturesRunner runner) throws Exception {
043    // File home = makeHome(distrib.home());
044    // app = new NuxeoApp(home);
045    // app.setVerbose(true);
046    // app.setOffline(distrib.offline());
047    // app.setUpdatePolicy(distrib.updatePolicy());
048    // if (distrib.config().length() > 0) {
049    // app.build(makeUrl(distrib.config()), distrib.useCache());
050    // } else {
051    // app.build(distrib.profile(), distrib.useCache());
052    // }
053    // NuxeoApp.setHttpServerAddress(distrib.host(), distrib.port());
054    // app.start();
055    // }
056    //
057    // protected File makeHome(String path) {
058    // if (path.startsWith("~")) {
059    // path = System.getProperty("user.home") + path.substring(1);
060    // }
061    // path = path.replace("{profile}", distrib.profile());
062    // path = path.replace("{tmp}", System.getProperty("java.io.tmpdir"));
063    // return new File(path);
064    // }
065    //
066    // @Override
067    // public void stop(FeaturesRunner runner) throws Exception {
068    // app.shutdown();
069    // }
070    //
071    //
072    // protected static URL makeUrl(String spec) {
073    // try {
074    // if (spec.indexOf(':') > -1) {
075    // if (spec.startsWith("java:")) {
076    // spec = spec.substring(5);
077    // ClassLoader cl = getContextClassLoader();
078    // URL url = cl.getResource(spec);
079    // if (url == null) {
080    // fail("Canot found java resource: "+spec);
081    // }
082    // return url;
083    // } else {
084    // return new URL(spec);
085    // }
086    // } else {
087    // return new File(spec).toURI().toURL();
088    // }
089    // } catch (Exception e) {
090    // fail("Invalid config file soecification. Not a valid URL or file: "+spec);
091    // return null;
092    // }
093    // }
094    //
095    // protected static void fail(String msg) {
096    // System.err.println(msg);
097    // System.exit(2);
098    // }
099    //
100    // protected static ClassLoader getContextClassLoader() {
101    // ClassLoader cl = Thread.currentThread().getContextClassLoader();
102    // return cl == null ? DistributionFeature.class.getClassLoader() : cl;
103    // }
104
105}