This project has retired. For details please refer to its Attic page.
GenericIndexManager xref
View Javadoc
1   package org.apache.archiva.indexer;
2   
3   /*
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
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
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
19   * under the License.
20   */
21  
22  import org.apache.archiva.common.utils.PathUtil;
23  import org.apache.archiva.repository.Repository;
24  import org.apache.archiva.repository.RepositoryType;
25  import org.apache.archiva.repository.features.IndexCreationFeature;
26  import org.apache.commons.lang.StringUtils;
27  import org.slf4j.Logger;
28  import org.slf4j.LoggerFactory;
29  import org.springframework.stereotype.Service;
30  
31  import java.io.IOException;
32  import java.net.URI;
33  import java.nio.file.Files;
34  import java.nio.file.Path;
35  import java.util.Collection;
36  
37  @Service("indexManager#none")
38  public class GenericIndexManager implements ArchivaIndexManager {
39  
40      private final Logger log = LoggerFactory.getLogger(GenericIndexManager.class);
41  
42      public static final String DEFAULT_INDEXER_DIR = ".indexer";
43  
44      @Override
45      public void pack(ArchivaIndexingContext context) {
46  
47      }
48  
49      @Override
50      public void scan(ArchivaIndexingContext context) {
51  
52      }
53  
54      @Override
55      public void update(ArchivaIndexingContext context, boolean fullUpdate) {
56  
57      }
58  
59      @Override
60      public void addArtifactsToIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) {
61  
62      }
63  
64      @Override
65      public void removeArtifactsFromIndex(ArchivaIndexingContext context, Collection<URI> artifactReference) {
66  
67      }
68  
69      @Override
70      public boolean supportsRepository(RepositoryType type) {
71          return false;
72      }
73  
74      @Override
75      public ArchivaIndexingContext createContext(Repository repository) {
76          return null;
77      }
78  
79      @Override
80      public ArchivaIndexingContext reset(ArchivaIndexingContext context) throws IndexUpdateFailedException {
81          return null;
82      }
83  
84      @Override
85      public ArchivaIndexingContext move(ArchivaIndexingContext context, Repository repo) throws IndexCreationFailedException {
86          return null;
87      }
88  
89      @Override
90      public void updateLocalIndexPath(Repository repo) {
91          if (repo.supportsFeature(IndexCreationFeature.class)) {
92              IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
93              try {
94                  icf.setLocalIndexPath(getIndexPath(repo));
95              } catch (IOException e) {
96                  log.error("Could not set local index path for {}. New URI: {}", repo.getId(), icf.getIndexPath());
97              }
98          }
99      }
100 
101     private Path getIndexPath(Repository repo) throws IOException {
102         IndexCreationFeature icf = repo.getFeature(IndexCreationFeature.class).get();
103         Path repoDir = repo.getLocalPath();
104         URI indexDir = icf.getIndexPath();
105         Path indexDirectory = null;
106         if ( ! StringUtils.isEmpty(indexDir.toString( ) ) )
107         {
108 
109             indexDirectory = PathUtil.getPathFromUri( indexDir );
110             // not absolute so create it in repository directory
111             if ( !indexDirectory.isAbsolute( ) )
112             {
113                 indexDirectory = repoDir.resolve( indexDirectory );
114             }
115         }
116         else
117         {
118             indexDirectory = repoDir.resolve( DEFAULT_INDEXER_DIR);
119         }
120 
121         if ( !Files.exists( indexDirectory ) )
122         {
123             Files.createDirectories( indexDirectory );
124         }
125         return indexDirectory;
126     }
127 
128 }