001package org.apache.maven.classrealm;
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.List;
023import java.util.Map;
024
025import org.apache.maven.model.Model;
026import org.apache.maven.model.Plugin;
027import org.codehaus.plexus.classworlds.realm.ClassRealm;
028import org.eclipse.aether.artifact.Artifact;
029
030/**
031 * Manages the class realms used by Maven. <strong>Warning:</strong> This is an internal utility interface that is only
032 * public for technical reasons, it is not part of the public API. In particular, this interface can be changed or
033 * deleted without prior notice.
034 * 
035 * @author Benjamin Bentmann
036 */
037public interface ClassRealmManager
038{
039
040    /**
041     * Gets the class realm hosting the Maven core.
042     * 
043     * @return The class realm hosting the Maven core, never {@code null}.
044     */
045    ClassRealm getCoreRealm();
046
047    /**
048     * Gets the class realm exposing the Maven API. This is basically a restricted view on the Maven core realm.
049     * 
050     * @return The class realm exposing the Maven API, never {@code null}.
051     */
052    ClassRealm getMavenApiRealm();
053
054    /**
055     * Creates a new class realm for the specified project and its build extensions.
056     * 
057     * @param model The model of the project for which to create a realm, must not be {@code null}.
058     * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
059     *            missing file) will automatically be excluded from the realm.
060     * @return The new project realm, never {@code null}.
061     */
062    ClassRealm createProjectRealm( Model model, List<Artifact> artifacts );
063
064    /**
065     * Creates a new class realm for the specified build extension.
066     * 
067     * @param extension The extension plugin for which to create a realm, must not be {@code null}.
068     * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
069     *            missing file) will automatically be excluded from the realm.
070     * @return The new extension realm, never {@code null}.
071     */
072    ClassRealm createExtensionRealm( Plugin extension, List<Artifact> artifacts );
073
074    /**
075     * Creates a new class realm for the specified plugin.
076     * 
077     * @param plugin The plugin for which to create a realm, must not be {@code null}.
078     * @param parent The parent realm for the new realm, may be {@code null}.
079     * @param parentImports The packages/types to import from the parent realm, may be {@code null}.
080     * @param foreignImports The packages/types to import from foreign realms, may be {@code null}.
081     * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
082     *            missing file) will automatically be excluded from the realm.
083     * @return The new plugin realm, never {@code null}.
084     */
085    ClassRealm createPluginRealm( Plugin plugin, ClassLoader parent, List<String> parentImports,
086                                  Map<String, ClassLoader> foreignImports, List<Artifact> artifacts );
087
088}