2727import static ch .qos .logback .core .CoreConstants .NA ;
2828
2929
30-
3130/**
3231 * Utility class for handling and validating version information of various artifacts.
3332 *
@@ -107,18 +106,17 @@ static private String getVersionOfClassByModule(Class<?> aClass) {
107106 * <code>moduleName-version.properties</code>. The properties file should contain a single key-value pair,
108107 * where the key is <code>moduleName-version</code>, and the value is the module version.
109108 *
110- * @param aClass the class used to locate the resource file, the properties file is expected to be in the same package
109+ * @param aClass the class used to locate the resource file, the properties file is expected to be in the same package
111110 * @param moduleName the name of the module, which is used to construct the properties file name and the key
112111 * @return the version of the module as a string, or null if the version cannot be determined
113- *
114112 * @since 1.5.26
115113 */
116114 static public String getArtifactVersionBySelfDeclaredProperties (Class <?> aClass , String moduleName ) {
117115 Properties props = new Properties ();
118116 // example propertiesFileName: logback-core-version.properties
119117 //
120118 String propertiesFileName = moduleName + "-version.properties" ;
121- String propertyKey = moduleName + "-version" ;
119+ String propertyKey = moduleName + "-version" ;
122120 try (InputStream is = aClass .getResourceAsStream (propertiesFileName )) {
123121 if (is != null ) {
124122 props .load (is );
@@ -135,7 +133,7 @@ static public String getArtifactVersionBySelfDeclaredProperties(Class<?> aClass,
135133 // dependency synonym dependee
136134 // depender synonym dependent
137135
138- static String getExpectedVersionOfDependeeByProperties (Class <?> dependerClass , String propertiesFileName , String dependencyNameAsKey ) {
136+ static String getExpectedVersionOfDependencyByProperties (Class <?> dependerClass , String propertiesFileName , String dependencyNameAsKey ) {
139137 Properties props = new Properties ();
140138 // propertiesFileName : logback-access-common-dependees.properties
141139 try (InputStream is = dependerClass .getClassLoader ()
@@ -151,24 +149,33 @@ static String getExpectedVersionOfDependeeByProperties(Class<?> dependerClass, S
151149 }
152150 }
153151
152+
154153 static public void checkForVersionEquality (Context context , Class <?> dependerClass , Class <?> dependencyClass , String dependentName , String dependencyName ) {
155154 // the depender depends on the dependency
156- String dependentVersion = nonNull (getVersionOfArtifact (dependerClass ));
155+ String dependerVersion = nonNull (getVersionOfArtifact (dependerClass ));
157156 String dependencyVersion = nonNull (getVersionOfArtifact (dependencyClass ));
158157
159- checkForVersionEquality (context , dependentVersion , dependencyVersion , dependentName , dependencyName );
158+ checkForVersionEquality (context , dependerVersion , dependencyVersion , dependentName , dependencyName );
159+ }
160+
161+ // depender depends on dependency
162+ // dependency synonym dependee
163+ // depender synonym dependent
164+ static public void checkForVersionEquality (Context context , Class <?> dependerClass , String dependencyVersion , String dependentName , String dependencyName ) {
165+ String dependerVersion = nonNull (getVersionOfArtifact (dependerClass ));
166+ checkForVersionEquality (context , dependerVersion , dependencyVersion , dependentName , dependencyName );
160167 }
161168
169+
162170 /**
163171 * Compares the versions of a dependent and a dependency to determine if they are equal.
164172 * Updates the context's status manager with version information and logs a warning if the versions differ.
165173 *
166- * @param context the logging context to which status messages are added
167- * @param dependentVersion the version string of the dependent component
174+ * @param context the logging context to which status messages are added
175+ * @param dependentVersion the version string of the dependent component
168176 * @param dependencyVersion the version string of the dependency component
169- * @param dependentName the name of the dependent component
170- * @param dependencyName the name of the dependency component
171- *
177+ * @param dependentName the name of the dependent component
178+ * @param dependencyName the name of the dependency component
172179 * @since 1.5.26
173180 */
174181 static public void checkForVersionEquality (Context context , String dependentVersion , String dependencyVersion , String dependentName , String dependencyName ) {
@@ -182,25 +189,36 @@ static public void checkForVersionEquality(Context context, String dependentVers
182189 }
183190 }
184191
185- private static void addFoundVersionStatus (Context context , String name , String version ) {
192+
193+
194+
195+
196+ private static void addFoundVersionStatus (Context context , String name , String version ) {
186197 String foundDependent = String .format ("Found %s version %s" , name , version );
187198 context .getStatusManager ().add (new InfoStatus (foundDependent , context ));
188199 }
189200
190201
191-
192- private static String nameToFilename (String name ) {
193- return name +"-dependencies.properties" ;
202+ private static String nameToFilename (String name ) {
203+ return name + "-dependencies.properties" ;
194204 }
195205
206+ // // dependency synonym dependee
207+ // // depender synonym dependent
208+ // static public void compareExpectedAndFoundVersion(Context context, Class<?> dependerClass, Class<?> dependencyClass,
209+ // String dependerName, String dependencyName) {
210+ // String actualDependencyVersion = nonNull(getVersionOfArtifact(dependencyClass));
211+ // String dependerVersion = nonNull(getVersionOfArtifact(dependerClass));
212+ //
213+ // compareExpectedAndFoundVersion(context, actualDependencyVersion, dependerClass, dependerVersion, dependerName, dependencyName);
214+ // }
215+
196216 // dependency synonym dependee
197217 // depender synonym dependent
198- static public void compareExpectedAndFoundVersion (Context context , Class <?> dependerClass , Class <?> dependencyClass ,
199- String dependerName , String dependencyName ) {
218+ static public void compareExpectedAndFoundVersion (Context context , String actualDependencyVersion , Class <?>dependerClass , String dependerVersion ,
219+ String dependerName , String dependencyName ) {
200220
201- String expectedDependencyVersion = nonNull (getExpectedVersionOfDependeeByProperties (dependerClass , nameToFilename (dependerName ), dependencyName ));
202- String actualDependencyVersion = nonNull (getVersionOfArtifact (dependencyClass ));
203- String dependerVersion = nonNull (getVersionOfArtifact (dependerClass ));
221+ String expectedDependencyVersion = nonNull (getExpectedVersionOfDependencyByProperties (dependerClass , nameToFilename (dependerName ), dependencyName ));
204222
205223 addFoundVersionStatus (context , dependencyName , actualDependencyVersion );
206224 addFoundVersionStatus (context , dependerName , dependerVersion );
@@ -209,6 +227,5 @@ static public void compareExpectedAndFoundVersion(Context context, Class<?> depe
209227 String discrepancyMsg = String .format ("Expected version of %s is %s but found %s" , dependencyName , expectedDependencyVersion , actualDependencyVersion );
210228 context .getStatusManager ().add (new WarnStatus (discrepancyMsg , context ));
211229 }
212-
213230 }
214231}
0 commit comments