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