From 9339de36a111cb959e71e6581198fa77aad668f4 Mon Sep 17 00:00:00 2001 From: Sai Saran Vaidyanathan Date: Tue, 22 Oct 2024 08:59:31 -0700 Subject: [PATCH] fix: validations --- samples/pom.xml | 2 +- .../config/mavenplugin/ApiVersionsMojo.java | 29 +++++++++---------- .../apihub/config/mavenplugin/ApisMojo.java | 27 +++++++++-------- .../config/mavenplugin/AttributesMojo.java | 29 +++++++++---------- .../config/mavenplugin/DependenciesMojo.java | 29 +++++++++---------- .../config/mavenplugin/DeploymentsMojo.java | 29 +++++++++---------- .../config/mavenplugin/ExternalApisMojo.java | 29 +++++++++---------- .../apihub/config/mavenplugin/SpecsMojo.java | 29 +++++++++---------- 8 files changed, 92 insertions(+), 111 deletions(-) diff --git a/samples/pom.xml b/samples/pom.xml index c64f16c..87d63b8 100755 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -42,7 +42,7 @@ com.apigee.apihub.config apigee-apihub-maven-plugin - 1.1.0 + 1.1.1 apigee-apihub-attributes diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/ApiVersionsMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/ApiVersionsMojo.java index 6539cf8..941cc20 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/ApiVersionsMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/ApiVersionsMojo.java @@ -135,34 +135,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/ApisMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/ApisMojo.java index 29b0900..5bc722f 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/ApisMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/ApisMojo.java @@ -120,32 +120,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/AttributesMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/AttributesMojo.java index a2a9c51..7c074f9 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/AttributesMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/AttributesMojo.java @@ -120,34 +120,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/DependenciesMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/DependenciesMojo.java index 6dbe847..f5695aa 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/DependenciesMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/DependenciesMojo.java @@ -120,34 +120,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/DeploymentsMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/DeploymentsMojo.java index 9f6b29e..48c7044 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/DeploymentsMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/DeploymentsMojo.java @@ -120,34 +120,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/ExternalApisMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/ExternalApisMojo.java index 7ba6094..c4eaad7 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/ExternalApisMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/ExternalApisMojo.java @@ -120,34 +120,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; } diff --git a/src/main/java/com/apigee/apihub/config/mavenplugin/SpecsMojo.java b/src/main/java/com/apigee/apihub/config/mavenplugin/SpecsMojo.java index c0f97f4..fd9338e 100644 --- a/src/main/java/com/apigee/apihub/config/mavenplugin/SpecsMojo.java +++ b/src/main/java/com/apigee/apihub/config/mavenplugin/SpecsMojo.java @@ -140,34 +140,31 @@ public void init() throws MojoExecutionException, MojoFailureException { logger.debug("Build option " + buildOption.name()); - if (buildProfile.getProjectId() == null) { - throw new MojoExecutionException("Apigee API hub Project ID is missing"); + if (Strings.isNullOrEmpty(buildProfile.getProjectId())) { + throw new MojoExecutionException("Apigee API hub Project ID is missing or empty"); } - if (buildProfile.getLocation() == null) { - throw new MojoExecutionException("Apigee API hub Location is missing"); + if (Strings.isNullOrEmpty(buildProfile.getLocation())) { + throw new MojoExecutionException("Apigee API hub Location is missing or empty"); } - if (buildProfile.getServiceAccountFilePath() == null && buildProfile.getBearer() == null) { - throw new MojoExecutionException("Service Account file path or Bearer token is missing"); + if (Strings.isNullOrEmpty(buildProfile.getServiceAccountFilePath()) && Strings.isNullOrEmpty(buildProfile.getBearer())) { + throw new MojoExecutionException("Service Account file path or Bearer token is missing or empty"); } - if (buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (!buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigDir())) { + throw new MojoExecutionException("API Config Directory is missing"); } - if (!buildOption.equals(OPTIONS.export) && buildProfile.getConfigDir() == null) { - throw new MojoExecutionException("API Confile Dir is missing"); + if (buildOption.equals(OPTIONS.export) && Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { + throw new MojoExecutionException("Config Export Directory is missing"); } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() == null) { - throw new MojoExecutionException("Confile Export Dir is missing"); - } - if (buildOption.equals(OPTIONS.export) && buildProfile.getConfigExportDir() != null) { + if (buildOption.equals(OPTIONS.export) && !Strings.isNullOrEmpty(buildProfile.getConfigExportDir())) { File f = new File(buildProfile.getConfigExportDir()); if (!f.exists() || !f.isDirectory()) { - throw new MojoExecutionException("Export Dir is not created or is incorrect"); + throw new MojoExecutionException("Config Export Directory is not created or is incorrect"); } } } catch (IllegalArgumentException e) { - throw new RuntimeException("Invalid apigee.option provided"); + throw new RuntimeException("Invalid apigee.apihub.config.options provided"); } catch (RuntimeException e) { throw e; }