Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment variables for team identifier and name of the provisioning profiles. #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.509.2</version>
<version>1.554.1</version>
<relativePath />
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -208,9 +208,17 @@ public EnvironmentImpl(List<KPPProvisioningProfile> provisioningProfiles) {
private Map<String, String> getEnvMap() {
Map<String, String> map = new HashMap<String,String>();
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;
Expand All @@ -235,4 +243,4 @@ public boolean tearDown(AbstractBuild build, BuildListener listener)
}

}


Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@
*/
public class KPPProvisioningProfile implements Describable<KPPProvisioningProfile>, 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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -112,19 +156,41 @@ 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;
}

/**
* Get the filename and uuid in one string.
* @return filename and uuid
*/
public String getFileNameUuidDescription() {
return String.format("%s (%s)", getFileName(), getUuid());
return String.format("%s (%s)", getFileName(), getProfileUuid());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,60 @@ public File getProvisioningFile(String fileName) {
* @return UUID
*/
public static String parseUUIDFromProvisioningProfileFile(String fileName) {
String uuid = "UUID not found";
String value = parseStringValueFromProvisioningProfileFile(fileName, "UUID");
if (value == null || value.isEmpty()) {
return "UUID not found";
}
return value;
}

/**
* 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 value = parseStringValueFromProvisioningProfileFile(fileName, "Name");
if (value == null || value.isEmpty()) {
return "Name not found";
}
return value;
}

/**
* 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 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);
File file = KPPProvisioningProfilesProvider.getInstance().getProvisioningFile(fileNameWithoutUUID);
FileReader reader = new FileReader(file);
br = new BufferedReader(reader);
String line;
boolean foundUUID = false;
boolean foundKeyName = false;
while (br!=null && (line = br.readLine()) != null) {
if (line.contains("<key>UUID</key>")) {
foundUUID = true; // next line is value
} else if (foundUUID) {
if (line.contains("<key>" + keyName + "</key>")) {
foundKeyName = true; // next line is value
} else if (foundKeyName) {
final String openTag = "<string>";
final String closeTag = "</string>";
// parse value for UUID key
// parse value for Name 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);
keyValue = line.substring(indexOfOpenTag+openTag.length(), indexOfCloseTag);
}
break;
}
Expand All @@ -103,6 +137,6 @@ public static String parseUUIDFromProvisioningProfileFile(String fileName) {
LOGGER.log(Level.SEVERE, null, ex);
}
}
return uuid;
return keyValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ THE SOFTWARE.
<f:entry title="${%prefix}" field="varPrefix" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-varPrefix.jelly">
<f:textbox />
</f:entry>
<f:entry title="${%variable}" field="variableName" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-variableName.jelly">
<f:entry title="${%variables}" field="variableNames" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-variableNames.jelly">
<f:readOnlyTextbox/>
</f:entry>
<f:entry title="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@ THE SOFTWARE.
<f:entry title="${%filename}" field="fileName" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-fileName.jelly">
<f:readOnlyTextbox value="${it.fileName}"/>
</f:entry>
<f:entry title="${%teamIdentifier}" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-teamIdentifier.jelly">
<f:readOnlyTextbox value="${it.profileTeamIdentifier}"/>
</f:entry>
<f:entry title="${%uuid}" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-uuid.jelly">
<f:readOnlyTextbox value="${it.uuid}"/>
<f:readOnlyTextbox value="${it.profileUuid}"/>
</f:entry>
<f:entry title="${%name}" help="/plugin/kpp-management-plugin/model/KPPProvisioningProfile/help-name.jelly">
<f:readOnlyTextbox value="${it.profileName}"/>
</f:entry>
<f:entry title="">
<div align="right">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# THE SOFTWARE.

filename = Filename
teamIdentifier = Team Identifier
uuid = UUID
name = Name
delete_btn = Delete Provisioning Profile

29 changes: 29 additions & 0 deletions src/main/webapp/model/KPPProvisioningProfile/help-name.jelly
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright 2013 Michael Bär SIC! Software GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:i="jelly:fmt">
The automatically detected name of the provisioning profile.
</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The MIT License

Copyright 2013 Michael Bär SIC! Software GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->

<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:i="jelly:fmt">
The automatically detected team identifier of the provisioning profile.
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ THE SOFTWARE.
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:i="jelly:fmt">
Variables added to the build environment. They can be used in other build steps.
<dl>
<dt>${DEVELOPMENT_TEAM}</dt>
<dd>Contains the team identifier of the provisioning profile.</dd>
<dt>${PROVISIONING_PROFILE}</dt>
<dd>Contains the uuid of the provisioning profile.</dd>
<dt>${PROVISIONING_PROFILE_SPECIFIER}</dt>
<dd>Contains the name of the provisioning profile.</dd>
</dl>
</j:jelly>