001package org.apache.maven.extension.internal;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.LinkedHashMap;
023import java.util.Map;
024import java.util.Set;
025
026import org.codehaus.plexus.classworlds.realm.ClassRealm;
027
028import com.google.common.collect.ImmutableMap;
029import com.google.common.collect.ImmutableSet;
030
031/**
032 * Provides information about artifacts (identified by groupId:artifactId string key) and classpath elements exported by
033 * Maven core itself and loaded Maven core extensions.
034 * 
035 * @since 3.3.0
036 */
037public class CoreExports
038{
039    private final Set<String> artifacts;
040
041    private final Map<String, ClassLoader> packages;
042
043    public CoreExports( CoreExtensionEntry entry )
044    {
045        this( entry.getClassRealm(), entry.getExportedArtifacts(), entry.getExportedPackages() );
046    }
047
048    public CoreExports( ClassRealm realm, Set<String> exportedArtifacts, Set<String> exportedPackages )
049    {
050        Map<String, ClassLoader> packages = new LinkedHashMap<>();
051        for ( String pkg : exportedPackages )
052        {
053            packages.put( pkg, realm );
054        }
055        this.artifacts = ImmutableSet.copyOf( exportedArtifacts );
056        this.packages = ImmutableMap.copyOf( packages );
057    }
058
059    /**
060     * Returns artifacts exported by Maven core and core extensions. Artifacts are identified by their
061     * groupId:artifactId string key.
062     */
063    public Set<String> getExportedArtifacts()
064    {
065        return artifacts;
066    }
067
068    /**
069     * Returns packages exported by Maven core and core extensions.
070     */
071    public Map<String, ClassLoader> getExportedPackages()
072    {
073        return packages;
074    }
075}