/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public void setBoolean(final String section, final String subsection, final String name, final boolean value) { setString(section, subsection, name, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ }
public void changeValue(String newValue) throws IllegalArgumentException { if (newValue.length() == 0) throw new IllegalArgumentException( UIText.ConfigurationEditorComponent_EmptyStringNotAllowed); Config config = getConfig(); if (index < 0) { if (sectionparent != null) config.setString(sectionparent.name, null, name, newValue); else config.setString(subsectionparent.parent.name, subsectionparent.name, name, newValue); } else { String[] entries; if (sectionparent != null) { entries = config.getStringList(sectionparent.name, null, name); entries[index] = newValue; config.setStringList(sectionparent.name, null, name, Arrays.asList(entries)); } else { entries = config.getStringList( subsectionparent.parent.name, subsectionparent.name, name); entries[index] = newValue; config.setStringList(subsectionparent.parent.name, subsectionparent.name, name, Arrays.asList(entries)); } } }
s = String.valueOf(value); setString(section, subsection, name, s);
private RemoteConfig newRemoteConfig(String name, String refUrl, RefSpec... refSpec) { try { Config repoConfig = new Config(); // Make up a repo config from the request parameters repoConfig.setString("remote", name, "url", refUrl); List<String> str = new ArrayList<>(); if(refSpec != null && refSpec.length > 0) for (RefSpec rs: refSpec) str.add(rs.toString()); repoConfig.setStringList("remote", name, "fetch", str); return RemoteConfig.getAllRemoteConfigs(repoConfig).get(0); } catch (Exception ex) { throw new GitException("Error trying to create JGit configuration", ex); } }
private void set(final Config rc, final String key, final String currentValue, final String defaultValue) { if (defaultValue.equals(currentValue)) unset(rc, key); else rc.setString(SECTION, getName(), key, currentValue); }
public static List<RemoteConfig> createRepositoryConfigurations(String[] urls, String[] repoNames, String[] refs) throws IOException { List<RemoteConfig> remoteRepositories; Config repoConfig = new Config(); // Make up a repo config from the request parameters String[] names = repoNames; names = GitUtils.fixupNames(names, urls); for (int i = 0; i < names.length; i++) { String url = urls[i]; if (url == null) { continue; } String name = names[i]; name = name.replace(' ', '_'); if (isBlank(refs[i])) { refs[i] = "+refs/heads/*:refs/remotes/" + name + "/*"; } repoConfig.setString("remote", name, "url", url); repoConfig.setStringList("remote", name, "fetch", new ArrayList<>(Arrays.asList(refs[i].split("\\s+")))); } try { remoteRepositories = RemoteConfig.getAllRemoteConfigs(repoConfig); } catch (Exception e) { throw new GitException("Error creating repositories", e); } return remoteRepositories; }
/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public <T extends Enum<?>> void setEnum(final String section, final String subsection, final String name, final T value) { String n; if (value instanceof ConfigEnum) n = ((ConfigEnum) value).toConfigValue(); else n = value.name().toLowerCase(Locale.ROOT).replace('_', ' '); setString(section, subsection, name, n); }
/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public void setBoolean(final String section, final String subsection, final String name, final boolean value) { setString(section, subsection, name, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public void setBoolean(final String section, final String subsection, final String name, final boolean value) { setString(section, subsection, name, value ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$ }
cfg.setString("submodule", name, "branch", //$NON-NLS-1$ //$NON-NLS-2$ proj.getRevision()); submodUrl = relativize(targetUri, submodUrl); cfg.setString("submodule", name, "path", path); //$NON-NLS-1$ //$NON-NLS-2$ cfg.setString("submodule", name, "url", //$NON-NLS-1$ //$NON-NLS-2$ submodUrl.toString());
private static void set(Config cfg, String section, String subsection, String key, String value) { if (value == null || "".equals(value)) cfg.unset(section, subsection, key); else cfg.setString(section, subsection, key, value); }
private RemoteConfig newRemoteConfig(String name, String refUrl, RefSpec refSpec, String relativeTargetDir) { try { Config repoConfig = new Config(); // Make up a repo config from the request parameters repoConfig.setString(GitRepository.REMOTE_SECTION, name, "url", refUrl); repoConfig.setString(GitRepository.REMOTE_SECTION, name, "fetch", refSpec.toString()); repoConfig.setString(GitRepository.REMOTE_SECTION, name, GitRepository.TARGET_DIR_KEY, relativeTargetDir); return GitRepository.getAllGitRepositories(repoConfig).get(0); } catch (Exception ex) { throw new GitException("Remote's configuration is invalid", ex); } }
Config c = Decoder.defaultConfig(); c.setString("-hmm", "../../model/en-us/en-us"); c.setString("-lm", "../../model/en-us/en-us.lm.bin"); c.setString("-dict", "../../model/en-us/cmudict-en-us.dict"); Decoder d = new Decoder(c); FileInputStream ais = new FileInputStream(new File("../../test/data/goforward.raw")); d.startUtt(); d.setRawdataSize(300000); byte[] b = new byte[4096]; int nbytes; while ((nbytes = ais.read(b)) >= 0) { ByteBuffer bb = ByteBuffer.wrap(b, 0, nbytes); bb.order(ByteOrder.LITTLE_ENDIAN); short[] s = new short[nbytes/2]; bb.asShortBuffer().get(s); d.processRaw(s, nbytes/2, false, false); } d.endUtt(); System.out.println(d.hyp().getHypstr()); short[] data = d.getRawdata(); System.out.println("Data size: " + data.length); DataOutputStream dos = new DataOutputStream(new FileOutputStream(new File("/tmp/test.raw"))); for (int i = 0; i < data.length; i++) { dos.writeShort(data[i]); } dos.close(); for (Segment seg : d.seg()) { System.out.println(seg.getWord()); }
private void set(final Config rc, final String key, final String currentValue, final String defaultValue) { if (defaultValue.equals(currentValue)) unset(rc, key); else rc.setString(SECTION, getName(), key, currentValue); }
private void set(final Config rc, final String key, final String currentValue, final String defaultValue) { if (defaultValue.equals(currentValue)) unset(rc, key); else rc.setString(SECTION, getName(), key, currentValue); }
/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public <T extends Enum<?>> void setEnum(final String section, final String subsection, final String name, final T value) { String n; if (value instanceof ConfigEnum) n = ((ConfigEnum) value).toConfigValue(); else n = value.name().toLowerCase(Locale.ROOT).replace('_', ' '); setString(section, subsection, name, n); }
/** * Add or modify a configuration value. The parameters will result in a * configuration entry like this. * * <pre> * [section "subsection"] * name = value * </pre> * * @param <T> * type of the enumeration object. * @param section * section name, e.g "branch" * @param subsection * optional subsection value, e.g. a branch name * @param name * parameter name, e.g. "filemode" * @param value * parameter value */ public <T extends Enum<?>> void setEnum(final String section, final String subsection, final String name, final T value) { String n; if (value instanceof ConfigEnum) n = ((ConfigEnum) value).toConfigValue(); else n = value.name().toLowerCase().replace('_', ' '); setString(section, subsection, name, n); }
/** * Validates the remote repository URL. * * @param value value to validate. * @return {@link FormValidation}. * @throws java.io.IOException IOException. * @throws javax.servlet.ServletException ServletException. */ public FormValidation doCheckRepositoryUrl(@QueryParameter String value) throws IOException, ServletException { if (StringUtils.isEmpty(value)) { return FormValidation.error( hudson.plugins.git.Messages.GitSCM_Repository_IncorrectRepositoryFormatMsg()); } Config repoConfig = new Config(); repoConfig.setString("remote", GitUtils.DEFAULD_REPO_NAME, "url", value); try { RemoteConfig.getAllRemoteConfigs(repoConfig); } catch (Exception e) { return FormValidation.error( hudson.plugins.git.Messages.GitSCM_Repository_IncorrectRepositoryFormatMsg() + ": " + e.getMessage()); } return FormValidation.ok(); }
@Override public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { RefSpec ref = (refspec != null) ? new RefSpec(fixRefSpec(repo)) : Transport.REFSPEC_PUSH_ALL; listener.getLogger().println("RefSpec is \""+ref+"\"."); Git g = git(repo); Config config = g.getRepository().getConfig(); config.setString("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url", remote.toPrivateASCIIString()); org.eclipse.jgit.api.PushCommand pc = g.push().setRemote("org_jenkinsci_plugins_gitclient_JGitAPIImpl").setRefSpecs(ref) .setProgressMonitor(new JGitProgressMonitor(listener)) .setCredentialsProvider(getProvider()) .setForce(force); if(tags) { pc.setPushTags(); } Iterable<PushResult> results = pc.call(); for(PushResult result:results) for(RemoteRefUpdate update:result.getRemoteUpdates()) { RemoteRefUpdate.Status status = update.getStatus(); if(!OK.equals(status)&&!UP_TO_DATE.equals(status)) { throw new GitException(update.getMessage() + " " + status + " for '" + ref + "' refspec '" + refspec + "' to " + remote.toPrivateASCIIString()); } } config.unset("remote", "org_jenkinsci_plugins_gitclient_JGitAPIImpl", "url"); } catch (IOException | JGitInternalException | GitAPIException e) { throw new GitException(e); } }