1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.eclipse.aether.repository; 20 21 import java.util.Collection; 22 import java.util.Collections; 23 24 import org.eclipse.aether.artifact.Artifact; 25 26 /** 27 * A request to register an artifact within the local repository. Certain local repository implementations can refuse to 28 * serve physically present artifacts if those haven't been previously registered to them. 29 * 30 * @see LocalRepositoryManager#add(org.eclipse.aether.RepositorySystemSession, LocalArtifactRegistration) 31 */ 32 public final class LocalArtifactRegistration { 33 34 private Artifact artifact; 35 36 private RemoteRepository repository; 37 38 private Collection<String> contexts = Collections.emptyList(); 39 40 /** 41 * Creates an uninitialized registration. 42 */ 43 public LocalArtifactRegistration() { 44 // enables default constructor 45 } 46 47 /** 48 * Creates a registration request for the specified (locally installed) artifact. 49 * 50 * @param artifact The artifact to register, may be {@code null}. 51 */ 52 public LocalArtifactRegistration(Artifact artifact) { 53 setArtifact(artifact); 54 } 55 56 /** 57 * Creates a registration request for the specified artifact. 58 * 59 * @param artifact The artifact to register, may be {@code null}. 60 * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was 61 * locally installed. 62 * @param contexts The resolution contexts, may be {@code null}. 63 */ 64 public LocalArtifactRegistration(Artifact artifact, RemoteRepository repository, Collection<String> contexts) { 65 setArtifact(artifact); 66 setRepository(repository); 67 setContexts(contexts); 68 } 69 70 /** 71 * Gets the artifact to register. 72 * 73 * @return The artifact or {@code null} if not set. 74 */ 75 public Artifact getArtifact() { 76 return artifact; 77 } 78 79 /** 80 * Sets the artifact to register. 81 * 82 * @param artifact The artifact, may be {@code null}. 83 * @return This request for chaining, never {@code null}. 84 */ 85 public LocalArtifactRegistration setArtifact(Artifact artifact) { 86 this.artifact = artifact; 87 return this; 88 } 89 90 /** 91 * Gets the remote repository from which the artifact was resolved. 92 * 93 * @return The remote repository or {@code null} if the artifact was locally installed. 94 */ 95 public RemoteRepository getRepository() { 96 return repository; 97 } 98 99 /** 100 * Sets the remote repository from which the artifact was resolved. 101 * 102 * @param repository The remote repository or {@code null} if the artifact was locally installed. 103 * @return This request for chaining, never {@code null}. 104 */ 105 public LocalArtifactRegistration setRepository(RemoteRepository repository) { 106 this.repository = repository; 107 return this; 108 } 109 110 /** 111 * Gets the resolution contexts in which the artifact is available. 112 * 113 * @return The resolution contexts in which the artifact is available, never {@code null}. 114 */ 115 public Collection<String> getContexts() { 116 return contexts; 117 } 118 119 /** 120 * Sets the resolution contexts in which the artifact is available. 121 * 122 * @param contexts The resolution contexts, may be {@code null}. 123 * @return This request for chaining, never {@code null}. 124 */ 125 public LocalArtifactRegistration setContexts(Collection<String> contexts) { 126 if (contexts != null) { 127 this.contexts = contexts; 128 } else { 129 this.contexts = Collections.emptyList(); 130 } 131 return this; 132 } 133 }