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.internal.impl.collect;
020
021import java.util.List;
022
023import org.eclipse.aether.RepositorySystemSession;
024import org.eclipse.aether.artifact.Artifact;
025import org.eclipse.aether.collection.DependencyCollectionContext;
026import org.eclipse.aether.graph.Dependency;
027
028/**
029 * Internal helper class for collector implementations.
030 */
031public final class DefaultDependencyCollectionContext implements DependencyCollectionContext {
032
033    private final RepositorySystemSession session;
034
035    private final Artifact artifact;
036
037    private final Dependency dependency;
038
039    private final List<Dependency> managedDependencies;
040
041    public DefaultDependencyCollectionContext(
042            RepositorySystemSession session,
043            Artifact artifact,
044            Dependency dependency,
045            List<Dependency> managedDependencies) {
046        this.session = session;
047        this.artifact = (dependency != null) ? dependency.getArtifact() : artifact;
048        this.dependency = dependency;
049        this.managedDependencies = managedDependencies;
050    }
051
052    @Override
053    public RepositorySystemSession getSession() {
054        return session;
055    }
056
057    @Override
058    public Artifact getArtifact() {
059        return artifact;
060    }
061
062    @Override
063    public Dependency getDependency() {
064        return dependency;
065    }
066
067    @Override
068    public List<Dependency> getManagedDependencies() {
069        return managedDependencies;
070    }
071
072    public DefaultDependencyCollectionContext set(Dependency dependency, List<Dependency> managedDependencies) {
073        return new DefaultDependencyCollectionContext(
074                session, dependency.getArtifact(), dependency, managedDependencies);
075    }
076
077    @Override
078    public String toString() {
079        return String.valueOf(getDependency());
080    }
081}