Skip to content

Commit 7562bab

Browse files
authored
Merge pull request #1816 from vladak/repositories_add_historyguru
populate HistoryGuru repositories list from add project Message
2 parents 789b58e + 9f4fc5c commit 7562bab

File tree

14 files changed

+399
-247
lines changed

14 files changed

+399
-247
lines changed

src/org/opensolaris/opengrok/configuration/ConfigMerge.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
import java.lang.reflect.Method;
3232
import java.lang.reflect.Modifier;
3333
import java.text.ParseException;
34-
import java.util.logging.Level;
35-
import java.util.logging.Logger;
3634
import org.opensolaris.opengrok.util.Getopt;
3735

3836
/**
@@ -49,6 +47,7 @@ public class ConfigMerge {
4947
* Merge base and new configuration.
5048
* @param cfgBase base configuration
5149
* @param cfgNew new configuration, will receive properties from the base configuration
50+
* @throws Exception
5251
*/
5352
public static void merge(Configuration cfgBase, Configuration cfgNew) throws Exception {
5453
Configuration cfgDefault = new Configuration();

src/org/opensolaris/opengrok/configuration/Configuration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,13 @@ public final class Configuration {
114114
*/
115115
private int messageLimit;
116116
/**
117-
* Directory with authorization plugins. Default value is
118-
* dataRoot/../plugins (can be /var/opengrok/plugins if dataRoot is
119-
* /var/opengrok/data).
117+
* Directory with authorization plug-ins. Default value is
118+
* {@code dataRoot/../plugins} (can be {@code /var/opengrok/plugins} if dataRoot is
119+
* {@code /var/opengrok/data}).
120120
*/
121121
private String pluginDirectory;
122122
/**
123-
* Enable watching the plugin directory for changes in real time. Suitable
123+
* Enable watching the plug-in directory for changes in real time. Suitable
124124
* for development.
125125
*/
126126
private boolean authorizationWatchdogEnabled;
@@ -658,7 +658,7 @@ public String getDataRoot() {
658658
* @see #setPluginDirectory(java.lang.String)
659659
* @see #setStatisticsFilePath(java.lang.String)
660660
*
661-
* @param dataRoot
661+
* @param dataRoot data root path
662662
*/
663663
public void setDataRoot(String dataRoot) {
664664
if (dataRoot != null && getPluginDirectory() == null) {

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,14 +700,35 @@ public List<RepositoryInfo> getRepositories() {
700700
}
701701

702702
/**
703-
* Set the map of external SCM repositories
703+
* Set the list of repositories.
704704
*
705705
* @param repositories the repositories to use
706706
*/
707707
public void setRepositories(List<RepositoryInfo> repositories) {
708708
threadConfig.get().setRepositories(repositories);
709709
}
710+
711+
public void removeRepositories() {
712+
threadConfig.get().setRepositories(null);
713+
}
714+
715+
/**
716+
* Search through the directory for repositories and use the result to replace
717+
* the lists of repositories in both RuntimeEnvironment/Configuration and HistoryGuru.
718+
*
719+
* @param dir the root directory to start the search in
720+
*/
721+
public void setRepositories(String dir) {
722+
List<RepositoryInfo> repos = new ArrayList<>(HistoryGuru.getInstance().
723+
addRepositories(new File[]{new File(dir)},
724+
RuntimeEnvironment.getInstance().getIgnoredNames()));
725+
RuntimeEnvironment.getInstance().setRepositories(repos);
726+
}
710727

728+
/**
729+
* Add repositories to the list.
730+
* @param repositories
731+
*/
711732
public void addRepositories(List<RepositoryInfo> repositories) {
712733
threadConfig.get().addRepositories(repositories);
713734
}
@@ -1330,20 +1351,29 @@ public void setConfiguration(Configuration configuration) {
13301351

13311352
public void setConfiguration(Configuration configuration, List<String> subFileList) {
13321353
this.configuration = configuration;
1354+
HistoryGuru histGuru = HistoryGuru.getInstance();
1355+
13331356
register();
1357+
13341358
try {
13351359
generateProjectRepositoriesMap();
13361360
} catch (IOException ex) {
13371361
LOGGER.log(Level.SEVERE, "Cannot generate project - repository map", ex);
13381362
}
1363+
13391364
populateGroups(getGroups(), new TreeSet<>(getProjects().values()));
1365+
1366+
// Set the working repositories in HistoryGuru.
13401367
if (subFileList != null) {
1341-
HistoryGuru.getInstance().invalidateRepositories(
1368+
histGuru.invalidateRepositories(
13421369
configuration.getRepositories(), subFileList);
13431370
} else {
1344-
HistoryGuru.getInstance().invalidateRepositories(
1371+
histGuru.invalidateRepositories(
13451372
configuration.getRepositories());
13461373
}
1374+
// The invalidation of repositories above might have excluded some
1375+
// repositories in HistoryGuru so the configuration needs to reflect that.
1376+
configuration.setRepositories(new ArrayList<>(histGuru.getRepositories()));
13471377
}
13481378

13491379
public Configuration getConfiguration() {

src/org/opensolaris/opengrok/configuration/messages/ProjectMessage.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,18 @@ private void validateMore(RuntimeEnvironment env) throws Exception {
8787
}
8888
}
8989

90-
private List<RepositoryInfo> getRepositoriesInDir(RuntimeEnvironment env, File projDir) {
91-
List<RepositoryInfo> repos = new ArrayList<>();
92-
HistoryGuru hg = HistoryGuru.getInstance();
90+
private List<RepositoryInfo> getRepositoriesInDir(RuntimeEnvironment env,
91+
File projDir) {
92+
93+
HistoryGuru histGuru = HistoryGuru.getInstance();
9394

9495
// There is no need to perform the work of invalidateRepositories(),
9596
// since addRepositories() calls getRepository() for each of
9697
// the repos.
97-
hg.addRepositories(new File[]{projDir}, repos,
98-
env.getIgnoredNames());
99-
100-
return repos;
98+
return new ArrayList<>(histGuru.addRepositories(new File[]{projDir},
99+
env.getIgnoredNames()));
101100
}
102-
101+
103102
@Override
104103
protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
105104
String command = getText();
@@ -193,11 +192,7 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
193192
File.separator + projectName));
194193
}
195194
HistoryGuru guru = HistoryGuru.getInstance();
196-
// removeCache() for single repository would call
197-
// {@code invalidateRepositories()} on it which
198-
// would corrupt HistoryGuru's view of all repositories
199-
// so call clearCache() to avoid it.
200-
guru.clearCache(repos.stream().
195+
guru.removeCache(repos.stream().
201196
map((x) -> {
202197
try {
203198
return env.getPathRelativeToSourceRoot(
@@ -213,9 +208,6 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
213208
return "";
214209
}
215210
}).collect(Collectors.toSet()));
216-
217-
// Remove the repositories in the HistoryGuru.
218-
guru.removeRepositories(repos);
219211
}
220212
break;
221213
case "indexed":
@@ -245,7 +237,7 @@ protected byte[] applyMessage(RuntimeEnvironment env) throws Exception {
245237
}
246238
}
247239

248-
// In case this project has just been incremetally indexed,
240+
// In case this project has just been incrementally indexed,
249241
// its IndexSearcher needs a poke.
250242
env.maybeRefreshIndexSearchers(getTags());
251243

0 commit comments

Comments
 (0)