Java 类org.openide.util.EditableProperties 实例源码

项目:incubator-netbeans    文件:ProjectConfiguration.java   
private static Project suiteProject(Project prj) {
    try {
        FileObject suiteProperties = prj.getProjectDirectory().getFileObject("nbproject/suite.properties");

        if (suiteProperties == null) return null; //not a suite component

        EditableProperties p = new EditableProperties(false);

        try (InputStream is = suiteProperties.getInputStream()) {
            p.load(is);
        }

        String suiteDir = p.get("suite.dir").replace("${basedir}/", "");
        FileObject suiteProjectLoc = suiteDir != null ? prj.getProjectDirectory().getFileObject(suiteDir) : null;

        return suiteProjectLoc != null ? ProjectManager.getDefault().findProject(suiteProjectLoc) : null;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return null;
    }
}
项目:incubator-netbeans    文件:PropertiesStorage.java   
public EditableProperties load() throws IOException {
    Statistics.StopWatch sw = Statistics.getStopWatch(Statistics.LOAD, true);
    try {
        EditableProperties retval = new EditableProperties(true);
        FileObject file = toPropertiesFile(false);
        if (file != null) {
            try {
                InputStream is = file.getInputStream();
                try {
                    retval.load(is);
                } finally {
                    is.close();
                }
            } catch (IllegalArgumentException x) { // #167745
                Logger.getLogger(PropertiesStorage.class.getName()).log(Level.INFO, "While loading " + file, x);
                file.delete();
            }
        }
        return retval;
    } finally {
        sw.stop();
    }
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
/**
 * Add **\/*.mirah to build.classes.excludes.
 */
protected final boolean addExcludes() {
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        String exclude = props.getProperty(EXCLUDE_PROPERTY);
        //props.setProperty("mirahc.ant.classpath", "foobarfoo");
        if (!exclude.contains(EXCLUSION_PATTERN)) {
            //System.out.println(EXCLUSION_PATTERN+" is not found");
            props.setProperty(EXCLUDE_PROPERTY, exclude + "," + EXCLUSION_PATTERN); // NOI18N
            storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        } else {
            //System.out.println("Exclusion pattern "+EXCLUSION_PATTERN+" was found");
        }
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
/**
 * Inverse operation to {@link #addExcludes()}.
 * Remove **\/*.mirah from build.classes.excludes.
 */
protected final boolean removeExcludes() {
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        String exclude = props.getProperty(EXCLUDE_PROPERTY);
        if (exclude.contains("," + EXCLUSION_PATTERN)) {
            exclude = exclude.replace("," + EXCLUSION_PATTERN, "");
            props.setProperty(EXCLUDE_PROPERTY, exclude);
            storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        }
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
private static void storeEditableProperties(final Project prj, final  String propertiesPath, final EditableProperties ep)
    throws IOException {
    try {
        ProjectManager.mutex().writeAccess(new Mutex.ExceptionAction<Void>() {
            @Override
            public Void run() throws IOException {
                FileObject propertiesFo = prj.getProjectDirectory().getFileObject(propertiesPath);
                if (propertiesFo!=null) {
                    OutputStream os = null;
                    try {
                        os = propertiesFo.getOutputStream();
                        ep.store(os);
                    } finally {
                        if (os != null) {
                            os.close();
                        }
                    }
                }
                return null;
            }
        });
    } catch (MutexException ex) {
    }
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
@Override
public boolean isCurrent(){
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        int version = 0;
        if ( props.containsKey(VERSION_PROPERTY) ){
            try {
                version = Integer.parseInt(props.getProperty(VERSION_PROPERTY));
            } catch ( Throwable t){}
        }
        System.out.println("The current version is "+version);
        return isActive() &&  version >= PLUGIN_VERSION;
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }

}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
public void addModuleToSuiteProperties(String propertiesFilePath, String pluginBasePackage, String pluginName) throws IOException
{
    FileObject propFileObject = FileUtil.toFileObject(new File(propertiesFilePath));

    EditableProperties ep = loadProperties(propFileObject);
    String prop = ep.getProperty("modules");

    if (prop.trim().isEmpty())
    {
        prop = "${project." + pluginBasePackage + "}";
    }
    else
    {
        prop += ":${project." + pluginBasePackage + "}";
    }

    ep.setProperty("modules", prop);
    ep.setProperty("project." + pluginBasePackage, pluginName);

    storeProperties(propFileObject, ep);
}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
private void storeProperties(FileObject propsFO, EditableProperties props) throws IOException
{
    FileLock lock = propsFO.lock();

    try
    {
        OutputStream os = propsFO.getOutputStream(lock);

        try
        {
            props.store(os);
        }
        finally
        {
            os.close();
        }
    }
    finally
    {
        lock.releaseLock();
    }
}
项目:incubator-netbeans    文件:PropertiesStorage.java   
public void save(final EditableProperties properties) throws IOException {
     if (isModified) {
         Statistics.StopWatch sw = Statistics.getStopWatch(Statistics.FLUSH, true);
         try {
             isModified = false;
             if (!properties.isEmpty()) {
                 OutputStream os = null;
                 try {
                     os = outputStream();
                     properties.store(os);
                 } finally {
                     if (os != null) {
    LOGGER.log(Level.FINE, "Closing output-stream for file {0} in {1}.", new Object[]{filePath, folderPath});
    os.close();
}
                 }
             } else {
                 FileObject file = toPropertiesFile();
                 if (file != null) {
                     file.delete();
                 }
                 FileObject folder = toFolder();
                 while (folder != null && folder != preferencesRoot() && folder.getChildren().length == 0) {
                     folder.delete();
                     folder = folder.getParent();
                 }
             }
         } finally {
             sw.stop();
         }
     }
 }
项目:incubator-netbeans    文件:NbPreferences.java   
private void putAllProperties(EditableProperties props, boolean clear) {
    synchronized (lock) {
        if (clear) {
            properties().clear();
        }
        properties().putAll(props);
    }
}
项目:incubator-netbeans    文件:TestFileStorage.java   
public void testBasic() throws IOException {
    //preconditions
    noFileRepresentationAssertion();

    //load doesn't change file layout
    EditableProperties p = instance.load();
    p.put("key", "value");//NOI18N
    noFileRepresentationAssertion();

    //save doesn't change file layout if not marked modified
    instance.save(p);
    noFileRepresentationAssertion();

    //marked modified but not saved
    instance.markModified();
    noFileRepresentationAssertion();

    if (!instance.isReadOnly()) {
        //saved after marked modified
        instance.save(p);            
        fileRepresentationAssertion();
    } else {
        try {
            //saved after marked modified
            instance.save(p);                
            fail();
        } catch (IOException ex) {}
        noFileRepresentationAssertion();
    }
}
项目:incubator-netbeans    文件:OptionsExportModel.java   
/** Returns properties from relative path in zip or userdir.
 * @param relativePath relative path
 * @return properties from relative path in zip or userdir.
 * @throws IOException if cannot open stream
 */
private EditableProperties getProperties(String relativePath) throws IOException {
    EditableProperties properties = new EditableProperties(false);
    InputStream in = null;
    try {
        in = getInputStream(relativePath);
        properties.load(in);
    } finally {
        if (in != null) {
            in.close();
        }
    }
    return properties;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
protected final boolean addMacrosClasspath(){
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        props.setProperty(MIRAH_MACROS_JARDIR_PROPERTY, "lib/mirah/macros"); // NOI18N
        storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        FileObject projectFO = project.getProjectDirectory();

        FileUtil.createFolder(new File(projectFO.getPath(), "lib/mirah/macros"));
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
/**
 * Disables compile on save for the project.
 *
 * @return true if CoS were disabled, false otherwise
 */
protected final boolean addDisableCompileOnSaveProperty() {
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        props.put(DISABLE_COMPILE_ON_SAVE, "true");
        storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
private final boolean addCN1LibProperty(){
    try {
        EditableProperties props = getEditableProperties(project, CN1_LIBRARY_PROPERTIES_PATH);
        props.put("codename1.is_library", "true");
        storeEditableProperties(project, CN1_LIBRARY_PROPERTIES_PATH, props);
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
/**
 * Inverse operation to {@link #addDisableCompileOnSaveProperty()}.
 * Enabled compile on save for the project.
 *
 * @return true if CoS were enabled, false otherwise
 */
protected final boolean removeDisableCompileOnSaveProperty() {
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        props.remove(DISABLE_COMPILE_ON_SAVE);
        storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return false;
}
项目:mirah-nbm    文件:AbstractMirahExtender.java   
@Override
public boolean update(){
    try {
        EditableProperties props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
        int version = 0;
        if ( props.containsKey(VERSION_PROPERTY) ){
            try {
                version = Integer.parseInt(props.getProperty(VERSION_PROPERTY));
            } catch ( Throwable t){}
        }

        if ( !removeExcludes() || !removeBuildScript() || !addExcludes() || !addBuildScript()){
            System.out.println("Failed to update");
            return false;
        }

        if ( version < PLUGIN_VERSION){
            props = getEditableProperties(project, PROJECT_PROPERTIES_PATH);
            props.setProperty(VERSION_PROPERTY, String.valueOf(PLUGIN_VERSION));
            storeEditableProperties(project, PROJECT_PROPERTIES_PATH, props);
        }


        return true;
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
        return false;
    }
}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
public boolean basePackageAlreadyExistsInModuleSuite(FileObject fo, String basePackage)
{
    try
    {
        EditableProperties ep = loadProperties(fo);
        return (!(ep.getProperty("project." + basePackage) == null));
    }
    catch (IOException ex)
    {
        Exceptions.printStackTrace(ex);
        return false;
    }
}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
public void setLicenseInProjectProperties(String projPropPath, String licenseLoc) throws IOException
{
    File projPropFile = new File(projPropPath);
    FileObject fo = FileUtil.toFileObject(projPropFile);

    String licensePath = "src/" + licenseLoc.replace("\\", "/");

    EditableProperties ep = loadProperties(fo);
    ep.setProperty("license.file", licensePath);
    storeProperties(fo, ep);
}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
public void createBundlePropertiesFile(FileObject fo, String pluginName) throws IOException
{
    EditableProperties ep = loadProperties(fo);
    ep.setProperty("OpenIDE-Module-Name", pluginName);
    ep.setProperty("OpenIDE-Module-Short-Description", "A short description...");
    ep.setProperty("OpenIDE-Module-Long-Description", "A long description...");
    ep.setProperty("OpenIDE-Module-Display-Category", "jMonkeyEngine");
    storeProperties(fo, ep);
}
项目:sdk-plugin-wizard    文件:WizardUtils.java   
private EditableProperties loadProperties(FileObject propsFO) throws IOException
{
    InputStream propsIS = propsFO.getInputStream();
    EditableProperties props = new EditableProperties(true);
    try
    {
        props.load(propsIS);
    }
    finally
    {
        propsIS.close();
    }
    return props;
}
项目:nbrunwithargs    文件:PropertyHandler.java   
PropertyHandler(Project project, String propertyFilePath) {

        this.project = project;
        this.propsFO = project.getProjectDirectory()
                .getFileObject(propertyFilePath);
        if (this.propsFO != null) {
            this.props = new EditableProperties(false);
        }

    }
项目:incubator-netbeans    文件:UseNbBundleMessages.java   
@Override protected void performRewrite(JavaFix.TransformationContext ctx) throws Exception {
    WorkingCopy wc = ctx.getWorkingCopy();
    TreePath treePath = ctx.getPath();
            TreeMaker make = wc.getTreeMaker();
            if (treePath.getLeaf().getKind() == Kind.METHOD_INVOCATION) {
                MethodInvocationTree mit = (MethodInvocationTree) treePath.getLeaf();
                CompilationUnitTree cut = wc.getCompilationUnit();
                boolean imported = false;
                String importBundleStar = cut.getPackageName() + ".Bundle.*";
                for (ImportTree it : cut.getImports()) {
                    if (it.isStatic() && it.getQualifiedIdentifier().toString().equals(importBundleStar)) {
                        imported = true;
                        break;
                    }
                }
                if (!imported) {
                    wc.rewrite(cut, make.addCompUnitImport(cut, make.Import(make.Identifier(importBundleStar), true)));
                }
                List<? extends ExpressionTree> args = mit.getArguments();
                List<? extends ExpressionTree> params;
                if (args.size() == 3 && args.get(2).getKind() == Kind.NEW_ARRAY) {
                    params = ((NewArrayTree) args.get(2)).getInitializers();
                } else {
                    params = args.subList(2, args.size());
                }
                wc.rewrite(mit, make.MethodInvocation(Collections.<ExpressionTree>emptyList(), make.Identifier(toIdentifier(key)), params));
            } // else annotation value, nothing to change
            if (!isAlreadyRegistered) {
                EditableProperties ep = new EditableProperties(true);
                InputStream is = ctx.getResourceContent(bundleProperties);
                try {
                    ep.load(is);
                } finally {
                    is.close();
                }
                List<ExpressionTree> lines = new ArrayList<ExpressionTree>();
                for (String comment : ep.getComment(key)) {
                    lines.add(make.Literal(comment));
                }
                lines.add(make.Literal(key + '=' + ep.remove(key)));
                TypeElement nbBundleMessages = wc.getElements().getTypeElement("org.openide.util.NbBundle.Messages");
                if (nbBundleMessages == null) {
                    throw new IllegalArgumentException("cannot resolve org.openide.util.NbBundle.Messages");
                }
                GeneratorUtilities gu = GeneratorUtilities.get(wc);
                Tree enclosing = findEnclosingElement(wc, treePath);
                Tree modifiers;
                Tree nueModifiers;
                ExpressionTree[] linesA = lines.toArray(new ExpressionTree[lines.size()]);
                switch (enclosing.getKind()) {
                case METHOD:
                    modifiers = wc.resolveRewriteTarget(((MethodTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case VARIABLE:
                    modifiers = wc.resolveRewriteTarget(((VariableTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                case COMPILATION_UNIT:
                    modifiers = wc.resolveRewriteTarget(enclosing);
                    nueModifiers = gu.appendToAnnotationValue((CompilationUnitTree) modifiers, nbBundleMessages, "value", linesA);
                    break;
                default:
                    modifiers = wc.resolveRewriteTarget(((ClassTree) enclosing).getModifiers());
                    nueModifiers = gu.appendToAnnotationValue((ModifiersTree) modifiers, nbBundleMessages, "value", linesA);
                }
                wc.rewrite(modifiers, nueModifiers);
            // XXX remove NbBundle import if now unused
            OutputStream os = ctx.getResourceOutput(bundleProperties);
            try {
                ep.store(os);
            } finally {
                os.close();
            }
        }
    // XXX after JavaFix rewrite, Savable.save (on DataObject.find(src)) no longer works (JG13 again)
}
项目:incubator-netbeans    文件:ArchiveTimeStamps.java   
public Store() {
    lock = new Object();
    properties = new EditableProperties(true);
}
项目:incubator-netbeans    文件:NbPreferences.java   
EditableProperties load() throws IOException;
项目:incubator-netbeans    文件:NbPreferences.java   
void save(final EditableProperties properties) throws IOException;