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;
30 import java.time.ZonedDateTime;
34 * Maven implementation of index context
36 public class MavenIndexContext implements ArchivaIndexingContext {
38 private IndexingContext delegate;
39 private Repository repository;
41 MavenIndexContext(Repository repository, IndexingContext delegate) {
42 this.delegate = delegate;
43 this.repository = repository;
48 public String getId() {
49 return delegate.getId();
53 public Repository getRepository() {
58 public URI getPath() {
59 return delegate.getIndexDirectoryFile().toURI();
63 public boolean isEmpty() throws IOException {
64 return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0;
68 public void commit() throws IOException {
73 public void rollback() throws IOException {
78 public void optimize() throws IOException {
83 public void close(boolean deleteFiles) throws IOException {
84 delegate.close(deleteFiles);
88 public void purge() throws IOException {
93 public boolean supports(Class<?> clazz) {
94 return IndexingContext.class.equals(clazz);
98 public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException {
99 if (IndexingContext.class.equals(clazz)) {
102 throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer");
107 public Set<String> getGroups() throws IOException {
108 return delegate.getAllGroups();
112 public void updateTimestamp(boolean save) throws IOException {
113 delegate.updateTimestamp(save);
117 public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException {
118 delegate.updateTimestamp(save, Date.from(time.toInstant()));