From: Martin Stockhammer Date: Thu, 3 Oct 2019 15:37:37 +0000 (+0200) Subject: [MRM-2000] Adding NOTICE file with apache license information X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=76f47ea2033b09c145295799f6d8b64f7a02a77f;p=archiva.git [MRM-2000] Adding NOTICE file with apache license information --- diff --git a/NOTICE b/NOTICE new file mode 100644 index 000000000..1c78d10d3 --- /dev/null +++ b/NOTICE @@ -0,0 +1,5 @@ +Apache Archiva +Copyright 2006-2019 The Apache Software Foundation + +This product includes software developed at +The Apache Software Foundation (http://www.apache.org/). \ No newline at end of file diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/Event.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/Event.java new file mode 100644 index 000000000..dc91defc5 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/Event.java @@ -0,0 +1,112 @@ +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.time.LocalDateTime; +import java.util.EventObject; + +/** + * Base class for events. Events have a type and a source. + * The source is the instance that raised the event. + * + * There are different event types for a given event. The types are represented in a hierarchical structure. + * + * Events can be chained, which means a event listener can catch events and rethrow them as its own event. + * + */ +public class Event extends EventObject implements Cloneable { + + private static final long serialVersionUID = -7171846575892044990L; + + public static final EventType ANY = EventType.ROOT; + + private Event previous; + private final EventType type; + private final LocalDateTime createTime; + + public Event(EventType type, Object originator) { + super(originator); + this.type = type; + this.createTime = LocalDateTime.now(); + } + + private Event(Event previous, Object originator) { + super(originator); + this.previous = previous; + this.type = previous.getType(); + this.createTime = previous.getCreateTime(); + } + + /** + * Returns the event type that is associated with this event instance. + * @return the event type + */ + public EventType getType() { + return type; + }; + + /** + * Returns the time, when the event was created. + * @return + */ + public LocalDateTime getCreateTime() { + return createTime; + } + + + /** + * Recreates the event with the given instance as the new source. The + * current source is stored in the previous event. + * @param newSource The new source + * @return a new event instance, where this is stored as previous event + */ + public Event copyFor(Object newSource) { + Event newEvent = (Event) this.clone(); + newEvent.previous = this; + newEvent.source = newSource; + return newEvent; + } + + /** + * Returns the previous event or null, if this is a root event. + * @return the previous event or null, if it does not exist + */ + public Event getPreviousEvent() { + return previous; + } + + /** + * Returns true, if the event has a previous event. + * @return true, if this has a previous event, otherwise false + */ + public boolean hasPreviousEvent() { + return previous!=null; + } + + @Override + protected Object clone() { + try { + return super.clone(); + } catch (CloneNotSupportedException e) { + // this should not happen + throw new RuntimeException("Event is not clonable"); + } + } +} diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventHandler.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventHandler.java new file mode 100644 index 000000000..9f2d4411e --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventHandler.java @@ -0,0 +1,30 @@ +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.EventListener; + +/** + * A listener that accepts events. + */ +public interface EventHandler extends EventListener { + + void handle(T event); +} diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventManager.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventManager.java new file mode 100644 index 000000000..694cfd9e6 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventManager.java @@ -0,0 +1,79 @@ +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; + +public class EventManager implements EventSource { + + private static final Logger log = LoggerFactory.getLogger(EventManager.class); + + private final ConcurrentHashMap, Set> handlerMap = new ConcurrentHashMap<>(); + + private final Object source; + + public EventManager(Object source) { + if (source==null) { + throw new IllegalArgumentException("The source may not be null"); + } + this.source = source; + } + + @Override + public void registerEventHandler(EventType type, EventHandler eventHandler) { + Set handlers = handlerMap.computeIfAbsent(type, t -> new LinkedHashSet<>()); + if (!handlers.contains(eventHandler)) { + handlers.add(eventHandler); + } + } + + @Override + public void unregisterEventHandler(EventType type, EventHandler eventHandler) { + if (handlerMap.containsKey(type)) { + handlerMap.get(type).remove(eventHandler); + } + } + + public void fireEvent(Event fireEvent) { + final EventType type = fireEvent.getType(); + Event event; + if (fireEvent.getSource()!=source) { + event = fireEvent.copyFor(source); + } else { + event = fireEvent; + } + for (EventType handlerType : handlerMap.keySet()) { + if (EventType.isInstanceOf(type, handlerType)) { + for (EventHandler handler : handlerMap.get(handlerType)) { + try { + handler.handle(event); + } catch (Exception e) { + // We catch all errors from handlers + log.error("An error occured during event handling: {}", e.getMessage(), e); + } + } + } + } + } +} diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventSource.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventSource.java new file mode 100644 index 000000000..cffaeaf56 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventSource.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. + */ + +/** + * A repository event source raises events to its registered listeners. + * Listeners register to event types that are structured hierarchical. + * + */ +public interface EventSource { + + void registerEventHandler(EventType type, EventHandler eventHandler); + + void unregisterEventHandler(EventType type, EventHandler eventHandler); + +} diff --git a/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventType.java b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventType.java new file mode 100644 index 000000000..ab9678ab2 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-common/src/main/java/org/apache/archiva/event/EventType.java @@ -0,0 +1,166 @@ +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.io.InvalidObjectException; +import java.io.ObjectStreamException; +import java.io.Serializable; +import java.util.*; + +/** + * Event types define a hierarchical structure of events. Each event is bound to a certain event type. + * All event types have a super type, only the root event type {@link EventType#ROOT} has no super type. + * + * Event types should be stored as static fields on the events itself. + * + * @param The type class parameter allows to define the types in a type safe way and represents a event class, + * where the type is associated to. + */ +public class EventType implements Serializable { + + + public static final EventType ROOT = new EventType<>(); + + private final String name; + private final EventType superType; + private WeakHashMap, Void> subTypes; + + /** + * Creates a type with the given name and the root type as parent. + * @param name the name of the new type + */ + public EventType(String name) { + this.superType = ROOT; + this.name = name; + } + + /** + * Creates a event type instance with the given super type and name. + * + * @param superType The super type or null, if this is the root type. + * @param name + */ + public EventType(EventType superType, String name) { + if (superType==null) { + throw new NullPointerException("Super Type may not be null"); + } + this.name = name; + this.superType = superType; + superType.register(this); + } + + /** + * Creates the root type + */ + private EventType() { + this.name="ROOT"; + this.superType=null; + } + + public String name() { + return name; + } + + public EventType getSuperType() { + return superType; + } + + private void register(EventType subType) { + if (subTypes == null) { + subTypes = new WeakHashMap<>(); + } + for (EventType t : subTypes.keySet()) { + if (((t.name == null && subType.name == null) || (t.name != null && t.name.equals(subType.name)))) { + throw new IllegalArgumentException("EventType \"" + subType + "\"" + + "with parent \"" + subType.getSuperType()+"\" already exists"); + } + } + subTypes.put(subType, null); + } + + + public static List> fetchSuperTypes(EventType type) { + List> typeList = new ArrayList<>(); + EventType cType = type; + while (cType!=null) { + typeList.add(cType); + cType = cType.getSuperType(); + } + return typeList; + } + + public static boolean isInstanceOf(EventType type, EventType baseType) { + EventType cType = type; + while(cType!=null) { + if (cType == baseType) { + return true; + } + cType = cType.getSuperType(); + } + return false; + } + + + private Object writeReplace() throws ObjectStreamException { + Deque path = new LinkedList(); + EventType t = this; + while (t != ROOT) { + path.addFirst(t.name); + t = t.superType; + } + return new EventTypeSerialization(new ArrayList<>(path)); + } + + static class EventTypeSerialization implements Serializable { + private static final long serialVersionUID = 1841649460281865547L; + private List path; + + public EventTypeSerialization(List path) { + this.path = path; + } + + private Object readResolve() throws ObjectStreamException { + EventType t = ROOT; + for (int i = 0; i < path.size(); ++i) { + String p = path.get(i); + if (t.subTypes != null) { + EventType s = findSubType(t.subTypes.keySet(), p); + if (s == null) { + throw new InvalidObjectException("Cannot find event type \"" + p + "\" (of " + t + ")"); + } + t = s; + } else { + throw new InvalidObjectException("Cannot find event type \"" + p + "\" (of " + t + ")"); + } + } + return t; + } + + private EventType findSubType(Set subTypes, String name) { + for (EventType t : subTypes) { + if (((t.name == null && name == null) || (t.name != null && t.name.equals(name)))) { + return t; + } + } + return null; + } + + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/LifecycleEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/LifecycleEvent.java new file mode 100644 index 000000000..6408eb534 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/LifecycleEvent.java @@ -0,0 +1,43 @@ +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; + +/** + * Raises events about the repository lifecycle. The following events are raised: + *
    + *
  • REGISTERED: a repository has been registered by the repository registry
  • + *
  • UNREGISTERED: a repository has been removed by the repository registry
  • + *
  • UPDATED: A repository attribute was updated
  • + *
+ */ +public class LifecycleEvent extends RepositoryEvent { + + private static final long serialVersionUID = -2520982087439428714L; + public static EventType ANY = new EventType<>(RepositoryEvent.ANY, "REPOSITORY.LIFECYCLE"); + public static EventType REGISTERED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.REGISTERED"); + public static EventType UNREGISTERED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.UNREGISTERED"); + public static EventType UPDATED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.UPDATED"); + + public LifecycleEvent(EventType type, Object origin, Repository repository) { + super(type, origin, repository); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryEvent.java new file mode 100644 index 000000000..28d4770c0 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryEvent.java @@ -0,0 +1,49 @@ +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; + +/** + * A repository event is specific to a repository and holds a reference to the repository that + * is related to this event. + */ +public class RepositoryEvent extends Event { + + private static final long serialVersionUID = 4676673476606414834L; + + public static final EventType ANY = new EventType<>(Event.ANY, "REPOSITORY"); + + private final Repository repository; + + public RepositoryEvent(EventType type, Object origin, Repository repository) { + super(type, origin); + this.repository = repository; + } + + public Repository getRepository() { + return repository; + } + + @Override + public EventType getType() { + return (EventType) super.getType(); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryIndexEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryIndexEvent.java new file mode 100644 index 000000000..9f1b2a60d --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryIndexEvent.java @@ -0,0 +1,49 @@ +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; + +import java.net.URI; + +/** + * These events are thrown, when index information has changed. + */ +public class RepositoryIndexEvent extends RepositoryValueEvent { + + private static final long serialVersionUID = -7801989699524776524L; + + public static EventType ANY = new EventType<>(RepositoryValueEvent.ANY, "REPOSITORY.VALUE.INDEX"); + public static EventType INDEX_URI_CHANGED = new EventType<>(ANY, "REPOSITORY.VALUE.INDEX.URI_CHANGED"); + public static EventType PACKED_INDEX_URI_CHANGED = new EventType<>(ANY, "REPOSITORY.VALUE.INDEX.PACKED_URI_CHANGED"); + + RepositoryIndexEvent(EventType type, Object origin, Repository repo, URI oldValue, URI value) { + super(type, origin, repo, oldValue, value, "index.uri"); + } + + public static final RepositoryIndexEvent indexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { + return new RepositoryIndexEvent(INDEX_URI_CHANGED, origin, repo, oldValue, newValue); + } + + public static final RepositoryIndexEvent packedIndexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { + return new RepositoryIndexEvent(PACKED_INDEX_URI_CHANGED, origin, repo, oldValue, newValue); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryRegistryEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryRegistryEvent.java new file mode 100644 index 000000000..fbaa97199 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryRegistryEvent.java @@ -0,0 +1,49 @@ +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. + */ + +/** + * Repository registry events are raised by the repository registry itself. + */ +public class RepositoryRegistryEvent extends Event { + + private static final long serialVersionUID = -4740127827269612094L; + + /** + * All repository registry events + */ + public static EventType ANY = new EventType(EventType.ROOT, "REGISTRY"); + /** + * When the registry has reloaded the registry data from the configuration + */ + public static EventType RELOADED = new EventType(ANY, "REGISTRY.RELOADED"); + /** + * When the registry was destroyed. Repository instances may still be referenced, but are not updated. + */ + public static EventType DESTROYED = new EventType(ANY, "REGISTRY.DESTROYED"); + /** + * When the registry was initialized + */ + public static EventType INITIALIZED = new EventType(ANY, "REGISTRY.INITIALIZED"); + + public RepositoryRegistryEvent(EventType type, Object origin) { + super(type, origin); + } +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryValueEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryValueEvent.java new file mode 100644 index 000000000..448d72027 --- /dev/null +++ b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryValueEvent.java @@ -0,0 +1,60 @@ +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 value events are used for providing information about repository attribute changes. + * The value event gives information of the attribute value before and after the change. + * + * @param The type of the changed attribute + */ +public class RepositoryValueEvent extends RepositoryEvent { + + private static final long serialVersionUID = 4176597620699304794L; + + public static final EventType> ANY = new EventType(RepositoryEvent.ANY, "REPOSITORY.VALUE"); + + final V value; + final V oldValue; + final String attributeName; + + public RepositoryValueEvent(EventType> type, Object origin, Repository repo, V oldValue, V value, + String attributeName) { + super(type, origin, repo); + this.value = value; + this.oldValue = oldValue; + this.attributeName = attributeName; + } + + public V getValue() { + return value; + } + + public V getOldValue() { + return oldValue; + } + + public String getAttributeName() { + return attributeName; + } + +} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/Event.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/Event.java deleted file mode 100644 index dc91defc5..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/Event.java +++ /dev/null @@ -1,112 +0,0 @@ -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.time.LocalDateTime; -import java.util.EventObject; - -/** - * Base class for events. Events have a type and a source. - * The source is the instance that raised the event. - * - * There are different event types for a given event. The types are represented in a hierarchical structure. - * - * Events can be chained, which means a event listener can catch events and rethrow them as its own event. - * - */ -public class Event extends EventObject implements Cloneable { - - private static final long serialVersionUID = -7171846575892044990L; - - public static final EventType ANY = EventType.ROOT; - - private Event previous; - private final EventType type; - private final LocalDateTime createTime; - - public Event(EventType type, Object originator) { - super(originator); - this.type = type; - this.createTime = LocalDateTime.now(); - } - - private Event(Event previous, Object originator) { - super(originator); - this.previous = previous; - this.type = previous.getType(); - this.createTime = previous.getCreateTime(); - } - - /** - * Returns the event type that is associated with this event instance. - * @return the event type - */ - public EventType getType() { - return type; - }; - - /** - * Returns the time, when the event was created. - * @return - */ - public LocalDateTime getCreateTime() { - return createTime; - } - - - /** - * Recreates the event with the given instance as the new source. The - * current source is stored in the previous event. - * @param newSource The new source - * @return a new event instance, where this is stored as previous event - */ - public Event copyFor(Object newSource) { - Event newEvent = (Event) this.clone(); - newEvent.previous = this; - newEvent.source = newSource; - return newEvent; - } - - /** - * Returns the previous event or null, if this is a root event. - * @return the previous event or null, if it does not exist - */ - public Event getPreviousEvent() { - return previous; - } - - /** - * Returns true, if the event has a previous event. - * @return true, if this has a previous event, otherwise false - */ - public boolean hasPreviousEvent() { - return previous!=null; - } - - @Override - protected Object clone() { - try { - return super.clone(); - } catch (CloneNotSupportedException e) { - // this should not happen - throw new RuntimeException("Event is not clonable"); - } - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventHandler.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventHandler.java deleted file mode 100644 index 9f2d4411e..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -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.EventListener; - -/** - * A listener that accepts events. - */ -public interface EventHandler extends EventListener { - - void handle(T event); -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventManager.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventManager.java deleted file mode 100644 index 694cfd9e6..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventManager.java +++ /dev/null @@ -1,79 +0,0 @@ -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.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class EventManager implements EventSource { - - private static final Logger log = LoggerFactory.getLogger(EventManager.class); - - private final ConcurrentHashMap, Set> handlerMap = new ConcurrentHashMap<>(); - - private final Object source; - - public EventManager(Object source) { - if (source==null) { - throw new IllegalArgumentException("The source may not be null"); - } - this.source = source; - } - - @Override - public void registerEventHandler(EventType type, EventHandler eventHandler) { - Set handlers = handlerMap.computeIfAbsent(type, t -> new LinkedHashSet<>()); - if (!handlers.contains(eventHandler)) { - handlers.add(eventHandler); - } - } - - @Override - public void unregisterEventHandler(EventType type, EventHandler eventHandler) { - if (handlerMap.containsKey(type)) { - handlerMap.get(type).remove(eventHandler); - } - } - - public void fireEvent(Event fireEvent) { - final EventType type = fireEvent.getType(); - Event event; - if (fireEvent.getSource()!=source) { - event = fireEvent.copyFor(source); - } else { - event = fireEvent; - } - for (EventType handlerType : handlerMap.keySet()) { - if (EventType.isInstanceOf(type, handlerType)) { - for (EventHandler handler : handlerMap.get(handlerType)) { - try { - handler.handle(event); - } catch (Exception e) { - // We catch all errors from handlers - log.error("An error occured during event handling: {}", e.getMessage(), e); - } - } - } - } - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventSource.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventSource.java deleted file mode 100644 index cffaeaf56..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventSource.java +++ /dev/null @@ -1,33 +0,0 @@ -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. - */ - -/** - * A repository event source raises events to its registered listeners. - * Listeners register to event types that are structured hierarchical. - * - */ -public interface EventSource { - - void registerEventHandler(EventType type, EventHandler eventHandler); - - void unregisterEventHandler(EventType type, EventHandler eventHandler); - -} 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 deleted file mode 100644 index ab9678ab2..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/EventType.java +++ /dev/null @@ -1,166 +0,0 @@ -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.io.InvalidObjectException; -import java.io.ObjectStreamException; -import java.io.Serializable; -import java.util.*; - -/** - * Event types define a hierarchical structure of events. Each event is bound to a certain event type. - * All event types have a super type, only the root event type {@link EventType#ROOT} has no super type. - * - * Event types should be stored as static fields on the events itself. - * - * @param The type class parameter allows to define the types in a type safe way and represents a event class, - * where the type is associated to. - */ -public class EventType implements Serializable { - - - public static final EventType ROOT = new EventType<>(); - - private final String name; - private final EventType superType; - private WeakHashMap, Void> subTypes; - - /** - * Creates a type with the given name and the root type as parent. - * @param name the name of the new type - */ - public EventType(String name) { - this.superType = ROOT; - this.name = name; - } - - /** - * Creates a event type instance with the given super type and name. - * - * @param superType The super type or null, if this is the root type. - * @param name - */ - public EventType(EventType superType, String name) { - if (superType==null) { - throw new NullPointerException("Super Type may not be null"); - } - this.name = name; - this.superType = superType; - superType.register(this); - } - - /** - * Creates the root type - */ - private EventType() { - this.name="ROOT"; - this.superType=null; - } - - public String name() { - return name; - } - - public EventType getSuperType() { - return superType; - } - - private void register(EventType subType) { - if (subTypes == null) { - subTypes = new WeakHashMap<>(); - } - for (EventType t : subTypes.keySet()) { - if (((t.name == null && subType.name == null) || (t.name != null && t.name.equals(subType.name)))) { - throw new IllegalArgumentException("EventType \"" + subType + "\"" - + "with parent \"" + subType.getSuperType()+"\" already exists"); - } - } - subTypes.put(subType, null); - } - - - public static List> fetchSuperTypes(EventType type) { - List> typeList = new ArrayList<>(); - EventType cType = type; - while (cType!=null) { - typeList.add(cType); - cType = cType.getSuperType(); - } - return typeList; - } - - public static boolean isInstanceOf(EventType type, EventType baseType) { - EventType cType = type; - while(cType!=null) { - if (cType == baseType) { - return true; - } - cType = cType.getSuperType(); - } - return false; - } - - - private Object writeReplace() throws ObjectStreamException { - Deque path = new LinkedList(); - EventType t = this; - while (t != ROOT) { - path.addFirst(t.name); - t = t.superType; - } - return new EventTypeSerialization(new ArrayList<>(path)); - } - - static class EventTypeSerialization implements Serializable { - private static final long serialVersionUID = 1841649460281865547L; - private List path; - - public EventTypeSerialization(List path) { - this.path = path; - } - - private Object readResolve() throws ObjectStreamException { - EventType t = ROOT; - for (int i = 0; i < path.size(); ++i) { - String p = path.get(i); - if (t.subTypes != null) { - EventType s = findSubType(t.subTypes.keySet(), p); - if (s == null) { - throw new InvalidObjectException("Cannot find event type \"" + p + "\" (of " + t + ")"); - } - t = s; - } else { - throw new InvalidObjectException("Cannot find event type \"" + p + "\" (of " + t + ")"); - } - } - return t; - } - - private EventType findSubType(Set subTypes, String name) { - for (EventType t : subTypes) { - if (((t.name == null && name == null) || (t.name != null && t.name.equals(name)))) { - return t; - } - } - return null; - } - - } -} 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 deleted file mode 100644 index 6408eb534..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/LifecycleEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -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; - -/** - * Raises events about the repository lifecycle. The following events are raised: - *
    - *
  • REGISTERED: a repository has been registered by the repository registry
  • - *
  • UNREGISTERED: a repository has been removed by the repository registry
  • - *
  • UPDATED: A repository attribute was updated
  • - *
- */ -public class LifecycleEvent extends RepositoryEvent { - - private static final long serialVersionUID = -2520982087439428714L; - public static EventType ANY = new EventType<>(RepositoryEvent.ANY, "REPOSITORY.LIFECYCLE"); - public static EventType REGISTERED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.REGISTERED"); - public static EventType UNREGISTERED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.UNREGISTERED"); - public static EventType UPDATED = new EventType<>(ANY, "REPOSITORY.LIFECYCLE.UPDATED"); - - public LifecycleEvent(EventType type, Object 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 deleted file mode 100644 index 28d4770c0..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -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; - -/** - * A repository event is specific to a repository and holds a reference to the repository that - * is related to this event. - */ -public class RepositoryEvent extends Event { - - private static final long serialVersionUID = 4676673476606414834L; - - public static final EventType ANY = new EventType<>(Event.ANY, "REPOSITORY"); - - private final Repository repository; - - public RepositoryEvent(EventType type, Object origin, Repository repository) { - super(type, origin); - this.repository = repository; - } - - public Repository getRepository() { - return repository; - } - - @Override - public EventType getType() { - return (EventType) super.getType(); - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryIndexEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryIndexEvent.java deleted file mode 100644 index 9f1b2a60d..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryIndexEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -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; - -import java.net.URI; - -/** - * These events are thrown, when index information has changed. - */ -public class RepositoryIndexEvent extends RepositoryValueEvent { - - private static final long serialVersionUID = -7801989699524776524L; - - public static EventType ANY = new EventType<>(RepositoryValueEvent.ANY, "REPOSITORY.VALUE.INDEX"); - public static EventType INDEX_URI_CHANGED = new EventType<>(ANY, "REPOSITORY.VALUE.INDEX.URI_CHANGED"); - public static EventType PACKED_INDEX_URI_CHANGED = new EventType<>(ANY, "REPOSITORY.VALUE.INDEX.PACKED_URI_CHANGED"); - - RepositoryIndexEvent(EventType type, Object origin, Repository repo, URI oldValue, URI value) { - super(type, origin, repo, oldValue, value, "index.uri"); - } - - public static final RepositoryIndexEvent indexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { - return new RepositoryIndexEvent(INDEX_URI_CHANGED, origin, repo, oldValue, newValue); - } - - public static final RepositoryIndexEvent packedIndexUriChange(O origin, Repository repo, URI oldValue, URI newValue) { - return new RepositoryIndexEvent(PACKED_INDEX_URI_CHANGED, origin, repo, oldValue, newValue); - } -} diff --git a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryRegistryEvent.java b/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryRegistryEvent.java deleted file mode 100644 index fbaa97199..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryRegistryEvent.java +++ /dev/null @@ -1,49 +0,0 @@ -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. - */ - -/** - * Repository registry events are raised by the repository registry itself. - */ -public class RepositoryRegistryEvent extends Event { - - private static final long serialVersionUID = -4740127827269612094L; - - /** - * All repository registry events - */ - public static EventType ANY = new EventType(EventType.ROOT, "REGISTRY"); - /** - * When the registry has reloaded the registry data from the configuration - */ - public static EventType RELOADED = new EventType(ANY, "REGISTRY.RELOADED"); - /** - * When the registry was destroyed. Repository instances may still be referenced, but are not updated. - */ - public static EventType DESTROYED = new EventType(ANY, "REGISTRY.DESTROYED"); - /** - * When the registry was initialized - */ - public static EventType INITIALIZED = new EventType(ANY, "REGISTRY.INITIALIZED"); - - public RepositoryRegistryEvent(EventType type, Object 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 deleted file mode 100644 index 448d72027..000000000 --- a/archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryValueEvent.java +++ /dev/null @@ -1,60 +0,0 @@ -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 value events are used for providing information about repository attribute changes. - * The value event gives information of the attribute value before and after the change. - * - * @param The type of the changed attribute - */ -public class RepositoryValueEvent extends RepositoryEvent { - - private static final long serialVersionUID = 4176597620699304794L; - - public static final EventType> ANY = new EventType(RepositoryEvent.ANY, "REPOSITORY.VALUE"); - - final V value; - final V oldValue; - final String attributeName; - - public RepositoryValueEvent(EventType> type, Object origin, Repository repo, V oldValue, V value, - String attributeName) { - super(type, origin, repo); - this.value = value; - this.oldValue = oldValue; - this.attributeName = attributeName; - } - - public V getValue() { - return value; - } - - public V getOldValue() { - return oldValue; - } - - public String getAttributeName() { - return attributeName; - } - -} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/AuditListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/AuditListener.java new file mode 100644 index 000000000..ade9f7959 --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/AuditListener.java @@ -0,0 +1,37 @@ +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.metadata.model.facets.AuditEvent; + +/** + * AuditListener + * + * + */ +public interface AuditListener +{ + /** + * Notification that an audit event occured. + * + * @param event the event details. + */ + void auditEvent( AuditEvent event ); +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryListener.java new file mode 100644 index 000000000..e23b2ec6a --- /dev/null +++ b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/event/RepositoryListener.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.metadata.model.ProjectVersionMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.archiva.metadata.repository.RepositorySession; +import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException; + +/** + * Listen to events on the repository. This class is a stopgap + * refactoring measure until an event bus is in place to handle + * generic events such as these. + *

+ * This assumes that the events occur before the action has completed, though they don't currently offer any mechanism + * to prevent an event from occurring or guarantee that it will happen. + *

+ * FIXME: this needs to be made more permanent since 3rd party plugins will depend on it heavily + */ +public interface RepositoryListener +{ + void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace, String project, + String version, String id ); + + void addArtifact( RepositorySession session, String repoId, String namespace, String projectId, + ProjectVersionMetadata metadata ); + + // FIXME: this would be better as a "processException" method, with the event information captured in a single class + void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId, + String projectVersion, RepositoryStorageMetadataException exception ); +} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/AuditListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/AuditListener.java deleted file mode 100644 index ade9f7959..000000000 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/AuditListener.java +++ /dev/null @@ -1,37 +0,0 @@ -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.metadata.model.facets.AuditEvent; - -/** - * AuditListener - * - * - */ -public interface AuditListener -{ - /** - * Notification that an audit event occured. - * - * @param event the event details. - */ - void auditEvent( AuditEvent event ); -} diff --git a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java b/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java deleted file mode 100644 index e23b2ec6a..000000000 --- a/archiva-modules/metadata/metadata-repository-api/src/main/java/org/apache/archiva/repository/events/RepositoryListener.java +++ /dev/null @@ -1,48 +0,0 @@ -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.metadata.model.ProjectVersionMetadata; -import org.apache.archiva.metadata.repository.MetadataRepository; -import org.apache.archiva.metadata.repository.RepositorySession; -import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataException; - -/** - * Listen to events on the repository. This class is a stopgap - * refactoring measure until an event bus is in place to handle - * generic events such as these. - *

- * This assumes that the events occur before the action has completed, though they don't currently offer any mechanism - * to prevent an event from occurring or guarantee that it will happen. - *

- * FIXME: this needs to be made more permanent since 3rd party plugins will depend on it heavily - */ -public interface RepositoryListener -{ - void deleteArtifact( MetadataRepository metadataRepository, String repositoryId, String namespace, String project, - String version, String id ); - - void addArtifact( RepositorySession session, String repoId, String namespace, String projectId, - ProjectVersionMetadata metadata ); - - // FIXME: this would be better as a "processException" method, with the event information captured in a single class - void addArtifactProblem( RepositorySession session, String repoId, String namespace, String projectId, - String projectVersion, RepositoryStorageMetadataException exception ); -}