org.openide.filesystems.FileUtil.runAtomicAction()方法的使用及代码示例

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

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

FileUtil.runAtomicAction介绍

[英]Executes atomic action. For more info see FileSystem#runAtomicAction.

All events about filesystem changes (related to events on all affected instances of FileSystem) are postponed after the whole atomicCode is executed.
[中]执行原子操作。有关更多信息,请参阅文件系统#runAtomicAction。
所有关于文件系统更改的事件(与FileSystem的所有受影响实例上的事件相关)都将在整个atomicCode执行后延迟。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

/**
 * Executes atomic action. For more info see {@link FileSystem#runAtomicAction}. 
 * <p>
 * All events about filesystem changes (related to events on all affected instances of <code>FileSystem</code>)
 * are postponed after the whole <code>atomicCode</code> 
 * is executed.
 * </p>
 * @param atomicCode code that is supposed to be run as atomic action. See {@link FileSystem#runAtomicAction}
 * @since 7.5
 */
public static final void runAtomicAction(final Runnable atomicCode) {
  final AtomicAction action = new FileSystem.AtomicAction() {
    public void run() throws IOException {
      atomicCode.run();
    }
  };
  try {
    FileUtil.runAtomicAction(action);
  } catch (IOException ex) {
    Exceptions.printStackTrace(ex);
  }
}        
/**

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

FileUtil.runAtomicAction(new Runnable() {
  @Override
  public void run() {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-makeproject

@Override
  public void run() {
    FileUtil.runAtomicAction(refresher);
    fon.onFinish(curPAE);
    MakeLogicalViewProvider.refreshBrokenItems(project);
  }
});

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-palette

public void actionPerformed(ActionEvent evt) {
    refreshDescriptorRegistry();
    try {
      FileUtil.runAtomicAction(new AtomicAction() {
        public void run() {
          clean();
          init();
        }
      });
    } catch (IOException e) {
      Debug.warning(e);
    }
  }
};

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-vmd-model

if (fo != null) {
  try {
    FileUtil.runAtomicAction(new AtomicAction() {
      public void run() {
        try {
if (fo1 != null) {
  try {
    FileUtil.runAtomicAction(new AtomicAction() {
      public void run() {
        try {

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-project-ant-ui

public static FileObject copyFolderRecursively(final FileObject sourceFolder, final FileObject destination) throws IOException {
  FileUtil.runAtomicAction(new FileSystem.AtomicAction() {
    @Override public void run() throws IOException {
      assert sourceFolder.isFolder() : sourceFolder;
      assert destination.isFolder() : destination;
      FileObject destinationSubFolder = destination.getFileObject(sourceFolder.getName());
      if (destinationSubFolder == null) {
        destinationSubFolder = destination.createFolder(sourceFolder.getName());
      }
      for (FileObject fo : sourceFolder.getChildren()) {
        if (fo.isFolder()) {
          copyFolderRecursively(fo, destinationSubFolder);
        } else {
          FileObject foExists = destinationSubFolder.getFileObject(fo.getName(), fo.getExt());
          if (foExists != null) {
            foExists.delete();
          }
          FileUtil.copyFile(fo, destinationSubFolder, fo.getName(), fo.getExt());
        }
      }
    }
  });
  return destination.getFileObject(sourceFolder.getName());
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private void downloadFile(final TransferInfo transferInfo, final TransferFile file) {
  if (cancelled) {
    LOGGER.fine("Download cancelled");
    return;
  }
  getOperationMonitor().operationProcess(Operation.DOWNLOAD, file);
  try {
    FileUtil.runAtomicAction(new DownloadAtomicAction(new Runnable() {
      @Override
      public void run() {
        try {
          downloadFileInternal(transferInfo, file);
        } catch (IOException | RemoteException exc) {
          LOGGER.log(Level.INFO, null, exc);
          transferFailed(transferInfo, file, NbBundle.getMessage(RemoteClient.class, "MSG_ErrorReason", exc.getMessage().trim()));
        }
      }
    }));
  } catch (IOException ex) {
    LOGGER.log(Level.INFO, null, ex);
    transferFailed(transferInfo, file, NbBundle.getMessage(RemoteClient.class, "MSG_ErrorReason", ex.getMessage().trim()));
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

void generateTests(final Node[] activatedNodes, final PhpProject phpProject, final PhpTestingProvider testingProvider) {
  assert phpProject != null;
  assert !EventQueue.isDispatchThread();
  List<FileObject> files = CommandUtils.getFileObjects(activatedNodes);
  assert !files.isEmpty() : "No files for tests?!";
  final List<FileObject> sanitizedFiles = new ArrayList<>(files.size() * 2);
  sanitizeFiles(sanitizedFiles, files, phpProject, PhpVisibilityQuery.forProject(phpProject));
  if (sanitizedFiles.isEmpty()) {
    LOGGER.info("No visible files for creating tests -> exiting.");
    return;
  }
  final Set<FileObject> succeeded = new HashSet<>();
  final Set<FileObject> failed = new HashSet<>();
  final PhpModule phpModule = phpProject.getPhpModule();
  FileUtil.runAtomicAction(new Runnable() {
    @Override
    public void run() {
      CreateTestsResult result = testingProvider.createTests(phpModule, sanitizedFiles);
      succeeded.addAll(result.getSucceeded());
      failed.addAll(result.getFailed());
    }
  });
  showFailures(failed);
  reformat(succeeded);
  open(succeeded);
  refreshTests(ProjectPropertiesSupport.getTestDirectories(phpProject, false));
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base

@CheckForNull
public ClassIndexImpl getUsagesQuery (@NonNull final URL root, final boolean beforeCreateAllowed) {
  final ClassIndexImpl[] index = new ClassIndexImpl[] {null};
  FileUtil.runAtomicAction(new Runnable() {
    @Override
    public void run() {

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor

@Override
public void implement() throws Exception {
  final DataFolder dataFolder = DataFolder.findFolder(folder);
  final DataObject configDataObject = DataObject.find(template);
  final FileObject[] clsFo = new FileObject[1];
  FileUtil.runAtomicAction(new Runnable() {
    @Override
    public void run() {
      try {
        DataObject clsDataObject = configDataObject.createFromTemplate(dataFolder, clsName);
        clsFo[0] = clsDataObject.getPrimaryFile();
        FileObject fo = clsFo[0];
        FileLock lock = fo.lock();
        try {
          fo.rename(lock, fo.getName(), "php"); //NOI18N
        } finally {
          lock.releaseLock();
        }
      } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
      }
    }
  });
  if (clsFo[0] != null) {
    UiUtils.open(clsFo[0], 0);
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

FileUtil.runAtomicAction(action);
if (action.getException() != null) {
  throw action.getException();

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

/**
 * Created validation.xml deployment descriptor
 * @param j2eeProfile Java EE profile
 * @param dir Directory where validation.xml should be created
 * @param name name of configuration file to create;
 * @return validation.xml file as FileObject
 * @throws IOException
 * @since 1.52
 */
public static FileObject createValidationXml(Profile j2eeProfile, FileObject dir, String name) throws IOException {
  String template = null;
  if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile ||
      Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
    template = "validation.xml"; //NOI18N
  }
  if (template == null)
    return null;
  MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, name+".xml");
  FileUtil.runAtomicAction(action);
  if (action.getException() != null)
    throw action.getException();
  else
    return action.getResult();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

/**
 * Creates beans.xml deployment descriptor.
 * @param j2eeProfile Java EE profile to specify which version of beans.xml should be created
 * @param dir Directory where beans.xml should be created
 * @param name name of configuration file to create; should be always "beans" for now
 * @return beans.xml file as FileObject
 * @throws java.io.IOException
 * @since 1.49
 */
public static FileObject createBeansXml(Profile j2eeProfile, FileObject dir, String name) throws IOException {
  String template = null;
  if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) {
    template = "beans-1.0.xml"; //NOI18N
  }
  if (Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
    template = "beans-1.1.xml"; //NOI18N
  }
  if (template == null)
    return null;
  MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, name+".xml");
  FileUtil.runAtomicAction(action);
  if (action.getException() != null)
    throw action.getException();
  else
    return action.getResult();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

/**
 * Creates web-fragment.xml deployment descriptor.
 * @param j2eeProfile Java EE profile to specify which version of web-fragment.xml should be created
 * @param dir Directory where web-fragment.xml should be created
 * @return web-fragment.xml file as FileObject
 * @throws java.io.IOException
 */
public static FileObject createWebFragmentXml(Profile j2eeProfile, FileObject dir) throws IOException {
  String template = null;
  if (Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
    template = "web-fragment-3.1.xml"; //NOI18N
  } else if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) {
    template = "web-fragment-3.0.xml"; //NOI18N
  }
  if (template == null)
    return null;
  MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, "web-fragment.xml");
  FileUtil.runAtomicAction(action);
  if (action.getException() != null)
    throw action.getException();
  else
    return action.getResult();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

/**
 * Created Constraint declaration deployment descriptor
 * @param j2eeProfile Java EE profile
 * @param dir Directory where constraint.xml should be created
 * @param name name of configuration file to create;
 * @return validation.xml file as FileObject
 * @throws IOException
 * @since 1.52
 */
public static FileObject createConstraintXml(Profile j2eeProfile, FileObject dir, String name) throws IOException {
  String template = null;
  if (Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile ||
      Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) {
    template = "constraint.xml"; //NOI18N
  }
  if (template == null)
    return null;
  MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, name+".xml");
  FileUtil.runAtomicAction(action);
  if (action.getException() != null)
    throw action.getException();
  else
    return action.getResult();
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-common

/**
 * Creates web.xml deployment descriptor.
 * @param j2eeProfile Java EE profile to specify which version of web.xml should be created
 * @param webXmlRequired true if web.xml should be created also for profiles where it is not required
 * @param dir Directory where web.xml should be created
 * @return web.xml file as FileObject
 * @throws java.io.IOException
 */
public static FileObject createWebXml(Profile j2eeProfile, boolean webXmlRequired, FileObject dir) throws IOException {
  String template = null;
  if ((Profile.JAVA_EE_7_FULL == j2eeProfile || Profile.JAVA_EE_7_WEB == j2eeProfile) && webXmlRequired) {
    template = "web-3.1.xml"; //NOI18N
  } else if ((Profile.JAVA_EE_6_FULL == j2eeProfile || Profile.JAVA_EE_6_WEB == j2eeProfile) && webXmlRequired) {
    template = "web-3.0.xml"; //NOI18N
  } else if (Profile.JAVA_EE_5 == j2eeProfile) {
    template = "web-2.5.xml"; //NOI18N
  } else if (Profile.J2EE_14 == j2eeProfile) {
    template = "web-2.4.xml"; //NOI18N
  } else if (Profile.J2EE_13 == j2eeProfile) {
    template = "web-2.3.xml"; //NOI18N
  }
  if (template == null)
    return null;
  MakeFileCopy action = new MakeFileCopy(RESOURCE_FOLDER + template, dir, "web.xml");
  FileUtil.runAtomicAction(action);
  if (action.getException() != null)
    throw action.getException();
  else
    return action.getResult();
}

相关文章