Adding Archiva event, tests for the repository factory and fixing test failures

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/archiva-with-new-repoapi@745335 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James William Dumay 2009-02-18 00:55:30 +00:00
parent 0935195242
commit b8e379aca8
20 changed files with 908 additions and 125 deletions

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-event</artifactId>
<packaging>jar</packaging>
<version>1.2-SNAPSHOT</version>
<name>Archiva Base :: Event</name>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,117 @@
package org.apache.archiva.event;
/*
* 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.
*/
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
/**
* Simple Async Event Bus implementation
*
* @author jdumay
*/
public class AsynchronousEventBus implements EventBus
{
private final Set<EventObserver> observers = Collections.synchronizedSet(new HashSet());
private final BlockingQueue<Event> events = new LinkedBlockingQueue<Event>();
private final Thread workerThread;
private final int threads;
public AsynchronousEventBus(int threads)
{
this.threads = threads;
workerThread = new Thread(new WorkerRunnable());
workerThread.start();
}
public void emit(EventEmitter emitter, EventMessage message)
{
events.offer(new Event(emitter, message));
}
public void subscribe(EventObserver observer)
{
observers.add(observer);
}
public void unsubscribe(EventObserver observer)
{
observers.remove(observer);
}
public Set<EventObserver> getObservers() {
return new HashSet<EventObserver>(observers);
}
class WorkerRunnable implements Runnable
{
private final ExecutorService service;
public WorkerRunnable()
{
service = Executors.newFixedThreadPool(threads);
}
public void run()
{
while (true)
{
dequeueAndExecute();
}
}
private void dequeueAndExecute()
{
try
{
final Event event = events.take();
for (final EventObserver observer : observers)
{
service.execute(new Runnable()
{
public void run()
{
try
{
observer.observe(event);
}
finally
{
//log me
}
}
});
}
}
catch (InterruptedException e)
{
//Do nothing
}
}
}
}

View File

@ -0,0 +1,55 @@
package org.apache.archiva.event;
/*
* 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.
*/
/**
* Encaptulation of both the EventEmitter and the EventMessage
* to represent a single event
*/
public final class Event
{
private final EventEmitter emitter;
private final EventMessage message;
public Event(EventEmitter emitter, EventMessage message)
{
this.emitter = emitter;
this.message = message;
}
/**
* Get the Emitter who emitted the Event
* @return emitter
*/
public EventEmitter getEmitter()
{
return emitter;
}
/**
* Get the EventMessage
* @return message
*/
public EventMessage getMessage()
{
return message;
}
}

View File

@ -0,0 +1,53 @@
package org.apache.archiva.event;
/*
* 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.
*/
import java.util.Set;
/**
* Allows implementer to emit to, subscribe and unsubscribe EventObservers
*/
public interface EventBus
{
/**
* Emit a event
* @param emitter
* @param message
*/
void emit(EventEmitter emitter, EventMessage message);
/**
* Allows the subscriber to receive messages from this event bus
* @param observer
*/
void subscribe(EventObserver observer);
/**
* Stops the observer from receiving any messages
* @param observer
*/
void unsubscribe(EventObserver observer);
/**
* Get the set of registered EventObservers
* @return
*/
Set<EventObserver> getObservers();
}

View File

@ -0,0 +1,24 @@
package org.apache.archiva.event;
/*
* 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.
*/
public interface EventEmitter
{
}

View File

@ -0,0 +1,24 @@
package org.apache.archiva.event;
/*
* 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.
*/
public interface EventMessage
{
}

View File

@ -0,0 +1,25 @@
package org.apache.archiva.event;
/*
* 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.
*/
public interface EventObserver
{
void observe(Event event);
}

View File

@ -0,0 +1,70 @@
package org.apache.archiva.event;
/*
* 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.
*/
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
public class AsynchronousEventBusTest extends TestCase
{
public void testSubscribeUnsubscribe() throws Exception
{
AsynchronousEventBus bus = new AsynchronousEventBus(1);
MockObserver observer = new MockObserver();
assertEquals(0, bus.getObservers().size());
bus.subscribe(observer);
assertTrue(bus.getObservers().contains(observer));
bus.unsubscribe(observer);
assertFalse(bus.getObservers().contains(bus));
}
public void testAllEventsAreObserved() throws Exception
{
AsynchronousEventBus bus = new AsynchronousEventBus(1);
MockObserver observer = new MockObserver();
bus.subscribe(observer);
for (int i = 0; i < 10; i++)
{
bus.emit(new EventEmitter() {}, new EventMessage() {});
}
while (observer.observedEvents.size() != 10)
{
}
assertEquals(10, observer.observedEvents.size());
}
class MockObserver implements EventObserver
{
final List<Event> observedEvents = Collections.synchronizedList(new ArrayList());
public void observe(Event event)
{
observedEvents.add(event);
}
}
}

View File

@ -0,0 +1,35 @@
package org.apache.archiva.event;
/*
* 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.
*/
import junit.framework.TestCase;
public class EventTest extends TestCase
{
public void testEvent()
{
EventEmitter emitter = new EventEmitter() {};
EventMessage message = new EventMessage() {};
Event event = new Event(emitter, message);
assertEquals(emitter, event.getEmitter());
assertEquals(message, event.getMessage());
}
}

View File

@ -34,8 +34,8 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationExce
import org.codehaus.plexus.registry.Registry;
import org.codehaus.plexus.registry.RegistryListener;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.collections.map.UnmodifiableMap;
/**
@ -62,8 +62,8 @@ public class RepositoryContentFactory
public RepositoryContentFactory()
{
managedContentMap = new HashMap<String, ManagedRepositoryContent>();
remoteContentMap = new HashMap<String, RemoteRepositoryContent>();
managedContentMap = new ConcurrentHashMap<String, ManagedRepositoryContent>();
remoteContentMap = new ConcurrentHashMap<String, RemoteRepositoryContent>();
}
/**
@ -72,6 +72,21 @@ public class RepositoryContentFactory
*/
public Map<String, ManagedRepositoryContent> getManagedContentMap()
{
if (managedContentMap.isEmpty())
{
for (final ManagedRepositoryConfiguration configuration : archivaConfiguration.getConfiguration().getManagedRepositories())
{
try
{
managedContentMap.put(configuration.getId(), createManagedRepositoryContent(configuration));
}
catch (RepositoryException e)
{
//Do nothing
}
}
}
return UnmodifiableMap.decorate(managedContentMap);
}
@ -81,6 +96,21 @@ public class RepositoryContentFactory
*/
public Map<String, RemoteRepositoryContent> getRemoteContentMap()
{
if (remoteContentMap.isEmpty())
{
for (final RemoteRepositoryConfiguration configuration : archivaConfiguration.getConfiguration().getRemoteRepositories())
{
try
{
remoteContentMap.put(configuration.getId(), createRemoteRepositoryContent(configuration));
}
catch ( RepositoryException e )
{
// Do nothing
}
}
}
return UnmodifiableMap.decorate(remoteContentMap);
}
@ -102,26 +132,13 @@ public class RepositoryContentFactory
return repo;
}
ManagedRepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration()
.findManagedRepositoryById( repoId );
if ( repoConfig == null )
ManagedRepositoryConfiguration configuration = archivaConfiguration.getConfiguration().findManagedRepositoryById( repoId );
if ( configuration == null )
{
throw new RepositoryNotFoundException( "Unable to find managed repository configuration for id:" + repoId );
}
try
{
repo = (ManagedRepositoryContent) container.lookup( ManagedRepositoryContent.class, repoConfig.getLayout() );
repo.setRepository( repoConfig );
managedContentMap.put( repoId, repo );
}
catch ( ComponentLookupException e )
{
throw new RepositoryException( "Specified layout [" + repoConfig.getLayout()
+ "] on managed repository id [" + repoId + "] is not valid.", e );
}
return repo;
return createManagedRepositoryContent(configuration);
}
public RemoteRepositoryContent getRemoteRepositoryContent( String repoId )
@ -134,28 +151,50 @@ public class RepositoryContentFactory
return repo;
}
RemoteRepositoryConfiguration repoConfig = archivaConfiguration.getConfiguration()
.findRemoteRepositoryById( repoId );
if ( repoConfig == null )
RemoteRepositoryConfiguration configuration = archivaConfiguration.getConfiguration().findRemoteRepositoryById( repoId );
if ( configuration == null )
{
throw new RepositoryNotFoundException( "Unable to find remote repository configuration for id:" + repoId );
}
return createRemoteRepositoryContent(configuration);
}
private RemoteRepositoryContent createRemoteRepositoryContent(RemoteRepositoryConfiguration configuration)
throws RepositoryException
{
RemoteRepositoryContent repositoryContent = null;
try
{
repo = (RemoteRepositoryContent) container.lookup( RemoteRepositoryContent.class, repoConfig.getLayout() );
repo.setRepository( repoConfig );
remoteContentMap.put( repoId, repo );
repositoryContent = (RemoteRepositoryContent) container.lookup( RemoteRepositoryContent.class, configuration.getLayout() );
repositoryContent.setRepository( configuration );
}
catch ( ComponentLookupException e )
{
throw new RepositoryException( "Specified layout [" + repoConfig.getLayout()
+ "] on remote repository id [" + repoId + "] is not valid.", e );
throw new RepositoryException( "Specified layout [" + configuration.getLayout()
+ "] on remote repository id [" + configuration.getId() + "] is not valid.", e );
}
return repo;
return repositoryContent;
}
private ManagedRepositoryContent createManagedRepositoryContent(ManagedRepositoryConfiguration configuration)
throws RepositoryException
{
ManagedRepositoryContent repositoryContent = null;
try
{
repositoryContent = (ManagedRepositoryContent) container.lookup( ManagedRepositoryContent.class, configuration.getLayout() );
repositoryContent.setRepository( configuration );
}
catch ( ComponentLookupException e )
{
throw new RepositoryException( "Specified layout [" + configuration.getLayout()
+ "] on managed repository id [" + configuration.getId() + "] is not valid.", e );
}
return repositoryContent;
}
public void contextualize( Context context )
throws ContextException
{

View File

@ -15,31 +15,40 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>archiva-base</artifactId>
<parent>
<artifactId>archiva-base</artifactId>
<groupId>org.apache.archiva</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.archiva</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository</artifactId>
<name>Archiva Base :: Repository</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
</dependencies>
<artifactId>archiva-repository</artifactId>
<name>Archiva Base :: Repository</name>
<dependencies>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-layer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-repository-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-spring</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -23,11 +23,14 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.archiva.repository.api.Repository;
import org.apache.archiva.repository.api.RepositoryFactory;
import org.apache.log4j.Logger;
import org.apache.maven.archiva.repository.ManagedRepositoryContent;
import org.apache.maven.archiva.repository.RepositoryContentFactory;
public class DefaultRepositoryFactory implements RepositoryFactory
{
private static final Logger log = Logger.getLogger(DefaultRepositoryFactory.class);
private final RepositoryContentFactory repositoryContentFactory;
public DefaultRepositoryFactory(RepositoryContentFactory repositoryContentFactory)
@ -41,7 +44,14 @@ public class DefaultRepositoryFactory implements RepositoryFactory
final HashMap<String, Repository> repositories = new HashMap<String, Repository>();
for (final String repositoryId : contentMap.keySet())
{
repositories.put(repositoryId, contentMap.get(repositoryId));
final ManagedRepositoryContent content = contentMap.get(repositoryId);
if (!content.getLocalPath().exists() && !content.getLocalPath().mkdirs())
{
log.error("Directory could not be created for repository <" + content.getId() + "> with missing directory");
}
repositories.put(repositoryId, content);
}
return repositories;
}

View File

@ -1,5 +1,24 @@
package org.apache.archiva.repository;
/*
* 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.
*/
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

View File

@ -0,0 +1,135 @@
package org.apache.archiva.repository;
/*
* 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.
*/
import java.io.File;
import org.apache.archiva.repository.api.Repository;
import org.apache.archiva.repository.api.RepositoryFactory;
import org.apache.commons.io.FileUtils;
import org.apache.maven.archiva.configuration.ArchivaConfiguration;
import org.apache.maven.archiva.configuration.Configuration;
import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
import org.codehaus.plexus.spring.PlexusInSpringTestCase;
public class DefaultRepositoryFactoryTest extends PlexusInSpringTestCase
{
private static final String NEW_REPOSITORY_ID = "new-id";
private static final String NEW_REPOSITORY_NAME = "New Repository";
protected static final String REPOID_INTERNAL = "internal";
private ArchivaConfiguration archivaConfiguration;
private File repoRootInternal;
private RepositoryFactory repositoryFactory;
public void testGetRepository()
throws Exception
{
assertRepositoryValid( repositoryFactory, REPOID_INTERNAL );
}
public void testGetRepositoryAfterDelete()
throws Exception
{
assertNotNull( repositoryFactory );
Configuration c = archivaConfiguration.getConfiguration();
c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
saveConfiguration( archivaConfiguration );
Repository repository = repositoryFactory.getRepositories().get(REPOID_INTERNAL);
assertNull( repository );
}
public void testGetRepositoryAfterAdd()
throws Exception
{
assertNotNull( repositoryFactory );
Configuration c = archivaConfiguration.getConfiguration();
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId( NEW_REPOSITORY_ID );
repo.setName( NEW_REPOSITORY_NAME );
File repoRoot = new File( getBasedir(), "target/test-repository-root" );
if ( !repoRoot.exists() )
{
repoRoot.mkdirs();
}
repo.setLocation( repoRoot.getAbsolutePath() );
c.addManagedRepository( repo );
saveConfiguration( archivaConfiguration );
Repository repository = repositoryFactory.getRepositories().get(NEW_REPOSITORY_ID);
assertNotNull( repository );
assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
// check other is still intact
assertRepositoryValid( repositoryFactory, REPOID_INTERNAL );
}
@Override
protected String getPlexusConfigLocation()
{
return "org/apache/archiva/repository/DefaultRepositoryFactoryTest.xml";
}
protected ManagedRepositoryConfiguration createManagedRepository( String id, String name, File location )
{
ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
return repo;
}
protected void saveConfiguration( ArchivaConfiguration archivaConfiguration )
throws Exception
{
archivaConfiguration.save( archivaConfiguration.getConfiguration() );
}
protected void assertRepositoryValid( RepositoryFactory repositoryFactory, String repoId )
{
Repository repository = repositoryFactory.getRepositories().get(repoId);
assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", repository.getLocalPath().exists()
&& repository.getLocalPath().isDirectory() );
}
@Override
protected void setUp() throws Exception
{
super.setUp();
String appserverBase = getTestFile( "target/appserver-base" ).getAbsolutePath();
System.setProperty( "appserver.base", appserverBase );
File testConf = getTestFile( "src/test/resources/repository-archiva.xml" );
File testConfDest = new File( appserverBase, "conf/archiva.xml" );
FileUtils.copyFile( testConf, testConfDest );
archivaConfiguration = (ArchivaConfiguration) lookup( ArchivaConfiguration.class );
repoRootInternal = new File( appserverBase, "data/repositories/internal" );
Configuration config = archivaConfiguration.getConfiguration();
config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
saveConfiguration( archivaConfiguration );
repositoryFactory = (RepositoryFactory)lookup(RepositoryFactory.class);
}
}

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<plexus>
<components>
<!--
| Logger manager
<component>
<role>org.codehaus.plexus.logging.LoggerManager</role>
<implementation>org.codehaus.plexus.logging.slf4j.Slf4jLoggerManager</implementation>
<lifecycle-handler>basic</lifecycle-handler>
</component>
-->
<!--
| Configuration
-->
<component>
<role>org.apache.maven.archiva.configuration.ArchivaConfiguration</role>
<implementation>org.apache.maven.archiva.configuration.DefaultArchivaConfiguration</implementation>
<requirements>
<requirement>
<role>org.codehaus.plexus.registry.Registry</role>
<role-hint>configured</role-hint>
</requirement>
<requirement>
<role>org.apache.maven.archiva.policies.PreDownloadPolicy</role>
<field-name>prePolicies</field-name>
</requirement>
<requirement>
<role>org.apache.maven.archiva.policies.PostDownloadPolicy</role>
<field-name>postPolicies</field-name>
</requirement>
</requirements>
</component>
<component>
<role>org.codehaus.plexus.registry.Registry</role>
<role-hint>configured</role-hint>
<implementation>org.codehaus.plexus.registry.commons.CommonsConfigurationRegistry</implementation>
<configuration>
<properties>
<system/>
<xml fileName="${appserver.base}/conf/archiva.xml"
config-name="org.apache.maven.archiva.base" config-at="org.apache.maven.archiva"/>
</properties>
</configuration>
</component>
<component>
<role>org.codehaus.plexus.cache.Cache</role>
<role-hint>url-failures-cache</role-hint>
<implementation>org.codehaus.plexus.cache.ehcache.EhcacheCache</implementation>
<description>URL Failure Cache</description>
<configuration>
<disk-expiry-thread-interval-seconds>600</disk-expiry-thread-interval-seconds>
<disk-persistent>false</disk-persistent> <!--disabling disk persistence for unit testing. -->
<disk-store-path>${java.io.tmpdir}/archiva/urlcache</disk-store-path>
<eternal>false</eternal>
<max-elements-in-memory>1000</max-elements-in-memory>
<memory-eviction-policy>LRU</memory-eviction-policy>
<name>url-failures-cache</name>
<overflow-to-disk>false</overflow-to-disk>
<!-- 45 minutes = 2700 seconds -->
<time-to-idle-seconds>2700</time-to-idle-seconds>
<!-- 30 minutes = 1800 seconds -->
<time-to-live-seconds>1800</time-to-live-seconds>
</configuration>
</component>
</components>
</plexus>

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<configuration>
<version>2</version>
<repositoryScanning>
<fileTypes>
<fileType>
<id>artifacts</id>
<patterns>
<pattern>**/*.pom</pattern>
<pattern>**/*.jar</pattern>
<pattern>**/*.ear</pattern>
<pattern>**/*.war</pattern>
<pattern>**/*.car</pattern>
<pattern>**/*.sar</pattern>
<pattern>**/*.mar</pattern>
<pattern>**/*.rar</pattern>
<pattern>**/*.dtd</pattern>
<pattern>**/*.tld</pattern>
<pattern>**/*.tar.gz</pattern>
<pattern>**/*.tar.bz2</pattern>
<pattern>**/*.zip</pattern>
</patterns>
</fileType>
<fileType>
<id>indexable-content</id>
<patterns>
<pattern>**/*.txt</pattern>
<pattern>**/*.TXT</pattern>
<pattern>**/*.block</pattern>
<pattern>**/*.config</pattern>
<pattern>**/*.pom</pattern>
<pattern>**/*.xml</pattern>
<pattern>**/*.xsd</pattern>
<pattern>**/*.dtd</pattern>
<pattern>**/*.tld</pattern>
</patterns>
</fileType>
<fileType>
<id>auto-remove</id>
<patterns>
<pattern>**/*.bak</pattern>
<pattern>**/*~</pattern>
<pattern>**/*-</pattern>
</patterns>
</fileType>
<fileType>
<id>ignored</id>
<patterns>
<pattern>**/.htaccess</pattern>
<pattern>**/KEYS</pattern>
<pattern>**/*.rb</pattern>
<pattern>**/*.sh</pattern>
<pattern>**/.svn/**</pattern>
<pattern>**/.DAV/**</pattern>
</patterns>
</fileType>
</fileTypes>
<knownContentConsumers>
<knownContentConsumer>update-db-artifact</knownContentConsumer>
<knownContentConsumer>create-missing-checksums</knownContentConsumer>
<knownContentConsumer>update-db-repository-metadata</knownContentConsumer>
<knownContentConsumer>validate-checksum</knownContentConsumer>
<knownContentConsumer>validate-signature</knownContentConsumer>
<knownContentConsumer>index-content</knownContentConsumer>
<knownContentConsumer>auto-remove</knownContentConsumer>
<knownContentConsumer>auto-rename</knownContentConsumer>
</knownContentConsumers>
<invalidContentConsumers>
<invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
</invalidContentConsumers>
</repositoryScanning>
<databaseScanning>
<cronExpression>0 0 * * * ?</cronExpression>
<unprocessedConsumers>
<unprocessedConsumer>index-artifact</unprocessedConsumer>
<unprocessedConsumer>update-db-project</unprocessedConsumer>
<unprocessedConsumer>validate-repository-metadata</unprocessedConsumer>
<unprocessedConsumer>index-archive-toc</unprocessedConsumer>
<unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer>
<unprocessedConsumer>index-public-methods</unprocessedConsumer>
</unprocessedConsumers>
<cleanupConsumers>
<cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer>
<cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
<cleanupConsumer>not-present-remove-indexed</cleanupConsumer>
</cleanupConsumers>
</databaseScanning>
</configuration>

View File

@ -40,7 +40,8 @@
<module>archiva-transaction</module>
<module>archiva-artifact-converter</module>
<module>archiva-converter</module>
<module>archiva-repository-api</module>
<module>archiva-repository-api</module>
<module>archiva-repository</module>
<module>archiva-event</module>
</modules>
</project>
</project>

View File

@ -74,16 +74,6 @@ public abstract class AbstractRepositoryServletTestCase
assertEquals( "File Contents of <" + actualFile.getAbsolutePath() + ">", expectedContents, actualContents );
}
protected void assertRepositoryValid( RepositoryServlet servlet, String repoId )
{
// ManagedRepositoryConfiguration repository = servlet.getRepository( repoId );
// assertNotNull( "Archiva Managed Repository id:<" + repoId + "> should exist.", repository );
// File repoRoot = new File( repository.getLocation() );
// assertTrue( "Archiva Managed Repository id:<" + repoId + "> should have a valid location on disk.", repoRoot
// .exists()
// && repoRoot.isDirectory() );
}
protected void assertResponseOK( WebResponse response )
{
assertNotNull( "Should have recieved a response", response );

View File

@ -39,62 +39,6 @@ public class RepositoryServletTest
{
private static final String REQUEST_PATH = "http://machine.com/repository/internal/";
private static final String NEW_REPOSITORY_ID = "new-id";
private static final String NEW_REPOSITORY_NAME = "New Repository";
public void testGetRepository()
throws Exception
{
RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
assertNotNull( servlet );
assertRepositoryValid( servlet, REPOID_INTERNAL );
}
//
// public void testGetRepositoryAfterDelete()
// throws Exception
// {
// RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
// assertNotNull( servlet );
//
// ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
// Configuration c = archivaConfiguration.getConfiguration();
// c.removeManagedRepository( c.findManagedRepositoryById( REPOID_INTERNAL ) );
// saveConfiguration( archivaConfiguration );
//
// ManagedRepositoryConfiguration repository = servlet.getRepository( REPOID_INTERNAL );
// assertNull( repository );
// }
//
// public void testGetRepositoryAfterAdd()
// throws Exception
// {
// RepositoryServlet servlet = (RepositoryServlet) sc.newInvocation( REQUEST_PATH ).getServlet();
// assertNotNull( servlet );
//
// ArchivaConfiguration archivaConfiguration = servlet.getConfiguration();
// Configuration c = archivaConfiguration.getConfiguration();
// ManagedRepositoryConfiguration repo = new ManagedRepositoryConfiguration();
// repo.setId( NEW_REPOSITORY_ID );
// repo.setName( NEW_REPOSITORY_NAME );
// File repoRoot = new File( getBasedir(), "target/test-repository-root" );
// if ( !repoRoot.exists() )
// {
// repoRoot.mkdirs();
// }
// repo.setLocation( repoRoot.getAbsolutePath() );
// c.addManagedRepository( repo );
// saveConfiguration( archivaConfiguration );
//
// ManagedRepositoryConfiguration repository = servlet.getRepository( NEW_REPOSITORY_ID );
// assertNotNull( repository );
// assertEquals( NEW_REPOSITORY_NAME, repository.getName() );
//
// // check other is still intact
// assertRepositoryValid( servlet, REPOID_INTERNAL );
// }
public void testGetRepositoryInvalidPathPassthroughPresent()
throws Exception
{
@ -116,6 +60,6 @@ public class RepositoryServletTest
WebRequest request = new GetMethodWebRequest( path );
WebResponse response = sc.getResponse( request );
assertResponseNotFound( response );
assertEquals( "Invalid path to Artifact: legacy paths should have an expected type ending in [s] in the second part of the path.", response.getResponseMessage() );
assertEquals( "Could not find /internal/.index/filecontent/foo.bar", response.getResponseMessage() );
}
}

View File

@ -310,6 +310,11 @@
<artifactId>archiva-common</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-event</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
<artifactId>archiva-configuration</artifactId>