/** * Cache the installed application location and version in the preferences. * * @param installDir - The directory the application was installed to. * @param versionedFileLocation - Can be the URL that we grabbed the installer from, or any other * string that contains a version information in a form of x.y.z. * @param appName - The application name (e.g. xampp) */ @SuppressWarnings("unchecked") public void cacheVersion(String installDir, String versionedFileLocation, String appName) { IPreferenceStore preferenceStore = PortalUIPlugin.getDefault().getPreferenceStore(); String versions = preferenceStore.getString(IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME); Map<String, Map<String, String>> versionsMap = null; if (versions == null || versions.equals(StringUtil.EMPTY)) { versionsMap = new HashMap<String, Map<String, String>>(); } else { versionsMap = (Map<String, Map<String, String>>) JSON.parse(versions); } Map<String, String> appVersionMap = new HashMap<String, String>(); Version version = VersionUtil.parseVersion(versionedFileLocation); if (!VersionUtil.isEmpty(version)) { appVersionMap.put(IPortalPreferences.CACHED_VERSION_PROPERTY, version.toString()); appVersionMap.put(IPortalPreferences.CACHED_LOCATION_PROPERTY, installDir); versionsMap.put(appName.toLowerCase(), appVersionMap); preferenceStore.setValue( IPortalPreferences.CACHED_VERSIONS_PROPERTY_NAME, JSON.toString(versionsMap)); } else { IdeLog.logError( PortalUIPlugin.getDefault(), MessageFormat.format( "Could not cache the location and version for {0}. Install dir: {1}, versionedFileLocation: {2}", //$NON-NLS-1$ appName, installDir, versionedFileLocation), new Exception()); } }
@Test public void testSpecialAllUserAgentFlag() { // create property and use all user agents PropertyElement property = new PropertyElement(); property.setName("property"); property.setHasAllUserAgents(); // create type for property so we can write it to the index TypeElement type = new TypeElement(); type.setName("Testing"); type.addProperty(property); // write type and its property JSIndexWriter writer = new JSIndexWriter(); writer.writeType(getIndex(), type); // perform low-level query // @formatter:off List<QueryResult> properties = getIndex() .query( new String[] {IJSIndexConstants.PROPERTY}, type.getName(), SearchPattern.PREFIX_MATCH); // @formatter:on // make sure we got something assertNotNull(properties); assertEquals(1, properties.size()); // split result into columns String word = properties.get(0).getWord(); String[] columns = IndexReader.DELIMITER_PATTERN.split(word); assertEquals(3, columns.length); // grab last column and parse as JSON String json = columns[2]; Object m = JSON.parse(json); // make sure we have a map assertTrue("Expected a Map from the JSON string", m instanceof Map); Map<?, ?> map = (Map<?, ?>) m; // test userAgents for "special value" which is really just a null value. assertTrue("Expected a userAgents property", map.containsKey("userAgents")); assertNull("Expected userAgents property to be null", map.get("userAgents")); }
/** * @deprecated use {@link #parse(Reader, boolean)} * @param in Stream containing JSON object or array. * @param stripOuterComment If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ @Deprecated public static Object parse(InputStream in, boolean stripOuterComment) throws IOException { return DEFAULT.parse(new StringSource(IO.toString(in)), stripOuterComment); }
/** * @deprecated use {@link #parse(Reader)} * @param in Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ @Deprecated public static Object parse(InputStream in) throws IOException { return DEFAULT.parse(new StringSource(IO.toString(in)), false); }
/** * @param in Reader containing JSON object or array. * @param stripOuterComment If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(Reader in, boolean stripOuterComment) throws IOException { return DEFAULT.parse(new ReaderSource(in), stripOuterComment); }
/** * @param in Reader containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(Reader in) throws IOException { return DEFAULT.parse(new ReaderSource(in), false); }
/** * @param s String containing JSON object or array. * @param stripOuterComment If true, an outer comment around the JSON is ignored. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s, boolean stripOuterComment) { return DEFAULT.parse(new StringSource(s), stripOuterComment); }
/** * @param s String containing JSON object or array. * @return A Map, Object array or primitive array parsed from the JSON. */ public static Object parse(String s) { return DEFAULT.parse(new StringSource(s), false); }