11///usr/bin/env jbang "$0" "$@" ; exit $?
22//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
33//JAVA 17+
4- import static java .lang .System .*;
5- import org .buildobjects .process .ProcBuilder ;
4+ import com .fasterxml .jackson .databind .DeserializationFeature ;
65import com .fasterxml .jackson .databind .ObjectMapper ;
6+ import java .io .File ;
7+ import java .nio .file .Files ;
8+ import java .nio .file .Path ;
79import java .util .*;
810import java .util .stream .Collectors ;
11+ import org .buildobjects .process .ProcBuilder ;
912import org .eclipse .jgit .api .Git ;
1013import 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 .*;
1515import static org .junit .jupiter .api .Assertions .*;
1616
1717public 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" ;
2019 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+ );
2927
30- public static void main (String ... args ) throws Exception {
28+ public static void main (String ... args ) throws Exception {
3129 mapper .configure (DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false );
3230 Path mavenPath = Path .of ("./maven_plugin/./mvnw" );
3331 String pluginVersion = getProjectVersion (mavenPath );
3432 new ProcBuilder (mavenPath .toString (), "clean" , "install" , "-DskipTests" , "-q" )
35- .withNoTimeout ()
36- .run ();
33+ .withNoTimeout ()
34+ .run ();
3735 out .println ("your version is: " + getProjectVersion (mavenPath ));
3836 String command = String .format (pluginCommand , pluginVersion );
37+
38+ File smoketestsDir = new File ("smoketests" );
39+ if (!smoketestsDir .exists ()) {
40+ smoketestsDir .mkdirs ();
41+ }
42+
3943 for (CiProject projectUrl : projects ) {
4044 out .println ("Testing project " + projectUrl );
45+ String projectName = projectUrl .projectUrl .substring (projectUrl .projectUrl .lastIndexOf ('/' ) + 1 );
4146 try (Git result = Git .cloneRepository ().setURI (projectUrl .projectUrl )
47+ .setDirectory (new File ("smoketests/" + projectName ))
4248 .call ()) {
4349 result .checkout ().setName (projectUrl .commitHash ).call ();
4450 File workingDir = result .getRepository ().getDirectory ().getParentFile ();
4551 System .out .println ("Cloned " + projectUrl .projectUrl + " to " + workingDir );
46- new ProcBuilder (
47- "." + mavenPath .toString (), command )
52+ new ProcBuilder ("../../maven_plugin/mvnw" , command )
4853 .withWorkingDirectory (workingDir )
4954 .withNoTimeout ()
5055 .run ();
5156 LockFile lockFile = mapper .readValue (new File (workingDir , "lockfile.json" ), LockFile .class );
52- new ProcBuilder ("." + mavenPath , mavenGraph )
57+ new ProcBuilder ("../../maven_plugin/mvnw" , mavenGraph )
5358 .withWorkingDirectory (workingDir )
5459 .withNoTimeout ()
5560 .run ();
5661
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 <>()));
8379 }
8480 }
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+ }
8589 }
90+ }
8691 }
8792
8893 private static DependencyLockFile findDependency (List <DependencyLockFile > dependencies ,
@@ -99,13 +104,14 @@ private static String getProjectVersion(Path path) {
99104 return new ProcBuilder (path .toAbsolutePath ().toString (), new String []{ "help:evaluate" , "-Dexpression=project.version" , "-q" ,
100105 "-DforceStdout" }).withNoTimeout ().withWorkingDirectory (Path .of ("./maven_plugin" ).toFile ()).run ().getOutputString ().trim ();
101106 }
102-
107+
103108 record Dependency (String groupId , String artifactId , String classifier , String version ,
104109 String scope , int depth , String submodule ) {
105110 };
106111
107112 public record JsonFile (String graphName , List <Node > artifacts , List <Edge > dependencies ) {
108113 };
114+
109115 record Node (String id , int numericId , String groupId , String artifactId , String version ,
110116 boolean optional , List <String > classifiers , List <String > scopes ,
111117 List <String > types ) {
@@ -114,14 +120,15 @@ record Node(String id, int numericId, String groupId, String artifactId, String
114120 record Edge (String from , String to , int numericFrom , int numericTo , String resolution ) {
115121 };
116122
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 ) {
118125 };
119126
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 ) {
122130 };
123131
124132 private record CiProject (String projectUrl , String commitHash ) {
125133 };
126-
127134}
0 commit comments