Skip to content

Commit

Permalink
[FIXED JENKINS-16120] removing 'disable sync and changelog' and addin…
Browse files Browse the repository at this point in the history
…g 'disable changelog'
  • Loading branch information
Rob Petti committed May 9, 2013
1 parent 644ad88 commit 3796f06
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 104 deletions.
214 changes: 119 additions & 95 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
Expand Up @@ -130,7 +130,12 @@ public class PerforceSCM extends SCM {
* Disable Workspace pre-build automatic sync and changelog retrieval
* This should be renamed if we can implement upgrade logic to handle old configs
*/
@Deprecated
boolean disableAutoSync = false;
/**
* Disable ChangeLog retrieval
*/
boolean disableChangeLogOnly = false;
/**
* Disable Workspace syncing
*/
Expand Down Expand Up @@ -292,7 +297,7 @@ public PerforceSCM(
boolean alwaysForceSync,
boolean createWorkspace,
boolean updateView,
boolean disableAutoSync,
boolean disableChangeLogOnly,
boolean disableSyncOnly,
boolean showIntegChanges,
boolean dontUpdateClient,
Expand All @@ -306,7 +311,7 @@ public PerforceSCM(
String excludedFiles,
boolean excludedFilesCaseSensitivity) {

this.configVersion = 0L;
this.configVersion = 1L;

this.p4User = p4User;
this.setP4Passwd(p4Passwd);
Expand Down Expand Up @@ -346,7 +351,7 @@ public PerforceSCM(
this.forceSync = forceSync;
this.dontUpdateServer = dontUpdateServer;
this.alwaysForceSync = alwaysForceSync;
this.disableAutoSync = disableAutoSync;
this.disableChangeLogOnly = disableChangeLogOnly;
this.disableSyncOnly = disableSyncOnly;
this.showIntegChanges = showIntegChanges;
this.browser = browser;
Expand Down Expand Up @@ -556,6 +561,13 @@ public Object readResolve() {
if (configVersion == null) {
configVersion = 0L;
}

if (configVersion == 0L) {
this.disableSyncOnly = this.disableAutoSync;
this.disableChangeLogOnly = this.disableAutoSync;

configVersion = 1L;
}

return this;
}
Expand Down Expand Up @@ -772,10 +784,12 @@ public boolean checkout(AbstractBuild build, Launcher launcher,
"P4CLEANREPOINWORKSPACE", build, this.wipeRepoBeforeBuild);
boolean forceSync = overrideWithBooleanParameter(
"P4FORCESYNC", build, this.forceSync);
boolean disableAutoSync = overrideWithBooleanParameter(
"P4DISABLESYNC", build, this.disableAutoSync);
boolean disableChangeLogOnly = overrideWithBooleanParameter(
"P4DISABLECHANGELOG", build, this.disableAutoSync);
boolean disableSyncOnly = overrideWithBooleanParameter(
"P4DISABLESYNCONLY", build, this.disableSyncOnly);
disableSyncOnly = overrideWithBooleanParameter(
"P4DISABLESYNC", build, this.disableSyncOnly);

// If we're doing a matrix build, we should always force sync.
if ((Object)build instanceof MatrixBuild || (Object)build instanceof MatrixRun) {
Expand Down Expand Up @@ -850,74 +864,75 @@ public boolean checkout(AbstractBuild build, Launcher launcher,
projectPath = p4workspace.getTrimmedViewsAsString();
}

//Get the list of changes since the last time we looked...
String p4WorkspacePath = "//" + p4workspace.getName() + "/...";
int lastChange = getLastChange((Run)build.getPreviousBuild());
log.println("Last build changeset: " + lastChange);

// Determine changeset number
int newestChange = lastChange;

if (!disableAutoSync)
{
List<Changelist> changes;
if (p4Label != null && !p4Label.trim().isEmpty()) {
newestChange = depot.getChanges().getHighestLabelChangeNumber(p4workspace, p4Label.trim(), p4WorkspacePath);
List<Changelist> changes;
if (p4Label != null && !p4Label.trim().isEmpty()) {
newestChange = depot.getChanges().getHighestLabelChangeNumber(p4workspace, p4Label.trim(), p4WorkspacePath);
} else {
if (p4UpstreamProject != null && p4UpstreamProject.length() > 0) {
log.println("Using last successful or unstable build of upstream project " + p4UpstreamProject);
Job job = Hudson.getInstance().getItemByFullName(p4UpstreamProject, Job.class);
if (job == null) {
throw new AbortException(
"Configured upstream job does not exist anymore: " + p4UpstreamProject + ". Please update your job configuration.");
}
Run upStreamRun = job.getLastSuccessfulBuild();
int lastUpStreamChange = getLastChangeNoFirstChange(upStreamRun);
if (lastUpStreamChange > 0) {
log.println("Using P4 revision " + lastUpStreamChange + " from upstream project " + p4UpstreamProject);
newestChange = lastUpStreamChange;
} else {
log.println("No P4 revision found in upstream project " + p4UpstreamProject);
throw new AbortException(
"Configured upstream job has not been run yet: " + p4UpstreamProject + ". Please run it once befor launching a new build.");
}
} else
if (p4Counter != null && !updateCounterValue) {
//use a counter
String counterName;
counterName = substituteParameters(this.p4Counter, build);
Counter counter = depot.getCounters().getCounter(counterName);
newestChange = counter.getValue();
} else {
if (p4UpstreamProject != null && p4UpstreamProject.length() > 0) {
log.println("Using last successful or unstable build of upstream project " + p4UpstreamProject);
Job job = Hudson.getInstance().getItemByFullName(p4UpstreamProject, Job.class);
if (job == null) {
throw new AbortException(
"Configured upstream job does not exist anymore: " + p4UpstreamProject + ". Please update your job configuration.");
}
Run upStreamRun = job.getLastSuccessfulBuild();
int lastUpStreamChange = getLastChangeNoFirstChange(upStreamRun);
if (lastUpStreamChange > 0) {
log.println("Using P4 revision " + lastUpStreamChange + " from upstream project " + p4UpstreamProject);
newestChange = lastUpStreamChange;
//use the latest submitted change from workspace, or depot
try {
List<Integer> workspaceChanges = depot.getChanges().getChangeNumbers(p4WorkspacePath, 0, 1);
if (workspaceChanges != null && workspaceChanges.size() > 0) {
newestChange = workspaceChanges.get(0);
} else {
log.println("No P4 revision found in upstream project " + p4UpstreamProject);
throw new AbortException(
"Configured upstream job has not been run yet: " + p4UpstreamProject + ". Please run it once befor launching a new build.");
}
} else
if (p4Counter != null && !updateCounterValue) {
//use a counter
String counterName;
counterName = substituteParameters(this.p4Counter, build);
Counter counter = depot.getCounters().getCounter(counterName);
newestChange = counter.getValue();
} else {
//use the latest submitted change from workspace, or depot
try {
List<Integer> workspaceChanges = depot.getChanges().getChangeNumbers(p4WorkspacePath, 0, 1);
if (workspaceChanges != null && workspaceChanges.size() > 0) {
newestChange = workspaceChanges.get(0);
} else {
List<Integer> depotChanges = depot.getChanges().getChangeNumbers("//...", 0, 1);
if (depotChanges != null && depotChanges.size() > 0) {
newestChange = depotChanges.get(0);
}
List<Integer> depotChanges = depot.getChanges().getChangeNumbers("//...", 0, 1);
if (depotChanges != null && depotChanges.size() > 0) {
newestChange = depotChanges.get(0);
}
} catch (PerforceException e) {
//fall back onto 'change' counter value
log.println("Failed to get last submitted changeset in the view, falling back to change counter. Error was: " + e.getMessage());
Counter counter = depot.getCounters().getCounter("change");
newestChange = counter.getValue();
}
} catch (PerforceException e) {
//fall back onto 'change' counter value
log.println("Failed to get last submitted changeset in the view, falling back to change counter. Error was: " + e.getMessage());
Counter counter = depot.getCounters().getCounter("change");
newestChange = counter.getValue();
}
}
}

if (build instanceof MatrixRun) {
newestChange = getOrSetMatrixChangeSet(build, depot, newestChange, projectPath, log);
}
if (build instanceof MatrixRun) {
newestChange = getOrSetMatrixChangeSet(build, depot, newestChange, projectPath, log);
}

if (lastChange <= 0) {
lastChange = newestChange - MAX_CHANGESETS_ON_FIRST_BUILD;
if (lastChange < 0) {
lastChange = 0;
}
if (lastChange <= 0) {
lastChange = newestChange - MAX_CHANGESETS_ON_FIRST_BUILD;
if (lastChange < 0) {
lastChange = 0;
}
}

// Get ChangeLog
if (!disableChangeLogOnly) {
if (lastChange >= newestChange) {
changes = new ArrayList<Changelist>(0);
} else {
Expand All @@ -941,51 +956,52 @@ public boolean checkout(AbstractBuild build, Launcher launcher,
// No new changes discovered (though the definition of the workspace or label may have changed).
createEmptyChangeLog(changelogFile, listener, "changelog");
}
}

if (!disableSyncOnly) {
// Now we can actually do the sync process...
StringBuilder sbMessage = new StringBuilder("Sync'ing workspace to ");
StringBuilder sbSyncPath = new StringBuilder(p4WorkspacePath);
StringBuilder sbSyncPathSuffix = new StringBuilder();
sbSyncPathSuffix.append("@");

if (p4Label != null && !p4Label.trim().isEmpty()) {
sbMessage.append("label ");
sbMessage.append(p4Label);
sbSyncPathSuffix.append(p4Label);
} else {
sbMessage.append("changelist ");
sbMessage.append(newestChange);
sbSyncPathSuffix.append(newestChange);
}
// Sync workspace
if (!disableSyncOnly) {
// Now we can actually do the sync process...
StringBuilder sbMessage = new StringBuilder("Sync'ing workspace to ");
StringBuilder sbSyncPath = new StringBuilder(p4WorkspacePath);
StringBuilder sbSyncPathSuffix = new StringBuilder();
sbSyncPathSuffix.append("@");

sbSyncPath.append(sbSyncPathSuffix);
if (p4Label != null && !p4Label.trim().isEmpty()) {
sbMessage.append("label ");
sbMessage.append(p4Label);
sbSyncPathSuffix.append(p4Label);
} else {
sbMessage.append("changelist ");
sbMessage.append(newestChange);
sbSyncPathSuffix.append(newestChange);
}

if (forceSync || alwaysForceSync)
sbMessage.append(" (forcing sync of unchanged files).");
else
sbMessage.append(".");
sbSyncPath.append(sbSyncPathSuffix);

log.println(sbMessage.toString());
String syncPath = sbSyncPath.toString();
if (forceSync || alwaysForceSync)
sbMessage.append(" (forcing sync of unchanged files).");
else
sbMessage.append(".");

long startTime = System.currentTimeMillis();
log.println(sbMessage.toString());
String syncPath = sbSyncPath.toString();

if (useViewMaskForSyncing && useViewMask) {
for (String path : viewMask.replaceAll("\r", "").split("\n")) {
StringBuilder sbMaskPath = new StringBuilder(path);
sbMaskPath.append(sbSyncPathSuffix);
String maskPath = sbMaskPath.toString();
depot.getWorkspaces().syncTo(maskPath, forceSync || alwaysForceSync, dontUpdateServer);
}
} else {
depot.getWorkspaces().syncTo(syncPath, forceSync || alwaysForceSync, dontUpdateServer);
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
long startTime = System.currentTimeMillis();

log.println("Sync complete, took " + duration + " ms");
if (useViewMaskForSyncing && useViewMask) {
for (String path : viewMask.replaceAll("\r", "").split("\n")) {
StringBuilder sbMaskPath = new StringBuilder(path);
sbMaskPath.append(sbSyncPathSuffix);
String maskPath = sbMaskPath.toString();
depot.getWorkspaces().syncTo(maskPath, forceSync || alwaysForceSync, dontUpdateServer);
}
} else {
depot.getWorkspaces().syncTo(syncPath, forceSync || alwaysForceSync, dontUpdateServer);
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;

log.println("Sync complete, took " + duration + " ms");
}

boolean doSaveProject = false;
Expand Down Expand Up @@ -2839,6 +2855,14 @@ public void setShowIntegChanges(boolean showIntegChanges) {
this.showIntegChanges = showIntegChanges;
}

public boolean isDisableChangeLogOnly() {
return disableChangeLogOnly;
}

public void setDisableChangeLogOnly(boolean disableChangeLogOnly) {
this.disableChangeLogOnly = disableChangeLogOnly;
}

public boolean isDisableSyncOnly() {
return disableSyncOnly;
}
Expand Down
Expand Up @@ -115,8 +115,8 @@
<f:checkbox field="alwaysForceSync" value="True" id="alwaysForceSync" />
</f:entry>

<f:entry title="Disable Sync and Changelog" help="/plugin/perforce/help/disableAutoSync.html">
<f:checkbox field="disableAutoSync" value="False"/>
<f:entry title="Disable Changelog" help="/plugin/perforce/help/disableChangeLogOnly.html">
<f:checkbox field="disableChangeLogOnly" value="False"/>
</f:entry>

<f:entry title="Disable Syncing Only" help="/plugin/perforce/help/disableSyncOnly.html">
Expand Down
7 changes: 0 additions & 7 deletions src/main/webapp/help/disableAutoSync.html

This file was deleted.

7 changes: 7 additions & 0 deletions src/main/webapp/help/disableChangeLogOnly.html
@@ -0,0 +1,7 @@
<div>
<p>
<b>Disable ChangeLog Only</b>: allows you to tell this plugin to not retreive changelog information
before the build begins. This may be useful if you have a large amount of changelog information that you do not want Jenkins to store.
</p>
<p>This option can also be controlled at build time by creating a boolean parameter on the build called "P4DISABLECHANGELOG".</p>
</div>

0 comments on commit 3796f06

Please sign in to comment.