@Override public URI toURI() { try { return f.toURI(); } catch (Exception x) { return URI.create(f.getRemote()); } } @Override public VirtualFile getParent() {
public String getNormalizedBaseDirectory() { try { return baseDirectory.toURI().normalize().getPath(); } catch (Exception e) { throw new RuntimeException(Messages.exception_normalizeDirectory(baseDirectory), e); } }
@Override public URI toURI() { try { return f.toURI(); } catch (Exception x) { return URI.create(f.getRemote()); } } @Override public VirtualFile getParent() {
/** * Returns the relative directory path between a child and it's ancestor * FilePath. For example, if ancestor = /a/b/c/d/ and child = * /a/b/c/d/e/f/g.txt this function will return /e/f. If ancestor is not * really an ancestor, "" will be returned. * * @param ancestor * @param child * @return the child's directory, relative to the ancestor's. */ private String getRelativePath(FilePath ancestor, FilePath child) { try { String ancestor_str = ancestor.toURI().toString(); String child_str = child.getParent().toURI().toString(); if (child_str.startsWith(ancestor_str)) { return child_str.replaceFirst(ancestor_str, ""); } } catch (InterruptedException e){ //TODO: perhaps log this. } catch (IOException e){ //TODO: perhaps log this. } return ""; }
private static String buildGemPath(String currentGem, FilePath global, Collection<FilePath> candidateGems) throws InterruptedException, IOException { StringBuilder path = new StringBuilder(); Collection<String> paths = new LinkedHashSet<String>(); paths.add(currentGem); for (FilePath gem : candidateGems) { File gemFile = new File(gem.toURI()); String canonicalPath = gemFile.getCanonicalPath(); if ((canonicalPath.startsWith(currentGem + "@") && gem.child("specifications").exists())) { paths.add(canonicalPath); } } if (global != null && global.child("specifications").exists()) { File globalFile = new File(global.toURI()); paths.add(globalFile.getCanonicalPath()); } for (String canonical : paths) { if (path.length() > 0) { path.append(File.pathSeparator); } path.append(canonical); } return path.toString(); }
public String getRelativeDir(final FilePath filePath, final String removePrefix) throws IOException, InterruptedException { final String normalizedPath = filePath.toURI().normalize().getPath(); String relativePath = normalizedPath.replace(getNormalizedBaseDirectory(), ""); if (Util.fixEmptyAndTrim(removePrefix) != null) { final String expanded = Util.fixEmptyAndTrim(Util.replaceMacro(removePrefix.trim(), getEnvVars())); relativePath = removePrefix(relativePath, expanded); } return relativePath; }
/** * Get a local location for the workspace data, copying it to a temp * directory if needed. * * @author Chris Lewis */ private FilePath copyToLocalWorkspace(FilePath currentWorkspace) throws InterruptedException, IOException { FilePath newSourceLocation = (new FilePath(new File(System.getProperty("java.io.tmpdir"))).createTempDir("hudson-jdepend", "")); log("Copying remote data to " + newSourceLocation.toURI()); currentWorkspace.copyRecursiveTo(newSourceLocation); log("Copy complete"); return newSourceLocation; }
public void copyFiles(final DynamicSubBuild run, final DynamicBuild parent, final String outputFiles, final BuildListener listener) throws IOException { final String baseWorkSpace; try { listener.getLogger().println("Copying files :" + outputFiles); final FilePath workspacePath = run.getWorkspace(); final FilePath targetPath = parent.getWorkspace(); if (workspacePath != null && targetPath != null) { baseWorkSpace = workspacePath.toURI().toString(); for (final FilePath file : workspacePath.list(outputFiles)) { final String dir = file.toURI().toString().replaceAll(baseWorkSpace, "").replaceAll(file.getName(), ""); final FilePath targetChildDir = targetPath.child(dir); if (!targetChildDir.exists()) { targetChildDir.mkdirs(); } file.copyTo(targetChildDir.child(file.getName())); } } } catch (final InterruptedException e) { Thread.currentThread().interrupt(); } }
@Override public Void run() throws Exception { final FilePath target = this.getContext().get(FilePath.class).child(this.step.getFile()); final TaskListener listener = this.getContext().get(TaskListener.class); final EnvVars envVars = this.getContext().get(EnvVars.class); final String bucket = this.step.getBucket(); final String path = this.step.getPath(); final boolean force = this.step.isForce(); Preconditions.checkArgument(bucket != null && !bucket.isEmpty(), "Bucket must not be null or empty"); listener.getLogger().format("Downloading s3://%s/%s to %s %n ", bucket, path, target.toURI()); if (target.exists()) { if (force) { if (target.isDirectory()) { target.deleteRecursive(); } else { target.delete(); } } else { listener.getLogger().println("Download failed due to existing target file; set force=true to overwrite target file"); throw new RuntimeException("Target exists: " + target.toURI().toString()); } } target.act(new RemoteDownloader(Execution.this.step.createS3ClientOptions(), envVars, listener, bucket, path)); listener.getLogger().println("Download complete"); return null; }
credentials.getPassword().getPlainText(), releaseRepository.getTargetRepoPrivateUri(), client.getWorkTree().toURI())); log(buildListener,"Push dry-run completed successfully");
@Override public boolean perform(AbstractBuild build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException { EnvVars env = build.getEnvironment(listener); env.overrideAll(build.getBuildVariables()); if(Computer.currentComputer() instanceof SlaveComputer) { FilePath destinationFilePath; if(isOverrideDestinationFolder() && StringUtils.isNotBlank(getDestinationFolder())) { destinationFilePath = new FilePath(new File(env.expand(getDestinationFolder()))); } else { destinationFilePath = CopyToSlaveUtils.getProjectWorkspaceOnMaster(build, listener.getLogger()); } FilePath projectWorkspaceOnSlave = build.getProject().getWorkspace(); String includes = env.expand(getIncludes()); String excludes = env.expand(getExcludes()); listener.getLogger().printf("[copy-to-slave] Copying '%s', excluding %s, from '%s' on '%s' to '%s' on the master.\n", includes, StringUtils.isBlank(excludes) ? "nothing" : '\'' + excludes + '\'', projectWorkspaceOnSlave.toURI(), Computer.currentComputer().getNode(), destinationFilePath.toURI()); projectWorkspaceOnSlave.copyRecursiveTo(includes, excludes, destinationFilePath); } else if(Computer.currentComputer() instanceof MasterComputer) { listener.getLogger().println( "[copy-to-slave] The build is taking place on the master node, no copy back to the master will take place."); } return true; }
public void notifyCommit(FilePath repo) throws Exception { j.jenkins.getDescriptorByType(SCMTrigger.DescriptorImpl.class).synchronousPolling = true; System.out.println(j.createWebClient().goTo("mercurial/notifyCommit?url=" + repo.toURI().toString(), "text/plain").getWebResponse().getContentAsString()); j.waitUntilNoActivity(); }
args.add("-f").add(workspace.getPackagesDir().toURI().toURL().toExternalForm());
public void registerHook(FilePath repo) throws Exception { assert !repo.isRemote() : "TODO not currently supported for remote repositories since the callback URL would not be accessible from the Docker container unless we do some more exotic network configuration"; FilePath hgDir = repo.child(".hg"); FilePath hook = hgDir.child("hook.py"); hook.write( "import urllib\n" + "import urllib2\n" + "\n" + "def commit(ui, repo, node, **kwargs):\n" + " data = {\n" + " 'url': '" + repo.toURI().toString() + "',\n" + " 'branch': repo[node].branch(),\n" + " 'changesetId': node,\n" + " }\n" + " req = urllib2.Request('" + j.getURL() + "mercurial/notifyCommit')\n" + " rsp = urllib2.urlopen(req, urllib.urlencode(data))\n" + " ui.warn('Notify Commit hook response: %s\\n' % rsp.read())\n" + " pass\n", null); hgDir.child("hgrc").write( "[hooks]\n" + "commit.jenkins = python:" + hook.getRemote() + ":commit", null); }
"node('" + slave.getNodeName() + "') {\n" + " dir('main') {\n" + " checkout([$class: 'MercurialSCM', source: $/" + sampleRepo.toURI() + "/$, installation: '" + inst.getName() + "'])\n" + " }\n" + " dir('other') {\n" + " checkout([$class: 'MercurialSCM', source: $/" + otherRepo.toURI() + "/$, installation: '" + inst.getName() + "', clean: true])\n" + " if (fileExists('unversioned')) {\n" + " error 'unversioned did exist'\n" + Iterator<? extends SCM> scms = p.getSCMs().iterator(); assertTrue(scms.hasNext()); assertEquals(sampleRepo.toURI().toString(), ((MercurialSCM) scms.next()).getSource()); assertTrue(scms.hasNext()); assertEquals(otherRepo.toURI().toString(), ((MercurialSCM) scms.next()).getSource()); assertFalse(scms.hasNext()); List<ChangeLogSet<? extends ChangeLogSet.Entry>> changeSets = b.getChangeSets();
r.jenkins.getDescriptorByType(MercurialInstallation.DescriptorImpl.class).setInstallations(installation); installation.forNode(r.jenkins, StreamTaskListener.fromStdout()); mp.getSourcesList().add(new BranchSource(new MercurialSCMSource(null, instName, sampleRepo.toURI().toString(), null, null, null, null, null, true))); WorkflowJob p = scheduleAndFindBranchProject(mp, "default"); r.waitUntilNoActivity();
r.jenkins.getDescriptorByType(MercurialInstallation.DescriptorImpl.class).setInstallations( new MercurialInstallation(instName, "", "hg", false, true, false, null, null)); mp.getSourcesList().add(new BranchSource(new MercurialSCMSource(null, instName, sampleRepo.toURI().toString(), null, null, null, null, null, true))); WorkflowJob p = scheduleAndFindBranchProject(mp, "default"); assertEquals(1, mp.getItems().size());