001package org.apache.maven.eventspy;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Map;
023
024/**
025 * A core extension to monitor Maven's execution. Typically, such an extension gets loaded into Maven by specifying the
026 * system property {@code maven.ext.class.path} on the command line. As soon as dependency injection is setup, Maven
027 * looks up all implementators of this interface and calls their {@link #init(Context)} method. <em>Note:</em>
028 * Implementors are strongly advised to inherit from {@link AbstractEventSpy} instead of directly implementing this
029 * interface.
030 * @since 3.0.2
031 */
032public interface EventSpy
033{
034
035    interface Context
036    {
037
038        /**
039         * Gets key-value pairs providing information about the Maven runtime.
040         * 
041         * @return The key-value pairs, never {@code null}.
042         */
043        Map<String, Object> getData();
044
045    }
046
047    /**
048     * Initializes the spy.
049     * 
050     * @param context The event spy context, never {@code null}.
051     */
052    void init( Context context )
053        throws Exception;
054
055    /**
056     * Notifies the spy of some build event/operation.
057     * 
058     * @param event The event, never {@code null}.
059     * @see org.apache.maven.settings.building.SettingsBuildingRequest
060     * @see org.apache.maven.settings.building.SettingsBuildingResult
061     * @see org.apache.maven.execution.MavenExecutionRequest
062     * @see org.apache.maven.execution.MavenExecutionResult
063     * @see org.apache.maven.project.DependencyResolutionRequest
064     * @see org.apache.maven.project.DependencyResolutionResult
065     * @see org.apache.maven.execution.ExecutionEvent
066     * @see org.eclipse.aether.RepositoryEvent
067     */
068    void onEvent( Object event )
069        throws Exception;
070
071    /**
072     * Notifies the spy of Maven's termination, allowing it to free any resources allocated by it.
073     */
074    void close()
075        throws Exception;
076
077}