@Test public void testViolationOfHardConstraintFallsBackToNearestSeenNotFirstSeen() throws Exception { DependencyNode x1 = builder.artifactId( "x" ).version( "1" ).build(); DependencyNode x2 = builder.artifactId( "x" ).version( "2" ).build(); DependencyNode x3 = builder.artifactId( "x" ).version( "3" ).build(); DependencyNode x2r = builder.artifactId( "x" ).version( "2" ).range( "[2,)" ).build(); DependencyNode b = builder.artifactId( "b" ).version( "1" ).build(); b.getChildren().add( x3 ); DependencyNode a = builder.artifactId( "a" ).build(); a.getChildren().add( b ); DependencyNode c = builder.artifactId( "c" ).build(); c.getChildren().add( x2 ); DependencyNode e = builder.artifactId( "e" ).build(); e.getChildren().add( x2r ); DependencyNode d = builder.artifactId( "d" ).build(); d.getChildren().add( e ); DependencyNode root = builder.artifactId( null ).build(); root.getChildren().add( x1 ); root.getChildren().add( a ); root.getChildren().add( c ); root.getChildren().add( d ); Map<DependencyNode, Object> conflictIds = new IdentityHashMap<DependencyNode, Object>(); conflictIds.put( x1, "x" ); conflictIds.put( x2, "x" ); conflictIds.put( x3, "x" ); conflictIds.put( x2r, "x" ); conflictIds.put( a, "a" ); conflictIds.put( b, "b" ); conflictIds.put( c, "c" ); conflictIds.put( d, "d" ); conflictIds.put( e, "e" ); context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds ); NearestVersionConflictResolver transformer = new NearestVersionConflictResolver(); root = transformer.transformGraph( root, context ); List<DependencyNode> trail = find( root, "x" ); assertEquals( 3, trail.size() ); assertSame( x2, trail.get( 0 ) ); }
public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); if ( sortedConflictIds == null ) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context ); sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); } Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); if ( conflictIds == null ) { throw new RepositoryException( "conflict groups have not been identified" ); } Map<DependencyNode, Integer> depths = new IdentityHashMap<DependencyNode, Integer>( conflictIds.size() ); for ( Object key : sortedConflictIds ) { ConflictGroup group = new ConflictGroup( key ); depths.clear(); selectVersion( node, null, 0, depths, group, conflictIds, node ); pruneNonSelectedVersions( group, conflictIds ); } return node; }
NearestVersionConflictResolver implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); if ( sortedConflictIds == null ) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context ); sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); } Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); if ( conflictIds == null ) { throw new RepositoryException( "conflict groups have not been identified" ); } Map<DependencyNode, Integer> depths = new IdentityHashMap<DependencyNode, Integer>( conflictIds.size() ); for ( Object key : sortedConflictIds ) { ConflictGroup group = new ConflictGroup( key ); depths.clear(); selectVersion( node, null, 0, depths, group, conflictIds, node ); pruneNonSelectedVersions( group, conflictIds ); } return node; } }
NearestVersionConflictResolver implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); if ( sortedConflictIds == null ) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context ); sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); } Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); if ( conflictIds == null ) { throw new RepositoryException( "conflict groups have not been identified" ); } Map<DependencyNode, Integer> depths = new IdentityHashMap<DependencyNode, Integer>( conflictIds.size() ); for ( Object key : sortedConflictIds ) { ConflictGroup group = new ConflictGroup( key ); depths.clear(); selectVersion( node, null, 0, depths, group, conflictIds, node ); pruneNonSelectedVersions( group, conflictIds ); } return node; }  }
NearestVersionConflictResolver implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); if ( sortedConflictIds == null ) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context ); sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); } Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); if ( conflictIds == null ) { throw new RepositoryException( "conflict groups have not been identified" ); } Map<DependencyNode, Integer> depths = new IdentityHashMap<DependencyNode, Integer>( conflictIds.size() ); for ( Object key : sortedConflictIds ) { ConflictGroup group = new ConflictGroup( key ); depths.clear(); selectVersion( node, null, 0, depths, group, conflictIds, node ); pruneNonSelectedVersions( group, conflictIds ); } return node; }  DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ); }
NearestVersionConflictResolver implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { List<?> sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); if ( sortedConflictIds == null ) { ConflictIdSorter sorter = new ConflictIdSorter(); sorter.transformGraph( node, context ); sortedConflictIds = (List<?>) context.get( TransformationContextKeys.SORTED_CONFLICT_IDS ); } Map<?, ?> conflictIds = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); if ( conflictIds == null ) { throw new RepositoryException( "conflict groups have not been identified" ); } Map<DependencyNode, Integer> depths = new IdentityHashMap<DependencyNode, Integer>( conflictIds.size() ); for ( Object key : sortedConflictIds ) { ConflictGroup group = new ConflictGroup( key ); depths.clear(); selectVersion( node, null, 0, depths, group, conflictIds, node ); pruneNonSelectedVersions( group, conflictIds ); } return node; }  DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context );  }