Skip to content

Commit

Permalink
Split repeated code out from CordappPlugin into a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
malachyb committed Dec 5, 2023
1 parent 0ebcdd3 commit 57235c1
Showing 1 changed file with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,9 @@ private void configureCordappAttributes(@NotNull String symbolicName, @NotNull A
final CordappData contract = cordapp.getContract();
Pattern cordappCpkNamePattern = Pattern.compile("[a-zA-Z0-9.\\-]+");
if (!contract.isEmpty()) {
final String cordappCpkName = contract.getCordappCpkName().getOrNull();
final String cordappCpkName = getCordaCpkCordappName(contract);
if (cordappCpkName != null) {
Matcher matcher = cordappCpkNamePattern.matcher(cordappCpkName);
if (matcher.matches()) {
attributes.put(CPK_CORDAPP_NAME, cordappCpkName);
} else {
throw new InvalidUserDataException("contract.cordappCpkName should contain only letters, numbers, dots, and dashes.");
}
attributes.put(CPK_CORDAPP_NAME, cordappCpkName);
} else {
attributes.put(CPK_CORDAPP_NAME, symbolicName);
}
Expand All @@ -542,14 +537,9 @@ private void configureCordappAttributes(@NotNull String symbolicName, @NotNull A

final CordappData workflow = cordapp.getWorkflow();
if (!workflow.isEmpty()) {
final String cordappCpkName = workflow.getCordappCpkName().getOrNull();
final String cordappCpkName = getCordaCpkCordappName(workflow);
if (cordappCpkName != null) {
Matcher matcher = cordappCpkNamePattern.matcher(cordappCpkName);
if (matcher.matches()) {
attributes.put(CPK_CORDAPP_NAME, cordappCpkName);
} else {
throw new InvalidUserDataException("workflow.cordappCpkName should contain only letters, numbers, dots, and dashes.");
}
attributes.put(CPK_CORDAPP_NAME, cordappCpkName);
} else {
attributes.put(CPK_CORDAPP_NAME, symbolicName);
}
Expand Down Expand Up @@ -627,6 +617,21 @@ private static void mustContainAll(@NotNull Map<String, String> instructions, @N
}
}
}

private static String getCordaCpkCordappName(@NotNull CordappData cordappData) {
Pattern cordappCpkNamePattern = Pattern.compile("[a-zA-Z0-9.\\-]+");
final String cordappCpkName = cordappData.getCordappCpkName().getOrNull();
if (cordappCpkName != null) {
Matcher matcher = cordappCpkNamePattern.matcher(cordappCpkName);
if (matcher.matches()) {
return cordappCpkName;
} else {
throw new InvalidUserDataException("cordappCpkName \"" + cordappCpkName + "\" should contain only letters, numbers, dots, and dashes.");
}
} else {
return null;
}
}
}

final class CordappVariantMapping implements Action<ConfigurationVariantDetails> {
Expand Down

0 comments on commit 57235c1

Please sign in to comment.