All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.maven.graph.effective.rel.DependencyRelationship Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 * Copyright 2012 John Casey
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package org.apache.maven.graph.effective.rel;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.maven.graph.common.DependencyScope;
import org.apache.maven.graph.common.RelationshipType;
import org.apache.maven.graph.common.ref.ArtifactRef;
import org.apache.maven.graph.common.ref.ProjectRef;
import org.apache.maven.graph.common.ref.ProjectVersionRef;

public final class DependencyRelationship
    extends AbstractProjectRelationship
    implements Serializable
{

    private static final long serialVersionUID = 1L;

    private final boolean managed;

    private final DependencyScope scope;

    private final Set excludes;

    public DependencyRelationship( final ProjectVersionRef declaring, final ArtifactRef target,
                                   final DependencyScope scope, final int index, final boolean managed,
                                   final ProjectRef... excludes )
    {
        super( RelationshipType.DEPENDENCY, declaring, target, index );
        this.scope = scope == null ? DependencyScope.compile : scope;
        this.managed = managed;
        this.excludes = new HashSet( Arrays.asList( excludes ) );
    }

    public final boolean isManaged()
    {
        return managed;
    }

    public final DependencyScope getScope()
    {
        return scope;
    }

    @Override
    public synchronized ProjectRelationship cloneFor( final ProjectVersionRef projectRef )
    {
        return new DependencyRelationship( projectRef, getTarget(), scope, getIndex(), managed );
    }

    @Override
    public int hashCode()
    {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ( managed ? 1231 : 1237 );
        return result;
    }

    @Override
    public boolean equals( final Object obj )
    {
        if ( this == obj )
        {
            return true;
        }
        if ( !super.equals( obj ) )
        {
            return false;
        }
        if ( getClass() != obj.getClass() )
        {
            return false;
        }
        final DependencyRelationship other = (DependencyRelationship) obj;
        if ( managed != other.managed )
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return String.format( "DependencyRelationship [%s => %s (managed=%s, scope=%s, index=%s)]", getDeclaring(),
                              getTarget(), managed, scope, getIndex() );
    }

    @Override
    public ArtifactRef getTargetArtifact()
    {
        return getTarget();
    }

    public Set getExcludes()
    {
        return excludes;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy