ConflictMarker implements DependencyGraphTransformer { public DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context ) throws RepositoryException { Map<DependencyNode, Object> nodes = new IdentityHashMap<DependencyNode, Object>( 1024 ); Map<Object, ConflictGroup> groups = new HashMap<Object, ConflictGroup>( 1024 ); analyze( node, nodes, groups ); Map<DependencyNode, Object> conflictIds = mark( nodes.keySet(), groups ); context.put( TransformationContextKeys.CONFLICT_IDS, conflictIds ); return node; }  DependencyNode transformGraph( DependencyNode node, DependencyGraphTransformationContext context );  }
@Test public void testSimple() throws Exception { NodeBuilder builder = new NodeBuilder(); DependencyNode root = builder.build(); root.getChildren().add( builder.artifactId( "a" ).build() ); root.getChildren().add( builder.artifactId( "b" ).build() ); DependencyGraphTransformationContext context = newContext(); assertSame( root, new ConflictMarker().transformGraph( root, context ) ); Map<?, ?> ids = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); assertNotNull( ids ); assertNull( ids.get( root ) ); assertNotNull( ids.get( root.getChildren().get( 0 ) ) ); assertNotNull( ids.get( root.getChildren().get( 1 ) ) ); assertNotSame( ids.get( root.getChildren().get( 0 ) ), ids.get( root.getChildren().get( 1 ) ) ); assertFalse( ids.get( root.getChildren().get( 0 ) ).equals( ids.get( root.getChildren().get( 1 ) ) ) ); }
@Test public void testRelocation1() throws Exception { NodeBuilder builder = new NodeBuilder(); DependencyNode root = builder.build(); root.getChildren().add( builder.artifactId( "a" ).build() ); root.getChildren().add( builder.artifactId( "a" ).reloc( "reloc" ).build() ); DependencyGraphTransformationContext context = newContext(); assertSame( root, new ConflictMarker().transformGraph( root, context ) ); Map<?, ?> ids = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); assertNotNull( ids ); assertNull( ids.get( root ) ); assertNotNull( ids.get( root.getChildren().get( 0 ) ) ); assertNotNull( ids.get( root.getChildren().get( 1 ) ) ); assertSame( ids.get( root.getChildren().get( 0 ) ), ids.get( root.getChildren().get( 1 ) ) ); }
@Test public void testRelocation2() throws Exception { NodeBuilder builder = new NodeBuilder(); DependencyNode root = builder.build(); root.getChildren().add( builder.artifactId( "a" ).reloc( "reloc" ).build() ); root.getChildren().add( builder.artifactId( "a" ).build() ); DependencyGraphTransformationContext context = newContext(); assertSame( root, new ConflictMarker().transformGraph( root, context ) ); Map<?, ?> ids = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); assertNotNull( ids ); assertNull( ids.get( root ) ); assertNotNull( ids.get( root.getChildren().get( 0 ) ) ); assertNotNull( ids.get( root.getChildren().get( 1 ) ) ); assertSame( ids.get( root.getChildren().get( 0 ) ), ids.get( root.getChildren().get( 1 ) ) ); }
@Test public void testRelocation3() throws Exception { NodeBuilder builder = new NodeBuilder(); DependencyNode root = builder.build(); root.getChildren().add( builder.artifactId( "a" ).build() ); root.getChildren().add( builder.artifactId( "b" ).build() ); root.getChildren().add( builder.artifactId( "c" ).reloc( "a" ).reloc( "b" ).build() ); DependencyGraphTransformationContext context = newContext(); assertSame( root, new ConflictMarker().transformGraph( root, context ) ); Map<?, ?> ids = (Map<?, ?>) context.get( TransformationContextKeys.CONFLICT_IDS ); assertNotNull( ids ); assertNull( ids.get( root ) ); assertNotNull( ids.get( root.getChildren().get( 0 ) ) ); assertNotNull( ids.get( root.getChildren().get( 1 ) ) ); assertNotNull( ids.get( root.getChildren().get( 2 ) ) ); assertSame( ids.get( root.getChildren().get( 0 ) ), ids.get( root.getChildren().get( 1 ) ) ); assertSame( ids.get( root.getChildren().get( 1 ) ), ids.get( root.getChildren().get( 2 ) ) ); }