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