SOLR-13568: Precommit fail Java var until 9x. Fail var...

This commit is contained in:
Erick Erickson 2019-08-11 11:49:54 -04:00
parent 52f1108a0e
commit f6f1b4244c
3 changed files with 20 additions and 5 deletions

View File

@ -49,6 +49,13 @@ def invalidPatterns = [
(~$/import java\.lang\.\w+;/$) : 'java.lang import is unnecessary'
]
// Python and others merrily use var declarations, this is a problem _only_ in Java at least for 8x where we're forbidding var declarations
def invalidJavaOnlyPatterns = [
(~$/\n\s*var\s+.*=.*<>.*/$) : 'Diamond operators should not be used with var',
(~$/\n\s*var\s+/$) : 'var is not allowed in until we stop development on the 8x code line'
]
def baseDir = properties['basedir'];
def baseDirLen = baseDir.length() + 1;
@ -200,6 +207,11 @@ ant.fileScanner{
reportViolation(f, "Solr test cases should extend SolrTestCase rather than LuceneTestCase");
}
}
invalidJavaOnlyPatterns.each { pattern,name ->
if (pattern.matcher(text).find()) {
reportViolation(f, name);
}
}
}
if (f.name.endsWith('.xml') || f.name.endsWith('.xml.template')) {
checkLicenseHeaderPrecedes(f, '<tag>', xmlTagPattern, xmlCommentPattern, text, ratDocument);

View File

@ -166,6 +166,8 @@ Other Changes
* SOLR-13573: Add SolrRangeQuery getters for upper, lower bound (Brian Rhees via Jason Gerlowski)
* SOLR-13658: Precommit fail Java "var" until 9x. Fail "var...<>" constructs entirely (Erick Erickson)
================== 8.2.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -18,6 +18,7 @@ package org.apache.solr.client.solrj;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@ -688,15 +689,15 @@ abstract public class SolrExampleTests extends SolrExampleTestsBase
Assert.assertEquals(0, rsp.getResults().getNumFound());
ContentStreamUpdateRequest up = new ContentStreamUpdateRequest("/update");
var file = getFile("solrj/books.csv");
File file = getFile("solrj/books.csv");
final int opened[] = new int[] {0};
final int closed[] = new int[] {0};
var assertClosed = random().nextBoolean();
boolean assertClosed = random().nextBoolean();
if (assertClosed) {
var allBytes = Files.readAllBytes(file.toPath());
var contentStreamMock = new ContentStreamBase.ByteArrayStream(allBytes, "solrj/books.csv", "application/csv") {
byte[] allBytes = Files.readAllBytes(file.toPath());
ContentStreamBase.ByteArrayStream contentStreamMock = new ContentStreamBase.ByteArrayStream(allBytes, "solrj/books.csv", "application/csv") {
@Override
public InputStream getStream() throws IOException {
opened [0]++;