/** * To be kept in sync with {@link FileVF#computeRelativePathToRoot()} */ private String computeRelativePathToRoot(){ if (this.root.equals(this.f)) { return ""; } LinkedList<String> relativePath = new LinkedList<>(); FilePath current = this.f; while (current != null && !current.equals(this.root)) { relativePath.addFirst(current.getName()); current = current.getParent(); } return String.join(File.separator, relativePath) + File.separator; } }
private boolean isSubDirectory(FilePath parent, FilePath child) { FilePath parentFolder = child; while (parentFolder!=null) { if (parent.equals(parentFolder)) { return true; } parentFolder = parentFolder.getParent(); } return false; }
private List<FilePath> getPossibleWrapperLocations(AbstractBuild<?, ?> build, Launcher launcher, VariableResolver<String> resolver, FilePath normalizedRootBuildScriptDir) throws IOException, InterruptedException { FilePath moduleRoot = build.getModuleRoot(); if (wrapperLocation != null && wrapperLocation.trim().length() != 0) { // Override with provided relative path to gradlew String wrapperLocationNormalized = wrapperLocation.trim().replaceAll("[\t\r\n]+", ""); wrapperLocationNormalized = Util.replaceMacro(wrapperLocationNormalized.trim(), resolver); return ImmutableList.of(new FilePath(moduleRoot, wrapperLocationNormalized)); } else if (buildFile != null && !buildFile.isEmpty()) { // Check if the target project is located not at the root dir FilePath parentOfBuildFile = new FilePath(normalizedRootBuildScriptDir == null ? moduleRoot : normalizedRootBuildScriptDir, buildFile).getParent(); if (parentOfBuildFile != null && !parentOfBuildFile.equals(moduleRoot)) { return ImmutableList.of(parentOfBuildFile, moduleRoot); } } return ImmutableList.of(moduleRoot); }
@Override public Boolean invoke(File parent, VirtualChannel channel) throws IOException, InterruptedException { if (potentialChild.isRemote()) { //Not on the same machine so can't be a child of the local file return false; } FilePath test = potentialChild.getParent(); FilePath target = new FilePath(parent); while(test != null && !target.equals(test)) { test = test.getParent(); } return target.equals(test); } }
if (lastBuildOnNode != null && nodeRootPath.equals(lastBuildOnNode.getRootPath())) { result.add(0, node); } else {
@SuppressFBWarnings(value="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", justification="TODO 1.653+ switch to Jenkins.getInstanceOrNull") @Override protected WorkspaceList.Lease tryResolve() throws InterruptedException { Jenkins j = Jenkins.getInstance(); if (j == null) { return null; } // FilePathUtils.find not useful here since we need c anyway, and cannot easily return a tuple // (could call toComputer on result but then we iterate computers twice, a possible race condition) Computer c = j.getComputer(slave); if (c == null) { return null; } VirtualChannel ch = c.getChannel(); if (ch == null) { return null; } FilePath fp = new FilePath(ch, path); // Since there is no equivalent to Lock.tryLock for WorkspaceList (.record would work but throws AssertionError and swaps the holder): WorkspaceList.Lease lease = c.getWorkspaceList().allocate(fp); if (lease.path.equals(fp)) { return lease; } else { // @2 or other variant, not what we expected to be able to lock without contention lease.release(); throw new IllegalStateException("JENKINS-37121: something already locked " + fp); } } @Override public String toString() {