Handling exceptions following fasten guidelines in the consume method.
@@ -86,8 +86,8 @@ public class DebianLicenseDetectorPlugin extends Plugin {
}
@Override
- public void consume(String record) throws IOException, InterruptedException, TimeoutException {
- //try { // Fasten error-handling guidelines
+ public void consume(String record) {
+ try { // Fasten error-handling guidelines
reset();
JSONObject json = new JSONObject(record);
logger.info("Debian license detector started.");
@@ -149,7 +149,19 @@ public class DebianLicenseDetectorPlugin extends Plugin {
NumberOfFilesWithDoubleEntries = 0;
file = null;
FileDoubleEntered = null;
- //}
+ } catch (SocketTimeoutException ex) {
+ ex.printStackTrace();
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ } catch (TimeoutException ex) {
+ ex.printStackTrace();
+ }
+ /*} catch (Exception e) { // Fasten error-handling guidelines
+ logger.error(e.getMessage(), e.getCause());
+ setPluginError(e);
+ }*/
}
@Override
@@ -349,7 +361,7 @@ public class DebianLicenseDetectorPlugin extends Plugin {
* @return the package version
* @throws IllegalArgumentException in case the function couldn't find the package version.
*/
- protected String extractPackageVersion(JSONObject json) throws IllegalArgumentException {
+ protected static String extractPackageVersion(JSONObject json) throws IllegalArgumentException {
for (var key : json.keySet()) {
if (key.equals("version")) {
return json.getString("version");
@@ -373,7 +385,7 @@ public class DebianLicenseDetectorPlugin extends Plugin {
* @param json the input record containing package information.
* @return the package name.
*/
- protected String extractPackageName(JSONObject json) {
+ protected static String extractPackageName(JSONObject json) {
for (var key : json.keySet()) {
if (key.equals("product")) {
return json.getString("product");
@@ -603,7 +615,7 @@ public class DebianLicenseDetectorPlugin extends Plugin {
}
// this method retrieves the json file given a path
- protected JSONObject GetDirectoryOrFileJSON(String path) throws InterruptedException, RuntimeException, IOException, TimeoutException, SocketTimeoutException {
+ protected static JSONObject GetDirectoryOrFileJSON(String path) throws InterruptedException, RuntimeException, IOException, TimeoutException, SocketTimeoutException {
JSONObject JSONDirectoryOrFile = new JSONObject();
URL url = new URL("https://sources.debian.org/api/src/" + path + "/");
System.out.println(url);
@@ -673,7 +685,7 @@ public class DebianLicenseDetectorPlugin extends Plugin {
}
// this method is used to measure the time elapsed for scanning a given package
- protected void MeasureElapsedTime() {
+ protected static void MeasureElapsedTime() {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
@@ -682,7 +694,7 @@ public class DebianLicenseDetectorPlugin extends Plugin {
}
// this method convert from milliseconds to minutes and seconds.
- protected String ConvertMsToMins(long milliseconds) {
+ protected static String ConvertMsToMins(long milliseconds) {
// formula for conversion for
// milliseconds to minutes.
