package org.jenkinsci.plugins.p4.client; import com.cloudbees.plugins.credentials.CredentialsDescriptor; import com.perforce.p4java.Metadata; import com.perforce.p4java.client.IClient; import hudson.model.Cause; import hudson.model.Cause.UserIdCause; import hudson.model.FreeStyleBuild; import hudson.model.FreeStyleProject; import hudson.model.Result; import hudson.scm.SCMDescriptor; import hudson.util.FormValidation; import hudson.util.ListBoxModel; import org.jenkinsci.plugins.p4.DefaultEnvironment; import org.jenkinsci.plugins.p4.PerforceScm; import org.jenkinsci.plugins.p4.PerforceScm.DescriptorImpl; import org.jenkinsci.plugins.p4.SampleServerRule; import org.jenkinsci.plugins.p4.credentials.P4PasswordImpl; import org.jenkinsci.plugins.p4.populate.AutoCleanImpl; import org.jenkinsci.plugins.p4.populate.Populate; 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.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; import org.jenkinsci.plugins.workflow.job.WorkflowJob; import org.jenkinsci.plugins.workflow.job.WorkflowRun; import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.jvnet.hudson.test.JenkinsRule; import java.io.File; import java.net.InetAddress; import java.util.List; import java.util.logging.Logger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class ConnectionTest extends DefaultEnvironment { private static Logger logger = Logger.getLogger(ConnectionTest.class.getName()); private static final String P4ROOT = "tmp-ConnectionTest-p4root"; private static P4PasswordImpl auth; @ClassRule public static JenkinsRule jenkins = new JenkinsRule(); @Rule public SampleServerRule p4d = new SampleServerRule(P4ROOT, VERSION); @Before public void buildCredentials() throws Exception { auth = createCredentials("jenkins", "jenkins", p4d); } @Test public void testCheckP4d() throws Exception { int ver = p4d.getVersion(); assertTrue(ver >= 20121); } @Test public void testCredentialsList() throws Exception { FreeStyleProject project = jenkins.createFreeStyleProject("CredentialsList"); Workspace workspace = new StaticWorkspaceImpl("none", false, "test.ws"); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); SCMDescriptor<?> desc = project.getScm().getDescriptor(); assertNotNull(desc); PerforceScm.DescriptorImpl impl = (DescriptorImpl) desc; ListBoxModel list = impl.doFillCredentialItems(); assertTrue(list.size() == 1); FormValidation form = impl.doCheckCredential(CREDENTIAL); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testFreeStyleProject_buildHead() throws Exception { FreeStyleProject project = jenkins.createFreeStyleProject("BuildHead"); Workspace workspace = new StaticWorkspaceImpl("none", false, "test.ws"); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); List<String> log = build.getLog(LOG_LIMIT); assertTrue(log.contains("P4 Task: syncing files at change: 40")); CredentialsDescriptor desc = auth.getDescriptor(); assertNotNull(desc); assertEquals("Perforce Password Credential", desc.getDisplayName()); P4PasswordImpl.DescriptorImpl impl = (P4PasswordImpl.DescriptorImpl) desc; FormValidation form = impl.doTestConnection(p4d.getRshPort(), "false", null, "jenkins", "0", "0", "jenkins"); assertEquals(FormValidation.Kind.OK, form.kind); } @Test public void testPinHost_ManualWs() throws Exception { String client = "manual.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/Data/... //" + client + "/..."; WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, false, false, stream, line, view); FreeStyleProject project = jenkins.createFreeStyleProject("Manual-Head"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", true, client, spec); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); // Log in with client for next set of tests... ClientHelper p4 = new ClientHelper(auth, null, "manual.ws", "utf8"); IClient iclient = p4.getClient(); String clienthost = iclient.getHostName(); String hostname = InetAddress.getLocalHost().getHostName(); assertNotNull(clienthost); assertEquals(hostname, clienthost); } @Test public void testTPI83() throws Exception { FreeStyleProject project = jenkins.createFreeStyleProject("TPI83"); Workspace workspace = new StaticWorkspaceImpl("none", false, "test.ws"); Populate populate = new AutoCleanImpl(); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); String filename = "add_@%#$%^&().txt"; String path = build.getWorkspace() + "/" + filename; File add = new File(path); add.createNewFile(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); } @Test public void testManual_Modtime() throws Exception { String client = "modtime.ws"; String stream = null; String line = "LOCAL"; String view = "//depot/Data/... //" + client + "/..."; // The test was designed for pre 15.1 modtime checks. Since RSH requires 15.1 // the test is not required, however later assets have some use. The pre20151 // bool 'fakes' the test and allows the other checks to pass. boolean pre20151 = false; WorkspaceSpec spec = new WorkspaceSpec(false, false, false, false, !pre20151, false, stream, line, view); FreeStyleProject project = jenkins.createFreeStyleProject("Manual_Modtime"); ManualWorkspaceImpl workspace = new ManualWorkspaceImpl("none", false, client, spec); boolean isModtime = true; Populate populate = new AutoCleanImpl(true, true, isModtime, false, null, null); PerforceScm scm = new PerforceScm(CREDENTIAL, workspace, populate); project.setScm(scm); project.save(); FreeStyleBuild build; UserIdCause cause = new Cause.UserIdCause(); build = project.scheduleBuild2(0, cause).get(); assertEquals(Result.SUCCESS, build.getResult()); // Log in for next set of tests... ClientHelper p4 = new ClientHelper(auth, null, client, "utf8"); boolean mod = p4.getClient().getOptions().isModtime(); assertEquals(true, mod); // Check file exists with the correct date String ws = build.getWorkspace().getRemote(); File file = new File(ws + "/file-0.dat"); assertEquals(true, file.exists()); String ver = Metadata.getP4JVersionString(); logger.info("P4Java Version: " + ver); long epoch = file.lastModified(); assertEquals(1397049803000L, epoch); } @Test public void testWorkflow() throws Exception { String id = auth.getId(); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "demo"); job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " p4sync credential: '" + id + "', template: 'test.ws'\n" + " p4tag rawLabelDesc: 'TestLabel', rawLabelName: 'jenkins-label'\n" + " publisher = [$class: 'SubmitImpl', description: 'Submitted by Jenkins', onlyOnSuccess: false, reopen: false]\n" + " buildWorkspace = [$class: 'TemplateWorkspaceImpl', charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}', pinHost: false, templateName: 'test.ws']\n" + " p4publish credential: '" + id + "', publish: publisher, workspace: buildWorkspace" + " \n" + "}")); WorkflowRun run = jenkins.assertBuildStatusSuccess(job.scheduleBuild2(0)); jenkins.assertLogContains("P4 Task: syncing files at change", run); jenkins.assertLogContains("P4 Task: tagging build.", run); jenkins.assertLogContains("P4 Task: reconcile files to changelist.", run); } @Test public void testWorkflowEnv() throws Exception { String id = auth.getId(); WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "workflowEnv"); job.setDefinition(new CpsFlowDefinition("" + "node {\n" + " p4sync credential: '" + id + "', template: 'test.ws'\n" + " println \"P4_CHANGELIST: ${env.P4_CHANGELIST}\"\n" + "}")); WorkflowRun run = jenkins.assertBuildStatusSuccess(job.scheduleBuild2(0)); jenkins.assertLogContains("P4 Task: syncing files at change", run); jenkins.assertLogContains("P4_CHANGELIST: 40", run); } @Test public void testP4GroovyConnectAndSync() throws Exception { WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p4groovy"); job.setDefinition(new CpsFlowDefinition("" + "node() {\n" + " ws = [$class: 'StreamWorkspaceImpl', charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}', pinHost: false, streamName: '//stream/main']\n" + " p4 = p4(credential: '" + auth.getId() + "', workspace: ws)\n" + " p4.run('sync', '//...')\n" + "}")); job.save(); WorkflowRun run = job.scheduleBuild2(0).get(); jenkins.assertLogContains("p4 sync //...", run); jenkins.assertLogContains("totalFileCount 10", run); } @Test public void testP4GroovySpecEdit() throws Exception { WorkflowJob job = jenkins.jenkins.createProject(WorkflowJob.class, "p4groovy.spec"); job.setDefinition(new CpsFlowDefinition("" + "node() {\n" + " ws = [$class: 'StreamWorkspaceImpl', charset: 'none', format: 'jenkins-${NODE_NAME}-${JOB_NAME}', pinHost: false, streamName: '//stream/main']\n" + " p4 = p4(credential: '" + auth.getId() + "', workspace: ws)\n" + " clientName = p4.getClientName();\n" + " client = p4.fetch('client', clientName)\n" + " echo \"Client: ${client}\"" + " client.put('Description', 'foo')" + " p4.save('client', client)" + "}")); job.save(); WorkflowRun run = job.scheduleBuild2(0).get(); jenkins.assertLogContains("p4 client -o jenkins-master-p4groovy.spec", run); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#46 | 29812 | Sandeep Kumar |
Merge pull request #[178] from [joel-f-brown:masterp] Do not call "p4 counter " when the value is an integer as the helix core server does not allow integer counters. In isCounter() method, check for all digits early. If all digits, return false. |
||
#45 | 26673 | Paul Allen |
Code cleanup - remove calls to Deprecated methods - Deprecated classes like AbstractStepImpl, AbstractStepDescriptorImpl and AbstractSynchronousStepExecution for P4TaggingStep |
||
#44 | 24487 | Paul Allen | Perforce Connection Refactor. | ||
#43 | 23819 | Paul Allen | Cleanup test cases to use Credential ID. | ||
#42 | 22989 | Paul Allen | Include Advanced 'allhost' field in Test Connection. | ||
#41 | 21936 | Paul Allen |
Refactor tests for 17.1 release. Removed pseudo web server on FreeStyleTest |
||
#40 | 21794 | Paul Allen |
Merge pull request #39 from Dohbedoh/JENKINS-34825 Jenkins 34825 |
||
#39 | 21171 | Paul Allen |
Jenkinsfile basic test. Moved Workflow tests out of Connection test class. |
||
#38 | 21154 | Paul Allen | P4HOST support for connection. | ||
#37 | 21146 | Paul Allen | Test Case support for Windows Clients. | ||
#36 | 21133 | Paul Allen |
P4 Environment Variables for pipeline. JENKINS-37584 |
||
#35 | 20985 | Paul Allen |
Minor fixes to test cases. Clean credential list between tests and use unique names for test Jobs. |
||
#34 | 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). |
||
#33 | 20954 | Paul Allen |
Add purge -S<n> option for the Submit stage of Publish. If a value is provided it will set the purge option on all files found as part of the reconcile (ADD/EDIT). It will not remove the purge option once set. JENKINS-36112 |
||
#32 | 20873 | Paul Allen | Support Pin to a change in a counter. | ||
#31 | 20787 | Paul Allen |
Polling Fix for use with quiet period. Switched all uses of change/label to P4Revision object and implemented Comparable. The changes to build are now calculated at build time (after the quiet period) not during the polling phase. JENKINS-36883 #review-20780 |
||
#30 | 20308 | Paul Allen |
P4Groovy (experimental) Get a P4 object in groovy. Supporting basic functions: ’run’ (to run perforce commands), ‘fetch’ and ‘save’ (to access Perforce specs). |
||
#29 | 20224 | Paul Allen |
(@stuartr) Implementing View Mask Filter. JENKINS-30622 JENKINS-28225 #review-20188 @paul_allen @stuartr |
||
#28 | 19890 | Paul Allen |
Set environment before removing workspace. Verify NPE with test case. JENKINS-36422 |
||
#27 | 19881 | Paul Allen | Change label form submit button to input. | ||
#26 | 19633 | Paul Allen |
Merge pull request #25 from amuniz/JENKINS-35210 Fix for SECURITY-170 |
||
#25 | 19630 | Paul Allen |
Merge pull request #24 from Dohbedoh/JENKINS-25249 Changes to make the P4 Trigger pipeline compatible. Added some tests of the P4 trigger for both Pipeline/Non Pipeline jobs. |
||
#24 | 19324 | Paul Allen |
Added Parallel Sync. An Advanced Populate option. Must specify the PATH to the ‘p4’ executable as parallel sync is not supported by p4java. JENKINS-29228 |
||
#23 | 18160 | Paul Allen |
Update test case testFreeStyleProject_buildLabel for Jenkins 1.625.3 Find the form submit button and call a click() instead of the internal submit() method. |
||
#22 | 16815 | Paul Allen |
Enable early binding for CHARSET Expose CHARSET to AbstractTask to allow the charset to be set at the point the client workspace is set as current in ClientHelper. |
||
#21 | 16502 | Paul Allen |
Advanced Credentials option for RPC_SOCKET_SO_TIMEOUT_NICK JENKINS-31196 |
||
#20 | 15881 | Paul Allen | Updated testcase to use Template workspace as the Static workspace does not update the Root. | ||
#19 | 15394 | Paul Allen |
Workflow-DSL functionality. Tested workflow DSL against 1.596.1 older functionality tested against 1.580.1 @sven_erik_knop |
||
#18 | 15293 | Paul Allen |
Add retry attempts to Perforce Tasks. If a task fails due to an exception then the task will retry based on the value specified in the connection Credential. |
||
#17 | 12977 | Paul Allen | Quiet option for Populate. | ||
#16 | 12953 | Paul Allen |
Update logging to support expand/collapse divs. - Additional Publish logging |
||
#15 | 11566 | Paul Allen | False positive from using incorrect client. | ||
#14 | 11564 | Paul Allen | Enable 'pin hostname' option in test. | ||
#13 | 11563 | Paul Allen | Changed hostname test to use Manual workspace. | ||
#12 | 11472 | Paul Allen |
Pin the Workspace to the build host. Added a check box under the Workspace configuration to allow Jenkins to Pin the workspace, by setting the Host field. The hostname is resolved from the Computer object or InetAddress. |
||
#11 | 11335 | Paul Allen | Remote slave support for Polling. | ||
#10 | 11334 | Paul Allen |
Remote slave support for Publish Perforce Publish commands need to be executed from the remote slave. - Includes refactoring into task package |
||
#9 | 10841 | Paul Allen |
Support for 2014.1 reconcile by MODTIME Feature allows a user check the option ‘Sync with MODTIME for consistency check’ under the ‘Populate’ option to enable reconcile to check files based on MODTIME. Includes test case for MODTIME and minor fix for fetching a Label when there is no previous change. JENKINS-25341 |
||
#8 | 10802 | Paul Allen |
Test cases for SCM Polling Added test case for Polling with Limits (pinning) and Incremental. |
||
#7 | 10775 | Paul Allen |
Fix change detection when using a moving label If a build was pinned or built from a label, the label name was recorded <buildChange>. If the label is updated between builds then comparing against an earlier build will give you the wrong result. This fix stores the automatic label ‘Revision’ field and stores this in <buildChange>. NOTE: you will need to run a manual build to flush the label, so that the last build has a change number. JENKINS-25300 |
||
#6 | 10755 | Paul Allen |
Separate name space for 'label' parameter. Perforce Review endpoint added `label`, `change`, `status`, `pass`, and `fail` parameter into the environment, which is a shared name space. This clashed with the default `label` matrix name and causing users issues. The change prefixes the review parameters with `p4.` on addition to the environment. |
||
#5 | 10013 | Paul Allen |
Added Client support to sync check https://issues.jenkins-ci.org/browse/JENKINS-24055 |
||
#4 | 9980 | Paul Allen |
Changed error reporting to use AbortException. - Use direct access of scm attributes, not via build.getProject().getScm() - Improved logging around labels/changes. |
||
#3 | 9851 | Paul Allen | Merging using p4-jenkins | ||
#2 | 9803 | Paul Allen | Merging using p4-jenkins | ||
#1 | 9690 | Paul Allen |
[Branching using p4-jenkins] Release 1.0.1 |
||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4/client/ConnectionTest.java | |||||
#2 | 9683 | Paul Allen | Added P4D for win/mac/linux, so tests are ready to run. | ||
#1 | 9672 | Paul Allen | Refactor name from 'p4_client' to 'p4'. | ||
//guest/paul_allen/dev/p4-jenkins/p4-client/src/test/java/org/jenkinsci/plugins/p4_client/client/ConnectionTest.java | |||||
#20 | 9472 | Paul Allen |
Added support to pin build at a label in the populate configuration. - includes help and updates to tests. |
||
#19 | 9137 | Paul Allen | Functional tests for tabBuild endpoint (submitting Labels) and browser (P4Web/Swarm) dummy http server checks. | ||
#18 | 9115 | Paul Allen |
Initial implementation of workspace Cleanup and Sync options. - Includes 3 modes: Automatic Clean/Sync, Force Clean/Sync, Sync Only Automatic Clean/Sync Uses reconcile to clean up workspace and sync changes. Force Clean/Sync Force sync of all files (does not remove files yet...) Sync Only Normal sync with no cleanup TODO: - remove of files in Force Clean/Sync mode - Inline help - Update docs - Add unit/functional tests |
||
#17 | 9091 | Paul Allen |
Added Changelist build filtering for SCM polling: - Configuration uses 'repeatableHeteroProperty' - Filter on Perforce username - Filter on Perforce Depot path (no wildcard support) |
||
#16 | 9055 | Paul Allen |
Label support. Build at a label using the pram 'label'. This includes adding the label to the ChangeEntry, building the change reports and Browser links to Swarm. (TPI-102) |
||
#15 | 8969 | Paul Allen |
Adds all contributing change-lists for the build to the change log (using p4 cstat). - Includes exception logging for server connection to the Jenkins console. |
||
#14 | 8940 | Paul Allen |
Major refactor for the ConnectionHelper class to simplify serialisation. Fixed remote Jenkins JNLP slave connection issue. ClientHelper now extends ConnectionHelper and takes on all methods that require a client workspace. P4StandardCredentials is sent to the remote node instead of Credentials ID due to an issue accessing the Credentials store over a remote connection. For simplicity Client ID (workspace name) is serialised instead of the Workspace object. |
||
#13 | 8926 | Paul Allen |
Bug fix when unshelving files with the Template workspace option. p4-java was unable to switch the worksapce view (without the -f flag) if there were files open. - Improved logging (as this error was hidden) - Added test case for this condition. |
||
#12 | 8922 | Paul Allen | Repo Browser unit tests | ||
#11 | 8916 | Paul Allen | Unit tests for ChangeLog feature and minor fix when listing files if the change is Submitted or Shelved. | ||
#10 | 8915 | Paul Allen |
Support for ChangeLog and RepoBrowser. - Added RepoBrowser for Swarm (porting the others should be easy) - ChangeLog XML file now only stores the changelist number all other information is fetched from Perforce |
||
#9 | 8909 | Paul Allen |
[TPI-83] Clean Workspace that may contain files with wildcards. Added (-f) flag to reconcile and ignore warnings for empty files. |
||
#8 | 8908 | Paul Allen |
Test Workspace Spec used for Manual Workspace configuration. (Total coverage ~80%) |
||
#7 | 8902 | Paul Allen |
Updated test cases: Pushed Workspace 'charset' to abstract Workspace class. Minor bugfixes in Workspace AutoCompletionCandidates method. |
||
#6 | 8898 | Paul Allen | Removed Deprecated 'HudsonTestCase' for Jenkins @Rule | ||
#5 | 8888 | Paul Allen |
Extended test coverage for Workspace and Credentials. - Removed ununsed methods. |
||
#4 | 8865 | Paul Allen | System tests for Workspace behaviours (Static, Manual, Template, Stream). | ||
#3 | 8852 | Paul Allen |
Functional test for unshelve. Includes fix for reconcile and unshelve exclusive locked files. |
||
#2 | 8816 | Paul Allen | Functional tests for build @HEAD and @change; includes build console log check. | ||
#1 | 8815 | Paul Allen | P4D test harness. |