1 /******************************************************************************* 2 * Copyright (c) 2010, 2011 Sonatype, Inc. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Eclipse Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/epl-v10.html 7 * 8 * Contributors: 9 * Sonatype, Inc. - initial API and implementation 10 *******************************************************************************/ 11 package org.eclipse.aether.repository; 12 13 import java.util.Collection; 14 import java.util.Collections; 15 16 import org.eclipse.aether.RepositorySystemSession; 17 import org.eclipse.aether.artifact.Artifact; 18 19 /** 20 * A request to register an artifact within the local repository. Certain local repository implementations can refuse to 21 * serve physically present artifacts if those haven't been previously registered to them. 22 * 23 * @see LocalRepositoryManager#add(RepositorySystemSession, LocalArtifactRegistration) 24 */ 25 public final class LocalArtifactRegistration 26 { 27 28 private Artifact artifact; 29 30 private RemoteRepository repository; 31 32 private Collection<String> contexts = Collections.emptyList(); 33 34 /** 35 * Creates an uninitialized registration. 36 */ 37 public LocalArtifactRegistration() 38 { 39 // enables default constructor 40 } 41 42 /** 43 * Creates a registration request for the specified (locally installed) artifact. 44 * 45 * @param artifact The artifact to register, may be {@code null}. 46 */ 47 public LocalArtifactRegistration( Artifact artifact ) 48 { 49 setArtifact( artifact ); 50 } 51 52 /** 53 * Creates a registration request for the specified artifact. 54 * 55 * @param artifact The artifact to register, may be {@code null}. 56 * @param repository The remote repository from which the artifact was resolved or {@code null} if the artifact was 57 * locally installed. 58 * @param contexts The resolution contexts, may be {@code null}. 59 */ 60 public LocalArtifactRegistration( Artifact artifact, RemoteRepository repository, Collection<String> contexts ) 61 { 62 setArtifact( artifact ); 63 setRepository( repository ); 64 setContexts( contexts ); 65 } 66 67 /** 68 * Gets the artifact to register. 69 * 70 * @return The artifact or {@code null} if not set. 71 */ 72 public Artifact getArtifact() 73 { 74 return artifact; 75 } 76 77 /** 78 * Sets the artifact to register. 79 * 80 * @param artifact The artifact, may be {@code null}. 81 * @return This request for chaining, never {@code null}. 82 */ 83 public LocalArtifactRegistration setArtifact( Artifact artifact ) 84 { 85 this.artifact = artifact; 86 return this; 87 } 88 89 /** 90 * Gets the remote repository from which the artifact was resolved. 91 * 92 * @return The remote repository or {@code null} if the artifact was locally installed. 93 */ 94 public RemoteRepository getRepository() 95 { 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 { 107 this.repository = repository; 108 return this; 109 } 110 111 /** 112 * Gets the resolution contexts in which the artifact is available. 113 * 114 * @return The resolution contexts in which the artifact is available, never {@code null}. 115 */ 116 public Collection<String> getContexts() 117 { 118 return contexts; 119 } 120 121 /** 122 * Sets the resolution contexts in which the artifact is available. 123 * 124 * @param contexts The resolution contexts, may be {@code null}. 125 * @return This request for chaining, never {@code null}. 126 */ 127 public LocalArtifactRegistration setContexts( Collection<String> contexts ) 128 { 129 if ( contexts != null ) 130 { 131 this.contexts = contexts; 132 } 133 else 134 { 135 this.contexts = Collections.emptyList(); 136 } 137 return this; 138 } 139 140 }