001/*
002 * (C) Copyright 2006-2011 Nuxeo SA (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 *     bstefanescu
018 */
019package org.nuxeo.osgi.application.client;
020
021import java.io.File;
022import java.lang.reflect.Method;
023import java.util.Collection;
024
025/**
026 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
027 */
028public class Main {
029
030    public static void main(String[] args) throws Exception {
031        if (args.length < 1) {
032            System.out.println("Usage app classToRun");
033            System.exit(1);
034        }
035        Collection<File> files = null;
036        String bundles = System.getProperty("nuxeo.bundles");
037        if (bundles != null) {
038            files = NuxeoApp.getBundleFiles(new File("."), bundles, ":");
039        }
040        NuxeoApp app = new NuxeoApp();
041        app.start();
042        System.out.println("Deploying bundles: " + files);
043        if (files != null) {
044            app.deployBundles(files);
045        }
046        if (args.length > 0) {
047            Class<?> klass = Class.forName(args[0]);
048            Method main = klass.getMethod("main", String[].class);
049            String[] tmp = new String[args.length - 1];
050            if (tmp.length > 0) {
051                System.arraycopy(args, 1, tmp, 0, tmp.length);
052            }
053            main.invoke(null, new Object[] { tmp });
054        }
055        app.shutdown();
056    }
057
058}