1 package org.apache.maven.archiva.web.action.admin.repositories;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.archiva.configuration.Configuration;
24 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
25 import org.codehaus.plexus.redback.role.RoleManager;
26 import org.codehaus.plexus.redback.role.RoleManagerException;
29 import java.io.IOException;
32 * Abstract ManagedRepositories Action.
34 * Place for all generic methods used in Managed Repository Administration.
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public abstract class AbstractManagedRepositoriesAction
40 extends AbstractRepositoriesAdminAction
43 * @plexus.requirement role-hint="default"
45 protected RoleManager roleManager;
47 public RoleManager getRoleManager()
52 public void setRoleManager( RoleManager roleManager )
54 this.roleManager = roleManager;
57 protected void addRepository( ManagedRepositoryConfiguration repository, Configuration configuration )
61 File file = new File( repository.getLocation() );
62 repository.setLocation( file.getCanonicalPath() );
67 if ( !file.exists() || !file.isDirectory() )
69 throw new IOException( "unable to add repository - can not create the root directory: " + file );
72 configuration.addManagedRepository( repository );
76 protected void addRepositoryRoles( ManagedRepositoryConfiguration newRepository ) throws RoleManagerException
78 // TODO: double check these are configured on start up
79 // TODO: belongs in the business logic
80 roleManager.createTemplatedRole( "archiva-repository-manager", newRepository.getId() );
81 roleManager.createTemplatedRole( "archiva-repository-observer", newRepository.getId() );
84 protected void removeContents( ManagedRepositoryConfiguration existingRepository )
87 FileUtils.deleteDirectory( new File( existingRepository.getLocation() ) );
90 protected void removeRepository( String repoId, Configuration configuration )
92 ManagedRepositoryConfiguration toremove = configuration.findManagedRepositoryById( repoId );
93 if ( toremove != null )
95 configuration.removeManagedRepository( toremove );
99 protected void removeRepositoryRoles( ManagedRepositoryConfiguration existingRepository )
100 throws RoleManagerException
102 roleManager.removeTemplatedRole( "archiva-repository-manager", existingRepository.getId() );
103 roleManager.removeTemplatedRole( "archiva-repository-observer", existingRepository.getId() );
105 getLogger().debug( "removed user roles associated with repository " + existingRepository.getId() );