soc.2012.android: b7e74353: Documented rules for ant, gave extractco...
michael at soc.pidgin.im
michael at soc.pidgin.im
Mon May 28 07:18:24 EDT 2012
----------------------------------------------------------------------
Revision: b7e743537d55de04975119fefcc3503b7a3d7f65
Parent: a9b9e815db3424846349fe791eb95e77ac16194b
Author: michael at soc.pidgin.im
Date: 05/28/12 06:52:16
Branch: im.pidgin.soc.2012.android
URL: http://d.pidgin.im/viewmtn/revision/info/b7e743537d55de04975119fefcc3503b7a3d7f65
Changelog:
Documented rules for ant, gave extractconstants an override=true|false attribute
Changes against parent a9b9e815db3424846349fe791eb95e77ac16194b
patched android/workspace/im.pidgin.libpurple.build/buildscripts/common.ant
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractorException.java
patched android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/libs/LibraryDirectory.java
-------------- next part --------------
============================================================
--- android/workspace/im.pidgin.libpurple.build/buildscripts/common.ant 4d1403aa5e0469e7d10b29838efc1edff0eb674a
+++ android/workspace/im.pidgin.libpurple.build/buildscripts/common.ant 1582ece752285ed42b4509468c54118bda477e47
@@ -14,7 +14,7 @@
<dirname file="${ant.file.libpurple.buildscripts}" property="libpurple.buildscripts"/>
<dirname file="${libpurple.buildscripts}" property="build.base"/>
-
+
<property name="libpurple.downloads" location="${build.base}/downloads" />
<property name="libpurple.build" location="${build.base}/build" />
<property name="libpurple.prefix" location="${build.base}/build/prefix" />
@@ -48,13 +48,13 @@
<available file="${builddir}" property="download.builddir.exists" />
</target>
-
+
<!-- - - - - - - - - - - - - - - - - -
target: configure
- - - - - - - - - - - - - - - - - -->
<target name="configure-default" depends="configure-set-no-flags,configure-set-no-precommand">
<mkdir dir="${libpurple.prefix}" />
-<echo message="
+ <echo message="
cd "${builddir}" || exit 1;
export PATH="${ndk.bin}:$PATH";
${configure.precommand}
@@ -106,13 +106,13 @@
" />
</exec>
</target>
-
+
<!-- - - - - - - - - - - - - - - - - -
target: build-set-no-flags
- - - - - - - - - - - - - - - - - -->
- <target name="build-set-no-flags" unless="make.flags">
- <property name="make.flags" value=""/>
- </target>
+ <target name="build-set-no-flags" unless="make.flags">
+ <property name="make.flags" value=""/>
+ </target>
@@ -141,20 +141,20 @@
<!-- =================================
target: ant-contrib.load
================================= -->
- <target name="ant-contrib.load" depends="" description="Initializes and loads ant contrib">
-
- <taskdef resource="net/sf/antcontrib/antlib.xml">
- </taskdef>
-
- <path id="bin">
- <pathelement path="${build.base}/bin"/>
- </path>
-
- <taskdef name="extractconstants" classpathref="bin" classname="im.pidgin.libpurple.build.constants.ExtractConstants"></taskdef>
- <taskdef name="enum" classpathref="bin" classname="im.pidgin.libpurple.build.constants.EnumName"></taskdef>
- <taskdef name="constant" classpathref="bin" classname="im.pidgin.libpurple.build.constants.ConstantName"></taskdef>
-
- <taskdef name="replaceLibNames" classpathref="bin" classname="im.pidgin.libpurple.build.libs.ReplaceLibNames"></taskdef>
- </target>
-
+ <target name="ant-contrib.load" depends="" description="Initializes and loads ant contrib">
+
+ <taskdef resource="net/sf/antcontrib/antlib.xml">
+ </taskdef>
+
+ <path id="bin">
+ <pathelement path="${build.base}/bin"/>
+ </path>
+
+ <taskdef name="extractconstants" classpathref="bin" classname="im.pidgin.libpurple.build.constants.ExtractConstants">
+ </taskdef>
+
+ <taskdef name="replaceLibNames" classpathref="bin" classname="im.pidgin.libpurple.build.libs.ReplaceLibNames">
+ </taskdef>
+ </target>
+
</project>
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java abf381881d98656c8177474d0b06294431eee761
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/EnumObject.java d8cb8adf2760f9a156807c13ca6762355843019e
@@ -5,101 +5,103 @@ import java.util.regex.Pattern;
/**
* This is a enum from a C file
+ *
* @author michaelz
- *
+ *
*/
public class EnumObject {
- private static final String ITEM_PATTERN_STRING = "\\s*(\\w+)\\s*(?:=\\s*(-?\\d+|0x[\\da-fA-F]+)\\s*)?";
- private static final Pattern ITEM_PATTERN = Pattern.compile(
- ITEM_PATTERN_STRING);
- private static final String IGNORED_ENUM_PARTS = "/\\*[\\s\\S]*?\\*/|//[^\\n]*";
- public static final String ENUM_PATTERN_STRING =
- "\\s*typedef\\s+enum\\s+\\{\\s*([^\\}]*?)\\s*,?\\s*\\}\\s*(\\w+)\\s*;";
- private static final Pattern ENUM_PATTERN = Pattern.compile(ENUM_PATTERN_STRING);
- private final String name;
- private final EnumItem[] items;
- private final String commonString;
+ private static final String ITEM_PATTERN_STRING = "\\s*(\\w+)\\s*(?:=\\s*(-?\\d+|0x[\\da-fA-F]+)\\s*)?";
+ private static final Pattern ITEM_PATTERN = Pattern
+ .compile(ITEM_PATTERN_STRING);
+ private static final String IGNORED_ENUM_PARTS = "/\\*[\\s\\S]*?\\*/|//[^\\n]*";
+ public static final String ENUM_PATTERN_STRING = "\\s*typedef\\s+enum\\s+\\{\\s*([^\\}]*?)\\s*,?\\s*\\}\\s*(\\w+)\\s*;";
+ private static final Pattern ENUM_PATTERN = Pattern
+ .compile(ENUM_PATTERN_STRING);
+ private final String name;
+ private final EnumItem[] items;
+ private final String commonString;
- public EnumObject(String enumSource) {
- String uncommentedSource = enumSource.replaceAll(IGNORED_ENUM_PARTS, "");
- Matcher m =
- ENUM_PATTERN.matcher(
- uncommentedSource);
- if (!m.matches()) {
- throw new IllegalArgumentException(
- "Input does not match outer enum pattern (typedef enum {...} <name>)");
+ public EnumObject(String enumSource) {
+ String uncommentedSource = enumSource
+ .replaceAll(IGNORED_ENUM_PARTS, "");
+ Matcher m = ENUM_PATTERN.matcher(uncommentedSource);
+ if (!m.matches()) {
+ throw new IllegalArgumentException(
+ "Input does not match outer enum pattern (typedef enum {...} <name>)");
+ }
+ name = m.group(2);
+ String[] content = m.group(1).split(",");
+ items = new EnumItem[content.length];
+ int nextValue = 0;
+ for (int i = 0; i < content.length; i++) {
+ Matcher m2 = ITEM_PATTERN.matcher(content[i]);
+ if (!m2.matches()) {
+ throw new IllegalArgumentException("Enum constant " + i
+ + " does not match expected item regexp. Got: "
+ + content[i]);
}
- name = m.group(2);
- String[] content = m.group(1).split(",");
- items = new EnumItem[content.length];
- int nextValue = 0;
- for (int i = 0; i < content.length; i++) {
- Matcher m2 =
- ITEM_PATTERN
- .matcher(content[i]);
- if (!m2.matches()) {
- throw new IllegalArgumentException("Enum constant " + i
- + " does not match expected item regexp. Got: "
- + content[i]);
- }
- String valueString = m2.group(2);
- if (valueString != null && !valueString.isEmpty()) {
- nextValue = ConstantExtractor.parseInteger(valueString);
- }
- items[i] = new EnumItem(m2.group(1), nextValue);
- nextValue++;
+ String valueString = m2.group(2);
+ if (valueString != null && !valueString.isEmpty()) {
+ nextValue = ConstantExtractor.parseInteger(valueString);
}
+ items[i] = new EnumItem(m2.group(1), nextValue);
+ nextValue++;
+ }
- String commonString = computeCommonString(content);
- this.commonString = commonString;
- }
+ String commonString = computeCommonString(content);
+ this.commonString = commonString;
+ }
- private String computeCommonString(String[] content) {
- String commonString;
- if (content.length > 0) {
- commonString = items[0].getName();
- for (int i = 1; i < items.length; i++) {
- commonString = getCommonStart(items[i].getName(), commonString);
- }
- } else {
- commonString = "";
+ private String computeCommonString(String[] content) {
+ String commonString;
+ if (content.length > 0) {
+ commonString = items[0].getName();
+ for (int i = 1; i < items.length; i++) {
+ commonString = getCommonStart(items[i].getName(), commonString);
}
- return commonString;
+ } else {
+ commonString = "";
}
+ return commonString;
+ }
- private static String getCommonStart(String string, String string2) {
- int end = Math.min(string.length(), string2.length());
- for (int i = 0; i < end; i++) {
- if (string.charAt(i) != string2.charAt(i)) {
- return string.substring(0, i);
- }
+ private static String getCommonStart(String string, String string2) {
+ int end = Math.min(string.length(), string2.length());
+ for (int i = 0; i < end; i++) {
+ if (string.charAt(i) != string2.charAt(i)) {
+ return string.substring(0, i);
}
- return string.substring(0, end);
}
+ return string.substring(0, end);
+ }
- /**
- * Gets the name of the enum.
- * @return The name as declared in the C file
- */
- public String getName() {
- return name;
- }
+ /**
+ * Gets the name of the enum.
+ *
+ * @return The name as declared in the C file
+ */
+ public String getName() {
+ return name;
+ }
- /**
- * gets the items of the enum as array.
- * @return All items as array.
- */
- public EnumItem[] getItems() {
- return items;
- }
+ /**
+ * gets the items of the enum as array.
+ *
+ * @return All items as array.
+ */
+ public EnumItem[] getItems() {
+ return items;
+ }
- /**
- * Gets a shorter version of the item name
- * @param item The item index
- * @return The name with the common part for this enum stripped.
- */
- public String getNiceItemName(int item) {
- return items[item].getName().substring(commonString.length());
- }
+ /**
+ * Gets a shorter version of the item name
+ *
+ * @param item
+ * The item index
+ * @return The name with the common part for this enum stripped.
+ */
+ public String getNiceItemName(int item) {
+ return items[item].getName().substring(commonString.length());
+ }
}
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java b80d1c4cc11655193c25c09fb9e8731a29c7cc62
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractConstants.java 8c0239ef2f34c70e46490e67051701f3e81a6f9a
@@ -5,27 +5,53 @@ import java.util.LinkedList;
import java.io.PrintWriter;
import java.util.LinkedList;
+/**
+ * This is an ant rule that extracts constants and enums from a C header file to
+ * a java class.
+ * <p>
+ * Usage:
+ *
+ * <pre>
+ * <extractconstants
+ * input="<i>headerfile</i>"
+ * output="<i>Java file name</i>"
+ * package="<i>java package name to include in file</i>">
+ * <constant name="<i>C constant (#define) name</i>"/>
+ * <enum name="<i>Enum name</i>"/>
+ * </extractconstants>
+ *
+ * </pre>
+ *
+ *
+ * @author michaelz
+ *
+ */
public class ExtractConstants {
-
+
private String input = "";
private String output = "";
-
+
private final LinkedList<ConstantName> constants = new LinkedList<ConstantName>();
private final LinkedList<EnumName> enums = new LinkedList<EnumName>();
private String packageString = "";
+
+ private Boolean override = false;
-
public void setInput(String input) {
this.input = input;
-
+
}
public void setOutput(String output) {
this.output = output;
}
+
+ public void setPackage(String packageString) {
+ this.packageString = packageString;
+ }
- public void setPackage(String packageString) {
- this.packageString = packageString;
+ public void setOverride(Boolean override) {
+ this.override = override;
}
public ConstantName createConstant() {
@@ -33,77 +59,89 @@ public class ExtractConstants {
constants.add(name);
return name;
}
-
+
public EnumName createEnum() {
EnumName name = new EnumName();
enums.add(name);
return name;
}
-
+
/**
* This method is called by ant to execute this build item.
+ *
* @throws ExtractorException
*/
public void execute() throws ExtractorException {
try {
File in = new File(input);
-
+
File out = new File(output);
-
- ConstantExtractor extractor = new ConstantExtractor();
-
- extractor.parseFile(in);
-
- PrintWriter writer;
- try {
- writer = new PrintWriter(out);
- } catch (FileNotFoundException e) {
- throw new ExtractorException(e.getMessage());
- }
-
- writeFileHeader(writer);
-
- for (EnumName name : enums) {
- EnumObject e = extractor.getEnum(name.getName());
- if (e == null) {
- throw new ExtractorException("Enum " + name.getName() + " not found.");
- }
-
- for (EnumItem item : e.getItems()) {
- String itemName = item.getName();
- int value = item.getValue();
- writeIntConstant(writer, itemName, value);
- }
- System.out.println("Enum " + name.getName() + " extracted.");
+ if (override || out.lastModified() < in.lastModified()) {
+ extractConstants(in, out);
+ } else {
+ System.out.println("Skipping unmofidied " + in.getName());
}
-
- for (ConstantName name : constants) {
- int value = extractor.getIntegerConstant(name.getName());
- writeIntConstant(writer, name.getName(), value);
- System.out.println("Constant " + name.getName() + " extracted.");
- }
- writeFooter(writer);
- writer.close();
-
+
} catch (RuntimeException t) {
t.printStackTrace();
throw t;
}
}
+ private void extractConstants(File in, File out) throws ExtractorException {
+ ConstantExtractor extractor = new ConstantExtractor();
+
+ extractor.parseFile(in);
+
+ PrintWriter writer;
+ try {
+ writer = new PrintWriter(out);
+ } catch (FileNotFoundException e) {
+ throw new ExtractorException(e.getMessage());
+ }
+
+ writeFileHeader(writer);
+
+ for (EnumName name : enums) {
+ EnumObject e = extractor.getEnum(name.getName());
+ if (e == null) {
+ throw new ExtractorException("Enum " + name.getName()
+ + " not found.");
+ }
+
+ for (EnumItem item : e.getItems()) {
+ String itemName = item.getName();
+ int value = item.getValue();
+ writeIntConstant(writer, itemName, value);
+ }
+ System.out.println("Enum " + name.getName() + " extracted.");
+ }
+
+ for (ConstantName name : constants) {
+ int value = extractor.getIntegerConstant(name.getName());
+ writeIntConstant(writer, name.getName(), value);
+ System.out
+ .println("Constant " + name.getName() + " extracted.");
+ }
+ writeFooter(writer);
+ writer.close();
+ }
+
private void writeFileHeader(PrintWriter writer) {
if (!packageString.isEmpty()) {
- writer.println("package " + packageString + ";");
- }
- writer.println();
- String className = new File(output).getName().replaceAll("\\.java$", "");
- writer.println("public final class " + className + " {");
- writer.println("\tprivate " + className + "() {}");
- writer.println();
+ writer.println("package " + packageString + ";");
+ }
+ writer.println();
+ String className = new File(output).getName()
+ .replaceAll("\\.java$", "");
+ writer.println("public final class " + className + " {");
+ writer.println("\tprivate " + className + "() {}");
+ writer.println();
}
private void writeIntConstant(PrintWriter writer, String itemName, int value) {
- writer.println("\tpublic static final int " + itemName + " = " + value + ";\n");
+ writer.println("\tpublic static final int " + itemName + " = " + value
+ + ";\n");
}
private void writeFooter(PrintWriter writer) {
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractorException.java 0b71f52fe428caf493a9b76897479e6d64c53265
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/constants/ExtractorException.java f41c584aa25a709ba12d5605e1bca69fa1130257
@@ -1,7 +1,7 @@ package im.pidgin.libpurple.build.consta
package im.pidgin.libpurple.build.constants;
/**
- * This exception is thrown if something during the neum extraction process goes
+ * This exception is thrown if something during the enum extraction process goes
* wrong.
*
* @author michaelz
@@ -9,29 +9,29 @@ public class ExtractorException extends
*/
public class ExtractorException extends Exception {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
public ExtractorException() {
- // TODO Auto-generated constructor stub
}
public ExtractorException(String message) {
super(message);
- // TODO Auto-generated constructor stub
}
public ExtractorException(Throwable cause) {
super(cause);
- // TODO Auto-generated constructor stub
}
public ExtractorException(String message, Throwable cause) {
super(message, cause);
- // TODO Auto-generated constructor stub
}
public ExtractorException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
- // TODO Auto-generated constructor stub
}
}
============================================================
--- android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/libs/LibraryDirectory.java 01295f98e08a3a2f48f3c1350584df636be06704
+++ android/workspace/im.pidgin.libpurple.build/src/im/pidgin/libpurple/build/libs/LibraryDirectory.java 97aa9f4d101e68af37f7b2d072f30f0a478755bb
@@ -2,6 +2,11 @@ import java.io.File;
import java.io.File;
+/**
+ * @see ReplaceLibNames#createDirectory()
+ * @author michaelz
+ *
+ */
public class LibraryDirectory {
private File dir;
More information about the Commits
mailing list