Remove TransformException
diff --git a/src/com/google/enterprise/adaptor/DocumentHandler.java b/src/com/google/enterprise/adaptor/DocumentHandler.java
index ec71b75..3da3c31 100644
--- a/src/com/google/enterprise/adaptor/DocumentHandler.java
+++ b/src/com/google/enterprise/adaptor/DocumentHandler.java
@@ -885,11 +885,7 @@
Map<String, String> params = new HashMap<String, String>();
params.put("DocId", docId.getUniqueId());
params.put("Content-Type", contentType);
- try {
- transform.transform(metadata, params);
- } catch (TransformException e) {
- throw new RuntimeException("transform failed", e);
- }
+ transform.transform(metadata, params);
contentType = params.get("Content-Type");
}
diff --git a/src/com/google/enterprise/adaptor/DocumentTransform.java b/src/com/google/enterprise/adaptor/DocumentTransform.java
index 02b1559..5269e44 100644
--- a/src/com/google/enterprise/adaptor/DocumentTransform.java
+++ b/src/com/google/enterprise/adaptor/DocumentTransform.java
@@ -27,10 +27,6 @@
/**
* Any changes to {@code metadata} and {@code params} will be
* passed on to subsequent transforms. This method must be thread-safe.
- *
- * @throws TransformException
- * @throws IOException
*/
- public void transform(Metadata metadata, Map<String, String> params)
- throws TransformException;
+ public void transform(Metadata metadata, Map<String, String> params);
}
diff --git a/src/com/google/enterprise/adaptor/TransformException.java b/src/com/google/enterprise/adaptor/TransformException.java
deleted file mode 100644
index 312c0d3..0000000
--- a/src/com/google/enterprise/adaptor/TransformException.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2011 Google Inc. All Rights Reserved.
-//
-// Licensed 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.
-
-package com.google.enterprise.adaptor;
-
-/**
- * Exception produced by {@link DocumentTransform}s and {@link
- * DocumentTransform} in the case of a fatal error.
- */
-public class TransformException extends Exception {
- /**
- * Constructs a new exception with a detailed message. The exception's cause
- * is left uninitialized.
- */
- public TransformException(String message) {
- super(message);
- }
-
- /**
- * Constructs a new exception with a detailed message and a cause initialized
- * to {@code cause}.
- */
- public TransformException(String message, Throwable cause) {
- super(message, cause);
- }
-
- /**
- * Constructs a new exception with a {@code null} message and a cause
- * initalized to {@code cause}.
- */
- public TransformException(Throwable cause) {
- super(cause);
- }
-}
diff --git a/src/com/google/enterprise/adaptor/TransformPipeline.java b/src/com/google/enterprise/adaptor/TransformPipeline.java
index f9f6ecb..3c7edc0 100644
--- a/src/com/google/enterprise/adaptor/TransformPipeline.java
+++ b/src/com/google/enterprise/adaptor/TransformPipeline.java
@@ -48,8 +48,7 @@
/**
* Transform {@code metadata}.
*/
- public void transform(Metadata metadata, Map<String, String> params)
- throws TransformException {
+ public void transform(Metadata metadata, Map<String, String> params) {
if (transformList.isEmpty()) {
return;
}
@@ -62,8 +61,9 @@
DocumentTransform transform = transformList.get(i);
try {
transform.transform(metadataInTransit, paramsInTransit);
- } catch (TransformException e) {
- throw new TransformException("Aborting " + names.get(i), e);
+ } catch (RuntimeException e) {
+ throw new RuntimeException(
+ "Exception during transform " + names.get(i), e);
}
}
diff --git a/src/com/google/enterprise/adaptor/prebuilt/CommandLineTransform.java b/src/com/google/enterprise/adaptor/prebuilt/CommandLineTransform.java
index 85d81f8..d798fea 100644
--- a/src/com/google/enterprise/adaptor/prebuilt/CommandLineTransform.java
+++ b/src/com/google/enterprise/adaptor/prebuilt/CommandLineTransform.java
@@ -19,7 +19,6 @@
import com.google.enterprise.adaptor.DocumentTransform;
import com.google.enterprise.adaptor.IOHelper;
import com.google.enterprise.adaptor.Metadata;
-import com.google.enterprise.adaptor.TransformException;
import java.io.*;
import java.nio.charset.Charset;
@@ -81,8 +80,7 @@
}
@Override
- public void transform(Metadata metadata, Map<String, String> params)
- throws TransformException {
+ public void transform(Metadata metadata, Map<String, String> params) {
if (transformCommand == null) {
throw new NullPointerException("transformCommand must not be null");
}
@@ -106,7 +104,8 @@
try {
command.exec(commandLine, workingDirectory);
} catch (InterruptedException ex) {
- throw new TransformException(ex);
+ Thread.currentThread().interrupt();
+ throw new RuntimeException(ex);
}
int exitCode = command.getReturnCode();
@@ -114,7 +113,7 @@
// Handle stderr
if (exitCode != 0) {
String errorOutput = new String(command.getStderr(), charset);
- throw new TransformException("Exit code " + exitCode + ". Stderr: "
+ throw new RuntimeException("Exit code " + exitCode + ". Stderr: "
+ errorOutput);
}
@@ -129,7 +128,7 @@
params.putAll(readMapFromFile(paramsFile));
}
} catch (IOException ioe) {
- throw new TransformException(ioe);
+ throw new RuntimeException(ioe);
} finally {
if (metadataFile != null) {
metadataFile.delete();
@@ -141,20 +140,20 @@
}
private File writeMapToTempFile(Map<String, String> map)
- throws IOException, TransformException {
+ throws IOException {
return writeIterableToTempFile(map.entrySet());
}
private File writeIterableToTempFile(Iterable<Map.Entry<String, String>> it)
- throws IOException, TransformException {
+ throws IOException {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> me : it) {
if (me.getKey().contains("\0")) {
- throw new TransformException("Key cannot contain the null character: "
+ throw new RuntimeException("Key cannot contain the null character: "
+ me.getKey());
}
if (me.getValue().contains("\0")) {
- throw new TransformException("Value for key '" + me.getKey()
+ throw new RuntimeException("Value for key '" + me.getKey()
+ "' cannot contain the null " + "character: " + me.getKey());
}
sb.append(me.getKey()).append('\0');
diff --git a/test/com/google/enterprise/adaptor/TransformPipelineTest.java b/test/com/google/enterprise/adaptor/TransformPipelineTest.java
index 611a70b..f9dd295 100644
--- a/test/com/google/enterprise/adaptor/TransformPipelineTest.java
+++ b/test/com/google/enterprise/adaptor/TransformPipelineTest.java
@@ -30,7 +30,7 @@
public ExpectedException thrown = ExpectedException.none();
@Test
- public void testNoOpEmpty() throws IOException, TransformException {
+ public void testNoOpEmpty() throws IOException {
TransformPipeline pipeline = new TransformPipeline(
Collections.<DocumentTransform>emptyList(), Collections.<String>emptyList());
Metadata metadata = new Metadata();
@@ -42,7 +42,7 @@
}
@Test
- public void testNoOpWithInput() throws IOException, TransformException {
+ public void testNoOpWithInput() throws IOException {
TransformPipeline pipeline = new TransformPipeline(
Collections.<DocumentTransform>emptyList(), Collections.<String>emptyList());
Metadata metadata = new Metadata();
@@ -58,7 +58,7 @@
}
@Test
- public void testAddMetadataAndParams() throws IOException, TransformException {
+ public void testAddMetadataAndParams() throws IOException {
Metadata metadata = new Metadata();
metadata.add("key1", "value1");
Map<String, String> params = new HashMap<String, String>();
@@ -67,7 +67,7 @@
List<DocumentTransform> transforms = new ArrayList<DocumentTransform>();
transforms.add(new DocumentTransform() {
@Override
- public void transform(Metadata m, Map<String, String> p) throws TransformException {
+ public void transform(Metadata m, Map<String, String> p) {
m.set("newMeta", "metaValue");
p.put("newKey", "newValue");
}
@@ -86,19 +86,17 @@
private static class ErroringTransform implements DocumentTransform {
@Override
- public void transform(Metadata metadata, Map<String, String> p)
- throws TransformException {
+ public void transform(Metadata metadata, Map<String, String> p) {
// Do some work, but don't complete.
metadata.set("trash", "value");
p.put("more trash", "values");
- throw new TransformException("test exception");
+ throw new RuntimeException("test exception");
}
}
private static class IncrementTransform implements DocumentTransform {
@Override
- public void transform(Metadata metadata, Map<String, String> p)
- throws TransformException {
+ public void transform(Metadata metadata, Map<String, String> p) {
metadata.set("int", "" + (Integer.parseInt(metadata.getOneValue("int")) + 1));
p.put("int", "" + (Integer.parseInt(p.get("int")) + 1));
}
@@ -112,15 +110,14 @@
}
@Override
- public void transform(Metadata metadata, Map<String, String> p)
- throws TransformException {
+ public void transform(Metadata metadata, Map<String, String> p) {
metadata.set("int", "" + (Integer.parseInt(metadata.getOneValue("int")) * factor));
p.put("int", "" + (Integer.parseInt(p.get("int")) * factor));
}
}
@Test
- public void testTransform() throws IOException, TransformException {
+ public void testTransform() throws IOException {
TransformPipeline pipeline = new TransformPipeline(
Arrays.asList(new IncrementTransform()), Arrays.asList("it"));
Metadata metadata = new Metadata();
@@ -137,7 +134,7 @@
}
@Test
- public void testMultipleTransforms() throws IOException, TransformException {
+ public void testMultipleTransforms() throws IOException {
TransformPipeline pipeline = new TransformPipeline(Arrays.asList(
new IncrementTransform(), new ProductTransform(2)),
Arrays.asList("it", "pt"));
@@ -156,7 +153,7 @@
}
@Test
- public void testTransformErrorFatal() throws IOException, TransformException {
+ public void testTransformErrorFatal() throws IOException {
TransformPipeline pipeline = new TransformPipeline(Arrays.asList(
new IncrementTransform(), new ErroringTransform()),
Arrays.asList("it", "et"));
@@ -165,7 +162,7 @@
Map<String, String> params = new HashMap<String, String>();
params.put("int", "1");
- thrown.expect(TransformException.class);
+ thrown.expect(RuntimeException.class);
try {
pipeline.transform(metadata, params);
} finally {
diff --git a/test/com/google/enterprise/adaptor/prebuilt/CommandLineTransformTest.java b/test/com/google/enterprise/adaptor/prebuilt/CommandLineTransformTest.java
index e9e95fd..9979508 100644
--- a/test/com/google/enterprise/adaptor/prebuilt/CommandLineTransformTest.java
+++ b/test/com/google/enterprise/adaptor/prebuilt/CommandLineTransformTest.java
@@ -18,7 +18,6 @@
import com.google.enterprise.adaptor.Metadata;
import com.google.enterprise.adaptor.TestHelper;
-import com.google.enterprise.adaptor.TransformException;
import org.junit.Test;
@@ -31,7 +30,7 @@
*/
public class CommandLineTransformTest {
@Test
- public void testSed() throws IOException, TransformException {
+ public void testSed() throws IOException {
TestHelper.assumeOsIsNotWindows();
ByteArrayOutputStream contentOut = new ByteArrayOutputStream();
@@ -52,7 +51,7 @@
}
@Test
- public void testSedWithMetadata() throws IOException, TransformException {
+ public void testSedWithMetadata() throws IOException {
TestHelper.assumeOsIsNotWindows();
Metadata metadata = new Metadata();