Java Code Examples for jenkins.scm.api.SCMFileSystem#of()
The following examples show how to use
jenkins.scm.api.SCMFileSystem#of() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 6 votes |
@Test public void readFileFromDir() throws Exception { assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class)); assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(), is("c0e024f89969b976da165eecaa71e09dc60c3da1")); SCMFileSystem fs = SCMFileSystem.of(source, master, revision); String expected = "Some text\n"; // In previous versions of github-api, GHContent.read() (called by contentAsString()) // would pull from the "raw" url of the GHContent instance. // Thus on windows, if somebody did not configure Git correctly, // the checkout may have "fixed" line endings that we needed to handle. // The problem with the raw url data is that it can get out of sync when from the actual content. // The GitHub API info stays sync'd and correct, so now GHContent.read() pulls from mime encoded data // in the GHContent record itself. Keeping this for reference in case it changes again. // try (InputStream inputStream = getClass().getResourceAsStream("/raw/__files/body-fu-bar.txt-b4k4I.txt")) { // if (inputStream != null) { // expected = IOUtils.toString(inputStream, StandardCharsets.US_ASCII); // } // } catch (IOException e) { // // ignore // } assertThat(fs.getRoot().child("fu/bar.txt").contentAsString(), is(expected)); }
Example 2
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 6 votes |
@Test public void resolveDirPRHead() throws Exception { assumeThat(revision, nullValue()); assertThat(prHeadRevision.isMerge(), is(false)); SCMFileSystem fs = SCMFileSystem.of(source, prHead, prHeadRevision); assertThat(fs, instanceOf(GitHubSCMFileSystem.class)); // We can't check the sha, but we can check last modified // which are different for head or merge assertThat(((GitHubSCMFileSystem)fs).lastModified(), is(1480691047000L)); assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY)); }
Example 3
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 6 votes |
@Test public void resolveDirPRMerge() throws Exception { assumeThat(revision, nullValue()); assertThat(prMergeRevision.isMerge(), is(true)); SCMFileSystem fs = SCMFileSystem.of(source, prMerge, prMergeRevision); assertThat(fs, instanceOf(GitHubSCMFileSystem.class)); // We can't check the sha, but we can check last modified // which are different for head or merge assertThat(((GitHubSCMFileSystem)fs).lastModified(), is(1480777447000L)); assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY)); }
Example 4
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test public void resolveDir() throws Exception { assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class)); assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(), is("c0e024f89969b976da165eecaa71e09dc60c3da1")); SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().child("fu").getType(), is(SCMFile.Type.DIRECTORY)); }
Example 5
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test public void listDir() throws Exception { assumeThat(revision, instanceOf(AbstractGitSCMSource.SCMRevisionImpl.class)); assumeThat(((AbstractGitSCMSource.SCMRevisionImpl) revision).getHash(), is("c0e024f89969b976da165eecaa71e09dc60c3da1")); SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().child("fu").children(), hasItem(Matchers.<SCMFile>hasProperty("name", is("manchu.txt")))); }
Example 6
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test public void resolveDirPRInvalidMerge() throws Exception { assumeThat(revision, nullValue()); assertThat(prMergeInvalidRevision.isMerge(), is(true)); SCMFileSystem fs = SCMFileSystem.of(source, prMerge, prMergeInvalidRevision); assertThat(fs, nullValue()); }
Example 7
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 5 votes |
@Test(expected = AbortException.class) public void resolveDirPRNotMergeable() throws Exception { assumeThat(revision, nullValue()); assertThat(prMergeNotMergeableRevision.isMerge(), is(true)); SCMFileSystem fs = SCMFileSystem.of(source, prMerge, prMergeNotMergeableRevision); fail(); }
Example 8
Source File: YamlFlowDefinition.java From simple-pull-request-job-plugin with Apache License 2.0 | 4 votes |
@Override public FlowExecution create(FlowExecutionOwner owner, TaskListener listener, List<? extends Action> actions) throws Exception { Queue.Executable exec = owner.getExecutable(); if (!(exec instanceof WorkflowRun)) { throw new IllegalStateException("inappropriate context"); } WorkflowRun build = (WorkflowRun) exec; WorkflowJob job = build.getParent(); BranchJobProperty property = job.getProperty(BranchJobProperty.class); Branch branch = property.getBranch(); ItemGroup<?> parent = job.getParent(); if (!(parent instanceof WorkflowMultiBranchProject)) { throw new IllegalStateException("inappropriate context"); } SCMSource scmSource = ((WorkflowMultiBranchProject) parent).getSCMSource(branch.getSourceId()); if (scmSource == null) { throw new IllegalStateException(branch.getSourceId() + " not found"); } GitConfig gitConfig = new GitConfig(); SCMHead head = branch.getHead(); if ("Pull Request".equals(head.getPronoun())) { ChangeRequestSCMHead2 changeRequestSCMHead2 = (ChangeRequestSCMHead2) branch.getHead(); head = changeRequestSCMHead2.getTarget(); } SCMRevision tip = scmSource.fetch(head, listener); if (tip == null) { throw new IllegalStateException("Cannot determine the revision."); } SCMRevision rev = scmSource.getTrustedRevision(tip, listener); GitSCM gitSCM = (GitSCM) scmSource.build(head, rev); gitConfig.setGitUrl(gitSCM.getUserRemoteConfigs().get(0).getUrl()); gitConfig.setCredentialsId(gitSCM.getUserRemoteConfigs().get(0).getCredentialsId()); gitConfig.setGitBranch(head.getName()); String script; try (SCMFileSystem fs = SCMFileSystem.of(scmSource, head, rev)) { if (fs != null) { InputStream yamlInputStream = fs.child(scriptPath).content(); listener.getLogger().println("Path of yaml/yml config file: " + fs.child(scriptPath).getPath()); YamlToPipeline y = new YamlToPipeline(); script = y.generatePipeline(yamlInputStream, gitConfig, listener); } else { throw new IOException("SCM not supported"); // FIXME implement full checkout } } listener.getLogger().println(script); return new CpsFlowExecution(script, false, owner); }
Example 9
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void rootIsADirectory() throws Exception { SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().getType(), is(SCMFile.Type.DIRECTORY)); }
Example 10
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void listFilesInRoot() throws Exception { SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().children(), hasItem(Matchers.<SCMFile>hasProperty("name", is("README.md")))); }
Example 11
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void readmeIsAFile() throws Exception { SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().child("README.md").getType(), is(SCMFile.Type.REGULAR_FILE)); }
Example 12
Source File: GitHubSCMFileSystemTest.java From github-branch-source-plugin with MIT License | 4 votes |
@Test public void readmeContents() throws Exception { SCMFileSystem fs = SCMFileSystem.of(source, master, revision); assertThat(fs.getRoot().child("README.md").contentAsString(), containsString("yolo")); }