org.ini4j.Config Java Examples

The following examples show how to use org.ini4j.Config. 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: IniModuleConfigParser.java    From nuls-v2 with MIT License 7 votes vote down vote up
@Override
public Map<String, Map<String,ConfigurationLoader.ConfigItem>> parse(String configFile,InputStream inputStream) throws Exception {
    Config cfg = new Config();
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(inputStream);
    Map<String,Map<String,ConfigurationLoader.ConfigItem>> res = new HashMap<>(ini.size());
    ini.values().forEach(s-> {
        Map<String,ConfigurationLoader.ConfigItem> domainValues = new HashMap<>(s.size());
        s.forEach((key, value) -> domainValues.put(key, new ConfigurationLoader.ConfigItem(configFile, value)));
        res.put(s.getName(),domainValues);
    });
    Log.debug("{},加载配置:{}",configFile,res);
    return res;
}
 
Example #2
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Read sdk.ini file (or file tree with includes) from the given location. 
 * @param xdsHomePath - folder to search sdk.ini file
 */
public SdkIniFileReader(String xdsHomePath) {
	aSdk        = new ArrayList<Sdk>();
	sbErrLog    = new StringBuilder();
	
	try {
	    Ini ini = loadFile(xdsHomePath, MAIN_INI_FILE_NAME, true);
	    if (ini != null) {
            Section global = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME);
            List<String> imports = global.getAll(IMPORT_PROPERTY);
            if ((imports == null) || imports.isEmpty()) {
                processIniFile(xdsHomePath, MAIN_INI_FILE_NAME);
            } else {
                for (String import_file_name: imports) {
                    processIniFile(xdsHomePath, import_file_name);
                }
            }
	    }
       } catch (Exception e) {
           LogHelper.logError(e);
           aSdk.clear();
           setError(e.getMessage());
       }
	
}
 
Example #3
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
   * @param basePath  the base path to attach to, if relative file name is used
   * @param fileName  the name of the file to be loaded 
   * @param enableMultiOption  the state of multi-option configuration flag  
   */
private Ini loadFile ( String basePath, String fileName
                     , boolean enableMultiOption ) throws Exception 
{
    String full_name = FilenameUtils.concat(basePath, fileName);
    File file = new File(full_name); 
       if (file.exists() && file.isFile()) {
           Ini ini = new Wini();
           Config config = ini.getConfig();
           
           config.setMultiSection(true);
           config.setMultiOption(enableMultiOption);
           config.setGlobalSection(true);
           config.setComment(true);

           ini.setFile(file);
           ini.setComment(COMMENT_LINE_CHARS);
           try(InputStreamReader inputStreamReader = TextEncoding.getInputStreamReader(file)){
           	ini.load(inputStreamReader);
           }
           return ini;
       }
    return null;
}
 
Example #4
Source File: IniUtil.java    From spring-boot-plus with Apache License 2.0 5 votes vote down vote up
public static Map<String,String> parseIni(String string) {
    Config config = new Config();
    config.setGlobalSection(true);
    config.setGlobalSectionName("");
    Ini ini = new Ini();
    ini.setConfig(config);
    try {
        ini.load(new StringReader(string));
        Profile.Section section = ini.get("");
        return section;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #5
Source File: DBUtils.java    From nuls-v2 with MIT License 5 votes vote down vote up
private static String getProjectDbPath() throws Exception {
        Config cfg = new Config();
        cfg.setMultiSection(true);
        Ini ini = new Ini();
        ini.setConfig(cfg);
        ini.load(new File("module.ncf"));  //可以读取到nuls_2.0项目根目录下的module.ncf,在生产环境读到jar同目录下的module.ncf
        IniEntity ie = new IniEntity(ini);
        String filePath = ie.getCfgValue("Module", "DataPath");
//        Log.debug(filePath); //读取配置的data文件夹路径
        return filePath;
    }
 
Example #6
Source File: MyKernelBootstrap.java    From nuls-v2 with MIT License 5 votes vote down vote up
/**
 * 启动模块
 * @param modules
 * @throws Exception
 */
private void startModule(File modules) throws Exception {
    Config cfg = new Config();
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(new File(modules.getAbsolutePath() + File.separator + "Module.ncf"));
    IniEntity ie = new IniEntity(ini);
    String managed = ie.getCfgValue("Core", "Managed");
    if ("1".equals(managed)) {
        ThreadUtils.createAndRunThread("module-start", () -> {
            Process process = null;
            try {
                String cmd = modules.getAbsolutePath() + File.separator + "start.sh "
                        + " --jre " + System.getProperty("java.home")
                        + " --managerurl " + "ws://127.0.0.1:7771/ "
                        + (StringUtils.isNotBlank(logPath) ? " --logpath " + logPath: "")
                        + (StringUtils.isNotBlank(dataPath) ? " --datapath " + dataPath : "")
                        + (StringUtils.isNotBlank(logLevel) ? " --loglevel " + logLevel : "")
                        + " --debug " + debug
                        + (StringUtils.isNotBlank(config) ? " --config " + config : "")
                        + " -r ";
                Log.info("run script:{}",cmd);
                process = Runtime.getRuntime().exec(cmd);
                synchronized (MODULE_STOP_LIST_SCRIPT){
                    MODULE_STOP_LIST_SCRIPT.add(modules.getAbsolutePath() + File.separator + "stop.sh ");
                }
                printRuntimeConsole(process);
            } catch (IOException e) {
                log.error("启动模块异常",e);
            }
        });
    }
}
 
Example #7
Source File: SvnConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
     * Creates a new instance
     */
    private SvnConfigFiles() {      
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(Subversion.class.getClassLoader());
        try {
            Config.getGlobal().setEscape(false); // do not escape characters
            // copy config file
            config = copyConfigFileToIDEConfigDir("config", new ConfigIniFilePatcher());    // NOI18N
            // get the system servers file
            svnServers = loadSystemIniFile("servers");
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }
//        SvnModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this);
    }
 
Example #8
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance
 */
private HgConfigFiles() {
    bIsProjectConfig = false;
    // get the system hgrc file
    Config.getGlobal().setEscape(false); // escaping characters disabled
    if(Utilities.isWindows()) {
        // on windows both Mercurial.ini and .hgrc are allowed
        hgrc = loadSystemAndGlobalFile(new String[] {WINDOWS_HG_RC_FILE, "." + HG_RC_FILE}); //NOI18N
    } else {
        hgrc = loadSystemAndGlobalFile(new String[] {HG_RC_FILE});
    }
}
 
Example #9
Source File: HgConfigFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public HgConfigFiles(File file) {
    Config.getGlobal().setEscape(false); // escaping characters disabled
    bIsProjectConfig = true;
    dir = file;        
    // <repository>/.hg/hgrc on all platforms
    hgrc = loadRepoHgrcFile(file);
}
 
Example #10
Source File: ConfigLoader.java    From nuls with MIT License 5 votes vote down vote up
public static IniEntity loadIni(String fileName) throws IOException {
    Config cfg = new Config();
    URL url = ConfigLoader.class.getClassLoader().getResource(fileName);
    cfg.setMultiSection(true);
    Ini ini = new Ini();
    ini.setConfig(cfg);
    ini.load(url);
    return new IniEntity(ini);
}
 
Example #11
Source File: PersistentTokenDescriptor.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public void preferenciesFromIni(Ini ini) {
    String s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, styleId);
    if (s != null) {
        styleWhenEnabled = Integer.parseInt(s);
    } else {
        styleWhenEnabled = getDefaultStyle();
    }
    
    s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, disabledId);
    if (s != null) {
        isDisabled = (Integer.parseInt(s) != 0);
    } else {
        isDisabled = false;
    }
    
    s = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, colorId);
    if (s != null) {
        rgbWhenEnabled = StringConverter.asRGB(s, getDefaultRgb());
    } else {
        rgbWhenEnabled = getDefaultRgb();
    }
    
    if (isDisabled && iTokens != null) {
        PersistentTokenDescriptor pt = iTokens.getDefaultColoring();
        TextAttributeDescriptor ta = pt.getTextAttribute();
        if (ta != null) {
            setTextAttribute(new TextAttributeDescriptor(ta.getForeground(), null, ta.getStyle()));
        }
    } else {
    	setTextAttribute(new TextAttributeDescriptor(rgbWhenEnabled, null, styleWhenEnabled));
    }
}
 
Example #12
Source File: Inis.java    From buck with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
public static Ini makeIniParser(boolean enable_includes) {
  Ini ini = new Ini();
  Config config = new Config();
  config.setEscape(false);
  config.setEscapeNewline(true);
  config.setMultiOption(false);
  config.setInclude(enable_includes);
  ini.setConfig(config);
  return ini;
}
 
Example #13
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
private void processIniFile(String basePath, String fileName) throws Exception {
    Ini ini = loadFile(basePath, fileName, false);
    String homePath = ini.getFile().getParentFile().getCanonicalPath();

    Sdk sdk = SdkManager.createSdk();
    sdk.setPropertyInternal(Property.XDS_HOME, homePath);

    for (Sdk.Property property: Sdk.Property.values()) {
        String val = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, property.key); // '?' for the default (global) section
        if (val != null) {
            switch (property) {
            case XDS_NAME:
                sdk.setPropertyInternal(Property.XDS_NAME, val);
                break;
            case XDS_HOME:
                sdk.setPropertyInternal(Property.XDS_HOME, makePath(homePath, val));
                break;
            case XDS_EXE_EXTENSION:
                sdk.setPropertyInternal(Property.XDS_EXE_EXTENSION, val);
                break;
            case XDS_PRIM_EXTENSIONS:
                sdk.setPropertyInternal(Property.XDS_PRIM_EXTENSIONS, val);
                break;
            default:
                if ( Sdk.Property.XDS_XSHELL_FORMAT.equals(property) 
                  || Sdk.Property.XDS_DIRS_TO_CREATE.equals(property)
                  || Sdk.Property.XDS_FOLDER_PRJ_FILE.equals(property)
                  || Sdk.Property.XDS_FOLDER_MAIN_MODULE.equals(property)) 
                {
                    sdk.setPropertyInternal(property, val);
                } else {
                    sdk.setPropertyInternal(property, makePathNS(homePath, val));
                }
            }
        }
            
        for (Sdk.Tag tag : property.possibleTags) {
            String tval = ini.get(Config.DEFAULT_GLOBAL_SECTION_NAME, property.key + "." + tag.tagName); //$NON-NLS-1$
            if (tval != null) {
                sdk.setTag(property, tag, tval);
            }
        }
    }
    
    adjustSettings(ini.getFile(), sdk);
    
    // Get additional settings from xds.ini etc.:
    addSettingsFromLocation(sdk);

    processEnvironmentSection(sdk, ini);
    processToolSections(sdk, ini);
    
    aSdk.add(sdk);        
}