org.ini4j.Profile.Section Java Examples

The following examples show how to use org.ini4j.Profile.Section. 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: SvnConfigFilesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void isSubsetOf(String sourceIniPath, String expectedIniPath) throws IOException {
    Ini goldenIni = new Ini(new FileInputStream(expectedIniPath));
    Ini sourceIni = new Ini(new FileInputStream(sourceIniPath));
    for(String key : goldenIni.keySet()) {
        if(!sourceIni.containsKey(key) && goldenIni.get(key).size() > 0) {
            fail("missing section " + key + " in file " + sourceIniPath);
        }

        Section goldenSection = goldenIni.get(key);
        Section sourceSection = sourceIni.get(key);

        for(String name : goldenSection.childrenNames()) {
            if(!sourceSection.containsKey(name)) {
                fail("missing name " + name + " in file " + sourceIniPath + " section [" + name + "]");
            }                
            assertEquals(goldenSection.get(name), sourceSection.get(name));
        }                
    }
}
 
Example #2
Source File: ArtifactUtils.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * This method downloads the rule sets from the NEXUS server
 */
public static boolean downloadRulesets() {

	Map<String, Double> defaultRulesetUrls = new HashMap<String, Double>();
	Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER);
	defaultRulesetUrls.put(ini.get(Constants.INI_JCA_NEXUS), Constants.MIN_JCA_RULE_VERSION);
	defaultRulesetUrls.put(ini.get(Constants.INI_BC_NEXUS), Constants.MIN_BC_RULE_VERSION);
	defaultRulesetUrls.put(ini.get(Constants.INI_TINK_NEXUS), Constants.MIN_TINK_RULE_VERSION);
	defaultRulesetUrls.put(ini.get(Constants.INI_BCJCA_NEXUS), Constants.MIN_BCJCA_RULE_VERSION);

	Iterator<Entry<String, Double>> it = defaultRulesetUrls.entrySet().iterator();
	while (it.hasNext()) {
		Entry<String, Double> pair = (Entry<String, Double>) it.next();
		String metaFilePath = pair.getKey() + File.separator + "maven-metadata.xml";
		try {
			ArtifactUtils.parseMetaData(metaFilePath, pair.getValue());
		}
		catch (IOException | ParserConfigurationException | SAXException e) {
			Activator.getDefault().logError(e);
			return false;
		}
	}
	return true;
}
 
Example #3
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 #4
Source File: SvnConfigFilesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Section getSection(File serversFile) throws FileNotFoundException, IOException {
    FileInputStream is = new FileInputStream(serversFile);
    Ini ini = new Ini();
    try {
        ini.load(is);
    } finally {
        is.close();
    }
    return ini.get("global");
}
 
Example #5
Source File: ArtifactDownload.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method fetches the artifact from the remote server using aether library
 * 
 * @param groupId group ID of the artifact
 * @param artifactId artifact ID of the artifact
 * @param version artifact version to be downloaded
 * @param classifier classifier of the artifact
 * @param packaging packaging of the artifact
 * @param localRepository destination path
 * @return location of the downloaded artifact in the local system
 * @throws IOException
 */
public static File getArtifactByAether(String groupId, String artifactId, String version, String classifier, String packaging, File localRepository) throws IOException {
	RepositorySystem repositorySystem = newRepositorySystem();
	RepositorySystemSession session = newSession(repositorySystem, localRepository);

	Artifact artifact = new DefaultArtifact(groupId, artifactId, classifier, packaging, version);
	ArtifactRequest artifactRequest = new ArtifactRequest();
	artifactRequest.setArtifact(artifact);

	List<RemoteRepository> repositories = new ArrayList<>();
	Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER);

	RemoteRepository remoteRepository = new RemoteRepository.Builder("public", "default", ini.get(Constants.INI_NEXUS_SOOT_RELEASE)).build();

	repositories.add(remoteRepository);

	artifactRequest.setRepositories(repositories);
	File result = null;

	try {
		ArtifactResult artifactResult = repositorySystem.resolveArtifact(session, artifactRequest);
		artifact = artifactResult.getArtifact();
		if (artifact != null) {
			result = artifact.getFile();
		}
	}
	catch (ArtifactResolutionException e) {
		throw new IOException("Artifact " + groupId + ":" + artifactId + ":" + version + " could not be downloaded due to " + e.getMessage());
	}

	return result;

}
 
Example #6
Source File: DefaultRulePreferences.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
public static void addDefaults() {
	Preferences rulePreferences = InstanceScope.INSTANCE.getNode(de.cognicrypt.core.Activator.PLUGIN_ID);
	String[] listOfNodes;
	try {
		listOfNodes = rulePreferences.childrenNames();
		if (listOfNodes.length == 0) {
			Section ini = Utils.getConfig().get(Constants.INI_URL_HEADER);
			List<Ruleset> listOfRulesets = new ArrayList<Ruleset>() {
		 		private static final long serialVersionUID = 1L;
		 		{
		 			add(new Ruleset(ini.get(Constants.INI_JCA_NEXUS), true));
		 			add(new Ruleset(ini.get(Constants.INI_BC_NEXUS)));
		 			add(new Ruleset(ini.get(Constants.INI_TINK_NEXUS)));
		 			add(new Ruleset(ini.get(Constants.INI_BCJCA_NEXUS)));
		 		}
		 	};
		 	for (Iterator<Ruleset> itr = listOfRulesets.iterator(); itr.hasNext();) {
	 			Ruleset ruleset = (Ruleset) itr.next();
	
	 			Preferences subPref = rulePreferences.node(ruleset.getFolderName());
	 			subPref.putBoolean("CheckboxState", ruleset.isChecked());
	 			subPref.put("FolderName", ruleset.getFolderName());
	 			subPref.put("SelectedVersion", ruleset.getSelectedVersion());
	 			subPref.put("Url", ruleset.getUrl());
	 		}
		}
	} catch (BackingStoreException e) {
		Activator.getDefault().logError(e);
	}
}
 
Example #7
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void processEnvironmentSection(Sdk sdk, Ini ini) {
       List<Section> environments = ini.getAll(ENVIRONMENT_SECTION_NAME);
       if (environments != null) {
           for (Section envSection : environments) {
               Set<Entry<String, String>> entrySet = envSection.entrySet();
               for (Entry<String, String> entry : entrySet) {
                   sdk.putEnvironmentVariable(entry.getKey(), entry.getValue());
               }
           }
       }
}
 
Example #8
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private void processToolSections(Sdk sdk, Ini ini) {
    List<Section> tools = ini.getAll(TOOL_SECTION_NAME);
    if (tools != null) {
        for (Section toolSection : tools) {
               SdkTool tool = parseTool(sdk, toolSection);
               if (tool.isValid()) {
                   sdk.addTool(tool);
               } else {
                   LogHelper.logError(tool.getErrorMessage());
               }
        }
    }
}
 
Example #9
Source File: SdkIniFileReader.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
private SdkTool parseTool(Sdk sdk, Section toolSection) {
       SdkTool tool;
    if (toolSection.containsKey("isSeparator")) { //$NON-NLS-1$
        tool = new SdkTool(); // new SdkTool() makes separator, not a tool
    } else {
           tool = new SdkTool(sdk);
    }
	for (SdkTool.Property property : SdkTool.Property.values()) {
	    String value = toolSection.get(property.key);
	    if (value != null) {
	        tool.setPropertyValue(property, value);
	    }
	}
	return tool;
}
 
Example #10
Source File: GtConfig.java    From GitToolBox with Apache License 2.0 5 votes vote down vote up
@NotNull
public static GtConfig load(@NotNull File configFile) {
  if (!configFile.exists()) {
    LOG.info("No .git/config file at " + configFile.getPath());
    return EMPTY;
  } else {
    Ini ini = new Ini();
    ini.getConfig().setMultiOption(true);
    ini.getConfig().setTree(false);

    try {
      ini.load(configFile);
    } catch (IOException exception) {
      LOG.warn(new RepoStateException("Couldn\'t load .git/config file at " + configFile.getPath(), exception));
      return EMPTY;
    }
    ImmutableSet.Builder<String> svnRemotes = ImmutableSet.builder();
    for (Entry<String, Section> section : ini.entrySet()) {
      Matcher matcher = SVN_REMOTE_SECTION.matcher(section.getKey());
      if (matcher.matches()) {
        String name = matcher.group(1);
        svnRemotes.add(name);
      }
    }
    return new GtConfig(svnRemotes);
  }
}
 
Example #11
Source File: IniTest.java    From buck with Apache License 2.0 5 votes vote down vote up
@Test
public void testSecondaryLoadOverridesOriginalDefs() throws IOException {
  Ini ini = Inis.makeIniParser(false);
  Reader originalInput =
      new StringReader(
          Joiner.on("\n")
              .join(
                  "[alias]",
                  "  buck = //src/com/facebook/buck/cli:cli",
                  "[cache]",
                  "  mode = dir"));
  Reader overrideInput =
      new StringReader(
          Joiner.on("\n")
              .join(
                  "[alias]",
                  "  test_util = //test/com/facebook/buck/util:util",
                  "[cache]",
                  "  mode ="));
  ini.load(originalInput);
  ini.load(overrideInput);

  Section aliasSection = ini.get("alias");
  assertEquals(
      "Should be the union of the two [alias] sections.",
      ImmutableMap.of(
          "buck", "//src/com/facebook/buck/cli:cli",
          "test_util", "//test/com/facebook/buck/util:util"),
      aliasSection);

  Section cacheSection = ini.get("cache");
  assertEquals(
      "Values from overrideInput should supercede those from originalInput, as appropriate.",
      ImmutableMap.of("mode", ""),
      cacheSection);
}
 
Example #12
Source File: SvnConfigFilesTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testSSL() throws MalformedURLException, IOException {
    SVNUrl url = new SVNUrl("https://feher.lo.nem.lo.com/kuon");
    RepositoryConnection rc = new RepositoryConnection(
            url.toString(),
            "usr", "psswd".toCharArray(), null, false, "/cert/file", "pssphrs".toCharArray(), -1);

    SvnModuleConfig.getDefault().insertRecentUrl(rc);
    String path = "/tmp" + File.separator + "svn" + File.separator + "config" + System.currentTimeMillis();
    System.setProperty("netbeans.t9y.svn.nb.config.path", path);
    SvnConfigFiles scf = SvnConfigFiles.getInstance();
    scf.storeSvnServersSettings(url, ConnectionType.cli);

    File serversFile = new File(path + "/servers");
    long lastMod = serversFile.lastModified();
    Section s = getSection(serversFile);
    assertNotNull(s);

    // values were written
    assertEquals("/cert/file", s.get("ssl-client-cert-file"));
    assertEquals("pssphrs", s.get("ssl-client-cert-password"));

    // nothing was changed ...
    scf.storeSvnServersSettings(url, ConnectionType.cli);
    // ... the file so also the file musn't change
    assertEquals(lastMod, serversFile.lastModified());

    // lets change the credentials ...
    rc = new RepositoryConnection(
            url.toString(),
            "usr", "psswd".toCharArray(), null, false, "/cert/file2", "pssphrs2".toCharArray(), -1);
    SvnModuleConfig.getDefault().insertRecentUrl(rc);
    scf.storeSvnServersSettings(url, ConnectionType.cli);
    s = getSection(serversFile);
    // values were written
    assertNotNull(s);
    assertNotSame(lastMod, serversFile.lastModified());
    assertEquals("/cert/file2", s.get("ssl-client-cert-file"));
    assertEquals("pssphrs2", s.get("ssl-client-cert-password"));

    // lets test a new url
    url = url.appendPath("whatever");
    rc = new RepositoryConnection(
            url.toString(),
            "usr", "psswd".toCharArray(), null, false, "/cert/file3", "pssphrs3".toCharArray(), -1);
    SvnModuleConfig.getDefault().insertRecentUrl(rc);
    lastMod = serversFile.lastModified();
    scf.storeSvnServersSettings(url, ConnectionType.cli);
    s = getSection(serversFile);
    // values were written
    assertNotNull(s);
    assertNotSame(lastMod, serversFile.lastModified());
    assertEquals("/cert/file3", s.get("ssl-client-cert-file"));
    assertEquals("pssphrs3", s.get("ssl-client-cert-password"));
}