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 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.osgi.application;
023
024import java.io.BufferedInputStream;
025import java.io.File;
026import java.io.FileInputStream;
027import java.io.FileNotFoundException;
028import java.io.IOException;
029import java.io.InputStream;
030import java.util.Properties;
031import java.util.regex.Pattern;
032
033/**
034 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a>
035 */
036public class TestMain {
037
038    public static final String CONFIG_FILE = ".properties";
039
040    public static final String BUNDLES = "bundles";
041
042    public static final String INSTALL_DIR = "installdir";
043
044    public static final String LIB_DIR = "libdir";
045
046    public static final Pattern STR_LIST = Pattern.compile("\\s,\\s");
047
048    public static void main(String[] args) throws Exception {
049        CommandLineOptions cmdArgs = new CommandLineOptions(args);
050
051        // String clear = cmdArgs.getOption("c");
052
053        File configFile;
054        String cfg = cmdArgs.getOption("f");
055        if (cfg != null) {
056            configFile = new File(cfg);
057        } else {
058            configFile = new File(CONFIG_FILE);
059        }
060
061        String installDirProp;
062        String bundlesList = null;
063        String libList;
064        if (configFile.isFile()) {
065            Properties config = new Properties();
066            InputStream in = new BufferedInputStream(new FileInputStream(configFile));
067            config.load(in);
068            installDirProp = config.getProperty(INSTALL_DIR);
069            bundlesList = config.getProperty(BUNDLES);
070            libList = config.getProperty(LIB_DIR);
071        } else {
072            installDirProp = cmdArgs.getOption("d");
073            bundlesList = cmdArgs.getOption("b");
074            libList = cmdArgs.getOption("cp");
075        }
076
077        File installDir = null;
078        if (installDirProp == null) {
079            installDir = new File("."); // current dir
080        } else {
081            installDir = new File(installDirProp);
082        }
083
084        SharedClassLoader cl = new SharedClassLoaderImpl(TestMain.class.getClassLoader());
085        if (libList != null) {
086            String[] libs = STR_LIST.split(libList, 0);
087            // loadLibs(cl, installDir, libs);
088        }
089    }
090
091}