From 07134ce5581a0bdaea237155171978edcb4acde6 Mon Sep 17 00:00:00 2001 From: Dmitry Gruzd Date: Mon, 19 Sep 2016 17:12:31 +0300 Subject: [PATCH 1/3] Environment variables for team identifier and name of the provisioning profiles. --- .../KPPProvisioningProfilesBuildWrapper.java | 18 ++-- .../kpp/model/KPPProvisioningProfile.java | 78 ++++++++++++++-- .../KPPProvisioningProfilesProvider.java | 88 +++++++++++++++++++ .../config.jelly | 2 +- .../config.properties | 2 +- .../model/KPPProvisioningProfile/config.jelly | 8 +- .../KPPProvisioningProfile/config.properties | 2 + .../KPPProvisioningProfile/help-name.jelly | 29 ++++++ .../help-teamIdentifier.jelly | 29 ++++++ ...bleName.jelly => help-variableNames.jelly} | 4 + 10 files changed, 246 insertions(+), 14 deletions(-) create mode 100644 src/main/webapp/model/KPPProvisioningProfile/help-name.jelly create mode 100644 src/main/webapp/model/KPPProvisioningProfile/help-teamIdentifier.jelly rename src/main/webapp/model/KPPProvisioningProfile/{help-variableName.jelly => help-variableNames.jelly} (86%) diff --git a/src/main/java/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper.java b/src/main/java/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper.java index 2b82614c..f5448b31 100644 --- a/src/main/java/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper.java +++ b/src/main/java/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper.java @@ -155,7 +155,7 @@ private void copyProvisioningProfiles(AbstractBuild build) throws IOException, I for (KPPProvisioningProfile pp : provisioningProfiles) { FilePath from = new FilePath(hudsonRoot, pp.getProvisioningProfileFilePath()); - String toPPPath = String.format("%s%s%s", toProvisioningProfilesDirectoryPath, File.separator, KPPProvisioningProfilesProvider.getUUIDFileName(pp.getUuid())); + String toPPPath = String.format("%s%s%s", toProvisioningProfilesDirectoryPath, File.separator, KPPProvisioningProfilesProvider.getUUIDFileName(pp.getProfileUuid())); FilePath to = new FilePath(channel, toPPPath); if (overwriteExistingProfiles || !to.exists()) { from.copyTo(to); @@ -208,9 +208,17 @@ public EnvironmentImpl(List provisioningProfiles) { private Map getEnvMap() { Map map = new HashMap(); for(KPPProvisioningProfile profile : provisioningProfiles) { - String uuid = profile.getUuid(); - if (uuid != null && uuid.length()!=0) { - map.put(profile.getProvisioningProfileVariableName(), uuid); + String profileUuid = profile.getProfileUuid(); + if (profileUuid != null && profileUuid.length() != 0) { + map.put(profile.getProvisioningProfileVariableName(), profileUuid); + } + String profileName = profile.getProfileName(); + if (profileName != null && profileName.length() != 0) { + map.put(profile.getProvisioningProfileSpecifierVariableName(), profileName); + } + String profileTeamIdentifier = profile.getProfileTeamIdentifier(); + if (profileTeamIdentifier != null && profileTeamIdentifier.length() != 0) { + map.put(profile.getDevelopmentTeamVariableName(), profileTeamIdentifier); } } return map; @@ -235,4 +243,4 @@ public boolean tearDown(AbstractBuild build, BuildListener listener) } } - \ No newline at end of file + diff --git a/src/main/java/com/sic/plugins/kpp/model/KPPProvisioningProfile.java b/src/main/java/com/sic/plugins/kpp/model/KPPProvisioningProfile.java index 145e7d7b..e54f5d90 100644 --- a/src/main/java/com/sic/plugins/kpp/model/KPPProvisioningProfile.java +++ b/src/main/java/com/sic/plugins/kpp/model/KPPProvisioningProfile.java @@ -43,11 +43,16 @@ */ public class KPPProvisioningProfile implements Describable, Serializable { + private final static String DEVELOPMENT_TEAM_BASE_VARIABLE_NAME = "DEVELOPMENT_TEAM"; private final static String PROVISIONING_PROFILE_BASE_VARIABLE_NAME = "PROVISIONING_PROFILE"; + private final static String PROVISIONING_PROFILE_SPECIFIER_BASE_VARIABLE_NAME = "PROVISIONING_PROFILE_SPECIFIER"; private final String fileName; private final String varPrefix; // variable prefix for build step integration - private transient String uuid; + + private transient String profileUuid; + private transient String profileName; + private transient String profileTeamIdentifier; /** * Constructor @@ -85,6 +90,21 @@ public String getVarPrefix() { return varPrefix; } + /** + * Get the variable name for the development team. + * @return variable name. + */ + public String getDevelopmentTeamVariableName() { + String name; + String prefix = getVarPrefix(); + if (prefix!=null && !prefix.isEmpty()) { + name = String.format("%s_%s", prefix, DEVELOPMENT_TEAM_BASE_VARIABLE_NAME); + } else { + name = DEVELOPMENT_TEAM_BASE_VARIABLE_NAME; + } + return name; + } + /** * Get the variable name for the provisioning profile. * @return variable name. @@ -100,6 +120,30 @@ public String getProvisioningProfileVariableName() { return name; } + /** + * Get the variable name for the provisioning profile specifier. + * @return variable name. + */ + public String getProvisioningProfileSpecifierVariableName() { + String name; + String prefix = getVarPrefix(); + if (prefix!=null && !prefix.isEmpty()) { + name = String.format("%s_%s", prefix, PROVISIONING_PROFILE_SPECIFIER_BASE_VARIABLE_NAME); + } else { + name = PROVISIONING_PROFILE_SPECIFIER_BASE_VARIABLE_NAME; + } + return name; + } + + /** + * Get variable names which can be used in other build steps. + * @return development team, identifier (uuid) and name variable names + */ + public String getVariableNames() { + String variables = String.format("${%s} ${%s} ${%s}", getDevelopmentTeamVariableName(), getProvisioningProfileVariableName(), getProvisioningProfileSpecifierVariableName()); + return variables; + } + /** * Get the variable name included in ${}. * @return variable name @@ -112,11 +156,33 @@ public String getVariableName() { * Get the uuid of the provisioning profile. * @return uuid */ - public String getUuid() { - if (uuid==null || uuid.isEmpty()) { - uuid = KPPProvisioningProfilesProvider.parseUUIDFromProvisioningProfileFile(fileName); + public String getProfileUuid() { + if (profileUuid==null || profileUuid.isEmpty()) { + profileUuid = KPPProvisioningProfilesProvider.parseUUIDFromProvisioningProfileFile(fileName); + } + return profileUuid; + } + + /** + * Get the name of the provisioning profile. + * @return name + */ + public String getProfileName() { + if (profileName==null || profileName.isEmpty()) { + profileName = KPPProvisioningProfilesProvider.parseNameFromProvisioningProfileFile(fileName); + } + return profileName; + } + + /** + * Get the team identifier of the provisioning profile. + * @return team identifier + */ + public String getProfileTeamIdentifier() { + if (profileTeamIdentifier==null || profileTeamIdentifier.isEmpty()) { + profileTeamIdentifier = KPPProvisioningProfilesProvider.parseTeamIdentifierFromProvisioningProfileFile(fileName); } - return uuid; + return profileTeamIdentifier; } /** @@ -124,7 +190,7 @@ public String getUuid() { * @return filename and uuid */ public String getFileNameUuidDescription() { - return String.format("%s (%s)", getFileName(), getUuid()); + return String.format("%s (%s)", getFileName(), getProfileUuid()); } @Override diff --git a/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java b/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java index debe80c6..32cee2ca 100644 --- a/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java +++ b/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java @@ -105,4 +105,92 @@ public static String parseUUIDFromProvisioningProfileFile(String fileName) { } return uuid; } + + /** + * Parse the Name from the content of the provisioning profile file. + * @param fileName name of the provisioning profile file + * @return Name + */ + public static String parseNameFromProvisioningProfileFile(String fileName) { + String name = "Name not found"; + BufferedReader br = null; + try { + String fileNameWithoutUUID = KPPBaseProvisioningProfilesProvider.removeUUIDFromFileName(fileName); + File file = KPPProvisioningProfilesProvider.getInstance().getProvisioningFile(fileNameWithoutUUID); + FileReader reader = new FileReader(file); + br = new BufferedReader(reader); + String line; + boolean foundName = false; + while (br!=null && (line = br.readLine()) != null) { + if (line.contains("Name")) { + foundName = true; // next line is value + } else if (foundName) { + final String openTag = ""; + final String closeTag = ""; + // parse value for Name key + int indexOfOpenTag = line.indexOf(openTag); + int indexOfCloseTag = line.indexOf(closeTag); + if (indexOfOpenTag != -1 && indexOfCloseTag != -1 && indexOfOpenTag < indexOfCloseTag) { + name = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); + } + break; + } + } + } catch (FileNotFoundException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } catch (IOException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } finally { + try { + br.close(); + } catch (IOException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } + } + return name; + } + + /** + * Parse the TeamIdentifier from the content of the provisioning profile file. + * @param fileName name of the provisioning profile file + * @return TeamIdentifier + */ + public static String parseTeamIdentifierFromProvisioningProfileFile(String fileName) { + String teamIdentifier = "TeamIdentifier not found"; + BufferedReader br = null; + try { + String fileNameWithoutUUID = KPPBaseProvisioningProfilesProvider.removeUUIDFromFileName(fileName); + File file = KPPProvisioningProfilesProvider.getInstance().getProvisioningFile(fileNameWithoutUUID); + FileReader reader = new FileReader(file); + br = new BufferedReader(reader); + String line; + boolean foundTeamIdentifier = false; + while (br!=null && (line = br.readLine()) != null) { + if (line.contains("com.apple.developer.team-identifier")) { + foundTeamIdentifier = true; // next line is value + } else if (foundTeamIdentifier) { + final String openTag = ""; + final String closeTag = ""; + // parse value for Name key + int indexOfOpenTag = line.indexOf(openTag); + int indexOfCloseTag = line.indexOf(closeTag); + if (indexOfOpenTag != -1 && indexOfCloseTag != -1 && indexOfOpenTag < indexOfCloseTag) { + teamIdentifier = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); + } + break; + } + } + } catch (FileNotFoundException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } catch (IOException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } finally { + try { + br.close(); + } catch (IOException ex) { + LOGGER.log(Level.SEVERE, null, ex); + } + } + return teamIdentifier; + } } diff --git a/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.jelly b/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.jelly index 3d5beb39..e85b97cd 100644 --- a/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.jelly +++ b/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.jelly @@ -40,7 +40,7 @@ THE SOFTWARE. - + diff --git a/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.properties b/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.properties index e8ea1185..73261dc7 100644 --- a/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.properties +++ b/src/main/resources/com/sic/plugins/kpp/KPPProvisioningProfilesBuildWrapper/config.properties @@ -25,6 +25,6 @@ delete = Delete copied provisioning profiles after build add_btn = Add Provisioning Profile profile = Provisioning Profile prefix = Variable Prefix -variable = Variable +variables = Variables delete_btn = Delete diff --git a/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.jelly b/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.jelly index 90a0ce03..3c0ac518 100644 --- a/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.jelly +++ b/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.jelly @@ -29,8 +29,14 @@ THE SOFTWARE. + + + - + + + +
diff --git a/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.properties b/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.properties index b9346968..626aa808 100644 --- a/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.properties +++ b/src/main/resources/com/sic/plugins/kpp/model/KPPProvisioningProfile/config.properties @@ -21,6 +21,8 @@ # THE SOFTWARE. filename = Filename +teamIdentifier = Team Identifier uuid = UUID +name = Name delete_btn = Delete Provisioning Profile diff --git a/src/main/webapp/model/KPPProvisioningProfile/help-name.jelly b/src/main/webapp/model/KPPProvisioningProfile/help-name.jelly new file mode 100644 index 00000000..d110dfee --- /dev/null +++ b/src/main/webapp/model/KPPProvisioningProfile/help-name.jelly @@ -0,0 +1,29 @@ + + + + + + The automatically detected name of the provisioning profile. + diff --git a/src/main/webapp/model/KPPProvisioningProfile/help-teamIdentifier.jelly b/src/main/webapp/model/KPPProvisioningProfile/help-teamIdentifier.jelly new file mode 100644 index 00000000..8dba0a7a --- /dev/null +++ b/src/main/webapp/model/KPPProvisioningProfile/help-teamIdentifier.jelly @@ -0,0 +1,29 @@ + + + + + + The automatically detected team identifier of the provisioning profile. + diff --git a/src/main/webapp/model/KPPProvisioningProfile/help-variableName.jelly b/src/main/webapp/model/KPPProvisioningProfile/help-variableNames.jelly similarity index 86% rename from src/main/webapp/model/KPPProvisioningProfile/help-variableName.jelly rename to src/main/webapp/model/KPPProvisioningProfile/help-variableNames.jelly index 18b6c75f..fd242b5b 100644 --- a/src/main/webapp/model/KPPProvisioningProfile/help-variableName.jelly +++ b/src/main/webapp/model/KPPProvisioningProfile/help-variableNames.jelly @@ -27,7 +27,11 @@ THE SOFTWARE. Variables added to the build environment. They can be used in other build steps.
+
${DEVELOPMENT_TEAM}
+
Contains the team identifier of the provisioning profile.
${PROVISIONING_PROFILE}
Contains the uuid of the provisioning profile.
+
${PROVISIONING_PROFILE_SPECIFIER}
+
Contains the name of the provisioning profile.
From 6e35036df78cdbbd187f8c12998d77d4cc6563eb Mon Sep 17 00:00:00 2001 From: Dmitry Gruzd Date: Thu, 6 Oct 2016 01:57:43 +0300 Subject: [PATCH 2/3] Refactoring --- .../KPPProvisioningProfilesProvider.java | 100 ++++-------------- 1 file changed, 23 insertions(+), 77 deletions(-) diff --git a/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java b/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java index 32cee2ca..9748e59a 100644 --- a/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java +++ b/src/main/java/com/sic/plugins/kpp/provider/KPPProvisioningProfilesProvider.java @@ -68,42 +68,11 @@ public File getProvisioningFile(String fileName) { * @return UUID */ public static String parseUUIDFromProvisioningProfileFile(String fileName) { - String uuid = "UUID not found"; - BufferedReader br = null; - try { - String fileNameWithoutUUID = KPPBaseProvisioningProfilesProvider.removeUUIDFromFileName(fileName); - File file = KPPProvisioningProfilesProvider.getInstance().getProvisioningFile(fileNameWithoutUUID); - FileReader reader = new FileReader(file); - br = new BufferedReader(reader); - String line; - boolean foundUUID = false; - while (br!=null && (line = br.readLine()) != null) { - if (line.contains("UUID")) { - foundUUID = true; // next line is value - } else if (foundUUID) { - final String openTag = ""; - final String closeTag = ""; - // parse value for UUID key - int indexOfOpenTag = line.indexOf(openTag); - int indexOfCloseTag = line.indexOf(closeTag); - if (indexOfOpenTag != -1 && indexOfCloseTag != -1 && indexOfOpenTag < indexOfCloseTag) { - uuid = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); - } - break; - } - } - } catch (FileNotFoundException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } catch (IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } finally { - try { - br.close(); - } catch (IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } + String value = parseStringValueFromProvisioningProfileFile(fileName, "UUID"); + if (value == null || value.isEmpty()) { + return "UUID not found"; } - return uuid; + return value; } /** @@ -112,42 +81,11 @@ public static String parseUUIDFromProvisioningProfileFile(String fileName) { * @return Name */ public static String parseNameFromProvisioningProfileFile(String fileName) { - String name = "Name not found"; - BufferedReader br = null; - try { - String fileNameWithoutUUID = KPPBaseProvisioningProfilesProvider.removeUUIDFromFileName(fileName); - File file = KPPProvisioningProfilesProvider.getInstance().getProvisioningFile(fileNameWithoutUUID); - FileReader reader = new FileReader(file); - br = new BufferedReader(reader); - String line; - boolean foundName = false; - while (br!=null && (line = br.readLine()) != null) { - if (line.contains("Name")) { - foundName = true; // next line is value - } else if (foundName) { - final String openTag = ""; - final String closeTag = ""; - // parse value for Name key - int indexOfOpenTag = line.indexOf(openTag); - int indexOfCloseTag = line.indexOf(closeTag); - if (indexOfOpenTag != -1 && indexOfCloseTag != -1 && indexOfOpenTag < indexOfCloseTag) { - name = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); - } - break; - } - } - } catch (FileNotFoundException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } catch (IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } finally { - try { - br.close(); - } catch (IOException ex) { - LOGGER.log(Level.SEVERE, null, ex); - } + String value = parseStringValueFromProvisioningProfileFile(fileName, "Name"); + if (value == null || value.isEmpty()) { + return "Name not found"; } - return name; + return value; } /** @@ -156,7 +94,15 @@ public static String parseNameFromProvisioningProfileFile(String fileName) { * @return TeamIdentifier */ public static String parseTeamIdentifierFromProvisioningProfileFile(String fileName) { - String teamIdentifier = "TeamIdentifier not found"; + String value = parseStringValueFromProvisioningProfileFile(fileName, "com.apple.developer.team-identifier"); + if (value == null || value.isEmpty()) { + return "TeamIdentifier not found"; + } + return value; + } + + private static String parseStringValueFromProvisioningProfileFile(String fileName, String keyName) { + String keyValue = null; BufferedReader br = null; try { String fileNameWithoutUUID = KPPBaseProvisioningProfilesProvider.removeUUIDFromFileName(fileName); @@ -164,18 +110,18 @@ public static String parseTeamIdentifierFromProvisioningProfileFile(String fileN FileReader reader = new FileReader(file); br = new BufferedReader(reader); String line; - boolean foundTeamIdentifier = false; + boolean foundKeyName = false; while (br!=null && (line = br.readLine()) != null) { - if (line.contains("com.apple.developer.team-identifier")) { - foundTeamIdentifier = true; // next line is value - } else if (foundTeamIdentifier) { + if (line.contains("" + keyName + "")) { + foundKeyName = true; // next line is value + } else if (foundKeyName) { final String openTag = ""; final String closeTag = ""; // parse value for Name key int indexOfOpenTag = line.indexOf(openTag); int indexOfCloseTag = line.indexOf(closeTag); if (indexOfOpenTag != -1 && indexOfCloseTag != -1 && indexOfOpenTag < indexOfCloseTag) { - teamIdentifier = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); + keyValue = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag); } break; } @@ -191,6 +137,6 @@ public static String parseTeamIdentifierFromProvisioningProfileFile(String fileN LOGGER.log(Level.SEVERE, null, ex); } } - return teamIdentifier; + return keyValue; } } From dad1c337e6ce9e6c5f3a879fa192d79d6594cced Mon Sep 17 00:00:00 2001 From: Dmitry Gruzd Date: Thu, 6 Oct 2016 02:01:11 +0300 Subject: [PATCH 3/3] Core baseline updated to 1.554.1 in order to make builds and pass tests with JDK 8 Solution is described at: https://issues.jenkins-ci.org/browse/JENKINS-23239 https://issues.jenkins-ci.org/browse/JENKINS-27168 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ebf73f9c..b92647a3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.jenkins-ci.plugins plugin - 1.509.2 + 1.554.1