001package org.apache.archiva.repository.features; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.time.Period; 023 024/** 025 * 026 * This feature provides settings for artifact cleanup. This is meant mainly for snapshot artifacts, 027 * that should be deleted after a time period. 028 * 029 */ 030public class ArtifactCleanupFeature implements RepositoryFeature<ArtifactCleanupFeature> { 031 032 private boolean deleteReleasedSnapshots = false; 033 private Period retentionPeriod = Period.ofDays(100); 034 private int retentionCount = 2; 035 036 public ArtifactCleanupFeature() { 037 038 } 039 040 public ArtifactCleanupFeature( boolean deleteReleasedSnapshots, Period retentionPeriod, int retentionCount) { 041 this.deleteReleasedSnapshots = deleteReleasedSnapshots; 042 this.retentionPeriod = retentionPeriod; 043 this.retentionCount = retentionCount; 044 } 045 046 @Override 047 public ArtifactCleanupFeature get() { 048 return this; 049 } 050 051 /** 052 * Returns true, if snapshot artifacts should be deleted, when artifacts with release version 053 * exist in one of the managed repositories. 054 * @return True, if artifacts should be deleted after release, otherwise false. 055 */ 056 public boolean isDeleteReleasedSnapshots() { 057 return deleteReleasedSnapshots; 058 } 059 060 /** 061 * Sets the flag for the deletion of released snapshot artifacts. 062 * @param deleteReleasedSnapshots 063 */ 064 public void setDeleteReleasedSnapshots(boolean deleteReleasedSnapshots) { 065 this.deleteReleasedSnapshots = deleteReleasedSnapshots; 066 } 067 068 /** 069 * Returns the amount of time after that, the (snapshot) artifacts can be deleted. 070 * 071 * @return The time period after that the artifacts can be deleted. 072 */ 073 public Period getRetentionPeriod() { 074 return retentionPeriod; 075 } 076 077 /** 078 * Sets time period, after that artifacts can be deleted. 079 * @param retentionPeriod 080 */ 081 public void setRetentionPeriod( Period retentionPeriod ) { 082 this.retentionPeriod = retentionPeriod; 083 } 084 085 /** 086 * Sets the number of (snapshot) artifacts that should be kept, even if they are older 087 * than the retention time. 088 * @return The number of artifacts for a version that should be kept 089 */ 090 public int getRetentionCount() { 091 return retentionCount; 092 } 093 094 /** 095 * Sets the number of artifacts that should be kept and not be deleted. 096 * 097 * @param retentionCount 098 */ 099 public void setRetentionCount(int retentionCount) { 100 this.retentionCount = retentionCount; 101 } 102}