1 package org.apache.archiva.admin.repository.admin;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import net.sf.beanlib.provider.replicator.BeanReplicator;
22 import org.apache.archiva.admin.AuditInformation;
23 import org.apache.archiva.admin.repository.AbstractRepositoryAdmin;
24 import org.apache.archiva.admin.repository.RepositoryAdminException;
25 import org.apache.archiva.audit.AuditEvent;
26 import org.apache.commons.lang.StringUtils;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
29 import org.springframework.stereotype.Service;
31 import java.util.ArrayList;
32 import java.util.List;
35 * @author Olivier Lamy
37 @Service( "archivaAdministration#default" )
38 public class DefaultArchivaAdministration
39 extends AbstractRepositoryAdmin
40 implements ArchivaAdministration
42 public List<LegacyArtifactPath> getLegacyArtifactPaths()
43 throws RepositoryAdminException
45 List<LegacyArtifactPath> legacyArtifactPaths = new ArrayList<LegacyArtifactPath>();
46 for ( org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath : getArchivaConfiguration().getConfiguration().getLegacyArtifactPaths() )
48 legacyArtifactPaths.add(
49 new BeanReplicator().replicateBean( legacyArtifactPath, LegacyArtifactPath.class ) );
51 return legacyArtifactPaths;
55 public void addLegacyArtifactPath( LegacyArtifactPath legacyArtifactPath, AuditInformation auditInformation )
56 throws RepositoryAdminException
58 Configuration configuration = getArchivaConfiguration().getConfiguration();
60 configuration.addLegacyArtifactPath( new BeanReplicator().replicateBean( legacyArtifactPath,
61 org.apache.maven.archiva.configuration.LegacyArtifactPath.class ) );
63 saveConfiguration( configuration );
64 triggerAuditEvent( "", "", AuditEvent.ADD_LEGACY_PATH, auditInformation );
67 public void deleteLegacyArtifactPath( String path, AuditInformation auditInformation )
68 throws RepositoryAdminException
70 Configuration configuration = getArchivaConfiguration().getConfiguration();
71 org.apache.maven.archiva.configuration.LegacyArtifactPath legacyArtifactPath =
72 new org.apache.maven.archiva.configuration.LegacyArtifactPath();
74 legacyArtifactPath.setPath( path );
75 configuration.removeLegacyArtifactPath( legacyArtifactPath );
77 saveConfiguration( configuration );
78 triggerAuditEvent( "", "", AuditEvent.REMOVE_LEGACY_PATH, auditInformation );
81 public void updateRepositoryScanning( RepositoryScanning repositoryScanning, AuditInformation auditInformation )
82 throws RepositoryAdminException
84 Configuration configuration = getArchivaConfiguration().getConfiguration();
86 configuration.setRepositoryScanning(
87 new BeanReplicator().replicateBean( repositoryScanning, RepositoryScanningConfiguration.class ) );
89 saveConfiguration( configuration );
92 public RepositoryScanning getRepositoryScanning()
93 throws RepositoryAdminException
95 return new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
96 RepositoryScanning.class );
99 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
100 throws RepositoryAdminException
102 Configuration configuration = getArchivaConfiguration().getConfiguration();
104 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
105 if ( fileType == null )
109 fileType.addPattern( pattern );
111 saveConfiguration( configuration );
112 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
115 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
116 throws RepositoryAdminException
118 Configuration configuration = getArchivaConfiguration().getConfiguration();
120 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
121 if ( fileType == null )
125 fileType.removePattern( pattern );
127 saveConfiguration( configuration );
128 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
131 public FileType getFileType( String fileTypeId )
132 throws RepositoryAdminException
134 org.apache.maven.archiva.configuration.FileType fileType =
135 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
136 if ( fileType == null )
140 return new BeanReplicator().replicateBean( fileType, FileType.class );
143 public void addFileType( FileType fileType, AuditInformation auditInformation )
144 throws RepositoryAdminException
146 Configuration configuration = getArchivaConfiguration().getConfiguration();
147 if ( getFileTypeById( fileType.getId(), configuration ) != null )
149 throw new RepositoryAdminException(
150 "impossible to FileType with id " + fileType.getId() + " already exists" );
153 configuration.getRepositoryScanning().addFileType(
154 new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
155 saveConfiguration( configuration );
158 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
159 throws RepositoryAdminException
161 Configuration configuration = getArchivaConfiguration().getConfiguration();
162 org.apache.maven.archiva.configuration.FileType fileType =
163 new org.apache.maven.archiva.configuration.FileType();
164 fileType.setId( fileTypeId );
165 configuration.getRepositoryScanning().removeFileType( fileType );
166 saveConfiguration( configuration );
169 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
170 throws RepositoryAdminException
172 Configuration configuration = getArchivaConfiguration().getConfiguration();
173 if ( configuration.getRepositoryScanning().getKnownContentConsumers().contains( knownContentConsumer ) )
175 log.warn( "skip adding knownContentConsumer {} as already here", knownContentConsumer );
178 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
179 saveConfiguration( configuration );
180 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
183 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
184 throws RepositoryAdminException
186 Configuration configuration = getArchivaConfiguration().getConfiguration();
187 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
188 saveConfiguration( configuration );
189 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
192 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
193 throws RepositoryAdminException
195 Configuration configuration = getArchivaConfiguration().getConfiguration();
196 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().contains( invalidContentConsumer ) )
198 log.warn( "skip adding invalidContentConsumer {} as already here", invalidContentConsumer );
201 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
202 saveConfiguration( configuration );
203 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
206 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
207 throws RepositoryAdminException
209 Configuration configuration = getArchivaConfiguration().getConfiguration();
210 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
211 saveConfiguration( configuration );
212 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
215 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
216 throws RepositoryAdminException
218 if ( knownContentConsumers == null )
222 for ( String knowContentConsumer : knownContentConsumers )
224 addKnownContentConsumer( knowContentConsumer, auditInformation );
228 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
229 throws RepositoryAdminException
231 if ( invalidContentConsumers == null )
235 for ( String invalidContentConsumer : invalidContentConsumers )
237 addKnownContentConsumer( invalidContentConsumer, auditInformation );
241 //-------------------------
243 //-------------------------
245 private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
247 for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
249 if ( StringUtils.equals( id, fileType.getId() ) )