1 package org.apache.archiva.repository.index.mock;
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.common.filelock.DefaultFileLockManager;
23 import org.apache.archiva.indexer.ArchivaIndexingContext;
24 import org.apache.archiva.repository.Repository;
25 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
26 import org.apache.archiva.repository.storage.StorageAsset;
27 import org.apache.maven.index.context.IndexingContext;
29 import java.io.IOException;
30 import java.nio.file.Files;
31 import java.nio.file.NoSuchFileException;
33 import java.time.ZonedDateTime;
37 * Maven implementation of index context
39 public class MavenIndexContextMock implements ArchivaIndexingContext {
41 private boolean open = true;
42 private IndexingContext delegate;
43 private Repository repository;
44 private FilesystemStorage indexStorage;
46 MavenIndexContextMock(Repository repository, IndexingContext delegate) throws IOException {
47 this.delegate = delegate;
48 this.repository = repository;
49 indexStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager());
54 public String getId() {
55 return delegate.getId();
59 public Repository getRepository() {
64 public StorageAsset getPath() {
65 return indexStorage.getAsset("");
69 public boolean isEmpty() throws IOException {
70 return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0;
74 public void commit() throws IOException {
79 public void rollback() throws IOException {
84 public void optimize() throws IOException {
89 public void close(boolean deleteFiles) throws IOException {
92 delegate.close(deleteFiles);
93 } catch (NoSuchFileException e) {
94 // Ignore missing directory
99 public void close() throws IOException {
102 delegate.close(false);
103 } catch (NoSuchFileException e) {
104 // Ignore missing directory
109 public boolean isOpen() {
114 public void purge() throws IOException {
119 public boolean supports(Class<?> clazz) {
120 return IndexingContext.class.equals(clazz);
123 @SuppressWarnings( "unchecked" )
125 public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException {
126 if (IndexingContext.class.equals(clazz)) {
129 throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer");
134 public Set<String> getGroups() throws IOException {
135 return delegate.getAllGroups();
139 public void updateTimestamp(boolean save) throws IOException {
140 delegate.updateTimestamp(save);
144 public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException {
145 delegate.updateTimestamp(save, Date.from(time.toInstant()));