Skip to content
Permalink
Browse files

[FIXED JENKINS-9819] adding option for sync -p

  • Loading branch information...
Rob Petti
Rob Petti committed Jun 14, 2011
1 parent 2835992 commit acbfdde98af552f49ba40eaa2984444397a7ad0d
@@ -30,6 +30,7 @@
import com.tek42.perforce.Depot;
import com.tek42.perforce.PerforceException;
import com.tek42.perforce.model.Workspace;
import java.util.ArrayList;

/**
* Base API object for interacting with workspaces.
@@ -95,7 +96,7 @@ public StringBuilder syncToHead(String path, boolean forceSync) throws PerforceE
if(!path.endsWith("#head")) {
path += "#head";
}
return syncTo(path, forceSync);
return syncTo(path, forceSync, false);
}

/**
@@ -112,7 +113,7 @@ public StringBuilder syncToHead(String path, boolean forceSync) throws PerforceE
* A StringBuilder that contains the output of the p4 execution.
* @throws PerforceException
*/
public StringBuilder syncTo(String path, boolean forceSync) throws PerforceException {
public StringBuilder syncTo(String path, boolean forceSync, boolean populateOnly) throws PerforceException {
//Error handling and output filtering
final StringBuilder errors = new StringBuilder();
ResponseFilter filter = new ResponseFilter(){
@@ -139,26 +140,25 @@ public boolean accept(String line) {
};
//remove all quotes from the path, because perforce doesn't like extra ones very much.
path = path.replaceAll("\"", "");
if(forceSync){
StringBuilder response = getPerforceResponse(new String[] { getP4Exe(), "-s", "sync", "-f", path }, filter);
if(hitMax(response)){
throw new PerforceException("Hit perforce server limit while force syncing: " + response);
}
if(errors.length()>0){
throw new PerforceException("Errors encountered while force syncing: \n" + errors.toString());
}
return response;
ArrayList<String> cmdLineList = new ArrayList<String>();
cmdLineList.add(getP4Exe());
cmdLineList.add("-s");
cmdLineList.add("sync");
if(forceSync)
cmdLineList.add("-f");
if(populateOnly)
cmdLineList.add("-p");
cmdLineList.add(path);
String[] cmdLine = cmdLineList.toArray(new String[cmdLineList.size()]);

StringBuilder response = getPerforceResponse(cmdLine, filter);
if(hitMax(response)){
throw new PerforceException("Hit perforce server limit while " + (forceSync?"force ":"") + "syncing: \n" + response);
}
else {
StringBuilder response = getPerforceResponse(new String[] { getP4Exe(), "-s", "sync", path }, filter);
if(hitMax(response)){
throw new PerforceException("Hit perforce server limit while syncing: \n" + response);
}
if(errors.length()>0){
throw new PerforceException("Errors encountered while syncing: " + errors.toString());
}
return response;
if(errors.length()>0){
throw new PerforceException("Errors encountered while " + (forceSync?"force ":"") + "syncing: " + errors.toString());
}
return response;
}

public StringBuilder flushTo(String path) throws PerforceException {
@@ -108,6 +108,10 @@
* Always force sync the workspace when running a build
*/
boolean alwaysForceSync = false;
/**
* Don't update the 'have' database on the server when syncing.
*/
boolean dontUpdateServer = false;
/**
* Disable Workspace pre-build automatic sync and changelog retrieval
* This should be renamed if we can implement upgrade logic to handle old configs
@@ -240,6 +244,7 @@ public PerforceSCM(
String p4CommandCharset,
boolean updateCounterValue,
boolean forceSync,
boolean dontUpdateServer,
boolean alwaysForceSync,
boolean updateView,
boolean disableAutoSync,
@@ -325,6 +330,7 @@ public PerforceSCM(

this.lineEndValue = lineEndValue;
this.forceSync = forceSync;
this.dontUpdateServer = dontUpdateServer;
this.alwaysForceSync = alwaysForceSync;
this.disableAutoSync = disableAutoSync;
this.disableSyncOnly = disableSyncOnly;
@@ -669,10 +675,10 @@ public boolean checkout(AbstractBuild build, Launcher launcher,
StringBuilder sbMaskPath = new StringBuilder(path);
sbMaskPath.append(sbSyncPathSuffix);
String maskPath = sbMaskPath.toString();
depot.getWorkspaces().syncTo(maskPath, forceSync || alwaysForceSync);
depot.getWorkspaces().syncTo(maskPath, forceSync || alwaysForceSync, dontUpdateServer);
}
} else {
depot.getWorkspaces().syncTo(syncPath, forceSync || alwaysForceSync);
depot.getWorkspaces().syncTo(syncPath, forceSync || alwaysForceSync, dontUpdateServer);
}
long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
@@ -2137,6 +2143,14 @@ public void setPollOnlyOnMaster(boolean pollOnlyOnMaster) {
this.pollOnlyOnMaster = pollOnlyOnMaster;
}

public boolean isDontUpdateServer() {
return dontUpdateServer;
}

public void setDontUpdateServer(boolean dontUpdateServer) {
this.dontUpdateServer = dontUpdateServer;
}

public List<String> getAllLineEndChoices(){
List<String> allChoices = ((PerforceSCMDescriptor)this.getDescriptor()).getAllLineEndChoices();
ArrayList<String> choices = new ArrayList<String>();
@@ -112,7 +112,9 @@
<f:entry title="Don't update client workspace" help="/plugin/perforce/help/dontUpdateClient.html">
<f:checkbox field="dontUpdateClient" default="false" />
</f:entry>

<f:entry title="Don't update server database on sync (-p)" help="/plugin/perforce/help/dontUpdateServer.html">
<f:checkbox field="dontUpdateServer" default="false" />
</f:entry>
<f:entry title="Client name format for slaves" help="/plugin/perforce/help/clientNameFormat.html">
<f:textbox field="slaveClientNameFormat"/>
</f:entry>
@@ -0,0 +1,12 @@
<div>
<p>
If you do not want the plugin to update the server side 'have' database, check this box.
</p>
<p>
Typically Perforce keeps track of which files each client has synced down. This isn't always required, and in some cases may prevent the plugin from syncing at all (such as read-only/replicated servers). Enabling this option is equivalent to adding the '-p' flag to the sync command.
</p>
<p>From the Perforce documentation: <i>Populate a client workspace, but do not update the have list. Any file that is already synced or opened is bypassed with a warning message.
This option is typically used for workspaces used in processes (such as certain build or publication environments) where there is no need to track the state of the workspace after it has first been synced.</i>
See the rest of the doc here: <a href="http://www.perforce.com/perforce/doc.current/manuals/cmdref/sync.html">here</a>.
</p>
</div>
@@ -21,7 +21,7 @@ public void testConfigRoundtrip() throws Exception {
P4Web browser = new P4Web(new URL("http://localhost/"));
PerforceSCM scm = new PerforceSCM(
"user", "pass", "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, true, false,
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

@@ -42,7 +42,7 @@ public void testConfigPasswordEnctyptionAndDecription() throws Exception {
String password = "pass";
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, true, false,
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

@@ -66,7 +66,7 @@ public void testDepotContainsUnencryptedPassword() throws Exception {
String password = "pass";
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, true, false,
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");

project.setScm(scm);
@@ -80,7 +80,7 @@ public void testConfigSaveReloadAndSaveDoesNotDoubleEncryptThePassword() throws
String password = "pass";
PerforceSCM scm = new PerforceSCM(
"user", password, "client", "port", "path", "", "exe", "sysRoot",
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, false,
"sysDrive", "label", "counter", "shared", "charset", "charset2", false, true, true, true, true, false,
false, true, false, false, false, false, "${basename}", 0, browser, "exclude_user", "exclude_file");
project.setScm(scm);

0 comments on commit acbfdde

Please sign in to comment.
You can’t perform that action at this time.