Search in sources :

Example 16 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class WebappListener method contextInitialized.

/**
     * {@inheritDoc}
     */
@Override
public void contextInitialized(final ServletContextEvent servletContextEvent) {
    ServletContext context = servletContextEvent.getServletContext();
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    String config = context.getInitParameter("CONFIGURATION");
    if (config == null) {
        LOGGER.severe("CONFIGURATION section missing in web.xml");
    } else {
        try {
            env.readConfiguration(new File(config));
        } catch (IOException ex) {
            LOGGER.log(Level.WARNING, "OpenGrok Configuration error. Failed to read config file: ", ex);
        }
    }
    String address = context.getInitParameter("ConfigAddress");
    if (address != null && address.length() > 0) {
        LOGGER.log(Level.CONFIG, "Will listen for configuration on [{0}]", address);
        String[] cfg = address.split(":");
        if (cfg.length == 2) {
            try {
                SocketAddress addr = new InetSocketAddress(InetAddress.getByName(cfg[0]), Integer.parseInt(cfg[1]));
                if (!RuntimeEnvironment.getInstance().startConfigurationListenerThread(addr)) {
                    LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread");
                }
            } catch (NumberFormatException | UnknownHostException ex) {
                LOGGER.log(Level.SEVERE, "OpenGrok: Failed to start configuration listener thread:", ex);
            }
        } else {
            LOGGER.log(Level.SEVERE, "Incorrect format for the configuration address: ");
            for (int i = 0; i < cfg.length; ++i) {
                LOGGER.log(Level.SEVERE, "[{0}]", cfg[i]);
            }
        }
    }
    try {
        RuntimeEnvironment.getInstance().loadStatistics();
    } catch (IOException ex) {
        LOGGER.log(Level.INFO, "Could not load statistics from a file.", ex);
    } catch (ParseException ex) {
        LOGGER.log(Level.SEVERE, "Could not parse statistics from a file.", ex);
    }
    String pluginDirectory = context.getInitParameter(AUTHORIZATION_PLUGIN_DIRECTORY);
    if (pluginDirectory != null) {
        env.getConfiguration().setPluginDirectory(pluginDirectory);
        // start + load
        AuthorizationFramework.getInstance();
    } else {
        if (env.getDataRootPath() == null) {
            env.getConfiguration().setPluginDirectory(PLUGIN_DIRECTORY_DEFAULT);
        } else {
            env.getConfiguration().setPluginDirectory(env.getDataRootPath() + "/../" + PLUGIN_DIRECTORY_DEFAULT);
        }
        LOGGER.log(Level.INFO, AUTHORIZATION_PLUGIN_DIRECTORY + " is not set in web.xml. Default location will be used.");
    }
    String watchDog = context.getInitParameter(ENABLE_AUTHORIZATION_WATCH_DOG);
    if (pluginDirectory != null && watchDog != null && Boolean.parseBoolean(watchDog)) {
        RuntimeEnvironment.getInstance().startWatchDogService(new File(pluginDirectory));
    }
    RuntimeEnvironment.getInstance().startIndexReopenThread();
    RuntimeEnvironment.getInstance().startExpirationTimer();
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) ServletContext(javax.servlet.ServletContext) ParseException(org.json.simple.parser.ParseException) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) File(java.io.File)

Example 17 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class RepositoryFactory method getRepository.

/**
     * Returns a repository for the given file, or null if no repository was
     * found.
     *
     * @param file File that might contain a repository
     * @return Correct repository for the given file
     * @throws java.lang.InstantiationException in case we cannot create the
     * repository object
     * @throws java.lang.IllegalAccessException in case no permissions
     * to repository file
     */
public static Repository getRepository(File file) throws InstantiationException, IllegalAccessException {
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    Repository res = null;
    for (Repository rep : repositories) {
        if (rep.isRepositoryFor(file)) {
            res = rep.getClass().newInstance();
            try {
                res.setDirectoryName(file.getCanonicalPath());
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Failed to get canonical path name for " + file.getAbsolutePath(), e);
            }
            if (!res.isWorking()) {
                LOGGER.log(Level.WARNING, "{0} not working (missing binaries?): {1}", new Object[] { res.getClass().getSimpleName(), file.getPath() });
            }
            if (res.getType() == null || res.getType().length() == 0) {
                res.setType(res.getClass().getSimpleName());
            }
            if (res.getParent() == null || res.getParent().length() == 0) {
                try {
                    res.setParent(res.determineParent());
                } catch (IOException ex) {
                    LOGGER.log(Level.WARNING, "Failed to get parent for {0}: {1}", new Object[] { file.getAbsolutePath(), ex });
                }
            }
            if (res.getBranch() == null || res.getBranch().length() == 0) {
                try {
                    res.setBranch(res.determineBranch());
                } catch (IOException ex) {
                    LOGGER.log(Level.WARNING, "Failed to get branch for {0}: {1}", new Object[] { file.getAbsolutePath(), ex });
                }
            }
            if (res.getCurrentVersion() == null || res.getCurrentVersion().length() == 0) {
                try {
                    res.setCurrentVersion(res.determineCurrentVersion());
                } catch (IOException ex) {
                    LOGGER.log(Level.WARNING, "Failed to determineCurrentVersion for {0}: {1}", new Object[] { file.getAbsolutePath(), ex });
                }
            }
            // revision, we need to prepare list of all tags in advance.
            if (env.isTagsEnabled() && res.hasFileBasedTags()) {
                res.buildTagList(file);
            }
            break;
        }
    }
    return res;
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) IOException(java.io.IOException)

Example 18 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerRepoTest method testMainWithH.

@Test
public void testMainWithH() throws IOException {
    System.out.println("Generate index by using command line options with -H");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty(ctagsProperty, "ctags"));
    if (env.validateExuberantCtags()) {
        String[] argv = { "-S", "-H", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v" };
        Indexer.main(argv);
        checkNumberOfThreads();
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Example 19 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerRepoTest method testMainWithoutH.

@Test
public void testMainWithoutH() throws IOException {
    System.out.println("Generate index by using command line options without -H");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty(ctagsProperty, "ctags"));
    if (env.validateExuberantCtags()) {
        String[] argv = { "-S", "-P", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v" };
        Indexer.main(argv);
        checkNumberOfThreads();
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Example 20 with RuntimeEnvironment

use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.

the class IndexerTest method testMain.

/**
     * Test of doIndexerExecution method, of class Indexer.
     * @throws java.io.IOException
     */
@Test
public void testMain() throws IOException {
    System.out.println("Generate index by using command line options");
    RuntimeEnvironment env = RuntimeEnvironment.getInstance();
    env.setCtags(System.getProperty(ctagsProperty, "ctags"));
    if (env.validateExuberantCtags()) {
        String[] argv = { "-S", "-P", "-H", "-Q", "off", "-s", repository.getSourceRoot(), "-d", repository.getDataRoot(), "-v" };
        Indexer.main(argv);
    } else {
        System.out.println("Skipping test. Could not find a ctags I could use in path.");
    }
}
Also used : RuntimeEnvironment(org.opensolaris.opengrok.configuration.RuntimeEnvironment) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (org.opensolaris.opengrok.configuration.RuntimeEnvironment)45 File (java.io.File)20 IOException (java.io.IOException)17 Project (org.opensolaris.opengrok.configuration.Project)12 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)5 ParseException (java.text.ParseException)5 BufferedReader (java.io.BufferedReader)4 InputStreamReader (java.io.InputStreamReader)4 DateFormat (java.text.DateFormat)4 TestRepository (org.opensolaris.opengrok.util.TestRepository)4 Date (java.util.Date)3 IndexReader (org.apache.lucene.index.IndexReader)3 BeforeClass (org.junit.BeforeClass)3 OutputStreamWriter (java.io.OutputStreamWriter)2 HistoryException (org.opensolaris.opengrok.history.HistoryException)2 Repository (org.opensolaris.opengrok.history.Repository)2 Executor (org.opensolaris.opengrok.util.Executor)2 BufferedWriter (java.io.BufferedWriter)1