diff options
15 files changed, 523 insertions, 457 deletions
diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java b/org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java index 9157ffaca..d73a8fe58 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ConnectionPlugin.java @@ -38,9 +38,9 @@ import org.slf4j.LoggerFactory; import org.tizen.common.connection.preference.TizenConnectionExplorerPreferencePage; import org.tizen.common.connection.preference.TizenLogPreferencePage; import org.tizen.common.util.OSChecker; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; import org.tizen.sdblib.SmartDevelopmentBridge; +import org.tizen.sdblib.service.FileEntry; /** * The activator class controls the plug-in life cycle diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerContentProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerContentProvider.java index a8570bfe4..d9e722a88 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerContentProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerContentProvider.java @@ -25,11 +25,11 @@ */ package org.tizen.common.connection.explorer; -import static org.tizen.sdblib.service.FileListingService.TYPE_DIRECTORY; -import static org.tizen.sdblib.service.FileListingService.TYPE_DIRECTORY_LINK; -import static org.tizen.sdblib.service.FileListingService.TYPE_LINK; -import static org.tizen.sdblib.service.FileListingService.TYPE_ROOT_DEVICE; -import static org.tizen.sdblib.service.FileListingService.TYPE_ROOT_EMULATOR; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; import java.util.Arrays; import java.util.Collections; @@ -38,9 +38,9 @@ import java.util.Set; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; import org.tizen.sdblib.SmartDevelopmentBridge; +import org.tizen.sdblib.service.FileEntry; public class ConnectionExplorerContentProvider implements ITreeContentProvider { diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerLabelProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerLabelProvider.java index 9a0c3c4a9..fc1c8d60c 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerLabelProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerLabelProvider.java @@ -25,15 +25,22 @@ */ package org.tizen.common.connection.explorer; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_FILE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; + import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; import org.tizen.common.connection.ConnectionPlugin; import org.tizen.common.util.SWTUtil; -import org.tizen.sdblib.service.FileListingService; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.service.FileEntry; +import org.tizen.sdblib.service.FileListingService; public class ConnectionExplorerLabelProvider implements ITableLabelProvider { @@ -74,17 +81,17 @@ public class ConnectionExplorerLabelProvider implements ITableLabelProvider FileEntry entry = (FileEntry) element; switch (entry.getType()) { - case FileListingService.TYPE_FILE: + case TYPE_FILE: return fileImage; - case FileListingService.TYPE_LINK: + case TYPE_LINK: return fileLinkImage; - case FileListingService.TYPE_DIRECTORY: + case TYPE_DIRECTORY: return folderImage; - case FileListingService.TYPE_DIRECTORY_LINK: + case TYPE_DIRECTORY_LINK: return folderLinkImage; - case FileListingService.TYPE_ROOT_EMULATOR: + case TYPE_ROOT_EMULATOR: return emulatorImage; - case FileListingService.TYPE_ROOT_DEVICE: + case TYPE_ROOT_DEVICE: return deviceImage; default: return otherImage; diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerPanel.java b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerPanel.java index cf6c4f50b..c31bdcdf8 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerPanel.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/explorer/ConnectionExplorerPanel.java @@ -95,7 +95,7 @@ import org.tizen.sdblib.IDevice; import org.tizen.sdblib.IDeviceChangeListener; import org.tizen.sdblib.SmartDevelopmentBridge; import org.tizen.sdblib.receiver.MultiLineReceiver; -import org.tizen.sdblib.service.FileListingService.FileEntry; +import org.tizen.sdblib.service.FileEntry; import org.tizen.sdblib.service.ISyncProgressMonitor; import org.tizen.sdblib.service.SyncService; import org.tizen.sdblib.service.SyncService.SyncResult; diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerInfoPropertyPages.java b/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerInfoPropertyPages.java index 313e57b42..5887b0d30 100644 --- a/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerInfoPropertyPages.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerInfoPropertyPages.java @@ -25,6 +25,10 @@ */ package org.tizen.common.connection.properties; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; + +import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -33,9 +37,8 @@ import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbenchPropertyPage; import org.eclipse.ui.dialogs.PropertyPage; - +import org.tizen.sdblib.service.FileEntry; import org.tizen.sdblib.service.FileListingService; -import org.tizen.sdblib.service.FileListingService.FileEntry; public class ConnectionExplorerInfoPropertyPages extends PropertyPage implements IWorkbenchPropertyPage { @@ -145,8 +148,8 @@ public class ConnectionExplorerInfoPropertyPages extends PropertyPage implements composite.setLayoutData(data); FileEntry f = (FileEntry) getElement().getAdapter(FileEntry.class); - if (f.getType() == FileListingService.TYPE_ROOT_DEVICE || - f.getType() == FileListingService.TYPE_ROOT_EMULATOR) { + if (f.getType() == TYPE_ROOT_DEVICE || + f.getType() == TYPE_ROOT_EMULATOR) { addRtSection(composite); } else { addFirstSection(composite); diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerPermissionPropertyPages.java b/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerPermissionPropertyPages.java index 9c7367c27..7cdec5e33 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerPermissionPropertyPages.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/properties/ConnectionExplorerPermissionPropertyPages.java @@ -25,6 +25,10 @@ */ package org.tizen.common.connection.properties; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; + +import org.eclipse.jface.preference.PreferencePage; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -36,9 +40,8 @@ import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.dialogs.PropertyPage; - +import org.tizen.sdblib.service.FileEntry; import org.tizen.sdblib.service.FileListingService; -import org.tizen.sdblib.service.FileListingService.FileEntry; public class ConnectionExplorerPermissionPropertyPages extends PropertyPage { @@ -99,8 +102,8 @@ public class ConnectionExplorerPermissionPropertyPages extends PropertyPage { composite.setLayoutData(data); FileEntry f = (FileEntry) getElement().getAdapter(FileEntry.class); - if (f.getType() == FileListingService.TYPE_ROOT_DEVICE || - f.getType() == FileListingService.TYPE_ROOT_EMULATOR) { + if (f.getType() == TYPE_ROOT_DEVICE || + f.getType() == TYPE_ROOT_EMULATOR) { return composite; } createTable(composite); diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryTransfer.java b/org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryTransfer.java index 9631169ea..1edf19e03 100644 --- a/org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryTransfer.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/sdblib/dnd/FileEntryTransfer.java @@ -32,9 +32,8 @@ import java.io.DataOutputStream; import java.io.IOException; import org.eclipse.swt.dnd.ByteArrayTransfer; - import org.tizen.common.util.log.Logger; -import org.tizen.sdblib.service.FileListingService.FileEntry; +import org.tizen.sdblib.service.FileEntry; public class FileEntryTransfer extends ByteArrayTransfer { diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java index b9800a2c1..8fa6227d0 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/ConnectionExplorer.java @@ -68,7 +68,7 @@ import org.tizen.common.util.log.Logger; import org.tizen.sdblib.IDevice; import org.tizen.sdblib.SmartDevelopmentBridge; import org.tizen.sdblib.receiver.MultiLineReceiver; -import org.tizen.sdblib.service.FileListingService.FileEntry; +import org.tizen.sdblib.service.FileEntry; public class ConnectionExplorer extends ViewPart implements IPartListener2 { diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java index 5f71ac5ef..717ec706b 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileContentProvider.java @@ -25,14 +25,19 @@ */ package org.tizen.common.connection.ui; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; + import java.util.ArrayList; import java.util.List; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; - +import org.tizen.sdblib.service.FileEntry; import org.tizen.sdblib.service.FileListingService; -import org.tizen.sdblib.service.FileListingService.FileEntry; public class TizenRemoteFileContentProvider implements ITreeContentProvider { @@ -120,23 +125,23 @@ public class TizenRemoteFileContentProvider implements ITreeContentProvider { public boolean hasChildren(Object arg0) { if (arg0 instanceof FileEntry) { FileEntry entry = (FileEntry) arg0; - if (entry.getType() == FileListingService.TYPE_DIRECTORY_LINK) + if (entry.getType() == TYPE_DIRECTORY_LINK) { return true; } - else if (entry.getType() == FileListingService.TYPE_LINK) + else if (entry.getType() == TYPE_LINK) { return true; } - else if (entry.getType() == FileListingService.TYPE_DIRECTORY) + else if (entry.getType() == TYPE_DIRECTORY) { return true; } - else if (entry.getType() == FileListingService.TYPE_ROOT_EMULATOR) + else if (entry.getType() == TYPE_ROOT_EMULATOR) { return true; } - else if (entry.getType() == FileListingService.TYPE_ROOT_DEVICE) + else if (entry.getType() == TYPE_ROOT_DEVICE) { return true; } diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileDialog.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileDialog.java index d8da8c9db..8caced3b9 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileDialog.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileDialog.java @@ -48,8 +48,8 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.swt.widgets.TreeItem; import org.tizen.common.connection.ConnectionPlugin; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.service.FileEntry; public class TizenRemoteFileDialog { public enum TizenRemoteFileDialogResult { diff --git a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java index f0b2e3d4e..da5add010 100755 --- a/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java +++ b/org.tizen.common.connection/src/org/tizen/common/connection/ui/TizenRemoteFileLabelProvider.java @@ -25,14 +25,20 @@ */ package org.tizen.common.connection.ui; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_FILE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; + import org.eclipse.jface.viewers.ILabelProviderListener; import org.eclipse.jface.viewers.ITableLabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; - -import org.tizen.sdblib.service.FileListingService; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.IDevice; +import org.tizen.sdblib.service.FileEntry; +import org.tizen.sdblib.service.FileListingService; public class TizenRemoteFileLabelProvider implements ITableLabelProvider { @@ -63,17 +69,17 @@ public class TizenRemoteFileLabelProvider implements ITableLabelProvider { if (element instanceof FileEntry) { FileEntry entry = (FileEntry) element; switch (entry.getType()) { - case FileListingService.TYPE_FILE: + case TYPE_FILE: return mFileImage; - case FileListingService.TYPE_LINK: + case TYPE_LINK: return mFileLinkImage; - case FileListingService.TYPE_DIRECTORY: + case TYPE_DIRECTORY: return mFolderImage; - case FileListingService.TYPE_DIRECTORY_LINK: + case TYPE_DIRECTORY_LINK: return mFolderLinkImage; - case FileListingService.TYPE_ROOT_EMULATOR: + case TYPE_ROOT_EMULATOR: return mEmulatorImage; - case FileListingService.TYPE_ROOT_DEVICE: + case TYPE_ROOT_DEVICE: return mDeviceImage; default: return mOtherImage; diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java new file mode 100644 index 000000000..a62c9fc68 --- /dev/null +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntry.java @@ -0,0 +1,351 @@ +package org.tizen.sdblib.service;
+
+import static org.tizen.sdblib.service.FileEntryConstants.FILE_SEPARATOR;
+import static org.tizen.sdblib.service.FileEntryConstants.PKG_PATTERN;
+import static org.tizen.sdblib.service.FileEntryConstants.REFRESH_TEST;
+import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY;
+import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK;
+import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE;
+import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Represents an entry in a directory. This can be a file or a directory.
+ */
+public class FileEntry
+{
+ private static final String FILE_ROOT = "/"; //$NON-NLS-1$
+
+ /** Pattern to escape filenames for shell command consumption. */
+ private final static Pattern sEscapePattern = Pattern.compile("([\\\\\"$])"); //$NON-NLS-1$
+
+ FileEntry parent;
+ String name;
+ String info;
+ String permissions;
+ String size;
+ String date;
+ String time;
+ String owner;
+ String group;
+ String linkPath;
+ FileListingService fileListingService;
+ int type;
+ boolean isAppPackage;
+
+ boolean isRoot;
+
+ /**
+ * Indicates whether the entry content has been fetched yet, or not.
+ */
+ long fetchTime = 0;
+
+ final ArrayList<FileEntry> mChildren = new ArrayList<FileEntry>();
+
+ /**
+ * Creates a new file entry.
+ *
+ * @param parent
+ * parent entry or null if entry is root
+ * @param name
+ * name of the entry.
+ * @param type
+ * entry type. Can be one of the following:
+ * {@link FileListingService#TYPE_FILE},
+ * {@link FileListingService#TYPE_DIRECTORY},
+ * {@link FileListingService#TYPE_OTHER}.
+ */
+ public FileEntry(FileEntry parent, String name, int type, boolean isRoot, FileListingService service)
+ {
+ this.parent = parent;
+ this.name = name;
+ this.type = type;
+ this.isRoot = isRoot;
+ this.fileListingService = service;
+ }
+
+ /**
+ * Returns the name of the entry
+ */
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Returns the size string of the entry, as returned by <code>ls</code>.
+ */
+ public String getSize()
+ {
+ return size;
+ }
+
+ /**
+ * Returns the size of the entry.
+ */
+ public int getSizeValue()
+ {
+ return Integer.parseInt(size);
+ }
+
+ /**
+ * Returns the date string of the entry, as returned by <code>ls</code>.
+ */
+ public String getDate()
+ {
+ return date;
+ }
+
+ /**
+ * Returns the time string of the entry, as returned by <code>ls</code>.
+ */
+ public String getTime()
+ {
+ return time;
+ }
+
+ /**
+ * Returns the permission string of the entry, as returned by
+ * <code>ls</code>.
+ */
+ public String getPermissions()
+ {
+ return permissions;
+ }
+
+ /**
+ * Returns the extra info for the entry.
+ * <p/>
+ * For a link, it will be a description of the link.
+ * <p/>
+ * For an application apk file it will be the application package as
+ * returned by the Package Manager.
+ */
+ public String getInfo()
+ {
+ return info;
+ }
+
+ public String getLinkFullPath()
+ {
+ return linkPath;
+ }
+
+ /**
+ * Return the full path of the entry.
+ *
+ * @return a path string using {@link FileListingService#FILE_SEPARATOR}
+ * as separator.
+ */
+ public String getFullPath()
+ {
+ if (isRoot)
+ {
+ return FILE_ROOT;
+ }
+ StringBuilder pathBuilder = new StringBuilder();
+ fillPathBuilder(pathBuilder, false);
+
+ return pathBuilder.toString();
+ }
+
+ /**
+ * Return the fully escaped path of the entry. This path is safe to use
+ * in a shell command line.
+ *
+ * @return a path string using {@link FileListingService#FILE_SEPARATOR}
+ * as separator
+ */
+ public String getFullEscapedPath()
+ {
+ StringBuilder pathBuilder = new StringBuilder();
+ fillPathBuilder(pathBuilder, true);
+
+ return pathBuilder.toString();
+ }
+
+ /**
+ * Returns the path as a list of segments.
+ */
+ public String[] getPathSegments()
+ {
+ ArrayList<String> list = new ArrayList<String>();
+ fillPathSegments(list);
+
+ return list.toArray(new String[list.size()]);
+ }
+
+ /**
+ * Returns true if the entry is a directory, false otherwise;
+ */
+ public int getType()
+ {
+ return type;
+ }
+
+ public FileListingService getFileListingService()
+ {
+ return fileListingService;
+ }
+
+ /**
+ * Returns if the entry is a folder or a link to a folder.
+ */
+ public boolean isDirectory()
+ {
+ return type == TYPE_DIRECTORY || type == TYPE_DIRECTORY_LINK
+ || type == TYPE_ROOT_DEVICE || type == TYPE_ROOT_EMULATOR ;
+ }
+
+ /**
+ * Returns the parent entry.
+ */
+ public FileEntry getParent()
+ {
+ return parent;
+ }
+
+ /**
+ * Returns the cached children of the entry. This returns the cache
+ * created from calling <code>FileListingService.getChildren()</code>.
+ */
+ public FileEntry[] getCachedChildren()
+ {
+ return mChildren.toArray(new FileEntry[mChildren.size()]);
+ }
+
+ /**
+ * Returns the child {@link FileEntry} matching the name. This uses the
+ * cached children list.
+ *
+ * @param name
+ * the name of the child to return.
+ * @return the FileEntry matching the name or null.
+ */
+ public FileEntry findChild(String name)
+ {
+ for (FileEntry entry : mChildren)
+ {
+ if (entry.name.equals(name))
+ {
+ return entry;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns whether the entry is the root.
+ */
+ public boolean isRoot()
+ {
+ return isRoot;
+ }
+
+ void addChild(FileEntry child)
+ {
+ mChildren.add(child);
+ }
+
+ void setChildren(ArrayList<FileEntry> newChildren)
+ {
+ mChildren.clear();
+ mChildren.addAll(newChildren);
+ }
+
+ boolean needFetch()
+ {
+ if (fetchTime == 0)
+ {
+ return true;
+ }
+ long current = System.currentTimeMillis();
+ if (current - fetchTime > REFRESH_TEST)
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns if the entry is a valid application package.
+ */
+ public boolean isApplicationPackage()
+ {
+ return isAppPackage;
+ }
+
+ /**
+ * Returns if the file name is an application package name.
+ */
+ public boolean isAppFileName()
+ {
+ Matcher m = PKG_PATTERN.matcher(name);
+ return m.matches();
+ }
+
+ /**
+ * Recursively fills the pathBuilder with the full path
+ *
+ * @param pathBuilder
+ * a StringBuilder used to create the path.
+ * @param escapePath
+ * Whether the path need to be escaped for consumption by a
+ * shell command line.
+ */
+ protected void fillPathBuilder(StringBuilder pathBuilder, boolean escapePath)
+ {
+ if (isRoot)
+ {
+ return;
+ }
+
+ if (parent != null)
+ {
+ parent.fillPathBuilder(pathBuilder, escapePath);
+ }
+ pathBuilder.append(FILE_SEPARATOR);
+ pathBuilder.append(escapePath ? escape(name) : name);
+ }
+
+ /**
+ * Recursively fills the segment list with the full path.
+ *
+ * @param list
+ * The list of segments to fill.
+ */
+ protected void fillPathSegments(ArrayList<String> list)
+ {
+ if (isRoot)
+ {
+ return;
+ }
+
+ if (parent != null)
+ {
+ parent.fillPathSegments(list);
+ }
+
+ list.add(name);
+ }
+
+ /**
+ * Returns an escaped version of the entry name.
+ *
+ * @param entryName
+ */
+ private String escape(String entryName)
+ {
+ return sEscapePattern.matcher(entryName).replaceAll("\\\\$1"); //$NON-NLS-1$
+ }
+
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryConstants.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryConstants.java new file mode 100644 index 000000000..8afdfeca8 --- /dev/null +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileEntryConstants.java @@ -0,0 +1,64 @@ +package org.tizen.sdblib.service;
+
+import java.util.regex.Pattern;
+
+public class FileEntryConstants
+{
+ /** Pattern to find filenames that match "*.tpk" */
+ public final static Pattern PKG_PATTERN = Pattern.compile(".*\\.apk", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$
+
+ public final static String PM_FULL_LISTING = "pm list packages -f"; //$NON-NLS-1$
+
+ /**
+ * Pattern to parse the output of the 'pm -lf' command.<br>
+ * The output format looks like:<br>
+ * /data/app/myapp.apk=com.mypackage.myapp
+ */
+ public final static Pattern sPmPattern = Pattern.compile("^package:(.+?)=(.+)$"); //$NON-NLS-1$
+
+ /** Top level data folder. */
+ public final static String DIRECTORY_DATA = "data"; //$NON-NLS-1$
+ /** Top level sdcard folder. */
+ public final static String DIRECTORY_SDCARD = "sdcard"; //$NON-NLS-1$
+ /** Top level mount folder. */
+ public final static String DIRECTORY_MNT = "mnt"; //$NON-NLS-1$
+ /** Top level system folder. */
+ public final static String DIRECTORY_SYSTEM = "system"; //$NON-NLS-1$
+ /** Top level temp folder. */
+ public final static String DIRECTORY_TEMP = "tmp"; //$NON-NLS-1$
+ /** Application folder. */
+ public final static String DIRECTORY_APP = "app"; //$NON-NLS-1$
+
+ public static final long REFRESH_RATE = 5000L;
+ /**
+ * Refresh test has to be slightly lower for precision issue.
+ */
+ static final long REFRESH_TEST = (long) (REFRESH_RATE * .8);
+
+ /** Entry type: File */
+ public static final int TYPE_FILE = 0;
+ /** Entry type: Directory */
+ public static final int TYPE_DIRECTORY = 1;
+ /** Entry type: Directory Link */
+ public static final int TYPE_DIRECTORY_LINK = 2;
+ /** Entry type: Block */
+ public static final int TYPE_BLOCK = 3;
+ /** Entry type: Character */
+ public static final int TYPE_CHARACTER = 4;
+ /** Entry type: Link */
+ public static final int TYPE_LINK = 5;
+ /** Entry type: Socket */
+ public static final int TYPE_SOCKET = 6;
+ /** Entry type: FIFO */
+ public static final int TYPE_FIFO = 7;
+ /** Entry type: Other */
+ public static final int TYPE_OTHER = 8;
+ /** Entry type: root */
+ public static final int TYPE_ROOT_EMULATOR = 9;
+ public static final int TYPE_ROOT_DEVICE = 10;
+
+ /** Device side file separator. */
+ public static final String FILE_SEPARATOR = "/"; //$NON-NLS-1$
+
+
+}
diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileListingService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileListingService.java index c2257fa46..fa1047ebf 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileListingService.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/FileListingService.java @@ -25,6 +25,21 @@ */ package org.tizen.sdblib.service; +import static org.tizen.sdblib.service.FileEntryConstants.FILE_SEPARATOR; +import static org.tizen.sdblib.service.FileEntryConstants.PM_FULL_LISTING; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_BLOCK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_CHARACTER; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_FIFO; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_FILE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_OTHER; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_SOCKET; +import static org.tizen.sdblib.service.FileEntryConstants.sPmPattern; + import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -49,64 +64,6 @@ public class FileListingService { - /** Pattern to find filenames that match "*.tpk" */ - private final static Pattern PKG_PATTERN = Pattern.compile(".*\\.apk", Pattern.CASE_INSENSITIVE); //$NON-NLS-1$ - - private final static String PM_FULL_LISTING = "pm list packages -f"; //$NON-NLS-1$ - - /** - * Pattern to parse the output of the 'pm -lf' command.<br> - * The output format looks like:<br> - * /data/app/myapp.apk=com.mypackage.myapp - */ - private final static Pattern sPmPattern = Pattern.compile("^package:(.+?)=(.+)$"); //$NON-NLS-1$ - - /** Top level data folder. */ - public final static String DIRECTORY_DATA = "data"; //$NON-NLS-1$ - /** Top level sdcard folder. */ - public final static String DIRECTORY_SDCARD = "sdcard"; //$NON-NLS-1$ - /** Top level mount folder. */ - public final static String DIRECTORY_MNT = "mnt"; //$NON-NLS-1$ - /** Top level system folder. */ - public final static String DIRECTORY_SYSTEM = "system"; //$NON-NLS-1$ - /** Top level temp folder. */ - public final static String DIRECTORY_TEMP = "tmp"; //$NON-NLS-1$ - /** Application folder. */ - public final static String DIRECTORY_APP = "app"; //$NON-NLS-1$ - - public static final long REFRESH_RATE = 5000L; - /** - * Refresh test has to be slightly lower for precision issue. - */ - static final long REFRESH_TEST = (long) (REFRESH_RATE * .8); - - /** Entry type: File */ - public static final int TYPE_FILE = 0; - /** Entry type: Directory */ - public static final int TYPE_DIRECTORY = 1; - /** Entry type: Directory Link */ - public static final int TYPE_DIRECTORY_LINK = 2; - /** Entry type: Block */ - public static final int TYPE_BLOCK = 3; - /** Entry type: Character */ - public static final int TYPE_CHARACTER = 4; - /** Entry type: Link */ - public static final int TYPE_LINK = 5; - /** Entry type: Socket */ - public static final int TYPE_SOCKET = 6; - /** Entry type: FIFO */ - public static final int TYPE_FIFO = 7; - /** Entry type: Other */ - public static final int TYPE_OTHER = 8; - /** Entry type: root */ - public static final int TYPE_ROOT_EMULATOR = 9; - public static final int TYPE_ROOT_DEVICE = 10; - - /** Device side file separator. */ - public static final String FILE_SEPARATOR = "/"; //$NON-NLS-1$ - - private static final String FILE_ROOT = "/"; //$NON-NLS-1$ - /** * Regexp pattern to parse the result from ls. Do not think the same format * between Emulator and Device such as "ls -l --time-style=long-iso" @@ -136,357 +93,23 @@ FileListingService private final ArrayList<Thread> mThreadList = new ArrayList<Thread>(); /** - * Represents an entry in a directory. This can be a file or a directory. + * Comparator object for FileEntry */ - public final static class FileEntry + private static Comparator<FileEntry> sEntryComparator = new Comparator<FileEntry>() { - /** Pattern to escape filenames for shell command consumption. */ - private final static Pattern sEscapePattern = Pattern.compile("([\\\\\"$])"); //$NON-NLS-1$ - - /** - * Comparator object for FileEntry - */ - private static Comparator<FileEntry> sEntryComparator = new Comparator<FileEntry>() - { - @Override - public int compare(FileEntry o1, FileEntry o2) - { - if (o1 instanceof FileEntry && o2 instanceof FileEntry) - { - FileEntry fe1 = (FileEntry) o1; - FileEntry fe2 = (FileEntry) o2; - return fe1.name.compareTo(fe2.name); - } - return 0; - } - }; - - FileEntry parent; - String name; - String info; - String permissions; - String size; - String date; - String time; - String owner; - String group; - String linkPath; - FileListingService fileListingService; - int type; - boolean isAppPackage; - - boolean isRoot; - - /** - * Indicates whether the entry content has been fetched yet, or not. - */ - long fetchTime = 0; - - final ArrayList<FileEntry> mChildren = new ArrayList<FileEntry>(); - - /** - * Creates a new file entry. - * - * @param parent - * parent entry or null if entry is root - * @param name - * name of the entry. - * @param type - * entry type. Can be one of the following: - * {@link FileListingService#TYPE_FILE}, - * {@link FileListingService#TYPE_DIRECTORY}, - * {@link FileListingService#TYPE_OTHER}. - */ - public FileEntry(FileEntry parent, String name, int type, boolean isRoot, FileListingService service) - { - this.parent = parent; - this.name = name; - this.type = type; - this.isRoot = isRoot; - this.fileListingService = service; - } - - /** - * Returns the name of the entry - */ - public String getName() - { - return name; - } - - public void setName(String name) - { - this.name = name; - } - - /** - * Returns the size string of the entry, as returned by <code>ls</code>. - */ - public String getSize() - { - return size; - } - - /** - * Returns the size of the entry. - */ - public int getSizeValue() - { - return Integer.parseInt(size); - } - - /** - * Returns the date string of the entry, as returned by <code>ls</code>. - */ - public String getDate() - { - return date; - } - - /** - * Returns the time string of the entry, as returned by <code>ls</code>. - */ - public String getTime() - { - return time; - } - - /** - * Returns the permission string of the entry, as returned by - * <code>ls</code>. - */ - public String getPermissions() - { - return permissions; - } - - /** - * Returns the extra info for the entry. - * <p/> - * For a link, it will be a description of the link. - * <p/> - * For an application apk file it will be the application package as - * returned by the Package Manager. - */ - public String getInfo() - { - return info; - } - - public String getLinkFullPath() - { - return linkPath; - } - - /** - * Return the full path of the entry. - * - * @return a path string using {@link FileListingService#FILE_SEPARATOR} - * as separator. - */ - public String getFullPath() - { - if (isRoot) - { - return FILE_ROOT; - } - StringBuilder pathBuilder = new StringBuilder(); - fillPathBuilder(pathBuilder, false); - - return pathBuilder.toString(); - } - - /** - * Return the fully escaped path of the entry. This path is safe to use - * in a shell command line. - * - * @return a path string using {@link FileListingService#FILE_SEPARATOR} - * as separator - */ - public String getFullEscapedPath() - { - StringBuilder pathBuilder = new StringBuilder(); - fillPathBuilder(pathBuilder, true); - - return pathBuilder.toString(); - } - - /** - * Returns the path as a list of segments. - */ - public String[] getPathSegments() - { - ArrayList<String> list = new ArrayList<String>(); - fillPathSegments(list); - - return list.toArray(new String[list.size()]); - } - - /** - * Returns true if the entry is a directory, false otherwise; - */ - public int getType() - { - return type; - } - - public FileListingService getFileListingService() - { - return fileListingService; - } - - /** - * Returns if the entry is a folder or a link to a folder. - */ - public boolean isDirectory() - { - return type == TYPE_DIRECTORY || type == TYPE_DIRECTORY_LINK - || type == TYPE_ROOT_DEVICE || type == TYPE_ROOT_EMULATOR ; - } - - /** - * Returns the parent entry. - */ - public FileEntry getParent() - { - return parent; - } - - /** - * Returns the cached children of the entry. This returns the cache - * created from calling <code>FileListingService.getChildren()</code>. - */ - public FileEntry[] getCachedChildren() - { - return mChildren.toArray(new FileEntry[mChildren.size()]); - } - - /** - * Returns the child {@link FileEntry} matching the name. This uses the - * cached children list. - * - * @param name - * the name of the child to return. - * @return the FileEntry matching the name or null. - */ - public FileEntry findChild(String name) - { - for (FileEntry entry : mChildren) - { - if (entry.name.equals(name)) - { - return entry; - } - } - return null; - } - - /** - * Returns whether the entry is the root. - */ - public boolean isRoot() - { - return isRoot; - } - - void addChild(FileEntry child) - { - mChildren.add(child); - } - - void setChildren(ArrayList<FileEntry> newChildren) - { - mChildren.clear(); - mChildren.addAll(newChildren); - } - - boolean needFetch() - { - if (fetchTime == 0) - { - return true; - } - long current = System.currentTimeMillis(); - if (current - fetchTime > REFRESH_TEST) - { - return true; - } - - return false; - } - - /** - * Returns if the entry is a valid application package. - */ - public boolean isApplicationPackage() - { - return isAppPackage; - } - - /** - * Returns if the file name is an application package name. - */ - public boolean isAppFileName() - { - Matcher m = PKG_PATTERN.matcher(name); - return m.matches(); - } - - /** - * Recursively fills the pathBuilder with the full path - * - * @param pathBuilder - * a StringBuilder used to create the path. - * @param escapePath - * Whether the path need to be escaped for consumption by a - * shell command line. - */ - protected void fillPathBuilder(StringBuilder pathBuilder, boolean escapePath) - { - if (isRoot) - { - return; - } - - if (parent != null) - { - parent.fillPathBuilder(pathBuilder, escapePath); - } - pathBuilder.append(FILE_SEPARATOR); - pathBuilder.append(escapePath ? escape(name) : name); - } - - /** - * Recursively fills the segment list with the full path. - * - * @param list - * The list of segments to fill. - */ - protected void fillPathSegments(ArrayList<String> list) + @Override + public int compare(FileEntry o1, FileEntry o2) { - if (isRoot) - { - return; - } - - if (parent != null) + if (o1 instanceof FileEntry && o2 instanceof FileEntry) { - parent.fillPathSegments(list); + FileEntry fe1 = (FileEntry) o1; + FileEntry fe2 = (FileEntry) o2; + return fe1.name.compareTo(fe2.name); } - - list.add(name); + return 0; } + }; - /** - * Returns an escaped version of the entry name. - * - * @param entryName - */ - private String escape(String entryName) - { - return sEscapePattern.matcher(entryName).replaceAll("\\\\$1"); //$NON-NLS-1$ - } - } private class LsReceiver extends MultiLineReceiver { @@ -781,9 +404,9 @@ FileListingService { if (mRoot == null) { - int deviceType = FileListingService.TYPE_ROOT_DEVICE; + int deviceType = TYPE_ROOT_DEVICE; if (mDevice.isEmulator()) - deviceType = FileListingService.TYPE_ROOT_EMULATOR; + deviceType = TYPE_ROOT_EMULATOR; mRoot = new FileEntry(null, mDevice.getDeviceName(), deviceType, true, this); } @@ -972,7 +595,7 @@ FileListingService // create the command String lsCommand = null; String teeCommand = ""; - if (entry.getType() == FileListingService.TYPE_LINK || entry.getType() == FileListingService.TYPE_DIRECTORY_LINK) + if (entry.getType() == TYPE_LINK || entry.getType() == TYPE_DIRECTORY_LINK) { if (entry.getLinkFullPath().charAt(0) == '/') lsCommand = "ls -l " + getStringWithDoubleQuote(entry.getLinkFullPath()); //$NON-NLS-1$ @@ -1013,7 +636,7 @@ FileListingService entry.fetchTime = System.currentTimeMillis(); // sort the children and set them as the new children - Collections.sort(entryList, FileEntry.sEntryComparator); + Collections.sort(entryList, sEntryComparator); entry.setChildren(entryList); } diff --git a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java index d9fc839b9..91334fa21 100644 --- a/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java +++ b/org.tizen.common.sdblib/src/org/tizen/sdblib/service/SyncService.java @@ -16,6 +16,12 @@ package org.tizen.sdblib.service; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_DIRECTORY_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_FILE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_LINK; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_DEVICE; +import static org.tizen.sdblib.service.FileEntryConstants.TYPE_ROOT_EMULATOR; import static org.tizen.sdblib.util.ObjectUtil.nvl; import java.io.Closeable; @@ -34,7 +40,6 @@ import org.tizen.sdblib.SdbResponse; import org.tizen.sdblib.SmartDevelopmentBridge; import org.tizen.sdblib.exception.SdbCommandRejectedException; import org.tizen.sdblib.exception.TimeoutException; -import org.tizen.sdblib.service.FileListingService.FileEntry; import org.tizen.sdblib.util.ArrayHelper; import org.tizen.sdblib.util.Log; import org.tizen.sdblib.util.Preferences; @@ -610,12 +615,12 @@ public final class SyncService implements Closeable { int count = 0; for (FileEntry e : entries) { int type = e.getType(); - if (type == FileListingService.TYPE_DIRECTORY || type == FileListingService.TYPE_ROOT_DEVICE - || type == FileListingService.TYPE_ROOT_EMULATOR) { + if (type == TYPE_DIRECTORY || type == TYPE_ROOT_DEVICE + || type == TYPE_ROOT_EMULATOR) { // get the children FileEntry[] children = fls.getChildren(e, false, null); count += getTotalRemoteFileSize(children, fls) + 1; - } else if (type == FileListingService.TYPE_FILE) { + } else if (type == TYPE_FILE) { count += e.getSizeValue(); } } @@ -639,12 +644,12 @@ public final class SyncService implements Closeable { throw new InterruptedException("The long running operation was cancelled"); } int type = e.getType(); - if (type == FileListingService.TYPE_DIRECTORY || type == FileListingService.TYPE_ROOT_DEVICE - || type == FileListingService.TYPE_ROOT_EMULATOR | type == FileListingService.TYPE_LINK | type == FileListingService.TYPE_DIRECTORY_LINK) { + if (type == TYPE_DIRECTORY || type == TYPE_ROOT_DEVICE + || type == TYPE_ROOT_EMULATOR | type == TYPE_LINK | type == TYPE_DIRECTORY_LINK) { // get the children FileEntry[] children = fls.getChildren(e, false, null); count += getTotalRemoteFileSizeLong(children, fls, monitor) + 1; - } else if (type == FileListingService.TYPE_FILE) { + } else if (type == TYPE_FILE) { count += e.getSizeValue(); } } |