001package org.eclipse.aether.repository;
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.Collection;
023import java.util.Collections;
024
025import org.eclipse.aether.RepositorySystemSession;
026import org.eclipse.aether.metadata.Metadata;
027
028/**
029 * A request to register metadata within the local repository.
030 * 
031 * @see LocalRepositoryManager#add(RepositorySystemSession, LocalMetadataRegistration)
032 */
033public final class LocalMetadataRegistration
034{
035
036    private Metadata metadata;
037
038    private RemoteRepository repository;
039
040    private Collection<String> contexts = Collections.emptyList();
041
042    /**
043     * Creates an uninitialized registration.
044     */
045    public LocalMetadataRegistration()
046    {
047        // enables default constructor
048    }
049
050    /**
051     * Creates a registration request for the specified metadata accompanying a locally installed artifact.
052     * 
053     * @param metadata The metadata to register, may be {@code null}.
054     */
055    public LocalMetadataRegistration( Metadata metadata )
056    {
057        setMetadata( metadata );
058    }
059
060    /**
061     * Creates a registration request for the specified metadata.
062     * 
063     * @param metadata The metadata to register, may be {@code null}.
064     * @param repository The remote repository from which the metadata was resolved or {@code null} if the metadata
065     *            accompanies a locally installed artifact.
066     * @param contexts The resolution contexts, may be {@code null}.
067     */
068    public LocalMetadataRegistration( Metadata metadata, RemoteRepository repository, Collection<String> contexts )
069    {
070        setMetadata( metadata );
071        setRepository( repository );
072        setContexts( contexts );
073    }
074
075    /**
076     * Gets the metadata to register.
077     * 
078     * @return The metadata or {@code null} if not set.
079     */
080    public Metadata getMetadata()
081    {
082        return metadata;
083    }
084
085    /**
086     * Sets the metadata to register.
087     * 
088     * @param metadata The metadata, may be {@code null}.
089     * @return This request for chaining, never {@code null}.
090     */
091    public LocalMetadataRegistration setMetadata( Metadata metadata )
092    {
093        this.metadata = metadata;
094        return this;
095    }
096
097    /**
098     * Gets the remote repository from which the metadata was resolved.
099     * 
100     * @return The remote repository or {@code null} if the metadata was locally installed.
101     */
102    public RemoteRepository getRepository()
103    {
104        return repository;
105    }
106
107    /**
108     * Sets the remote repository from which the metadata was resolved.
109     * 
110     * @param repository The remote repository or {@code null} if the metadata accompanies a locally installed artifact.
111     * @return This request for chaining, never {@code null}.
112     */
113    public LocalMetadataRegistration setRepository( RemoteRepository repository )
114    {
115        this.repository = repository;
116        return this;
117    }
118
119    /**
120     * Gets the resolution contexts in which the metadata is available.
121     * 
122     * @return The resolution contexts in which the metadata is available, never {@code null}.
123     */
124    public Collection<String> getContexts()
125    {
126        return contexts;
127    }
128
129    /**
130     * Sets the resolution contexts in which the metadata is available.
131     * 
132     * @param contexts The resolution contexts, may be {@code null}.
133     * @return This request for chaining, never {@code null}.
134     */
135    public LocalMetadataRegistration setContexts( Collection<String> contexts )
136    {
137        if ( contexts != null )
138        {
139            this.contexts = contexts;
140        }
141        else
142        {
143            this.contexts = Collections.emptyList();
144        }
145        return this;
146    }
147
148}