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.util.graph.traverser;
020
021import org.eclipse.aether.artifact.ArtifactProperties;
022import org.eclipse.aether.collection.DependencyCollectionContext;
023import org.eclipse.aether.collection.DependencyTraverser;
024import org.eclipse.aether.graph.Dependency;
025
026import static java.util.Objects.requireNonNull;
027
028/**
029 * A dependency traverser that excludes the dependencies of fat artifacts from the traversal. Fat artifacts are
030 * artifacts that have the property {@link org.eclipse.aether.artifact.ArtifactProperties#INCLUDES_DEPENDENCIES} set to
031 * {@code true}.
032 *
033 * @see org.eclipse.aether.artifact.Artifact#getProperties()
034 */
035public final class FatArtifactTraverser implements DependencyTraverser {
036
037    /**
038     * Creates a new instance of this dependency traverser.
039     */
040    public FatArtifactTraverser() {}
041
042    public boolean traverseDependency(Dependency dependency) {
043        requireNonNull(dependency, "dependency cannot be null");
044        String prop = dependency.getArtifact().getProperty(ArtifactProperties.INCLUDES_DEPENDENCIES, "");
045        return !Boolean.parseBoolean(prop);
046    }
047
048    public DependencyTraverser deriveChildTraverser(DependencyCollectionContext context) {
049        requireNonNull(context, "context cannot be null");
050        return this;
051    }
052
053    @Override
054    public boolean equals(Object obj) {
055        if (this == obj) {
056            return true;
057        } else if (null == obj || !getClass().equals(obj.getClass())) {
058            return false;
059        }
060        return true;
061    }
062
063    @Override
064    public int hashCode() {
065        return getClass().hashCode();
066    }
067}