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

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

本文整理了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

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

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

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

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

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

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

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

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

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

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

  1. Util.deleteRecursive(tmp);
  2. Util.deleteRecursive(tmp);

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

  1. /**
  2. * Explodes the plugin into a directory, if necessary.
  3. */
  4. private static void explode(File archive, File destDir) throws IOException {
  5. destDir.mkdirs();
  6. // timestamp check
  7. File explodeTime = new File(destDir,".timestamp2");
  8. if(explodeTime.exists() && explodeTime.lastModified()==archive.lastModified())
  9. return; // no need to expand
  10. // delete the contents so that old files won't interfere with new files
  11. Util.deleteRecursive(destDir);
  12. try {
  13. Project prj = new Project();
  14. unzipExceptClasses(archive, destDir, prj);
  15. createClassJarFromWebInfClasses(archive, destDir, prj);
  16. } catch (BuildException x) {
  17. throw new IOException("Failed to expand " + archive,x);
  18. }
  19. try {
  20. new FilePath(explodeTime).touch(archive.lastModified());
  21. } catch (InterruptedException e) {
  22. throw new AssertionError(e); // impossible
  23. }
  24. }

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

  1. @Override
  2. protected void kill() {
  3. super.kill();
  4. closeChannel();
  5. try {
  6. log.close();
  7. } catch (IOException x) {
  8. LOGGER.log(Level.WARNING, "Failed to close agent log", x);
  9. }
  10. try {
  11. Util.deleteRecursive(getLogDir());
  12. } catch (IOException ex) {
  13. logger.log(Level.WARNING, "Unable to delete agent logs", ex);
  14. }
  15. }

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

  1. /**
  2. * Does the real job of deleting the item.
  3. */
  4. protected void performDelete() throws IOException, InterruptedException {
  5. getConfigFile().delete();
  6. Util.deleteRecursive(getRootDir());
  7. }

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

  1. /**
  2. * Actually persists a node on disk.
  3. *
  4. * @param node the node to be persisted.
  5. * @throws IOException if the node could not be persisted.
  6. */
  7. private void persistNode(final @Nonnull Node node) throws IOException {
  8. // no need for a full save() so we just do the minimum
  9. if (node instanceof EphemeralNode) {
  10. Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
  11. } else {
  12. XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM,
  13. new File(new File(getNodesDir(), node.getNodeName()), "config.xml"));
  14. xmlFile.write(node);
  15. SaveableListener.fireOnChange(this, xmlFile);
  16. }
  17. jenkins.getQueue().scheduleMaintenance();
  18. }

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

  1. /**
  2. * {@inheritDoc}
  3. */
  4. @Override
  5. public void save() throws IOException {
  6. if (BulkChange.contains(this)) {
  7. return;
  8. }
  9. final File nodesDir = getNodesDir();
  10. final Set<String> existing = new HashSet<String>();
  11. for (Node n : nodes.values()) {
  12. if (n instanceof EphemeralNode) {
  13. continue;
  14. }
  15. existing.add(n.getNodeName());
  16. XmlFile xmlFile = new XmlFile(Jenkins.XSTREAM, new File(new File(nodesDir, n.getNodeName()), "config.xml"));
  17. xmlFile.write(n);
  18. SaveableListener.fireOnChange(this, xmlFile);
  19. }
  20. for (File forDeletion : nodesDir.listFiles(new FileFilter() {
  21. @Override
  22. public boolean accept(File pathname) {
  23. return pathname.isDirectory() && !existing.contains(pathname.getName());
  24. }
  25. })) {
  26. Util.deleteRecursive(forDeletion);
  27. }
  28. }

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

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

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

  1. /**
  2. * Removes a node. If the node instance is not in the list of nodes, then this will be a no-op, even if
  3. * there is another instance with the same {@link Node#getNodeName()}.
  4. *
  5. * @param node the node instance to remove.
  6. * @throws IOException if the list of nodes could not be persisted.
  7. */
  8. public void removeNode(final @Nonnull Node node) throws IOException {
  9. if (node == nodes.get(node.getNodeName())) {
  10. Queue.withLock(new Runnable() {
  11. @Override
  12. public void run() {
  13. Computer c = node.toComputer();
  14. if (c != null) {
  15. c.recordTermination();
  16. c.disconnect(OfflineCause.create(hudson.model.Messages._Hudson_NodeBeingRemoved()));
  17. }
  18. if (node == nodes.remove(node.getNodeName())) {
  19. jenkins.updateComputerList();
  20. jenkins.trimLabels();
  21. }
  22. }
  23. });
  24. // no need for a full save() so we just do the minimum
  25. Util.deleteRecursive(new File(getNodesDir(), node.getNodeName()));
  26. NodeListener.fireOnDeleted(node);
  27. }
  28. }

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

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

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

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

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

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

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

  1. /**
  2. * Deletes the data directory and removes this user from Hudson.
  3. *
  4. * @throws IOException
  5. * if we fail to delete.
  6. */
  7. public synchronized void delete() throws IOException {
  8. synchronized (byName) {
  9. byName.remove(id);
  10. Util.deleteRecursive(new File(getRootDir(), id));
  11. }
  12. }

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

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

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

  1. /**
  2. * Does the real job of deleting the item.
  3. */
  4. protected void performDelete() throws IOException, InterruptedException {
  5. getConfigFile().delete();
  6. Util.deleteRecursive(getRootDir());
  7. }

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

  1. /**
  2. * Does the real job of deleting the item.
  3. */
  4. protected void performDelete() throws IOException, InterruptedException {
  5. getConfigFile().delete();
  6. Util.deleteRecursive(getRootDir());
  7. }

相关文章