Permalink
Browse files

Added web.xml and renamed main/conf to main/resources, both to simpli…

…fy war file build using mvn war:war. Assembly descriptor still puts those resources files to conf dir in -dist.zip .
  • Loading branch information...
1 parent 2977df2 commit a260e07b410efc96f8e6e3e0b00d33c3064d7e3b @cliffano cliffano committed May 25, 2011
@@ -26,12 +26,12 @@
<outputDirectory>/bin</outputDirectory>
</file>
<file>
- <source>${project.basedir}/src/main/conf/couchdb-lucene.ini</source>
+ <source>${project.basedir}/src/main/resources/couchdb-lucene.ini</source>
<fileMode>644</fileMode>
<outputDirectory>/conf</outputDirectory>
</file>
<file>
- <source>${project.basedir}/src/main/conf/log4j.xml</source>
+ <source>${project.basedir}/src/main/resources/log4j.xml</source>
<fileMode>644</fileMode>
<outputDirectory>/conf</outputDirectory>
</file>
@@ -0,0 +1,54 @@
+package com.github.rnewson.couchdb.lucene;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalINIConfiguration;
+import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy;
+import org.apache.http.client.HttpClient;
+import org.apache.log4j.Logger;
+
+public final class Config {
+
+ private static final Logger LOG = Logger.getLogger(Config.class);
+
+ private static final String CONFIG_FILE = "couchdb-lucene.ini";
+ private static final String LUCENE_DIR = "lucene.dir";
+ private static final String DEFAULT_DIR = "indexes";
+
+ private final HierarchicalINIConfiguration configuration;
+
+ public Config() throws ConfigurationException {
+ this.configuration = new HierarchicalINIConfiguration(Config.class
+ .getClassLoader().getResource(CONFIG_FILE));
+ this.configuration
+ .setReloadingStrategy(new FileChangedReloadingStrategy());
+ }
+
+ public final HierarchicalINIConfiguration getConfiguration() {
+ return this.configuration;
+ }
+
+ public final File getDir() throws IOException {
+ final File dir = new File(this.configuration.getString(LUCENE_DIR,
+ DEFAULT_DIR));
+ if (!dir.exists() && !dir.mkdir()) {
+ throw new IOException("Could not create " + dir.getCanonicalPath());
+ }
+ if (!dir.canRead()) {
+ throw new IOException(dir + " is not readable.");
+ }
+ if (!dir.canWrite()) {
+ throw new IOException(dir + " is not writable.");
+ }
+ LOG.info("Index output goes to: " + dir.getCanonicalPath());
+ return dir;
+ }
+
+ public final HttpClient getClient() throws MalformedURLException {
+ HttpClientFactory.setIni(this.configuration);
+ return HttpClientFactory.getInstance();
+ }
+}
File renamed without changes.
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+
+ <display-name>couchdb-lucene</display-name>
+ <description>Enables full-text searching of CouchDB documents using Lucene</description>
+
+ <servlet>
+ <servlet-name>lucene</servlet-name>
+ <servlet-class>com.github.rnewson.couchdb.lucene.LuceneServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>lucene</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+</web-app>
@@ -0,0 +1,64 @@
+package com.github.rnewson.couchdb.lucene;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalINIConfiguration;
+import org.apache.http.client.HttpClient;
+import org.junit.Test;
+
+public class ConfigTest {
+
+ @Test
+ public void testGetConfiguration() {
+ try {
+ final Config config = new Config();
+ HierarchicalINIConfiguration configuration = config
+ .getConfiguration();
+ assertEquals("localhost", configuration.getString("lucene.host"));
+ assertEquals(5985, configuration.getInt("lucene.port"));
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetDir() {
+ try {
+ final Config config = new Config();
+ File dir = config.getDir();
+ assertTrue(dir.exists());
+ assertTrue(dir.canRead());
+ assertTrue(dir.canWrite());
+ assertEquals("target/indexes", dir.getPath());
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ } catch (IOException ioe) {
+ fail("IOException shouldn't have been thrown." + ioe.getMessage());
+ }
+ }
+
+ @Test
+ public void testGetClient() {
+ try {
+ final Config config = new Config();
+ HttpClient client = config.getClient();
+ assertNotNull(client);
+ } catch (ConfigurationException ce) {
+ fail("ConfigurationException shouldn't have been thrown."
+ + ce.getMessage());
+ } catch (MalformedURLException mue) {
+ fail("MalformedURLException shouldn't have been thrown."
+ + mue.getMessage());
+ }
+ }
+}

0 comments on commit a260e07

Please sign in to comment.