Skip to content

Commit

Permalink
Merge pull request #3 from apigee/2-input-arg-validations
Browse files Browse the repository at this point in the history
fix: validations
  • Loading branch information
ssvaidyanathan authored Oct 22, 2024
2 parents 1937b2f + 9339de3 commit b8a1410
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 111 deletions.
2 changes: 1 addition & 1 deletion samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<plugin>
<groupId>com.apigee.apihub.config</groupId>
<artifactId>apigee-apihub-maven-plugin</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<executions>
<execution>
<id>apigee-apihub-attributes</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/com/apigee/apihub/config/mavenplugin/ApisMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 13 additions & 16 deletions src/main/java/com/apigee/apihub/config/mavenplugin/SpecsMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit b8a1410

Please sign in to comment.