快速生成Plugman中的"lib-file"、"source-file"的xml内容

前端之家收集整理的这篇文章主要介绍了快速生成Plugman中的"lib-file"、"source-file"的xml内容前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

目录结果:



工具类:

package com.inforstack.plugman;

import java.io.File;

public class Plugin {
	//插件的相对目录
	private static String basePath = "src/android/demo";
	//插件的绝对目录
	private static String path = "D:\\work\\cordova\\plugin\\demo\\src\\android\\demo";

	public static void main(String[] args) {
		getFile(path);
	}

	private static void getFile(String path) {
		// 获取路径所在的文件列表
		File dirFile = new File(path);
		// 获取文件列表
		File[] array = dirFile.listFiles();
		for (File file : array) {
			if (file.isFile()) {
				toXML(file.getName(),file.getPath());
			} else if (file.isDirectory()) {
				getFile(file.getPath());
			}
		}
	}

	private static void toXML(String fileName,String filePath) {
		if (fileName.indexOf(".java") != -1 || fileName.indexOf(".xml") != -1 || fileName.indexOf(".png") != -1) {
			String newFilePath = filePath.replace(path,"");
			String newDirPath = newFilePath.replace("\\" + fileName,"");
			newDirPath = newDirPath.substring(1,newDirPath.length());
			String xml = String.format("<source-file src=\"%s%s\" target-dir=\"%s\" />",basePath,newFilePath,newDirPath);
			xml = xml.replace("\\","/");
			System.out.println(xml);
		} else if (fileName.indexOf(".jar") != -1) {
			String newFilePath = filePath.replace(path,"");
			String xml = String.format("<lib-file src=\"%s%s\"/>",newFilePath);
			xml = xml.replace("\\","/");
			System.out.println(xml);
		}
	}
}


结果:
<lib-file src="src/android/demo/libs/MobCommons-2016.1222.1756.jar"/>
<lib-file src="src/android/demo/libs/MobTools-2016.1222.1756.jar"/>
<source-file src="src/android/demo/res/values/ssdk_instapaper_strings.xml" target-dir="res/values" />
<source-file src="src/android/demo/src/cn/sharesdk/onekeyshare/Customerlogo.java" target-dir="src/cn/sharesdk/onekeyshare" />
<source-file src="src/android/demo/src/cn/sharesdk/onekeyshare/themes/classic/ClassicTheme.java" target-dir="src/cn/sharesdk/onekeyshare/themes/classic" />
<source-file src="src/android/demo/src/cn/sharesdk/onekeyshare/themes/classic/land/EditPageLand.java" target-dir="src/cn/sharesdk/onekeyshare/themes/classic/land" />
<source-file src="src/android/demo/src/cn/sharesdk/onekeyshare/themes/classic/port/EditPagePort.java" target-dir="src/cn/sharesdk/onekeyshare/themes/classic/port" />

猜你在找的XML相关文章