1 package org.apache.archiva.admin.repository.runtime;
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.model.RepositoryAdminException;
23 import org.apache.archiva.admin.model.beans.ArchivaRuntimeConfiguration;
24 import org.apache.archiva.admin.model.beans.CacheConfiguration;
25 import org.apache.archiva.admin.model.beans.FileLockConfiguration;
26 import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin;
27 import org.apache.archiva.configuration.ArchivaConfiguration;
28 import org.apache.archiva.configuration.Configuration;
29 import org.apache.archiva.configuration.IndeterminateConfigurationException;
30 import org.apache.archiva.redback.components.cache.Cache;
31 import org.apache.archiva.redback.components.registry.RegistryException;
32 import org.springframework.stereotype.Service;
34 import javax.annotation.PostConstruct;
35 import javax.inject.Inject;
36 import javax.inject.Named;
39 * @author Olivier Lamy
42 @Service( "archivaRuntimeConfigurationAdmin#default" )
43 public class DefaultArchivaRuntimeConfigurationAdmin
44 implements ArchivaRuntimeConfigurationAdmin
48 private ArchivaConfiguration archivaConfiguration;
51 @Named( value = "cache#url-failures-cache" )
52 private Cache urlFailureCache;
55 public void initialize()
56 throws RepositoryAdminException
58 ArchivaRuntimeConfiguration archivaRuntimeConfiguration = getArchivaRuntimeConfiguration();
63 if ( archivaRuntimeConfiguration.getFileLockConfiguration() == null )
65 archivaRuntimeConfiguration.setFileLockConfiguration( new FileLockConfiguration() );
69 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() == null )
71 archivaRuntimeConfiguration.setUrlFailureCacheConfiguration( new CacheConfiguration() );
74 // if -1 it means non initialized to take values from the spring bean
75 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds() < 0 )
77 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToIdleSeconds(
78 urlFailureCache.getTimeToIdleSeconds() );
82 urlFailureCache.setTimeToIdleSeconds(
83 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToIdleSeconds() );
85 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds() < 0 )
87 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setTimeToLiveSeconds(
88 urlFailureCache.getTimeToLiveSeconds() );
92 urlFailureCache.setTimeToLiveSeconds(
93 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getTimeToLiveSeconds() );
95 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory() < 0 )
97 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsInMemory(
98 urlFailureCache.getMaxElementsInMemory() );
101 urlFailureCache.setMaxElementsInMemory(
102 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsInMemory() );
104 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk() < 0 )
106 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().setMaxElementsOnDisk(
107 urlFailureCache.getMaxElementsOnDisk() );
110 urlFailureCache.setMaxElementsOnDisk(
111 archivaRuntimeConfiguration.getUrlFailureCacheConfiguration().getMaxElementsOnDisk() );
115 updateArchivaRuntimeConfiguration( archivaRuntimeConfiguration );
120 public ArchivaRuntimeConfiguration getArchivaRuntimeConfiguration()
121 throws RepositoryAdminException
123 return build( archivaConfiguration.getConfiguration().getArchivaRuntimeConfiguration() );
126 public void updateArchivaRuntimeConfiguration( ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
127 throws RepositoryAdminException
129 Configuration configuration = archivaConfiguration.getConfiguration();
130 configuration.setArchivaRuntimeConfiguration( build( archivaRuntimeConfiguration ) );
133 archivaConfiguration.save( configuration );
135 catch ( RegistryException e )
137 throw new RepositoryAdminException( e.getMessage(), e );
139 catch ( IndeterminateConfigurationException e )
141 throw new RepositoryAdminException( e.getMessage(), e );
145 protected ArchivaRuntimeConfiguration build(
146 org.apache.archiva.configuration.ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
148 if ( archivaRuntimeConfiguration == null )
150 return new ArchivaRuntimeConfiguration();
153 ArchivaRuntimeConfiguration res =
154 new BeanReplicator().replicateBean( archivaRuntimeConfiguration, ArchivaRuntimeConfiguration.class );
156 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() != null )
159 res.setUrlFailureCacheConfiguration(
160 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(),
161 CacheConfiguration.class ) );
165 if ( archivaRuntimeConfiguration.getFileLockConfiguration() != null )
167 res.setFileLockConfiguration(
168 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getFileLockConfiguration(),
169 FileLockConfiguration.class ) );
175 protected org.apache.archiva.configuration.ArchivaRuntimeConfiguration build(
176 ArchivaRuntimeConfiguration archivaRuntimeConfiguration )
178 if ( archivaRuntimeConfiguration == null )
180 return new org.apache.archiva.configuration.ArchivaRuntimeConfiguration();
183 org.apache.archiva.configuration.ArchivaRuntimeConfiguration res =
184 new BeanReplicator().replicateBean( archivaRuntimeConfiguration,
185 org.apache.archiva.configuration.ArchivaRuntimeConfiguration.class );
187 if ( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration() != null )
190 res.setUrlFailureCacheConfiguration(
191 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getUrlFailureCacheConfiguration(),
192 org.apache.archiva.configuration.CacheConfiguration.class ) );
196 if ( archivaRuntimeConfiguration.getFileLockConfiguration() != null )
198 res.setFileLockConfiguration(
199 new BeanReplicator().replicateBean( archivaRuntimeConfiguration.getFileLockConfiguration(),
200 org.apache.archiva.configuration.FileLockConfiguration.class ) );