13
13
package org .eclipse .tycho .test ;
14
14
15
15
import static org .junit .Assert .assertEquals ;
16
+ import static org .junit .Assert .assertTrue ;
16
17
import static org .junit .Assert .fail ;
17
18
18
19
import java .io .File ;
19
20
import java .io .FileInputStream ;
20
21
import java .util .Collection ;
21
22
import java .util .List ;
22
23
import java .util .stream .Collectors ;
24
+ import java .util .stream .Stream ;
23
25
24
26
import org .apache .maven .it .Verifier ;
27
+ import org .eclipse .aether .util .version .GenericVersionScheme ;
28
+ import org .eclipse .aether .version .Version ;
29
+ import org .eclipse .aether .version .VersionScheme ;
25
30
import org .eclipse .tycho .targetplatform .TargetDefinition .InstallableUnitLocation ;
26
31
import org .eclipse .tycho .targetplatform .TargetDefinition .Location ;
27
32
import org .eclipse .tycho .targetplatform .TargetDefinition .MavenDependency ;
@@ -39,7 +44,6 @@ public void testUpdateTarget() throws Exception {
39
44
Verifier verifier = getVerifier ("tycho-version-bump-plugin/update-target" , false , true );
40
45
String sourceTargetFile = "update-target.target" ;
41
46
verifier .setSystemProperty ("target" , sourceTargetFile );
42
- verifier .setSystemProperty ("tycho.localArtifacts" , "ignore" );
43
47
verifier .executeGoal ("org.eclipse.tycho.extras:tycho-version-bump-plugin:" + TychoVersion .getTychoVersion ()
44
48
+ ":update-target" );
45
49
verifier .verifyErrorFreeLog ();
@@ -61,13 +65,57 @@ public void testUpdateTarget() throws Exception {
61
65
MavenGAVLocation maven = locations .stream ().filter (MavenGAVLocation .class ::isInstance )
62
66
.map (MavenGAVLocation .class ::cast ).findFirst ()
63
67
.orElseThrow (() -> new AssertionError ("Maven Location not found!" ));
64
- Collection <MavenDependency > roots = maven .getRoots ();
65
- assertEquals (1 , roots .size ());
66
- MavenDependency dependency = roots .iterator ().next ();
68
+ MavenDependency dependency = dependencies (maven , "javax.annotation" , "javax.annotation-api" ).findFirst ()
69
+ .orElseThrow (() -> new AssertionError ("javax.annotation dependency not found" ));
67
70
assertEquals ("Maven version was not updated correctly in " + targetFile , "1.3.2" , dependency .getVersion ());
71
+ List <MavenDependency > list = dependencies (maven , "jakarta.annotation" , "jakarta.annotation-api" ).toList ();
72
+ assertEquals (2 , list .size ());
73
+ VersionScheme scheme = new GenericVersionScheme ();
74
+ // we can not know the exact latest major version, but we know it must be larger
75
+ // than 3.0
76
+ Version version3 = scheme .parseVersion ("3" );
77
+ assertTrue ("Maven version was not updated correctly in " + targetFile + " for jakarta.annotation-api 1.3.5" ,
78
+ scheme .parseVersion (list .get (0 ).getVersion ()).compareTo (version3 ) >= 0 );
79
+ assertTrue (
80
+ "No Update for Maven version was expected in " + targetFile + " for jakarta.annotation-api 2.0.0" ,
81
+ scheme .parseVersion (list .get (1 ).getVersion ()).compareTo (version3 ) >= 0 );
68
82
}
69
83
}
70
84
85
+ @ Test
86
+ public void testUpdateTargetWithoutMajor () throws Exception {
87
+ Verifier verifier = getVerifier ("tycho-version-bump-plugin/update-target" , false , true );
88
+ String sourceTargetFile = "update-target.target" ;
89
+ verifier .setSystemProperty ("target" , sourceTargetFile );
90
+ verifier .setSystemProperty ("major" , "false" );
91
+ verifier .executeGoal ("org.eclipse.tycho.extras:tycho-version-bump-plugin:" + TychoVersion .getTychoVersion ()
92
+ + ":update-target" );
93
+ verifier .verifyErrorFreeLog ();
94
+ File targetFile = new File (verifier .getBasedir (), sourceTargetFile );
95
+ try (FileInputStream input = new FileInputStream (targetFile )) {
96
+ Document target = TargetDefinitionFile .parseDocument (input );
97
+ TargetDefinitionFile parsedTarget = TargetDefinitionFile .parse (target , targetFile .getAbsolutePath ());
98
+ List <? extends Location > locations = parsedTarget .getLocations ();
99
+ MavenGAVLocation maven = locations .stream ().filter (MavenGAVLocation .class ::isInstance )
100
+ .map (MavenGAVLocation .class ::cast ).findFirst ()
101
+ .orElseThrow (() -> new AssertionError ("Maven Location not found!" ));
102
+ List <MavenDependency > list = dependencies (maven , "jakarta.annotation" , "jakarta.annotation-api" ).toList ();
103
+ assertEquals (2 , list .size ());
104
+ assertEquals (
105
+ "No Update for Maven version was expected in " + targetFile + " for jakarta.annotation-api 1.3.5" ,
106
+ "1.3.5" , list .get (0 ).getVersion ());
107
+ assertEquals (
108
+ "Maven version was not updated correctly in " + targetFile + " for jakarta.annotation-api 2.0.0" ,
109
+ "2.1.1" , list .get (1 ).getVersion ());
110
+
111
+ }
112
+ }
113
+
114
+ private Stream <MavenDependency > dependencies (MavenGAVLocation maven , String g , String a ) {
115
+ Collection <MavenDependency > roots = maven .getRoots ();
116
+ return roots .stream ().filter (md -> md .getGroupId ().equals (g )).filter (md -> md .getArtifactId ().equals (a ));
117
+ }
118
+
71
119
private void assertIUVersion (String id , String version , List <? extends Unit > units , File targetFile ) {
72
120
for (Unit unit : units ) {
73
121
if (unit .getId ().equals (id ) && unit .getVersion ().equals (version )) {
0 commit comments