增加删除指定metaData里面内容的功能
parent
3cd8b8e15a
commit
a229e676a3
|
@ -68,6 +68,15 @@ public class ManifestEditorMain extends BaseCommand {
|
|||
", multi option is supported", argName = "application-attribute-name-value")
|
||||
private List<String> applicationAttributeList = new ArrayList<>();
|
||||
|
||||
@Opt(opt = "md", longOpt = "metaData", description = "add the meta data, " +
|
||||
" name and value should be separated by " + MULTI_NAME_SEPERATER +
|
||||
", multi option is supported", argName = "meta-data-name-value")
|
||||
private List<String> metaDataList = new ArrayList<>();
|
||||
|
||||
@Opt(opt = "dmd", longOpt = "deleteMetaDataList", description = "delete the meta data name" +
|
||||
", multi option is supported", argName = "delete-meta-data-name")
|
||||
private List<String> deleteMetaDataList = new ArrayList<>();
|
||||
|
||||
public static void main(String... args) {
|
||||
new ManifestEditorMain().doMain(args);
|
||||
}
|
||||
|
@ -227,6 +236,18 @@ public class ManifestEditorMain extends BaseCommand {
|
|||
}
|
||||
}
|
||||
|
||||
for (String metaData : metaDataList) {
|
||||
String[] nameValue = metaData.split(MULTI_NAME_SEPERATER);
|
||||
|
||||
if (nameValue.length == 2) {
|
||||
property.addMetaData(new ModificationProperty.MetaData(nameValue[0], nameValue[1]));
|
||||
}
|
||||
}
|
||||
|
||||
for (String metaData : deleteMetaDataList) {
|
||||
property.addDeleteMetaData(metaData);
|
||||
}
|
||||
|
||||
// property.addManifestAttribute(new AttributeItem(NodeValue.Manifest.PACKAGE, "wind.new.pkg.name111").setNamespace(null))
|
||||
// .addManifestAttribute(new AttributeItem(NodeValue.Manifest.VERSION_CODE, 1))
|
||||
// .addManifestAttribute(new AttributeItem(NodeValue.Manifest.VERSION_NAME, "1123"))
|
||||
|
|
|
@ -12,6 +12,7 @@ public class ModificationProperty {
|
|||
|
||||
private List<String> usesPermissionList = new ArrayList<>();
|
||||
private List<MetaData> metaDataList = new ArrayList<>();
|
||||
private List<MetaData> deleteMetaDataList = new ArrayList<>();
|
||||
|
||||
private List<AttributeItem> applicationAttributeList = new ArrayList<>();
|
||||
private List<AttributeItem> manifestAttributeList = new ArrayList<>();
|
||||
|
@ -52,6 +53,15 @@ public class ModificationProperty {
|
|||
return this;
|
||||
}
|
||||
|
||||
public List<MetaData> getDeleteMetaDataList() {
|
||||
return deleteMetaDataList;
|
||||
}
|
||||
|
||||
public ModificationProperty addDeleteMetaData(String name) {
|
||||
this.deleteMetaDataList.add(new MetaData(name, ""));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class MetaData {
|
||||
private String name;
|
||||
private String value;
|
||||
|
|
|
@ -5,7 +5,6 @@ import com.wind.meditor.property.ModificationProperty;
|
|||
import com.wind.meditor.utils.NodeValue;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pxb.android.axml.NodeVisitor;
|
||||
|
||||
/**
|
||||
|
@ -14,14 +13,17 @@ import pxb.android.axml.NodeVisitor;
|
|||
public class ApplicationTagVisitor extends ModifyAttributeVisitor {
|
||||
|
||||
private List<ModificationProperty.MetaData> metaDataList;
|
||||
private List<ModificationProperty.MetaData> deleteMetaDataList;
|
||||
private ModificationProperty.MetaData curMetaData;
|
||||
|
||||
private static final String META_DATA_FLAG = "meta_data_flag";
|
||||
|
||||
ApplicationTagVisitor(NodeVisitor nv, List<AttributeItem> modifyAttributeList,
|
||||
List<ModificationProperty.MetaData> metaDataList) {
|
||||
List<ModificationProperty.MetaData> metaDataList,
|
||||
List<ModificationProperty.MetaData> deleteMetaDataList) {
|
||||
super(nv, modifyAttributeList);
|
||||
this.metaDataList = metaDataList;
|
||||
this.deleteMetaDataList = deleteMetaDataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -32,6 +34,10 @@ public class ApplicationTagVisitor extends ModifyAttributeVisitor {
|
|||
return new MetaDataVisitor(nv, new ModificationProperty.MetaData(
|
||||
curMetaData.getName(), curMetaData.getValue()));
|
||||
}
|
||||
} else if (NodeValue.MetaData.TAG_NAME.equals(name)
|
||||
&& deleteMetaDataList != null && !deleteMetaDataList.isEmpty()) {
|
||||
NodeVisitor nv = super.child(ns, name);
|
||||
return new DeleteMetaDataVisitor(nv, deleteMetaDataList);
|
||||
}
|
||||
return super.child(ns, name);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.wind.meditor.visitor;
|
||||
|
||||
import com.wind.meditor.property.ModificationProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import pxb.android.axml.NodeVisitor;
|
||||
|
||||
/**
|
||||
* @author Windysha
|
||||
*/
|
||||
public class DeleteMetaDataVisitor extends NodeVisitor {
|
||||
|
||||
private List<ModificationProperty.MetaData> deleteMetaDataList;
|
||||
private boolean shouldDeleteNode = false; // 此metaData的value包含在deleteMetaDataList中,则删除metaData内容
|
||||
|
||||
DeleteMetaDataVisitor(NodeVisitor nv, List<ModificationProperty.MetaData> deleteMetaDataList) {
|
||||
super(nv);
|
||||
this.deleteMetaDataList = deleteMetaDataList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attr(String ns, String name, int resourceId, int type, Object obj) {
|
||||
if ("name".equals(name) && !shouldDeleteNode) {
|
||||
for (ModificationProperty.MetaData data : deleteMetaDataList) {
|
||||
if (data.getName() != null && data.getName().equals(obj)) {
|
||||
shouldDeleteNode = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!shouldDeleteNode) {
|
||||
super.attr(ns, name, resourceId, type, obj);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -34,7 +34,7 @@ public class ManifestTagVisitor extends ModifyAttributeVisitor {
|
|||
NodeVisitor child = super.child(ns, name);
|
||||
if (NodeValue.Application.TAG_NAME.equals(name)) {
|
||||
return new ApplicationTagVisitor(child, properties.getApplicationAttributeList(),
|
||||
properties.getMetaDataList());
|
||||
properties.getMetaDataList(), properties.getDeleteMetaDataList());
|
||||
}
|
||||
|
||||
if (NodeValue.UsesPermission.TAG_NAME.equals(name)) {
|
||||
|
|
Loading…
Reference in New Issue