View Javadoc
1   package org.apache.archiva.mock;
2   /*
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
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
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
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.AuditInformation;
22  import org.apache.archiva.admin.model.RepositoryAdminException;
23  import org.apache.archiva.admin.model.beans.ManagedRepository;
24  import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
25  import org.apache.commons.lang.StringUtils;
26  import org.apache.archiva.configuration.ArchivaConfiguration;
27  import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
28  import org.apache.maven.index.context.IndexingContext;
29  
30  import java.util.ArrayList;
31  import java.util.List;
32  import java.util.Map;
33  
34  /**
35   * @author Olivier Lamy
36   */
37  public class MockManagedRepositoryAdmin
38      implements ManagedRepositoryAdmin
39  {
40      private ArchivaConfiguration archivaConfiguration;
41  
42      @Override
43      public List<ManagedRepository> getManagedRepositories()
44          throws RepositoryAdminException
45      {
46          List<ManagedRepositoryConfiguration> managedRepoConfigs =
47              getArchivaConfiguration().getConfiguration().getManagedRepositories();
48  
49          List<ManagedRepository> managedRepos = new ArrayList<>( managedRepoConfigs.size() );
50  
51          for ( ManagedRepositoryConfiguration repoConfig : managedRepoConfigs )
52          {
53              // TODO add staging repo information back too
54              ManagedRepository repo =
55                  new ManagedRepository( repoConfig.getId(), repoConfig.getName(), repoConfig.getLocation(),
56                                         repoConfig.getLayout(), repoConfig.isSnapshots(), repoConfig.isReleases(),
57                                         repoConfig.isBlockRedeployments(), repoConfig.getRefreshCronExpression(),
58                                         repoConfig.getIndexDir(), repoConfig.isScanned(), repoConfig.getDaysOlder(),
59                                         repoConfig.getRetentionCount(), repoConfig.isDeleteReleasedSnapshots(), true );
60  
61              managedRepos.add( repo );
62          }
63  
64          return managedRepos;
65      }
66  
67      @Override
68      public Map<String, ManagedRepository> getManagedRepositoriesAsMap()
69          throws RepositoryAdminException
70      {
71          return null;
72      }
73  
74      @Override
75      public ManagedRepository getManagedRepository( String repositoryId )
76          throws RepositoryAdminException
77      {
78          List<ManagedRepository> repos = getManagedRepositories();
79          for ( ManagedRepository repo : repos )
80          {
81              if ( StringUtils.equals( repo.getId(), repositoryId ) )
82              {
83                  return repo;
84              }
85          }
86          return null;
87      }
88  
89      @Override
90      public Boolean deleteManagedRepository( String repositoryId, AuditInformation auditInformation,
91                                              boolean deleteContent )
92          throws RepositoryAdminException
93      {
94          return null;
95      }
96  
97      @Override
98      public Boolean addManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
99                                           AuditInformation auditInformation )
100         throws RepositoryAdminException
101     {
102         return null;
103     }
104 
105     @Override
106     public Boolean updateManagedRepository( ManagedRepository managedRepository, boolean needStageRepo,
107                                             AuditInformation auditInformation, boolean resetStats )
108         throws RepositoryAdminException
109     {
110         return null;
111     }
112 
113     public ArchivaConfiguration getArchivaConfiguration()
114     {
115         return archivaConfiguration;
116     }
117 
118     public void setArchivaConfiguration( ArchivaConfiguration archivaConfiguration )
119     {
120         this.archivaConfiguration = archivaConfiguration;
121     }
122 
123     @Override
124     public IndexingContext createIndexContext( ManagedRepository repository )
125         throws RepositoryAdminException
126     {
127         return null;
128     }
129 }