[BUILD] Check for tabs and nocommits in the code on validate

This commit adds checks for nocommit and tabs in the source code.
The task is executed during the validate phase and can be disabled via
`-Dvalidate.skip`
This commit is contained in:
Simon Willnauer 2014-06-12 10:22:34 +02:00
parent 56a264cf6d
commit 5575ba1a12
11 changed files with 149 additions and 140 deletions

View File

@ -197,19 +197,6 @@ def update_reference_docs(release_version, path='docs'):
pending_files.append(os.path.join(root, file_name))
return pending_files
# Checks all source files for //nocommit comments
def check_nocommits(path='src'):
pattern = re.compile(r'\bnocommit\b')
for root, _, file_names in os.walk(path):
for file_name in fnmatch.filter(file_names, '*.java'):
full_path = os.path.join(root, file_name)
line_number = 0
with open(full_path, 'r', encoding='utf-8') as current_file:
for line in current_file:
line_number = line_number + 1
if pattern.search(line):
raise RuntimeError('Found nocommit in %s line %s' % (full_path, line_number))
# Moves the pom.xml file from a snapshot to a release
def remove_maven_snapshot(pom, release):
pattern = '<version>%s-SNAPSHOT</version>' % (release)
@ -554,7 +541,6 @@ if __name__ == '__main__':
print('Preparing Release from branch [%s] running tests: [%s] dryrun: [%s]' % (src_branch, run_tests, dry_run))
print(' JAVA_HOME is [%s]' % JAVA_HOME)
print(' Running with maven command: [%s] ' % (MVN))
check_nocommits(path='src')
if build:
release_version = find_release_version(src_branch)
ensure_no_open_tickets(release_version)

30
pom.xml
View File

@ -526,6 +526,34 @@
</target>
</configuration>
</execution>
<execution>
<id>invalid-patterns</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target unless="${validate.skip}">
<pathconvert pathsep="${line.separator}" dirsep="/" property="validate.patternsFound" setonempty="false">
<fileset dir="${basedir}">
<include name="**/*.java"/>
<include name="**/*.py"/>
<include name="**/*.txt"/>
<include name="**/*.xml"/>
<include name="**/*.rb"/>
<include name="**/*.pl"/>
<exclude name="**/org/elasticsearch/cluster/routing/shard_routes.txt"/>
<or>
<containsregexp expression="\bno(n|)commit\b" casesensitive="no"/>
<containsregexp expression="\t" casesensitive="no"/>
</or>
</fileset>
<map from="${basedir}${file.separator}" to="* "/>
</pathconvert>
<fail if="validate.patternsFound">The following files contain tabs or nocommits:${line.separator}${validate.patternsFound}</fail>
</target>
</configuration>
</execution>
<execution>
<id>tests</id>
<phase>test</phase>
@ -643,7 +671,7 @@
<shadedPattern>org.elasticsearch.common.compress</shadedPattern>
</relocation>
<relocation>
<pattern>com.github.mustachejava</pattern>
<pattern>com.github.mustachejava</pattern>
<shadedPattern>org.elasticsearch.common.mustache</shadedPattern>
</relocation>
<relocation>

View File

@ -26,7 +26,7 @@ import org.elasticsearch.gateway.none.NoneGatewayAllocator;
/**
*/
public class ShardsAllocatorModule extends AbstractModule {
public static final String EVEN_SHARD_COUNT_ALLOCATOR_KEY = "even_shard";
public static final String BALANCED_ALLOCATOR_KEY = "balanced"; // default
@ -60,7 +60,7 @@ public class ShardsAllocatorModule extends AbstractModule {
bind(GatewayAllocator.class).to(gatewayAllocator).asEagerSingleton();
bind(ShardsAllocator.class).to(shardsAllocator).asEagerSingleton();
}
private Class<? extends ShardsAllocator> loadShardsAllocator(Settings settings) {
final Class<? extends ShardsAllocator> shardsAllocator;
final String type = settings.get(TYPE_KEY, BALANCED_ALLOCATOR_KEY);

View File

@ -39,76 +39,76 @@ import java.util.concurrent.TimeoutException;
* <li>Barrier as a trigger for elapsed notification events </li>
* <p/>
* <pre>
* class MyTestClass implements RemoteEventListener
* class MyTestClass implements RemoteEventListener
* {
* final ThreadBarrier barrier;
* final ThreadBarrier barrier;
*
* class Worker implements Runnable
* class Worker implements Runnable
* {
* public void run()
* public void run()
* {
* barrier.await(); //wait for all threads to reach run
* try
* barrier.await(); //wait for all threads to reach run
* try
* {
* prepare();
* barrier.await(); //wait for all threads to prepare
* process();
* barrier.await(); //wait for all threads to process
* prepare();
* barrier.await(); //wait for all threads to prepare
* process();
* barrier.await(); //wait for all threads to process
* }
* catch(Throwable t){
* log(&quot;Worker thread caught exception&quot;, t);
* barrier.reset(t);
* catch(Throwable t){
* log(&quot;Worker thread caught exception&quot;, t);
* barrier.reset(t);
* }
* }
* }
*
* public void testThreads() {
* barrier = new ThreadBarrier(N_THREADS + 1);
* for (int i = 0; i &lt; N; ++i)
* public void testThreads() {
* barrier = new ThreadBarrier(N_THREADS + 1);
* for (int i = 0; i &lt; N; ++i)
* new Thread(new Worker()).start();
*
* try{
* barrier.await(); //wait for all threads to reach run
* barrier.await(); //wait for all threads to prepare
* barrier.await(); //wait for all threads to process
* try{
* barrier.await(); //wait for all threads to reach run
* barrier.await(); //wait for all threads to prepare
* barrier.await(); //wait for all threads to process
* }
* catch(BrokenBarrierException bbe) {
* Assert.fail(bbe);
* catch(BrokenBarrierException bbe) {
* Assert.fail(bbe);
* }
* }
*
* int actualNotificationCount = 0;
* public synchronized void notify (RemoteEvent event) {
* try{
* actualNotificationCount++;
* if (actualNotificationCount == EXPECTED_COUNT)
* barrier.await(); //signal when all notifications arrive
* public synchronized void notify (RemoteEvent event) {
* try{
* actualNotificationCount++;
* if (actualNotificationCount == EXPECTED_COUNT)
* barrier.await(); //signal when all notifications arrive
*
* // too many notifications?
* Assert.assertFalse(&quot;Exceeded notification count&quot;,
* actualNotificationCount > EXPECTED_COUNT);
* // too many notifications?
* Assert.assertFalse(&quot;Exceeded notification count&quot;,
* actualNotificationCount > EXPECTED_COUNT);
* }
* catch(Throwable t) {
* log(&quot;Worker thread caught exception&quot;, t);
* barrier.reset(t);
* catch(Throwable t) {
* log(&quot;Worker thread caught exception&quot;, t);
* barrier.reset(t);
* }
* }
*
* public void testNotify() {
* barrier = new ThreadBarrier(N_LISTENERS + 1);
* registerNotification();
* triggerNotifications();
* public void testNotify() {
* barrier = new ThreadBarrier(N_LISTENERS + 1);
* registerNotification();
* triggerNotifications();
*
* //wait until either all notifications arrive, or
* //until a MAX_TIMEOUT is reached.
* barrier.await(MAX_TIMEOUT);
* //wait until either all notifications arrive, or
* //until a MAX_TIMEOUT is reached.
* barrier.await(MAX_TIMEOUT);
*
* //check if all notifications were accounted for or timed-out
* Assert.assertEquals(&quot;Notification count&quot;,
* EXPECTED_COUNT, actualNotificationCount);
* //check if all notifications were accounted for or timed-out
* Assert.assertEquals(&quot;Notification count&quot;,
* EXPECTED_COUNT, actualNotificationCount);
*
* //inspect that the barrier isn't broken
* barrier.inspect(); //throws BrokenBarrierException if broken
* //inspect that the barrier isn't broken
* barrier.inspect(); //throws BrokenBarrierException if broken
* }
* }
* </pre>
@ -255,7 +255,7 @@ public class ThreadBarrier extends CyclicBarrier {
* ..
* long time = timer.getTimeInNanos();
* long tpi = time / ((long)nREPEATS * nTHREADS); //throughput per thread iteration
* long secs = timer.getTimeInSeconds(); //total runtime in seconds
* long secs = timer.getTimeInSeconds(); //total runtime in seconds
* ..
* timer.reset(); // reuse timer
* </code></pre>

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.analysis;
import org.apache.lucene.analysis.th.ThaiAnalyzer;
import org.apache.lucene.analysis.util.CharArraySet;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.inject.assistedinject.Assisted;
import org.elasticsearch.common.settings.Settings;
@ -38,7 +37,7 @@ public class ThaiAnalyzerProvider extends AbstractIndexAnalyzerProvider<ThaiAnal
@Inject
public ThaiAnalyzerProvider(Index index, @IndexSettings Settings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) {
super(index, indexSettings, name, settings);
analyzer = new ThaiAnalyzer(version, Analysis.parseStopWords(env, settings, ThaiAnalyzer.getDefaultStopSet(), version));
analyzer = new ThaiAnalyzer(version, Analysis.parseStopWords(env, settings, ThaiAnalyzer.getDefaultStopSet(), version));
}
@Override

View File

@ -27,17 +27,15 @@ import java.util.List;
/**
* A filter that matches documents matching boolean combinations of other filters.
*
*
*/
public class BoolFilterBuilder extends BaseFilterBuilder {
private ArrayList<FilterBuilder> mustClauses = new ArrayList<>();
private ArrayList<FilterBuilder> mustNotClauses = new ArrayList<>();
private ArrayList<FilterBuilder> shouldClauses = new ArrayList<>();
private Boolean cache;
private String cacheKey;
@ -47,27 +45,27 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
* Adds a filter that <b>must</b> appear in the matching documents.
*/
public BoolFilterBuilder must(FilterBuilder filterBuilder) {
mustClauses.add(filterBuilder);
return this;
mustClauses.add(filterBuilder);
return this;
}
/**
* Adds a filter that <b>must not</b> appear in the matching documents.
*/
public BoolFilterBuilder mustNot(FilterBuilder filterBuilder) {
mustNotClauses.add(filterBuilder);
return this;
mustNotClauses.add(filterBuilder);
return this;
}
/**
* Adds a filter that <i>should</i> appear in the matching documents. For a boolean filter
* with no <tt>MUST</tt> clauses one or more <code>SHOULD</code> clauses must match a document
* for the BooleanQuery to match.
*/
public BoolFilterBuilder should(FilterBuilder filterBuilder) {
shouldClauses.add(filterBuilder);
return this;
shouldClauses.add(filterBuilder);
return this;
}
/**
@ -75,7 +73,7 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
*/
public BoolFilterBuilder must(FilterBuilder... filterBuilders) {
for (FilterBuilder fb : filterBuilders) {
mustClauses.add(fb);
mustClauses.add(fb);
}
return this;
}
@ -85,7 +83,7 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
*/
public BoolFilterBuilder mustNot(FilterBuilder... filterBuilders) {
for (FilterBuilder fb : filterBuilders) {
mustNotClauses.add(fb);
mustNotClauses.add(fb);
}
return this;
}
@ -95,7 +93,7 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
*/
public BoolFilterBuilder should(FilterBuilder... filterBuilders) {
for (FilterBuilder fb : filterBuilders) {
shouldClauses.add(fb);
shouldClauses.add(fb);
}
return this;
}
@ -107,7 +105,7 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
public boolean hasClauses() {
return !(mustClauses.isEmpty() && shouldClauses.isEmpty() && mustNotClauses.isEmpty());
}
/**
* Sets the filter name for the filter that can be used when searching for matched_filters per hit.
*/
@ -135,7 +133,7 @@ public class BoolFilterBuilder extends BaseFilterBuilder {
doXArrayContent("must", mustClauses, builder, params);
doXArrayContent("must_not", mustNotClauses, builder, params);
doXArrayContent("should", shouldClauses, builder, params);
if (filterName != null) {
builder.field("_name", filterName);
}

View File

@ -47,7 +47,7 @@ public abstract class QueryBuilders {
public static MatchQueryBuilder matchQuery(String name, Object text) {
return new MatchQueryBuilder(name, text).type(MatchQueryBuilder.Type.BOOLEAN);
}
/**
* Creates a common query for the provided field name and text.
*
@ -62,7 +62,7 @@ public abstract class QueryBuilders {
* Creates a match query with type "BOOLEAN" for the provided field name and text.
*
* @param fieldNames The field names.
* @param text The query text (to be analyzed).
* @param text The query text (to be analyzed).
*/
public static MultiMatchQueryBuilder multiMatchQuery(Object text, String... fieldNames) {
return new MultiMatchQueryBuilder(text, fieldNames); // BOOLEAN is the default
@ -359,19 +359,19 @@ public abstract class QueryBuilders {
public static SpanOrQueryBuilder spanOrQuery() {
return new SpanOrQueryBuilder();
}
/**
* Creates a {@link SpanQueryBuilder} which allows having a sub query
* which implements {@link MultiTermQueryBuilder}. This is useful for
* having e.g. wildcard or fuzzy queries inside spans.
*
* @param multiTermQueryBuilder The {@link MultiTermQueryBuilder} that
* backs the created builder.
*
* @param multiTermQueryBuilder The {@link MultiTermQueryBuilder} that
* backs the created builder.
* @return
*/
public static SpanMultiTermQueryBuilder spanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder){
return new SpanMultiTermQueryBuilder(multiTermQueryBuilder);
public static SpanMultiTermQueryBuilder spanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) {
return new SpanMultiTermQueryBuilder(multiTermQueryBuilder);
}
public static FieldMaskingSpanQueryBuilder fieldMaskingSpanQuery(SpanQueryBuilder query, String field) {
@ -408,7 +408,7 @@ public abstract class QueryBuilders {
public static ConstantScoreQueryBuilder constantScoreQuery(FilterBuilder filterBuilder) {
return new ConstantScoreQueryBuilder(filterBuilder);
}
/**
* A query that wraps another query and simply returns a constant score equal to the
* query boost for every document in the query.
@ -427,15 +427,14 @@ public abstract class QueryBuilders {
public static FunctionScoreQueryBuilder functionScoreQuery(QueryBuilder queryBuilder) {
return new FunctionScoreQueryBuilder(queryBuilder);
}
/**
* A query that allows to define a custom scoring function.
*
*/
public static FunctionScoreQueryBuilder functionScoreQuery() {
return new FunctionScoreQueryBuilder();
}
/**
* A query that allows to define a custom scoring function.
*
@ -444,27 +443,27 @@ public abstract class QueryBuilders {
public static FunctionScoreQueryBuilder functionScoreQuery(ScoreFunctionBuilder function) {
return new FunctionScoreQueryBuilder(function);
}
/**
* A query that allows to define a custom scoring function.
*
* @param queryBuilder The query to custom score
* @param function The function builder used to custom score
* @param function The function builder used to custom score
*/
public static FunctionScoreQueryBuilder functionScoreQuery(QueryBuilder queryBuilder, ScoreFunctionBuilder function) {
return (new FunctionScoreQueryBuilder(queryBuilder)).add(function);
}
/**
* A query that allows to define a custom scoring function.
*
* @param filterBuilder The query to custom score
* @param function The function builder used to custom score
* @param function The function builder used to custom score
*/
public static FunctionScoreQueryBuilder functionScoreQuery(FilterBuilder filterBuilder, ScoreFunctionBuilder function) {
return (new FunctionScoreQueryBuilder(filterBuilder)).add(function);
}
/**
* A query that allows to define a custom scoring function.
*
@ -473,6 +472,7 @@ public abstract class QueryBuilders {
public static FunctionScoreQueryBuilder functionScoreQuery(FilterBuilder filterBuilder) {
return new FunctionScoreQueryBuilder(filterBuilder);
}
/**
* A more like this query that finds documents that are "like" the provided {@link MoreLikeThisQueryBuilder#likeText(String)}
* which is checked against the fields the query is constructed with.
@ -732,7 +732,7 @@ public abstract class QueryBuilders {
* Query that matches Documents based on the relationship between the given shape and
* indexed shapes
*
* @param name The shape field name
* @param name The shape field name
* @param shape Shape to use in the Query
*/
public static GeoShapeQueryBuilder geoShapeQuery(String name, ShapeBuilder shape) {

View File

@ -18,28 +18,28 @@
*/
package org.elasticsearch.index.query;
import java.io.IOException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import java.io.IOException;
/**
*
*/
public class SpanMultiTermQueryBuilder extends BaseQueryBuilder implements SpanQueryBuilder{
public class SpanMultiTermQueryBuilder extends BaseQueryBuilder implements SpanQueryBuilder {
private MultiTermQueryBuilder multiTermQueryBuilder;
public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) {
this.multiTermQueryBuilder = multiTermQueryBuilder;
}
private MultiTermQueryBuilder multiTermQueryBuilder;
@Override
protected void doXContent(XContentBuilder builder, Params params)
throws IOException {
public SpanMultiTermQueryBuilder(MultiTermQueryBuilder multiTermQueryBuilder) {
this.multiTermQueryBuilder = multiTermQueryBuilder;
}
@Override
protected void doXContent(XContentBuilder builder, Params params)
throws IOException {
builder.startObject(SpanMultiTermQueryParser.NAME);
builder.field(SpanMultiTermQueryParser.MATCH_NAME);
multiTermQueryBuilder.toXContent(builder, params);
builder.endObject();
}
builder.endObject();
}
}

View File

@ -18,40 +18,39 @@
*/
package org.elasticsearch.index.query;
import java.io.IOException;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParser.Token;
import java.io.IOException;
/**
*
*/
public class SpanMultiTermQueryParser implements QueryParser {
public static final String NAME = "span_multi";
public static final String MATCH_NAME = "match";
public static final String NAME = "span_multi";
public static final String MATCH_NAME = "match";
@Inject
public SpanMultiTermQueryParser() {
}
@Inject
public SpanMultiTermQueryParser() {
}
@Override
public String[] names() {
return new String[] { NAME, Strings.toCamelCase(NAME) };
}
@Override
public String[] names() {
return new String[]{NAME, Strings.toCamelCase(NAME)};
}
@Override
@Override
public Query parse(QueryParseContext parseContext) throws IOException, QueryParsingException {
XContentParser parser = parseContext.parser();
Token token = parser.nextToken();
if (!MATCH_NAME.equals(parser.currentName()) || token != XContentParser.Token.FIELD_NAME) {
if (!MATCH_NAME.equals(parser.currentName()) || token != XContentParser.Token.FIELD_NAME) {
throw new QueryParsingException(parseContext.index(), "spanMultiTerm must have [" + MATCH_NAME + "] multi term query clause");
}

View File

@ -35,10 +35,10 @@ import java.util.Map;
/**
* This mapper add a new sub fields
* .bin Binary type
* .bool Boolean type
* .point GeoPoint type
* .shape GeoShape type
* .bin Binary type
* .bool Boolean type
* .point GeoPoint type
* .shape GeoShape type
*/
public class ExternalMapper implements Mapper {
public static class Names {
@ -175,14 +175,14 @@ public class ExternalMapper implements Mapper {
@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject(name);
builder.field("type", RegisterExternalTypes.EXTERNAL);
builder.startObject("fields");
binMapper.toXContent(builder, params);
boolMapper.toXContent(builder, params);
pointMapper.toXContent(builder, params);
shapeMapper.toXContent(builder, params);
builder.endObject();
builder.field("type", RegisterExternalTypes.EXTERNAL);
builder.startObject("fields");
binMapper.toXContent(builder, params);
boolMapper.toXContent(builder, params);
pointMapper.toXContent(builder, params);
shapeMapper.toXContent(builder, params);
builder.endObject();
builder.endObject();
return builder;
}

View File

@ -164,7 +164,6 @@ import static org.hamcrest.Matchers.equalTo;
@AbstractRandomizedTest.IntegrationTests
public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase {
private static ImmutableTestCluster GLOBAL_CLUSTER;
/**
* Key used to set the transport client ratio via the commandline -D{@value #TESTS_CLIENT_RATIO}
*/