aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdklib/src
diff options
context:
space:
mode:
authorXavier Ducrohet <xav@android.com>2010-02-18 19:52:14 -0800
committerXavier Ducrohet <xav@android.com>2010-02-23 16:18:21 -0800
commit610a7584cd2ede40772dbe95bd59e525a3859837 (patch)
tree01b03dcafc9aca050b7eba98933edac12eb6afea /sdkmanager/libs/sdklib/src
parente87bc60813f90110c1156b086138e5e856c93809 (diff)
downloadsdk-610a7584cd2ede40772dbe95bd59e525a3859837.zip
sdk-610a7584cd2ede40772dbe95bd59e525a3859837.tar.gz
sdk-610a7584cd2ede40772dbe95bd59e525a3859837.tar.bz2
ADT: Library support: source folder and pre-compiler.
This is the first step in the library support. For each library, create a source folder in the main project that is linked to the source folder of the library project. The linked resources use a path variable named after the library in the format: _android_<library name>. These variables are always created when the link is created. For now the link is recreated all the time, but we could do a check and not redo it if it's already done. Additionally, the pre-compiler creates the R class from the res folders of the main and library projects. Some misc fixes/clean-ups: * Fix an issue with the new ProjectState where opening a project would not trigger a load of its target data. * Changed the lock for all SDK operation: - moved the lock in Sdk accessible as Sdk.getLock() - made the few Sdk method that used their own synchronize block use the same lock as all others. * removed the builders project and moved its content to sdklib This was meant as a way to share code between the Eclipse builders and the Ant tasks but sdklib is already used by both, so it's better to put the code in sdklib than have yet another project. Change-Id: Ibfa449c7a809f28e428c03bbda8215969717ecde
Diffstat (limited to 'sdkmanager/libs/sdklib/src')
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java78
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java70
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java36
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java38
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractResource.java35
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/StreamException.java28
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java46
7 files changed, 331 insertions, 0 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java
new file mode 100644
index 0000000..b8af4be
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2008 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.io;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * An implementation of {@link IAbstractFile} on top of a {@link File} object.
+ *
+ */
+public class FileWrapper implements IAbstractFile {
+
+ private final File mFile;
+
+ /**
+ * Constructs a {@link FileWrapper} object. The underlying {@link File} object needs not
+ * exist or be a valid file.
+ */
+ public FileWrapper(File file) {
+ mFile = file;
+ }
+
+ public InputStream getContents() throws StreamException {
+ try {
+ return new FileInputStream(mFile);
+ } catch (FileNotFoundException e) {
+ throw new StreamException(e);
+ }
+ }
+
+ public String getOsLocation() {
+ return mFile.getAbsolutePath();
+ }
+
+ public String getName() {
+ return mFile.getName();
+ }
+
+ public boolean exists() {
+ return mFile.isFile();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof FileWrapper) {
+ return mFile.equals(((FileWrapper)obj).mFile);
+ }
+
+ if (obj instanceof File) {
+ return mFile.equals(obj);
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return mFile.hashCode();
+ }
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java
new file mode 100644
index 0000000..a9269ad
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2008 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.io;
+
+
+import java.io.File;
+
+/**
+ * An implementation of {@link IAbstractFolder} on top of a {@link File} object.
+ */
+public class FolderWrapper implements IAbstractFolder {
+
+ private final File mFolder;
+
+ /**
+ * Constructs a {@link FileWrapper} object. The underlying {@link File} object needs not exists
+ * or be a valid directory.
+ */
+ public FolderWrapper(File folder) {
+ mFolder = folder;
+ }
+
+ public boolean hasFile(String name) {
+ return false;
+ }
+
+ public IAbstractFile getFile(String name) {
+ return new FileWrapper(new File(mFolder, name));
+ }
+
+ public String getName() {
+ return mFolder.getName();
+ }
+
+ public boolean exists() {
+ return mFolder.isDirectory();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof FolderWrapper) {
+ return mFolder.equals(((FolderWrapper)obj).mFolder);
+ }
+
+ if (obj instanceof File) {
+ return mFolder.equals(obj);
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return mFolder.hashCode();
+ }
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java
new file mode 100644
index 0000000..f96ede6
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2008 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.io;
+
+import java.io.InputStream;
+
+/**
+ * A file.
+ */
+public interface IAbstractFile extends IAbstractResource {
+
+ /**
+ * Returns an {@link InputStream} object on the file content.
+ * @throws CoreException
+ */
+ InputStream getContents() throws StreamException;
+
+ /**
+ * Returns the OS path of the file location.
+ */
+ String getOsLocation();
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java
new file mode 100644
index 0000000..22f654b
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2008 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.io;
+
+
+/**
+ * A folder.
+ */
+public interface IAbstractFolder extends IAbstractResource {
+
+ /**
+ * Returns true if the receiver contains a file with a given name
+ * @param name the name of the file. This is the name without the path leading to the
+ * parent folder.
+ */
+ boolean hasFile(String name);
+
+ /**
+ * returns an {@link IAbstractFile} representing a child of the current folder with the
+ * given name. The file may not actually exist.
+ * @param name the name of the file.
+ */
+ IAbstractFile getFile(String name);
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractResource.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractResource.java
new file mode 100644
index 0000000..b34a404
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractResource.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2008 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.io;
+
+/**
+ * Base representation of a file system resource.<p/>
+ * This somewhat limited interface is designed to let classes use file-system resources, without
+ * having the manually handle either the standard Java file or the Eclipse file API..
+ */
+public interface IAbstractResource {
+
+ /**
+ * Returns the name of the resource.
+ */
+ String getName();
+
+ /**
+ * Returns whether the resource actually exists.
+ */
+ boolean exists();
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/StreamException.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/StreamException.java
new file mode 100644
index 0000000..70b1c8e
--- /dev/null
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/StreamException.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010 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.io;
+
+/**
+ * Exception thrown when {@link IAbstractFile#getContents()} fails.
+ */
+public class StreamException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public StreamException(Exception e) {
+ super(e);
+ }
+}
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java
index c4fa8bc..ae61a32 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/xml/AndroidManifest.java
@@ -16,6 +16,16 @@
package com.android.sdklib.xml;
+import com.android.sdklib.SdkConstants;
+import com.android.sdklib.internal.io.IAbstractFile;
+import com.android.sdklib.internal.io.IAbstractFolder;
+import com.android.sdklib.internal.io.StreamException;
+
+import org.xml.sax.InputSource;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+
/**
* Helper and Constants for the AndroidManifest.xml file.
*
@@ -43,6 +53,21 @@ public final class AndroidManifest {
public final static String ATTRIBUTE_TARGET_PACKAGE = "targetPackage"; //$NON-NLS-1$
public final static String ATTRIBUTE_EXPORTED = "exported"; //$NON-NLS-1$
+ public static String getPackage(IAbstractFolder projectFolder)
+ throws XPathExpressionException, StreamException {
+ IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
+ return getPackage(file);
+ }
+
+ public static String getPackage(IAbstractFile manifestFile)
+ throws XPathExpressionException, StreamException {
+ XPath xPath = AndroidXPathFactory.newXPath();
+
+ return xPath.evaluate(
+ "/" + NODE_MANIFEST +
+ "/@" + ATTRIBUTE_PACKAGE,
+ new InputSource(manifestFile.getContents()));
+ }
/**
* Combines a java package, with a class value from the manifest to make a fully qualified
@@ -77,4 +102,25 @@ public final class AndroidManifest {
}
}
+ /**
+ * Given a fully qualified activity name (e.g. com.foo.test.MyClass) and given a project
+ * package base name (e.g. com.foo), returns the relative activity name that would be used
+ * the "name" attribute of an "activity" element.
+ *
+ * @param fullActivityName a fully qualified activity class name, e.g. "com.foo.test.MyClass"
+ * @param packageName The project base package name, e.g. "com.foo"
+ * @return The relative activity name if it can be computed or the original fullActivityName.
+ */
+ public static String extractActivityName(String fullActivityName, String packageName) {
+ if (packageName != null && fullActivityName != null) {
+ if (packageName.length() > 0 && fullActivityName.startsWith(packageName)) {
+ String name = fullActivityName.substring(packageName.length());
+ if (name.length() > 0 && name.charAt(0) == '.') {
+ return name;
+ }
+ }
+ }
+
+ return fullActivityName;
+ }
}