001package org.eclipse.aether.resolution; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import java.util.Collections; 023import java.util.List; 024 025import org.eclipse.aether.RepositorySystem; 026import org.eclipse.aether.RepositorySystemSession; 027import org.eclipse.aether.graph.DependencyCycle; 028import org.eclipse.aether.graph.DependencyNode; 029 030/** 031 * The result of a dependency resolution request. 032 * 033 * @see RepositorySystem#resolveDependencies(RepositorySystemSession, DependencyRequest) 034 */ 035public final class DependencyResult 036{ 037 038 private final DependencyRequest request; 039 040 private DependencyNode root; 041 042 private List<DependencyCycle> cycles; 043 044 private List<Exception> collectExceptions; 045 046 private List<ArtifactResult> artifactResults; 047 048 /** 049 * Creates a new result for the specified request. 050 * 051 * @param request The resolution request, must not be {@code null}. 052 */ 053 public DependencyResult( DependencyRequest request ) 054 { 055 if ( request == null ) 056 { 057 throw new IllegalArgumentException( "dependency request has not been specified" ); 058 } 059 this.request = request; 060 root = request.getRoot(); 061 cycles = Collections.emptyList(); 062 collectExceptions = Collections.emptyList(); 063 artifactResults = Collections.emptyList(); 064 } 065 066 /** 067 * Gets the resolution request that was made. 068 * 069 * @return The resolution request, never {@code null}. 070 */ 071 public DependencyRequest getRequest() 072 { 073 return request; 074 } 075 076 /** 077 * Gets the root node of the resolved dependency graph. Note that this dependency graph might be 078 * incomplete/unfinished in case of {@link #getCollectExceptions()} indicating errors during its calculation. 079 * 080 * @return The root node of the resolved dependency graph or {@code null} if none. 081 */ 082 public DependencyNode getRoot() 083 { 084 return root; 085 } 086 087 /** 088 * Sets the root node of the resolved dependency graph. 089 * 090 * @param root The root node of the resolved dependency graph, may be {@code null}. 091 * @return This result for chaining, never {@code null}. 092 */ 093 public DependencyResult setRoot( DependencyNode root ) 094 { 095 this.root = root; 096 return this; 097 } 098 099 /** 100 * Gets the dependency cycles that were encountered while building the dependency graph. Note that dependency cycles 101 * will only be reported here if the underlying request was created from a 102 * {@link org.eclipse.aether.collection.CollectRequest CollectRequest}. If the underlying {@link DependencyRequest} 103 * was created from an existing dependency graph, information about cycles will not be available in this result. 104 * 105 * @return The dependency cycles in the (raw) graph, never {@code null}. 106 */ 107 public List<DependencyCycle> getCycles() 108 { 109 return cycles; 110 } 111 112 /** 113 * Records the specified dependency cycles while building the dependency graph. 114 * 115 * @param cycles The dependency cycles to record, may be {@code null}. 116 * @return This result for chaining, never {@code null}. 117 */ 118 public DependencyResult setCycles( List<DependencyCycle> cycles ) 119 { 120 if ( cycles == null ) 121 { 122 this.cycles = Collections.emptyList(); 123 } 124 else 125 { 126 this.cycles = cycles; 127 } 128 return this; 129 } 130 131 /** 132 * Gets the exceptions that occurred while building the dependency graph. 133 * 134 * @return The exceptions that occurred, never {@code null}. 135 */ 136 public List<Exception> getCollectExceptions() 137 { 138 return collectExceptions; 139 } 140 141 /** 142 * Records the specified exceptions while building the dependency graph. 143 * 144 * @param exceptions The exceptions to record, may be {@code null}. 145 * @return This result for chaining, never {@code null}. 146 */ 147 public DependencyResult setCollectExceptions( List<Exception> exceptions ) 148 { 149 if ( exceptions == null ) 150 { 151 this.collectExceptions = Collections.emptyList(); 152 } 153 else 154 { 155 this.collectExceptions = exceptions; 156 } 157 return this; 158 } 159 160 /** 161 * Gets the resolution results for the dependency artifacts that matched {@link DependencyRequest#getFilter()}. 162 * 163 * @return The resolution results for the dependency artifacts, never {@code null}. 164 */ 165 public List<ArtifactResult> getArtifactResults() 166 { 167 return artifactResults; 168 } 169 170 /** 171 * Sets the resolution results for the artifacts that matched {@link DependencyRequest#getFilter()}. 172 * 173 * @param results The resolution results for the artifacts, may be {@code null}. 174 * @return This result for chaining, never {@code null}. 175 */ 176 public DependencyResult setArtifactResults( List<ArtifactResult> results ) 177 { 178 if ( results == null ) 179 { 180 this.artifactResults = Collections.emptyList(); 181 } 182 else 183 { 184 this.artifactResults = results; 185 } 186 return this; 187 } 188 189 @Override 190 public String toString() 191 { 192 return String.valueOf( artifactResults ); 193 } 194 195}