use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class IndexDatabase method optimizeAll.
/**
* Optimize all index databases
*
* @param parallelizer a defined instance
* @throws IOException if an error occurs
*/
static void optimizeAll(IndexerParallelizer parallelizer) throws IOException {
List<IndexDatabase> dbs = new ArrayList<>();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.hasProjects()) {
for (Project project : env.getProjectList()) {
dbs.add(new IndexDatabase(project));
}
} else {
dbs.add(new IndexDatabase());
}
for (IndexDatabase d : dbs) {
final IndexDatabase db = d;
if (db.isDirty()) {
parallelizer.getFixedExecutor().submit(new Runnable() {
@Override
public void run() {
try {
db.update(parallelizer);
} catch (Throwable e) {
LOGGER.log(Level.SEVERE, "Problem updating lucene index database: ", e);
}
}
});
}
}
}
use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class ProjectMessage method applyMessage.
@Override
protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
String command = getText();
validateMore(env);
switch(command) {
case "add":
for (String projectName : getTags()) {
File srcRoot = env.getSourceRootFile();
File projDir = new File(srcRoot, projectName);
if (!env.getProjects().containsKey(projectName)) {
Project project = new Project(projectName, "/" + projectName);
project.setTabSize(env.getConfiguration().getTabSize());
// Add repositories in this project.
List<RepositoryInfo> repos = getRepositoriesInDir(env, projDir);
env.addRepositories(repos);
env.getProjectRepositoriesMap().put(project, repos);
// Finally introduce the project to the configuration.
// Note that the project is inactive in the UI until it is indexed.
// See {@code isIndexed()}
env.getProjects().put(projectName, project);
Set<Project> projectSet = new TreeSet<>();
projectSet.add(project);
env.populateGroups(env.getGroups(), projectSet);
} else {
Project project = env.getProjects().get(projectName);
Map<Project, List<RepositoryInfo>> map = env.getProjectRepositoriesMap();
// Refresh the list of repositories of this project.
// This is the goal of this action: if an existing project
// is re-added, this means its list of repositories has changed.
List<RepositoryInfo> repos = getRepositoriesInDir(env, projDir);
List<RepositoryInfo> allrepos = env.getRepositories();
synchronized (allrepos) {
// newly added repository
for (RepositoryInfo repo : repos) {
if (!allrepos.contains(repo)) {
allrepos.add(repo);
}
}
// deleted repository
for (RepositoryInfo repo : map.get(project)) {
if (!repos.contains(repo)) {
allrepos.remove(repo);
}
}
}
map.put(project, repos);
}
}
break;
case "delete":
for (String projectName : getTags()) {
Project proj = env.getProjects().get(projectName);
if (proj == null) {
throw new Exception("cannot get project \"" + projectName + "\"");
}
LOGGER.log(Level.INFO, "deleting configuration for project " + projectName);
// Remove the project from its groups.
for (Group group : proj.getGroups()) {
group.getRepositories().remove(proj);
group.getProjects().remove(proj);
}
// Now remove the repositories associated with this project.
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(proj);
env.getRepositories().removeAll(repos);
env.getProjectRepositoriesMap().remove(proj);
env.getProjects().remove(projectName, proj);
// Prevent the project to be included in new searches.
env.refreshSearcherManagerMap();
// Lastly, remove data associated with the project.
LOGGER.log(Level.INFO, "deleting data for project " + projectName);
for (String dirName : new String[] { IndexDatabase.INDEX_DIR, IndexDatabase.XREF_DIR }) {
IOUtils.removeRecursive(Paths.get(env.getDataRootPath() + File.separator + dirName + File.separator + projectName));
}
HistoryGuru guru = HistoryGuru.getInstance();
guru.removeCache(repos.stream().map((x) -> {
try {
return env.getPathRelativeToSourceRoot(new File((x).getDirectoryName()));
} catch (ForbiddenSymlinkException e) {
LOGGER.log(Level.FINER, e.getMessage());
return "";
} catch (IOException e) {
LOGGER.log(Level.INFO, "cannot remove files for repository {0}", x.getDirectoryName());
// {@code removeCache()} will return nothing.
return "";
}
}).collect(Collectors.toSet()));
}
break;
case "indexed":
for (String projectName : getTags()) {
Project project;
if ((project = env.getProjects().get(projectName)) != null) {
project.setIndexed(true);
// Refresh current version of the project's repositories.
List<RepositoryInfo> riList = env.getProjectRepositoriesMap().get(project);
if (riList != null) {
for (RepositoryInfo ri : riList) {
Repository repo = getRepository(ri);
if (repo != null && repo.getCurrentVersion() != null && repo.getCurrentVersion().length() > 0) {
// getRepository() always creates fresh instance
// of the Repository object so there is no need
// to call setCurrentVersion() on it.
ri.setCurrentVersion(repo.determineCurrentVersion());
}
}
}
} else {
LOGGER.log(Level.WARNING, "cannot find project " + projectName + " to mark as indexed");
}
}
// In case this project has just been incrementally indexed,
// its IndexSearcher needs a poke.
env.maybeRefreshIndexSearchers(getTags());
env.refreshDateForLastIndexRun();
break;
case "list":
return (env.getProjectNames().stream().collect(Collectors.joining("\n")).getBytes());
case "list-indexed":
return (env.getProjectList().stream().filter(p -> p.isIndexed()).map(p -> p.getName()).collect(Collectors.joining("\n")).getBytes());
case "get-repos":
List<String> repos = new ArrayList<>();
for (String projectName : getTags()) {
Project project;
if ((project = env.getProjects().get(projectName)) == null) {
continue;
}
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().get(project);
if (infos != null) {
repos.addAll(infos.stream().map(ri -> ri.getDirectoryNameRelative()).collect(Collectors.toList()));
}
}
return repos.stream().collect(Collectors.joining("\n")).getBytes();
case "get-repos-type":
Set<String> types = new TreeSet<>();
for (String projectName : getTags()) {
Project project;
if ((project = env.getProjects().get(projectName)) == null) {
continue;
}
List<RepositoryInfo> infos = env.getProjectRepositoriesMap().get(project);
if (infos != null) {
types.addAll(infos.stream().map(ri -> ri.getType()).collect(Collectors.toList()));
}
}
return types.stream().collect(Collectors.joining("\n")).getBytes();
}
return ("command \"" + getText() + "\" for projects " + String.join(",", getTags()) + " done").getBytes();
}
use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class PascalAnalyzerFactoryTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
ctags = new Ctags();
ctags.setBinary(RuntimeEnvironment.getInstance().getCtags());
repository = new TestRepository();
repository.create(PascalAnalyzerFactoryTest.class.getResourceAsStream("/org/opensolaris/opengrok/index/source.zip"));
PascalAnalyzerFactory analyzerFactory = new PascalAnalyzerFactory();
analyzer = analyzerFactory.getAnalyzer();
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
if (env.validateExuberantCtags()) {
analyzer.setCtags(new Ctags());
}
}
use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class AuthorizationEntityTest method setUp.
@Before
public void setUp() {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
envGroups = env.getGroups();
envProjects = env.getProjects();
env.setGroups(new TreeSet<>());
env.setProjects(new TreeMap<>());
}
use of org.opensolaris.opengrok.configuration.RuntimeEnvironment in project OpenGrok by OpenGrok.
the class AuthorizationEntityTest method testForGroupsAndForProjectsDiscoveryInvalidProjectInGroup.
/**
* Listed projects in the group don't exist.
*/
@Test
public void testForGroupsAndForProjectsDiscoveryInvalidProjectInGroup() {
AuthorizationEntity authEntity = authEntityFactory.apply(null);
authEntity.setForGroups(new TreeSet<>(Arrays.asList(new String[] { "group 1", "group 2" })));
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
Group g1 = new Group();
g1.setName("group 1");
g1.addProject(new Project("project 1"));
g1.addProject(new Project("project 2"));
g1.addProject(new Project("project 3"));
env.getGroups().add(g1);
authEntity.load(new TreeMap<>());
assertEquals(new TreeSet<>(Arrays.asList(new String[] { "group 1" })), authEntity.forGroups());
assertEquals(new TreeSet<>(), authEntity.forProjects());
}
Aggregations