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
96 RepositoryScanning repositoryScanning =
97 new BeanReplicator().replicateBean( getArchivaConfiguration().getConfiguration().getRepositoryScanning(),
98 RepositoryScanning.class )
100 return repositoryScanning;
103 public void addFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
104 throws RepositoryAdminException
106 Configuration configuration = getArchivaConfiguration().getConfiguration();
108 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
109 if ( fileType == null )
113 fileType.addPattern( pattern );
115 saveConfiguration( configuration );
116 triggerAuditEvent( "", "", AuditEvent.ADD_PATTERN, auditInformation );
119 public void removeFileTypePattern( String fileTypeId, String pattern, AuditInformation auditInformation )
120 throws RepositoryAdminException
122 Configuration configuration = getArchivaConfiguration().getConfiguration();
124 org.apache.maven.archiva.configuration.FileType fileType = getFileTypeById( fileTypeId, configuration );
125 if ( fileType == null )
129 fileType.removePattern( pattern );
131 saveConfiguration( configuration );
132 triggerAuditEvent( "", "", AuditEvent.REMOVE_PATTERN, auditInformation );
135 public FileType getFileType( String fileTypeId )
136 throws RepositoryAdminException
138 org.apache.maven.archiva.configuration.FileType fileType =
139 getFileTypeById( fileTypeId, getArchivaConfiguration().getConfiguration() );
140 if ( fileType == null )
144 return new BeanReplicator().replicateBean( fileType, FileType.class );
147 public void addFileType( FileType fileType, AuditInformation auditInformation )
148 throws RepositoryAdminException
150 Configuration configuration = getArchivaConfiguration().getConfiguration();
151 if ( getFileTypeById( fileType.getId(), configuration ) != null )
153 throw new RepositoryAdminException(
154 "impossible to FileType with id " + fileType.getId() + " already exists" );
157 configuration.getRepositoryScanning().addFileType(
158 new BeanReplicator().replicateBean( fileType, org.apache.maven.archiva.configuration.FileType.class ) );
159 saveConfiguration( configuration );
162 public void removeFileType( String fileTypeId, AuditInformation auditInformation )
163 throws RepositoryAdminException
165 Configuration configuration = getArchivaConfiguration().getConfiguration();
166 org.apache.maven.archiva.configuration.FileType fileType =
167 new org.apache.maven.archiva.configuration.FileType();
168 fileType.setId( fileTypeId );
169 configuration.getRepositoryScanning().removeFileType( fileType );
170 saveConfiguration( configuration );
173 public void addKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
174 throws RepositoryAdminException
176 Configuration configuration = getArchivaConfiguration().getConfiguration();
177 if ( configuration.getRepositoryScanning().getKnownContentConsumers().contains( knownContentConsumer ) )
179 log.warn( "skip adding knownContentConsumer {} as already here", knownContentConsumer );
182 configuration.getRepositoryScanning().addKnownContentConsumer( knownContentConsumer );
183 saveConfiguration( configuration );
184 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
187 public void removeKnownContentConsumer( String knownContentConsumer, AuditInformation auditInformation )
188 throws RepositoryAdminException
190 Configuration configuration = getArchivaConfiguration().getConfiguration();
191 configuration.getRepositoryScanning().removeKnownContentConsumer( knownContentConsumer );
192 saveConfiguration( configuration );
193 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
196 public void addInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
197 throws RepositoryAdminException
199 Configuration configuration = getArchivaConfiguration().getConfiguration();
200 if ( configuration.getRepositoryScanning().getInvalidContentConsumers().contains( invalidContentConsumer ) )
202 log.warn( "skip adding invalidContentConsumer {} as already here", invalidContentConsumer );
205 configuration.getRepositoryScanning().addInvalidContentConsumer( invalidContentConsumer );
206 saveConfiguration( configuration );
207 triggerAuditEvent( "", "", AuditEvent.ENABLE_REPO_CONSUMER, auditInformation );
210 public void removeInvalidContentConsumer( String invalidContentConsumer, AuditInformation auditInformation )
211 throws RepositoryAdminException
213 Configuration configuration = getArchivaConfiguration().getConfiguration();
214 configuration.getRepositoryScanning().removeInvalidContentConsumer( invalidContentConsumer );
215 saveConfiguration( configuration );
216 triggerAuditEvent( "", "", AuditEvent.DISABLE_REPO_CONSUMER, auditInformation );
219 public void setKnownContentConsumers( List<String> knownContentConsumers, AuditInformation auditInformation )
220 throws RepositoryAdminException
222 if ( knownContentConsumers == null )
226 for ( String knowContentConsumer : knownContentConsumers )
228 addKnownContentConsumer( knowContentConsumer, auditInformation );
232 public void setInvalidContentConsumers( List<String> invalidContentConsumers, AuditInformation auditInformation )
233 throws RepositoryAdminException
235 if ( invalidContentConsumers == null )
239 for ( String invalidContentConsumer : invalidContentConsumers )
241 addKnownContentConsumer( invalidContentConsumer, auditInformation );
245 //-------------------------
247 //-------------------------
249 private org.apache.maven.archiva.configuration.FileType getFileTypeById( String id, Configuration configuration )
251 for ( org.apache.maven.archiva.configuration.FileType fileType : configuration.getRepositoryScanning().getFileTypes() )
253 if ( StringUtils.equals( id, fileType.getId() ) )