List of usage examples for org.eclipse.jgit.errors ConfigInvalidException ConfigInvalidException
public ConfigInvalidException(String message)
From source file:com.amd.gerrit.plugins.manifestsubscription.VersionedManifests.java
License:Open Source License
@Override protected void onLoad() throws IOException, ConfigInvalidException { manifests = Maps.newHashMap();/* w w w . j a va 2 s .c o m*/ String path; Manifest manifest; try (RevWalk rw = new RevWalk(reader); TreeWalk treewalk = new TreeWalk(reader)) { // This happens when someone configured a invalid branch name if (getRevision() == null) { throw new ConfigInvalidException(refName); } RevCommit r = rw.parseCommit(getRevision()); treewalk.addTree(r.getTree()); treewalk.setRecursive(false); treewalk.setFilter(PathSuffixFilter.create(".xml")); while (treewalk.next()) { if (treewalk.isSubtree()) { treewalk.enterSubtree(); } else { path = treewalk.getPathString(); //TODO: Should this be done more lazily? //TODO: difficult to do when reader is not available outside of onLoad? try (ByteArrayInputStream input = new ByteArrayInputStream(readFile(path))) { manifest = (Manifest) manifestUnmarshaller.unmarshal(input); manifests.put(path, manifest); } catch (JAXBException e) { e.printStackTrace(); } } } } //TODO load changed manifest // DiffFormatter df = new DiffFormatter(DisabledOutputStream.INSTANCE); }
From source file:com.google.gerrit.server.account.externalids.ExternalId.java
License:Apache License
private static ConfigInvalidException invalidConfig(String noteId, String message) { return new ConfigInvalidException( String.format("Invalid external ID config for note '%s': %s", noteId, message)); }
From source file:com.google.gerrit.server.account.externalids.ExternalIdsUpdate.java
License:Apache License
/** * Insert or updates an new external ID and sets it in the note map. * * <p>If the external ID already exists it is overwritten. *///www. j a v a2 s. com public static void upsert(RevWalk rw, ObjectInserter ins, NoteMap noteMap, ExternalId extId) throws IOException, ConfigInvalidException { ObjectId noteId = extId.key().sha1(); Config c = new Config(); if (noteMap.contains(extId.key().sha1())) { byte[] raw = rw.getObjectReader().open(noteMap.get(noteId), OBJ_BLOB).getCachedBytes(MAX_NOTE_SZ); try { c.fromText(new String(raw, UTF_8)); } catch (ConfigInvalidException e) { throw new ConfigInvalidException( String.format("Invalid external id config for note %s: %s", noteId, e.getMessage())); } } extId.writeToConfig(c); byte[] raw = c.toText().getBytes(UTF_8); ObjectId dataBlob = ins.insert(OBJ_BLOB, raw); noteMap.set(noteId, dataBlob); }
From source file:com.google.gerrit.server.config.ConfigUtil.java
License:Apache License
/** * Store section by inspecting Java class attributes. * <p>//from ww w . j a v a 2 s .com * Optimize the storage by unsetting a variable if it is * being set to default value by the server. * <p> * Fields marked with final or transient modifiers are skipped. * * @param cfg config in which the values should be stored * @param section section * @param sub subsection * @param s instance of class with config values * @param defaults instance of class with default values * @throws ConfigInvalidException */ public static <T> void storeSection(Config cfg, String section, String sub, T s, T defaults) throws ConfigInvalidException { try { for (Field f : s.getClass().getDeclaredFields()) { if (skipField(f)) { continue; } Class<?> t = f.getType(); String n = f.getName(); f.setAccessible(true); Object c = f.get(s); Object d = f.get(defaults); Preconditions.checkNotNull(d, "Default cannot be null"); if (c == null || c.equals(d)) { cfg.unset(section, sub, n); } else { if (isString(t)) { cfg.setString(section, sub, n, (String) c); } else if (isInteger(t)) { cfg.setInt(section, sub, n, (Integer) c); } else if (isLong(t)) { cfg.setLong(section, sub, n, (Long) c); } else if (isBoolean(t)) { cfg.setBoolean(section, sub, n, (Boolean) c); } else if (t.isEnum()) { cfg.setEnum(section, sub, n, (Enum<?>) c); } else { throw new ConfigInvalidException("type is unknown: " + t.getName()); } } } } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new ConfigInvalidException("cannot save values", e); } }
From source file:com.google.gerrit.server.config.ConfigUtil.java
License:Apache License
/** * Load section by inspecting Java class attributes. * <p>/*from w w w . jav a 2s . c o m*/ * Config values are stored optimized: no default values are stored. * The loading is performed eagerly: all values are set. * <p> * Fields marked with final or transient modifiers are skipped. * <p> * Boolean fields are only set when their values are true. * * @param cfg config from which the values are loaded * @param section section * @param sub subsection * @param s instance of class in which the values are set * @param defaults instance of class with default values * @return loaded instance * @throws ConfigInvalidException */ public static <T> T loadSection(Config cfg, String section, String sub, T s, T defaults) throws ConfigInvalidException { try { for (Field f : s.getClass().getDeclaredFields()) { if (skipField(f)) { continue; } Class<?> t = f.getType(); String n = f.getName(); f.setAccessible(true); Object d = f.get(defaults); Preconditions.checkNotNull(d, "Default cannot be null"); if (isString(t)) { f.set(s, MoreObjects.firstNonNull(cfg.getString(section, sub, n), d)); } else if (isInteger(t)) { f.set(s, cfg.getInt(section, sub, n, (Integer) d)); } else if (isLong(t)) { f.set(s, cfg.getLong(section, sub, n, (Long) d)); } else if (isBoolean(t)) { boolean b = cfg.getBoolean(section, sub, n, (Boolean) d); if (b) { f.set(s, b); } } else if (t.isEnum()) { f.set(s, cfg.getEnum(section, sub, n, (Enum<?>) d)); } else { throw new ConfigInvalidException("type is unknown: " + t.getName()); } } } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { throw new ConfigInvalidException("cannot load values", e); } return s; }
From source file:com.google.gerrit.server.git.ProjectConfig.java
License:Apache License
public static final String validMaxObjectSizeLimit(String value) throws ConfigInvalidException { if (value == null) { return null; }/*ww w . ja v a 2 s . c om*/ value = value.trim(); if (value.isEmpty()) { return null; } Config cfg = new Config(); cfg.fromText("[s]\nn=" + value); try { long s = cfg.getLong("s", "n", 0); if (s < 0) { throw new ConfigInvalidException( String.format("Negative value '%s' not allowed as %s", value, KEY_MAX_OBJECT_SIZE_LIMIT)); } if (s == 0) { // return null for the default so that it is not persisted return null; } return value; } catch (IllegalArgumentException e) { throw new ConfigInvalidException(String.format("Value '%s' not parseable as a Long", value), e); } }
From source file:com.google.gerrit.server.git.PushReplication.java
License:Apache License
private List<RemoteConfig> allRemotes(final FileBasedConfig cfg) throws ConfigInvalidException { List<String> names = new ArrayList<String>(cfg.getSubsections("remote")); Collections.sort(names);//from w w w . j a v a 2 s.co m final List<RemoteConfig> result = new ArrayList<RemoteConfig>(names.size()); for (final String name : names) { try { result.add(new RemoteConfig(cfg, name)); } catch (URISyntaxException e) { throw new ConfigInvalidException("remote " + name + " has invalid URL in " + cfg.getFile()); } } return result; }
From source file:com.google.gerrit.server.notedb.ChangeNotes.java
License:Apache License
public static ConfigInvalidException parseException(Change.Id changeId, String fmt, Object... args) { return new ConfigInvalidException("Change " + changeId + ": " + String.format(fmt, args)); }
From source file:com.googlesource.gerrit.plugins.automerger.ConfigLoader.java
License:Apache License
private Config getConfig() throws ConfigInvalidException { try {/* ww w. j av a 2 s. c o m*/ return cfgFactory.getProjectPluginConfig(allProjectsName, pluginName); } catch (NoSuchProjectException e) { throw new ConfigInvalidException( "Config invalid because " + allProjectsName.get() + " does not exist!"); } }
From source file:com.googlesource.gerrit.plugins.automerger.ConfigLoader.java
License:Apache License
/** * Gets the upstream branches of the given branch and project. * * @param toBranch The downstream branch we would merge to. * @param project The project we are merging. * @return The branches upstream of the given branch for the given project. * @throws RestApiException/*from www . ja v a 2 s .c o m*/ * @throws IOException * @throws ConfigInvalidException */ public Set<String> getUpstreamBranches(String toBranch, String project) throws ConfigInvalidException, RestApiException, IOException { if (toBranch == null) { throw new IllegalArgumentException("toBranch cannot be null"); } Set<String> upstreamBranches = new HashSet<>(); // List all subsections of automerger, split by : Set<String> subsections = getConfig().getSubsections(pluginName); for (String subsection : subsections) { // Subsections are of the form "fromBranch:toBranch" List<String> branchPair = Splitter.on(BRANCH_DELIMITER).trimResults().omitEmptyStrings() .splitToList(subsection); if (branchPair.size() != 2) { throw new ConfigInvalidException("Automerger config branch pair malformed: " + subsection); } if (toBranch.equals(branchPair.get(1))) { // If toBranch matches, check if project is in both their manifests Set<String> projectsInScope = getProjectsInScope(branchPair.get(0), branchPair.get(1)); if (projectsInScope.contains(project)) { upstreamBranches.add(branchPair.get(0)); } } } return upstreamBranches; }