hudson.FilePath.lastModified()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中hudson.FilePath.lastModified()方法的一些代码示例,展示了FilePath.lastModified()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FilePath.lastModified()方法的具体详情如下:
包路径:hudson.FilePath
类名称:FilePath
方法名:lastModified

FilePath.lastModified介绍

[英]Gets the last modified time stamp of this file, by using the clock of the machine where this file actually resides.
[中]使用此文件实际驻留的计算机的时钟获取此文件上次修改的时间戳。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override public long lastModified() throws IOException {
  try {
    return f.lastModified();
  } catch (InterruptedException x) {
    throw new IOException(x);
  }
}
@Override public boolean canRead() throws IOException {

代码示例来源:origin: jenkinsci/jenkins

if(dir.lastModified() + retainForDays * DAY > now) {
  LOGGER.log(Level.FINE, "Directory {0} is only {1} old, so not deleting", new Object[] {dir, Util.getTimeSpanString(now-dir.lastModified())});
  return false;

代码示例来源:origin: jenkinsci/jenkins

private boolean installIfNecessaryFrom(@Nonnull URL archive, @CheckForNull TaskListener listener, @Nonnull String message, int maxRedirects) throws InterruptedException, IOException {
  try {
    FilePath timestamp = this.child(".timestamp");
    long lastModified = timestamp.lastModified();
    URLConnection con;
    try {

代码示例来源:origin: jenkinsci/jenkins

/**
 * Copies this file to the specified target, with file permissions and other meta attributes intact.
 * @since 1.311
 */
public void copyToWithPermission(FilePath target) throws IOException, InterruptedException {
  // Use NIO copy with StandardCopyOption.COPY_ATTRIBUTES when copying on the same machine.
  if (this.channel == target.channel) {
    act(new CopyToWithPermission(target));
    return;
  }
  copyTo(target);
  // copy file permission
  target.chmod(mode());
  target.setLastModifiedIfPossible(lastModified());
}
private class CopyToWithPermission extends SecureFileCallable<Void> {

代码示例来源:origin: jenkinsci/selenium-plugin

public SeleniumCallable(FilePath seleniumJar, FilePath htmlUnitDriverJar, String nodehost, String masterName, int masterPort, String nodeName, TaskListener listener,
    String confName, SeleniumRunOptions options) throws InterruptedException, IOException {
  this.seleniumJar = seleniumJar;
  seleniumJarTimestamp = seleniumJar.lastModified();
  this.htmlUnitDriverJar = htmlUnitDriverJar;
  htmlUnitDriverJarTimestamp = htmlUnitDriverJar.lastModified();
  this.nodeName = nodeName;
  this.options = options;
  this.listener = listener;
  config = confName;
  defaultArgs = new String[] {
      ROLE_PARAM, ROLE_NODE_VALUE,
      HUB_PARAM, "http://" + masterName + ":" + masterPort + "/wd/hub" };
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override public long lastModified() throws IOException {
  try {
    return f.lastModified();
  } catch (InterruptedException x) {
    throw (IOException) new IOException(x.toString()).initCause(x);
  }
}
@Override public boolean canRead() throws IOException {

代码示例来源:origin: jenkinsci/nodejs-plugin

public static boolean areNpmPackagesUpToDate(FilePath expected, String npmPackages, long npmPackagesRefreshHours) throws IOException, InterruptedException {
  FilePath marker = expected.child(NPM_PACKAGES_RECORD_FILENAME);
  return marker.exists() && marker.readToString().equals(npmPackages) && System.currentTimeMillis() < marker.lastModified()+ TimeUnit.HOURS.toMillis(npmPackagesRefreshHours);
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

protected FileWrapper(@Nonnull FilePath base, @Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(),
    file.getRemote().substring(base.getRemote().length() + 1),
    file.isDirectory(),
    file.length(),
    file.lastModified()
  );
}

代码示例来源:origin: org.jenkins-ci.plugins/pipeline-utility-steps

protected FileWrapper(@Nonnull FilePath base, @Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(),
      file.getRemote().substring(base.getRemote().length() + 1),
      file.isDirectory(),
      file.length(),
      file.lastModified());
}

代码示例来源:origin: jenkinsci/pipeline-utility-steps-plugin

protected FileWrapper(@Nonnull FilePath base, @Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(),
      file.getRemote().substring(base.getRemote().length() + 1),
      file.isDirectory(),
      file.length(),
      file.lastModified());
}

代码示例来源:origin: org.jenkins-ci.plugins/ivy

/**
 * Will only copy the file from the repository if its last modified time
 * exceeds what the instance thinks is the last recorded modified time of
 * the localFile, which is the local backup ivy file copy.  For this
 * to operate properly for remoting circumstances, the master and slave instances
 * must be reasonably time synchronized.
 * 
 * @param workspace Workspace root Directory
 * @param localFile The local file to be copied to
 * @return  true iff the file was actually copied
 * @throws IOException   If unable to access/copy the workspace ivy file
 * @throws InterruptedException  If interrupted while accessing the workspace ivy file
 */
private boolean copyFileFromWorkspaceIfNecessary(FilePath workspace, String fileToCopy, File localFile, String localDestFile) throws IOException, InterruptedException {
  boolean copied = false;
  if (workspace != null) { // Unless the workspace is non-null we can not copy a new ivy file
    FilePath f = workspace.child(fileToCopy);
    // Copy the ivy file from the workspace (possibly at a slave) to the projects dir (at Master)
    FilePath backupCopy = new FilePath(localFile).child(localDestFile);
    long flastModified = f.lastModified();
    if (flastModified == 0l) throw new FileNotFoundException("Can't stat file " + f);
    if (flastModified > lastmodified) {
      f.copyTo(backupCopy);
      localFile.setLastModified(flastModified);
      copied = true;
      LOGGER.info("Copied the workspace file "+fileToCopy+" to backup "+localFile.getCanonicalFile().toString()+"/"+localDestFile);
    }
  }
  return copied;
}

代码示例来源:origin: org.jvnet.hudson.plugins/ivy

/**
 * Will only copy the file from the repository if its last modified time
 * exceeds what the instance thinks is the last recorded modified time of
 * the localFile, which is the local backup ivy file copy.  For this
 * to operate properly for remoting circumstances, the master and slave instances
 * must be reasonably time synchronized.
 * 
 * @param workspace Workspace root Directory
 * @param localFile The local file to be copied to
 * @return  true iff the file was actually copied
 * @throws IOException   If unable to access/copy the workspace ivy file
 * @throws InterruptedException  If interrupted while accessing the workspace ivy file
 */
private boolean copyIvyFileFromWorkspaceIfNecessary(FilePath workspace, File localFile) throws IOException, InterruptedException {
  boolean copied = false;
  if (workspace != null) { // Unless the workspace is non-null we can not copy a new ivy file
    FilePath f = workspace.child(ivyFile);
    // Copy the ivy file from the workspace (possibly at a slave) to the projects dir (at Master)
    FilePath backupCopy = new FilePath(localFile);
    long flastModified = f.lastModified();
    if (flastModified == 0l) throw new FileNotFoundException("Can't stat file " + f);
    if (flastModified > lastmodified) {
      f.copyTo(backupCopy);
      localFile.setLastModified(flastModified);
      copied = true;
      LOGGER.info("Copied the workspace ivy file to backup");
    }
  }
  return copied;
}

代码示例来源:origin: jenkinsci/pipeline-aws-plugin

protected FileWrapper(@Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(), file.getRemote(), file.isDirectory(), file.length(), file.lastModified());
}

代码示例来源:origin: org.jenkins-ci.plugins/pipeline-utility-steps

protected FileWrapper(@Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(), file.getRemote(), file.isDirectory(), file.length(), file.lastModified());
}

代码示例来源:origin: jenkinsci/pipeline-utility-steps-plugin

protected FileWrapper(@Nonnull FilePath file) throws IOException, InterruptedException {
  this(file.getName(), file.getRemote(), file.isDirectory(), file.length(), file.lastModified());
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

public TestResult invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
    final long nowSlave = System.currentTimeMillis();
    // files older than this timestamp is considered stale
    long localBuildTime = buildTime + (nowSlave - nowMaster);
    FilePath[] paths = new FilePath(dir).list(testResultLocations);
    if (paths.length == 0) {
      throw new AbortException("No test reports that matches " + testResultLocations + " found. Configuration error?");
    }
    // since dir is local, paths all point to the local files
    List<File> files = new ArrayList<File>(paths.length);
    for (FilePath path : paths) {
      File report = new File(path.getRemote());
      if (ignoreTimestampCheck || localBuildTime - 3000 /*error margin*/ < report.lastModified()) {
        // this file is created during this build
        files.add(report);
      }
    }
    if (files.isEmpty()) {
      // none of the files were new
      throw new AbortException(
          String.format(
          "Test reports were found but none of them are new. Did tests run? \n"
          + "For example, %s is %s old\n", paths[0].getRemote(),
          Util.getTimeSpanString(localBuildTime - paths[0].lastModified())));
    }
    return parse(files, launcher, listener);
  }
});

代码示例来源:origin: hudson/hudson-2.x

public TestResult invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
    final long nowSlave = System.currentTimeMillis();
    // files older than this timestamp is considered stale
    long localBuildTime = buildTime + (nowSlave - nowMaster);
    FilePath[] paths = new FilePath(dir).list(testResultLocations);
    if (paths.length==0)
      throw new AbortException("No test reports that matches "+testResultLocations+" found. Configuration error?");
    // since dir is local, paths all point to the local files
    List<File> files = new ArrayList<File>(paths.length);
    for (FilePath path : paths) {
      File report = new File(path.getRemote());
      if (ignoreTimestampCheck || localBuildTime - 3000 /*error margin*/ < report.lastModified()) {
        // this file is created during this build
        files.add(report);
      }
    }
    if (files.isEmpty()) {
      // none of the files were new
      throw new AbortException(
        String.format(
        "Test reports were found but none of them are new. Did tests run? \n"+
        "For example, %s is %s old\n", paths[0].getRemote(),
        Util.getTimeSpanString(localBuildTime-paths[0].lastModified())));
    }
    return parse(files,launcher,listener);
  }
});

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

public TestResult invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException {
    final long nowSlave = System.currentTimeMillis();
    // files older than this timestamp is considered stale
    long localBuildTime = buildTime + (nowSlave - nowMaster);
    FilePath[] paths = new FilePath(dir).list(testResultLocations);
    if (paths.length==0)
      throw new AbortException("No test reports that matches "+testResultLocations+" found. Configuration error?");
    // since dir is local, paths all point to the local files
    List<File> files = new ArrayList<File>(paths.length);
    for (FilePath path : paths) {
      File report = new File(path.getRemote());
      if (ignoreTimestampCheck || localBuildTime - 3000 /*error margin*/ < report.lastModified()) {
        // this file is created during this build
        files.add(report);
      }
    }
    if (files.isEmpty()) {
      // none of the files were new
      throw new AbortException(
        String.format(
        "Test reports were found but none of them are new. Did tests run? \n"+
        "For example, %s is %s old\n", paths[0].getRemote(),
        Util.getTimeSpanString(localBuildTime-paths[0].lastModified())));
    }
    return parse(files,launcher,listener);
  }
});

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Copies this file to the specified target, with file permissions and other meta attributes intact.
 * @since 1.311
 */
public void copyToWithPermission(FilePath target) throws IOException, InterruptedException {
  copyTo(target);
  // copy file permission
  target.chmod(mode());
  target.setLastModifiedIfPossible(lastModified());
}

代码示例来源:origin: org.jenkins-ci.plugins/s3

public ObjectMetadata buildMetadata(FilePath filePath) throws IOException, InterruptedException {
  ObjectMetadata metadata = new ObjectMetadata();
  metadata.setContentType(Mimetypes.getInstance().getMimetype(filePath.getName()));
  metadata.setContentLength(filePath.length());
  metadata.setLastModified(new Date(filePath.lastModified()));
  if ((storageClass != null) && !"".equals(storageClass)) {
    metadata.setHeader("x-amz-storage-class", storageClass);
  }
  if (useServerSideEncryption) {
    metadata.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
  }
  for (MetadataPair metadataPair : userMetadata) {
    metadata.addUserMetadata(metadataPair.key, metadataPair.value);
  }
  return metadata;
}

相关文章