View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.classrealm;
20  
21  import java.util.List;
22  import java.util.Map;
23  
24  import org.apache.maven.model.Model;
25  import org.apache.maven.model.Plugin;
26  import org.codehaus.plexus.classworlds.realm.ClassRealm;
27  import org.eclipse.aether.artifact.Artifact;
28  
29  /**
30   * Manages the class realms used by Maven. <strong>Warning:</strong> This is an internal utility interface that is only
31   * public for technical reasons, it is not part of the public API. In particular, this interface can be changed or
32   * deleted without prior notice.
33   *
34   */
35  public interface ClassRealmManager {
36  
37      /**
38       * Gets the class realm hosting the Maven core.
39       *
40       * @return The class realm hosting the Maven core, never {@code null}.
41       */
42      ClassRealm getCoreRealm();
43  
44      /**
45       * Gets the class realm exposing the Maven API. This is basically a restricted view on the Maven core realm.
46       *
47       * @return The class realm exposing the Maven API, never {@code null}.
48       */
49      ClassRealm getMavenApiRealm();
50  
51      /**
52       * Gets the class realm exposing the Maven 4 API. This is basically a restricted view on the Maven core realm.
53       *
54       * @return The class realm exposing the Maven API, never {@code null}.
55       */
56      ClassRealm getMaven4ApiRealm();
57  
58      /**
59       * Creates a new class realm for the specified project and its build extensions.
60       *
61       * @param model The model of the project for which to create a realm, must not be {@code null}.
62       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
63       *            missing file) will automatically be excluded from the realm.
64       * @return The new project realm, never {@code null}.
65       */
66      ClassRealm createProjectRealm(Model model, List<Artifact> artifacts);
67  
68      /**
69       * Creates a new class realm for the specified build extension.
70       *
71       * @param extension The extension plugin for which to create a realm, must not be {@code null}.
72       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
73       *            missing file) will automatically be excluded from the realm.
74       * @return The new extension realm, never {@code null}.
75       */
76      ClassRealm createExtensionRealm(Plugin extension, List<Artifact> artifacts);
77  
78      /**
79       * Creates a new class realm for the specified plugin.
80       *
81       * @param plugin The plugin for which to create a realm, must not be {@code null}.
82       * @param parent The parent realm for the new realm, may be {@code null}.
83       * @param parentImports The packages/types to import from the parent realm, may be {@code null}.
84       * @param foreignImports The packages/types to import from foreign realms, may be {@code null}.
85       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
86       *            missing file) will automatically be excluded from the realm.
87       * @return The new plugin realm, never {@code null}.
88       */
89      ClassRealm createPluginRealm(
90              Plugin plugin,
91              ClassLoader parent,
92              List<String> parentImports,
93              Map<String, ClassLoader> foreignImports,
94              List<Artifact> artifacts);
95  }