From fbb6bac9be771b94c7b77bfc2ec2019ffb0cfc7e Mon Sep 17 00:00:00 2001 From: "Amir M. Mir" Date: Wed, 8 Jun 2022 10:20:44 +0200 Subject: [PATCH] Do NOT catch `Exception` in the plugins as it's already handled by the FASTEN server --- .../licensefeeder/LicenseFeederPlugin.java | 33 +++++++---------- .../PythonLicenseFeederPlugin.java | 36 ++++++++----------- .../VulnerabilityPackagesListener.java | 32 +++++++---------- .../VulnerabilityStatementsProcessor.java | 11 ++---- 4 files changed, 42 insertions(+), 70 deletions(-) diff --git a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java index 16135f7e8..6a5e343dc 100644 --- a/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java +++ b/analyzer/license-feeder/src/main/java/eu/fasten/analyzer/licensefeeder/LicenseFeederPlugin.java @@ -55,30 +55,23 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { - try { // Fasten error-handling guidelines + this.pluginError = null; - this.pluginError = null; + logger.info("License feeder started."); - logger.info("License feeder started."); + // Retrieving coordinates of the input record + Revision coordinates = extractMavenCoordinates(record); + logger.info("Input coordinates: " + coordinates + "."); - // Retrieving coordinates of the input record - Revision coordinates = extractMavenCoordinates(record); - logger.info("Input coordinates: " + coordinates + "."); - - // Inserting detected outbound into the database - var metadataDao = new MetadataDao(dslContext); - dslContext.transaction(transaction -> { - metadataDao.setContext(DSL.using(transaction)); - insertOutboundLicenses(coordinates, record, metadataDao); - insertFileLicenses(coordinates, record, metadataDao); - }); - - // TODO Inserting licenses in files + // Inserting detected outbound into the database + var metadataDao = new MetadataDao(dslContext); + dslContext.transaction(transaction -> { + metadataDao.setContext(DSL.using(transaction)); + insertOutboundLicenses(coordinates, record, metadataDao); + insertFileLicenses(coordinates, record, metadataDao); + }); - } catch (Exception e) { // Fasten error-handling guidelines - logger.error(e.getMessage(), e.getCause()); - throw e; - } + // TODO Inserting licenses in files } /** diff --git a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java index 2499541c0..acfaffe04 100644 --- a/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java +++ b/analyzer/python-license-feeder/src/main/java/eu/fasten/analyzer/pythonlicensefeeder/PythonLicenseFeederPlugin.java @@ -54,32 +54,24 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { - try { // Fasten error-handling guidelines + this.pluginError = null; - this.pluginError = null; + logger.info("License feeder started."); - logger.info("License feeder started."); + String packageName = extractPackageName(record); + String packageVersion = extractPackageVersion(record); + String sourcePath = extractSourcePath(record); - String packageName = extractPackageName(record); - String packageVersion = extractPackageVersion(record); - String sourcePath = extractSourcePath(record); + logger.info("Package name: " + packageName + "."); + logger.info("Package version: " + packageVersion + "."); - logger.info("Package name: " + packageName + "."); - logger.info("Package version: " + packageVersion + "."); - - // Inserting detected outbound into the database - var metadataDao = new MetadataDao(dslContext); - dslContext.transaction(transaction -> { - metadataDao.setContext(DSL.using(transaction)); - insertOutboundLicenses(packageName, packageVersion, record, metadataDao); - insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao); - }); - - - } catch (Exception e) { // Fasten error-handling guidelines - logger.error(e.getMessage(), e.getCause()); - throw e; - } + // Inserting detected outbound into the database + var metadataDao = new MetadataDao(dslContext); + dslContext.transaction(transaction -> { + metadataDao.setContext(DSL.using(transaction)); + insertOutboundLicenses(packageName, packageVersion, record, metadataDao); + insertFileLicenses(packageName, packageVersion, sourcePath, record, metadataDao); + }); } protected String extractPackageName(String record) { diff --git a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java index 4e0fdeac0..da12303c1 100644 --- a/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java +++ b/analyzer/vulnerability-packages-listener/src/main/java/eu/fasten/analyzer/vulnerabilitypackageslistener/VulnerabilityPackagesListener.java @@ -109,26 +109,18 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { setPluginError(null); - try { - statementsProcessor.setDBConnection(contexts); - statementsProcessor.setFastenApiClient(fastenApiClient); - var jsonRecord = new JSONObject(record); - var payload = findPayload(jsonRecord); - if(payload != null) { - var ecosystem = payload.getString("forge"); - var packageName = getPackageName(payload); - var version = payload.getString("version"); - logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version); - statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version); - } - else { - logger.error("Could not parse payload in message: " + record); - } - } - catch (Exception e) { - var error = "Error processing package update: " + e; - logger.error(error); - throw(e); + statementsProcessor.setDBConnection(contexts); + statementsProcessor.setFastenApiClient(fastenApiClient); + var jsonRecord = new JSONObject(record); + var payload = findPayload(jsonRecord); + if (payload != null) { + var ecosystem = payload.getString("forge"); + var packageName = getPackageName(payload); + var version = payload.getString("version"); + logger.info("Processing package update for forge \"" + ecosystem + "\": " + packageName + ":" + version); + statementsProcessor.updateNewPackageVersion(ecosystem, packageName, version); + } else { + logger.error("Could not parse payload in message: " + record); } } diff --git a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java index 4a2ae7772..44b73f48d 100644 --- a/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java +++ b/analyzer/vulnerability-statements-processor/src/main/java/eu/fasten/analyzer/vulnerabilitystatementsprocessor/VulnerabilityStatementsProcessor.java @@ -89,14 +89,9 @@ public void setTopics(List consumeTopics) { @Override public void consume(String record) { this.pluginError = null; - try { - var v = updateVulnerability(record); - outputPath = baseOutputPath + File.separator + v.getId() + ".json"; - lastProcessedVulnerability = v; - } catch (Exception e) { - logger.error("Error processing vulnerability statement: " + e); - throw e; - } + var v = updateVulnerability(record); + outputPath = baseOutputPath + File.separator + v.getId() + ".json"; + lastProcessedVulnerability = v; } @Override