aboutsummaryrefslogtreecommitdiffstats
path: root/manifmerger/src
diff options
context:
space:
mode:
authorRaphael Moll <ralf@android.com>2012-09-14 13:53:51 -0700
committerRaphael Moll <ralf@android.com>2012-09-14 22:33:47 -0700
commit0386f5dcf9d0f472f243506be3c40f5cf46287a2 (patch)
treea42010d151dca8adcd712e79d4a0cf40316901d0 /manifmerger/src
parenta35f8af9eca38249b5c37391d7a7ae56c53251ad (diff)
downloadsdk-0386f5dcf9d0f472f243506be3c40f5cf46287a2.zip
sdk-0386f5dcf9d0f472f243506be3c40f5cf46287a2.tar.gz
sdk-0386f5dcf9d0f472f243506be3c40f5cf46287a2.tar.bz2
ManifestMerger: fix handling of codenames in min/targetSdkVersion.
The change is that the manifest merger will only accept a codename if it's invoked in a context that can resolve that codename to an API level. This allows to produce an error on bogus codenames and to properly check that the API levels match appropriately. Change-Id: Ic70c0c3690b13d94dba81bb78cc09386016b2ef1
Diffstat (limited to 'manifmerger/src')
-rwxr-xr-xmanifmerger/src/com/android/manifmerger/ICallback.java37
-rw-r--r--manifmerger/src/com/android/manifmerger/Main.java2
-rwxr-xr-xmanifmerger/src/com/android/manifmerger/ManifestMerger.java64
3 files changed, 89 insertions, 14 deletions
diff --git a/manifmerger/src/com/android/manifmerger/ICallback.java b/manifmerger/src/com/android/manifmerger/ICallback.java
new file mode 100755
index 0000000..26ae40d
--- /dev/null
+++ b/manifmerger/src/com/android/manifmerger/ICallback.java
@@ -0,0 +1,37 @@
+/*
+ * 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.manifmerger;
+
+import com.android.annotations.NonNull;
+
+/**
+ * Callback used by the ManifestMerger to query the caller.
+ */
+public interface ICallback {
+
+ public static final int UNKNOWN_CODENAME = 0;
+
+ /**
+ * Queries the caller to find the API level for a given provisional API codename,
+ * as used in the &lt;uses-sdk&gt; {@code minSdkVersion} field.
+ *
+ * @param codename A non-null codename string.
+ * @return The integer API > 0 for the given codename, or {@link #UNKNOWN_CODENAME}.
+ */
+ public int queryCodenameApiLevel(@NonNull String codename);
+
+}
diff --git a/manifmerger/src/com/android/manifmerger/Main.java b/manifmerger/src/com/android/manifmerger/Main.java
index 78da1a3..c48033f 100644
--- a/manifmerger/src/com/android/manifmerger/Main.java
+++ b/manifmerger/src/com/android/manifmerger/Main.java
@@ -57,7 +57,7 @@ public class Main {
// Create a new ManifestMerger and call its process method.
// It will take care of validating its own arguments.
- ManifestMerger mm = new ManifestMerger(MergerLog.wrapSdkLog(mSdkLog));
+ ManifestMerger mm = new ManifestMerger(MergerLog.wrapSdkLog(mSdkLog), null);
String[] libPaths = mArgvParser.getParamLibs();
File[] libFiles = new File[libPaths.length];
diff --git a/manifmerger/src/com/android/manifmerger/ManifestMerger.java b/manifmerger/src/com/android/manifmerger/ManifestMerger.java
index 8a61e67..2d5d3ec 100755
--- a/manifmerger/src/com/android/manifmerger/ManifestMerger.java
+++ b/manifmerger/src/com/android/manifmerger/ManifestMerger.java
@@ -45,7 +45,7 @@ import javax.xml.xpath.XPathExpressionException;
/**
* Merges a library manifest into a main application manifest.
* <p/>
- * To use, create with {@link ManifestMerger#ManifestMerger(IMergerLog)} then
+ * To use, create with {@link ManifestMerger#ManifestMerger(IMergerLog, ICallback)} then
* call {@link ManifestMerger#process(File, File, File[])}.
* <p/>
* <pre> Merge operations:
@@ -69,6 +69,7 @@ import javax.xml.xpath.XPathExpressionException;
* => Add. OK if already defined.
* E- uses-sdk:
* {@code @minSdkVersion}: error if dest&lt;lib. Never automatically change dest minsdk.
+ * Codenames are accepted if we can resolve their API level.
* {@code @targetSdkVersion}: warning if dest&lt;lib.
* Never automatically change dest targetsdk.
* {@code @maxSdkVersion}: obsolete, ignored. Not used in comparisons and not merged.
@@ -117,7 +118,9 @@ import javax.xml.xpath.XPathExpressionException;
public class ManifestMerger {
/** Logger object. Never null. */
- private IMergerLog mLog;
+ private final IMergerLog mLog;
+ /** An optional callback that the merger can use to query the calling SDK. */
+ private final ICallback mCallback;
private XPath mXPath;
private Document mMainDoc;
@@ -125,8 +128,15 @@ public class ManifestMerger {
private String NS_PREFIX = AndroidXPathFactory.DEFAULT_NS_PREFIX;
private int destMinSdk;
- public ManifestMerger(IMergerLog log) {
+ /**
+ * Creates a new {@link ManifestMerger}.
+ *
+ * @param log A non-null merger log to capture all warnings, errors and their location.
+ * @param callback An optional callback that the merger can use to query the calling SDK.
+ */
+ public ManifestMerger(@NonNull IMergerLog log, @Nullable ICallback callback) {
mLog = log;
+ mCallback = callback;
}
/**
@@ -726,11 +736,12 @@ public class ManifestMerger {
}
/**
- * Checks (but does not merge) uses-sdk attribues using the following rules:
+ * Checks (but does not merge) uses-sdk attributes using the following rules:
* <pre>
* - {@code @minSdkVersion}: error if dest&lt;lib. Never automatically change dest minsdk.
* - {@code @targetSdkVersion}: warning if dest&lt;lib. Never automatically change destination.
* - {@code @maxSdkVersion}: obsolete, ignored. Not used in comparisons and not merged.
+ * - The API level can be a codename if we have a callback that can convert it to an integer.
* </pre>
* @param libDoc The library document to merge from. Must not be null.
* @return True on success, false if any error occurred (printed to the {@link IMergerLog}).
@@ -838,6 +849,7 @@ public class ManifestMerger {
String s = destUsesSdk == null ? "" //$NON-NLS-1$
: destUsesSdk.getAttributeNS(NS_URI, attr + "SdkVersion"); //$NON-NLS-1$
+ boolean result = true;
assert s != null;
s = s.trim();
try {
@@ -846,14 +858,27 @@ public class ManifestMerger {
destImplied.set(false);
}
} catch (NumberFormatException e) {
- // Note: NumberFormatException.toString() has no interesting information
- // so we don't output it.
- mLog.error(Severity.ERROR,
+ boolean error = true;
+ if (mCallback != null) {
+ // Versions can contain codenames such as "JellyBean".
+ // We'll accept it only if have a callback that can give us the API level for it.
+ int apiLevel = mCallback.queryCodenameApiLevel(s);
+ if (apiLevel > ICallback.UNKNOWN_CODENAME) {
+ destValue.set(apiLevel);
+ destImplied.set(false);
+ error = false;
+ }
+ }
+ if (error) {
+ // Note: NumberFormatException.toString() has no interesting information
+ // so we don't output it.
+ mLog.error(Severity.ERROR,
xmlFileAndLine(destUsesSdk == null ? mMainDoc : destUsesSdk),
- "Failed to parse <uses-sdk %1$sSdkVersion='%2$s'>: must be an integer number.",
+ "Failed to parse <uses-sdk %1$sSdkVersion='%2$s'>: must be an integer number or codename.",
attr,
s);
- return false;
+ result = false;
+ }
}
s = srcUsesSdk == null ? "" //$NON-NLS-1$
@@ -866,15 +891,28 @@ public class ManifestMerger {
srcImplied.set(false);
}
} catch (NumberFormatException e) {
- mLog.error(Severity.ERROR,
+ boolean error = true;
+ if (mCallback != null) {
+ // Versions can contain codenames such as "JellyBean".
+ // We'll accept it only if have a callback that can give us the API level for it.
+ int apiLevel = mCallback.queryCodenameApiLevel(s);
+ if (apiLevel > ICallback.UNKNOWN_CODENAME) {
+ srcValue.set(apiLevel);
+ srcImplied.set(false);
+ error = false;
+ }
+ }
+ if (error) {
+ mLog.error(Severity.ERROR,
xmlFileAndLine(srcUsesSdk == null ? libDoc : srcUsesSdk),
- "Failed to parse <uses-sdk %1$sSdkVersion='%2$s'>: must be an integer number.",
+ "Failed to parse <uses-sdk %1$sSdkVersion='%2$s'>: must be an integer number or codename.",
attr,
s);
- return false;
+ result = false;
+ }
}
- return true;
+ return result;
}