2828import java .util .List ;
2929import java .util .Map ;
3030
31- import com .fasterxml .jackson .core .JsonParseException ;
32- import com .fasterxml .jackson .databind .JsonMappingException ;
3331import com .fasterxml .jackson .databind .ObjectMapper ;
3432import org .gradle .api .file .FileTree ;
3533import org .gradle .api .file .RegularFileProperty ;
@@ -65,7 +63,7 @@ public FileTree getSource() {
6563 }
6664
6765 @ TaskAction
68- void check () throws JsonParseException , IOException {
66+ void check () throws IOException {
6967 Report report = createReport ();
7068 File reportFile = getReportLocation ().get ().getAsFile ();
7169 Files .write (reportFile .toPath (), report , StandardOpenOption .CREATE , StandardOpenOption .TRUNCATE_EXISTING );
@@ -76,21 +74,22 @@ void check() throws JsonParseException, IOException {
7674 }
7775
7876 @ SuppressWarnings ("unchecked" )
79- private Report createReport () throws IOException , JsonParseException , JsonMappingException {
77+ private Report createReport () throws IOException {
8078 ObjectMapper objectMapper = new ObjectMapper ();
8179 Report report = new Report ();
8280 for (File file : getSource ().getFiles ()) {
8381 Analysis analysis = report .analysis (this .projectDir .toPath ().relativize (file .toPath ()));
8482 Map <String , Object > json = objectMapper .readValue (file , Map .class );
85- check ("groups" , json , analysis );
86- check ("properties" , json , analysis );
87- check ("hints" , json , analysis );
83+ checkSorting ("groups" , json , analysis );
84+ checkSorting ("properties" , json , analysis );
85+ checkSorting ("hints" , json , analysis );
86+ checkPropertyDeprecationSince (json , analysis );
8887 }
8988 return report ;
9089 }
9190
9291 @ SuppressWarnings ("unchecked" )
93- private void check (String key , Map <String , Object > json , Analysis analysis ) {
92+ private void checkSorting (String key , Map <String , Object > json , Analysis analysis ) {
9493 List <Map <String , Object >> groups = (List <Map <String , Object >>) json .getOrDefault (key , Collections .emptyList ());
9594 List <String > names = groups .stream ().map ((group ) -> (String ) group .get ("name" )).toList ();
9695 List <String > sortedNames = sortedCopy (names );
@@ -110,6 +109,18 @@ private List<String> sortedCopy(Collection<String> original) {
110109 return copy ;
111110 }
112111
112+ @ SuppressWarnings ("unchecked" )
113+ private void checkPropertyDeprecationSince (Map <String , Object > json , Analysis analysis ) {
114+ List <Map <String , Object >> properties = (List <Map <String , Object >>) json .get ("properties" );
115+ properties .stream ().filter ((property ) -> property .containsKey ("deprecation" )).forEach ((property ) -> {
116+ Map <String , Object > deprecation = (Map <String , Object >) property .get ("deprecation" );
117+ if (!deprecation .containsKey ("since" )) {
118+ analysis .problems .add ("Property with name '" + property .get ("name" )
119+ + "' contains 'deprecation' without 'since' attribute" );
120+ }
121+ });
122+ }
123+
113124 private static final class Report implements Iterable <String > {
114125
115126 private final List <Analysis > analyses = new ArrayList <>();
0 commit comments