Skip to content

Commit

Permalink
Adapt to Gerrit 2.12
Browse files Browse the repository at this point in the history
* need to move Gitblit's Lucene to 5.3.0 (which is what Gerrit
  provides).
* some other minor API adaptaions
* Gitblit 1.6.2 makes in a few places use of Apache Commons IOUtils,
  which Gerrit no longer provides: don't exclude it anymore from the
  shaded jar.
  • Loading branch information
tomaswolf committed Dec 27, 2015
1 parent 81643cc commit 50c0058
Show file tree
Hide file tree
Showing 9 changed files with 651 additions and 28 deletions.
4 changes: 2 additions & 2 deletions docu/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ with full SSO through Gerrit.

* License: [Apache Public License 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [Home page](https://github.com/tomaswolf/gerrit-gitblit-plugin)
* Installed plugin version: <em id='gerrit-gitblit-current-version'>2.11.3.162.3-SNAPSHOT</em> &mdash; <a id='gerrit-gitblit-version-check' style='display:none;' href='#'>Check for updates</a>
* Installed plugin version: <em id='gerrit-gitblit-current-version'>2.12.162.1-SNAPSHOT</em> &mdash; <a id='gerrit-gitblit-version-check' style='display:none;' href='#'>Check for updates</a>

For a list of contributors, see at [GitHub](https://github.com/tomaswolf/gerrit-gitblit-plugin/graphs/contributors).

Expand Down Expand Up @@ -82,7 +82,7 @@ Report bugs or make feature requests at the [GitHub issue tracker](https://githu

<hr style="color: #C0C0C0; background-color: #C0C0C0; border-color: #C0C0C0; height: 2px;" />
<div style="float:right;">
<a href="https://github.com/tomaswolf/gerrit-gitblit-plugin" target="_blank">GitBlit plugin 2.11.3.162.3-SNAPSHOT</a>
<a href="https://github.com/tomaswolf/gerrit-gitblit-plugin" target="_blank">GitBlit plugin 2.12.162.1-SNAPSHOT</a>
</div>

<script type="text/javascript" src="version_check.js"></script>
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
<artifactId>gitblit-plugin</artifactId>
<description>GitBlit for Gerrit integrated as a plugin</description>
<name>Gerrit - GitBlit Plugin</name>
<version>2.11.3.162.3-SNAPSHOT</version><!-- Gerrit API version followed by collapsed GitBlit version, followed by plugin version -->
<version>2.12.162.1-SNAPSHOT</version><!-- Gerrit API version followed by collapsed GitBlit version, followed by plugin version -->
<licenses>
<license>
<name>Apache License 2.0</name>
Expand All @@ -29,7 +29,7 @@ limitations under the License.
</licenses>
<properties>
<Gerrit-ApiType>plugin</Gerrit-ApiType>
<Gerrit-ApiVersion>2.11.3</Gerrit-ApiVersion>
<Gerrit-ApiVersion>2.12</Gerrit-ApiVersion>
<GitBlit-Version>1.6.2</GitBlit-Version>
<Wicket-Version>1.4.21</Wicket-Version>
<Dagger-Version>1.1.0</Dagger-Version>
Expand Down Expand Up @@ -189,11 +189,10 @@ limitations under the License.
<exclude>org.apache.sshd:*</exclude><!-- In Gerrit API. GitBlit 0.12.0, Gerrit 0.11.1-atlassian-1 -->
<exclude>org.apache.commons:commons-compress</exclude><!-- In Gerrit API. GitBlit 1.4.1, Gerrit 1.7 -->
<!-- We can't exclude org.apache.lucene:* because gitblit uses also lucene-memory and lucene-highlighter, which apparently are not in the Gerrit API -->
<exclude>org.apache.lucene:lucene-core</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 4.6.0 -->
<exclude>org.apache.lucene:lucene-analyzers-commons</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 4.6.0 -->
<exclude>org.apache.lucene:lucene-core</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 5.3.0 -->
<exclude>org.apache.lucene:lucene-analyzers-commons</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 5.3.0 -->
<exclude>org.apache.lucene:lucene-queries</exclude><!-- In Gerrit API. -->
<exclude>org.apache.lucene:lucene-queryparser</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 4.6.0 -->
<exclude>commons-io:commons-io</exclude><!-- In Gerrit API. GitBlit 2.2, Gerrit 1.4 -->
<exclude>org.apache.lucene:lucene-queryparser</exclude><!-- In Gerrit API. GitBlit 4.6.0, Gerrit 5.3.0 -->
<exclude>commons-codec:commons-codec</exclude><!-- In Gerrit API. GitBlit 1.7, Gerrit 1.4 -->
<exclude>org.tukaani:*</exclude><!-- In Gerrit API. GitBlit 1.0, Gerrit 1.4 -->
<exclude>com.toedter:*</exclude><!-- Used only in GitBlit client, which doesn't run -->
Expand Down Expand Up @@ -279,6 +278,8 @@ limitations under the License.
<exclude>com/gitblit/wicket/panels/HistoryPanel$*.class</exclude>
<exclude>com/gitblit/tickets/BranchTicketService.class</exclude>
<exclude>com/gitblit/tickets/BranchTicketService$*.class</exclude>
<exclude>com/gitblit/tickets/TicketIndexer.class</exclude>
<exclude>com/gitblit/tickets/TicketIndexer$*.class</exclude>
<exclude>com/gitblit/servlet/RawServlet.class</exclude>
<exclude>com/gitblit/servlet/RawServlet$*.class</exclude>
<exclude>com/gitblit/service/LuceneService.class</exclude>
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/com/gitblit/service/LuceneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
import org.apache.lucene.search.highlight.SimpleSpanFragmenter;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
Expand Down Expand Up @@ -124,8 +123,6 @@ public class LuceneService implements Runnable {
private static final String CONF_ALIAS = "aliases";
private static final String CONF_BRANCH = "branches";

private static final Version LUCENE_VERSION = Version.LUCENE_46;

private final Logger logger = LoggerFactory.getLogger(LuceneService.class);

private final IStoredSettings storedSettings;
Expand Down Expand Up @@ -260,7 +257,7 @@ public synchronized void close() {
// close all writers
for (String writer : writers.keySet()) {
try {
writers.get(writer).close(true);
writers.get(writer).close();
} catch (Throwable t) {
logger.error("Failed to close Lucene writer for " + writer, t);
}
Expand Down Expand Up @@ -703,8 +700,8 @@ public boolean deleteBlob(String repositoryName, String branch, String path) thr
String q = MessageFormat.format(pattern, SearchObjectType.blob.name(), branch, path);

BooleanQuery query = new BooleanQuery();
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
QueryParser qp = new QueryParser(LUCENE_VERSION, FIELD_SUMMARY, analyzer);
StandardAnalyzer analyzer = new StandardAnalyzer();
QueryParser qp = new QueryParser(FIELD_SUMMARY, analyzer);
query.add(qp.parse(q), Occur.MUST);

IndexWriter writer = getIndexWriter(repositoryName);
Expand Down Expand Up @@ -946,14 +943,14 @@ private IndexWriter getIndexWriter(String repository) throws IOException {
IndexWriter indexWriter = writers.get(repository);
File repositoryFolder = FileKey.resolve(new File(repositoriesFolder, repository), FS.DETECTED);
File indexFolder = new File(repositoryFolder, LUCENE_DIR);
Directory directory = FSDirectory.open(indexFolder);
Directory directory = FSDirectory.open(indexFolder.toPath());

if (indexWriter == null) {
if (!indexFolder.exists()) {
indexFolder.mkdirs();
}
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
IndexWriterConfig config = new IndexWriterConfig(LUCENE_VERSION, analyzer);
StandardAnalyzer analyzer = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
config.setOpenMode(OpenMode.CREATE_OR_APPEND);
indexWriter = new IndexWriter(directory, config);
writers.put(repository, indexWriter);
Expand Down Expand Up @@ -1004,16 +1001,16 @@ public List<SearchResult> search(String text, int page, int pageSize, String...
return null;
}
Set<SearchResult> results = new LinkedHashSet<SearchResult>();
StandardAnalyzer analyzer = new StandardAnalyzer(LUCENE_VERSION);
StandardAnalyzer analyzer = new StandardAnalyzer();
try {
// default search checks summary and content
BooleanQuery query = new BooleanQuery();
QueryParser qp;
qp = new QueryParser(LUCENE_VERSION, FIELD_SUMMARY, analyzer);
qp = new QueryParser(FIELD_SUMMARY, analyzer);
qp.setAllowLeadingWildcard(true);
query.add(qp.parse(text), Occur.SHOULD);

qp = new QueryParser(LUCENE_VERSION, FIELD_CONTENT, analyzer);
qp = new QueryParser(FIELD_CONTENT, analyzer);
qp.setAllowLeadingWildcard(true);
query.add(qp.parse(text), Occur.SHOULD);

Expand All @@ -1036,7 +1033,7 @@ public List<SearchResult> search(String text, int page, int pageSize, String...
Query rewrittenQuery = searcher.rewrite(query);
logger.debug(rewrittenQuery.toString());

TopScoreDocCollector collector = TopScoreDocCollector.create(5000, true);
TopScoreDocCollector collector = TopScoreDocCollector.create(5000);
searcher.search(rewrittenQuery, collector);
int offset = Math.max(0, (page - 1) * pageSize);
ScoreDoc[] hits = collector.topDocs(offset, pageSize).scoreDocs;
Expand Down Expand Up @@ -1199,7 +1196,7 @@ float duration() {
*/
private class MultiSourceReader extends MultiReader {

MultiSourceReader(IndexReader[] readers) {
MultiSourceReader(IndexReader[] readers) throws IOException {
super(readers, false);
}

Expand Down
Loading

0 comments on commit 50c0058

Please sign in to comment.