Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2021, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.analysis;
Expand Down Expand Up @@ -596,7 +596,7 @@ public void populateDocument(Document doc, File file, String path, AbstractAnaly
doc.add(new SortedDocValuesField(QueryBuilder.FULLPATH,
new BytesRef(file.getAbsolutePath())));

if (RuntimeEnvironment.getInstance().isHistoryEnabled()) {
if (HistoryGuru.getInstance().repositorySupportsHistory(file)) {
populateDocumentHistory(doc, file);
}
doc.add(new Field(QueryBuilder.DATE, date, string_ft_stored_nanalyzed_norms));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2020, Aleksandr Kirillov <[email protected]>.
*/
Expand Down Expand Up @@ -580,7 +580,7 @@ public Configuration() {
setHandleHistoryOfRenamedFiles(false);
setHistoryBasedReindex(true);
setHistoryCache(true);
setHistoryEnabled(true);
setHistoryEnabled(false);
setHitsPerPage(25);
setIgnoredNames(new IgnoredNames());
setIncludedNames(new Filter());
Expand Down Expand Up @@ -1610,37 +1610,4 @@ public ConfigurationException(String message) {
super(message);
}
}

/**
* Check if configuration is populated and self-consistent.
* @throws ConfigurationException on error
*/
public void checkConfiguration() throws ConfigurationException {

if (getSourceRoot() == null) {
throw new ConfigurationException("Source root is not specified.");
}

if (getDataRoot() == null) {
throw new ConfigurationException("Data root is not specified.");
}

if (!new File(getSourceRoot()).canRead()) {
throw new ConfigurationException("Source root directory '" + getSourceRoot() + "' must be readable.");
}

if (!new File(getDataRoot()).canWrite()) {
throw new ConfigurationException("Data root directory '" + getDataRoot() + "' must be writable.");
}

if (!isHistoryEnabled() && isHistoryBasedReindex()) {
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " +
"History has to be enabled for history based reindex.");
}

if (!isHistoryCache() && isHistoryBasedReindex()) {
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " +
"History cache has to be enabled for history based reindex.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, 2020, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.history;
Expand Down Expand Up @@ -54,7 +54,6 @@
import org.opengrok.indexer.analysis.AnalyzerFactory;
import org.opengrok.indexer.analysis.AnalyzerGuru;
import org.opengrok.indexer.configuration.CommandTimeoutType;
import org.opengrok.indexer.configuration.Configuration;
import org.opengrok.indexer.configuration.Configuration.RemoteSCM;
import org.opengrok.indexer.configuration.OpenGrokThreadFactory;
import org.opengrok.indexer.configuration.PathAccepter;
Expand Down Expand Up @@ -630,6 +629,14 @@ public boolean hasHistory(File file) {
}
}

return repositorySupportsHistory(file);
}

/**
* @param file file object
* @return whether related {@link Repository} and settings allow for history retrieval
*/
public boolean repositorySupportsHistory(File file) {
Repository repo = getRepository(file);
if (repo == null) {
LOGGER.finest(() -> String.format("cannot find repository for '%s' to check history presence",
Expand All @@ -642,7 +649,7 @@ public boolean hasHistory(File file) {
}

// This should return true for Annotate view.
Configuration.RemoteSCM globalRemoteSupport = env.getRemoteScmSupported();
RemoteSCM globalRemoteSupport = env.getRemoteScmSupported();
boolean remoteSupported = ((globalRemoteSupport == RemoteSCM.ON)
|| (globalRemoteSupport == RemoteSCM.UIONLY)
|| (globalRemoteSupport == RemoteSCM.DIRBASED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
*/

/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.history;

import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.VisibleForTesting;
import org.opengrok.indexer.configuration.RuntimeEnvironment;
import org.opengrok.indexer.index.IndexDatabase;
import org.opengrok.indexer.logger.LoggerFactory;
import org.opengrok.indexer.search.QueryBuilder;
Expand All @@ -52,11 +51,11 @@ private LatestRevisionUtil() {

/**
* @param file file object corresponding to a file under source root
* @return last revision string for {@code file} or null
* @return last revision string for {@code file} or {@code null}
*/
@Nullable
public static String getLatestRevision(File file) {
if (!RuntimeEnvironment.getInstance().isHistoryEnabled()) {
if (!HistoryGuru.getInstance().repositorySupportsHistory(file)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ public static int runMain(String[] argv) {
exitWithHelp();
}

checkConfiguration();

if (awaitProfiler) {
pauseToAwaitProfiler();
}
Expand Down Expand Up @@ -278,6 +276,8 @@ public static int runMain(String[] argv) {
}
}

checkConfiguration(cfg);

// Set updated configuration in RuntimeEnvironment. This is called so that the tunables set
// via command line options are available.
env.setConfiguration(cfg, subFilePaths, CommandTimeoutType.INDEXER);
Expand Down Expand Up @@ -494,11 +494,44 @@ private static void checkIndexAndExit(Set<String> subFileArgs) {
System.exit(0);
}

/**
* Check if configuration is populated and self-consistent.
* @throws Configuration.ConfigurationException on error
*/
public static void checkConfigurationValues(Configuration cfg) throws Configuration.ConfigurationException {

if (cfg.getSourceRoot() == null) {
throw new Configuration.ConfigurationException("Source root is not specified.");
}

if (cfg.getDataRoot() == null) {
throw new Configuration.ConfigurationException("Data root is not specified.");
}

if (!new File(cfg.getSourceRoot()).canRead()) {
throw new Configuration.ConfigurationException("Source root directory '" + cfg.getSourceRoot() + "' must be readable.");
}

if (!new File(cfg.getDataRoot()).canWrite()) {
throw new Configuration.ConfigurationException("Data root directory '" + cfg.getDataRoot() + "' must be writable.");
}

if (!cfg.isHistoryEnabled() && cfg.isHistoryBasedReindex()) {
LOGGER.log(Level.INFO, "History based reindex is on, however history is off. " +
"History has to be enabled for history based reindex.");
}

if (!cfg.isHistoryCache() && cfg.isHistoryBasedReindex()) {
LOGGER.log(Level.INFO, "History based reindex is on, however history cache is off. " +
"History cache has to be enabled for history based reindex.");
}
}

/**
* This is supposed to be run after {@link #parseOptions(String[])}.
* It will exit the program if there is some serious configuration (meaning {@link #cfg}) discrepancy.
*/
private static void checkConfiguration() {
private static void checkConfiguration(Configuration cfg) {
if (bareConfig && (env.getConfigURI() == null || env.getConfigURI().isEmpty())) {
die("Missing webappURI setting");
}
Expand All @@ -513,7 +546,7 @@ private static void checkConfiguration() {
}

try {
cfg.checkConfiguration();
checkConfigurationValues(cfg);
} catch (Configuration.ConfigurationException e) {
die(e.getMessage());
}
Expand Down Expand Up @@ -1026,8 +1059,6 @@ public static String[] parseOptions(String[] argv) throws ParseException {
cfg = new Configuration();
}

cfg.setHistoryEnabled(false); // force user to turn on history capture

argv = optParser.parse(argv);

return argv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.history;

Expand Down Expand Up @@ -61,6 +61,8 @@ void setUp() throws Exception {
repositories = new TestRepository();
repositories.create(getClass().getResource("/repositories"));

env.setHistoryEnabled(true);

// This needs to be set before the call to env.setRepositories() below as it instantiates HistoryGuru.
env.setAnnotationCacheEnabled(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2018, 2020, Chris Fraire <[email protected]>.
* Portions Copyright (c) 2020, 2023, Ric Harris <[email protected]>.
*/
Expand Down Expand Up @@ -55,6 +55,7 @@
import org.apache.commons.lang3.time.DateUtils;
import org.eclipse.jgit.api.Git;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
Expand Down Expand Up @@ -90,6 +91,12 @@ class FileHistoryCacheTest {
private boolean savedIsHandleHistoryOfRenamedFiles;
private boolean savedIsTagsEnabled;

@BeforeAll
static void setUpClass() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setHistoryEnabled(true);
}

/**
* Set up the test environment with repositories and a cache instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class HistoryGuruTest {
@BeforeAll
static void setUpClass() throws Exception {
env = RuntimeEnvironment.getInstance();
env.setHistoryEnabled(true);
env.setAnnotationCacheEnabled(true);
savedNestingMaximum = env.getNestingMaximum();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -108,6 +109,12 @@ private void setUpTestRepository() throws IOException, URISyntaxException {
repositoryRoot = new File(repository.getSourceRoot(), "mercurial");
}

@BeforeAll
static void setUpClass() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setHistoryEnabled(true);
}

@BeforeEach
void setup() throws IOException, URISyntaxException {
setUpTestRepository();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.index;

Expand All @@ -36,6 +36,7 @@
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand Down Expand Up @@ -81,6 +82,12 @@
class IndexerVsDeletedDocumentsTest {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();

@BeforeAll
static void setUpClass() {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setHistoryEnabled(true);
}

private static String getRandomString(int numChars) {
Random random = new Random();
final StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2010, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
* Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
*/
package org.opengrok.indexer.search.context;
Expand Down Expand Up @@ -64,9 +64,12 @@ class HistoryContextTest {

@BeforeAll
static void setUpClass() throws Exception {
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
env.setHistoryEnabled(true);

repositories = new TestRepository();
repositories.create(HistoryContextTest.class.getResource("/repositories"));
RuntimeEnvironment.getInstance().setRepositories(repositories.getSourceRoot());
env.setRepositories(repositories.getSourceRoot());
}

@AfterAll
Expand Down
Loading
Loading