import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
-import org.apache.commons.io.FileUtils;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
-import org.apache.maven.index.NexusIndexer;
-import org.apache.maven.index.context.IndexingContext;
+import org.apache.archiva.webdav.util.MavenIndexerCleaner;
+import org.apache.commons.io.FileUtils;
+import org.apache.lucene.store.Lock;
+import org.apache.lucene.store.LockReleaseFailedException;
+import org.apache.lucene.store.NativeFSLockFactory;
import org.junit.After;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
/**
* AbstractRepositoryServletTestCase
saveConfiguration( archivaConfiguration );
}
+ @BeforeClass
+ public static void lockCleanup()
+ throws Exception
+ {
+ /*
+
+ try
+ {
+
+ /*
+ Field locks = NativeFSLockFactory.class.getDeclaredClasses()[0].getField( "LOCK_HELD" );
+ locks.setAccessible( true );
+ Method clear = locks.getClass().getMethod( "clear" );
+
+ clear.invoke( field, null );
+ */
+
+ /*
+ NativeFSLockFactory nativeFSLockFactory =
+ new NativeFSLockFactory( new File( "target/appserver-base/data/repositories/internal/.indexer" ) );
+
+ Lock lock = nativeFSLockFactory.makeLock( "write.lock" );
+ lock.release();
+ LoggerFactory.getLogger( AbstractRepositoryServletTestCase.class ).info( "cleanup lock" );
+
+
+ }
+ catch ( LockReleaseFailedException e )
+ {
+ // ignore
+ }
+ */
+ }
+
@Before
public void setUp()
throws Exception
{
+
+ lockCleanup();
super.setUp();
String appserverBase = new File( "target/appserver-base" ).getAbsolutePath();
archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
- //archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
repoRootLegacy = new File( appserverBase, "data/repositories/legacy" );
Configuration config = archivaConfiguration.getConfiguration();
HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
+ applicationContext.getBean( MavenIndexerCleaner.class ).cleanupIndex();
+
sr = new ServletRunner( new File( "src/test/resources/WEB-INF/web.xml" ) );
sr.registerServlet( "/repository/*", UnauthenticatedRepositoryServlet.class.getName() );
throws Exception
{
-
if ( sc != null )
{
sc.clearContents();
*/
import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
+import org.apache.lucene.store.Lock;
+import org.apache.lucene.store.LockReleaseFailedException;
+import org.apache.lucene.store.NativeFSLockFactory;
import org.apache.maven.index.NexusIndexer;
import org.apache.maven.index.context.IndexingContext;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
+import java.io.File;
/**
* @author Olivier Lamy
private ApplicationContext applicationContext;
@PostConstruct
- public void startup() throws Exception
+ public void startup()
+ throws Exception
{
plexusSisuBridge = applicationContext.getBean( PlexusSisuBridge.class );
- cleanupIndex( );
+ cleanupIndex();
}
@PreDestroy
public void shutdown()
throws Exception
{
- cleanupIndex( );
+ cleanupIndex();
}
WebApplicationContext wacu =
WebApplicationContextUtils.getRequiredWebApplicationContext( servletContextEvent.getServletContext() );
plexusSisuBridge = wacu.getBean( PlexusSisuBridge.class );
- cleanupIndex( );
+ cleanupIndex();
}
catch ( Exception e )
{
try
{
- cleanupIndex( );
+ cleanupIndex();
}
catch ( Exception e )
}
}
- public void cleanupIndex( )
+ public void cleanupIndex()
throws Exception
{
log.info( "cleanup IndexingContext" );
{
nexusIndexer.removeIndexingContext( context, true );
}
+
+ /*
+ try
+ {
+ NativeFSLockFactory nativeFSLockFactory =
+ new NativeFSLockFactory( new File( "target/appserver-base/data/repositories/internal/.indexer" ) );
+ Lock lock = nativeFSLockFactory.makeLock( "write.lock" );
+ lock.release();
+ log.info( "cleanup lock" );
+ }
+ catch ( LockReleaseFailedException e )
+ {
+ // ignore
+ }*/
+
}