Move ant.prop to sdk.prop and up a folder.
this file is meant to have general sdk properties, not
just Ant ones.
Also separated the library support from the Ant build version.
It's clearer whether or not libraries are supported, and it's
not just tied to Ant anyway (ADT needs to know as well).
Finally use that new property to do checks on library support
in both the custom Ant tasks and ADT.
Depends on a CL in development.git (sdk.atree change).
Change-Id: I77d229ed3fd60f0468b1d3d31f7cf147b03a32fb
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java
index 8facf62..2c0ad53 100644
--- a/anttasks/src/com/android/ant/SetupTask.java
+++ b/anttasks/src/com/android/ant/SetupTask.java
@@ -171,7 +171,8 @@
}
// check that this version of the custom Ant task can build this target
- int antBuildVersion = androidTarget.getAntBuildRevision();
+ int antBuildVersion = androidTarget.getProperty(SdkConstants.PROP_SDK_ANT_BUILD_REVISION,
+ 1);
if (antBuildVersion > ANT_RULES_MAX_VERSION) {
throw new BuildException(String.format(
"The project target (%1$s) requires a more recent version of the tools. Please update.",
@@ -200,6 +201,14 @@
}
System.out.println("API level: " + androidTarget.getVersion().getApiString());
+ // do a quick check to make sure the target supports library.
+ if (isLibrary &&
+ androidTarget.getProperty(SdkConstants.PROP_SDK_SUPPORT_LIBRARY, false) == false) {
+ throw new BuildException(String.format(
+ "Project target '%1$s' does not support building libraries.",
+ androidTarget.getFullName()));
+ }
+
// always check the manifest minSdkVersion.
checkManifest(antProject, androidTarget.getVersion());
@@ -274,7 +283,7 @@
if (rules.isFile() == false) {
throw new BuildException(String.format("Build rules file '%s' is missing.",
- templateFolder));
+ rules));
}
// set the file location to import
@@ -390,7 +399,8 @@
// get the build version for the current target. It'll be tested if there's at least
// one library.
- int antBuildVersion = androidTarget.getAntBuildRevision();
+ boolean supportLibrary = androidTarget.getProperty(SdkConstants.PROP_SDK_SUPPORT_LIBRARY,
+ false);
int index = 1;
while (true) {
@@ -401,7 +411,7 @@
break;
}
- if (antBuildVersion < SdkConstants.ANT_REV_LIBRARY) {
+ if (supportLibrary == false) {
throw new BuildException(String.format(
"The build system for this project target (%1$s) does not support libraries",
androidTarget.getFullName()));
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.java
index aef8692..b665a53 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.java
@@ -21,6 +21,7 @@
import com.android.ide.eclipse.adt.internal.sdk.LoadStatus;
import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.sdklib.IAndroidTarget;
+import com.android.sdklib.SdkConstants;
import com.android.sdklib.IAndroidTarget.IOptionalLibrary;
import org.eclipse.core.resources.IMarker;
@@ -177,6 +178,16 @@
// first make sure the target has loaded its data
Sdk.getCurrent().checkAndLoadTargetData(target, null /*project*/);
+ // now do a quick check to make sure the project's target is compatible
+ // with library (if applicable).
+ if (state.hasLibraries() &&
+ target.getProperty(
+ SdkConstants.PROP_SDK_SUPPORT_LIBRARY, false) == false) {
+ AdtPlugin.printErrorToConsole(iProject, String.format(
+ "Target '%1$s' does not support building project with libraries.",
+ target.getFullName()));
+ }
+
String targetName = target.getClasspathName();
return new AndroidClasspathContainer(
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectState.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectState.java
index 646b87f..b5ad1f0 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectState.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/project/ProjectState.java
@@ -310,6 +310,15 @@
}
/**
+ * Returns whether the project depends on one or more libraries.
+ */
+ public boolean hasLibraries() {
+ synchronized (mLibraries) {
+ return mLibraries.size() > 0;
+ }
+ }
+
+ /**
* Returns whether the project is missing some required libraries.
*/
public boolean isMissingLibraries() {
diff --git a/files/ant.properties b/files/ant.properties
deleted file mode 100644
index a690414..0000000
--- a/files/ant.properties
+++ /dev/null
@@ -1,3 +0,0 @@
-# revision for the Ant build files and templates
-ant.build.revision=2
-ant.templates.revision=1
\ No newline at end of file
diff --git a/files/sdk.properties b/files/sdk.properties
new file mode 100644
index 0000000..a48a85d
--- /dev/null
+++ b/files/sdk.properties
@@ -0,0 +1,4 @@
+# SDK properties
+sdk.build.support.library=true
+sdk.ant.build.revision=2
+sdk.ant.templates.revision=1
\ No newline at end of file
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/AddOnTarget.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/AddOnTarget.java
index 00c5ceb..f3da39c 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/AddOnTarget.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/AddOnTarget.java
@@ -212,18 +212,18 @@
return mBasePlatform.getProperty(name);
}
+ public Integer getProperty(String name, Integer defaultValue) {
+ return mBasePlatform.getProperty(name, defaultValue);
+ }
+
+ public Boolean getProperty(String name, Boolean defaultValue) {
+ return mBasePlatform.getProperty(name, defaultValue);
+ }
+
public Map<String, String> getProperties() {
return mBasePlatform.getProperties();
}
- public int getAntBuildRevision() {
- return mBasePlatform.getAntBuildRevision();
- }
-
- public int getAntTemplatesRevision() {
- return mBasePlatform.getAntTemplatesRevision();
- }
-
public int getUsbVendorId() {
return mVendorId;
}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java
index 8035ab0..b143fb1 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/IAndroidTarget.java
@@ -181,22 +181,36 @@
String getProperty(String name);
/**
+ * Returns the value of a given property for this target as an Integer value.
+ * <p/> If the value is missing or is not an integer, the method will return the given default
+ * value.
+ * @param name the name of the property to return
+ * @param defaultValue the default value to return.
+ *
+ * @see Integer#decode(String)
+ */
+ Integer getProperty(String name, Integer defaultValue);
+
+ /**
+ * Returns the value of a given property for this target as a Boolean value.
+ * <p/> If the value is missing or is not an boolean, the method will return the given default
+ * value.
+ *
+ * @param name the name of the property to return
+ * @param defaultValue the default value to return.
+ *
+ * @see Boolean#valueOf(String)
+ */
+
+ Boolean getProperty(String name, Boolean defaultValue);
+
+ /**
* Returns all the properties associated with this target. This can be null if the target has
* no properties.
*/
Map<String, String> getProperties();
/**
- * Returns the revision number of the Ant build system supported by this target.
- */
- int getAntBuildRevision();
-
- /**
- * Returns the revision number of the Ant templates supported by this target.
- */
- int getAntTemplatesRevision();
-
- /**
* Returns the USB Vendor ID for the vendor of this target.
* <p/>If the target defines no USB Vendor ID, then the method return 0.
*/
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/PlatformTarget.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/PlatformTarget.java
index 53e7127..ed09e5f 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/PlatformTarget.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/PlatformTarget.java
@@ -258,32 +258,32 @@
return mProperties.get(name);
}
+ public Integer getProperty(String name, Integer defaultValue) {
+ try {
+ String value = getProperty(name);
+ if (value != null) {
+ return Integer.decode(value);
+ }
+ } catch (NumberFormatException e) {
+ // ignore, return default value;
+ }
+
+ return defaultValue;
+ }
+
+ public Boolean getProperty(String name, Boolean defaultValue) {
+ String value = getProperty(name);
+ if (value != null) {
+ return Boolean.valueOf(value);
+ }
+
+ return defaultValue;
+ }
+
public Map<String, String> getProperties() {
return mProperties; // mProperties is unmodifiable.
}
- public int getAntBuildRevision() {
- try {
- String value = getProperty("ant.build.revision");
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- // ignore, return 1;
- }
-
- return 1;
- }
-
- public int getAntTemplatesRevision() {
- try {
- String value = getProperty("ant.templates.revision");
- return Integer.parseInt(value);
- } catch (NumberFormatException e) {
- // ignore, return 1;
- }
-
- return 1;
- }
-
// ---- platform only methods.
void setSkins(String[] skins) {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
index 847e3d1..747081d 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkConstants.java
@@ -120,8 +120,8 @@
public final static String FN_SOURCE_PROP = "source.properties"; //$NON-NLS-1$
/** properties file for content hash of installed packages */
public final static String FN_CONTENT_HASH_PROP = "content_hash.properties"; //$NON-NLS-1$
- /** properties file for Ant revisions */
- public final static String FN_ANT_PROP = "ant.properties"; //$NON-NLS-1$
+ /** properties file for the SDK */
+ public final static String FN_SDK_PROP = "sdk.properties"; //$NON-NLS-1$
/* Folder Names for Android Projects . */
@@ -271,8 +271,12 @@
/** Skin default **/
public final static String SKIN_DEFAULT = "default";
- /** Ant revision value: Library support introduction */
- public final static int ANT_REV_LIBRARY = 2;
+ /** SDK property: support for library */
+ public final static String PROP_SDK_SUPPORT_LIBRARY = "sdk.build.support.library"; //$NON-NLS-1$
+ /** SDK property: ant build revision */
+ public final static String PROP_SDK_ANT_BUILD_REVISION = "sdk.ant.build.revision"; //$NON-NLS-1$
+ /** SDK property: ant templates revision */
+ public final static String PROP_SDK_ANT_TEMPLATES_REVISION = "sdk.ant.templates.revision"; //$NON-NLS-1$
/** Returns the appropriate name for the 'android' command, which is 'android.bat' for
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java
index 457f78d..519e8fb 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/SdkManager.java
@@ -336,13 +336,10 @@
}
// Ant properties
- File templateFolder = new File(platform, SdkConstants.FD_TEMPLATES);
- if (templateFolder.isDirectory()) {
- File antPropFile = new File(templateFolder, SdkConstants.FN_ANT_PROP);
- Map<String, String> antProp = parsePropertyFile(antPropFile, log);
- if (antProp != null) {
- map.putAll(antProp);
- }
+ File sdkPropFile = new File(platform, SdkConstants.FN_SDK_PROP);
+ Map<String, String> antProp = parsePropertyFile(sdkPropFile, log);
+ if (antProp != null) {
+ map.putAll(antProp);
}
// api number and name look valid, perform a few more checks
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
index 4165b5d..2e49a0a 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/project/ProjectCreator.java
@@ -446,7 +446,7 @@
// before doing anything, make sure library (if present) can be applied.
if (libraryPath != null) {
IAndroidTarget finalTarget = target != null ? target : originalTarget;
- if (finalTarget.getAntBuildRevision() < SdkConstants.ANT_REV_LIBRARY) {
+ if (finalTarget.getProperty(SdkConstants.PROP_SDK_SUPPORT_LIBRARY, false) == false) {
mLog.error(null,
"The build system for this project target (%1$s) does not support libraries",
finalTarget.getFullName());
diff --git a/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockAddonPackage.java b/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockAddonPackage.java
index 051a7cb..e99463b 100755
--- a/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockAddonPackage.java
+++ b/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockAddonPackage.java
@@ -96,6 +96,14 @@
return null;
}
+ public Integer getProperty(String name, Integer defaultValue) {
+ return defaultValue;
+ }
+
+ public Boolean getProperty(String name, Boolean defaultValue) {
+ return defaultValue;
+ }
+
public Map<String, String> getProperties() {
return null;
}
@@ -140,13 +148,5 @@
public int compareTo(IAndroidTarget o) {
throw new UnsupportedOperationException("Implement this as needed for tests");
}
-
- public int getAntBuildRevision() {
- return 1;
- }
-
- public int getAntTemplatesRevision() {
- return 1;
- }
}
}
diff --git a/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java b/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java
index 35817f2..0a58487 100755
--- a/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java
+++ b/sdkmanager/libs/sdklib/tests/com/android/sdklib/internal/repository/MockPlatformPackage.java
@@ -128,6 +128,14 @@
return null;
}
+ public Integer getProperty(String name, Integer defaultValue) {
+ return defaultValue;
+ }
+
+ public Boolean getProperty(String name, Boolean defaultValue) {
+ return defaultValue;
+ }
+
public Map<String, String> getProperties() {
return null;
}
@@ -172,13 +180,5 @@
public int compareTo(IAndroidTarget o) {
throw new UnsupportedOperationException("Implement this as needed for tests");
}
-
- public int getAntBuildRevision() {
- return 1;
- }
-
- public int getAntTemplatesRevision() {
- return 1;
- }
}
}