org.openide.filesystems.FileSystem.AtomicAction Java Examples

The following examples show how to use org.openide.filesystems.FileSystem.AtomicAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EarProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new empty Enterprise Application project.
 *
 * @param prjDir the top-level directory (need not yet exist but if it does it must be empty)
 * @param name the code name for the project
 * @return the helper object permitting it to be further customized
 * @throws IOException in case something went wrong
 */
public static AntProjectHelper createProject(File prjDir, String name, Profile j2eeProfile,
        String serverInstanceId, String sourceLevel, String librariesDefinition) throws IOException {
    FileObject projectDir = FileUtil.createFolder(prjDir);
    final EarProjectGenerator earGen = new EarProjectGenerator(prjDir, projectDir, name, j2eeProfile,
            serverInstanceId, sourceLevel, librariesDefinition);
    final AntProjectHelper[] h = new AntProjectHelper[1];
    
    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = earGen.doCreateProject();
            h[0] = helper;
        }});
    return h[0];
}
 
Example #2
Source File: EarProjectGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static AntProjectHelper importProject(File pDir, final File sDir, String name,
        Profile j2eeProfile, String serverInstanceID, final String platformName,
        String sourceLevel, final Map<FileObject, ModuleType> userModules,
        String librariesDefinition)
        throws IOException {
    FileObject projectDir = FileUtil.createFolder(pDir);
    final EarProjectGenerator earGen = new EarProjectGenerator(pDir, projectDir, name,
            j2eeProfile, serverInstanceID, sourceLevel, librariesDefinition);
    final AntProjectHelper[] h = new AntProjectHelper[1];
    
    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = earGen.doImportProject(sDir, userModules, platformName);
            h[0] = helper;
        }});
    return h[0];
}
 
Example #3
Source File: WSUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void removeImplClass(Project project, String implClass) {
    Sources sources = project.getLookup().lookup(Sources.class);
    String resource = implClass.replace('.','/')+".java"; //NOI18N
    if (sources!=null) {
        SourceGroup[] srcGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i=0;i<srcGroup.length;i++) {
            final FileObject srcRoot = srcGroup[i].getRootFolder();
            final FileObject implClassFo = srcRoot.getFileObject(resource);
            if (implClassFo!=null) {
                try {
                    FileSystem fs = implClassFo.getFileSystem();
                    fs.runAtomicAction(new AtomicAction() {
                        @Override
                        public void run() {
                            deleteFile(implClassFo);
                        }
                    });
                } catch (IOException ex) {
                    ErrorManager.getDefault().notify(ex);
                }
                return;
            }
        }
    }
}
 
Example #4
Source File: WSUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void removeImplClass(Project project, String implClass) {
    Sources sources = project.getLookup().lookup(Sources.class);
    String resource = implClass.replace('.','/')+".java"; //NOI18N
    if (sources!=null) {
        SourceGroup[] srcGroup = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        for (int i=0;i<srcGroup.length;i++) {
            final FileObject srcRoot = srcGroup[i].getRootFolder();
            final FileObject implClassFo = srcRoot.getFileObject(resource);
            if (implClassFo!=null) {
                try {
                    FileSystem fs = implClassFo.getFileSystem();
                    fs.runAtomicAction(new AtomicAction() {
                        public void run() {
                            deleteFile(implClassFo);
                        }
                    });
                } catch (IOException ex) {
                    ErrorManager.getDefault().notify(ex);
                }
                return;
            }
        }
    }
}
 
Example #5
Source File: ProjectProperties.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void diskChange(FileEvent fe) {
    boolean writing = false;
    if (fe != null) {
        synchronized (saveActions) {
            for (AtomicAction a : saveActions) {
                if (fe.firedFrom(a)) {
                    writing = true;
                    break;
                }
            }
        }
    }
    if (!writing) {
        loaded = false;
        reloadedStackTrace = new Throwable("noticed disk change here");
    }
    fireChange();
    if (!writing) {
        helper.fireExternalChange(path);
    }
}
 
Example #6
Source File: InteceptorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void deleteA_CreateA_RunAtomic() throws IOException, SVNClientException {
    // init
    final File fileA = new File(wc, "A");
    fileA.createNewFile();        
    commit(wc);        
    assertEquals(SVNStatusKind.NORMAL, getSVNStatus(fileA).getTextStatus());        
    
    final FileObject fo = FileUtil.toFileObject(fileA);
    AtomicAction a = new AtomicAction() {
        public void run() throws IOException {             
            fo.delete();
            fo.getParent().createData(fo.getName());
        }
    };
    fo.getFileSystem().runAtomicAction(a);        
    
    waitALittleBit(500); // after create 
    
    // test 
    assertTrue(fileA.exists());        
    assertEquals(SVNStatusKind.NORMAL, getSVNStatus(fileA).getTextStatus());        
    assertEquals(FileInformation.STATUS_VERSIONED_UPTODATE, getStatus(fileA));                
}
 
Example #7
Source File: FilesystemInterceptorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testDeleteA_CreateA_RunAtomic() throws Exception {
    // init
    final File fileA = new File(repositoryLocation, "A");
    h.setFilesToRefresh(Collections.singleton(fileA));
    fileA.createNewFile();
    add();
    commit();
    assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fileA).getStatus());
    assertTrue(h.waitForFilesToRefresh());

    final FileObject fo = FileUtil.toFileObject(fileA);
    AtomicAction a = new AtomicAction() {
        @Override
        public void run() throws IOException {
            fo.delete();
            fo.getParent().createData(fo.getName());
        }
    };
    h.setFilesToRefresh(Collections.singleton(fileA));
    fo.getFileSystem().runAtomicAction(a);
    assertTrue(h.waitForFilesToRefresh());

    // test
    assertTrue(fileA.exists());
    assertEquals(EnumSet.of(Status.UPTODATE), getCache().getStatus(fileA).getStatus());
}
 
Example #8
Source File: DataEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** The time when the data has been modified
*/
public Date getTime() {
    // #32777 - refresh file object and return always the actual time
    action = new FileSystem.AtomicAction() {
        public void run() throws IOException {
            getFileImpl().refresh(false);
        }
    };
    try {
        getFileImpl().getFileSystem().runAtomicAction(action);
    } catch (IOException ex) {
        //Nothing to do here
    }
    
    return getFileImpl ().lastModified ();
}
 
Example #9
Source File: EjbJarProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AntProjectHelper createProject(final EjbJarProjectCreateData createData) throws IOException {
    File dir = createData.getProjectDir();

    final FileObject projectDir = FileUtil.createFolder(dir);
    final AntProjectHelper[] h = new AntProjectHelper[1];

    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = createProjectImpl(createData, projectDir);
            h[0] = helper;
        }});
    return h[0];
}
 
Example #10
Source File: EditorConfigProcessor.java    From editorconfig-netbeans with MIT License 5 votes vote down vote up
/**
 * TODO: Make sure that a Reformat is done to write correct indentions.
 *
 * @param info
 */
private void updateChangesInFile(FileInfo info) {
  LOG.log(Level.INFO, "Write content (with all rules applied) to file: {0}",
          info.getFileObject().getPath());

  try {
    FileUtil.runAtomicAction((AtomicAction) new WriteStringToFileAction(info));
  } catch (IOException ex) {
    LOG.log(Level.SEVERE, ex.getMessage());
  }
}
 
Example #11
Source File: AppClientProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AntProjectHelper createProject(final AppClientProjectCreateData createData) throws IOException {
    File dir = createData.getProjectDir();

    final AntProjectHelper[] h = new AntProjectHelper[1];
    final FileObject projectDir = FileUtil.createFolder(dir);

    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = createProjectImpl(createData, projectDir);
            h[0] = helper;
        }});
    return h[0];
}
 
Example #12
Source File: AppClientProjectGenerator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AntProjectHelper importProject(final AppClientProjectCreateData createData) throws IOException {
    File dir = createData.getProjectDir();
    
    final AntProjectHelper[] h = new AntProjectHelper[1];
    final FileObject projectDir = FileUtil.createFolder(dir);

    // create project in one FS atomic action:
    FileSystem fs = projectDir.getFileSystem();
    fs.runAtomicAction(new FileSystem.AtomicAction() {
        public void run() throws IOException {
            AntProjectHelper helper = importProjectImpl(createData, projectDir);
            h[0] = helper;
        }});
    return h[0];
}
 
Example #13
Source File: AntProjectHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void change(FileEvent fe) {
    synchronized (saveActions) {
        for (AtomicAction a : saveActions) {
            if (fe.firedFrom(a)) {
                return;
            }
        }
    }
    String path;
    File f = FileUtil.toFile(fe.getFile());
    synchronized (modifiedMetadataPaths) {
        if (f.equals(resolveFile(PROJECT_XML_PATH))) {
            if (modifiedMetadataPaths.contains(PROJECT_XML_PATH)) {
                //#68872: don't do anything if the given file has non-saved changes:
                return ;
            }
            path = PROJECT_XML_PATH;
            projectXmlValid = false;
        } else if (f.equals(resolveFile(PRIVATE_XML_PATH))) {
            if (modifiedMetadataPaths.contains(PRIVATE_XML_PATH)) {
                //#68872: don't do anything if the given file has non-saved changes:
                return ;
            }
            path = PRIVATE_XML_PATH;
            privateXmlValid = false;
        } else {
            LOG.log(Level.WARNING, "#184132: unexpected file change in {0}; possibly deleted project?", f);
            return;
        }
    }
    fireExternalChange(path);
}
 
Example #14
Source File: PropertiesEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Helper method. Saves this entry. */
    private void saveThisEntry() throws IOException {
        FileSystem.AtomicAction aa = new SaveImpl(this);
        FileUtil.runAtomicAction(aa);
//        super.saveDocument();
        // #32777 - it can happen that save operation was interrupted
        // and file is still modified. Mark it unmodified only when it is really
        // not modified.
        if (!env.isModified()) {
            myEntry.setModified(false);
        }
    }
 
Example #15
Source File: AbstractTestUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new Data Object
 */
public static DataObject createDataObject(DataFolder folder, final String name, final String extension, final String content) throws IOException {
    final FileObject targetFolder = folder.getPrimaryFile();
    FileSystem filesystem = targetFolder.getFileSystem();
    
    final FileObject[] fileObject = new FileObject[1];
    AtomicAction fsAction = new AtomicAction() {
        public void run() throws IOException {
            FileObject fo = targetFolder.createData(name, extension);
            FileLock lock = null;
            try {
                lock = fo.lock();
                OutputStream out = fo.getOutputStream(lock);
                out = new BufferedOutputStream(out, 999);
                Writer writer = new OutputStreamWriter(out, "UTF8");        // NOI18N
                writer.write(content + '\n');  // NOI18N                    
                writer.flush();
                writer.close();
                
                // return DataObject
                lock.releaseLock();
                lock = null;
                
                fileObject[0] = fo;
                
            } finally {
                if (lock != null) lock.releaseLock();
            }
        }
    };
    
    filesystem.runAtomicAction(fsAction);
    return DataObject.find(fileObject[0]);
}
 
Example #16
Source File: EditorConfigProcessor.java    From editorconfig-netbeans with MIT License 5 votes vote down vote up
private void updateChangesInEditorWindow(final FileInfo info) {
  LOG.log(Level.INFO, "Update changes in Editor window for: {0}", info.getPath());

      try {
        FileUtil.runAtomicAction((AtomicAction) new WriteEditorAction(info));
      } catch (IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage());
      }
}
 
Example #17
Source File: PackageRename.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void atomicSetName(final String name) {
    try {
        folder.getFileSystem().runAtomicAction(new AtomicAction() {
            @Override
            public void run() throws IOException {
                setName(name);
            }
        });
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #18
Source File: FileUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Extract jar file into folder represented by file object. If the JAR contains
* files with name filesystem.attributes, it is assumed that these files
* has been created by DefaultAttributes implementation and the content
* of these files is treated as attributes and added to extracted files.
* <p><code>META-INF/</code> directories are skipped over.
*
* @param fo file object of destination folder
* @param is input stream of jar file
* @exception IOException if the extraction fails
* @deprecated Use of XML filesystem layers generally obsoletes this method.
*             For tests, use {@link org.openide.util.test.TestFileUtils#unpackZipFile}.
*/
@Deprecated
public static void extractJar(final FileObject fo, final InputStream is)
throws IOException {
    FileSystem fs = fo.getFileSystem();

    fs.runAtomicAction(
        new FileSystem.AtomicAction() {
            public void run() throws IOException {
                extractJarImpl(fo, is);
            }
        }
    );
}
 
Example #19
Source File: FileUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #20
Source File: AntProjectSupportTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@RandomlyFails // NB-Core-Build #3638
public void testInitiallyInvalidScript() throws Exception {
    final FileObject fo = scratch.createData("x.ant");
    assertEquals("it is an APDO", AntProjectDataObject.class, DataObject.find(fo).getClass());
    AntProjectCookie apc = new AntProjectSupport(fo);
    assertNull("invalid", apc.getDocument());
    assertNotNull("invalid", apc.getParseException());
    MockChangeListener l = new MockChangeListener();
    apc.addChangeListener(l);
    //l.expectNoEvents(5000);
    fo.getFileSystem().runAtomicAction(new AtomicAction() {
        public void run() throws IOException {
            OutputStream os = fo.getOutputStream();
            try {
                os.write("<project default='x'><target name='x'/></project>".getBytes("UTF-8"));
            } finally {
                os.close();
            }
        }
    });
    l.expectEvent(5000);
    /* XXX parseException usually turns out to be non-null here still; too many threads running around, who knows what is going on
    Throwable x = apc.getParseException();
    if (x != null) {
        throw (AssertionFailedError) new AssertionFailedError("now valid (no exc)").initCause(x);
    }
    Document doc = apc.getDocument();
    assertNotNull("now valid (have doc)", doc);
    assertEquals("one target", 1, doc.getElementsByTagName("target").getLength());
     */
}
 
Example #21
Source File: FolderOrder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Changes the order of data objects.
 */
public void setOrder (final DataObject[] arr) throws IOException {
    // #251398: setOrder is internally synchronized(this) and fires FS events
    // while holding the lock over this FolderOrder, although the Order is
    // already updated. FSAA will defer event dispatch until after the FolderOrder
    // lock is released. Also helps Listeners to see the oder consistent, not
    // partially set as individual FObj attributes are changed.
    folder.getFileSystem().runAtomicAction(new AtomicAction() {
        public void run() throws IOException {
            doSetOrder(arr);
        }
    });
}
 
Example #22
Source File: PropertiesStorage.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void runAtomic(final Runnable run) {
    try {
        configRoot.getFileSystem().runAtomicAction(new AtomicAction() {
            public void run() throws IOException {
                run.run();
            }
        });
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
Example #23
Source File: FsEventFromAtomicActionTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFiredFromOneAtomicAction() throws Exception {
    final File workDir = getWorkDir();
    final FileObject workDirFo = FileUtil.toFileObject(workDir);

    final AtomicAction myAtomicAction = new AtomicAction() {
        @Override
        public void run() throws IOException {
            try {
                for (int i = 0; i < RUNS; ++i) {
                    FileUtil.createData(workDirFo, FILE_PREFIX + i);
                }
            } catch (IOException ex) {
                // checked later
            }
        }
    };
    MyFileChangeListener myChangeListener = new MyFileChangeListener(myAtomicAction);
    FileUtil.addRecursiveListener(myChangeListener, workDir);

    assertEquals("files before", 0, workDir.list().length);

    FileUtil.runAtomicAction(myAtomicAction);

    assertEquals("files after", RUNS, workDir.list().length);
    assertEquals(printEvents(myChangeListener.notFromAtomicAction), 0, myChangeListener.notFromAtomicAction.size());
    assertEquals("events", RUNS, myChangeListener.events.get());
}
 
Example #24
Source File: ModuleList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Delete a module from disk.
 */
private void deleteFromDisk(final Module m, final DiskStatus status) throws IOException {
    final String nameDashes = m.getCodeNameBase().replace('.', '-'); // NOI18N
    //final long expectedTime = status.lastApprovedChange;
    FileSystem.AtomicAction aa = new FileSystem.AtomicAction() {
        public void run() throws IOException {
            FileObject xml = folder.getFileObject(nameDashes, "xml"); // NOI18N
            if (xml == null) {
                // Could be that the XML was already deleted externally, etc.
                LOG.fine("ModuleList: " + m + "'s XML already gone from disk");
                return;
            }
            //if (xml == null) throw new IOException("No such XML file: " + nameDashes + ".xml"); // NOI18N
            if (status.dirty) {
                // Someone wrote to the file since we did. Don't delete it blindly!
                // XXX should this throw an exception, or just warn??
                throw new IOException("Unapproved external change to " + xml); // NOI18N
            }
            LOG.fine("ModuleList: deleting " + xml);
            /*
            if (xml.lastModified().getTime() != expectedTime) {
                // Someone wrote to the file since we did. Don't delete it blindly!
                throw new IOException("Unapproved external change to " + xml); // NOI18N
            }
             */
            xml.delete();
            FileObject ser = folder.getFileObject(nameDashes, "ser"); // NOI18N
            if (ser != null) {
                LOG.fine("(and also " + ser + ")");
                ser.delete();
            }
        }
    };
    myAtomicActions.add(aa);
    folder.getFileSystem().runAtomicAction(aa);
}
 
Example #25
Source File: ModuleList.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Check if a given file event in the Modules/ folder was a result
 * of our own manipulations, as opposed to some other code (or polled
 * refresh) manipulating one of these XML files. See #15573.
 */
private boolean isOurs(FileEvent ev) {
    for (FileSystem.AtomicAction action : myAtomicActions) {
        if (ev.firedFrom(action)) {
            return true;
        }
    }
    return false;
}
 
Example #26
Source File: ModuleList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    LOG.fine("ModuleList: will process outstanding external XML changes");
    mgr.mutexPrivileged().enterWriteAccess();
    try {
        folder.getFileSystem().runAtomicAction(new FileSystem.AtomicAction() {
            public void run() throws IOException {
                // 1. For any dirty XML for which status exists but reloadable differs from XML: change.
                // 2. For any XML for which we have no status: create & create status, as disabled.
                // 3. For all dirty XML which says enabled but status says disabled: batch-enable as possible.
                //    (Where not possible, mark disabled in XML??)
                // 4. For all dirty XML which says disabled but status says enabled: batch-disable plus others.
                // 5. For all status for which no XML exists: batch-disable plus others, then delete.
                // 6. For any dirty XML for which jar/autoload/eager/release/specversion differs from
                //    actual state of module: warn but do nothing.
                // 7. For now, ignore any changes in *.ser.
                // 8. For any dirty XML for which status now exists: replace diskProps with contents of XML.
                // 9. Mark all statuses clean.
                // Code name to module XMLs found on disk:
                Map<String,FileObject> xmlfiles = prepareXMLFiles();
                // Code name to properties for dirty XML or XML sans status only.
                Map<String,Map<String,Object>> dirtyprops = prepareDirtyProps(xmlfiles);
                // #27106: do not listen to changes we ourselves produce.
                // It only matters if statuses has not been updated before
                // the changes are fired.
                listening = false;
                try {
                    stepCheckReloadable(dirtyprops);
                    stepCreate(xmlfiles, dirtyprops);
                    stepEnable(dirtyprops);
                    stepDisable(dirtyprops);
                    stepDelete(xmlfiles);
                    stepCheckMisc(dirtyprops);
                    stepCheckSer(xmlfiles, dirtyprops);
                } finally {
                    listening = true;
                    stepUpdateProps(dirtyprops);
                    stepMarkClean();
                }
            }
        });
        LOG.fine("ModuleList: finished processing outstanding external XML changes");
    } catch (IOException ioe) {
        LOG.log(Level.WARNING, null, ioe);
    } finally {
        mgr.mutexPrivileged().exitWriteAccess();
    }
}
 
Example #27
Source File: ApplicationTypeManager.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void storeType(final ApplicationType type) throws IOException {
    Repository.getDefault().getDefaultFileSystem().runAtomicAction(new AtomicAction() {

        @Override
        public void run() throws IOException {
            String defName = type.getDefName();
            if (defName == null) {
                do {
                    defName = calculateDefName(type);
                } while (defRepository.getFileObject(defName) != null);
                type.setDefName(defName);
            }

            FileObject defFolder = defRepository.getFileObject(defName);
            if (defFolder == null) {
                defFolder = defRepository.createFolder(defName);
            }
            defFolder.setAttribute("displayName", type.getName());
            defFolder.setAttribute("mainClass", type.getMainClass());
            if (type.getInfoURL() != null) {
                defFolder.setAttribute("url", type.getInfoURL().toString());
            } else {
                defFolder.setAttribute("url", null);
            }
            if (type.getIconURL() != null) {
                FileObject iconFile = defFolder.getFileObject("icon.png");
                if (iconFile == null) {
                    iconFile = defFolder.createData("icon.png");
                }
                BufferedImage bIcon = ImageIO.read(type.getIconURL());

                FileLock lock = iconFile.lock();
                OutputStream os = iconFile.getOutputStream(lock);
                try {
                    ImageIO.write(ImageUtils.resizeImage(bIcon, 16, 16), "png", os);
                    defFolder.setAttribute("icon", iconFile.getURL().toString());
                    iconFile = null;
                } finally {
                    os.close();
                    lock.releaseLock();
                }
            } else {
                defFolder.setAttribute("icon", null);
            }
        }
    });
}
 
Example #28
Source File: ModuleList.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** Write information about a module out to disk.
 * If the old status is given as null, this is a newly
 * added module; create an appropriate status and return it.
 * Else update the existing status and return it (it is
 * assumed properties are already updated).
 * Should write the XML and create/rewrite/delete the serialized
 * installer file as needed.
 */
private DiskStatus writeOut(Module m, DiskStatus old) throws IOException {
    final DiskStatus nue;
    if (old == null) {
        nue = new DiskStatus();
        nue.module = m;
        nue.setDiskProps(computeProperties(m));
    } else {
        nue = old;
    }
    FileSystem.AtomicAction aa = new FileSystem.AtomicAction() {
        public void run() throws IOException {
            if (nue.file == null) {
                nue.file = FileUtil.createData(folder, ((String)nue.diskProps.get("name")).replace('.', '-') + ".xml"); // NOI18N
            } else {
                // Just verify that no one else touched it since we last did.
                if (/*nue.lastApprovedChange != nue.file.lastModified().getTime()*/nue.dirty) {
                    // Oops, something is wrong. #156764 - log at lower level.
                    LOG.log(Level.INFO, null, new IOException("Will not clobber external changes in " + nue.file));
                    return;
                }
            }
            LOG.fine("ModuleList: (re)writing " + nue.file);
            FileLock lock = nue.file.lock();
            try {
                OutputStream os = nue.file.getOutputStream(lock);
                try {
                    writeStatus(nue.diskProps, os);
                } finally {
                    os.close();
                }
            } finally {
                lock.releaseLock();
            }
            //nue.lastApprovedChange = nue.file.lastModified().getTime();
        }
    };
    myAtomicActions.add(aa);
    folder.getFileSystem().runAtomicAction(aa);
    return nue;
}
 
Example #29
Source File: AntProjectHelper.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void runSaveAA(AtomicAction action) throws IOException {
    synchronized (saveActions) {
        saveActions.add(action);
    }
    dir.getFileSystem().runAtomicAction(action);
}
 
Example #30
Source File: ProjectProperties.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void runSaveAA(AtomicAction action) throws IOException {
    synchronized (saveActions) {
        saveActions.add(action);
    }
    dir().getFileSystem().runAtomicAction(action);
}