1 package org.apache.archiva.indexer.maven;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import org.apache.archiva.indexer.ArchivaIndexingContext;
23 import org.apache.archiva.repository.Repository;
24 import org.apache.maven.index.context.IndexingContext;
26 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.NoSuchFileException;
31 import java.time.ZonedDateTime;
35 * Maven implementation of index context
37 public class MavenIndexContext implements ArchivaIndexingContext {
39 private IndexingContext delegate;
40 private Repository repository;
42 MavenIndexContext(Repository repository, IndexingContext delegate) {
43 this.delegate = delegate;
44 this.repository = repository;
49 public String getId() {
50 return delegate.getId();
54 public Repository getRepository() {
59 public URI getPath() {
60 return delegate.getIndexDirectoryFile().toURI();
64 public boolean isEmpty() throws IOException {
65 return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0;
69 public void commit() throws IOException {
74 public void rollback() throws IOException {
79 public void optimize() throws IOException {
84 public void close(boolean deleteFiles) throws IOException {
86 delegate.close(deleteFiles);
87 } catch (NoSuchFileException e) {
88 // Ignore missing directory
93 public void close() throws IOException {
95 delegate.close(false);
96 } catch (NoSuchFileException e) {
97 // Ignore missing directory
102 public void purge() throws IOException {
107 public boolean supports(Class<?> clazz) {
108 return IndexingContext.class.equals(clazz);
112 public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException {
113 if (IndexingContext.class.equals(clazz)) {
116 throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer");
121 public Set<String> getGroups() throws IOException {
122 return delegate.getAllGroups();
126 public void updateTimestamp(boolean save) throws IOException {
127 delegate.updateTimestamp(save);
131 public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException {
132 delegate.updateTimestamp(save, Date.from(time.toInstant()));