Absorb ImmutableSettings into Settings; fix other pre-existing compilation issues, but there are still forbidden API failures

This commit is contained in:
Michael McCandless 2015-05-26 09:25:44 -04:00 committed by mikemccand
parent 7263437ca5
commit 2da374f39d
9 changed files with 62 additions and 67 deletions

View File

@ -28,7 +28,7 @@ import org.apache.tika.metadata.Metadata;
import org.elasticsearch.Version;
import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.collect.Lists;
import org.elasticsearch.common.io.stream.BytesStreamInput;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.settings.Settings;
@ -68,7 +68,7 @@ import static org.elasticsearch.plugin.mapper.attachments.tika.TikaInstance.tika
* _content_length = Specify the maximum amount of characters to extract from the attachment. If not specified, then the default for
* tika is 100,000 characters. Caution is required when setting large values as this can cause memory issues.
*/
public class AttachmentMapper extends AbstractFieldMapper<Object> {
public class AttachmentMapper extends AbstractFieldMapper {
private static ESLogger logger = ESLoggerFactory.getLogger("mapper.attachment");
@ -179,7 +179,7 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
ContentPath.Type origPathType = context.path().pathType();
context.path().pathType(pathType);
FieldMapper<?> contentMapper;
FieldMapper contentMapper;
if (context.indexCreatedVersion().before(Version.V_2_0_0)) {
// old behavior, we need the content to be indexed under the attachment field name
if (contentBuilder instanceof AbstractFieldMapper.Builder == false) {
@ -187,21 +187,21 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
}
((AbstractFieldMapper.Builder)contentBuilder).indexName(name);
contentBuilder.name = name + "." + FieldNames.CONTENT;
contentMapper = (FieldMapper<?>) contentBuilder.build(context);
contentMapper = (FieldMapper) contentBuilder.build(context);
context.path().add(name);
} else {
context.path().add(name);
contentMapper = (FieldMapper<?>) contentBuilder.build(context);
contentMapper = (FieldMapper) contentBuilder.build(context);
}
FieldMapper<?> dateMapper = (FieldMapper<?>) dateBuilder.build(context);
FieldMapper<?> authorMapper = (FieldMapper<?>) authorBuilder.build(context);
FieldMapper<?> titleMapper = (FieldMapper<?>) titleBuilder.build(context);
FieldMapper<?> nameMapper = (FieldMapper<?>) nameBuilder.build(context);
FieldMapper<?> keywordsMapper = (FieldMapper<?>) keywordsBuilder.build(context);
FieldMapper<?> contentTypeMapper = (FieldMapper<?>) contentTypeBuilder.build(context);
FieldMapper<?> contentLength = (FieldMapper<?>) contentLengthBuilder.build(context);
FieldMapper<?> language = (FieldMapper<?>) languageBuilder.build(context);
FieldMapper dateMapper = (FieldMapper) dateBuilder.build(context);
FieldMapper authorMapper = (FieldMapper) authorBuilder.build(context);
FieldMapper titleMapper = (FieldMapper) titleBuilder.build(context);
FieldMapper nameMapper = (FieldMapper) nameBuilder.build(context);
FieldMapper keywordsMapper = (FieldMapper) keywordsBuilder.build(context);
FieldMapper contentTypeMapper = (FieldMapper) contentTypeBuilder.build(context);
FieldMapper contentLength = (FieldMapper) contentLengthBuilder.build(context);
FieldMapper language = (FieldMapper) languageBuilder.build(context);
context.path().remove();
context.path().pathType(origPathType);
@ -353,29 +353,29 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
private final boolean defaultLangDetect;
private final FieldMapper<?> contentMapper;
private final FieldMapper contentMapper;
private final FieldMapper<?> dateMapper;
private final FieldMapper dateMapper;
private final FieldMapper<?> authorMapper;
private final FieldMapper authorMapper;
private final FieldMapper<?> titleMapper;
private final FieldMapper titleMapper;
private final FieldMapper<?> nameMapper;
private final FieldMapper nameMapper;
private final FieldMapper<?> keywordsMapper;
private final FieldMapper keywordsMapper;
private final FieldMapper<?> contentTypeMapper;
private final FieldMapper contentTypeMapper;
private final FieldMapper<?> contentLengthMapper;
private final FieldMapper contentLengthMapper;
private final FieldMapper<?> languageMapper;
private final FieldMapper languageMapper;
public AttachmentMapper(Names names, ContentPath.Type pathType, int defaultIndexedChars, Boolean ignoreErrors,
Boolean defaultLangDetect, FieldMapper<?> contentMapper,
FieldMapper<?> dateMapper, FieldMapper<?> titleMapper, FieldMapper<?> nameMapper, FieldMapper<?> authorMapper,
FieldMapper<?> keywordsMapper, FieldMapper<?> contentTypeMapper, FieldMapper<?> contentLengthMapper,
FieldMapper<?> languageMapper, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
Boolean defaultLangDetect, FieldMapper contentMapper,
FieldMapper dateMapper, FieldMapper titleMapper, FieldMapper nameMapper, FieldMapper authorMapper,
FieldMapper keywordsMapper, FieldMapper contentTypeMapper, FieldMapper contentLengthMapper,
FieldMapper languageMapper, Settings indexSettings, MultiFields multiFields, CopyTo copyTo) {
super(names, 1.0f, AbstractFieldMapper.Defaults.FIELD_TYPE, false, null, null, null, null, null,
indexSettings, multiFields, copyTo);
this.pathType = pathType;
@ -476,7 +476,7 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
}
}
// Set the maximum length of strings returned by the parseToString method, -1 sets no limit
parsedContent = tika.parseToString(new BytesStreamInput(content), metadata, indexedChars);
parsedContent = tika.parseToString(StreamInput.wrap(content), metadata, indexedChars);
} catch (Throwable e) {
// It could happen that Tika adds a System property `sun.font.fontmanager` which should not happen
// TODO Remove when this will be fixed in Tika. See https://issues.apache.org/jira/browse/TIKA-1548
@ -611,7 +611,7 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
@Override
public Iterator<Mapper> iterator() {
List<FieldMapper<?>> extras = Lists.newArrayList(
List<FieldMapper> extras = Lists.newArrayList(
contentMapper,
dateMapper,
titleMapper,
@ -642,7 +642,7 @@ public class AttachmentMapper extends AbstractFieldMapper<Object> {
builder.startObject(name());
builder.field("type", CONTENT_TYPE);
if (indexCreatedBefore2x) {
builder.field("path", pathType.name().toLowerCase());
builder.field("path", pathType.name().toLowerCase(Locale.ROOT));
}
builder.startObject("fields");

View File

@ -24,7 +24,6 @@ import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.inject.Injector;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsModule;
import org.elasticsearch.env.Environment;
@ -54,7 +53,7 @@ import static org.elasticsearch.plugin.mapper.attachments.tika.LocaleChecker.isL
public class MapperTestUtils {
public static MapperService newMapperService(Path tempDir, ThreadPool testingThreadPool) {
return newMapperService(new Index("test"), ImmutableSettings.builder()
return newMapperService(new Index("test"), Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put("path.home", tempDir)
.build(), testingThreadPool);
@ -65,8 +64,8 @@ public class MapperTestUtils {
return new MapperService(index,
indexSettings,
newAnalysisService(indexSettings),
new IndexFieldDataService(index, ImmutableSettings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCache(ImmutableSettings.Builder.EMPTY_SETTINGS,
new IndexFieldDataService(index, Settings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCache(Settings.Builder.EMPTY_SETTINGS,
new IndicesFieldDataCacheListener(circuitBreakerService),
testingThreadPool),
circuitBreakerService),
@ -75,7 +74,7 @@ public class MapperTestUtils {
}
public static AnalysisService newAnalysisService(Path tempDir) {
return newAnalysisService(ImmutableSettings.builder()
return newAnalysisService(Settings.builder()
.put("path.home", tempDir)
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.build());
@ -97,13 +96,13 @@ public class MapperTestUtils {
}
public static DocumentMapperParser newMapperParser(Path tempDir) {
return newMapperParser(ImmutableSettings.builder()
return newMapperParser(Settings.builder()
.put("path.home", tempDir)
.build());
}
public static DocumentMapperParser newMapperParser(Settings settings) {
Settings forcedSettings = ImmutableSettings.builder()
Settings forcedSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
.put(settings)
.build();

View File

@ -20,7 +20,6 @@
package org.elasticsearch.index.mapper.attachment.test.integration;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.MapperParsingException;
import org.elasticsearch.plugins.PluginsService;
@ -29,7 +28,7 @@ import org.junit.Test;
import static org.elasticsearch.client.Requests.putMappingRequest;
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery;
import static org.hamcrest.Matchers.equalTo;
@ -42,7 +41,7 @@ public class EncryptedAttachmentIntegrationTests extends AttachmentIntegrationTe
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return ImmutableSettings.builder()
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true)
.build();

View File

@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper.attachment.test.integration;
import org.elasticsearch.action.count.CountResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.text.Text;
import org.elasticsearch.index.mapper.MapperParsingException;
@ -47,7 +46,7 @@ public class SimpleAttachmentIntegrationTests extends AttachmentIntegrationTestC
@Override
protected Settings nodeSettings(int nodeOrdinal) {
return ImmutableSettings.builder()
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put("plugins." + PluginsService.LOAD_PLUGIN_FROM_CLASSPATH, true)
.build();

View File

@ -21,7 +21,6 @@ package org.elasticsearch.index.mapper.attachment.test.unit;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Before;
@ -43,7 +42,7 @@ public class AttachmentUnitTestCase extends ElasticsearchTestCase {
@Before
public void createSettings() throws Exception {
testSettings = ImmutableSettings.builder()
testSettings = Settings.builder()
.put("path.home", createTempDir())
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT.id)
.build();

View File

@ -20,7 +20,7 @@
package org.elasticsearch.index.mapper.attachment.test.unit;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.MapperParsingException;
@ -110,7 +110,7 @@ public class EncryptedDocMapperTest extends AttachmentUnitTestCase {
@Test(expected = MapperParsingException.class)
public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
ImmutableSettings.builder()
Settings.builder()
.put("path.home", createTempDir())
.put("index.mapping.attachment.ignore_errors", false)
.build());

View File

@ -1,11 +1,11 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ -19,7 +19,7 @@
package org.elasticsearch.index.mapper.attachment.test.unit;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
@ -52,7 +52,7 @@ public class LanguageDetectionAttachmentMapperTests extends AttachmentUnitTestCa
public void setupMapperParser(boolean langDetect) throws IOException {
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(
ImmutableSettings.settingsBuilder()
Settings.settingsBuilder()
.put("path.home", createTempDir())
.put("index.mapping.attachment.detect_language", langDetect)
.build());

View File

@ -22,7 +22,6 @@ package org.elasticsearch.index.mapper.attachment.test.unit;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
@ -45,7 +44,7 @@ import static org.hamcrest.Matchers.*;
public class MetadataMapperTest extends AttachmentUnitTestCase {
protected void checkMeta(String filename, Settings otherSettings, Long expectedDate, Long expectedLength) throws IOException {
Settings settings = ImmutableSettings.builder()
Settings settings = Settings.builder()
.put(this.testSettings)
.put(otherSettings)
.build();
@ -81,31 +80,31 @@ public class MetadataMapperTest extends AttachmentUnitTestCase {
@Test
public void testIgnoreWithoutDate() throws Exception {
checkMeta("htmlWithoutDateMeta.html", ImmutableSettings.builder().build(), null, 300L);
checkMeta("htmlWithoutDateMeta.html", Settings.builder().build(), null, 300L);
}
@Test
public void testIgnoreWithEmptyDate() throws Exception {
checkMeta("htmlWithEmptyDateMeta.html", ImmutableSettings.builder().build(), null, 334L);
checkMeta("htmlWithEmptyDateMeta.html", Settings.builder().build(), null, 334L);
}
@Test
public void testIgnoreWithCorrectDate() throws Exception {
checkMeta("htmlWithValidDateMeta.html", ImmutableSettings.builder().build(), 1354233600000L, 344L);
checkMeta("htmlWithValidDateMeta.html", Settings.builder().build(), 1354233600000L, 344L);
}
@Test
public void testWithoutDate() throws Exception {
checkMeta("htmlWithoutDateMeta.html", ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, 300L);
checkMeta("htmlWithoutDateMeta.html", Settings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, 300L);
}
@Test(expected = MapperParsingException.class)
public void testWithEmptyDate() throws Exception {
checkMeta("htmlWithEmptyDateMeta.html", ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, null);
checkMeta("htmlWithEmptyDateMeta.html", Settings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, null);
}
@Test
public void testWithCorrectDate() throws Exception {
checkMeta("htmlWithValidDateMeta.html", ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(), 1354233600000L, 344L);
checkMeta("htmlWithValidDateMeta.html", Settings.builder().put("index.mapping.attachment.ignore_errors", false).build(), 1354233600000L, 344L);
}
}

View File

@ -22,7 +22,7 @@ package org.elasticsearch.index.mapper.attachment.test.unit;
import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.DocumentMapper;
import org.elasticsearch.index.mapper.DocumentMapperParser;
import org.elasticsearch.index.mapper.ParseContext;
@ -71,7 +71,7 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
}
public void testContentBackcompat() throws Exception {
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(ImmutableSettings.builder()
DocumentMapperParser mapperParser = MapperTestUtils.newMapperParser(Settings.builder()
.put("path.home", createTempDir())
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_1_4_2.id)
.build());