1 package org.apache.archiva.repository.maven.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
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.common.filelock.DefaultFileLockManager;
22 import org.apache.archiva.indexer.ArchivaIndexingContext;
23 import org.apache.archiva.repository.Repository;
24 import org.apache.archiva.repository.storage.fs.FilesystemStorage;
25 import org.apache.archiva.repository.storage.StorageAsset;
26 import org.apache.maven.index.context.IndexingContext;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.NoSuchFileException;
32 import java.time.ZonedDateTime;
36 * Maven implementation of index context
38 public class MavenIndexContextMock implements ArchivaIndexingContext {
40 private boolean open = true;
41 private IndexingContext delegate;
42 private Repository repository;
43 private FilesystemStorage indexStorage;
45 MavenIndexContextMock(Repository repository, IndexingContext delegate) throws IOException {
46 this.delegate = delegate;
47 this.repository = repository;
48 indexStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath(), new DefaultFileLockManager());
53 public String getId() {
54 return delegate.getId();
58 public Repository getRepository() {
63 public StorageAsset getPath() {
64 return indexStorage.getAsset("");
68 public boolean isEmpty() throws IOException {
69 return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0;
73 public void commit() throws IOException {
78 public void rollback() throws IOException {
83 public void optimize() throws IOException {
88 public void close(boolean deleteFiles) throws IOException {
91 delegate.close(deleteFiles);
92 } catch (NoSuchFileException e) {
93 // Ignore missing directory
98 public void close() throws IOException {
101 delegate.close(false);
102 } catch (NoSuchFileException e) {
103 // Ignore missing directory
108 public boolean isOpen() {
113 public void purge() throws IOException {
118 public boolean supports(Class<?> clazz) {
119 return IndexingContext.class.equals(clazz);
122 @SuppressWarnings( "unchecked" )
124 public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException {
125 if (IndexingContext.class.equals(clazz)) {
128 throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer");
133 public Set<String> getGroups() throws IOException {
134 return delegate.getAllGroups();
138 public void updateTimestamp(boolean save) throws IOException {
139 delegate.updateTimestamp(save);
143 public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException {
144 delegate.updateTimestamp(save, Date.from(time.toInstant()));