/** * Extracts the version information data from the <code>version.properties</code> file found in * the source directory. * * @return the version information from the <code>version.properties</code> file */ protected static VersionInfo createVersionInfo() { // We're not in a .jar file - try to find the build-res/version file and // read the version information from that. final VersionInfo versionInfo = new VersionInfo(); try { final ResourceBundle bundle = ResourceBundle.getBundle("version"); // $NON-NLS-1$ versionInfo.setFromManifest(false); versionInfo.setProductID(bundle.getString("impl.productID")); // $NON-NLS-1$ versionInfo.setTitle(bundle.getString("impl.title")); // $NON-NLS-1$ versionInfo.setVersionMajor(bundle.getString("release.major.number")); // $NON-NLS-1$ versionInfo.setVersionMinor(bundle.getString("release.minor.number")); // $NON-NLS-1$ versionInfo.setVersionBuild(bundle.getString("release.build.number")); // $NON-NLS-1$ // The release milestone number has both the release number and the milestone number final String releaseMilestoneNumber = bundle.getString("release.milestone.number"); // $NON-NLS-1$ if (releaseMilestoneNumber != null) { String[] parts = releaseMilestoneNumber.replace('-', '.').split("\\."); // $NON-NLS-1$ if (parts.length > 0) { versionInfo.setVersionRelease(parts[0]); if (parts.length > 1) { versionInfo.setVersionMilestone(parts[1]); } } } } catch (Exception e) { // TODO:log versionInfo.setVersion("No Version Information Available"); // $NON-NLS-1$ } return versionInfo; }
/** * 更新缓存信息 * * @param context 当前上下文 * @param vi 要缓存的版本信息 */ private void updateCache(Context context, VersionInfo vi) { SharedPreferences sp = context.getSharedPreferences("update_info", Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.putInt("versionCode", vi.mVersionCode); editor.putString("versionName", vi.getVersionName()); editor.putString("updateInfo", vi.getUpdateInfo()); editor.apply(); }
/** * Extracts the version information data from the manifest's attributes and puts them into a * VersionInfo instance. * * @param manifest the manifest information * @return the version information from the manifest */ protected static VersionInfo createVersionInfo(Manifest manifest) { final VersionInfo versionInfo = new VersionInfo(); final Attributes mainAttributes = manifest.getMainAttributes(); versionInfo.setFromManifest(true); versionInfo.setProductID(mainAttributes.getValue("Implementation-ProductID")); // $NON-NLS-1$ versionInfo.setTitle(mainAttributes.getValue("Implementation-Title")); // $NON-NLS-1$ versionInfo.setVersion(mainAttributes.getValue("Implementation-Version")); // $NON-NLS-1$ return versionInfo; }
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (this.tagName == null) return; String value = new String(ch, start, length); if (this.tagName.equalsIgnoreCase("UpdateInfo")) { if (mVersionInfo.mUpdateInfo == null) mVersionInfo.mUpdateInfo = ""; mVersionInfo.mUpdateInfo += value; } }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { this.tagName = localName; if (this.tagName.equalsIgnoreCase("Application")) { mVersionInfo.mVersionCode = Integer.parseInt(attributes.getValue("versionCode")); mVersionInfo.mVersionName = attributes.getValue("versionName"); mVersionInfo.mDownloadUrl = attributes.getValue("downloadUrl"); } }
public static VersionInfo getSuperuserVersionInfo(Context context) { VersionInfo info = new VersionInfo(); PackageManager pm = context.getPackageManager(); try { PackageInfo pInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); info.version = pInfo.versionName; info.versionCode = pInfo.versionCode; } catch (NameNotFoundException e) { Log.e(TAG, "Superuser is not installed?", e); } return info; }
/** * 获取当前软件版本信息 * * @param context * @return 版本信息 */ public VersionInfo getCurrentVersionInfo(Context context) { VersionInfo versionInfo = new VersionInfo(); try { PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); versionInfo.setVersionCode(pi.versionCode); versionInfo.setVersionName(pi.versionName); versionInfo.setDownloadUrl(null); versionInfo.setUpdateInfo(null); } catch (NameNotFoundException e) { Log.e(tag, "包名不存在"); return null; } return versionInfo; }
public Response makeResponse(FitNesseContext context, Request request) { SimpleResponse response = new SimpleResponse(); String resource = request.getResource(); WikiPagePath path = PathParser.parse(resource); WikiPage page = context.root.getPageCrawler().getPage(path); if (page == null) return new NotFoundResponder().makeResponse(context, request); PageData data = page.getData(); saveAttributes(request, data); VersionInfo commitRecord = page.commit(data); response.addHeader("Current-Version", commitRecord.getName()); context.recentChanges.updateRecentChanges(data); response.redirect(resource); return response; }
/** * 检查是否有缓存更新文件 * * @param context 当前上下文 * @param outVi 若有缓存更新信息,outVi为安装信息 * @param outPath 若有缓存安装文件,outPath记录安装路径,否则为null * @return 若返回false,说明没有缓存有效的更新文件,返回true说明有缓存更新文件 */ private boolean checkCache(Context context, final VersionInfo outVi, final StringBuffer outPath) { SharedPreferences sp = context.getSharedPreferences("update_info", Context.MODE_PRIVATE); outVi.mVersionCode = sp.getInt("versionCode", 0); outVi.mVersionName = sp.getString("versionName", null); outVi.mUpdateInfo = sp.getString("updateInfo", null); if (getCurrentVersionInfo(context).getVersionCode() >= outVi.getVersionCode()) { Log.d(tag, "当前版本比缓存版本更新"); return false; } outPath.append(sp.getString("savePath", null)); if (outPath == null || !new File(outPath.toString()).exists()) { Log.d(tag, "缓存文件不存在"); return false; } return true; }
private void initializeVersionInfo() { if (versionInfoInitialized) { } else { newVersionInfo.setCreated(new Date()); versionInfoDAO.makePersistent(newVersionInfo); versionInfoInitialized = true; } }
@Test public void testToString() { versionInfo.setVersion(VERSION_NUMBER_ONE); versionInfo.setFromManifest(true); versionInfo.setTitle(TITLE); versionInfo.setProductID(PRODUCT_ID); assertThat(TO_STRING, equalTo(versionInfo.toString())); assertThat(true, equalTo(versionInfo.isFromManifest())); assertThat(TITLE, equalTo(versionInfo.getTitle())); assertThat(PRODUCT_ID, equalTo(versionInfo.getProductID())); }
/** Construct the full path to the base directory of the library's resources. */ private void initPath() { StringBuilder builder = new StringBuilder(64), noLocaleBuilder = new StringBuilder(64); appendBasePath(builder); appendBasePath(noLocaleBuilder); if (localePrefix != null) { builder.append('/').append(localePrefix); } builder.append('/').append(name); noLocaleBuilder.append('/').append(name); if (version != null) { builder.append('/').append(version.getVersion()); noLocaleBuilder.append('/').append(version.getVersion()); } path = builder.toString(); nonLocalizedPath = noLocaleBuilder.toString(); }
public VersionInfo unmarshall(JsonUnmarshallerContext context) throws Exception { VersionInfo versionInfo = new VersionInfo(); int originalDepth = context.getCurrentDepth(); String currentParentElement = context.getCurrentParentElement(); int targetDepth = originalDepth + 1; JsonToken token = context.getCurrentToken(); if (token == null) token = context.nextToken(); if (token == VALUE_NULL) return null; while (true) { if (token == null) break; if (token == FIELD_NAME || token == START_OBJECT) { if (context.testExpression("agentVersion", targetDepth)) { context.nextToken(); versionInfo.setAgentVersion(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("agentHash", targetDepth)) { context.nextToken(); versionInfo.setAgentHash(context.getUnmarshaller(String.class).unmarshall(context)); } if (context.testExpression("dockerVersion", targetDepth)) { context.nextToken(); versionInfo.setDockerVersion(context.getUnmarshaller(String.class).unmarshall(context)); } } else if (token == END_ARRAY || token == END_OBJECT) { if (context.getLastParsedParentElement() == null || context.getLastParsedParentElement().equals(currentParentElement)) { if (context.getCurrentDepth() <= originalDepth) break; } } token = context.nextToken(); } return versionInfo; }
@Test public void testGetVersionNumber() { versionInfo.setVersion(VERSION_NUMBER_ONE); assertThat(VERSION_NUMBER_ONE, equalTo(versionInfo.getVersionNumber())); }
@Test public void testSetVersion() { versionInfo.setVersion(VERSION_NUMBER_ONE); assertThat("1", equalTo(versionInfo.getVersionMajor())); assertThat("6", equalTo(versionInfo.getVersionMinor())); assertThat("0", equalTo(versionInfo.getVersionRelease())); assertThat("GA", equalTo(versionInfo.getVersionMilestone())); assertThat("500", equalTo(versionInfo.getVersionBuild())); versionInfo.setVersion(VERSION_NUMBER_TWO); assertThat("1", equalTo(versionInfo.getVersionMajor())); assertThat("6", equalTo(versionInfo.getVersionMinor())); assertThat("0", equalTo(versionInfo.getVersionRelease())); assertThat("RC2", equalTo(versionInfo.getVersionMilestone())); assertThat("400", equalTo(versionInfo.getVersionBuild())); }
@Bean VersionInfo versionInfo() { return VersionInfo.versionInfo("1.0.0", "ab1234", "http://example.org/vcs/{version}"); }
public static VersionInfo getSuVersionInfo() { VersionInfo info = new VersionInfo(); Process process = null; String inLine = null; try { process = Runtime.getRuntime().exec("sh"); DataOutputStream os = new DataOutputStream(process.getOutputStream()); BufferedReader is = new BufferedReader( new InputStreamReader(new DataInputStream(process.getInputStream())), 64); os.writeBytes("su -v\n"); // We have to hold up the thread to make sure that we're ready to read // the stream, using increments of 5ms makes it return as quick as // possible, and limiting to 1000ms makes sure that it doesn't hang for // too long if there's a problem. for (int i = 0; i < 400; i++) { if (is.ready()) { break; } try { Thread.sleep(5); } catch (InterruptedException e) { Log.w(TAG, "Sleep timer got interrupted..."); } } if (is.ready()) { inLine = is.readLine(); if (inLine != null) { info.version = inLine; } } else { // If 'su -v' isn't supported, neither is 'su -V'. return legacy info os.writeBytes("exit\n"); info.version = "legacy"; info.versionCode = 0; return info; } os.writeBytes("su -v\n"); // We have to hold up the thread to make sure that we're ready to read // the stream, using increments of 5ms makes it return as quick as // possible, and limiting to 1000ms makes sure that it doesn't hang for // too long if there's a problem. for (int i = 0; i < 400; i++) { if (is.ready()) { break; } try { Thread.sleep(5); } catch (InterruptedException e) { Log.w(TAG, "Sleep timer got interrupted..."); } } if (is.ready()) { inLine = is.readLine(); if (inLine != null && Integer.parseInt(inLine.substring(0, 1)) > 2) { inLine = null; os.writeBytes("su -V\n"); inLine = is.readLine(); if (inLine != null) { info.versionCode = Integer.parseInt(inLine); } } else { info.versionCode = 0; } } else { os.writeBytes("exit\n"); } } catch (IOException e) { Log.e(TAG, "Problems reading current version.", e); } finally { if (process != null) { process.destroy(); } } return info; }