1 package org.apache.maven.archiva.consumers.core.repository;
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.maven.archiva.repository.layout.FilenameParts;
23 import org.apache.maven.archiva.repository.layout.LayoutException;
24 import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
25 import org.apache.maven.archiva.common.utils.VersionUtil;
26 import org.apache.maven.archiva.configuration.RepositoryConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.indexer.RepositoryIndexException;
29 import org.apache.maven.archiva.model.ArchivaRepository;
30 import org.apache.maven.archiva.database.ArtifactDAO;
32 import java.util.Calendar;
33 import java.util.GregorianCalendar;
37 * Purge repository for snapshots older than the specified days in the repository configuration.
39 * @author <a href="mailto:oching@apache.org">Maria Odea Ching</a>
42 public class DaysOldRepositoryPurge
43 extends AbstractRepositoryPurge
45 private RepositoryConfiguration repoConfig;
47 public DaysOldRepositoryPurge( ArchivaRepository repository,
48 BidirectionalRepositoryLayout layout, ArtifactDAO artifactDao,
49 RepositoryConfiguration repoConfig)
51 super( repository, layout, artifactDao );
52 this.repoConfig = repoConfig;
55 public void process( String path )
56 throws RepositoryPurgeException
60 File artifactFile = new File( repository.getUrl().getPath(), path );
62 if( !artifactFile.exists() )
67 FilenameParts parts = getFilenameParts( path );
69 if ( VersionUtil.isSnapshot( parts.version ) )
71 Calendar olderThanThisDate = Calendar.getInstance();
72 olderThanThisDate.add( Calendar.DATE, ( -1 * repoConfig.getDaysOlder() ) );
74 if ( artifactFile.lastModified() < olderThanThisDate.getTimeInMillis() )
76 String[] fileParts = artifactFile.getName().split( "." + parts.extension );
78 File[] artifactFiles = getFiles( artifactFile.getParentFile(), fileParts[0] );
80 purge( artifactFiles );
84 catch ( LayoutException le )
86 throw new RepositoryPurgeException( le.getMessage() );