aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager
diff options
context:
space:
mode:
Diffstat (limited to 'sdkmanager')
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolLoader.java90
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolWriter.java104
2 files changed, 194 insertions, 0 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolLoader.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolLoader.java
new file mode 100644
index 0000000..775c558
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolLoader.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.build;
+
+import com.google.common.base.Charsets;
+import com.google.common.collect.HashBasedTable;
+import com.google.common.collect.Table;
+import com.google.common.io.Files;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+/**
+ */
+public class SymbolLoader {
+
+ private final File mSymbolFile;
+ private HashBasedTable<String, String, SymbolEntry> mSymbols;
+
+ public static class SymbolEntry {
+ private final String mName;
+ private final String mType;
+ private final String mValue;
+
+ public SymbolEntry(String name, String type, String value) {
+ mName = name;
+ mType = type;
+ mValue = value;
+ }
+
+ public String getValue() {
+ return mValue;
+ }
+
+ public String getName() {
+ return mName;
+ }
+
+ public String getType() {
+ return mType;
+ }
+ }
+
+ public SymbolLoader(File symbolFile) {
+ mSymbolFile = symbolFile;
+ }
+
+ public void load() throws IOException {
+ List<String> lines = Files.readLines(mSymbolFile, Charsets.UTF_8);
+
+ mSymbols = HashBasedTable.create();
+
+ try {
+ for (String line : lines) {
+ // format is "<type> <class> <name> <value>"
+ // don't want to split on space as value could contain spaces.
+ int pos = line.indexOf(' ');
+ String type = line.substring(0, pos);
+ int pos2 = line.indexOf(' ', pos + 1);
+ String className = line.substring(pos + 1, pos2);
+ int pos3 = line.indexOf(' ', pos2 + 1);
+ String name = line.substring(pos2 + 1, pos3);
+ String value = line.substring(pos3 + 1);
+
+ mSymbols.put(className, name, new SymbolEntry(name, type, value));
+ }
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new IOException("File format error reading " + mSymbolFile.getAbsolutePath());
+ }
+ }
+
+ Table<String, String, SymbolEntry> getSymbols() {
+ return mSymbols;
+ }
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolWriter.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolWriter.java
new file mode 100644
index 0000000..63346c2
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/build/SymbolWriter.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdklib.internal.build;
+
+import com.android.SdkConstants;
+import com.android.sdklib.internal.build.SymbolLoader.SymbolEntry;
+import com.google.common.base.Charsets;
+import com.google.common.base.Splitter;
+import com.google.common.collect.Table;
+import com.google.common.io.Closeables;
+import com.google.common.io.Files;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ */
+public class SymbolWriter {
+
+ private final String mOutFolder;
+ private final String mPackageName;
+ private final SymbolLoader mSymbols;
+ private final SymbolLoader mValues;
+
+ public SymbolWriter(String outFolder, String packageName, SymbolLoader symbols,
+ SymbolLoader values) {
+ mOutFolder = outFolder;
+ mPackageName = packageName;
+ mSymbols = symbols;
+ mValues = values;
+ }
+
+ public void write() throws IOException {
+ Splitter splitter = Splitter.on('.');
+ Iterable<String> folders = splitter.split(mPackageName);
+ File file = new File(mOutFolder);
+ for (String folder : folders) {
+ file = new File(file, folder);
+ }
+ file.mkdirs();
+ file = new File(file, SdkConstants.FN_RESOURCE_CLASS);
+
+ BufferedWriter writer = null;
+ try {
+ writer = Files.newWriter(file, Charsets.UTF_8);
+
+ writer.write("/* AUTO-GENERATED FILE. DO NOT MODIFY.\n");
+ writer.write(" *\n");
+ writer.write(" * This class was automatically generated by the\n");
+ writer.write(" * aapt tool from the resource data it found. It\n");
+ writer.write(" * should not be modified by hand.\n");
+ writer.write(" */\n");
+
+ writer.write("package ");
+ writer.write(mPackageName);
+ writer.write(";\n\npublic final class R {\n");
+
+ Table<String, String, SymbolEntry> symbols = mSymbols.getSymbols();
+ Table<String, String, SymbolEntry> values = mValues.getSymbols();
+
+ for (String row : symbols.rowKeySet()) {
+ writer.write("\tpublic static final class ");
+ writer.write(row);
+ writer.write(" {\n");
+
+ for (Map.Entry<String, SymbolEntry> symbol : symbols.row(row).entrySet()) {
+ // get the matching SymbolEntry from the values Table.
+ SymbolEntry value = values.get(row, symbol.getKey());
+ if (value != null) {
+ writer.write("\t\tpublic static final ");
+ writer.write(value.getType());
+ writer.write(" ");
+ writer.write(value.getName());
+ writer.write(" = ");
+ writer.write(value.getValue());
+ writer.write(";\n");
+ }
+ }
+
+ writer.write("\t}\n");
+ }
+
+ writer.write("}\n");
+ } finally {
+ Closeables.closeQuietly(writer);
+ }
+ }
+} \ No newline at end of file