25
25
import net .sourceforge .argparse4j .internal .HelpScreenException ;
26
26
27
27
import java .io .PrintStream ;
28
- import java .nio .file .Files ;
29
- import java .nio .file .Path ;
30
- import java .nio .file .Paths ;
31
28
32
- import static org .apache .kafka .message .checker .CheckerUtils .getDataFromGit ;
29
+ import static org .apache .kafka .message .checker .CheckerUtils .readFileFromGitRef ;
33
30
34
31
public class MetadataSchemaCheckerTool {
35
32
public static void main (String [] args ) throws Exception {
@@ -54,18 +51,18 @@ public static void run(
54
51
required (true ).
55
52
help ("The path to a schema JSON file." );
56
53
Subparser evolutionVerifierParser = subparsers .addParser ("verify-evolution" ).
57
- help ("Verify that an evolution of a JSON file is valid." );
58
- evolutionVerifierParser .addArgument ("--path1 " , "-1" ).
54
+ help ("Verify that a schema JSON file is a valid evolution of a parent schema ." );
55
+ evolutionVerifierParser .addArgument ("--path " , "-1" ).
59
56
required (true ).
60
- help ("The initial schema JSON path ." );
61
- evolutionVerifierParser .addArgument ("--path2 " , "-2" ).
57
+ help ("The path to a schema JSON file ." );
58
+ evolutionVerifierParser .addArgument ("--parent_path " , "-2" ).
62
59
required (true ).
63
- help ("The final schema JSON path ." );
60
+ help ("The path to the parent schema JSON file ." );
64
61
Subparser evolutionGitVerifierParser = subparsers .addParser ("verify-evolution-git" ).
65
- help (" Verify that an evolution of a JSON file is valid using git." );
66
- evolutionGitVerifierParser .addArgument ("--file " , "-3" ).
62
+ help ("Verify that a schema JSON file is a valid evolution of your local git master branch ." );
63
+ evolutionGitVerifierParser .addArgument ("--path " , "-3" ).
67
64
required (true ).
68
- help ("The edited JSON file" );
65
+ help ("The path to your edited JSON file" );
69
66
evolutionGitVerifierParser .addArgument ("--ref" , "-4" )
70
67
.required (false )
71
68
.setDefault ("refs/heads/trunk" )
@@ -85,31 +82,24 @@ public static void run(
85
82
break ;
86
83
}
87
84
case "verify-evolution" : {
88
- String path1 = namespace .getString ("path1 " );
89
- String path2 = namespace .getString ("path2 " );
85
+ String child = namespace .getString ("path " );
86
+ String parent = namespace .getString ("parent_path " );
90
87
EvolutionVerifier verifier = new EvolutionVerifier (
91
- CheckerUtils .readMessageSpecFromFile (path1 ),
92
- CheckerUtils .readMessageSpecFromFile (path2 ));
88
+ CheckerUtils .readMessageSpecFromFile (parent ),
89
+ CheckerUtils .readMessageSpecFromFile (child ));
93
90
verifier .verify ();
94
- writer .println ("Successfully verified evolution of path1 : " + path1 +
95
- ", and path2 : " + path2 );
91
+ writer .println ("Successfully verified evolution of path : " + child +
92
+ " from parent : " + parent );
96
93
break ;
97
94
}
98
95
case "verify-evolution-git" : {
99
- String filePath = "/metadata/src/main/resources/common/metadata/" + namespace .getString ("file" );
100
- Path rootKafkaDirectory = Paths .get ("" ).toAbsolutePath ();
101
- while (!Files .exists (rootKafkaDirectory .resolve (".git" ))) {
102
- rootKafkaDirectory = rootKafkaDirectory .getParent ();
103
- if (rootKafkaDirectory == null ) {
104
- throw new RuntimeException ("Invalid directory, need to be within a Git repository" );
105
- }
106
- }
107
- String gitContent = getDataFromGit (filePath , rootKafkaDirectory , namespace .getString ("ref" ));
96
+ String path = namespace .getString ("path" );
97
+ String gitContent = readFileFromGitRef (path , namespace .getString ("ref" ));
108
98
EvolutionVerifier verifier = new EvolutionVerifier (
109
- CheckerUtils .readMessageSpecFromFile (rootKafkaDirectory + filePath ),
110
- CheckerUtils .readMessageSpecFromString (gitContent ));
99
+ CheckerUtils .readMessageSpecFromFile (path ),
100
+ CheckerUtils .readMessageSpecFromString (gitContent ));
111
101
verifier .verify ();
112
- writer .println ("Successfully verified evolution of file: " + namespace .getString ("file " ));
102
+ writer .println ("Successfully verified evolution of file: " + namespace .getString ("path " ));
113
103
break ;
114
104
}
115
105
default :
0 commit comments