Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jellybean42 mtk #12

Open
wants to merge 19 commits into
base: ics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ResValuesModify/jar/ResValuesModify
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

java -jar $PORT_ROOT/tools/ResValuesModify/jar/ResValuesModify.jar $*


Binary file added ResValuesModify/jar/ResValuesModify.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions ResValuesModify/jar/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# NOTE:
# default operation is replace dest node with src node if the dest node exist or
# append src node to the file if dest node doesn't exist
#
# - type [name]
# explicitly declare don't merge this kind of nodes
#
# + type [name]
# explicitly declare that merge this kind of nodes
#
# I array-type [name]
# explicitly declare that to insert new 'items' for 'array' type instead of default replacement
# insert new items to the head of array
# priority of "+" and "I" is higher then "-"

- add-resource

I string-array config_statusBarIcons
21 changes: 21 additions & 0 deletions ResValuesModify/src/Log.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Log {
public static void i(String info){
System.out.println(info);
}

public static void i(String tag, String info){
System.out.println( String.format("INFO[%s]: %s", tag, info));
}

public static void e(String tag, String err){
System.err.println( String.format("ERROR[%s]: %s", tag, err));
}

public static void w(String tag, String err){
System.err.println( String.format("WARING[%s]: %s", tag, err));
}

public static void e(String err){
System.err.println(err);
}
}
79 changes: 79 additions & 0 deletions ResValuesModify/src/ResValuesModify.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import java.io.File;
import java.util.ArrayList;

public class ResValuesModify {
private ArrayList<File> mSrcFiles = new ArrayList<File>();
private ArrayList<File> mDestFiles = new ArrayList<File>();
private ArrayList<File> mConfigFiles = new ArrayList<File>();
private static final String LOG_TAG = "CHECK";

public static void main(String[] args) {
ResValuesModify resVM = new ResValuesModify();
if (!resVM.checkArgs(args) || !resVM.checkPath(args)) {
resVM.usage();
return;
}
resVM.mergeXML();
}

private boolean checkArgs(String[] args) {
boolean ret = true;
if (args.length < 2) {
Log.e(LOG_TAG, "invalid argument count");
return false;
}

if (args[0].equals(args[1])) {
Log.e(LOG_TAG, "src dir is the same with dest dir");
ret = false;
}

for (int i = 2; i < args.length; i++) {
File f = new File(args[i]);
if (f.exists() && f.isFile()) {
mConfigFiles.add(f);
} else {
Log.i(LOG_TAG, "ignore config file:" + f.getName());
}
}
return ret;
}

private boolean checkPath(String[] args) {
return perpareXmlFiles(args[0], mSrcFiles) && perpareXmlFiles(args[1], mDestFiles);
}

private void mergeXML() {
(new XMLMerge(mSrcFiles, mDestFiles, mConfigFiles)).merge();
}

private void usage() {
Log.i("USAGE: ");
Log.i("ResValuesModify src-values-dir dest-values-dir [config-files ...]");
Log.i(" config-files: config file that explicitly declare merge-rule");
Log.i("");
}

private boolean perpareXmlFiles(String path, ArrayList<File> xmlFiles) {
File dir = new File(path);
if (!dir.isDirectory()) {
Log.w(LOG_TAG, path + " : no such directory");
return false;
}

File[] files = dir.listFiles();
for (File f : files) {
if (f.isFile()) {
if (f.getName().endsWith(".xml") || f.getName().endsWith(".xml.part")) {
xmlFiles.add(f);
}
}
}

if (0 == xmlFiles.size()) {
Log.w(LOG_TAG, "No xml file in " + path);
return false;
}
return true;
}
}
Loading