use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class Indexer method doIndexerExecution.
/*
* This is the second phase of the indexer which generates Lucene index
* by passing source code files through Exuberant ctags, generating xrefs
* and storing data from the source files in the index (along with history,
* if any).
*/
public void doIndexerExecution(final boolean update, int noThreads, List<String> subFiles, IndexChangedListener progress) throws IOException {
Statistics elapsed = new Statistics();
RuntimeEnvironment env = RuntimeEnvironment.getInstance().register();
LOGGER.info("Starting indexing");
ExecutorService executor = Executors.newFixedThreadPool(noThreads);
if (subFiles == null || subFiles.isEmpty()) {
if (update) {
IndexDatabase.updateAll(executor, progress);
} else if (env.isOptimizeDatabase()) {
IndexDatabase.optimizeAll(executor);
}
} else {
List<IndexDatabase> dbs = new ArrayList<>();
for (String path : subFiles) {
Project project = Project.getProject(path);
if (project == null && env.hasProjects()) {
LOGGER.log(Level.WARNING, "Could not find a project for \"{0}\"", path);
} else {
IndexDatabase db;
if (project == null) {
db = new IndexDatabase();
} else {
db = new IndexDatabase(project);
}
int idx = dbs.indexOf(db);
if (idx != -1) {
db = dbs.get(idx);
}
if (db.addDirectory(path)) {
if (idx == -1) {
dbs.add(db);
}
} else {
LOGGER.log(Level.WARNING, "Directory does not exist \"{0}\"", path);
}
}
}
for (final IndexDatabase db : dbs) {
final boolean optimize = env.isOptimizeDatabase();
db.addIndexChangedListener(progress);
executor.submit(new Runnable() {
@Override
public void run() {
try {
if (update) {
db.update();
} else if (optimize) {
db.optimize();
}
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "An error occured while " + (update ? "updating" : "optimizing") + " index", e);
}
}
});
}
}
executor.shutdown();
while (!executor.isTerminated()) {
try {
// Wait forever
executor.awaitTermination(999, TimeUnit.DAYS);
} catch (InterruptedException exp) {
LOGGER.log(Level.WARNING, "Received interrupt while waiting for executor to finish", exp);
}
}
try {
// It can happen that history index is not done in prepareIndexer()
// but via db.update() above in which case we must make sure the
// thread pool for renamed file handling is destroyed.
RuntimeEnvironment.destroyRenamedHistoryExecutor();
} catch (InterruptedException ex) {
LOGGER.log(Level.SEVERE, "destroying of renamed thread pool failed", ex);
}
elapsed.report(LOGGER, "Done indexing data of all repositories");
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class IndexDatabase method optimizeAll.
/**
* Optimize all index databases
*
* @param executor An executor to run the job
* @throws IOException if an error occurs
*/
static void optimizeAll(ExecutorService executor) throws IOException {
List<IndexDatabase> dbs = new ArrayList<>();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
for (Project project : env.getProjects()) {
dbs.add(new IndexDatabase(project));
}
} else {
dbs.add(new IndexDatabase());
}
for (IndexDatabase d : dbs) {
final IndexDatabase db = d;
if (db.isDirty()) {
executor.submit(new Runnable() {
@Override
public void run() {
try {
db.update();
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
}
}
});
}
}
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class AuthorizationFrameworkTest method createUnallowedProject.
private Project createUnallowedProject() {
Project p = new Project();
p.setName("not_allowed" + "_" + "project" + Math.random());
return p;
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class IndexerTest method testIncrementalIndexAddRemoveFile.
@Test
public void testIncrementalIndexAddRemoveFile() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setCtags(System.getProperty(ctagsProperty, "ctags"));
env.setSourceRoot(repository.getSourceRoot());
env.setDataRoot(repository.getDataRoot());
if (env.validateExuberantCtags()) {
Project project = new Project();
String ppath = "bug3430";
project.setPath("/" + ppath);
IndexDatabase idb = new IndexDatabase(project);
assertNotNull(idb);
MyIndexChangeListener listener = new MyIndexChangeListener();
idb.addIndexChangedListener(listener);
idb.update();
assertEquals(1, listener.files.size());
listener.reset();
repository.addDummyFile(ppath);
idb.update();
assertEquals("No new file added", 1, listener.files.size());
repository.removeDummyFile(ppath);
idb.update();
assertEquals("Didn't remove the dummy file", 0, listener.files.size());
assertEquals("Didn't remove the dummy file", 1, listener.removedFiles.size());
} else {
System.out.println("Skipping test. Could not find a ctags I could use in path.");
}
}
use of org.opensolaris.opengrok.configuration.Project in project OpenGrok by OpenGrok.
the class ProjectHelperTest method testGetGroupedProjects.
/**
* Test of getGroupedProjects method, of class ProjectHelper.
*/
@Test
public void testGetGroupedProjects() {
Set<Project> result = helper.getGroupedProjects();
Assert.assertEquals(4, result.size());
for (Project p : result) {
Assert.assertTrue(p.getName().startsWith("allowed_"));
}
}
Aggregations