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();
}
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;
}
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.");
}
}
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.");
}
}
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.");
}
}
Aggregations