1 package org.apache.archiva.rest.api.model.v2;/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
20 * Licensed to the Apache Software Foundation (ASF) under one
21 * or more contributor license agreements. See the NOTICE file
22 * distributed with this work for additional information
23 * regarding copyright ownership. The ASF licenses this file
24 * to you under the Apache License, Version 2.0 (the
25 * "License"); you may not use this file except in compliance
26 * with the License. You may obtain a copy of the License at
28 * http://www.apache.org/licenses/LICENSE-2.0
29 * Unless required by applicable law or agreed to in writing,
30 * software distributed under the License is distributed on an
31 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32 * KIND, either express or implied. See the License for the
33 * specific language governing permissions and limitations
37 import io.swagger.v3.oas.annotations.media.Schema;
38 import org.apache.archiva.repository.ManagedRepository;
39 import org.apache.archiva.repository.RepositoryType;
40 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
41 import org.apache.archiva.repository.features.IndexCreationFeature;
42 import org.apache.archiva.repository.features.StagingRepositoryFeature;
44 import java.time.Period;
45 import java.util.ArrayList;
46 import java.util.List;
47 import java.util.Objects;
48 import java.util.stream.Collectors;
51 * @author Martin Stockhammer <martin_s@apache.org>
53 @Schema(name="MavenManagedRepository",description = "A managed repository stores artifacts locally")
54 public class MavenManagedRepository extends Repository
56 private static final long serialVersionUID = -6853748886201905029L;
58 boolean blocksRedeployments;
59 List<String> releaseSchemes = new ArrayList<>( );
60 boolean deleteSnapshotsOfRelease = false;
61 private Period retentionPeriod;
62 private int retentionCount;
63 private String indexPath;
64 private String packedIndexPath;
65 private boolean skipPackedIndexCreation;
66 private boolean hasStagingRepository;
67 private String stagingRepository;
70 public MavenManagedRepository( )
72 super.setCharacteristic( Repository.CHARACTERISTIC_MANAGED );
73 super.setType( RepositoryType.MAVEN.name( ) );
76 protected static void update(MavenManagedRepository repo, ManagedRepository beanRepo) {
77 repo.setDescription( beanRepo.getDescription() );
78 repo.setId( beanRepo.getId() );
79 repo.setIndex( true );
80 repo.setLayout( beanRepo.getLayout() );
81 repo.setBlocksRedeployments( beanRepo.blocksRedeployments() );
82 repo.setReleaseSchemes( beanRepo.getActiveReleaseSchemes().stream().map( Objects::toString).collect( Collectors.toList()) );
83 repo.setLocation( beanRepo.getLocation().toString() );
84 repo.setName( beanRepo.getName());
85 repo.setScanned( beanRepo.isScanned() );
86 repo.setSchedulingDefinition( beanRepo.getSchedulingDefinition() );
87 ArtifactCleanupFeature artifactCleanupFeature = beanRepo.getFeature( ArtifactCleanupFeature.class ).get( );
88 repo.setDeleteSnapshotsOfRelease( artifactCleanupFeature.isDeleteReleasedSnapshots());
89 repo.setRetentionCount( artifactCleanupFeature.getRetentionCount());
90 repo.setRetentionPeriod( artifactCleanupFeature.getRetentionPeriod() );
91 IndexCreationFeature icf = beanRepo.getFeature( IndexCreationFeature.class ).get( );
92 repo.setIndex( icf.hasIndex( ) );
93 repo.setIndexPath( icf.getIndexPath( ).getPath( ) );
94 repo.setPackedIndexPath( icf.getPackedIndexPath( ).getPath( ) );
95 repo.setSkipPackedIndexCreation( icf.isSkipPackedIndexCreation() );
96 StagingRepositoryFeature srf = beanRepo.getFeature( StagingRepositoryFeature.class ).get( );
97 repo.setHasStagingRepository( srf.isStageRepoNeeded( ) );
98 repo.setStagingRepository( srf.getStagingRepository()!=null?srf.getStagingRepository().getId():"" );
101 public static MavenManagedRepository of( ManagedRepository beanRepo ) {
102 MavenManagedRepository repo = new MavenManagedRepository( );
103 update( repo, beanRepo );
107 @Schema(name="blocks_redeployments",description = "True, if redeployments to this repository are not allowed")
108 public boolean isBlocksRedeployments( )
110 return blocksRedeployments;
113 public void setBlocksRedeployments( boolean blocksRedeployments )
115 this.blocksRedeployments = blocksRedeployments;
118 @Schema(name="release_schemes", description = "The release schemes this repository is used for (e.g. RELEASE, SNAPSHOT)")
119 public List<String> getReleaseSchemes( )
121 return releaseSchemes;
124 public void setReleaseSchemes( List<String> releaseSchemes )
126 this.releaseSchemes = new ArrayList<>( releaseSchemes );
129 public void addReleaseScheme(String scheme) {
130 if (!this.releaseSchemes.contains( scheme ))
132 this.releaseSchemes.add( scheme );
136 @Schema(name="delete_snaphots_of_release", description = "True, if snapshots are deleted, after a version is released")
137 public boolean isDeleteSnapshotsOfRelease( )
139 return deleteSnapshotsOfRelease;
142 public void setDeleteSnapshotsOfRelease( boolean deleteSnapshotsOfRelease )
144 this.deleteSnapshotsOfRelease = deleteSnapshotsOfRelease;
147 @Schema(name="retention_period", description = "The period after which snapshots are deleted.")
148 public Period getRetentionPeriod( )
150 return retentionPeriod;
153 public void setRetentionPeriod( Period retentionPeriod )
155 this.retentionPeriod = retentionPeriod;
158 @Schema(name="retention_count", description = "Number of snapshot artifacts to keep.")
159 public int getRetentionCount( )
161 return retentionCount;
164 public void setRetentionCount( int retentionCount )
166 this.retentionCount = retentionCount;
169 @Schema( name = "index_path", description = "Path to the directory that contains the index, relative to the repository base directory" )
170 public String getIndexPath( )
175 public void setIndexPath( String indexPath )
177 this.indexPath = indexPath;
180 @Schema( name = "packed_index_path", description = "Path to the directory that contains the packed index, relative to the repository base directory" )
181 public String getPackedIndexPath( )
183 return packedIndexPath;
186 public void setPackedIndexPath( String packedIndexPath )
188 this.packedIndexPath = packedIndexPath;
191 @Schema(name="skip_packed_index_creation", description = "True, if packed index is not created during index update")
192 public boolean isSkipPackedIndexCreation( )
194 return skipPackedIndexCreation;
197 public void setSkipPackedIndexCreation( boolean skipPackedIndexCreation )
199 this.skipPackedIndexCreation = skipPackedIndexCreation;
202 @Schema(name="has_staging_repository", description = "True, if this repository has a staging repository assigned")
203 public boolean isHasStagingRepository( )
205 return hasStagingRepository;
208 public void setHasStagingRepository( boolean hasStagingRepository )
210 this.hasStagingRepository = hasStagingRepository;
213 @Schema(name="staging_repository", description = "The id of the assigned staging repository")
214 public String getStagingRepository( )
216 return stagingRepository;
219 public void setStagingRepository( String stagingRepository )
221 this.stagingRepository = stagingRepository;
225 public boolean equals( Object o )
227 if ( this == o ) return true;
228 if ( o == null || getClass( ) != o.getClass( ) ) return false;
229 if ( !super.equals( o ) ) return false;
231 MavenManagedRepository that = (MavenManagedRepository) o;
233 if ( blocksRedeployments != that.blocksRedeployments ) return false;
234 return releaseSchemes != null ? releaseSchemes.equals( that.releaseSchemes ) : that.releaseSchemes == null;
238 public int hashCode( )
240 int result = super.hashCode( );
241 result = 31 * result + ( blocksRedeployments ? 1 : 0 );
242 result = 31 * result + ( releaseSchemes != null ? releaseSchemes.hashCode( ) : 0 );
247 public String toString( )
249 final StringBuilder sb = new StringBuilder( "ManagedRepository{" );
250 sb.append( "blocksRedeployments=" ).append( blocksRedeployments );
251 sb.append( ", releaseSchemes=" ).append( releaseSchemes );
252 sb.append( ", id='" ).append( id ).append( '\'' );
253 sb.append( ", name='" ).append( name ).append( '\'' );
254 sb.append( ", description='" ).append( description ).append( '\'' );
255 sb.append( ", type='" ).append( type ).append( '\'' );
256 sb.append( ", location='" ).append( location ).append( '\'' );
257 sb.append( ", scanned=" ).append( scanned );
258 sb.append( ", schedulingDefinition='" ).append( schedulingDefinition ).append( '\'' );
259 sb.append( ", index=" ).append( index );
260 sb.append( ", layout='" ).append( layout ).append( '\'' );
262 return sb.toString( );