X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.repo%2Fsrc%2Forg%2Feclipse%2Faether%2Fcollection%2FUnsolvableVersionConflictException.java;fp=org.argeo.slc.repo%2Fsrc%2Forg%2Feclipse%2Faether%2Fcollection%2FUnsolvableVersionConflictException.java;h=8db55902bb946291b5096d398a6b7393f459c551;hb=825d60c5348dbe3f5be25b0bccf7bdebfe694219;hp=0000000000000000000000000000000000000000;hpb=5e991fff5cba01858dcc5747a27e637325bc5c8e;p=gpl%2Fargeo-jcr.git diff --git a/org.argeo.slc.repo/src/org/eclipse/aether/collection/UnsolvableVersionConflictException.java b/org.argeo.slc.repo/src/org/eclipse/aether/collection/UnsolvableVersionConflictException.java new file mode 100644 index 0000000..8db5590 --- /dev/null +++ b/org.argeo.slc.repo/src/org/eclipse/aether/collection/UnsolvableVersionConflictException.java @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2010, 2014 Sonatype, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Sonatype, Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.aether.collection; + +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; + +import org.eclipse.aether.RepositoryException; +import org.eclipse.aether.artifact.Artifact; +import org.eclipse.aether.graph.DependencyNode; +import org.eclipse.aether.version.VersionConstraint; + +/** + * Thrown in case of an unsolvable conflict between different version constraints for a dependency. + */ +public class UnsolvableVersionConflictException + extends RepositoryException +{ + + private final transient Collection versions; + + private final transient Collection> paths; + + /** + * Creates a new exception with the specified paths to conflicting nodes in the dependency graph. + * + * @param paths The paths to the dependency nodes that participate in the version conflict, may be {@code null}. + */ + public UnsolvableVersionConflictException( Collection> paths ) + { + super( "Could not resolve version conflict among " + toPaths( paths ) ); + if ( paths == null ) + { + this.paths = Collections.emptyList(); + this.versions = Collections.emptyList(); + } + else + { + this.paths = paths; + this.versions = new LinkedHashSet(); + for ( List path : paths ) + { + VersionConstraint constraint = path.get( path.size() - 1 ).getVersionConstraint(); + if ( constraint != null && constraint.getRange() != null ) + { + versions.add( constraint.toString() ); + } + } + } + } + + private static String toPaths( Collection> paths ) + { + String result = ""; + + if ( paths != null ) + { + Collection strings = new LinkedHashSet(); + + for ( List path : paths ) + { + strings.add( toPath( path ) ); + } + + result = strings.toString(); + } + + return result; + } + + private static String toPath( List path ) + { + StringBuilder buffer = new StringBuilder( 256 ); + + for ( Iterator it = path.iterator(); it.hasNext(); ) + { + DependencyNode node = it.next(); + if ( node.getDependency() == null ) + { + continue; + } + + Artifact artifact = node.getDependency().getArtifact(); + buffer.append( artifact.getGroupId() ); + buffer.append( ':' ).append( artifact.getArtifactId() ); + buffer.append( ':' ).append( artifact.getExtension() ); + if ( artifact.getClassifier().length() > 0 ) + { + buffer.append( ':' ).append( artifact.getClassifier() ); + } + buffer.append( ':' ).append( node.getVersionConstraint() ); + + if ( it.hasNext() ) + { + buffer.append( " -> " ); + } + } + + return buffer.toString(); + } + + /** + * Gets the paths leading to the conflicting dependencies. + * + * @return The (read-only) paths leading to the conflicting dependencies, never {@code null}. + */ + public Collection> getPaths() + { + return paths; + } + + /** + * Gets the conflicting version constraints of the dependency. + * + * @return The (read-only) conflicting version constraints, never {@code null}. + */ + public Collection getVersions() + { + return versions; + } + +}