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