diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-09-12 13:09:40 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-09-22 00:09:54 +0200 |
commit | 9948797e50b4af71913bdbf0dec7810b2f676fd7 (patch) | |
tree | 5515952953e35d87bb0e66bac5739331835eac04 /archiva-modules/archiva-base/archiva-repository-api | |
parent | b072f6921df0b59843f9c411b292b467dbe0f01a (diff) | |
download | archiva-9948797e50b4af71913bdbf0dec7810b2f676fd7.tar.gz archiva-9948797e50b4af71913bdbf0dec7810b2f676fd7.zip |
Enhancing repository events
Diffstat (limited to 'archiva-modules/archiva-base/archiva-repository-api')
14 files changed, 247 insertions, 54 deletions
diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java index cc43ab262..9b261434c 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/Repository.java @@ -20,12 +20,12 @@ package org.apache.archiva.repository; */ import org.apache.archiva.indexer.ArchivaIndexingContext; +import org.apache.archiva.repository.events.RepositoryEventHandler; import org.apache.archiva.repository.storage.RepositoryStorage; import org.apache.archiva.repository.features.RepositoryFeature; import org.apache.archiva.repository.storage.StorageAsset; import java.net.URI; -import java.nio.file.Path; import java.util.Locale; import java.util.Set; diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProvider.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProvider.java index 1f26a5d5e..3a405fbb0 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProvider.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryProvider.java @@ -22,6 +22,7 @@ package org.apache.archiva.repository; import org.apache.archiva.configuration.ManagedRepositoryConfiguration; import org.apache.archiva.configuration.RemoteRepositoryConfiguration; import org.apache.archiva.configuration.RepositoryGroupConfiguration; +import org.apache.archiva.repository.events.RepositoryEventListener; import java.io.IOException; import java.util.Set; diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/Event.java index 8a9db881f..afac04c10 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEvent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/Event.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository; +package org.apache.archiva.repository.events; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -21,49 +21,47 @@ package org.apache.archiva.repository; import java.time.LocalDateTime; -/** - * Repository event. Repository events are used for providing information about repository changes. - * - * @param <T> - */ -public class RepositoryEvent<T> { +public class Event<O> { + Event previous; + final O originator; final EventType type; - final Repository repo; - final T value; - final T oldValue; final LocalDateTime instant; - public RepositoryEvent(EventType type, Repository repo, T oldValue, T value) { + public Event(EventType type, O originator) { + this.originator = originator; this.type = type; - this.repo = repo; - this.value = value; - this.oldValue = oldValue; this.instant = LocalDateTime.now(); } - public interface EventType { - String name(); + private <OO> Event(Event<OO> previous, O originator) { + this.previous = previous; + this.originator = originator; + this.type = previous.getType(); + this.instant = previous.getInstant(); } - public EventType getType() { return type; }; - public Repository getRepository() { - return repo; - }; + public LocalDateTime getInstant() { + return instant; + } - public T getValue() { - return value; + public O getOriginator() { + return originator; } - public T getOldValue() { - return oldValue; + public <NO> Event<NO> recreate(NO newOrigin) { + return new Event(this, newOrigin); } - public LocalDateTime getInstant() { - return instant; + public Event getPreviousEvent() { + return previous; + } + + public boolean hasPreviousEvent() { + return previous!=null; } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventType.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventType.java new file mode 100644 index 000000000..5004a1526 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventType.java @@ -0,0 +1,25 @@ +package org.apache.archiva.repository.events; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public interface EventType { + + String name(); +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/LifecycleEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/LifecycleEvent.java new file mode 100644 index 000000000..5f69d1ed3 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/LifecycleEvent.java @@ -0,0 +1,33 @@ +package org.apache.archiva.repository.events; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.repository.Repository; + +public class LifecycleEvent<O> extends RepositoryEvent<O> { + + public enum LifecycleEventType implements EventType { + REGISTERED,UNREGISTERED,UPDATED + } + + public LifecycleEvent(LifecycleEventType type, O origin, Repository repository) { + super(type, origin, repository); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEvent.java new file mode 100644 index 000000000..dd5550b3e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEvent.java @@ -0,0 +1,36 @@ +package org.apache.archiva.repository.events; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.repository.Repository; + +public class RepositoryEvent<O> extends Event<O> { + + private final Repository repository; + + public RepositoryEvent(EventType type, O origin, Repository repository) { + super(type, origin); + this.repository = repository; + } + + public Repository getRepository() { + return repository; + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEventHandler.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEventHandler.java new file mode 100644 index 000000000..123ffb289 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEventHandler.java @@ -0,0 +1,40 @@ +package org.apache.archiva.repository.events; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Set; + +/** + * A repository event handler raises events to its registered listeners. + * Listeners may register for all events that are raised or only to a subset of events. + * + */ +public interface RepositoryEventHandler { + + void register(RepositoryEventListener listener); + + void register(RepositoryEventListener listener, EventType type); + + void register(RepositoryEventListener listener, Set<? extends EventType> types); + + void unregister(RepositoryEventListener listener); + + void clearListeners(); +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEventListener.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEventListener.java index 0234f34b4..1f0b2039d 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEventListener.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEventListener.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository; +package org.apache.archiva.repository.events; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,10 +19,12 @@ package org.apache.archiva.repository; * under the License. */ +import org.apache.archiva.repository.events.RepositoryValueEvent; + /** * Listener that accepts repository events. */ public interface RepositoryEventListener { - <T> void raise(RepositoryEvent<T> event); + void raise(Event event); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEventHandler.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryRegistryEvent.java index 74326270c..d9b891c3c 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryEventHandler.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryRegistryEvent.java @@ -1,4 +1,4 @@ -package org.apache.archiva.repository; +package org.apache.archiva.repository.events; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -19,14 +19,13 @@ package org.apache.archiva.repository; * under the License. */ -/** - * Implementations of this interface are able to handle repository event listeners - */ -public interface RepositoryEventHandler { - - void addListener(RepositoryEventListener listener); +public class RepositoryRegistryEvent<O> extends Event { - void removeListener(RepositoryEventListener listener); + public enum RegistryEventType implements EventType { + RELOADED,DESTROYED + } - void clearListeners(); + public RepositoryRegistryEvent(RegistryEventType type, O origin) { + super(type, origin); + } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryValueEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryValueEvent.java new file mode 100644 index 000000000..6081717e6 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryValueEvent.java @@ -0,0 +1,48 @@ +package org.apache.archiva.repository.events; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.archiva.repository.Repository; + +/** + * Repository event. Repository events are used for providing information about repository changes. + * + * @param <V> + */ +public class RepositoryValueEvent<O, V> extends RepositoryEvent<O> { + + final V value; + final V oldValue; + + public RepositoryValueEvent(EventType type, O origin, Repository repo, V oldValue, V value) { + super(type, origin, repo); + this.value = value; + this.oldValue = oldValue; + } + + public V getValue() { + return value; + } + + public V getOldValue() { + return oldValue; + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/AbstractFeature.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/AbstractFeature.java index 08d0bba4e..6b64d937c 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/AbstractFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/AbstractFeature.java @@ -19,8 +19,8 @@ package org.apache.archiva.repository.features; * under the License. */ -import org.apache.archiva.repository.RepositoryEvent; -import org.apache.archiva.repository.RepositoryEventListener; +import org.apache.archiva.repository.events.Event; +import org.apache.archiva.repository.events.RepositoryEventListener; import java.util.ArrayList; import java.util.Collection; @@ -56,7 +56,7 @@ public class AbstractFeature { this.listener.clear(); } - protected <T> void raiseEvent(RepositoryEvent<T> event) { + public void pushEvent(Event event) { for(RepositoryEventListener listr : listener) { listr.raise(event); } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationEvent.java index 49a3d444a..037ba4757 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationEvent.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationEvent.java @@ -20,29 +20,30 @@ package org.apache.archiva.repository.features; */ import org.apache.archiva.repository.Repository; -import org.apache.archiva.repository.RepositoryEvent; +import org.apache.archiva.repository.events.EventType; +import org.apache.archiva.repository.events.RepositoryValueEvent; import java.net.URI; -public class IndexCreationEvent extends RepositoryEvent<URI> { +public class IndexCreationEvent<O> extends RepositoryValueEvent<O, URI> { public enum Index implements EventType { INDEX_URI_CHANGE, PACKED_INDEX_URI_CHANGE } - IndexCreationEvent(Repository repo, URI oldValue, URI value) { - super(Index.INDEX_URI_CHANGE, repo, oldValue, value); + IndexCreationEvent(Repository repo, O origin, URI oldValue, URI value) { + super(Index.INDEX_URI_CHANGE, origin, repo, oldValue, value); } - IndexCreationEvent(Index type, Repository repo, URI oldValue, URI value) { - super(type, repo, oldValue, value); + IndexCreationEvent(Index type, O origin, Repository repo, URI oldValue, URI value) { + super(type, origin, repo, oldValue, value); } - public static final IndexCreationEvent indexUriChange(Repository repo, URI oldValue, URI newValue) { - return new IndexCreationEvent(Index.INDEX_URI_CHANGE, repo, oldValue, newValue); + public static final <O> IndexCreationEvent indexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { + return new IndexCreationEvent(Index.INDEX_URI_CHANGE, origin, repo, oldValue, newValue); } - public static final IndexCreationEvent packedIndexUriChange(Repository repo, URI oldValue, URI newValue) { - return new IndexCreationEvent(Index.PACKED_INDEX_URI_CHANGE, repo, oldValue, newValue); + public static final <O> IndexCreationEvent packedIndexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { + return new IndexCreationEvent(Index.PACKED_INDEX_URI_CHANGE, origin, repo, oldValue, newValue); } } diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java index 94812fcdd..cf7432c6e 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/IndexCreationFeature.java @@ -21,7 +21,7 @@ package org.apache.archiva.repository.features; import org.apache.archiva.repository.Repository; -import org.apache.archiva.repository.RepositoryEventListener; +import org.apache.archiva.repository.events.RepositoryEventListener; import org.apache.archiva.repository.storage.StorageAsset; import org.apache.commons.lang3.StringUtils; @@ -113,7 +113,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF { URI oldVal = this.indexPath; this.indexPath = indexPath; - raiseEvent(IndexCreationEvent.indexUriChange(repo, oldVal, this.indexPath)); + pushEvent(IndexCreationEvent.indexUriChange(this, repo, oldVal, this.indexPath)); } @@ -157,7 +157,7 @@ public class IndexCreationFeature extends AbstractFeature implements RepositoryF public void setPackedIndexPath(URI packedIndexPath) { URI oldVal = this.packedIndexPath; this.packedIndexPath = packedIndexPath; - raiseEvent(IndexCreationEvent.packedIndexUriChange(repo, oldVal, this.packedIndexPath)); + pushEvent(IndexCreationEvent.packedIndexUriChange(this, repo, oldVal, this.packedIndexPath)); } /** diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java index 3e154874c..245b8b07d 100644 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/features/RemoteIndexFeature.java @@ -23,6 +23,7 @@ package org.apache.archiva.repository.features; import org.apache.commons.lang3.StringUtils; import java.net.URI; +import java.net.URISyntaxException; import java.time.Duration; /** @@ -32,6 +33,15 @@ public class RemoteIndexFeature implements RepositoryFeature<RemoteIndexFeature> private boolean downloadRemoteIndex = false; private URI indexUri; + + { + try { + indexUri = new URI(".index"); + } catch (URISyntaxException e) { + // Ignore + } + } + private boolean downloadRemoteIndexOnStartup = false; private Duration downloadTimeout = Duration.ofSeconds( 600 ); private String proxyId = ""; |