View Javadoc
1   package org.apache.maven.extension.internal;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collections;
23  import java.util.HashSet;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.codehaus.plexus.classworlds.realm.ClassRealm;
28  
29  import static java.util.function.Function.identity;
30  import static java.util.stream.Collectors.collectingAndThen;
31  import static java.util.stream.Collectors.toMap;
32  
33  /**
34   * Provides information about artifacts (identified by groupId:artifactId string key) and classpath elements exported by
35   * Maven core itself and loaded Maven core extensions.
36   *
37   * @since 3.3.0
38   */
39  public class CoreExports
40  {
41      private final Set<String> artifacts;
42  
43      private final Map<String, ClassLoader> packages;
44  
45      public CoreExports( CoreExtensionEntry entry )
46      {
47          this( entry.getClassRealm(), entry.getExportedArtifacts(), entry.getExportedPackages() );
48      }
49  
50      public CoreExports( ClassRealm realm, Set<String> exportedArtifacts, Set<String> exportedPackages )
51      {
52          this.artifacts = Collections.unmodifiableSet( new HashSet<>( exportedArtifacts ) );
53          this.packages = exportedPackages.stream().collect(
54                  collectingAndThen( toMap( identity(), v -> realm ), Collections::unmodifiableMap ) );
55      }
56  
57      /**
58       * Returns artifacts exported by Maven core and core extensions. Artifacts are identified by their
59       * groupId:artifactId string key.
60       */
61      public Set<String> getExportedArtifacts()
62      {
63          return artifacts;
64      }
65  
66      /**
67       * Returns packages exported by Maven core and core extensions.
68       */
69      public Map<String, ClassLoader> getExportedPackages()
70      {
71          return packages;
72      }
73  }