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

📄 eclipseclasspath.java

📁 一个查找java程序里bug的程序的源代码,该程序本身也是java写的,对提高java编程水平很有用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				pluginId = attributes.getValue("Bundle-SymbolicName");				if (pluginId == null)					throw new EclipseClasspathException("Missing Bundle-SymbolicName in " + manifestFileName);				pluginId = stripSemiPart(pluginId);				// Get the plugin version				pluginVersion = attributes.getValue("Bundle-Version");				if (pluginVersion == null)					throw new EclipseClasspathException("Missing Bundle-Version in " + manifestFileName);				// Get required plugins				String required = attributes.getValue("Require-Bundle");				if (required != null) {					StringTokenizer tok = new StringTokenizer(required, ",");					while (tok.hasMoreTokens()) {						String requiredPlugin = tok.nextToken();						requiredPlugin = requiredPlugin.trim();						requiredPlugin = stripSemiPart(requiredPlugin);						//System.out.println("Required plugin=" +requiredPlugin);						requiredPluginIdList.add(requiredPlugin);					}				}				// Get exported libraries				String exported = attributes.getValue("Bundle-ClassPath");				if (exported != null) {					StringTokenizer tok2 = new StringTokenizer(exported, ",");					while (tok2.hasMoreTokens()) {						String jar = tok2.nextToken();						jar = jar.trim();						jar = stripSemiPart(jar);						exportedLibraryList.add(directory + File.separator + jar);					}				}			} catch (IOException e) {				throw new EclipseClasspathException("Could not parse Eclipse 3.0 plugin in " + directory, e);			} finally {				try {					if (in != null)						in.close();				} catch (IOException e) {					// Ignore				}			}		}		private String stripSemiPart(String s) {			int semi = s.indexOf(';');			if (semi >= 0)				s = s.substring(0, semi);			return s;		}	}	private static final Pattern pluginDirPattern = Pattern.compile("^(\\w+(\\.\\w+)*)_(\\w+(\\.\\w+)*)$");	private static final int PLUGIN_ID_GROUP = 1;	private String eclipseDir;	private String rootPluginDir;	private Map<String, File> pluginDirectoryMap;	private Map<String, String> varMap;	private Plugin rootPlugin;	private List<String> importList;	public EclipseClasspath(String eclipseDir, String rootPluginDir) {		this.eclipseDir = eclipseDir;		this.rootPluginDir = rootPluginDir;		this.pluginDirectoryMap = new HashMap<String, File>();		this.varMap = new HashMap<String, String>();	}	public void addRequiredPlugin(String pluginId, String pluginDir) {		pluginDirectoryMap.put(pluginId, new File(pluginDir));	}	private static class WorkListItem {		private String directory;		private boolean isDependent;		public WorkListItem(String directory, boolean isDependent) {			this.directory = directory;			this.isDependent = isDependent;		}		public String getDirectory() { return directory; }		public boolean isDependent() { return isDependent; }	}	public EclipseClasspath execute() throws EclipseClasspathException, DocumentException, IOException {		// Build plugin directory map		File pluginDir = new File(eclipseDir, "plugins");		File[] dirList = pluginDir.listFiles(new FileFilter() {			public boolean accept(File pathname) {				return pathname.isDirectory();			}		});		if (dirList == null)			throw new EclipseClasspathException("Could not list plugins in directory " + pluginDir);		for (int i = 0; i < dirList.length; ++i) {			String dirName = dirList[i].getName();			String pluginId = getPluginId(dirName);			if (pluginId != null) {				//System.out.println(pluginId + " ==> " + dirList[i]);				pluginDirectoryMap.put(pluginId, dirList[i]);				// HACK - see if we can deduce the value of the special "ws" variable.				if (pluginId.startsWith("org.eclipse.swt.")) {					String ws = pluginId.substring("org.eclipse.swt.".length());					if (ws.equals("gtk64"))						ws = "gtk";					varMap.put("ws", new File(dirList[i] + File.separator + "ws" + File.separator + ws).getPath().replace('\\', '/'));				}			}		}		Map<String, Plugin> requiredPluginMap = new HashMap<String, Plugin>();		LinkedList<WorkListItem> workList = new LinkedList<WorkListItem>();		workList.add(new WorkListItem(rootPluginDir, false));		while (!workList.isEmpty()) {			WorkListItem item = workList.removeFirst();			Plugin plugin = new Plugin(item.getDirectory(), item.isDependent());			requiredPluginMap.put(plugin.getId(), plugin);			if (!plugin.isDependent()) {				if (rootPlugin != null) throw new IllegalStateException("multiple root plugins");				this.rootPlugin = plugin;			}			// Add unresolved required plugins to the worklist			for (Iterator<String> i = plugin.requiredPluginIdIterator(); i.hasNext(); ) {				String requiredPluginId = i.next();				if (requiredPluginMap.get(requiredPluginId) == null) {					// Find the plugin's directory					File requiredPluginDir = pluginDirectoryMap.get(requiredPluginId);					if (requiredPluginDir == null)						throw new EclipseClasspathException("Unable to find plugin " + requiredPluginId);					workList.add(new WorkListItem(requiredPluginDir.getPath(), true));				}			}		}		//System.out.println("Found " + requiredPluginMap.size() + " required plugins");		importList = new LinkedList<String>();		for (Iterator<Plugin> i = requiredPluginMap.values().iterator(); i.hasNext(); ) {			Plugin plugin = i.next();			if (plugin.isDependent()) {				for (Iterator<String> j = plugin.exportedLibraryIterator(); j.hasNext(); ) {					//System.out.println("Import: " + j.next());					importList.add(j.next());				}			}		}		return this;	}	public Iterator<String> importListIterator() {		return importList.iterator();	}	public String getClasspath() {		if (importList == null) throw new IllegalStateException("execute() has not been called");		StringBuffer buf = new StringBuffer();		boolean first = true;		Iterator <String> i = importListIterator();		while (i.hasNext()) {			if (first)				first = false;			else				buf.append(File.pathSeparator);			buf.append(i.next());		}		// Convert backslashes to forward slashes,		// since raw backslashes cause problems in .properties files.		String s = buf.toString();		s = s.replace('\\', '/');		return s;	}	public Plugin getRootPlugin() {		return rootPlugin;	}	/**	 * Get the plugin id for given directory name.	 * Returns null if the directory name does not seem to	 * be a plugin.	 */	private String getPluginId(String dirName) {		Matcher m = pluginDirPattern.matcher(dirName);		return m.matches() ? m.group(PLUGIN_ID_GROUP) : null;	}	/**	 * Expand variables of the form $varname$ in library names.	 * This is used to handle the "$ws$" substitution used to refer to	 * the plugin containing swt.jar.	 */	private String replaceSpecial(String value) {		if (!varMap.isEmpty()) {			for (Iterator<String> i = varMap.keySet().iterator(); i.hasNext(); ) {				String key = i.next();				String replace = varMap.get(key);				Pattern pat = Pattern.compile("\\$\\Q" + key + "\\E\\$");				Matcher m = pat.matcher(value);				StringBuffer buf = new StringBuffer();					while (m.find())					m.appendReplacement(buf, replace);				m.appendTail(buf);					value = buf.toString();			}		}		return value;	}	public static void main(String[] argv) throws Exception {		if (argv.length < 2 || (argv.length % 2 != 0)) {			System.err.println("Usage: " + EclipseClasspath.class.getName() +				" <eclipse dir> <root plugin directory> [<required plugin id> <required plugin dir> ...]");			System.exit(1);		}		EclipseClasspath ec = new EclipseClasspath(argv[0], argv[1]);		for (int i = 2; i < argv.length; i += 2) {			ec.addRequiredPlugin(argv[i], new File(argv[i+1]).getAbsolutePath());		}		// Generate a build.properties file which communicates to Ant:		//   - what the build classpath should be		//   - what the plugin id and version are		ec.execute();		System.out.println("plugin.build.classpath=" + ec.getClasspath());		System.out.println("plugin.id=" + ec.getRootPlugin().getId());		System.out.println("plugin.version=" + ec.getRootPlugin().getVersion());	}}// vim:ts=4

⌨️ 快捷键说明

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