⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bundlehtmlextractortask.java

📁 OSGI这是一个中间件,与UPNP齐名,是用于移植到嵌入式平台之上
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
      pkgExportMap     = parseNames(attribs.getValue("Export-Package"));      pkgImportMap     = parseNames(attribs.getValue("Import-Package"));      serviceExportMap = parseNames(attribs.getValue("Export-Service"));      serviceImportMap = parseNames(attribs.getValue("Import-Service"));      if(true) {	extractSource(jarFile, new File(replace(file.getAbsolutePath(), ".jar", "") + "/src"));      }    }        // String -> String    Map sourceMap = new TreeMap();    boolean bSourceInside = false;    void extractSource(JarFile jarFile, File destDir) throws IOException {      String prefix = "OSGI-OPT/src";      int count = 0;      for(Enumeration e = jarFile.entries(); e.hasMoreElements(); ) {	ZipEntry entry = (ZipEntry)e.nextElement();		if(entry.getName().startsWith("OSGI-OPT/src")) {	  count++;	}      }      if(count > 0) {	bSourceInside = true;	//	System.out.println("found " + count + " source files in " + jarFile.getName());	//	System.out.println("creating "+ destDir.getAbsolutePath());	destDir.mkdirs();	for(Enumeration e = jarFile.entries(); e.hasMoreElements(); ) {	  ZipEntry entry = (ZipEntry)e.nextElement();	  	  if(entry.getName().startsWith(prefix)) {	    if(entry.isDirectory()) {	      makeDir(jarFile, entry, destDir, prefix);	    } else {	      copyEntry(jarFile, entry, destDir, prefix);	      String s = replace(entry.getName(), prefix + "/", "");	      sourceMap.put(s, s);	    }	    count++;	  }	}      } else {		// Check if we can copy source from original pos	String sourceDir = (String)attribs.getValue("Built-From");	if(sourceDir != null && !"".equals(sourceDir)) {	  File src = new File(sourceDir, "src");	  copyTree(src, destDir, sourceDir + "\\src\\", ".java");	}      }    }    void copyTree(File src, File dest, 		  String prefix,		  String suffix) throws IOException {      if(src.isDirectory()) {	if(!dest.exists()) {	  dest.mkdirs();	}		String[] files = src.list();	for(int i = 0; i < files.length; i++) {	  copyTree(new File(src, files[i]),		   new File(dest, files[i]),		   prefix,		   suffix);	}      } else if(src.isFile()) {	if(src.getName().endsWith(suffix)) {	  String path = src.getAbsolutePath();	  String s = replace(replace(path, prefix, ""), "\\", "/");	  	  copyStream(new FileInputStream(src),  new FileOutputStream(dest));	  sourceMap.put(s, s);	}      }    }            void makeDir(ZipFile file, 		 ZipEntry entry, 		 File destDir,		 String prefix) throws IOException {      File d = new File(destDir, replace(entry.getName(), prefix, ""));            d.mkdirs();      //      System.out.println("created dir  " + d.getAbsolutePath());    }            void copyEntry(ZipFile file, 		   ZipEntry entry, 		   File destDir,		   String prefix) throws IOException {      File d = new File(destDir, replace(entry.getName(), prefix, ""));            File dir = d.getParentFile();            if(!dir.exists()) {	dir.mkdirs();      }            //      System.out.println("extracting to " + d.getAbsolutePath());            copyStream(new BufferedInputStream(file.getInputStream(entry)),		 new BufferedOutputStream(new FileOutputStream(d)));    }        void copyStream(InputStream is, OutputStream os) throws IOException {      byte[] buf = new byte[1024];                  BufferedInputStream in   = null;      BufferedOutputStream out = null;      try {	in  = new BufferedInputStream(is);	out = new BufferedOutputStream(os);	int n;	int total = 0;	while ((n = in.read(buf)) > 0) {	  out.write(buf, 0, n);	  total += n;	}      } finally {	try { in.close(); } catch (Exception ignored) { } 	try { out.close(); } catch (Exception ignored) { }       }    }        Map parseNames(String s) {            Map map = new TreeMap();      //      System.out.println(file + ": " + s);      if(s != null) {	s = s.trim();	String[] lines = Util.splitwords(s, ",", '\"');	for(int i = 0; i < lines.length; i++) {	  String[] words = Util.splitwords(lines[i].trim(), ";", '\"');	  if(words.length < 1) {	    throw new RuntimeException("bad package spec '" + s + "'"); 	  }	  String spec = ArrayInt.UNDEF;	  String name = words[0].trim();	  for(int j = 1; j < words.length; j++) {	    String[] info = Util.splitwords(words[j], "=", '\"');	    if(info.length == 2) {	      if("specification-version".equals(info[0].trim())) {		spec = info[1].trim();	      }	    }	  }	  	  //	  System.out.println(" " + i + ": " + name + ", version=" + spec);	  ArrayInt version = new ArrayInt(spec);	  map.put(name, version);	}      }      return map;    }    public void writeInfo() throws IOException {            //    System.out.println("jar info from " + file);            String template = stdReplace(Util.load(getBundleInfoTemplate().getAbsolutePath()));      String outName  = (String)vars.get("html.file");            Util.writeStringToFile(new File(outName), template);    }        public String stdReplace(String template) throws IOException {      return stdReplace(template, true);    }    public String stdReplace(String template, boolean bDepend) throws IOException {      for(Iterator it = globalVars.keySet().iterator(); it.hasNext(); ) {	Object key = it.next();	Object val = globalVars.get(key);		template = replace(template, "${" + key + "}", "" + val);		//      System.out.println(key + "->" + val);      }      for(Iterator it = vars.keySet().iterator(); it.hasNext(); ) {	Object key = it.next();	Object val = vars.get(key);		template = replace(template, "${" + key + "}", "" + val);		//      System.out.println(key + "->" + val);      }            Set handledSet = new TreeSet();            for(Iterator it = attribs.keySet().iterator(); it.hasNext(); ) {	Object key = it.next();	if(-1 != template.indexOf("${" + key.toString() + "}")) {	  handledSet.add(key.toString());	}      }      for(Iterator it = attribs.keySet().iterator(); it.hasNext(); ) {	Object key = it.next();	Object val = attribs.get(key);	      	String str = (String)attribs.get(key);		if("Export-Package".equals(key.toString()) ||	   "Import-Package".equals(key.toString()) ||	   "Import-Service".equals(key.toString()) ||	   "Export-Service".equals(key.toString())) {	} else {	  if(listPropSet.contains(key.toString())) {	    str = replace(str, ",", listSeparator);	  }	  	  template = replace(template, "${" + key + "}", str);	}      }                  template = replace(template, 			 "${Export-Package}", 			 getPackageString(pkgExportMap, 					  "/package-summary.html"));            template = replace(template, 			 "${Import-Package}", 			 getPackageString(pkgImportMap, 					  "/package-summary.html"));            template = replace(template, 			 "${Export-Service}", 			 getPackageString(serviceExportMap, 					  ".html"));            template = replace(template, 			 "${Import-Service}", 			 getPackageString(serviceImportMap, 					  ".html"));                  for(Iterator it = alwaysPropSet.iterator(); it.hasNext(); ) {	String key = (String)it.next();	String val = "";		template = replace(template, "${" + key + "}", val);      }      StringBuffer sb = new StringBuffer();      for(Iterator it = attribs.keySet().iterator(); it.hasNext(); ) {	Object key = it.next();		if(!handledSet.contains(key.toString())) {	  if(!skipAttribSet.contains(key.toString())) {	    sb.append("<tr>\n" + 		      " <td>" + key + "</td>\n" + 		      " <td>" + attribs.getValue(key.toString()) + "</td>\n" + 		      "</tr>\n");	  }	}      }            template = replace(template,  "${MF.UNHANDLED}",  sb.toString());            template = replace(template,  "${FILE}",  file.getName());      template = replace(template,  "${FILE.short}",  replace(file.getName(), ".jar", ""));      template = replace(template,  "${BYTES}", "" + file.length());      template = replace(template,  "${KBYTES}", "" + (file.length() / 1024));            template = replace(template,  "${relpath}",     relPath);      template = replace(template,  "${javadocdir}",  			 javadocRelPath != null ? javadocRelPath : "");            if(bDepend) {	unresolvedMap = new TreeMap();	template = replace(template, 			   "${depending.list}", 			   getDepend(				     new MapSelector() {					 public Map getMap(BundleInfo info) {					   return info.pkgExportMap;					 }				       },				     new MapSelector() {					 public Map getMap(BundleInfo info) {					   return info.pkgImportMap;					 }				       },				     null,				     false));		template = replace(template, 			   "${depends.list}",			   getDepend(				     new MapSelector() {					 public Map getMap(BundleInfo info) {					   return info.pkgImportMap;					 }				       },				     new MapSelector() {					 public Map getMap(BundleInfo info) {					   return info.pkgExportMap;					 }				       },				     unresolvedMap,				     true));	      }      sb = new StringBuffer();      if(sourceMap.size() > 0) {	String srcBase = replace(file.getName(), ".jar", "") + "/src";		sb.append("<table>");	for(Iterator it = sourceMap.keySet().iterator(); it.hasNext();) {	  String name = (String)it.next();	  	  	  sb.append(" <tr>\n");	  sb.append("  <td>\n");	  sb.append("  <a href=\"" + srcBase + "/" + name + "\">" + name + "<a>\n");	  sb.append(" </tr>\n");	  sb.append(" </tr>\n");	  	}	sb.append("</table>");	      } else{	sb.append("None found");      }      template = replace(template, "${sources.list}", sb.toString());      if(bSourceInside && sourceMap.size() > 0) {	template = replace(template, 			   "${FILEINFO}", 			   file.length() + " bytes, includes <a href=\"#source\">source</a>");      } else {	template = replace(template, 			   "${FILEINFO}", 			   file.length() + " bytes");      }            return template;    }          String getDepend(MapSelector importMap, 		     MapSelector exportMap,		     Map         unresolvedMapDest,		     boolean bShowUnresolved) throws IOException {      Map map        = new TreeMap();      if(unresolvedMapDest == null) {	unresolvedMapDest = new TreeMap();      }      for(Iterator it = importMap.getMap(this).keySet().iterator(); it.hasNext(); ) {	String   name    = (String)it.next();	ArrayInt version = (ArrayInt)importMap.getMap(this).get(name);		boolean bFound = false;	for(Iterator it2 = jarMap.keySet().iterator(); it2.hasNext();) {	  File jarFile = (File)it2.next();	  BundleInfo info = (BundleInfo)jarMap.get(jarFile);	  	  for(Iterator it3 = exportMap.getMap(info).keySet().iterator(); it3.hasNext(); ) {	    String   name2    = (String)it3.next();	    ArrayInt version2 = (ArrayInt)exportMap.getMap(info).get(name);	    	    if(name.equals(name2)) {	      if(version2.compareTo(version) >= 0) {		bFound = true;		map.put(jarFile, name);	      } else {		System.out.println(file + ": need " + name + " version " + version + ", found version " + version2);	      }	    }	  }	}	if(!bFound && !isSystemPackage(name)) {	  unresolvedMapDest.put(name, version);	}      }      StringBuffer sb = new StringBuffer();            if(map.size() == 0 && unresolvedMapDest.size() == 0) {	sb.append("None found");      } else {	for(Iterator it = map.keySet().iterator(); it.hasNext();) {	  Object     key     = it.next();	  File       jarFile = (File)key;	  BundleInfo info    = (BundleInfo)jarMap.get(jarFile);	  String     what    = (String)map.get(jarFile);	  	  String row = info.stdReplace(bundleRow, false);	  	  row = replace(row, "${what}", what);	  row = replace(row, 			"${bundledoc}", 			replace(relPath + info.path, ".jar", ".html"));	  sb.append(row);	}	if(bShowUnresolved) {	  if(unresolvedMapDest.size() > 0) {	    String row = missingRow;	    	    row = replace(row, "${name}",    "<b>Unresolved</b>");	    row = replace(row, "${version}", "");	    	    sb.append(row);	  }	  for(Iterator it = unresolvedMapDest.keySet().iterator(); it.hasNext();) {	    String   name    = (String)it.next();	    ArrayInt version = (ArrayInt)unresolvedMapDest.get(name);	    	    String row = missingRow;	    	    row = replace(row, "${name}",    name);	    row = replace(row, "${version}", version.toString());	    	    sb.append(row);	    	  }	}      }      return sb.toString();    }	    String getPackageString(Map map, String linkSuffix) {      StringBuffer sb = new StringBuffer();            for(Iterator it = map.keySet().iterator(); it.hasNext(); ) {	String   name    = (String)it.next();	ArrayInt version = (ArrayInt)map.get(name);		String html = pkgHTML;	String docFile = replace(name, ".", "/") + linkSuffix;		String docPath = relPath + javadocRelPath + "/" + docFile;		File f = new File(file.getParentFile(), docPath);	if(javadocRelPath != null && !"".equals(javadocRelPath)) {	  if(bCheckJavaDoc && !f.exists() && !isSystemPackage(name)) {	    html = replace(html, "${namelink}", "${name}");	    missingDocs.put(name, this);	  } else {	    html = replace(html, 			 "${namelink}", "<a href=\"${javadoc}\">${name}</a>");	  }	} else {	  html = replace(html, "${namelink}", "${name}");	}		String row     = replace(html, "${name}", name);	row = replace(row, "${version}", version.toString());	row = replace(row, "${javadoc}", docPath);      	sb.append(row);      }      return sb.toString();    }  }     boolean isSystemPackage(String name) {    for(Iterator it = systemPackageSet.iterator(); it.hasNext();) {      String prefix = (String)it.next();      if(name.startsWith(prefix)) {	return true;      }    }    return false;  }  String replace(String src, String a, String b) {    return Util.replace(src, a, b == null ? "" : b);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -