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       * Creates a new class realm for the specified project and its build extensions.
53       *
54       * @param model The model of the project for which to create a realm, must not be {@code null}.
55       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
56       *            missing file) will automatically be excluded from the realm.
57       * @return The new project realm, never {@code null}.
58       */
59      ClassRealm createProjectRealm(Model model, List<Artifact> artifacts);
60  
61      /**
62       * Creates a new class realm for the specified build extension.
63       *
64       * @param extension The extension plugin for which to create a realm, must not be {@code null}.
65       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
66       *            missing file) will automatically be excluded from the realm.
67       * @return The new extension realm, never {@code null}.
68       */
69      ClassRealm createExtensionRealm(Plugin extension, List<Artifact> artifacts);
70  
71      /**
72       * Creates a new class realm for the specified plugin.
73       *
74       * @param plugin The plugin for which to create a realm, must not be {@code null}.
75       * @param parent The parent realm for the new realm, may be {@code null}.
76       * @param parentImports The packages/types to import from the parent realm, may be {@code null}.
77       * @param foreignImports The packages/types to import from foreign realms, may be {@code null}.
78       * @param artifacts The artifacts to add to the class realm, may be {@code null}. Unresolved artifacts (i.e. with a
79       *            missing file) will automatically be excluded from the realm.
80       * @return The new plugin realm, never {@code null}.
81       */
82      ClassRealm createPluginRealm(
83              Plugin plugin,
84              ClassLoader parent,
85              List<String> parentImports,
86              Map<String, ClassLoader> foreignImports,
87              List<Artifact> artifacts);
88  }