1 package org.eclipse.aether.repository; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.util.Collection; 23 import java.util.Collections; 24 25 import org.eclipse.aether.RepositorySystemSession; 26 import org.eclipse.aether.metadata.Metadata; 27 28 /** 29 * A request to register metadata within the local repository. 30 * 31 * @see LocalRepositoryManager#add(RepositorySystemSession, LocalMetadataRegistration) 32 */ 33 public final class LocalMetadataRegistration 34 { 35 36 private Metadata metadata; 37 38 private RemoteRepository repository; 39 40 private Collection<String> contexts = Collections.emptyList(); 41 42 /** 43 * Creates an uninitialized registration. 44 */ 45 public LocalMetadataRegistration() 46 { 47 // enables default constructor 48 } 49 50 /** 51 * Creates a registration request for the specified metadata accompanying a locally installed artifact. 52 * 53 * @param metadata The metadata to register, may be {@code null}. 54 */ 55 public LocalMetadataRegistration( Metadata metadata ) 56 { 57 setMetadata( metadata ); 58 } 59 60 /** 61 * Creates a registration request for the specified metadata. 62 * 63 * @param metadata The metadata to register, may be {@code null}. 64 * @param repository The remote repository from which the metadata was resolved or {@code null} if the metadata 65 * accompanies a locally installed artifact. 66 * @param contexts The resolution contexts, may be {@code null}. 67 */ 68 public LocalMetadataRegistration( Metadata metadata, RemoteRepository repository, Collection<String> contexts ) 69 { 70 setMetadata( metadata ); 71 setRepository( repository ); 72 setContexts( contexts ); 73 } 74 75 /** 76 * Gets the metadata to register. 77 * 78 * @return The metadata or {@code null} if not set. 79 */ 80 public Metadata getMetadata() 81 { 82 return metadata; 83 } 84 85 /** 86 * Sets the metadata to register. 87 * 88 * @param metadata The metadata, may be {@code null}. 89 * @return This request for chaining, never {@code null}. 90 */ 91 public LocalMetadataRegistration setMetadata( Metadata metadata ) 92 { 93 this.metadata = metadata; 94 return this; 95 } 96 97 /** 98 * Gets the remote repository from which the metadata was resolved. 99 * 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 }