1 package org.apache.archiva.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.FilesystemAsset;
26 import org.apache.archiva.repository.storage.FilesystemStorage;
27 import org.apache.archiva.repository.storage.StorageAsset;
28 import org.apache.maven.index.context.IndexingContext;
30 import java.io.IOException;
32 import java.nio.file.Files;
33 import java.nio.file.NoSuchFileException;
35 import java.time.ZonedDateTime;
39 * Maven implementation of index context
41 public class MavenIndexContextMock implements ArchivaIndexingContext {
43 private boolean open = true;
45 private IndexingContext delegate;
46 private Repository repository;
47 private FilesystemStorage filesystemStorage;
49 MavenIndexContextMock( Repository repository, IndexingContext delegate) {
50 this.delegate = delegate;
51 this.repository = repository;
53 filesystemStorage = new FilesystemStorage(delegate.getIndexDirectoryFile().toPath().getParent(), new DefaultFileLockManager());
54 } catch (IOException e) {
61 public String getId() {
62 return delegate.getId();
66 public Repository getRepository() {
71 public StorageAsset getPath() {
72 return new FilesystemAsset(filesystemStorage, delegate.getIndexDirectoryFile().toPath().getFileName().toString(), delegate.getIndexDirectoryFile().toPath());
77 public boolean isEmpty() throws IOException {
78 return Files.list(delegate.getIndexDirectoryFile().toPath()).count()==0;
82 public void commit() throws IOException {
87 public void rollback() throws IOException {
92 public void optimize() throws IOException {
97 public void close(boolean deleteFiles) throws IOException {
100 delegate.close(deleteFiles);
101 } catch (NoSuchFileException e) {
102 // Ignore missing directory
107 public void close() throws IOException {
110 delegate.close(false);
111 } catch (NoSuchFileException e) {
112 // Ignore missing directory
117 public boolean isOpen() {
122 public void purge() throws IOException {
127 public boolean supports(Class<?> clazz) {
128 return IndexingContext.class.equals(clazz);
131 @SuppressWarnings( "unchecked" )
133 public <T> T getBaseContext(Class<T> clazz) throws UnsupportedOperationException {
134 if (IndexingContext.class.equals(clazz)) {
137 throw new UnsupportedOperationException("The class "+clazz+" is not supported by the maven indexer");
142 public Set<String> getGroups() throws IOException {
143 return delegate.getAllGroups();
147 public void updateTimestamp(boolean save) throws IOException {
148 delegate.updateTimestamp(save);
152 public void updateTimestamp(boolean save, ZonedDateTime time) throws IOException {
153 delegate.updateTimestamp(save, Date.from(time.toInstant()));