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

Enabled #28

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5fb6671
changed pom.xml to enabled version
DylanSale Aug 19, 2013
c70780f
changed the build notes appended from change log to include all the l…
DylanSale Aug 19, 2013
9459001
started working on build notes path option, but realised we could do …
DylanSale Aug 19, 2013
4d01179
finished adding build notes file path option
DylanSale Aug 19, 2013
8294f36
fixed possible bug when build notes path is empty or null
DylanSale Aug 19, 2013
1f5183d
refactored the accumulation to use provided apis and to traverse the …
DylanSale Aug 19, 2013
04f63ea
fixed edge case bugs where the current changes were not being sent
DylanSale Aug 19, 2013
0010f21
passing vars to remoteRecorder
ndis1 Jun 16, 2014
ff096ae
passing vars to TestFlightUploader
ndis1 Jun 16, 2014
7896c37
added buildNotesPath to UploadRequest
ndis1 Jun 16, 2014
5db682a
fixed tests by passing null for EnvVars to RemoteRecorder constructor
ndis1 Jun 16, 2014
acc9028
added getBuildNotesFile to testFlightUploader and changed entity part…
ndis1 Jun 16, 2014
afbcb3f
added createBuildNotes to TestflightUploader and passed appendChangeL…
ndis1 Jun 16, 2014
e1f32f9
added getting build notes and notes entered in box back in
ndis1 Jun 16, 2014
106dd39
passed logger through to TestflightUploader
ndis1 Jun 16, 2014
dbc0a78
fixed buildpath name bug
ndis1 Jun 16, 2014
0d96fb9
fixed duplicating text bug
ndis1 Jun 16, 2014
fbbe27e
Merge pull request #2 from urbn/enabling_slave
hunt3r Jun 17, 2014
2dc5d44
fixed main bug
ndis1 Jun 17, 2014
15269c8
fixed main bug
ndis1 Jun 17, 2014
c648859
stopped passing through listener because it was causing a serializati…
ndis1 Jun 17, 2014
b8316b8
Stopped passing logger to Testflight Uploader because it was causing …
ndis1 Jun 17, 2014
84e408d
fixed main bug
ndis1 Jun 17, 2014
00089ca
changed serializable not to use constructor
ndis1 Jun 17, 2014
8085c38
added vars.expand to get environment variables in buildnotes written …
ndis1 Jun 17, 2014
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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.420</version><!-- which version of Jenkins is this plugin built against? -->
<version>1.525</version><!-- which version of Jenkins is this plugin built against? -->
</parent>

<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>testflight</artifactId>
<name>Testflight Plugin</name>
<description>Uploads .ipa files to www.testflightapp.com</description>
<version>1.3.10-SNAPSHOT</version>
<version>1.3.10-ENABLED</version>
<packaging>hpi</packaging>

<!-- get every artifact through maven.glassfish.org, which proxies all the artifacts that we need -->
Expand Down
161 changes: 142 additions & 19 deletions src/main/java/testflight/TestflightRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import hudson.util.RunList;
import hudson.util.Secret;
import org.apache.commons.collections.Predicate;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import hudson.model.Hudson;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.*;

import net.sf.json.JSONObject;
Expand Down Expand Up @@ -56,12 +60,25 @@ public String getBuildNotes() {
return this.buildNotes;
}

private String buildNotesPath;

public String getBuildNotesPath() {
return this.buildNotesPath;
}


private boolean appendChangelog;

public boolean getAppendChangelog() {
return this.appendChangelog;
}

private boolean combineChangelogSinceLastSuccess;

public boolean getCombineChangelogSinceLastSuccess() {
return this.combineChangelogSinceLastSuccess;
}

/**
* Comma- or space-separated list of patterns of files/directories to be archived.
* The variable hasn't been renamed yet for compatibility reasons
Expand Down Expand Up @@ -124,20 +141,22 @@ public Boolean getDebug() {
return this.debug;
}

private TestflightTeam [] additionalTeams;
public TestflightTeam [] getAdditionalTeams() {
private TestflightTeam[] additionalTeams;

public TestflightTeam[] getAdditionalTeams() {
return this.additionalTeams;
}

@DataBoundConstructor
public TestflightRecorder(String tokenPairName, Secret apiToken, Secret teamToken, Boolean notifyTeam, String buildNotes, Boolean appendChangelog, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort, Boolean debug, TestflightTeam [] additionalTeams) {
public TestflightRecorder(String tokenPairName, Secret apiToken, Secret teamToken, Boolean notifyTeam, String buildNotesPath, String buildNotes, Boolean appendChangelog, Boolean combineChangelogSinceLastSuccess, String filePath, String dsymPath, String lists, Boolean replace, String proxyHost, String proxyUser, String proxyPass, int proxyPort, Boolean debug, TestflightTeam[] additionalTeams) {
this.tokenPairName = tokenPairName;
this.apiToken = apiToken;
this.teamToken = teamToken;
this.notifyTeam = notifyTeam;
this.buildNotes = buildNotes;
this.buildNotesPath = buildNotesPath;
this.appendChangelog = appendChangelog;
this.combineChangelogSinceLastSuccess = combineChangelogSinceLastSuccess;
this.filePath = filePath;
this.dsymPath = dsymPath;
this.replace = replace;
Expand All @@ -163,7 +182,6 @@ public BuildStepMonitor getRequiredMonitorService() {
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, final BuildListener listener) {
if (build.getResult().isWorseOrEqualTo(Result.FAILURE))
return false;

listener.getLogger().println(Messages.TestflightRecorder_InfoUploading());

try {
Expand All @@ -173,7 +191,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, final Build

List<TestflightUploader.UploadRequest> urList = new ArrayList<TestflightUploader.UploadRequest>();

for(TestflightTeam team : createDefaultPlusAdditionalTeams()) {
for (TestflightTeam team : createDefaultPlusAdditionalTeams()) {
try {
TestflightUploader.UploadRequest ur = createPartialUploadRequest(team, vars, build);
urList.add(ur);
Expand All @@ -183,11 +201,13 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, final Build
}
}

for(TestflightUploader.UploadRequest ur : urList) {
for (TestflightUploader.UploadRequest ur : urList) {
List<Entry> entries = combineChangelogSinceLastSuccess ? getChangeSetEntriesSinceLastSuccess(build) : getChangeSetEntries(build);

TestflightRemoteRecorder remoteRecorder = new TestflightRemoteRecorder(workspace, ur, listener);

final List<Map> parsedMaps;

try {
Object result = launcher.getChannel().call(remoteRecorder);
parsedMaps = (List<Map>) result;
Expand All @@ -196,12 +216,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, final Build
listener.getLogger().println(ue.getResponseBody());
return false;
}

if (parsedMaps.size() == 0) {
listener.getLogger().println(Messages.TestflightRecorder_NoUploadedFile(ur.filePaths));
return false;
}
for (Map parsedMap: parsedMaps) {
for (Map parsedMap : parsedMaps) {
addTestflightLinks(build, listener, parsedMap);
}
}
Expand All @@ -218,7 +238,7 @@ private List<TestflightTeam> createDefaultPlusAdditionalTeams() {
List<TestflightTeam> allTeams = new ArrayList<TestflightTeam>();
// first team is default
allTeams.add(new TestflightTeam(getTokenPairName(), getFilePath(), getDsymPath()));
if(additionalTeams != null) {
if (additionalTeams != null) {
allTeams.addAll(Arrays.asList(additionalTeams));
}
return allTeams;
Expand Down Expand Up @@ -257,7 +277,10 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
ur.filePaths = vars.expand(StringUtils.trim(team.getFilePath()));
ur.dsymPath = vars.expand(StringUtils.trim(team.getDsymPath()));
ur.apiToken = vars.expand(Secret.toString(tokenPair.getApiToken()));
ur.buildNotes = createBuildNotes(vars.expand(buildNotes), build.getChangeSet());
List<Entry> entries = combineChangelogSinceLastSuccess ? getChangeSetEntriesSinceLastSuccess(build) : getChangeSetEntries(build);
File buildNotesFile = getBuildNotesFile(vars, buildNotesPath);
ur.buildNotes = this.buildNotes;
ur.buildNotesPath = this.buildNotesPath;
ur.lists = vars.expand(lists);
ur.notifyTeam = notifyTeam;
ProxyConfiguration proxy = getProxy();
Expand All @@ -268,9 +291,100 @@ private TestflightUploader.UploadRequest createPartialUploadRequest(TestflightTe
ur.replace = replace;
ur.teamToken = vars.expand(Secret.toString(tokenPair.getTeamToken()));
ur.debug = debug;
ur.vars = vars;
ur.changeLog = getChangeLog(entries);
return ur;
}

private String getChangeLog(List<Entry> entries) {

String changeLog = "";
if(appendChangelog)

{
StringBuilder stringBuilder = new StringBuilder();

// Then append the changelog
stringBuilder.append("\n\n")
.append(entries.isEmpty() ? Messages.TestflightRecorder_EmptyChangeSet() : Messages.TestflightRecorder_Changelog())
.append("\n");
stringBuilder.append(changeLog);
int entryNumber = 1;

for (ChangeLogSet.Entry entry : entries) {
stringBuilder.append("\n").append(entryNumber).append(". ");
stringBuilder.append(entry.getMsg()).append(" \u2014 ").append(entry.getAuthor());

entryNumber++;
}
changeLog = stringBuilder.toString();
}
return changeLog;
}

private File getBuildNotesFile(EnvVars vars, String buildNotesPath) {
if(buildNotesPath != null && !buildNotesPath.isEmpty()) {
buildNotesPath = vars.expand(buildNotesPath);
File buildNotesFile = new File(buildNotesPath);
if(buildNotesFile.exists()) {
return buildNotesFile;
}
else {
buildNotesFile = new File(vars.expand("$WORKSPACE"), buildNotesPath);
if (buildNotesFile.exists()) {
return buildNotesFile;
}
}
}

File buildNotesFile = new File(vars.expand("$WORKSPACE"),"BUILD_NOTES");
if (buildNotesFile.exists()) {
return buildNotesFile;
}

return null;
}

private List<Entry> getChangeSetEntries(AbstractBuild<?, ?> build) {
ArrayList<Entry> entries = new ArrayList<Entry>();
ChangeLogSet<?> changeSet = build.getChangeSet();
for (Entry entry : changeSet) {
entries.add(entry);
}
return entries;
}

private List<Entry> getChangeSetEntriesSinceLastSuccess(AbstractBuild<?, ?> build) {
ArrayList<Entry> entries = new ArrayList<Entry>();

//The next build after the last successful one should either be a failure, or the current build.
//It could be in progress I guess, but we should probably just append the changelog anyway.
AbstractBuild<?, ?> lastBuild = build.getPreviousSuccessfulBuild();
if(lastBuild != null) {
lastBuild = lastBuild.getNextBuild();
}
else {
return getChangeSetEntries(build);
}

while(lastBuild != null) {

ChangeLogSet<?> changeSet = lastBuild.getChangeSet();
if(changeSet != null) {
for (Entry entry : changeSet) {
entries.add(entry);
}
}

if(lastBuild.equals(build))
break;

lastBuild = lastBuild.getNextBuild();
}

return entries;
}

private ProxyConfiguration getProxy() {
ProxyConfiguration proxy;
if (Hudson.getInstance() != null && Hudson.getInstance().proxy != null) {
Expand All @@ -285,16 +399,25 @@ private ProxyConfiguration getProxy() {
}

// Append the changelog if we should and can
private String createBuildNotes(String buildNotes, final ChangeLogSet<?> changeSet) {
private String createBuildNotes(File buildNotesFile, String buildNotes, final List<Entry> changeSet) {
if(buildNotesFile != null) {
try {
String fileContents = FileUtils.readFileToString(buildNotesFile, "UTF-8");
buildNotes = fileContents + "\n\n" + buildNotes;
} catch (FileNotFoundException e) {
//the file should have been checked if it exists, but if not, just ignore it.
} catch (IOException e) {
//ignore it
}
}


if (appendChangelog) {
StringBuilder stringBuilder = new StringBuilder();

// Show the build notes first
stringBuilder.append(buildNotes);

// Then append the changelog
stringBuilder.append("\n\n")
.append(changeSet.isEmptySet() ? Messages.TestflightRecorder_EmptyChangeSet() : Messages.TestflightRecorder_Changelog())
.append(changeSet.isEmpty() ? Messages.TestflightRecorder_EmptyChangeSet() : Messages.TestflightRecorder_Changelog())
.append("\n");

int entryNumber = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/testflight/TestflightRemoteRecorder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package testflight;

import hudson.EnvVars;
import hudson.model.BuildListener;
import hudson.remoting.Callable;
import hudson.Util;
Expand All @@ -14,10 +15,12 @@
import java.util.Iterator;
import java.util.List;

import hudson.scm.ChangeLogSet;
import org.apache.commons.lang.StringUtils;
import org.apache.tools.ant.types.FileSet;
import org.apache.commons.io.FilenameUtils;


/**
* Code for sending a build to TestFlight which can run on a master or slave.
* <p/>
Expand Down
Loading