This project has retired. For details please refer to its Attic page.
MavenRemoteRepository xref
View Javadoc
1   package org.apache.archiva.repository.maven2;
2   
3   import org.apache.archiva.common.filelock.DefaultFileLockManager;
4   import org.apache.archiva.common.filelock.FileLockManager;
5   import org.apache.archiva.repository.base.AbstractRemoteRepository;
6   import org.apache.archiva.repository.ReleaseScheme;
7   import org.apache.archiva.repository.RemoteRepository;
8   import org.apache.archiva.repository.RepositoryCapabilities;
9   import org.apache.archiva.repository.RepositoryType;
10  import org.apache.archiva.repository.StandardCapabilities;
11  import org.apache.archiva.repository.UnsupportedFeatureException;
12  import org.apache.archiva.repository.storage.FilesystemStorage;
13  import org.apache.archiva.repository.features.IndexCreationFeature;
14  import org.apache.archiva.repository.features.RemoteIndexFeature;
15  import org.apache.archiva.repository.features.RepositoryFeature;
16  import org.slf4j.Logger;
17  import org.slf4j.LoggerFactory;
18  
19  import java.io.IOException;
20  import java.nio.file.Path;
21  import java.util.Locale;
22  
23  /*
24   * Licensed to the Apache Software Foundation (ASF) under one
25   * or more contributor license agreements.  See the NOTICE file
26   * distributed with this work for additional information
27   * regarding copyright ownership.  The ASF licenses this file
28   * to you under the Apache License, Version 2.0 (the
29   * "License"); you may not use this file except in compliance
30   * with the License.  You may obtain a copy of the License at
31   *
32   *  http://www.apache.org/licenses/LICENSE-2.0
33   *
34   * Unless required by applicable law or agreed to in writing,
35   * software distributed under the License is distributed on an
36   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
37   * KIND, either express or implied.  See the License for the
38   * specific language governing permissions and limitations
39   * under the License.
40   */
41  
42  /**
43   * Maven2 remote repository implementation
44   */
45  public class MavenRemoteRepository extends AbstractRemoteRepository
46      implements RemoteRepository
47  {
48  
49      Logger log = LoggerFactory.getLogger(MavenRemoteRepository.class);
50  
51      final private RemoteIndexFeaturexFeature.html#RemoteIndexFeature">RemoteIndexFeature remoteIndexFeature = new RemoteIndexFeature();
52      final private IndexCreationFeature indexCreationFeature;
53  
54      private static final RepositoryCapabilities CAPABILITIES = new StandardCapabilities(
55          new ReleaseScheme[] { ReleaseScheme.RELEASE, ReleaseScheme.SNAPSHOT },
56          new String[] { MavenManagedRepository.DEFAULT_LAYOUT, MavenManagedRepository.LEGACY_LAYOUT},
57          new String[] {},
58          new String[] {RemoteIndexFeature.class.getName(), IndexCreationFeature.class.getName()},
59          true,
60          true,
61          true,
62          true,
63          false
64      );
65  
66      public MavenRemoteRepository(String id, String name, FilesystemStorage storage)
67      {
68          super( RepositoryType.MAVEN, id, name, storage );
69          this.indexCreationFeature = new IndexCreationFeature(this, this);
70  
71      }
72  
73      public MavenRemoteRepository( Locale primaryLocale, String id, String name, FilesystemStorage storage )
74      {
75          super( primaryLocale, RepositoryType.MAVEN, id, name, storage );
76          this.indexCreationFeature = new IndexCreationFeature(this, this);
77      }
78  
79      @Override
80      public boolean hasIndex( )
81      {
82          return remoteIndexFeature.hasIndex();
83      }
84  
85      @Override
86      public RepositoryCapabilities getCapabilities( )
87      {
88          return CAPABILITIES;
89      }
90  
91      @SuppressWarnings( "unchecked" )
92      @Override
93      public <T extends RepositoryFeature<T>> RepositoryFeature<T> getFeature( Class<T> clazz ) throws UnsupportedFeatureException
94      {
95          if (RemoteIndexFeature.class.equals( clazz )) {
96              return (RepositoryFeature<T>) remoteIndexFeature;
97          } else if (IndexCreationFeature.class.equals(clazz)) {
98              return (RepositoryFeature<T>) indexCreationFeature;
99          } else {
100             throw new UnsupportedFeatureException(  );
101         }
102     }
103 
104     @Override
105     public <T extends RepositoryFeature<T>> boolean supportsFeature( Class<T> clazz )
106     {
107         if ( RemoteIndexFeature.class.equals(clazz) || IndexCreationFeature.class.equals(clazz)) {
108             return true;
109         } else {
110             return false;
111         }
112     }
113 
114     @Override
115     public String toString() {
116         return super.toString()+", remoteIndexFeature="+remoteIndexFeature.toString()+", indexCreationFeature="+indexCreationFeature.toString();
117     }
118 
119     public static MavenRemoteRepository newLocalInstance(String id, String name, Path basePath) throws IOException {
120         FileLockManager lockManager = new DefaultFileLockManager();
121         FilesystemStorage/FilesystemStorage.html#FilesystemStorage">FilesystemStorage storage = new FilesystemStorage(basePath.resolve(id), lockManager);
122         return new MavenRemoteRepository(id, name, storage);
123     }
124 }