版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/inforstack/article/details/78755362
目录结果:
工具类:
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\"/>", basePath,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" />