`
winhkey
  • 浏览: 4218 次
文章分类
社区版块
存档分类
最新评论

myeclipse 7 插件

阅读更多

安装完myeclipse 7,发现原来的插件无法再用link添加,上网搜之,找到被很多人转的一段程序用来添加插件,但是我的插件都是统一放在d:/java/myplugins下的,有10来个,一个一个运行太麻烦了,于是把搜到的程序改一下,也没什么技术含量,只是做个备忘,等myeclipse的新版本出来应该会改良这个功能,这段程序到时候也许就没用了。

 

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class AddPluginsConfig
{
	private static void createContent(String path, StringBuffer buffer)
	{
		List<String> list = getFileList(path);
		if (list == null || list.isEmpty())
		{
			return;
		}
		String thePath = null;
		String fileName = null;
		String[] filenames = null;
		File file = null;
		for (String filePath : list)
		{
			thePath = getFormatPath(getString(filePath));
			file = new File(thePath);
			if (file.isDirectory())
			{
				fileName = file.getName();
				if (fileName.indexOf("_") < 0)
				{
					continue;
				}
				filenames = fileName.split("_");
				buffer.append(filenames[0]).append(",").append(filenames[1]).append(",file:/").append(path).append(fileName).append("/,4,false");
			}
			else if (file.isFile())
			{
				fileName = file.getName();
				if (fileName.indexOf("_") < 0)
				{
					continue;
				}
				filenames = fileName.split("_");
				buffer.append(filenames[0]).append(",").append(filenames[1].substring(0, filenames[1] .lastIndexOf("."))).append(",file:/").append(path).append(fileName).append(",4,false");
			}
			buffer.append(System.getProperty("line.separator"));
		}
	}

	private static 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;
	}

	private static String getString(Object object) {
		if (object == null)
		{
			return "";
		}
		return String.valueOf(object);
	}

	private static String getFormatPath(String path)
	{
		path = path.replaceAll("\\\\", "/");
		path = path.replaceAll("//", "/");
		return path;
	}
	
	private static void addContentByWriter(String fileName, String content) throws IOException
	{
		FileWriter writer = new FileWriter(fileName, true);
		writer.write(content);
		writer.close();
	}
	
	/**
	 * 将插件路径加入文件
	 * @param directory 自定义插件路径
	 * @param path myeclipse7安装路径
	 * @throws IOException
	 */
	public static void addContent(String directory, String path) throws IOException
	{
		File parentDir = new File(directory);
		File[] list = parentDir.listFiles();
		StringBuffer buffer = new StringBuffer();
		for (File dir : list)
		{
			if (dir.isDirectory())
			{
				createContent(dir.getPath() + "/eclipse/plugins", buffer);
			}
		}
		addContentByWriter(path + "/MyEclipse 7.0/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info", buffer.toString());
	}

	public static void main(String[] args) throws IOException
	{
		addContent("d:/java/myplugins", "d:/Program Files/Genuitec");
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics