package org.jenkinsci.plugins.p4_client.workspace; import hudson.Extension; import hudson.model.AutoCompletionCandidates; import hudson.util.FormValidation; import java.util.logging.Logger; import net.sf.json.JSONObject; import org.jenkinsci.plugins.p4_client.client.ConnectionFactory; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.bind.JavaScriptMethod; import com.perforce.p4java.client.IClient; import com.perforce.p4java.client.IClientSummary.ClientLineEnd; import com.perforce.p4java.client.IClientViewMapping; import com.perforce.p4java.impl.generic.client.ClientOptions; import com.perforce.p4java.impl.generic.client.ClientView; import com.perforce.p4java.impl.generic.client.ClientView.ClientViewMapping; import com.perforce.p4java.impl.mapbased.client.Client; import com.perforce.p4java.server.IOptionsServer; public class ManualWorkspaceImpl extends Workspace { private final String name; public WorkspaceSpec spec; private static Logger logger = Logger.getLogger(ManualWorkspaceImpl.class .getName()); @Override public String getName() { return name; } public WorkspaceSpec getSpec() { return spec; } @Override public WorkspaceType getType() { return WorkspaceType.MANUAL; } @DataBoundConstructor public ManualWorkspaceImpl(String charset, String name, WorkspaceSpec spec) { super(charset); this.name = name; this.spec = spec; } @Override public IClient setClient(IOptionsServer connection, String user) throws Exception { IClient iclient = connection.getClient(getName()); if (iclient == null) { logger.info("... Creating manual client: " + getName()); Client implClient = new Client(); implClient.setName(getName()); connection.createClient(implClient); iclient = connection.getClient(getName()); } iclient.setOwnerName(user); ClientOptions options = new ClientOptions(); options.setAllWrite(getSpec().allwrite); options.setClobber(getSpec().clobber); options.setCompress(getSpec().compress); options.setLocked(getSpec().locked); options.setModtime(getSpec().modtime); options.setRmdir(getSpec().rmdir); iclient.setOptions(options); iclient.setStream(getSpec().getStream()); iclient.setLineEnd(parseLineEnd(getSpec().getLine())); ClientView clientView = new ClientView(); int order = 0; for (String line : getSpec().getView().split("\\n")) { ClientViewMapping entry = new ClientViewMapping(order, line); order++; clientView.addEntry(entry); } iclient.setClientView(clientView); return iclient; } private ClientLineEnd parseLineEnd(String line) { for (ClientLineEnd end : ClientLineEnd.values()) { end.name().equalsIgnoreCase(line); return end; } return ClientLineEnd.LOCAL; } @Extension public static final class DescriptorImpl extends WorkspaceDescriptor { @Override public String getDisplayName() { return "Manual (custom view)"; } /** * Provides auto-completion for workspace names. Stapler finds this * method via the naming convention. * * @param value * The text that the user entered. */ public AutoCompletionCandidates doAutoCompleteName( @QueryParameter String value) { return autoCompleteName(value); } public FormValidation doCheckName(@QueryParameter String value) { return checkClientName(value); } } @JavaScriptMethod public JSONObject getSpecJSON(String client) { try { IOptionsServer p4 = ConnectionFactory.getConnection(); IClient c = p4.getClient(client); StringBuffer sb = new StringBuffer(); for (IClientViewMapping view : c.getClientView()) { sb.append(view.toString(" ", true)); sb.append("\n"); } JSONObject option = new JSONObject(); option.put("allwrite", c.getOptions().isAllWrite()); option.put("clobber", c.getOptions().isClobber()); option.put("compress", c.getOptions().isCompress()); option.put("locked", c.getOptions().isLocked()); option.put("modtime", c.getOptions().isModtime()); option.put("rmdir", c.getOptions().isRmdir()); JSONObject spec = new JSONObject(); spec.put("stream", (c.getStream() == null) ? "" : c.getStream()); spec.put("line", c.getLineEnd().name()); spec.put("view", sb.toString()); spec.put("options", option); return spec; } catch (Exception e) { JSONObject option = new JSONObject(); option.put("allwrite", false); option.put("clobber", true); option.put("compress", false); option.put("locked", false); option.put("modtime", false); option.put("rmdir", false); JSONObject spec = new JSONObject(); spec.put("stream", ""); spec.put("line", "LOCAL"); spec.put("view", "please define view..."); spec.put("options", option); return spec; } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 9554 | gronk | mege in Paul's changes | ||
#1 | 8783 | gronk | Populate //guest/gronk/p4-jenkins/.... | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/main/java/org/jenkinsci/plugins/p4_client/workspace/ManualWorkspaceImpl.java | |||||
#6 | 8771 | Paul Allen |
Perforce Server 12.1 min check for: Build configuration and password/ticket credentials. Includes: - Added logging for Perforce connections (fine) and set connection pool to 2. - Add 'none' to empty charset list (connection bug?) - Supress P4Java errors for syncing ubinary, xtext, unicode |
||
#5 | 8769 | Paul Allen | Update to charset option for workspaces to use a drop-down select with a default of 'none'. | ||
#4 | 8756 | Paul Allen | Added Stream field to Manual Workspace config. | ||
#3 | 8755 | Paul Allen | JavaScript automation for populating Client workspace spec in Manual mode. | ||
#2 | 8749 | Paul Allen |
Split off Worksapce Spec from Manual Workspace configuration into a Property Jelly item. Plan to autoload values based on selected client. |
||
#1 | 8697 | Paul Allen |
Added Manual workspace option for user to define Options/LineEnd/View etc... in Jenkins. |