/**
   * Test of validateDirectory method, of class YiiCustomizerValidator.
   *
   * @throws java.io.IOException
   */
  @Test
  public void testValidateDirectory() throws IOException {
    FileSystem fileSystem = FileUtil.createMemoryFileSystem();
    FileObject sourceDirectory = fileSystem.getRoot();
    sourceDirectory.createFolder("myfolder");
    sourceDirectory.createData("test.php");

    // existing directory
    YiiCustomizerValidator validator =
        new YiiCustomizerValidator().validateDirectory(sourceDirectory, "myfolder");
    ValidationResult result = validator.getResult();
    assertFalse(result.hasErrors());
    assertFalse(result.hasWarnings());

    // not existing directory
    validator = new YiiCustomizerValidator().validateDirectory(sourceDirectory, "dummy");
    result = validator.getResult();
    assertFalse(result.hasErrors());
    assertTrue(result.hasWarnings());

    // file
    validator = new YiiCustomizerValidator().validateDirectory(sourceDirectory, "test.php");
    result = validator.getResult();
    assertFalse(result.hasErrors());
    assertTrue(result.hasWarnings());
  }
  /**
   * Simulates deadlock issue 133616 - create MultiFileSystem - create lookup to set our
   * MultiFileSystem and system filesystem - create handler to manage threads - put test FileObject
   * to 'potentialLock' set - call hasLocks - it call LocalFileSystemEx.getInvalid which ends in our
   * DeadlockHandler - it starts lockingThread which calls FileObject.lock which locks our
   * FileObject - when we in LocalFileSystemEx.lock, we notify main thread which continues in
   * getInvalid and tries to accuire lock on FileObject and it dead locks
   */
  public void testLocalFileSystemEx133616() throws Exception {
    System.setProperty("workdir", getWorkDirPath());
    clearWorkDir();

    FileSystem lfs =
        TestUtilHid.createLocalFileSystem("mfs1" + getName(), new String[] {"/fold/file1"});
    LocalFileSystemEx exfs = new LocalFileSystemEx();
    exfs.setRootDirectory(FileUtil.toFile(lfs.getRoot()));
    FileSystem xfs = TestUtilHid.createXMLFileSystem(getName(), new String[] {});
    FileSystem mfs = new MultiFileSystem(exfs, xfs);
    testedFS = mfs;
    System.setProperty(
        "org.openide.util.Lookup", LocalFileSystemEx133616Test.class.getName() + "$Lkp");
    Lookup l = Lookup.getDefault();
    if (!(l instanceof Lkp)) {
      fail("Wrong lookup: " + l);
    }

    final FileObject file1FO = mfs.findResource("/fold/file1");
    File file1File = FileUtil.toFile(file1FO);

    Logger.getLogger(LocalFileSystemEx.class.getName()).setLevel(Level.FINEST);
    Logger.getLogger(LocalFileSystemEx.class.getName()).addHandler(new DeadlockHandler(file1FO));
    LocalFileSystemEx.potentialLock(file1FO.getPath());
    LocalFileSystemEx.hasLocks();
  }
예제 #3
0
 /** Refreshes NB's file cache like "Source -> Scan for External Changes". */
 public void scanForExternalChanges(Collection<TmcProjectInfo> projects) {
   HashSet<FileSystem> filesystems = new HashSet<FileSystem>();
   for (TmcProjectInfo project : projects) {
     try {
       filesystems.add(project.getProjectDir().getFileSystem());
     } catch (Exception e) {
     }
   }
   for (FileSystem fs : filesystems) { // Probably just one
     fs.refresh(true);
   }
 }
예제 #4
0
  public void testSetModifiedRemovesSaveCookie() throws Exception {
    FileSystem fs = FileUtil.createMemoryFileSystem();
    FileObject f = fs.getRoot().createData("index.test");
    DataObject dob = DataObject.find(f);
    assertEquals("The right object", GsfDataObject.class, dob.getClass());

    dob.getLookup().lookup(EditorCookie.class).openDocument().insertString(0, "modified", null);
    assertTrue("Should be modified.", dob.isModified());
    dob.setModified(false);
    assertFalse("Should not be modified.", dob.isModified());
    assertNull("Should not have SaveCookie.", dob.getLookup().lookup(SaveCookie.class));
  }
예제 #5
0
 public void run() {
   computeKeys();
   refreshKeys();
   try {
     FileSystem fs = root.getFileSystem();
     wfcl = (FileChangeListener) WeakListeners.create(FileChangeListener.class, this, fs);
     fs.addFileChangeListener(wfcl);
   } catch (FileStateInvalidException e) {
     ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
   }
   wvqcl = WeakListeners.change(this, VisibilityQuery.getDefault());
   VisibilityQuery.getDefault().addChangeListener(wvqcl);
 }
 @Override
 protected FileSystem createFS(String... resources) throws IOException {
   for (String s : resources) {
     FileObject fo = FileUtil.getConfigFile(s.replaceAll("/.*", ""));
     if (fo != null) {
       fo.delete();
     }
   }
   FileSystem sfs = FileUtil.getConfigRoot().getFileSystem();
   for (String s : resources) {
     assertNotNull("creating: " + s, FileUtil.createData(sfs.getRoot(), s));
   }
   return sfs;
 }
예제 #7
0
  public static void generateFile(
      final FileObject file,
      String libraryPath,
      String name,
      String src,
      String safeName,
      String realName)
      throws IOException {
    try {
      FileSystem fs = file.getFileSystem();
      String text = libraryParser.getTemplate(libraryPath + "/" + src);
      text = text.replaceAll(Pattern.quote("${real_name}"), realName);
      text = text.replaceAll(Pattern.quote("${safe_name}"), safeName);
      final String textOut = text;
      fs.runAtomicAction(
          new FileSystem.AtomicAction() {

            public void run() throws IOException {
              FileLock lock = file.lock();
              try {
                BufferedWriter bw =
                    new BufferedWriter(new OutputStreamWriter(file.getOutputStream(lock)));

                bw.write(textOut);
                bw.close();
              } finally {
                lock.releaseLock();
              }
            }
          });

    } catch (FileStateInvalidException ex) {
      Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
      Exceptions.printStackTrace(ex);
    }
  }
예제 #8
0
 @Before
 public void setUp() {
   fs = FileUtil.createMemoryFileSystem();
   fsRoot = fs.getRoot();
 }