@@ -444,6 +444,52 @@ public void testPropertySanitizing() throws Exception
444444
445445 File file = new File ( getBasedir (), "target" + File .separatorChar + "test.props" );
446446 builder .getProperties ().store ( new FileOutputStream ( file ), "TEST" );
447- }
447+ }
448+
449+ public void testToArtifactCopiesScopeAndOptionalFromDependency ()
450+ {
451+ org .eclipse .aether .artifact .Artifact aetherArtifact =
452+ new org .eclipse .aether .artifact .DefaultArtifact ( "g" , "a" , "tests" , "jar" , "1.0" );
453+ org .eclipse .aether .graph .DependencyNode node = new org .eclipse .aether .graph .DefaultDependencyNode (
454+ new org .eclipse .aether .graph .Dependency ( aetherArtifact , Artifact .SCOPE_RUNTIME , true ) );
455+
456+ Artifact artifact = BundlePlugin .toArtifact ( node , new MavenProject () );
457+
458+ assertEquals ( "g" , artifact .getGroupId () );
459+ assertEquals ( "a" , artifact .getArtifactId () );
460+ assertEquals ( "1.0" , artifact .getVersion () );
461+ assertEquals ( "jar" , artifact .getType () );
462+ assertEquals ( "tests" , artifact .getClassifier () );
463+ assertEquals ( Artifact .SCOPE_RUNTIME , artifact .getScope () );
464+ assertTrue ( artifact .isOptional () );
465+ }
466+
467+
468+ public void testToArtifactNotOptional ()
469+ {
470+ org .eclipse .aether .graph .DependencyNode node = new org .eclipse .aether .graph .DefaultDependencyNode (
471+ new org .eclipse .aether .graph .Dependency (
472+ new org .eclipse .aether .artifact .DefaultArtifact ( "g" , "a" , "jar" , "1.0" ), Artifact .SCOPE_SYSTEM ) );
473+
474+ Artifact artifact = BundlePlugin .toArtifact ( node , new MavenProject () );
475+
476+ assertEquals ( Artifact .SCOPE_SYSTEM , artifact .getScope () );
477+ assertFalse ( artifact .isOptional () );
478+ }
479+
480+
481+ public void testToArtifactOfRootIsProjectArtifact ()
482+ {
483+ MavenProject project = new MavenProject ();
484+ Artifact projectArtifact = new org .apache .maven .artifact .DefaultArtifact ( "g" , "root" , "2.0" , null , "jar" , null ,
485+ new org .apache .maven .artifact .handler .DefaultArtifactHandler ( "jar" ) );
486+ project .setArtifact ( projectArtifact );
487+
488+ // the root of a collected graph has no dependency
489+ Artifact artifact =
490+ BundlePlugin .toArtifact ( new org .eclipse .aether .graph .DefaultDependencyNode ( ( org .eclipse .aether .graph .Dependency ) null ), project );
491+
492+ assertSame ( projectArtifact , artifact );
493+ }
448494
449495}
0 commit comments