[hibernate-commits] Hibernate SVN: r20678 - in search/trunk/hibernate-search/src: main/java/org/hibernate/search/backend/impl and 6 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Tue Sep 21 11:42:43 EDT 2010


Author: hardy.ferentschik
Date: 2010-09-21 11:42:42 -0400 (Tue, 21 Sep 2010)
New Revision: 20678

Added:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/ClassLoaderHelper.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/BarAnalyzer.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ClassLoaderHelperTest.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/FooAnalyzer.java
Removed:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PluginLoader.java
   search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
Modified:
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ConfigContext.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
   search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
Log:
HSEARCH-457 Renamed PluginLoader to ClassLoaderHelper. Added tests for ClassLoaderHelper.analyzerInstanceFromClass

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/WorkerFactory.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.backend;
 
@@ -29,10 +28,10 @@
 
 import org.hibernate.annotations.common.util.StringHelper;
 import org.hibernate.search.Environment;
-import org.hibernate.search.spi.WorkerBuildContext;
 import org.hibernate.search.backend.impl.TransactionalWorker;
 import org.hibernate.search.cfg.SearchConfiguration;
-import org.hibernate.search.util.PluginLoader;
+import org.hibernate.search.spi.WorkerBuildContext;
+import org.hibernate.search.util.ClassLoaderHelper;
 
 /**
  * @author Emmanuel Bernard
@@ -42,11 +41,11 @@
 	private static Properties getProperties(SearchConfiguration cfg) {
 		Properties props = cfg.getProperties();
 		Properties workerProperties = new Properties();
-		for (Map.Entry entry : props.entrySet()) {
-			String key = (String) entry.getKey();
+		for ( Map.Entry entry : props.entrySet() ) {
+			String key = ( String ) entry.getKey();
 			if ( key.startsWith( Environment.WORKER_PREFIX ) ) {
 				//key.substring( Environment.WORKER_PREFIX.length() )
-				workerProperties.setProperty( key, (String) entry.getValue() );
+				workerProperties.setProperty( key, ( String ) entry.getValue() );
 			}
 		}
 		return workerProperties;
@@ -63,11 +62,12 @@
 			worker = new TransactionalWorker();
 		}
 		else {
-			worker = PluginLoader.instanceFromName( Worker.class,
-					impl, WorkerFactory.class, "worker" );
+			worker = ClassLoaderHelper.instanceFromName(
+					Worker.class,
+					impl, WorkerFactory.class, "worker"
+			);
 		}
 		worker.initialize( props, context );
 		return worker;
 	}
-	
 }

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/backend/impl/BatchedQueueingProcessor.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.backend.impl;
 
@@ -58,9 +57,9 @@
 import org.hibernate.search.engine.DocumentBuilderContainedEntity;
 import org.hibernate.search.engine.DocumentBuilderIndexedEntity;
 import org.hibernate.search.engine.SearchFactoryImplementor;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.HibernateHelper;
 import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.search.util.PluginLoader;
 
 /**
  * Batch work until {@link #performWorks} is called.
@@ -116,7 +115,7 @@
 				backendQueueProcessorFactory = new SlaveJGroupsBackendQueueProcessorFactory();
 		}
 		else {
-			backendQueueProcessorFactory = PluginLoader.instanceFromName( BackendQueueProcessorFactory.class,
+			backendQueueProcessorFactory = ClassLoaderHelper.instanceFromName( BackendQueueProcessorFactory.class,
 					backend, BatchedQueueingProcessor.class, "processor" );
 		}
 		backendQueueProcessorFactory.initialize( properties, context );

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/engine/DocumentBuilderContainedEntity.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.engine;
 
@@ -38,7 +37,6 @@
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.document.Field;
 import org.apache.lucene.search.Similarity;
-import org.apache.lucene.util.Version;
 import org.slf4j.Logger;
 
 import org.hibernate.annotations.common.AssertionFailure;
@@ -71,7 +69,7 @@
 import org.hibernate.search.util.HibernateHelper;
 import org.hibernate.search.util.LoggerFactory;
 import org.hibernate.search.util.PassThroughAnalyzer;
-import org.hibernate.search.util.PluginLoader;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.ReflectionHelper;
 import org.hibernate.search.util.ScopedAnalyzer;
 
@@ -249,13 +247,12 @@
 				return null;
 			}
 			else {
-
 				return context.buildLazyAnalyzer( definition );
 			}
 		}
 		else {
 			try {
-				return PluginLoader.analyzerInstanceFromClass(  analyzerClass, context.getLuceneMatchVersion() );
+				return ClassLoaderHelper.analyzerInstanceFromClass(  analyzerClass, context.getLuceneMatchVersion() );
 			}
 			catch ( ClassCastException e ) {
 				throw new SearchException(

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ConfigContext.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ConfigContext.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ConfigContext.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -41,9 +41,9 @@
 import org.hibernate.search.SearchException;
 import org.hibernate.search.annotations.AnalyzerDef;
 import org.hibernate.search.cfg.SearchConfiguration;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.DelegateNamedAnalyzer;
 import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.search.util.PluginLoader;
 
 /**
  * Provides access to some default configuration settings (eg default <code>Analyzer</code> or default
@@ -114,7 +114,7 @@
 		else {
 			analyzerClass = StandardAnalyzer.class;
 		}
-		return PluginLoader.analyzerInstanceFromClass( analyzerClass, luceneMatchVersion );
+		return ClassLoaderHelper.analyzerInstanceFromClass( analyzerClass, luceneMatchVersion );
 	}
 
 	/**
@@ -131,7 +131,7 @@
 			defaultSimilarity = Similarity.getDefault();
 		}
 		else {
-			defaultSimilarity = PluginLoader.instanceFromName(
+			defaultSimilarity = ClassLoaderHelper.instanceFromName(
 					Similarity.class, similarityClassName, ConfigContext.class, "default similarity"
 			);
 		}

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/ImmutableSearchFactory.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -71,8 +71,8 @@
 import org.hibernate.search.stat.StatisticsImplementor;
 import org.hibernate.search.store.DirectoryProvider;
 import org.hibernate.search.store.optimization.OptimizerStrategy;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.search.util.PluginLoader;
 
 /**
  * This implementation is never directly exposed to the user, it is always wrapped into a {@link org.hibernate.search.impl.MutableSearchFactory}
@@ -332,7 +332,7 @@
 			batchBackend = new LuceneBatchBackend();
 		}
 		else {
-			batchBackend = PluginLoader.instanceFromName(
+			batchBackend = ClassLoaderHelper.instanceFromName(
 					BatchBackend.class, impl, ImmutableSearchFactory.class,
 					"batchbackend"
 			);

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/impl/SearchFactoryBuilder.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -87,8 +87,8 @@
 import org.hibernate.search.store.DirectoryProvider;
 import org.hibernate.search.store.DirectoryProviderFactory;
 import org.hibernate.search.store.optimization.OptimizerStrategy;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.search.util.PluginLoader;
 import org.hibernate.search.util.ReflectionHelper;
 
 /**
@@ -332,7 +332,7 @@
 			filterCachingStrategy = new MRUFilterCachingStrategy();
 		}
 		else {
-			filterCachingStrategy = PluginLoader.instanceFromName(
+			filterCachingStrategy = ClassLoaderHelper.instanceFromName(
 					FilterCachingStrategy.class,
 					impl, ImmutableSearchFactory.class, "filterCachingStrategy"
 			);
@@ -519,7 +519,7 @@
 			return new LogErrorHandler();
 		}
 		else {
-			return PluginLoader.instanceFromName(
+			return ClassLoaderHelper.instanceFromName(
 					ErrorHandler.class, errorHandlerClassName,
 					ImmutableSearchFactory.class, "Error Handler"
 			);

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/reader/ReaderProviderFactory.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.reader;
 
@@ -29,9 +28,9 @@
 
 import org.hibernate.annotations.common.util.StringHelper;
 import org.hibernate.search.Environment;
+import org.hibernate.search.cfg.SearchConfiguration;
 import org.hibernate.search.spi.BuildContext;
-import org.hibernate.search.cfg.SearchConfiguration;
-import org.hibernate.search.util.PluginLoader;
+import org.hibernate.search.util.ClassLoaderHelper;
 
 /**
  * @author Emmanuel Bernard
@@ -41,10 +40,10 @@
 	private static Properties getProperties(SearchConfiguration cfg) {
 		Properties props = cfg.getProperties();
 		Properties workerProperties = new Properties();
-		for (Map.Entry entry : props.entrySet()) {
-			String key = (String) entry.getKey();
+		for ( Map.Entry entry : props.entrySet() ) {
+			String key = ( String ) entry.getKey();
 			if ( key.startsWith( Environment.READER_PREFIX ) ) {
-				workerProperties.setProperty( key, (String) entry.getValue() );
+				workerProperties.setProperty( key, ( String ) entry.getValue() );
 			}
 		}
 		return workerProperties;
@@ -69,8 +68,10 @@
 			readerProvider = new SharingBufferReaderProvider();
 		}
 		else {
-			readerProvider = PluginLoader.instanceFromName( ReaderProvider.class, impl,
-					ReaderProviderFactory.class, "readerProvider" );
+			readerProvider = ClassLoaderHelper.instanceFromName(
+					ReaderProvider.class, impl,
+					ReaderProviderFactory.class, "readerProvider"
+			);
 		}
 		readerProvider.initialize( props, context );
 		return readerProvider;

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderFactory.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.store;
 
@@ -43,7 +42,7 @@
 import org.hibernate.search.store.optimization.IncrementalOptimizerStrategy;
 import org.hibernate.search.store.optimization.NoOpOptimizerStrategy;
 import org.hibernate.search.store.optimization.OptimizerStrategy;
-import org.hibernate.search.util.PluginLoader;
+import org.hibernate.search.util.ClassLoaderHelper;
 
 /**
  * Create a Lucene directory provider which can be configured
@@ -102,7 +101,7 @@
 			}
 		}
 		else {
-			shardingStrategy = PluginLoader.instanceFromName( IndexShardingStrategy.class,
+			shardingStrategy = ClassLoaderHelper.instanceFromName( IndexShardingStrategy.class,
 					shardingStrategyName, DirectoryProviderFactory.class, "IndexShardingStrategy" );
 		}
 		shardingStrategy.initialize(
@@ -124,7 +123,7 @@
 			provider = new FSDirectoryProvider();
 		}
 		else {
-			provider = PluginLoader.instanceFromName( DirectoryProvider.class, className,
+			provider = ClassLoaderHelper.instanceFromName( DirectoryProvider.class, className,
 					DirectoryProviderFactory.class, "directory provider" );
 		}
 		try {
@@ -176,7 +175,7 @@
 	 * in a global scope it will take priority on local transaction parameters.
 	 * </p>
 	 *
-	 * @param searchFactoryImplementor the search factory.
+	 * @param context the build context.
 	 * @param directoryProperties	  The properties extracted from the configuration.
 	 * @param provider				 The directory provider for which to configure the indexing parameters.
 	 */

Modified: search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/store/DirectoryProviderHelper.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,26 +1,25 @@
-/* $Id$
- * 
+/*
  * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
  */
 package org.hibernate.search.store;
 
@@ -41,9 +40,9 @@
 
 import org.hibernate.annotations.common.util.StringHelper;
 import org.hibernate.search.SearchException;
+import org.hibernate.search.util.ClassLoaderHelper;
 import org.hibernate.search.util.FileHelper;
 import org.hibernate.search.util.LoggerFactory;
-import org.hibernate.search.util.PluginLoader;
 
 /**
  * @author Emmanuel Bernard
@@ -161,7 +160,7 @@
 			return new NoLockFactory();
 		}
 		else {
-			LockFactoryFactory lockFactoryFactory = PluginLoader.instanceFromName( LockFactoryFactory.class,
+			LockFactoryFactory lockFactoryFactory = ClassLoaderHelper.instanceFromName( LockFactoryFactory.class,
 						lockFactoryName, DirectoryProviderHelper.class, "locking_strategy" );
 			return lockFactoryFactory.createLockFactory( indexDir, dirConfiguration );
 		}

Copied: search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/ClassLoaderHelper.java (from rev 20676, search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PluginLoader.java)
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/ClassLoaderHelper.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/ClassLoaderHelper.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -0,0 +1,225 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.util;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.util.Version;
+
+import org.hibernate.annotations.common.util.ReflectHelper;
+import org.hibernate.search.SearchException;
+
+/**
+ * Utility class to load instances of other classes by using a fully qualified name,
+ * or from a class type.
+ * Uses reflection and throws SearchException(s) with proper descriptions of the error,
+ * like the target class is missing a proper constructor, is an interface, is not found...
+ *
+ * @author Sanne Grinovero
+ * @author Hardy Ferentschik
+ */
+public class ClassLoaderHelper {
+
+	private ClassLoaderHelper() {
+	}
+
+	/**
+	 * Creates an instance of a target class designed by fully qualified name
+	 *
+	 * @param <T> matches the type of targetSuperType: defines the return type
+	 * @param targetSuperType the return type of the function, the classNameToLoad will be checked
+	 * to be assignable to this type.
+	 * @param classNameToLoad a fully qualified class name, whose type is assignable to targetSuperType
+	 * @param caller the class of the caller, needed for classloading purposes
+	 * @param componentDescription a meaningful description of the role the instance will have,
+	 * used to enrich error messages to describe the context of the error
+	 *
+	 * @return a new instance of classNameToLoad
+	 *
+	 * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
+	 *                         classNotFound, missing proper constructor, wrong type, security errors.
+	 */
+	public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad,
+										 Class<?> caller, String componentDescription) {
+		final Class<?> clazzDef;
+		clazzDef = classForName( classNameToLoad, caller, componentDescription );
+		return instanceFromClass( targetSuperType, clazzDef, componentDescription );
+	}
+
+	/**
+	 * Creates an instance of target class
+	 *
+	 * @param <T> the type of targetSuperType: defines the return type
+	 * @param targetSuperType the created instance will be checked to be assignable to this type
+	 * @param classToLoad the class to be instantiated
+	 * @param componentDescription a role name/description to contextualize error messages
+	 *
+	 * @return a new instance of classToLoad
+	 *
+	 * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
+	 *                         missing proper constructor, wrong type, security errors.
+	 */
+	@SuppressWarnings("unchecked")
+	public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription) {
+		checkClassType( classToLoad, componentDescription );
+		checkHasNoArgConstructor( classToLoad, componentDescription );
+		Object instance;
+		try {
+			instance = classToLoad.newInstance();
+		}
+		catch ( IllegalAccessException e ) {
+			throw new SearchException(
+					"Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
+							". Class or constructor is not accessible.", e
+			);
+		}
+		catch ( InstantiationException e ) {
+			throw new SearchException(
+					"Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
+							". Verify it has a no-args public constructor and is not abstract.", e
+			);
+		}
+		if ( !targetSuperType.isInstance( instance ) ) {
+			// have a proper error message according to interface implementation or subclassing
+			if ( targetSuperType.isInterface() ) {
+				throw new SearchException(
+						"Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
+								+ " does not implement interface " + targetSuperType.getName()
+				);
+			}
+			else {
+				throw new SearchException(
+						"Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
+								+ " is not a subtype of " + targetSuperType.getName()
+				);
+			}
+		}
+		else {
+			return ( T ) instance;
+		}
+	}
+
+	public static Analyzer analyzerInstanceFromClass(Class<?> classToInstantiate, Version luceneMatchVersion) {
+		checkClassType( classToInstantiate, "analyzer" );
+		Analyzer analyzerInstance;
+
+		// try to get a constructor with a version parameter
+		Constructor constructor;
+		boolean useVersionParameter = true;
+		try {
+			constructor = classToInstantiate.getConstructor( Version.class );
+		}
+		catch ( NoSuchMethodException e ) {
+			try {
+				constructor = classToInstantiate.getConstructor();
+				useVersionParameter = false;
+			}
+			catch ( NoSuchMethodException nsme ) {
+				StringBuilder msg = new StringBuilder( "Unable to instantiate analyzer class: " );
+				msg.append( classToInstantiate.getName() );
+				msg.append( ". Class neither has a default constructor nor a constructor with a Version parameter" );
+				throw new SearchException( msg.toString(), e );
+			}
+		}
+
+		try {
+			if ( useVersionParameter ) {
+				analyzerInstance = ( Analyzer ) constructor.newInstance( luceneMatchVersion );
+			}
+			else {
+				analyzerInstance = ( Analyzer ) constructor.newInstance();
+			}
+		}
+		catch ( IllegalAccessException e ) {
+			throw new SearchException(
+					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
+							". Class or constructor is not accessible.", e
+			);
+		}
+		catch ( InstantiationException e ) {
+			throw new SearchException(
+					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
+							". Verify it has a no-args public constructor and is not abstract.", e
+			);
+		}
+		catch ( InvocationTargetException e ) {
+			throw new SearchException(
+					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
+							". Verify it has a no-args public constructor and is not abstract.", e
+			);
+		}
+		return analyzerInstance;
+	}
+
+	private static void checkClassType(Class<?> classToLoad, String componentDescription) {
+		if ( classToLoad.isInterface() ) {
+			throw new SearchException(
+					classToLoad.getName() + " defined for component " + componentDescription
+							+ " is an interface: implementation required."
+			);
+		}
+	}
+
+	/**
+	 * Verifies if target class has a no-args constructor, and that it is
+	 * accessible in current security manager.
+	 *
+	 * @param classToLoad the class type to check
+	 * @param componentDescription adds a meaningful description to the type to describe in the
+	 * exception message
+	 */
+	private static void checkHasNoArgConstructor(Class<?> classToLoad, String componentDescription) {
+		try {
+			classToLoad.getConstructor();
+		}
+		catch ( SecurityException e ) {
+			throw new SearchException(
+					classToLoad.getName() + " defined for component " + componentDescription
+							+ " could not be instantiated because of a security manager error", e
+			);
+		}
+		catch ( NoSuchMethodException e ) {
+			throw new SearchException(
+					classToLoad.getName() + " defined for component " + componentDescription
+							+ " is missing a no-arguments constructor"
+			);
+		}
+	}
+
+	private static Class<?> classForName(String classNameToLoad, Class<?> caller, String componentDescription) {
+		Class<?> clazzDef;
+		try {
+			clazzDef = ReflectHelper.classForName( classNameToLoad, caller );
+		}
+		catch ( ClassNotFoundException e ) {
+			throw new SearchException(
+					"Unable to find " + componentDescription +
+							" implementation class: " + classNameToLoad, e
+			);
+		}
+		return clazzDef;
+	}
+}

Deleted: search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PluginLoader.java
===================================================================
--- search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PluginLoader.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/main/java/org/hibernate/search/util/PluginLoader.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,225 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
- *  indicated by the @author tags or express copyright attribution
- *  statements applied by the authors.  All third-party contributions are
- *  distributed under license by Red Hat, Inc.
- *
- *  This copyrighted material is made available to anyone wishing to use, modify,
- *  copy, or redistribute it subject to the terms and conditions of the GNU
- *  Lesser General Public License, as published by the Free Software Foundation.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- *  for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public License
- *  along with this distribution; if not, write to:
- *  Free Software Foundation, Inc.
- *  51 Franklin Street, Fifth Floor
- *  Boston, MA  02110-1301  USA
- */
-package org.hibernate.search.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.util.Version;
-
-import org.hibernate.annotations.common.util.ReflectHelper;
-import org.hibernate.search.SearchException;
-
-/**
- * Utility class to load instances of other classes by using a fully qualified name,
- * or from a class type.
- * Uses reflection and throws SearchException(s) with proper descriptions of the error,
- * like the target class is missing a proper constructor, is an interface, is not found...
- *
- * @author Sanne Grinovero
- * @author Hardy Ferentschik
- */
-public class PluginLoader {
-
-	private PluginLoader() {
-	}
-
-	/**
-	 * Creates an instance of a target class designed by fully qualified name
-	 *
-	 * @param <T> matches the type of targetSuperType: defines the return type
-	 * @param targetSuperType the return type of the function, the classNameToLoad will be checked
-	 * to be assignable to this type.
-	 * @param classNameToLoad a fully qualified class name, whose type is assignable to targetSuperType
-	 * @param caller the class of the caller, needed for classloading purposes
-	 * @param componentDescription a meaningful description of the role the instance will have,
-	 * used to enrich error messages to describe the context of the error
-	 *
-	 * @return a new instance of classNameToLoad
-	 *
-	 * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
-	 *                         classNotFound, missing proper constructor, wrong type, security errors.
-	 */
-	public static <T> T instanceFromName(Class<T> targetSuperType, String classNameToLoad,
-										 Class<?> caller, String componentDescription) {
-		final Class<?> clazzDef;
-		clazzDef = classForName( classNameToLoad, caller, componentDescription );
-		return instanceFromClass( targetSuperType, clazzDef, componentDescription );
-	}
-
-	/**
-	 * Creates an instance of target class
-	 *
-	 * @param <T> the type of targetSuperType: defines the return type
-	 * @param targetSuperType the created instance will be checked to be assignable to this type
-	 * @param classToLoad the class to be instantiated
-	 * @param componentDescription a role name/description to contextualize error messages
-	 *
-	 * @return a new instance of classToLoad
-	 *
-	 * @throws SearchException wrapping other error types with a proper error message for all kind of problems, like
-	 *                         missing proper constructor, wrong type, security errors.
-	 */
-	@SuppressWarnings("unchecked")
-	public static <T> T instanceFromClass(Class<T> targetSuperType, Class<?> classToLoad, String componentDescription) {
-		checkClassType( classToLoad, componentDescription );
-		checkHasNoArgConstructor( classToLoad, componentDescription );
-		Object instance;
-		try {
-			instance = classToLoad.newInstance();
-		}
-		catch ( IllegalAccessException e ) {
-			throw new SearchException(
-					"Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
-							". Class or constructor is not accessible.", e
-			);
-		}
-		catch ( InstantiationException e ) {
-			throw new SearchException(
-					"Unable to instantiate " + componentDescription + " class: " + classToLoad.getName() +
-							". Verify it has a no-args public constructor and is not abstract.", e
-			);
-		}
-		if ( !targetSuperType.isInstance( instance ) ) {
-			// have a proper error message according to interface implementation or subclassing
-			if ( targetSuperType.isInterface() ) {
-				throw new SearchException(
-						"Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
-								+ " does not implement interface " + targetSuperType.getName()
-				);
-			}
-			else {
-				throw new SearchException(
-						"Wrong configuration of " + componentDescription + ": class " + classToLoad.getName()
-								+ " is not a subtype of " + targetSuperType.getName()
-				);
-			}
-		}
-		else {
-			return ( T ) instance;
-		}
-	}
-
-	public static Analyzer analyzerInstanceFromClass(Class<?> classToInstantiate, Version luceneMatchVersion) {
-		checkClassType( classToInstantiate, "analyzer" );
-		Analyzer analyzerInstance;
-
-		// try to get a constructor with a version parameter
-		Constructor constructor;
-		boolean useVersionParameter = true;
-		try {
-			constructor = classToInstantiate.getConstructor( Version.class );
-		}
-		catch ( NoSuchMethodException e ) {
-			try {
-				constructor = classToInstantiate.getConstructor();
-				useVersionParameter = false;
-			}
-			catch ( NoSuchMethodException nsme ) {
-				StringBuilder msg = new StringBuilder( "Unable to instantiate analyzer class: " );
-				msg.append( classToInstantiate.getName() );
-				msg.append( ". Class neither has a default constructor nor a constructor with a Version parameter" );
-				throw new SearchException( msg.toString(), e );
-			}
-		}
-
-		try {
-			if ( useVersionParameter ) {
-				analyzerInstance = ( Analyzer ) constructor.newInstance( luceneMatchVersion );
-			}
-			else {
-				analyzerInstance = ( Analyzer ) constructor.newInstance();
-			}
-		}
-		catch ( IllegalAccessException e ) {
-			throw new SearchException(
-					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
-							". Class or constructor is not accessible.", e
-			);
-		}
-		catch ( InstantiationException e ) {
-			throw new SearchException(
-					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
-							". Verify it has a no-args public constructor and is not abstract.", e
-			);
-		}
-		catch ( InvocationTargetException e ) {
-			throw new SearchException(
-					"Unable to instantiate analyzer class: " + classToInstantiate.getName() +
-							". Verify it has a no-args public constructor and is not abstract.", e
-			);
-		}
-		return analyzerInstance;
-	}
-
-	private static void checkClassType(Class<?> classToLoad, String componentDescription) {
-		if ( classToLoad.isInterface() ) {
-			throw new SearchException(
-					classToLoad.getName() + " defined for component " + componentDescription
-							+ " is an interface: implementation required."
-			);
-		}
-	}
-
-	/**
-	 * Verifies if target class has a no-args constructor, and that it is
-	 * accessible in current security manager.
-	 *
-	 * @param classToLoad the class type to check
-	 * @param componentDescription adds a meaningful description to the type to describe in the
-	 * exception message
-	 */
-	private static void checkHasNoArgConstructor(Class<?> classToLoad, String componentDescription) {
-		try {
-			classToLoad.getConstructor();
-		}
-		catch ( SecurityException e ) {
-			throw new SearchException(
-					classToLoad.getName() + " defined for component " + componentDescription
-							+ " could not be instantiated because of a security manager error", e
-			);
-		}
-		catch ( NoSuchMethodException e ) {
-			throw new SearchException(
-					classToLoad.getName() + " defined for component " + componentDescription
-							+ " is missing a no-arguments constructor"
-			);
-		}
-	}
-
-	private static Class<?> classForName(String classNameToLoad, Class<?> caller, String componentDescription) {
-		Class<?> clazzDef;
-		try {
-			clazzDef = ReflectHelper.classForName( classNameToLoad, caller );
-		}
-		catch ( ClassNotFoundException e ) {
-			throw new SearchException(
-					"Unable to find " + componentDescription +
-							" implementation class: " + classNameToLoad, e
-			);
-		}
-		return clazzDef;
-	}
-}

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/BarAnalyzer.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/BarAnalyzer.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/BarAnalyzer.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -0,0 +1,45 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.test.util;
+
+import java.io.Reader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class BarAnalyzer extends Analyzer {
+
+	private BarAnalyzer() {
+	}
+
+	@Override
+	public TokenStream tokenStream(String fieldName, Reader reader) {
+		return null;
+	}
+}
+
+

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ClassLoaderHelperTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ClassLoaderHelperTest.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/ClassLoaderHelperTest.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -0,0 +1,154 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.test.util;
+
+import junit.framework.TestCase;
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.search.DefaultSimilarity;
+import org.apache.lucene.search.Similarity;
+
+import org.hibernate.Session;
+import org.hibernate.search.FullTextSession;
+import org.hibernate.search.SearchException;
+import org.hibernate.search.backend.BackendQueueProcessorFactory;
+import org.hibernate.search.backend.impl.batchlucene.BatchBackend;
+import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
+import org.hibernate.search.impl.FullTextSessionImpl;
+import org.hibernate.search.util.ClassLoaderHelper;
+
+/**
+ * Tests for {@code ClassLoaderHelper}. Verifying amongst other that it throws easy to understand exceptions.
+ *
+ * @author Sanne Grinovero
+ * @author Hardy Ferentschik
+ */
+public class ClassLoaderHelperTest extends TestCase {
+
+	public void testInstanceFromName() {
+		BatchBackend batchBackend = ClassLoaderHelper.instanceFromName(
+				BatchBackend.class, LuceneBatchBackend.class.getName(), getClass(), "Lucene batch backend"
+		);
+		assertNotNull( batchBackend );
+		assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+		try {
+			ClassLoaderHelper.instanceFromName(
+					BackendQueueProcessorFactory.class, "HeyThisClassIsNotThere", getClass(), "backend"
+			);
+			fail( "was expecting a SearchException" );
+		}
+		catch ( Exception e ) {
+			assertEquals( e.getClass(), SearchException.class );
+			assertEquals( "Unable to find backend implementation class: HeyThisClassIsNotThere", e.getMessage() );
+		}
+	}
+
+	public void testInstanceFromClass() {
+		//testing for interface implementation:
+		BatchBackend batchBackend = ClassLoaderHelper.instanceFromClass(
+				BatchBackend.class, LuceneBatchBackend.class, "Lucene batch backend"
+		);
+		assertNotNull( batchBackend );
+		assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
+
+		//testing for subclasses:
+		Similarity sim = ClassLoaderHelper.instanceFromClass(
+				Similarity.class, DefaultSimilarity.class, "default similarity"
+		);
+		assertNotNull( sim );
+		assertTrue( sim.getClass().equals( DefaultSimilarity.class ) );
+
+		//testing proper error messages:
+		wrappingTestFromClass(
+				"Wrong configuration of Lucene batch backend: class " +
+						"org.hibernate.search.test.util.ClassLoaderHelperTest does not implement " +
+						"interface org.hibernate.search.backend.impl.batchlucene.BatchBackend",
+				BatchBackend.class, ClassLoaderHelperTest.class, "Lucene batch backend"
+		);
+		wrappingTestFromClass(
+				"org.hibernate.search.impl.FullTextSessionImpl defined for component session " +
+						"is missing a no-arguments constructor",
+				FullTextSession.class, FullTextSessionImpl.class, "session"
+		);
+		wrappingTestFromClass(
+				"org.hibernate.Session defined for component session is an interface: implementation required.",
+				FullTextSession.class, Session.class, "session"
+		);
+		wrappingTestFromClass(
+				"Wrong configuration of default similarity: " +
+						"class org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend " +
+						"is not a subtype of org.apache.lucene.search.Similarity",
+				Similarity.class, LuceneBatchBackend.class, "default similarity"
+		);
+		wrappingTestFromClass(
+				"Unable to instantiate default similarity class: org.apache.lucene.search.Similarity. " +
+						"Verify it has a no-args public constructor and is not abstract.",
+				Similarity.class, Similarity.class, "default similarity"
+		);
+	}
+
+	public void testLoadingAnalyzerWithVersionConstructor() {
+		Analyzer analyzer = ClassLoaderHelper.analyzerInstanceFromClass(
+				StandardAnalyzer.class, org.apache.lucene.util.Version.LUCENE_30
+		);
+		assertNotNull( "We should be able to instantiate an analyzer with a Lucene version parameter", analyzer );
+	}
+
+	public void testLoadingAnalyzerWithDefaultConstructor() {
+		Analyzer analyzer = ClassLoaderHelper.analyzerInstanceFromClass(
+				FooAnalyzer.class, org.apache.lucene.util.Version.LUCENE_30
+		);
+		assertNotNull( "We should be able to instantiate an analyzer which has only a default constructor", analyzer );
+	}
+
+	public void testLoadingAnalyzerWithNoVersionOrDefaultConstructor() {
+		try {
+			ClassLoaderHelper.analyzerInstanceFromClass(
+					BarAnalyzer.class, org.apache.lucene.util.Version.LUCENE_30
+			);
+			fail( "We should not be able to instantiate a analyzer with no default constructor or simple Version parameter." );
+		}
+		catch ( SearchException e ) {
+			assertEquals( e.getClass(), SearchException.class );
+			assertEquals(
+					"Unable to instantiate analyzer class: org.hibernate.search.test.util.BarAnalyzer. " +
+							"Class neither has a default constructor nor a constructor with a Version parameter",
+					e.getMessage()
+			);
+		}
+	}
+
+	private void wrappingTestFromClass(String expectedErrorMessage, Class<?> interf, Class<?> impl, String componentName) {
+		try {
+			ClassLoaderHelper.instanceFromClass( interf, impl, componentName );
+			fail( "was expecting a SearchException" );
+		}
+		catch ( Exception e ) {
+			assertEquals( e.getClass(), SearchException.class );
+			assertEquals( expectedErrorMessage, e.getMessage() );
+		}
+	}
+}
+

Added: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/FooAnalyzer.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/FooAnalyzer.java	                        (rev 0)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/FooAnalyzer.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -0,0 +1,41 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ *  Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as
+ *  indicated by the @author tags or express copyright attribution
+ *  statements applied by the authors.  All third-party contributions are
+ *  distributed under license by Red Hat, Inc.
+ *
+ *  This copyrighted material is made available to anyone wishing to use, modify,
+ *  copy, or redistribute it subject to the terms and conditions of the GNU
+ *  Lesser General Public License, as published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ *  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ *  for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this distribution; if not, write to:
+ *  Free Software Foundation, Inc.
+ *  51 Franklin Street, Fifth Floor
+ *  Boston, MA  02110-1301  USA
+ */
+package org.hibernate.search.test.util;
+
+import java.io.Reader;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.TokenStream;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class FooAnalyzer extends Analyzer {
+	@Override
+	public TokenStream tokenStream(String fieldName, Reader reader) {
+		return null;
+	}
+}
+
+

Deleted: search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java
===================================================================
--- search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java	2010-09-21 14:30:34 UTC (rev 20677)
+++ search/trunk/hibernate-search/src/test/java/org/hibernate/search/test/util/PluginLoaderTest.java	2010-09-21 15:42:42 UTC (rev 20678)
@@ -1,114 +0,0 @@
-/* $Id$
- * 
- * Hibernate, Relational Persistence for Idiomatic Java
- * 
- * Copyright (c) 2009, Red Hat, Inc. and/or its affiliates or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors.  All third-party contributions are
- * distributed under license by Red Hat, Inc.
- * 
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
- * for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA  02110-1301  USA
- */
-package org.hibernate.search.test.util;
-
-import org.apache.lucene.search.DefaultSimilarity;
-import org.apache.lucene.search.Similarity;
-import org.hibernate.Session;
-import org.hibernate.search.FullTextSession;
-import org.hibernate.search.SearchException;
-import org.hibernate.search.backend.BackendQueueProcessorFactory;
-import org.hibernate.search.backend.impl.batchlucene.BatchBackend;
-import org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend;
-import org.hibernate.search.impl.FullTextSessionImpl;
-import org.hibernate.search.util.PluginLoader;
-
-import junit.framework.TestCase;
-
-/**
- * Test for PluginLoader, also verifying it throws easy to understand exceptions
- * 
- * @author Sanne Grinovero
- */
-public class PluginLoaderTest extends TestCase {
-	
-	public void testInstanceFromName() {
-		BatchBackend batchBackend = PluginLoader.instanceFromName(BatchBackend.class, LuceneBatchBackend.class.getName(), getClass(), "Lucene batch backend");
-		assertNotNull( batchBackend );
-		assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
-		
-		try {
-			PluginLoader.instanceFromName( BackendQueueProcessorFactory.class, "HeyThisClassIsNotThere", getClass(), "backend" );
-			fail( "was expecting a SearchException" );
-		}
-		catch (Exception e) {
-			assertEquals( e.getClass(), SearchException.class );
-			assertEquals( "Unable to find backend implementation class: HeyThisClassIsNotThere", e.getMessage() );
-		}
-	}
-
-	public void testInstanceFromClass() {
-		//testing for interface implementation:
-		BatchBackend batchBackend = PluginLoader.instanceFromClass( BatchBackend.class, LuceneBatchBackend.class, "Lucene batch backend" );
-		assertNotNull( batchBackend );
-		assertTrue( batchBackend.getClass().equals( LuceneBatchBackend.class ) );
-		
-		//testing for subclasses:
-		Similarity sim =  PluginLoader.instanceFromClass( Similarity.class, DefaultSimilarity.class, "default similarity" );
-		assertNotNull( sim );
-		assertTrue( sim.getClass().equals( DefaultSimilarity.class ) );
-		
-		//testing proper error messages:
-		wrappingTestFromClass(
-				"Wrong configuration of Lucene batch backend: class " +
-				"org.hibernate.search.test.util.PluginLoaderTest does not implement " + 
-				"interface org.hibernate.search.backend.impl.batchlucene.BatchBackend",
-				BatchBackend.class, PluginLoaderTest.class, "Lucene batch backend"
-			);
-		wrappingTestFromClass(
-				"org.hibernate.search.impl.FullTextSessionImpl defined for component session " +
-				"is missing a no-arguments constructor",
-				FullTextSession.class, FullTextSessionImpl.class, "session"
-			);
-		wrappingTestFromClass(
-				"org.hibernate.Session defined for component session is an interface: implementation required.",
-				FullTextSession.class, Session.class, "session"
-			);
-		wrappingTestFromClass(
-				"Wrong configuration of default similarity: " +
-				"class org.hibernate.search.backend.impl.batchlucene.LuceneBatchBackend " +
-				"is not a subtype of org.apache.lucene.search.Similarity",
-				Similarity.class, LuceneBatchBackend.class, "default similarity"
-			);
-		wrappingTestFromClass(
-				"Unable to instantiate default similarity class: org.apache.lucene.search.Similarity. " +
-				"Verify it has a no-args public constructor and is not abstract.",
-				Similarity.class, Similarity.class, "default similarity"
-			);
-	}
-	
-	private void wrappingTestFromClass(String expectedErrorMessage, Class<?> interf, Class<?> impl, String componentName) {
-		try {
-			PluginLoader.instanceFromClass( interf, impl, componentName );
-			fail( "was expecting a SearchException" );
-		}
-		catch (Exception e) {
-			assertEquals( e.getClass(), SearchException.class );
-			assertEquals( expectedErrorMessage, e.getMessage() );
-		}
-	}
-	
-}
-



More information about the hibernate-commits mailing list