李敏 |
|
|||
日歷
統計
導航常用鏈接留言簿(1)文章分類
文章檔案
相冊收藏夾它山之石聚賢莊搜索最新評論
|
首先聲明,此方法不是我所發明。所以我在這里只是一個轉述者。 所謂暴力,即是通過普通方法無法完成而選用的下下策。 方法原理就是通過手工添加配置信息來進行強行安裝插件。(我目前只測試了SVN的插件,至于其他的插件則無法保證) 示例: 向MyEclipse8.6中安裝SVN插件。 準備工作: 1)下載site-1.6.18.zip文件包 2)插件配置代碼生成器(PluginConfigCreator.java) 3)備份MyEclipse-8.6\configuration 文件夾 步驟: 1)根據個人的開發習慣來安排site-1.6.18.zip中的文件 2)用“插件配置代碼生成器”來生成指定目錄下所包含的插件的配置信息 3)把配置信息寫入到configuration\org.eclipse.equinox.simpleconfigurator目錄下的bundles.info中 最后再來展示PluginConfigCreator.java源碼。(為了編譯方便,所以沒有采用“顯示行號”的樣式) import java.io.File; import java.util.ArrayList; import java.util.List; /** * 9. * MyEclipse9 插件配置代碼生成器 10. * 11. * 12. */ public class PluginConfigCreator { public PluginConfigCreator() { } public void print(String path) { List<String> list = getFileList(path); if (list == null) { return; } int length = list.size(); for (int i = 0; i < length; i++) { String result = ""; String thePath = getFormatPath(getString(list.get(i))); File file = new File(thePath); if (file.isDirectory()) { String fileName = file.getName(); if (fileName.indexOf("_") < 0) { print(thePath); continue; } String[] filenames = fileName.split("_"); String filename1 = filenames[0]; String filename2 = filenames[1]; result = filename1 + "," + filename2 + ",file:/" + path + "\\" + fileName + "\\,4,false"; System.out.println(result); } else if (file.isFile()) { String fileName = file.getName(); if (fileName.indexOf("_") < 0) { continue; } int last = fileName.lastIndexOf("_");// 最后一個下劃線的位置 String filename1 = fileName.substring(0, last); String filename2 = fileName.substring(last + 1, fileName .length() - 4); result = filename1 + "," + filename2 + ",file:/" + path + "\\" + fileName + ",4,false"; System.out.println(result); } } } public List<String> getFileList(String path) { path = getFormatPath(path); path = path + "/"; File filePath = new File(path); if (!filePath.isDirectory()) { return null; } String[] filelist = filePath.list(); List<String> filelistFilter = new ArrayList<String>(); for (int i = 0; i < filelist.length; i++) { String tempfilename = getFormatPath(path + filelist[i]); filelistFilter.add(tempfilename); } return filelistFilter; } public String getString(Object object) { if (object == null) { return ""; } return String.valueOf(object); } public String getFormatPath(String path) { path = path.replaceAll("\\\\", "/"); path = path.replaceAll("//", "/"); return path; } public static void main(String[] args) { /* 你的插件的安裝目錄 (切記文件分隔符) */ String plugin = "D:\\Project\\Tools\\Java\\SDK\\Genuitec\\MyEclipse-8.6\\third-plugin\\site-1.6.18"; new PluginConfigCreator().print(plugin); } } 由于以上源碼采用的是控制臺輸出信息的方式,所以不方便采集。不過,我們可以通過一個DOS命令來解決這個問題。 C:\bin>java PluginConfigCreator > c:\config.txt “>”命令可以進行簡單的IO輸出。這里則是把輸出信息保存到C盤下的一個名為config的文本文件中。 原文: http://heisetoufa.iteye.com/blog/994724
|
![]() |
|
Copyright © 李敏 | Powered by: 博客園 模板提供:滬江博客 |