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.extension.internal;
20  
21  import java.util.Collections;
22  import java.util.HashSet;
23  import java.util.Map;
24  import java.util.Set;
25  
26  import org.codehaus.plexus.classworlds.realm.ClassRealm;
27  
28  import static java.util.function.Function.identity;
29  import static java.util.stream.Collectors.collectingAndThen;
30  import static java.util.stream.Collectors.toMap;
31  
32  /**
33   * Provides information about artifacts (identified by groupId:artifactId string key) and classpath elements exported by
34   * Maven core itself and loaded Maven core extensions.
35   *
36   * @since 3.3.0
37   */
38  public class CoreExports {
39      private final Set<String> artifacts;
40  
41      private final Map<String, ClassLoader> packages;
42  
43      public CoreExports(CoreExtensionEntry entry) {
44          this(entry.getClassRealm(), entry.getExportedArtifacts(), entry.getExportedPackages());
45      }
46  
47      public CoreExports(ClassRealm realm, Set<String> exportedArtifacts, Set<String> exportedPackages) {
48          this.artifacts = Collections.unmodifiableSet(new HashSet<>(exportedArtifacts));
49          this.packages = exportedPackages.stream()
50                  .collect(collectingAndThen(toMap(identity(), v -> realm), Collections::unmodifiableMap));
51      }
52  
53      /**
54       * Returns artifacts exported by Maven core and core extensions. Artifacts are identified by their
55       * groupId:artifactId string key.
56       */
57      public Set<String> getExportedArtifacts() {
58          return artifacts;
59      }
60  
61      /**
62       * Returns packages exported by Maven core and core extensions.
63       */
64      public Map<String, ClassLoader> getExportedPackages() {
65          return packages;
66      }
67  }