summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/pom.xml15
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java37
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/AbstractRepositoryAdminTest.java5
-rw-r--r--archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java42
4 files changed, 84 insertions, 15 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml
index 9406abd88..f0841c946 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/pom.xml
+++ b/archiva-modules/archiva-base/archiva-repository-admin/pom.xml
@@ -109,4 +109,19 @@
</dependency>
</dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemPropertyVariables>
+ <appserver.base>${project.build.outputDirectory}</appserver.base>
+ </systemPropertyVariables>
+ </configuration>
+
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
index 15c41070e..290a3944f 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/main/java/org/apache/archiva/admin/repository/managed/DefaultManagedRepositoryAdmin.java
@@ -107,12 +107,6 @@ public class DefaultManagedRepositoryAdmin
return null;
}
- public Boolean deleteManagedRepository( String repositoryId )
- throws RepositoryAdminException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo )
throws RepositoryAdminException
{
@@ -133,35 +127,41 @@ public class DefaultManagedRepositoryAdmin
Configuration config = archivaConfiguration.getConfiguration();
- CronExpressionValidator validator = new CronExpressionValidator();
-
if ( config.getManagedRepositoriesAsMap().containsKey( repoId ) )
{
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a managed repository." );
}
- else if ( config.getRemoteRepositoriesAsMap().containsKey( repoId ) )
- {
- throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
- + "], that id already exists as a remote repository." );
- }
else if ( config.getRepositoryGroupsAsMap().containsKey( repoId ) )
{
throw new RepositoryAdminException( "Unable to add new repository with id [" + repoId
+ "], that id already exists as a repository group." );
}
- if ( !validator.validate( cronExpression ) )
+ // FIXME : olamy can be empty to avoid scheduled scan ?
+ if ( StringUtils.isNotBlank( cronExpression ) )
{
- throw new RepositoryAdminException( "Invalid cron expression." );
+ CronExpressionValidator validator = new CronExpressionValidator();
+
+ if ( !validator.validate( cronExpression ) )
+ {
+ throw new RepositoryAdminException( "Invalid cron expression." );
+ }
}
+ // FIXME checKid non empty
+
if ( !GenericValidator.matchRegexp( repoId, REPOSITORY_ID_VALID_EXPRESSION ) )
{
throw new RepositoryAdminException(
"Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
}
+ if ( StringUtils.isBlank( name ) )
+ {
+ throw new RepositoryAdminException( "repository name cannot be empty" );
+ }
+
if ( !GenericValidator.matchRegexp( name, REPOSITORY_NAME_VALID_EXPRESSION ) )
{
throw new RepositoryAdminException(
@@ -232,6 +232,13 @@ public class DefaultManagedRepositoryAdmin
return null; //To change body of implemented methods use File | Settings | File Templates.
}
+
+ public Boolean deleteManagedRepository( String repositoryId )
+ throws RepositoryAdminException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
//--------------------------
// utils methods
//--------------------------
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/AbstractRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/AbstractRepositoryAdminTest.java
index 753dfa522..59498113c 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/AbstractRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/AbstractRepositoryAdminTest.java
@@ -20,6 +20,8 @@ package org.apache.archiva.admin.repository.managed;
import junit.framework.TestCase;
import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -31,5 +33,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public abstract class AbstractRepositoryAdminTest
extends TestCase
{
+ protected Logger log = LoggerFactory.getLogger( getClass() );
+
+ public static final String APPSERVER_BASE_PATH = System.getProperty( "appserver.base" );
// no op
}
diff --git a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
index 907c4145e..9e01fc2b9 100644
--- a/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
+++ b/archiva-modules/archiva-base/archiva-repository-admin/src/test/java/org/apache/archiva/admin/repository/managed/ManagedRepositoryAdminTest.java
@@ -18,6 +18,7 @@ package org.apache.archiva.admin.repository.managed;
* under the License.
*/
+import org.apache.commons.lang.StringUtils;
import org.junit.Test;
import javax.inject.Inject;
@@ -40,6 +41,13 @@ public class ManagedRepositoryAdminTest
List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
assertNotNull( repos );
assertTrue( repos.size() > 0 );
+ log.info( "repos " + repos );
+
+ // check default internal
+ ManagedRepository internal = findManagedRepoById( repos, "internal" );
+ assertNotNull( internal );
+ assertTrue( internal.isReleases() );
+ assertFalse( internal.isSnapshots() );
}
@Test
@@ -50,4 +58,38 @@ public class ManagedRepositoryAdminTest
assertNotNull( repo );
}
+ @Test
+ public void addManagedRepo()
+ throws Exception
+ {
+ List<ManagedRepository> repos = managedRepositoryAdmin.getManagedRepositories();
+ assertNotNull( repos );
+ int initialSize = repos.size();
+ assertTrue( initialSize > 0 );
+
+ ManagedRepository repo = new ManagedRepository();
+ repo.setId( "test-new-one" );
+ repo.setName( "test repo" );
+ repo.setUrl( APPSERVER_BASE_PATH + repo.getId() );
+ managedRepositoryAdmin.addManagedRepository( repo, false );
+ repos = managedRepositoryAdmin.getManagedRepositories();
+ assertNotNull( repos );
+ assertEquals( initialSize + 1, repos.size() );
+
+ assertNotNull( managedRepositoryAdmin.getManagedRepository( "test-new-one" ) );
+ }
+
+
+ private ManagedRepository findManagedRepoById( List<ManagedRepository> repos, String id )
+ {
+ for ( ManagedRepository repo : repos )
+ {
+ if ( StringUtils.equals( id, repo.getId() ) )
+ {
+ return repo;
+ }
+ }
+ return null;
+ }
+
}