001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.artifact.repository.metadata;
020
021import java.util.Iterator;
022import java.util.List;
023
024import org.apache.maven.artifact.repository.ArtifactRepository;
025
026/**
027 * Metadata for the group directory of the repository.
028 * Class copied from maven-compat for to remove dependency but keep compatibility with Maven 3 (and Nexus Staging
029 * Plugin, see <a href="https://issues.apache.org/jira/browse/MPLUGIN-384">MPLUGIN-384</a>)
030 *
031 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
032 */
033public class GroupRepositoryMetadata extends AbstractRepositoryMetadata {
034    private final String groupId;
035
036    public GroupRepositoryMetadata(String groupId) {
037        super(new Metadata());
038        this.groupId = groupId;
039    }
040
041    public boolean storedInGroupDirectory() {
042        return true;
043    }
044
045    public boolean storedInArtifactVersionDirectory() {
046        return false;
047    }
048
049    public String getGroupId() {
050        return groupId;
051    }
052
053    public String getArtifactId() {
054        return null;
055    }
056
057    public String getBaseVersion() {
058        return null;
059    }
060
061    public void addPluginMapping(String goalPrefix, String artifactId) {
062        addPluginMapping(goalPrefix, artifactId, artifactId);
063    }
064
065    public void addPluginMapping(String goalPrefix, String artifactId, String name) {
066        List<Plugin> plugins = getMetadata().getPlugins();
067        boolean found = false;
068        for (Iterator<Plugin> i = plugins.iterator(); i.hasNext() && !found; ) {
069            Plugin plugin = i.next();
070            if (plugin.getPrefix().equals(goalPrefix)) {
071                found = true;
072            }
073        }
074        if (!found) {
075            Plugin plugin = new Plugin();
076            plugin.setPrefix(goalPrefix);
077            plugin.setArtifactId(artifactId);
078            plugin.setName(name);
079
080            getMetadata().addPlugin(plugin);
081        }
082    }
083
084    public Object getKey() {
085        return groupId;
086    }
087
088    public boolean isSnapshot() {
089        return false;
090    }
091
092    public ArtifactRepository getRepository() {
093        return null;
094    }
095
096    public void setRepository(ArtifactRepository remoteRepository) {
097        // intentionally blank
098    }
099}