コード例 #1
0
 @NotNull
 private static FilePath rebasePath(
     @NotNull FilePath oldBase, @NotNull FilePath newBase, @NotNull FilePath path) {
   String relativePath =
       ObjectUtils.assertNotNull(FileUtil.getRelativePath(oldBase.getPath(), path.getPath(), '/'));
   return VcsUtil.getFilePath(newBase.getPath() + "/" + relativePath, path.isDirectory());
 }
コード例 #2
0
 private Couple<String> keyForChange(final Change change) {
   final FilePath beforePath = ChangesUtil.getBeforePath(change);
   final String beforeKey = beforePath == null ? null : beforePath.getIOFile().getAbsolutePath();
   final FilePath afterPath = ChangesUtil.getAfterPath(change);
   final String afterKey = afterPath == null ? null : afterPath.getIOFile().getAbsolutePath();
   return Couple.of(beforeKey, afterKey);
 }
コード例 #3
0
ファイル: FilePathTest.java プロジェクト: fujibee/hudson
 public void testCopyTo() throws Exception {
   File tmp = File.createTempFile("testCopyTo", "");
   FilePath f = new FilePath(french, tmp.getPath());
   f.copyTo(new NullStream());
   Assert.assertTrue("target does not exist", tmp.exists());
   Assert.assertTrue("could not delete target " + tmp.getPath(), tmp.delete());
 }
コード例 #4
0
  @CalledInAwt
  public static void refreshPassedFilesAndMoveToChangelist(
      @NotNull final Project project,
      final Collection<FilePath> directlyAffected,
      final Collection<VirtualFile> indirectlyAffected,
      final Consumer<Collection<FilePath>> targetChangelistMover) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    for (FilePath filePath : directlyAffected) {
      lfs.refreshAndFindFileByIoFile(filePath.getIOFile());
    }
    if (project.isDisposed()) return;

    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (!directlyAffected.isEmpty() && targetChangelistMover != null) {
      changeListManager.invokeAfterUpdate(
          new Runnable() {
            @Override
            public void run() {
              targetChangelistMover.consume(directlyAffected);
            }
          },
          InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE,
          VcsBundle.message("change.lists.manager.move.changes.to.list"),
          new Consumer<VcsDirtyScopeManager>() {
            @Override
            public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) {
              markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected);
            }
          },
          null);
    } else {
      markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected);
    }
  }
コード例 #5
0
 public ThreeState haveChangesUnder(@NotNull VirtualFile virtualFile) {
   FilePath dir = VcsUtil.getFilePath(virtualFile);
   FilePath changeCandidate = myIdx.getAffectedPaths().ceiling(dir);
   if (changeCandidate == null) {
     return ThreeState.NO;
   }
   return FileUtil.isAncestorThreeState(dir.getPath(), changeCandidate.getPath(), false);
 }
コード例 #6
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#getOutputStream(com.continuent.tungsten.common.file.FilePath)
  */
 public FileOutputStream getOutputStream(FilePath path) throws FileIOException {
   try {
     File f = new File(path.toString());
     return (new FileOutputStream(f));
   } catch (IOException e) {
     throw new FileIOException("Unable to write data to file: file=" + path.toString(), e);
   }
 }
コード例 #7
0
 private static void screenCaptureToFile(AbstractBuild build, AndroidDeviceContext device)
     throws IOException, InterruptedException {
   FilePath screencapFile = build.getWorkspace().createTempFile("screencap", ".png");
   OutputStream screencapStream = screencapFile.write();
   FilterOutputStream replaceFilterStream = new ReplaceFilterOutputStream(screencapStream);
   device.screenshot(replaceFilterStream);
   screencapFile.copyTo(new FilePath(build.getArtifactsDir()).child("screencap.png"));
 }
コード例 #8
0
 public List<File> getAffectedPaths() {
   final SortedSet<FilePath> set = myIdx.getAffectedPaths();
   final List<File> result = new ArrayList<File>(set.size());
   for (FilePath path : set) {
     result.add(path.getIOFile());
   }
   return result;
 }
コード例 #9
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#getInputStream(com.continuent.tungsten.common.file.FilePath)
  */
 public FileInputStream getInputStream(FilePath path) throws FileIOException {
   try {
     File f = new File(path.toString());
     return new FileInputStream(f);
   } catch (IOException e) {
     throw new FileIOException("Unable to read data from file: file=" + path.toString(), e);
   }
 }
コード例 #10
0
 /** Check the location of the POM, alternate settings file, etc - any file. */
 public FormValidation doCheckFileInWorkspace(@QueryParameter String value)
     throws IOException, ServletException {
   MavenModuleSetBuild lb = getLastBuild();
   if (lb != null) {
     FilePath ws = lb.getModuleRoot();
     if (ws != null) return ws.validateRelativePath(value, true, true);
   }
   return FormValidation.ok();
 }
コード例 #11
0
 public static BeforeAfter<DiffContent> createBinaryDiffContents(
     final Project project, final Change change) throws VcsException {
   final FilePath filePath = ChangesUtil.getFilePath(change);
   try {
     return new BeforeAfter<DiffContent>(
         createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()),
         createBinaryFileContent(project, change.getAfterRevision(), filePath.getName()));
   } catch (IOException e) {
     throw new VcsException(e);
   }
 }
コード例 #12
0
 public static void refreshFiles(Project project, HashSet<FilePath> paths) {
   for (FilePath path : paths) {
     VirtualFile vFile = path.getVirtualFile();
     if (vFile != null) {
       if (vFile.isDirectory()) {
         markFileAsDirty(project, vFile);
       } else {
         vFile.refresh(true, vFile.isDirectory());
       }
     }
   }
 }
コード例 #13
0
ファイル: FilePathTest.java プロジェクト: fujibee/hudson
  /**
   * An attempt to reproduce the file descriptor leak. If this operation leaks a file descriptor,
   * 2500 should be enough, I think.
   */
  public void testCopyTo2() throws Exception {
    for (int j = 0; j < 2500; j++) {
      File tmp = File.createTempFile("testCopyTo", "");
      FilePath f = new FilePath(tmp);
      File tmp2 = File.createTempFile("testCopyTo", "");
      FilePath f2 = new FilePath(british, tmp.getPath());

      f.copyTo(f2);

      Assert.assertTrue("could not delete target " + tmp.getPath(), tmp.delete());
      Assert.assertTrue("could not delete target " + tmp2.getPath(), tmp2.delete());
    }
  }
コード例 #14
0
 private static SimpleDiffRequest createBinaryDiffRequest(
     final Project project, final Change change) throws VcsException {
   final FilePath filePath = ChangesUtil.getFilePath(change);
   final SimpleDiffRequest request = new SimpleDiffRequest(project, filePath.getPath());
   try {
     request.setContents(
         createBinaryFileContent(project, change.getBeforeRevision(), filePath.getName()),
         createBinaryFileContent(project, change.getAfterRevision(), filePath.getName()));
     return request;
   } catch (IOException e) {
     throw new VcsException(e);
   }
 }
コード例 #15
0
ファイル: Path.java プロジェクト: afmckinney/ai2-kawa
 public static Path coerceToPathOrNull(Object path) {
   if (path instanceof Path) return (Path) path;
   if (path instanceof URL) return URLPath.valueOf((URL) path);
   /* #ifdef use:java.net.URI */
   if (path instanceof URI) return URIPath.valueOf((URI) path);
   /* #endif */
   if (path instanceof File) return FilePath.valueOf((File) path);
   String str;
   if (path instanceof gnu.lists.FString) // FIXME: || UntypedAtomic
   str = path.toString();
   else if (!(path instanceof String)) return null;
   else str = (String) path;
   if (Path.uriSchemeSpecified(str)) return URIPath.valueOf(str);
   else return FilePath.valueOf(str);
 }
コード例 #16
0
 private static boolean directoryOrBinary(final Change change) {
   // todo instead for repository tab, filter directories (? ask remotely ? non leaf nodes)
   /*if ((change.getBeforeRevision() instanceof BinaryContentRevision) || (change.getAfterRevision() instanceof BinaryContentRevision)) {
     changesList.remove(i);
     continue;
   }*/
   final FilePath path = ChangesUtil.getFilePath(change);
   if (path.isDirectory()) {
     return !change.hasOtherLayers();
   }
   /*final FileType type = path.getFileType();
   if ((! FileTypes.UNKNOWN.equals(type)) && (type.isBinary())) {
     return true;
   }*/
   return false;
 }
コード例 #17
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#write(com.continuent.tungsten.common.file.FilePath,
  *     java.lang.String, java.lang.String, boolean)
  */
 @Override
 public void write(FilePath path, String value, String charset, boolean fsync)
     throws FileIOException {
   // Write the value and flush to storage. This overwrites any
   // previous version.
   FileOutputStream fos = null;
   try {
     fos = getOutputStream(path);
     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos, charset));
     bw.write(value);
     bw.flush();
     if (fsync) {
       fos.getFD().sync();
     }
   } catch (IOException e) {
     throw new FileIOException(
         "Unable to write data to file: file="
             + path.toString()
             + " value="
             + safeSynopsis(value, 20),
         e);
   } finally {
     if (fos != null) {
       try {
         fos.close();
       } catch (IOException e) {
       }
     }
   }
 }
コード例 #18
0
  protected boolean httpGetFile(String strContType) throws IOException {
    if (!isDbFilesPath(uri.getPath())
        && !isKnownExtension(uri.getPath())
        && strContType.length() == 0) {
      String strTemp = FilePath.join(uri.getPath(), "/");

      if (RhoSupport.findClass(strTemp + "controller") != null) return false;

      int nPos = findIndex(uri.getPath());
      if (nPos >= 0) {
        String url = uri.getPath(); // + (nPos == 0 ? ".iseq" : "");
        Properties reqHash = new Properties();
        this.doDispatch(reqHash, url);
        //	RubyValue res = RhoRuby.processIndexRequest(url);//erb-compiled should load from class
        // processResponse(res);

        // RhodesApp.getInstance().keepLastVisitedUrl(url_external);
        return true;
      }

      if (httpGetIndexFile()) return true;
    }

    return httpServeFile(strContType);
  }
コード例 #19
0
 /**
  * Returns true if the specified file path represents a file which exists in the VCS repository
  * (is neither unversioned nor scheduled for addition). This method is called only for directories
  * which are mapped to this VCS in the project configuration.
  *
  * @param path the path to check.
  * @return true if the corresponding file exists in the repository, false otherwise.
  */
 public boolean fileExistsInVcs(FilePath path) {
   final VirtualFile virtualFile = path.getVirtualFile();
   if (virtualFile != null) {
     final FileStatus fileStatus = FileStatusManager.getInstance(myProject).getStatus(virtualFile);
     return fileStatus != FileStatus.UNKNOWN && fileStatus != FileStatus.ADDED;
   }
   return true;
 }
コード例 #20
0
 private static void correctListForRevision(
     final ProjectLevelVcsManager plVcsManager,
     final ContentRevision revision,
     final SVNChangelistClient client,
     final String name) {
   if (revision != null) {
     final FilePath path = revision.getFile();
     final AbstractVcs vcs = plVcsManager.getVcsFor(path);
     if (vcs != null && VCS_NAME.equals(vcs.getName())) {
       try {
         client.doAddToChangelist(new File[] {path.getIOFile()}, SVNDepth.EMPTY, name, null);
       } catch (SVNException e) {
         // left in default list
       }
     }
   }
 }
コード例 #21
0
 @Override
 protected boolean approximatelyHasRoots(final VcsContext dataContext) {
   final FilePath[] paths = dataContext.getSelectedFilePaths();
   if (paths.length == 0) return false;
   final FileStatusManager fsm = FileStatusManager.getInstance(dataContext.getProject());
   for (final FilePath path : paths) {
     VirtualFile file = path.getVirtualFile();
     if (file == null) {
       continue;
     }
     FileStatus status = fsm.getStatus(file);
     if (isApplicableRoot(file, status, dataContext)) {
       return true;
     }
   }
   return false;
 }
コード例 #22
0
  /** Check that the provided file is a relative path. And check that it exists, just in case. */
  public FormValidation doCheckFileRelative(@QueryParameter String value)
      throws IOException, ServletException {
    String v = fixEmpty(value);
    if ((v == null) || (v.length() == 0)) {
      // Null values are allowed.
      return FormValidation.ok();
    }
    if ((v.startsWith("/")) || (v.startsWith("\\")) || (v.matches("^\\w\\:\\\\.*"))) {
      return FormValidation.error("Alternate settings file must be a relative path.");
    }

    MavenModuleSetBuild lb = getLastBuild();
    if (lb != null) {
      FilePath ws = lb.getWorkspace();
      if (ws != null) return ws.validateRelativePath(value, true, true);
    }
    return FormValidation.ok();
  }
コード例 #23
0
 @SneakyThrows
 public void writeFrameworkFiles(FilePath frameworkPath) {
   for (String asset : ASSETS) {
     String source = IOUtils.toString(getClass().getResourceAsStream(asset));
     String assetFileName = FilenameUtils.getName(asset);
     String destinationFilename = FilenameUtils.concat(frameworkPath.getPath(), assetFileName);
     FileUtils.write(new File(destinationFilename), source);
   }
 }
コード例 #24
0
 private String modifyCheckinActionName(final VcsContext dataContext, String checkinActionName) {
   final FilePath[] roots = getRoots(dataContext);
   if (roots == null || roots.length == 0) return checkinActionName;
   final FilePath first = roots[0];
   if (roots.length == 1) {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directory", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.file", checkinActionName);
     }
   } else {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directories", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.files", checkinActionName);
     }
   }
 }
コード例 #25
0
 @Override
 public boolean fileIsUnderVcs(FilePath path) {
   final ChangeListManager clManager = ChangeListManager.getInstance(myProject);
   final VirtualFile file = path.getVirtualFile();
   if (file == null) {
     return false;
   }
   return !SvnStatusUtil.isIgnoredInAnySense(clManager, file) && !clManager.isUnversioned(file);
 }
コード例 #26
0
 private boolean isUnderOldDir(Change change, FilePath path) {
   if (change.getBeforeRevision() != null) {
     final boolean isUnder =
         FileUtil.isAncestor(
             path.getIOFile(), change.getBeforeRevision().getFile().getIOFile(), true);
     if (isUnder) {
       return true;
     }
   }
   if (change.getAfterRevision() != null) {
     final boolean isUnder =
         FileUtil.isAncestor(
             path.getIOFile(), change.getAfterRevision().getFile().getIOFile(), true);
     if (isUnder) {
       return isUnder;
     }
   }
   return false;
 }
コード例 #27
0
  @Override
  protected LocalChangeList getInitiallySelectedChangeList(
      final VcsContext context, final Project project) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    LocalChangeList defaultChangeList = changeListManager.getDefaultChangeList();

    final FilePath[] roots = getRoots(context);
    LocalChangeList changeList = null;
    for (final FilePath root : roots) {
      final VirtualFile file = root.getVirtualFile();
      if (file == null) continue;
      Collection<LocalChangeList> lists = getChangeListsForRoot(changeListManager, root);
      if (lists.contains(defaultChangeList)) {
        return defaultChangeList;
      }
      Iterator<LocalChangeList> it = lists.iterator();
      changeList = it.hasNext() ? it.next() : null;
    }
    return changeList == null ? defaultChangeList : changeList;
  }
コード例 #28
0
ファイル: Launcher.java プロジェクト: Rafal-G/jenkins
        public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException {
            printCommandLine(cmd, _workDir);

            Pipe out = Pipe.createRemoteToLocal();
            final String workDir = _workDir==null ? null : _workDir.getRemote();

            OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides));

            return new Channel("remotely launched channel on "+channel,
                Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os));
        }
コード例 #29
0
 /**
  * {@inheritDoc}
  *
  * @see
  *     com.continuent.tungsten.common.file.FileIO#list(com.continuent.tungsten.common.file.FilePath,
  *     java.lang.String)
  */
 @Override
 public String[] list(FilePath path, String prefix) {
   // Children can only exist on directories.
   if (isDirectory(path)) {
     File dir = new File(path.toString());
     String[] seqnoFileNames = dir.list(new LocalFilenameFilter(prefix));
     return seqnoFileNames;
   } else {
     return new String[0];
   }
 }
コード例 #30
0
ファイル: Launcher.java プロジェクト: Rafal-G/jenkins
 /**
  * Prints out the command line to the listener so that users know what we are doing.
  */
 protected final void printCommandLine(String[] cmd, FilePath workDir) {
     StringBuilder buf = new StringBuilder();
     if (workDir != null) {
         buf.append('[');
         if(showFullPath)
             buf.append(workDir.getRemote());
         else
             buf.append(workDir.getRemote().replaceFirst("^.+[/\\\\]", ""));
         buf.append("] ");
     }
     buf.append('$');
     for (String c : cmd) {
         buf.append(' ');
         if(c.indexOf(' ')>=0) {
             if(c.indexOf('"')>=0)
                 buf.append('\'').append(c).append('\'');
             else
                 buf.append('"').append(c).append('"');
         } else
             buf.append(c);
     }
     listener.getLogger().println(buf.toString());
 }