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
9 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org
.eclipse
.aether
.resolution
;
13 import org
.eclipse
.aether
.RepositorySystem
;
14 import org
.eclipse
.aether
.RepositorySystemSession
;
15 import org
.eclipse
.aether
.metadata
.Metadata
;
16 import org
.eclipse
.aether
.transfer
.MetadataNotFoundException
;
19 * The result of a metadata resolution request.
21 * @see RepositorySystem#resolveMetadata(RepositorySystemSession, java.util.Collection)
23 public final class MetadataResult
26 private final MetadataRequest request
;
28 private Exception exception
;
30 private boolean updated
;
32 private Metadata metadata
;
35 * Creates a new result for the specified request.
37 * @param request The resolution request, must not be {@code null}.
39 public MetadataResult( MetadataRequest request
)
41 if ( request
== null )
43 throw new IllegalArgumentException( "metadata request has not been specified" );
45 this.request
= request
;
49 * Gets the resolution request that was made.
51 * @return The resolution request, never {@code null}.
53 public MetadataRequest
getRequest()
59 * Gets the resolved metadata (if any).
61 * @return The resolved metadata or {@code null} if the resolution failed.
63 public Metadata
getMetadata()
69 * Sets the resolved metadata.
71 * @param metadata The resolved metadata, may be {@code null} if the resolution failed.
72 * @return This result for chaining, never {@code null}.
74 public MetadataResult
setMetadata( Metadata metadata
)
76 this.metadata
= metadata
;
81 * Records the specified exception while resolving the metadata.
83 * @param exception The exception to record, may be {@code null}.
84 * @return This result for chaining, never {@code null}.
86 public MetadataResult
setException( Exception exception
)
88 this.exception
= exception
;
93 * Gets the exception that occurred while resolving the metadata.
95 * @return The exception that occurred or {@code null} if none.
97 public Exception
getException()
103 * Sets the updated flag for the metadata.
105 * @param updated {@code true} if the metadata was actually fetched from the remote repository during the
106 * resolution, {@code false} if the metadata was resolved from a locally cached copy.
107 * @return This result for chaining, never {@code null}.
109 public MetadataResult
setUpdated( boolean updated
)
111 this.updated
= updated
;
116 * Indicates whether the metadata was actually fetched from the remote repository or resolved from the local cache.
117 * If metadata has been locally cached during a previous resolution request and this local copy is still up-to-date
118 * according to the remote repository's update policy, no remote access is made.
120 * @return {@code true} if the metadata was actually fetched from the remote repository during the resolution,
121 * {@code false} if the metadata was resolved from a locally cached copy.
123 public boolean isUpdated()
129 * Indicates whether the requested metadata was resolved. Note that the metadata might have been successfully
130 * resolved (from the local cache) despite {@link #getException()} indicating a transfer error while trying to
131 * refetch the metadata from the remote repository.
133 * @return {@code true} if the metadata was resolved, {@code false} otherwise.
134 * @see Metadata#getFile()
136 public boolean isResolved()
138 return getMetadata() != null && getMetadata().getFile() != null;
142 * Indicates whether the requested metadata is not present in the remote repository.
144 * @return {@code true} if the metadata is not present in the remote repository, {@code false} otherwise.
146 public boolean isMissing()
148 return getException() instanceof MetadataNotFoundException
;
152 public String
toString()
154 return getMetadata() + ( isUpdated() ?
" (updated)" : " (cached)" );