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.artifact.Artifact; 025 026/** 027 * A request to register an artifact within the local repository. Certain local repository implementations can refuse to 028 * serve physically present artifacts if those haven't been previously registered to them. 029 * 030 * @see LocalRepositoryManager#add(org.eclipse.aether.RepositorySystemSession, LocalArtifactRegistration) 031 */ 032public final class LocalArtifactRegistration { 033 034 private Artifact artifact; 035 036 private RemoteRepository repository; 037 038 private Collection<String> contexts = Collections.emptyList(); 039 040 /** 041 * Creates an uninitialized registration. 042 */ 043 public LocalArtifactRegistration() { 044 // enables default constructor 045 } 046 047 /** 048 * Creates a registration request for the specified (locally installed) artifact. 049 * 050 * @param artifact The artifact to register, may be {@code null}. 051 */ 052 public LocalArtifactRegistration(Artifact artifact) { 053 setArtifact(artifact); 054 } 055 056 /** 057 * Creates a registration request for the specified artifact. 058 * 059 * @param artifact The artifact to register, may be {@code null}. 060 * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was 061 * locally installed. 062 * @param contexts The resolution contexts, may be {@code null}. 063 */ 064 public LocalArtifactRegistration(Artifact artifact, RemoteRepository repository, Collection<String> contexts) { 065 setArtifact(artifact); 066 setRepository(repository); 067 setContexts(contexts); 068 } 069 070 /** 071 * Gets the artifact to register. 072 * 073 * @return The artifact or {@code null} if not set. 074 */ 075 public Artifact getArtifact() { 076 return artifact; 077 } 078 079 /** 080 * Sets the artifact to register. 081 * 082 * @param artifact The artifact, may be {@code null}. 083 * @return This request for chaining, never {@code null}. 084 */ 085 public LocalArtifactRegistration setArtifact(Artifact artifact) { 086 this.artifact = artifact; 087 return this; 088 } 089 090 /** 091 * Gets the remote repository from which the artifact was resolved. 092 * 093 * @return The remote repository or {@code null} if the artifact was locally installed. 094 */ 095 public RemoteRepository getRepository() { 096 return repository; 097 } 098 099 /** 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}