001package org.apache.maven.plugin.prefix;
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.Collections;
023import java.util.List;
024
025import org.apache.maven.execution.MavenSession;
026import org.apache.maven.model.Model;
027import org.apache.maven.project.MavenProject;
028import org.eclipse.aether.RepositorySystemSession;
029import org.eclipse.aether.repository.RemoteRepository;
030
031/**
032 * Collects settings required to resolve a plugin prefix.
033 * 
034 * @since 3.0
035 * @author Benjamin Bentmann
036 */
037public class DefaultPluginPrefixRequest
038    implements PluginPrefixRequest
039{
040
041    private String prefix;
042
043    private List<String> pluginGroups = Collections.emptyList();
044
045    private Model pom;
046
047    private List<RemoteRepository> repositories = Collections.emptyList();
048
049    private RepositorySystemSession session;
050
051    /**
052     * Creates an empty request.
053     */
054    public DefaultPluginPrefixRequest()
055    {
056    }
057
058    /**
059     * Creates a request for the specified plugin prefix and build session. The provided build session will be used to
060     * configure repository settings. If the session has a current project, its plugin repositories and model will be
061     * used as well.
062     * 
063     * @param prefix The plugin prefix to resolve, must not be {@code null}.
064     * @param session The build session from which to derive further settings, must not be {@code null}.
065     */
066    public DefaultPluginPrefixRequest( String prefix, MavenSession session )
067    {
068        setPrefix( prefix );
069
070        setRepositorySession( session.getRepositorySession() );
071
072        MavenProject project = session.getCurrentProject();
073        if ( project != null )
074        {
075            setRepositories( project.getRemotePluginRepositories() );
076            setPom( project.getModel() );
077        }
078
079        setPluginGroups( session.getPluginGroups() );
080    }
081
082    public String getPrefix()
083    {
084        return prefix;
085    }
086
087    public DefaultPluginPrefixRequest setPrefix( String prefix )
088    {
089        this.prefix = prefix;
090
091        return this;
092    }
093
094    public List<String> getPluginGroups()
095    {
096        return pluginGroups;
097    }
098
099    public DefaultPluginPrefixRequest setPluginGroups( List<String> pluginGroups )
100    {
101        if ( pluginGroups != null )
102        {
103            this.pluginGroups = pluginGroups;
104        }
105        else
106        {
107            this.pluginGroups = Collections.emptyList();
108        }
109
110        return this;
111    }
112
113    public Model getPom()
114    {
115        return pom;
116    }
117
118    public DefaultPluginPrefixRequest setPom( Model pom )
119    {
120        this.pom = pom;
121
122        return this;
123    }
124
125    public List<RemoteRepository> getRepositories()
126    {
127        return repositories;
128    }
129
130    public DefaultPluginPrefixRequest setRepositories( List<RemoteRepository> repositories )
131    {
132        if ( repositories != null )
133        {
134            this.repositories = repositories;
135        }
136        else
137        {
138            this.repositories = Collections.emptyList();
139        }
140
141        return this;
142    }
143
144    public RepositorySystemSession getRepositorySession()
145    {
146        return session;
147    }
148
149    public DefaultPluginPrefixRequest setRepositorySession( RepositorySystemSession session )
150    {
151        this.session = session;
152
153        return this;
154    }
155
156}