/** Returns the input strings, but with all values interned. */ public static String[] internInPlace(String[] input) { if (input == null) { return null; } else if (input.length == 0) { return EMPTY_STRING_ARRAY; } for (int i=0; i<input.length; i++) { input[i] = Util.intern(input[i]); } return input; }
public Dependency(String s) { int idx = s.indexOf(':'); if(idx==-1) throw new IllegalArgumentException("Illegal dependency specifier "+s); this.shortName = Util.intern(s.substring(0,idx)); String version = Util.intern(s.substring(idx+1)); boolean isOptional = false; String[] osgiProperties = version.split("[;]"); for (int i = 1; i < osgiProperties.length; i++) { String osgiProperty = osgiProperties[i].trim(); if (osgiProperty.equalsIgnoreCase("resolution:=optional")) { isOptional = true; } } this.optional = isOptional; if (isOptional) { this.version = osgiProperties[0]; } else { this.version = version; } }
/** * @param archive * A .jpi archive file jar file, or a .jpl linked plugin. * @param manifest * The manifest for the plugin * @param baseResourceURL * A URL pointing to the resources for this plugin * @param classLoader * a classloader that loads classes from this plugin and its dependencies * @param disableFile * if this file exists on startup, the plugin will not be activated * @param dependencies a list of mandatory dependencies * @param optionalDependencies a list of optional dependencies */ public PluginWrapper(PluginManager parent, File archive, Manifest manifest, URL baseResourceURL, ClassLoader classLoader, File disableFile, List<Dependency> dependencies, List<Dependency> optionalDependencies) { this.parent = parent; this.manifest = manifest; this.shortName = Util.intern(computeShortName(manifest, archive.getName())); this.baseResourceURL = baseResourceURL; this.classLoader = classLoader; this.disableFile = disableFile; this.active = !disableFile.exists(); this.dependencies = dependencies; this.optionalDependencies = optionalDependencies; this.archive = archive; }
public WarningVersionRange(JSONObject o) { this.name = Util.fixEmpty(o.optString("name")); this.firstVersion = Util.intern(Util.fixEmpty(o.optString("firstVersion"))); this.lastVersion = Util.intern(Util.fixEmpty(o.optString("lastVersion"))); Pattern p; try { p = Pattern.compile(o.getString("pattern")); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "Failed to compile pattern '" + o.getString("pattern") + "', using '.*' instead", ex); p = Pattern.compile(".*"); } this.pattern = p; }
Entry(String sourceId, JSONObject o, String baseURL) { this.sourceId = sourceId; this.name = Util.intern(o.getString("name")); this.version = Util.intern(o.getString("version")); // Trim this to prevent issues when the other end used Base64.encodeBase64String that added newlines // to the end in old commons-codec. Not the case on updates.jenkins-ci.org, but let's be safe. this.sha1 = Util.fixEmptyAndTrim(o.optString("sha1")); this.sha256 = Util.fixEmptyAndTrim(o.optString("sha256")); this.sha512 = Util.fixEmptyAndTrim(o.optString("sha512")); String url = o.getString("url"); if (!URI.create(url).isAbsolute()) { if (baseURL == null) { throw new IllegalArgumentException("Cannot resolve " + url + " without a base URL"); } url = URI.create(baseURL).resolve(url).toString(); } this.url = url; }
@DataBoundConstructor public Plugin(String sourceId, JSONObject o) { super(sourceId, o, UpdateSite.this.url); this.wiki = get(o,"wiki"); this.title = get(o,"title"); this.excerpt = get(o,"excerpt"); this.compatibleSinceVersion = Util.intern(get(o,"compatibleSinceVersion")); this.minimumJavaVersion = Util.intern(get(o, "minimumJavaVersion")); this.requiredCore = Util.intern(get(o,"requiredCore")); this.categories = o.has("labels") ? internInPlace((String[])o.getJSONArray("labels").toArray(EMPTY_STRING_ARRAY)) : null; JSONArray ja = o.getJSONArray("dependencies"); int depCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL)).count()); int optionalDepCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL.negate())).count()); dependencies = getPresizedMutableMap(depCount); optionalDependencies = getPresizedMutableMap(optionalDepCount); for(Object jo : o.getJSONArray("dependencies")) { JSONObject depObj = (JSONObject) jo; // Make sure there's a name attribute and that the optional value isn't true. String depName = Util.intern(get(depObj,"name")); if (depName!=null) { if (get(depObj, "optional").equals("false")) { dependencies.put(depName, Util.intern(get(depObj, "version"))); } else { optionalDependencies.put(depName, Util.intern(get(depObj, "version"))); } } } }
/** * * @param o the {@link JSONObject} representing the warning * @throws JSONException if the argument does not match the expected format */ @Restricted(NoExternalUse.class) public Warning(JSONObject o) { try { this.type = Type.valueOf(o.getString("type").toUpperCase(Locale.US)); } catch (IllegalArgumentException ex) { this.type = Type.UNKNOWN; } this.id = o.getString("id"); this.component = Util.intern(o.getString("name")); this.message = o.getString("message"); this.url = o.getString("url"); if (o.has("versions")) { JSONArray versions = o.getJSONArray("versions"); List<WarningVersionRange> ranges = new ArrayList<>(versions.size()); for (int i = 0; i < versions.size(); i++) { WarningVersionRange range = new WarningVersionRange(versions.getJSONObject(i)); ranges.add(range); } this.versionRanges = Collections.unmodifiableList(ranges); } else { this.versionRanges = Collections.emptyList(); } }
/** * Lots of {@link ExecutedMojo}s tend to have the same groupId, artifactId, etc., so interning them help * with memory consumption. * * TODO: better if XStream has a declarative way of marking fields as "target for intern". */ ExecutedMojo readResolve() { return new ExecutedMojo(intern(groupId),intern(artifactId),intern(version),intern(goal),intern(executionId),duration,intern(digest)); }
/** * Lots of {@link ExecutedMojo}s tend to have the same groupId, artifactId, etc., so interning them help * with memory consumption. * * TODO: better if XStream has a declarative way of marking fields as "target for intern". */ protected Object readResolve() { return new ExecutedMojo(intern(groupId),intern(artifactId),intern(version),intern(goal),intern(executionId),duration,intern(digest)); }
public void setMavenVersionUsed( String mavenVersionUsed ) throws IOException { this.mavenVersionUsed = Util.intern(mavenVersionUsed); save(); }