hudson.Util.deleteRecursive()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(254)

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

Util.deleteRecursive介绍

[英]Deletes the given directory (including its contents) recursively. It does not take no for an answer - if necessary, it will have multiple attempts at deleting things.
[中]递归删除给定目录(包括其内容)。答案并不一定是否定的——如果有必要,它会多次尝试删除内容。

代码示例

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

private void deleteExistingUserFolder(File existingUserFolder) throws IOException {
  if (existingUserFolder != null && existingUserFolder.exists()) {
    Util.deleteRecursive(existingUserFolder);
  }
}

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

@Override public final boolean delete() throws IOException, InterruptedException {
  File ad = getArtifactsDir();
  if (!ad.exists()) {
    LOG.log(Level.FINE, "no such directory {0} to delete for {1}", new Object[] {ad, build});
    return false;
  }
  LOG.log(Level.FINE, "deleting {0} for {1}", new Object[] {ad, build});
  Util.deleteRecursive(ad);
  return true;
}

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

/**
 * Deletes the given directory (including its contents) recursively.
 * It does not take no for an answer - if necessary, it will have multiple
 * attempts at deleting things.
 *
 * @throws IOException
 * if the operation fails.
 */
public static void deleteRecursive(@Nonnull File dir) throws IOException {
  deleteRecursive(fileToPath(dir), PathRemover.PathChecker.ALLOW_ALL);
}

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

@Override
  public Void invoke(File f, VirtualChannel channel) throws IOException {
    Util.deleteRecursive(fileToPath(f), path -> deleting(path.toFile()));
    return null;
  }
}

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

@Override public void delete() throws IOException, InterruptedException {
  super.delete();
  Util.deleteRecursive(getBuildDir());
}

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

Util.deleteRecursive(tmp);
Util.deleteRecursive(tmp);

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

/**
 * Explodes the plugin into a directory, if necessary.
 */
private static void explode(File archive, File destDir) throws IOException {
  destDir.mkdirs();
  // timestamp check
  File explodeTime = new File(destDir,".timestamp2");
  if(explodeTime.exists() && explodeTime.lastModified()==archive.lastModified())
    return; // no need to expand
  // delete the contents so that old files won't interfere with new files
  Util.deleteRecursive(destDir);
  try {
    Project prj = new Project();
    unzipExceptClasses(archive, destDir, prj);
    createClassJarFromWebInfClasses(archive, destDir, prj);
  } catch (BuildException x) {
    throw new IOException("Failed to expand " + archive,x);
  }
  try {
    new FilePath(explodeTime).touch(archive.lastModified());
  } catch (InterruptedException e) {
    throw new AssertionError(e); // impossible
  }
}

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

@Override
protected void kill() {
  super.kill();
  closeChannel();
  try {
    log.close();
  } catch (IOException x) {
    LOGGER.log(Level.WARNING, "Failed to close agent log", x);
  }
  try {
    Util.deleteRecursive(getLogDir());
  } catch (IOException ex) {
    logger.log(Level.WARNING, "Unable to delete agent logs", ex);
  }
}

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

/**
 * Does the real job of deleting the item.
 */
protected void performDelete() throws IOException, InterruptedException {
  getConfigFile().delete();
  Util.deleteRecursive(getRootDir());
}

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

/**
 * Actually persists a node on disk.
 *
 * @param node the node to be persisted.
 * @throws IOException if the node could not be persisted.
 */
private void persistNode(final @Nonnull Node node)  throws IOException {
  // no need for a full save() so we just do the minimum
  if (node instanceof EphemeralNode) {
    Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
  } else {
    XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM,
        new File(new File(getNodesDir(), node.getNodeName()), "config.xml"));
    xmlFile.write(node);
    SaveableListener.fireOnChange(this, xmlFile);
  }
  jenkins.getQueue().scheduleMaintenance();
}

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

/**
 * {@inheritDoc}
 */
@Override
public void save() throws IOException {
  if (BulkChange.contains(this)) {
    return;
  }
  final File nodesDir = getNodesDir();
  final Set<String> existing = new HashSet<String>();
  for (Node n : nodes.values()) {
    if (n instanceof EphemeralNode) {
      continue;
    }
    existing.add(n.getNodeName());
    XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM, new File(new File(nodesDir, n.getNodeName()), "config.xml"));
    xmlFile.write(n);
    SaveableListener.fireOnChange(this, xmlFile);
  }
  for (File forDeletion : nodesDir.listFiles(new FileFilter() {
    @Override
    public boolean accept(File pathname) {
      return pathname.isDirectory() && !existing.contains(pathname.getName());
    }
  })) {
    Util.deleteRecursive(forDeletion);
  }
}

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

@SuppressWarnings("OverridableMethodCallInConstructor") // should have been final
public RekeySecretAdminMonitor() throws IOException {
  // if JENKINS_HOME existed <1.497, we need to offer rewrite
  // this computation needs to be done and the value be captured,
  // since $JENKINS_HOME/config.xml can be saved later before the user has
  // actually rewritten XML files.
  Jenkins j = Jenkins.getInstance();
  if (j.isUpgradedFromBefore(new VersionNumber("1.496.*"))
  &&  new FileBoolean(new File(j.getRootDir(),"secret.key.not-so-secret")).isOff())
    needed.on();
  Util.deleteRecursive(new File(getBaseDir(), "backups")); // SECURITY-376: no longer used
}

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

/**
 * Removes a node. If the node instance is not in the list of nodes, then this will be a no-op, even if
 * there is another instance with the same {@link Node#getNodeName()}.
 *
 * @param node the node instance to remove.
 * @throws IOException if the list of nodes could not be persisted.
 */
public void removeNode(final @Nonnull Node node) throws IOException {
  if (node == nodes.get(node.getNodeName())) {
    Queue.withLock(new Runnable() {
      @Override
      public void run() {
        Computer c = node.toComputer();
        if (c != null) {
          c.recordTermination();
          c.disconnect(OfflineCause.create(hudson.model.Messages._Hudson_NodeBeingRemoved()));
        }
        if (node == nodes.remove(node.getNodeName())) {
          jenkins.updateComputerList();
          jenkins.trimLabels();
        }
      }
    });
    // no need for a full save() so we just do the minimum
    Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
    NodeListener.fireOnDeleted(node);
  }
}

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

out.println("Moving "+home+" to "+backup);
if(backup.exists())
  Util.deleteRecursive(backup);
if(!home.renameTo(backup)) {
  out.println("Failed to move your current data "+home+" out of the way");

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

if (!success) {
  Util.deleteRecursive(dir);

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

Util.deleteRecursive(oldRoot);
} catch (IOException e) {

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

/**
 * Deletes the data directory and removes this user from Hudson.
 *
 * @throws IOException
 *      if we fail to delete.
 */
public synchronized void delete() throws IOException {
  synchronized (byName) {
    byName.remove(id);
    Util.deleteRecursive(new File(getRootDir(), id));
  }
}

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

@Override public final boolean delete() throws IOException, InterruptedException {
  File ad = getArtifactsDir();
  if (!ad.exists()) {
    LOG.log(Level.FINE, "no such directory {0} to delete for {1}", new Object[] {ad, build});
    return false;
  }
  LOG.log(Level.FINE, "deleting {0} for {1}", new Object[] {ad, build});
  Util.deleteRecursive(ad);
  return true;
}

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

/**
 * Does the real job of deleting the item.
 */
protected void performDelete() throws IOException, InterruptedException {
  getConfigFile().delete();
  Util.deleteRecursive(getRootDir());
}

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

/**
 * Does the real job of deleting the item.
 */
protected void performDelete() throws IOException, InterruptedException {
  getConfigFile().delete();
  Util.deleteRecursive(getRootDir());
}

相关文章