aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--anttasks/src/com/android/ant/SetupTask.java4
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java32
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFileWrapper.java9
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFolderWrapper.java24
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java5
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java107
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java99
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java7
-rw-r--r--sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java5
9 files changed, 218 insertions, 74 deletions
diff --git a/anttasks/src/com/android/ant/SetupTask.java b/anttasks/src/com/android/ant/SetupTask.java
index f25d09f..ed93c7e 100644
--- a/anttasks/src/com/android/ant/SetupTask.java
+++ b/anttasks/src/com/android/ant/SetupTask.java
@@ -419,9 +419,9 @@ public final class SetupTask extends ImportTask {
}
// get the package from the manifest.
- File manifest = new File(rootPath, SdkConstants.FN_ANDROID_MANIFEST_XML);
+ FileWrapper manifest = new FileWrapper(rootPath, SdkConstants.FN_ANDROID_MANIFEST_XML);
try {
- String value = AndroidManifest.getPackage(new FileWrapper(manifest));
+ String value = AndroidManifest.getPackage(manifest);
if (value != null) { // aapt will complain if it's missing.
sb.append(';');
sb.append(value);
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java
index 6da34f4..66e055b 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/ResourceManager.java
@@ -28,10 +28,10 @@ import com.android.ide.eclipse.adt.internal.resources.manager.files.IFileWrapper
import com.android.ide.eclipse.adt.internal.resources.manager.files.IFolderWrapper;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
-import com.android.sdklib.internal.io.FileWrapper;
import com.android.sdklib.internal.io.FolderWrapper;
import com.android.sdklib.internal.io.IAbstractFile;
import com.android.sdklib.internal.io.IAbstractFolder;
+import com.android.sdklib.internal.io.IAbstractResource;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -388,8 +388,8 @@ public final class ResourceManager {
public ProjectResources loadFrameworkResources(IAndroidTarget androidTarget) {
String osResourcesPath = androidTarget.getPath(IAndroidTarget.RESOURCES);
- File frameworkRes = new File(osResourcesPath);
- if (frameworkRes.isDirectory()) {
+ FolderWrapper frameworkRes = new FolderWrapper(osResourcesPath);
+ if (frameworkRes.exists()) {
ProjectResources resources = new ProjectResources(true /* isFrameworkRepository */);
try {
@@ -421,28 +421,28 @@ public final class ResourceManager {
*
* @param resources The {@link ProjectResources} files to load. It is expected that the
* framework flag has been properly setup. This is filled up with the content of the folder.
- * @param folder The folder to read the resources from. This is the top level resource folder
- * (res/)
+ * @param rootFolder The folder to read the resources from. This is the top level
+ * resource folder (res/)
* @throws IOException
*/
- public void loadResources(ProjectResources resources, File folder) throws IOException {
- File[] files = folder.listFiles();
- for (File file : files) {
- if (file.isDirectory()) {
- ResourceFolder resFolder = processFolder(new FolderWrapper(file),
- resources);
+ public void loadResources(ProjectResources resources, IAbstractFolder rootFolder)
+ throws IOException {
+ IAbstractResource[] files = rootFolder.listMembers();
+ for (IAbstractResource file : files) {
+ if (file instanceof IAbstractFolder) {
+ IAbstractFolder folder = (IAbstractFolder) file;
+ ResourceFolder resFolder = processFolder(folder, resources);
if (resFolder != null) {
// now we process the content of the folder
- File[] children = file.listFiles();
+ IAbstractResource[] children = folder.listMembers();
- for (File childRes : children) {
- if (childRes.isFile()) {
- processFile(new FileWrapper(childRes), resFolder);
+ for (IAbstractResource childRes : children) {
+ if (childRes instanceof IAbstractFile) {
+ processFile((IAbstractFile) childRes, resFolder);
}
}
}
-
}
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFileWrapper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFileWrapper.java
index b8db6b0..81f1500 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFileWrapper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFileWrapper.java
@@ -20,6 +20,7 @@ import com.android.sdklib.internal.io.IAbstractFile;
import com.android.sdklib.internal.io.StreamException;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import java.io.InputStream;
@@ -43,6 +44,14 @@ public class IFileWrapper implements IAbstractFile {
}
}
+ public void setContents(InputStream source) throws StreamException {
+ try {
+ mFile.setContents(source, IResource.FORCE, null);
+ } catch (CoreException e) {
+ throw new StreamException(e);
+ }
+ }
+
public String getOsLocation() {
return mFile.getLocation().toOSString();
}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFolderWrapper.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFolderWrapper.java
index 23dab60..b910b83 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFolderWrapper.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/resources/manager/files/IFolderWrapper.java
@@ -18,6 +18,7 @@ package com.android.ide.eclipse.adt.internal.resources.manager.files;
import com.android.sdklib.internal.io.IAbstractFile;
import com.android.sdklib.internal.io.IAbstractFolder;
+import com.android.sdklib.internal.io.IAbstractResource;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
@@ -52,6 +53,29 @@ public class IFolderWrapper implements IAbstractFolder {
return mContainer.exists();
}
+ public IAbstractResource[] listMembers() {
+ try {
+ IResource[] members = mContainer.members();
+ final int count = members.length;
+ IAbstractResource[] afiles = new IAbstractResource[count];
+
+ for (int i = 0 ; i < count ; i++) {
+ IResource f = members[i];
+ if (f instanceof IFile) {
+ afiles[i] = new IFileWrapper((IFile) f);
+ } else {
+ afiles[i] = new IFolderWrapper((IContainer) f);
+ }
+ }
+
+ return afiles;
+ } catch (CoreException e) {
+ // return empty array below
+ }
+
+ return new IAbstractResource[0];
+ }
+
public boolean hasFile(String name) {
try {
IResource[] files = mContainer.members();
diff --git a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
index 1bbce87..a3afb6d 100644
--- a/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
+++ b/eclipse/plugins/com.android.ide.eclipse.tests/src/com/android/ide/eclipse/tests/functests/layoutRendering/ApiDemosRenderingTest.java
@@ -46,6 +46,7 @@ import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.IXmlPullParser;
import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
+import com.android.sdklib.internal.io.FolderWrapper;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParser;
@@ -151,8 +152,8 @@ public class ApiDemosRenderingTest extends SdkTestCase {
fail("Fail to load the bridge");
}
- File resFolder = new File(sampleProject, SdkConstants.FD_RES);
- if (resFolder.isDirectory() == false) {
+ FolderWrapper resFolder = new FolderWrapper(sampleProject, SdkConstants.FD_RES);
+ if (resFolder.exists() == false) {
fail("Sample project has no res folder!");
}
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
index b8af4be..0fe8902 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FileWrapper.java
@@ -20,59 +20,108 @@ package com.android.sdklib.internal.io;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
/**
- * An implementation of {@link IAbstractFile} on top of a {@link File} object.
- *
+ * An implementation of {@link IAbstractFile} extending {@link File}.
*/
-public class FileWrapper implements IAbstractFile {
+public class FileWrapper extends File implements IAbstractFile {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new File instance from a parent abstract pathname and a child pathname string.
+ * @param parent the parent pathname
+ * @param child the child name
+ *
+ * @see File#File(File, String)
+ */
+ public FileWrapper(File parent, String child) {
+ super(parent, child);
+ }
- private final File mFile;
+ /**
+ * Creates a new File instance by converting the given pathname string into an abstract
+ * pathname.
+ * @param pathname the pathname
+ *
+ * @see File#File(String)
+ */
+ public FileWrapper(String pathname) {
+ super(pathname);
+ }
+
+ /**
+ * Creates a new File instance from a parent abstract pathname and a child pathname string.
+ * @param parent the parent pathname
+ * @param child the child name
+ *
+ * @see File#File(String, String)
+ */
+ public FileWrapper(String parent, String child) {
+ super(parent, child);
+ }
+
+ /**
+ * Creates a new File instance by converting the given <code>file:</code> URI into an
+ * abstract pathname.
+ * @param uri An absolute, hierarchical URI with a scheme equal to "file", a non-empty path
+ * component, and undefined authority, query, and fragment components
+ *
+ * @see File#File(URI)
+ */
+ public FileWrapper(URI uri) {
+ super(uri);
+ }
/**
- * Constructs a {@link FileWrapper} object. The underlying {@link File} object needs not
- * exist or be a valid file.
+ * Creates a new File instance matching a give {@link File} object.
+ * @param file the file to match
*/
public FileWrapper(File file) {
- mFile = file;
+ super(file.getAbsolutePath());
}
public InputStream getContents() throws StreamException {
try {
- return new FileInputStream(mFile);
+ return new FileInputStream(this);
} 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();
- }
+ public void setContents(InputStream source) throws StreamException {
+ FileOutputStream fos = null;
+ try {
+ fos = new FileOutputStream(this);
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof FileWrapper) {
- return mFile.equals(((FileWrapper)obj).mFile);
+ byte[] buffer = new byte[1024];
+ int count = 0;
+ while ((count = source.read(buffer)) != -1) {
+ fos.write(buffer, 0, count);
+ }
+ } catch (IOException e) {
+ throw new StreamException(e);
+ } finally {
+ if (fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ throw new StreamException(e);
+ }
+ }
}
+ }
- if (obj instanceof File) {
- return mFile.equals(obj);
- }
- return super.equals(obj);
+ public String getOsLocation() {
+ return getAbsolutePath();
}
@Override
- public int hashCode() {
- return mFile.hashCode();
+ public boolean exists() {
+ return isFile();
}
}
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
index a9269ad..1496216 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/FolderWrapper.java
@@ -18,53 +18,102 @@ package com.android.sdklib.internal.io;
import java.io.File;
+import java.io.FilenameFilter;
+import java.net.URI;
/**
- * An implementation of {@link IAbstractFolder} on top of a {@link File} object.
+ * An implementation of {@link IAbstractFolder} extending {@link File}.
*/
-public class FolderWrapper implements IAbstractFolder {
+public class FolderWrapper extends File implements IAbstractFolder {
- private final File mFolder;
+ private static final long serialVersionUID = 1L;
/**
- * Constructs a {@link FileWrapper} object. The underlying {@link File} object needs not exists
- * or be a valid directory.
+ * Creates a new File instance from a parent abstract pathname and a child pathname string.
+ * @param parent the parent pathname
+ * @param child the child name
+ *
+ * @see File#File(File, String)
*/
- public FolderWrapper(File folder) {
- mFolder = folder;
+ public FolderWrapper(File parent, String child) {
+ super(parent, child);
}
- public boolean hasFile(String name) {
- return false;
+ /**
+ * Creates a new File instance by converting the given pathname string into an abstract
+ * pathname.
+ * @param pathname the pathname
+ *
+ * @see File#File(String)
+ */
+ public FolderWrapper(String pathname) {
+ super(pathname);
}
- public IAbstractFile getFile(String name) {
- return new FileWrapper(new File(mFolder, name));
+ /**
+ * Creates a new File instance from a parent abstract pathname and a child pathname string.
+ * @param parent the parent pathname
+ * @param child the child name
+ *
+ * @see File#File(String, String)
+ */
+ public FolderWrapper(String parent, String child) {
+ super(parent, child);
}
- public String getName() {
- return mFolder.getName();
+ /**
+ * Creates a new File instance by converting the given <code>file:</code> URI into an
+ * abstract pathname.
+ * @param uri An absolute, hierarchical URI with a scheme equal to "file", a non-empty path
+ * component, and undefined authority, query, and fragment components
+ *
+ * @see File#File(URI)
+ */
+ public FolderWrapper(URI uri) {
+ super(uri);
}
- public boolean exists() {
- return mFolder.isDirectory();
+ /**
+ * Creates a new File instance matching a give {@link File} object.
+ * @param file the file to match
+ */
+ public FolderWrapper(File file) {
+ super(file.getAbsolutePath());
}
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof FolderWrapper) {
- return mFolder.equals(((FolderWrapper)obj).mFolder);
- }
+ public IAbstractResource[] listMembers() {
+ File[] files = listFiles();
+ final int count = files.length;
+ IAbstractResource[] afiles = new IAbstractResource[count];
- if (obj instanceof File) {
- return mFolder.equals(obj);
+ for (int i = 0 ; i < count ; i++) {
+ File f = files[i];
+ if (f.isFile()) {
+ afiles[i] = new FileWrapper(f);
+ } else {
+ afiles[i] = new FolderWrapper(f);
+ }
}
- return super.equals(obj);
+ return afiles;
+ }
+
+ public boolean hasFile(final String name) {
+ String[] match = list(new FilenameFilter() {
+ public boolean accept(File dir, String filename) {
+ return name.equals(filename);
+ }
+ });
+
+ return match.length > 0;
+ }
+
+ public IAbstractFile getFile(String name) {
+ return new FileWrapper(this, name);
}
@Override
- public int hashCode() {
- return mFolder.hashCode();
+ public boolean exists() {
+ return isDirectory();
}
}
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
index f96ede6..3c9ffd3 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFile.java
@@ -30,6 +30,13 @@ public interface IAbstractFile extends IAbstractResource {
InputStream getContents() throws StreamException;
/**
+ * Sets the content of the file.
+ * @param source the content
+ * @throws StreamException
+ */
+ void setContents(InputStream source) 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
index 22f654b..7751767 100644
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/io/IAbstractFolder.java
@@ -35,4 +35,9 @@ public interface IAbstractFolder extends IAbstractResource {
* @param name the name of the file.
*/
IAbstractFile getFile(String name);
+
+ /**
+ * returns a list of existing members in this folder.
+ */
+ IAbstractResource[] listMembers();
}