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 Artifact artifact;
036
037    private Dependency dependency;
038
039    private 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    public RepositorySystemSession getSession() {
053        return session;
054    }
055
056    public Artifact getArtifact() {
057        return artifact;
058    }
059
060    public Dependency getDependency() {
061        return dependency;
062    }
063
064    public List<Dependency> getManagedDependencies() {
065        return managedDependencies;
066    }
067
068    public void set(Dependency dependency, List<Dependency> managedDependencies) {
069        artifact = dependency.getArtifact();
070        this.dependency = dependency;
071        this.managedDependencies = managedDependencies;
072    }
073
074    @Override
075    public String toString() {
076        return String.valueOf(getDependency());
077    }
078}