From 48133ed363971104af4f085c8525cba73700b108 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Mon, 21 Jan 2013 19:13:43 +0000 Subject: [PATCH] make 4.1 codec read-only and add impersonator for testing git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1436558 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/codecs/lucene41/Lucene41Codec.java | 22 +++++++++++-- .../codecs/lucene41/Lucene41RWCodec.java | 32 +++++++++++++++++++ .../lucene/codecs/lucene41/package.html | 25 +++++++++++++++ .../services/org.apache.lucene.codecs.Codec | 1 + 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java create mode 100644 lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/package.html diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java index 6817a930b95..fc517b70158 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java @@ -17,6 +17,8 @@ package org.apache.lucene.codecs.lucene41; * limitations under the License. */ +import java.io.IOException; + import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.FieldInfosFormat; import org.apache.lucene.codecs.FilterCodec; @@ -26,13 +28,19 @@ import org.apache.lucene.codecs.SegmentInfoFormat; import org.apache.lucene.codecs.DocValuesFormat; import org.apache.lucene.codecs.NormsFormat; import org.apache.lucene.codecs.StoredFieldsFormat; +import org.apache.lucene.codecs.StoredFieldsWriter; import org.apache.lucene.codecs.TermVectorsFormat; +import org.apache.lucene.codecs.compressing.CompressingStoredFieldsFormat; +import org.apache.lucene.codecs.compressing.CompressionMode; import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosFormat; import org.apache.lucene.codecs.lucene40.Lucene40LiveDocsFormat; import org.apache.lucene.codecs.lucene40.Lucene40SegmentInfoFormat; import org.apache.lucene.codecs.lucene40.Lucene40TermVectorsFormat; import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat; import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat; +import org.apache.lucene.index.SegmentInfo; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IOContext; /** * Implements the Lucene 4.1 index format, with configurable per-field postings formats. @@ -41,11 +49,18 @@ import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat; * {@link FilterCodec}. * * @see org.apache.lucene.codecs.lucene41 package documentation for file format details. + * @deprecated Only for reading old 4.0 segments * @lucene.experimental */ -// nocommit: make readonly +@Deprecated public class Lucene41Codec extends Codec { - private final StoredFieldsFormat fieldsFormat = new Lucene41StoredFieldsFormat(); + // TODO: slightly evil + private final StoredFieldsFormat fieldsFormat = new CompressingStoredFieldsFormat("Lucene41StoredFields", CompressionMode.FAST, 1 << 14) { + @Override + public StoredFieldsWriter fieldsWriter(Directory directory, SegmentInfo si, IOContext context) throws IOException { + throw new UnsupportedOperationException("this codec can only be used for reading"); + } + }; private final TermVectorsFormat vectorsFormat = new Lucene40TermVectorsFormat(); private final FieldInfosFormat fieldInfosFormat = new Lucene40FieldInfosFormat(); private final SegmentInfoFormat infosFormat = new Lucene40SegmentInfoFormat(); @@ -63,8 +78,9 @@ public class Lucene41Codec extends Codec { super("Lucene41"); } + // TODO: slightly evil @Override - public final StoredFieldsFormat storedFieldsFormat() { + public StoredFieldsFormat storedFieldsFormat() { return fieldsFormat; } diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java new file mode 100644 index 00000000000..ad5e72f7693 --- /dev/null +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java @@ -0,0 +1,32 @@ +package org.apache.lucene.codecs.lucene41; + +import org.apache.lucene.codecs.StoredFieldsFormat; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Read-write version of {@link Lucene41Codec} for testing. + */ +public class Lucene41RWCodec extends Lucene41Codec { + private final StoredFieldsFormat fieldsFormat = new Lucene41StoredFieldsFormat(); + + @Override + public StoredFieldsFormat storedFieldsFormat() { + return fieldsFormat; + } +} diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/package.html b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/package.html new file mode 100644 index 00000000000..f9d00126b29 --- /dev/null +++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/package.html @@ -0,0 +1,25 @@ + + + + + + + +Support for testing {@link org.apache.lucene.codecs.lucene41.Lucene41Codec}. + + diff --git a/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec b/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec index 9898475e139..38d3ea861a3 100644 --- a/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec +++ b/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec @@ -18,3 +18,4 @@ org.apache.lucene.codecs.compressing.FastCompressingCodec org.apache.lucene.codecs.compressing.FastDecompressionCompressingCodec org.apache.lucene.codecs.compressing.HighCompressionCompressingCodec org.apache.lucene.codecs.compressing.dummy.DummyCompressingCodec +org.apache.lucene.codecs.lucene41.Lucene41RWCodec