1
1
///usr/bin/env jbang "$0" "$@" ; exit $?
2
2
//DEPS org.buildobjects:jproc:2.8.2 com.fasterxml.jackson.core:jackson-databind:2.14.2 org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r org.junit.jupiter:junit-jupiter-api:5.7.2 org.junit.jupiter:junit-jupiter-engine:5.7.2
3
3
//JAVA 17+
4
- import static java .lang .System .*;
5
- import org .buildobjects .process .ProcBuilder ;
4
+ import com .fasterxml .jackson .databind .DeserializationFeature ;
6
5
import com .fasterxml .jackson .databind .ObjectMapper ;
6
+ import java .io .File ;
7
+ import java .nio .file .Files ;
8
+ import java .nio .file .Path ;
7
9
import java .util .*;
8
10
import java .util .stream .Collectors ;
11
+ import org .buildobjects .process .ProcBuilder ;
9
12
import org .eclipse .jgit .api .Git ;
10
13
import org .eclipse .jgit .api .errors .GitAPIException ;
11
- import java .io .File ;
12
- import java .nio .file .Files ;
13
- import java .nio .file .Path ;
14
- import com .fasterxml .jackson .databind .DeserializationFeature ;
14
+ import static java .lang .System .*;
15
15
import static org .junit .jupiter .api .Assertions .*;
16
16
17
17
public class SmokeTest {
18
- private static String pluginCommand =
19
- "io.github.chains-project:maven-lockfile:%s:generate" ;
18
+ private static String pluginCommand = "io.github.chains-project:maven-lockfile:%s:generate" ;
20
19
private static String [] mavenGraph = new String [] { "com.github.ferstl:depgraph-maven-plugin:4.0.2:graph" , "-DgraphFormat=json" };
21
- private static ObjectMapper mapper = new ObjectMapper ();
22
- private static List <CiProject > projects =
23
- List .of (new CiProject ("https://github.com/INRIA/spoon" ,"8e1d4272f58189587279033e3b3ca80c5f78f8ff" ),
24
- new CiProject ("https://github.com/stanfordnlp/CoreNLP" ,"139893242878ecacde79b2ba1d0102b855526610" ),
25
- new CiProject ("https://github.com/javaparser/javaparser" ,"7e761814c661d67293fb9941287f544ce7fdd14c" ),
26
- new CiProject ("https://github.com/checkstyle/checkstyle" ,"dffecfe45722704f54b1727f969445e2aacd4cb3" )
27
- );
28
-
20
+ private static ObjectMapper mapper = new ObjectMapper ();
21
+ private static List <CiProject > projects = List .of (
22
+ new CiProject ("https://github.com/INRIA/spoon" ,"8e1d4272f58189587279033e3b3ca80c5f78f8ff" ),
23
+ new CiProject ("https://github.com/stanfordnlp/CoreNLP" ,"139893242878ecacde79b2ba1d0102b855526610" ),
24
+ new CiProject ("https://github.com/javaparser/javaparser" ,"7e761814c661d67293fb9941287f544ce7fdd14c" ),
25
+ new CiProject ("https://github.com/checkstyle/checkstyle" ,"dffecfe45722704f54b1727f969445e2aacd4cb3" )
26
+ );
29
27
30
- public static void main (String ... args ) throws Exception {
28
+ public static void main (String ... args ) throws Exception {
31
29
mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
32
30
Path mavenPath = Path .of ("./maven_plugin/./mvnw" );
33
31
String pluginVersion = getProjectVersion (mavenPath );
34
32
new ProcBuilder (mavenPath .toString (), "clean" , "install" , "-DskipTests" , "-q" )
35
- .withNoTimeout ()
36
- .run ();
33
+ .withNoTimeout ()
34
+ .run ();
37
35
out .println ("your version is: " + getProjectVersion (mavenPath ));
38
36
String command = String .format (pluginCommand , pluginVersion );
37
+
38
+ File smoketestsDir = new File ("smoketests" );
39
+ if (!smoketestsDir .exists ()) {
40
+ smoketestsDir .mkdirs ();
41
+ }
42
+
39
43
for (CiProject projectUrl : projects ) {
40
44
out .println ("Testing project " + projectUrl );
45
+ String projectName = projectUrl .projectUrl .substring (projectUrl .projectUrl .lastIndexOf ('/' ) + 1 );
41
46
try (Git result = Git .cloneRepository ().setURI (projectUrl .projectUrl )
47
+ .setDirectory (new File ("smoketests/" + projectName ))
42
48
.call ()) {
43
49
result .checkout ().setName (projectUrl .commitHash ).call ();
44
50
File workingDir = result .getRepository ().getDirectory ().getParentFile ();
45
51
System .out .println ("Cloned " + projectUrl .projectUrl + " to " + workingDir );
46
- new ProcBuilder (
47
- "." + mavenPath .toString (), command )
52
+ new ProcBuilder ("../../maven_plugin/mvnw" , command )
48
53
.withWorkingDirectory (workingDir )
49
54
.withNoTimeout ()
50
55
.run ();
51
56
LockFile lockFile = mapper .readValue (new File (workingDir , "lockfile.json" ), LockFile .class );
52
- new ProcBuilder ("." + mavenPath , mavenGraph )
57
+ new ProcBuilder ("../../maven_plugin/mvnw" , mavenGraph )
53
58
.withWorkingDirectory (workingDir )
54
59
.withNoTimeout ()
55
60
.run ();
56
61
57
- JsonFile jsonFile = mapper .readValue (new File (workingDir , "/target/dependency-graph.json" ), JsonFile .class );
58
- List <Node > dependencies = jsonFile .artifacts ;
59
- // the first is the root
60
- dependencies .remove (0 );
61
- List <DependencyLockFile > errors = new ArrayList <>();
62
- Queue <DependencyLockFile > workingQueue = new ArrayDeque <>(lockFile .dependencies ());
63
- List <DependencyLockFile > completeList = new ArrayList <>();
64
- while (!workingQueue .isEmpty ()) {
65
- DependencyLockFile current = workingQueue .poll ();
66
- completeList .add (current );
67
- workingQueue .addAll (current .children ());
68
- }
69
- for (Node dependency : dependencies ) {
70
- DependencyLockFile lockFileDependency = findDependency (
71
- completeList , dependency );
72
- if (lockFileDependency == null ) {
73
- errors .add (new DependencyLockFile (dependency .groupId (), dependency .artifactId (), dependency .version (), "" , "" , "" , "" , new ArrayList <>()));
74
- }
75
- }
76
- if (!errors .isEmpty ()) {
77
- fail ("The following dependencies are not in the lockfile: " + errors .stream ()
78
- .map (d -> d .groupId () + ":" + d .artifactId () + ":" + d .version )
79
- .collect (Collectors .joining ("\n " )));
80
- }
81
- if (errors .isEmpty ()) {
82
- out .println ("All dependencies are in the lockfile" );
62
+ JsonFile jsonFile = mapper .readValue (new File (workingDir , "/target/dependency-graph.json" ), JsonFile .class );
63
+ List <Node > dependencies = jsonFile .artifacts ;
64
+ // the first is the root
65
+ dependencies .remove (0 );
66
+ List <DependencyLockFile > errors = new ArrayList <>();
67
+ Queue <DependencyLockFile > workingQueue = new ArrayDeque <>(lockFile .dependencies ());
68
+ List <DependencyLockFile > completeList = new ArrayList <>();
69
+ while (!workingQueue .isEmpty ()) {
70
+ DependencyLockFile current = workingQueue .poll ();
71
+ completeList .add (current );
72
+ workingQueue .addAll (current .children ());
73
+ }
74
+ for (Node dependency : dependencies ) {
75
+ DependencyLockFile lockFileDependency = findDependency (
76
+ completeList , dependency );
77
+ if (lockFileDependency == null ) {
78
+ errors .add (new DependencyLockFile (dependency .groupId (), dependency .artifactId (), dependency .version (), "" , "" , "" , "" , new ArrayList <>()));
83
79
}
84
80
}
81
+ if (!errors .isEmpty ()) {
82
+ fail ("The following dependencies are not in the lockfile: " + errors .stream ()
83
+ .map (d -> d .groupId () + ":" + d .artifactId () + ":" + d .version )
84
+ .collect (Collectors .joining ("\n " )));
85
+ }
86
+ if (errors .isEmpty ()) {
87
+ out .println ("All dependencies are in the lockfile" );
88
+ }
85
89
}
90
+ }
86
91
}
87
92
88
93
private static DependencyLockFile findDependency (List <DependencyLockFile > dependencies ,
@@ -99,13 +104,14 @@ private static String getProjectVersion(Path path) {
99
104
return new ProcBuilder (path .toAbsolutePath ().toString (), new String []{ "help:evaluate" , "-Dexpression=project.version" , "-q" ,
100
105
"-DforceStdout" }).withNoTimeout ().withWorkingDirectory (Path .of ("./maven_plugin" ).toFile ()).run ().getOutputString ().trim ();
101
106
}
102
-
107
+
103
108
record Dependency (String groupId , String artifactId , String classifier , String version ,
104
109
String scope , int depth , String submodule ) {
105
110
};
106
111
107
112
public record JsonFile (String graphName , List <Node > artifacts , List <Edge > dependencies ) {
108
113
};
114
+
109
115
record Node (String id , int numericId , String groupId , String artifactId , String version ,
110
116
boolean optional , List <String > classifiers , List <String > scopes ,
111
117
List <String > types ) {
@@ -114,14 +120,15 @@ record Node(String id, int numericId, String groupId, String artifactId, String
114
120
record Edge (String from , String to , int numericFrom , int numericTo , String resolution ) {
115
121
};
116
122
117
- public record LockFile (String artifactID , String groupID , String version , String lockFileVersion , List <DependencyLockFile > dependencies ) {
123
+ public record LockFile (String artifactID , String groupID , String version , String lockFileVersion ,
124
+ List <DependencyLockFile > dependencies ) {
118
125
};
119
126
120
- public record DependencyLockFile (String groupId , String artifactId , String version , String checksumAlgorithm , String checksum ,
121
- String id ,String parent , List <DependencyLockFile > children ) {
127
+ public record DependencyLockFile (String groupId , String artifactId , String version ,
128
+ String checksumAlgorithm , String checksum , String id ,String parent ,
129
+ List <DependencyLockFile > children ) {
122
130
};
123
131
124
132
private record CiProject (String projectUrl , String commitHash ) {
125
133
};
126
-
127
134
}
0 commit comments