Skip to content

Commit

Permalink
[PerforceSCM.DataBoundConstructor] - Added "proof-of-concept" impleme…
Browse files Browse the repository at this point in the history
…ntation of the bugfix.

Related issue: https://issues.jenkins-ci.org/browse/JENKINS-18583

Signed-off-by: Oleg Nenashev <nenashev@synopsys.com>
  • Loading branch information
oleg-nenashev committed Jul 4, 2013
1 parent 043a336 commit 21f91d6
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 9 deletions.
9 changes: 7 additions & 2 deletions pom.xml
Expand Up @@ -2,9 +2,9 @@
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.jvnet.hudson.plugins</groupId>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.346</version>
<version>1.480.3</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -120,6 +120,11 @@
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>multiple-scms</artifactId>
<version>0.2</version>
</dependency>
</dependencies>

<distributionManagement>
Expand Down
@@ -0,0 +1,77 @@
/*
* The MIT License
*
* Copyright 2013 Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
*
* 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.
*/
package com.synopsys.arc.jenkinsci.plugins.perforce;

import hudson.plugins.perforce.PerforceSCM;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* Provides databound-transfer of depot type parameters for PerforceSCM.
* Class is developed in order to resolve <a href="https://issues.jenkins-ci.org/browse/JENKINS-18583">JENKINS-18583 issue</a>
* @see PerforceSCMceSCM
* @author Oleg Nenashev <nenashev@synopsys.com>, Synopsys Inc.
* @since 1.4.0
*/
public class DepotType {
public static final String USE_P4STREAM_MARKER="stream";
public static final String USE_CLIENTSPEC_MARKER="file";
public static final String USE_PROJECTPATH_MARKER="map";

String value;
String p4Stream;
String clientSpec;
String projectPath;

@DataBoundConstructor
public DepotType(String value, String p4Stream, String clientSpec, String projectPath) {
this.value = value;
this.p4Stream = p4Stream;
this.clientSpec = clientSpec;
this.projectPath = projectPath;
}

public String getProjectPath() {
return projectPath;
}

public boolean useProjectPath() {
return value.equals(USE_PROJECTPATH_MARKER);
}

public String getClientSpec() {
return clientSpec;
}

public boolean useClientSpec() {
return value.equals(USE_CLIENTSPEC_MARKER);
}

public String getP4Stream() {
return p4Stream;
}

public boolean useP4Stream() {
return value.equals(USE_P4STREAM_MARKER);
}
}
17 changes: 13 additions & 4 deletions src/main/java/hudson/plugins/perforce/PerforceSCM.java
@@ -1,5 +1,6 @@
package hudson.plugins.perforce;

import com.synopsys.arc.jenkinsci.plugins.perforce.DepotType;
import com.tek42.perforce.Depot;
import com.tek42.perforce.PerforceException;
import com.tek42.perforce.model.Changelist;
Expand Down Expand Up @@ -311,7 +312,8 @@ public PerforceSCM(
PerforceRepositoryBrowser browser,
String excludedUsers,
String excludedFiles,
boolean excludedFilesCaseSensitivity) {
boolean excludedFilesCaseSensitivity,
DepotType depotType) {

this.configVersion = 1L;

Expand All @@ -338,8 +340,14 @@ public PerforceSCM(

this.p4UpstreamProject = Util.fixEmptyAndTrim(p4UpstreamProject);

this.projectPath = Util.fixEmptyAndTrim(projectPath);

// Get data from the depot type
this.p4Stream = depotType.getP4Stream();
this.clientSpec = depotType.getClientSpec();
this.projectPath = Util.fixEmptyAndTrim(depotType.getProjectPath());
this.useStreamDepot = depotType.useP4Stream();
this.useClientSpec = depotType.useClientSpec();
this.useViewMask = depotType.useProjectPath();

this.clientOwner = Util.fixEmptyAndTrim(clientOwner);

if (p4SysRoot != null) {
Expand Down Expand Up @@ -461,6 +469,7 @@ protected Depot getDepot(Launcher launcher, FilePath workspace, AbstractProject
return depot;
}


/**
* Override of SCM.buildEnvVars() in order to setup the last change we have
* sync'd to as a Hudson
Expand All @@ -470,7 +479,7 @@ protected Depot getDepot(Launcher launcher, FilePath workspace, AbstractProject
* @param env
*/
@Override
public void buildEnvVars(AbstractBuild build, Map<String, String> env) {
public void buildEnvVars(AbstractBuild<?, ?> build, Map<String, String> env) {
super.buildEnvVars(build, env);
try {
env.put("P4PORT", MacroStringHelper.substituteParameters(p4Port, build));
Expand Down
Expand Up @@ -56,10 +56,10 @@
</f:entry>
</f:radioBlock>
<f:radioBlock name="p4.depotType" title="View Map" value="map" checked="${!instance.useClientSpec and !instance.useStreamDepot}" help="/plugin/perforce/help/projectPath.html">
<f:entry>
<f:entry>
<f:textarea name="projectPath" field="projectPath" />
</f:entry>
</f:radioBlock>
</f:entry>
</f:radioBlock>
</table>
</f:entry>

Expand Down

0 comments on commit 21f91d6

Please sign in to comment.