From 57235c1af529909973e5b77a769166f3c8806f5a Mon Sep 17 00:00:00 2001 From: malachy Date: Tue, 5 Dec 2023 14:05:01 +0000 Subject: [PATCH] Split repeated code out from CordappPlugin into a separate function --- .../net/corda/plugins/cpk2/CordappPlugin.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/cordapp-cpk2/src/main/java/net/corda/plugins/cpk2/CordappPlugin.java b/cordapp-cpk2/src/main/java/net/corda/plugins/cpk2/CordappPlugin.java index 6050f678e..c4e5fd033 100644 --- a/cordapp-cpk2/src/main/java/net/corda/plugins/cpk2/CordappPlugin.java +++ b/cordapp-cpk2/src/main/java/net/corda/plugins/cpk2/CordappPlugin.java @@ -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); } @@ -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); } @@ -627,6 +617,21 @@ private static void mustContainAll(@NotNull Map 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 {