package org.jenkinsci.plugins.p4; import com.cloudbees.plugins.credentials.CredentialsScope; import com.cloudbees.plugins.credentials.SystemCredentialsProvider; import hudson.FilePath; import hudson.Launcher; import hudson.model.AbstractBuild; import hudson.model.BuildListener; import hudson.model.Cause; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.model.Result; import hudson.tasks.Builder; import org.jenkinsci.plugins.p4.client.ClientHelper; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4.populate.GraphHybridImpl; import org.jenkinsci.plugins.p4.populate.Populate; import org.jenkinsci.plugins.p4.publish.CommitImpl; import org.jenkinsci.plugins.p4.publish.Publish; import org.jenkinsci.plugins.p4.publish.PublishNotifier; import org.jenkinsci.plugins.p4.publish.ShelveImpl; import org.jenkinsci.plugins.p4.publish.SubmitImpl; import org.jenkinsci.plugins.p4.workspace.ManualWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.StaticWorkspaceImpl; import org.jenkinsci.plugins.p4.workspace.Workspace; import org.jenkinsci.plugins.p4.workspace.WorkspaceSpec; import org.jvnet.hudson.test.JenkinsRule; import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.logging.Handler; import java.util.logging.LogRecord; import static org.junit.Assert.assertEquals; abstract public class DefaultEnvironment { protected final static String R15_1 = "r15.1"; protected final static String R17_1 = "r17.1"; protected final static String R18_1 = "r18.1"; protected final static String CREDENTIAL = "id"; protected final static int HTTP_PORT = 1888; protected final static String HTTP_URL = "http://localhost:" + HTTP_PORT; protected final int LOG_LIMIT = 1000; protected P4PasswordImpl createCredentials(String user, String password, String p4port, String id) throws IOException { CredentialsScope scope = CredentialsScope.GLOBAL; P4PasswordImpl auth = new P4PasswordImpl(scope, id, "desc", p4port, null, user, "0", "0", null, password); SystemCredentialsProvider.getInstance().getCredentials().add(auth); SystemCredentialsProvider.getInstance().save(); return auth; } protected static void startHttpServer(int port) throws Exception { DummyServer server = new DummyServer(port); new Thread(server).start(); } protected String defaultClient() { String client = "test.ws"; String os = System.getProperty("os.name").toLowerCase(); if (os.contains("win")) { client = "test.win"; } return client; } protected Workspace defaultWorkspace(String name) { StaticWorkspaceImpl workspace = new StaticWorkspaceImpl("none", false, name); return workspace; } protected static final class CreateArtifact extends Builder { private final String filename; private final String content; public CreateArtifact(String filename, String content) { this.filename = filename; this.content = content; } @Override public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { build.getWorkspace().child(filename).write(content, "UTF-8"); return true; } } protected String shelveFile(JenkinsRule jenkins, String path, String content) throws Exception { ManualWorkspaceImpl workspace = createWorkspace(path); FilePath filePath = createFilePath(path, content); try (ClientHelper p4 = new ClientHelper(jenkins.getInstance(), CREDENTIAL, null, workspace)) { Publish publish = new ShelveImpl("Submit test files", false, false, false); boolean open = p4.buildChange(publish); if (open) { return p4.publishChange(publish); } } finally { filePath.delete(); } return null; } protected String submitFile(JenkinsRule jenkins, String path, String content) throws Exception { ManualWorkspaceImpl workspace = createWorkspace(path); FilePath filePath = createFilePath(path, content); try (ClientHelper p4 = new ClientHelper(jenkins.getInstance(), CREDENTIAL, null, workspace)) { Publish publish = new SubmitImpl("Submit test files", false, false, false, null); boolean open = p4.buildChange(publish); if (open) { return p4.publishChange(publish); } } finally { filePath.delete(); } return null; } private ManualWorkspaceImpl createWorkspace(String path) { String filename = path.substring(path.lastIndexOf("/") + 1, path.length()); // Create workspace String client = "submit.ws"; String stream = null; String line = "LOCAL"; String view = "\"" + path + "\"" + " //" + client + "/" + filename; WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view, null, null, null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); workspace.setExpand(new HashMap<String, String>()); File wsRoot = new File("target/submit.ws").getAbsoluteFile(); workspace.setRootPath(wsRoot.toString()); return workspace; } private FilePath createFilePath(String path, String content) throws IOException, InterruptedException { String filename = path.substring(path.lastIndexOf("/") + 1, path.length()); File wsRoot = new File("target/submit.ws").getAbsoluteFile(); File file = new File(wsRoot + File.separator + filename).getAbsoluteFile(); FilePath filePath = new FilePath(file); filePath.delete(); filePath.write(content, "UTF-8"); return filePath; } protected void commitFile(JenkinsRule jenkins, String path, String content) throws Exception { String filename = path.substring(path.lastIndexOf("/") + 1, path.length()); // Create workspace String client = "graphCommit.ws"; String stream = null; String line = "LOCAL"; String view = "\"" + path + "\"" + " //" + client + "/" + filename; WorkspaceSpec spec = new WorkspaceSpec(true, true, false, false, false, false, stream, line, view, null, "graph", null, true); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); // Populate with P4 scm Populate populate = new GraphHybridImpl(false, null, null); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); // Freestyle job FreeStyleProject project = jenkins.createFreeStyleProject(); project.setScm(scm); // Create artifact files project.getBuildersList().add(new CreateArtifact(filename, content)); // Submit artifacts CommitImpl commit = new CommitImpl("publish", true, true); commit.addFile(path); PublishNotifier publish = new PublishNotifier(CREDENTIAL, workspace, commit); project.getPublishersList().add(publish); project.save(); // Start build Cause.UserIdCause cause = new Cause.UserIdCause(); FreeStyleBuild build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } public class TestHandler extends Handler { private StringBuffer sb = new StringBuffer(); @Override public void publish(LogRecord record) { sb.append(record.getMessage()); sb.append("\n"); } @Override public void flush() { } @Override public void close() throws SecurityException { } public String getLogBuffer() { return sb.toString(); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#31 | 29848 | Sandeep Kumar |
Merge pull request #195 from jenkinsci/StreamAtChange Support StreamAtChange for ManualWorkspace. |
||
#30 | 28735 | Paul Allen |
Merge pull request #142 from skumar7322/branchIndexing JENKINS-64946 : Branch indexing occurring for every multibranch job |
||
#29 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#28 | 26616 | Paul Allen |
Upgrade P4Java to 2020.1.1989745 Includes fixes for P4IGNORE, reconcile flags and performance improvments for ExtendedFileSpec operations. Fix tests: must set stream owner and user alternative p4ignore. JENKINS-59922 JENKINS-39094 JENKINS-51192 |
||
#27 | 26143 | Paul Allen |
Update p4java 2019.1.1873579 Entended test delay for slow build machines. JENKINS-59213 JENKINS-59611 |
||
#26 | 26112 | Paul Allen |
Merge pull request #110 from p4charu/jenkinsci-master Fix for JENKINS-58639. If last build is not completely built look for last build… |
||
#25 | 25668 | Paul Allen |
Merge pull request #94 from lystor/bug-56414 JENKINS-56414: Support of Reconcile with Modtime in P4Publish |
||
#24 | 25659 | Paul Allen | Fix Windows tests for submitStreamFile | ||
#23 | 25655 | Paul Allen |
Extract the Job Environment when fetching the Jenkinsfile. Allow Parameterized builds for the Stream field when using 'Pipline Script from SCM'. JENKINS-56775 |
||
#22 | 25056 | Paul Allen |
Check for duplicate syncIDs and test polling after failed build. JENKINS-55075 |
||
#21 | 24986 | Paul Allen |
Merge pull request #87 from p4charu/jenkinsci-master Test to confirm JENKINS-54628 is fixed. |
||
#20 | 24939 | Paul Allen |
Escape unsupported XML low ascii characters with a '?'. JENKINS-52661 JENKINS-54841 |
||
#19 | 24529 | Paul Allen |
Swarm Commit Event support, refactoring and test. JENKINS-52605 (Fix doc in 'Includes' help bubble for MultiBranch) JENKINS-52066 (Improve Swarm Commit and Branch Event support) |
||
#18 | 24492 | Paul Allen |
Initial work for MultiBranch Event trigger. JENKINS-52066 (Triggered Events and not Polling per change) |
||
#17 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#16 | 24409 | Paul Allen | Added ChangeView and Client Backup support. | ||
#15 | 24403 | Paul Allen |
Support spaces in depot path for MultiBranch and DepotSource JENKINS-52604 |
||
#14 | 24233 | Paul Allen |
Merge pull request #74 from msmeeth56/master Updated tests to work against Windows, and lower spec computers. JENKINS-52145 |
||
#13 | 23943 | Paul Allen |
Poll per change for Pipeline. JENKINS-47427 |
||
#12 | 23858 | Paul Allen |
Skip probing disabled Jobs. Includes minor updates to Polling tests. JENKINS-50634 |
||
#11 | 23819 | Paul Allen | Cleanup test cases to use Credential ID. | ||
#10 | 22163 | Paul Allen |
Manual Workspace support for READONLY and PARTITIONED. Change Type to Enum. JENKINS-39753 |
||
#9 | 22128 | Paul Allen |
Helix Graph support for Jenkins. JENKINS-40354 |
||
#8 | 21936 | Paul Allen |
Refactor tests for 17.1 release. Removed pseudo web server on FreeStyleTest |
||
#7 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#6 | 21562 | Paul Allen |
Expand variables for Spec Workspace definitions. Add test to verify variable expansion for name and view. |
||
#5 | 21171 | Paul Allen |
Jenkinsfile basic test. Moved Workflow tests out of Connection test class. |
||
#4 | 21154 | Paul Allen | P4HOST support for connection. | ||
#3 | 21146 | Paul Allen | Test Case support for Windows Clients. | ||
#2 | 20985 | Paul Allen |
Minor fixes to test cases. Clean credential list between tests and use unique names for test Jobs. |
||
#1 | 20980 | Paul Allen |
Functional test upgrade. Switched to RSH pipe for Perforce connection and upgraded to 15.1 P4D binaries. Made use of ClassRule for Jenkins (faster startup) and a Rule for Perforce with separate roots (to allow for parallel test runs). |