aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs
diff options
context:
space:
mode:
authorRaphael <raphael@google.com>2012-02-06 13:25:16 -0800
committerRaphael <raphael@google.com>2012-02-06 15:27:11 -0800
commit72b588de47324540a1989fcc7d1b820b56045371 (patch)
tree8531b69047f4979692a2da89dbb7daa1c3794228 /sdkmanager/libs
parent3c16d164a654ac15466c7476388f6b5fa2519798 (diff)
downloadsdk-72b588de47324540a1989fcc7d1b820b56045371.zip
sdk-72b588de47324540a1989fcc7d1b820b56045371.tar.gz
sdk-72b588de47324540a1989fcc7d1b820b56045371.tar.bz2
SDK Manager: extract source packages as r-o.
Extract Java sources from source packages as read-only. When such sources are added to the target build path in Eclipse it prevents users from modifying them by mistake. Change-Id: I271d1d55e35ba275494b9d5d899817a7d0ad0361
Diffstat (limited to 'sdkmanager/libs')
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java30
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java43
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SourcePackage.java21
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java8
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/io/IFileOp.java7
-rwxr-xr-xsdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/ArchiveInstallerTest.java4
-rwxr-xr-xsdkmanager/libs/sdklib/tests/src/com/android/sdklib/io/MockFileOp.java8
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java28
8 files changed, 117 insertions, 32 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
index 934044f..9046e63 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ArchiveInstaller.java
@@ -535,7 +535,10 @@ public class ArchiveInstaller {
return false;
}
- if (!unzipFolder(archiveFile, newArchive.getSize(), destFolder, pkgName, monitor)) {
+ if (!unzipFolder(archiveInfo,
+ archiveFile,
+ destFolder,
+ monitor)) {
return false;
}
@@ -633,21 +636,21 @@ public class ArchiveInstaller {
*/
@SuppressWarnings("unchecked")
@VisibleForTesting(visibility=Visibility.PRIVATE)
- protected boolean unzipFolder(File archiveFile,
- long compressedSize,
+ protected boolean unzipFolder(
+ ArchiveReplacement archiveInfo,
+ File archiveFile,
File unzipDestFolder,
- String pkgName,
ITaskMonitor monitor) {
+ Archive newArchive = archiveInfo.getNewArchive();
+ Package pkg = newArchive.getParentPackage();
+ String pkgName = pkg.getShortDescription();
+ long compressedSize = newArchive.getSize();
+
ZipFile zipFile = null;
try {
zipFile = new ZipFile(archiveFile);
- // figure if we'll need to set the unix permissions
- boolean usingUnixPerm =
- SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_DARWIN ||
- SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_LINUX;
-
// To advance the percent and the progress bar, we don't know the number of
// items left to unzip. However we know the size of the archive and the size of
// each uncompressed item. The zip file format overhead is negligible so that's
@@ -730,14 +733,7 @@ public class ArchiveInstaller {
}
}
- // if needed set the permissions.
- if (usingUnixPerm && mFileOp.isFile(destFile)) {
- // get the mode and test if it contains the executable bit
- int mode = entry.getUnixMode();
- if ((mode & 0111) != 0) {
- mFileOp.setExecutablePermission(destFile);
- }
- }
+ pkg.postUnzipFileHook(newArchive, monitor, mFileOp, destFile, entry);
// Increment progress bar to match. We update only between files.
for(incTotal += entry.getCompressedSize(); incCurr < incTotal; incCurr += incStep) {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
index 2091cb7..b09e2ee 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/Package.java
@@ -19,16 +19,20 @@ package com.android.sdklib.internal.repository;
import com.android.annotations.VisibleForTesting;
import com.android.annotations.VisibleForTesting.Visibility;
import com.android.sdklib.AndroidVersion;
+import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import com.android.sdklib.internal.repository.Archive.Arch;
import com.android.sdklib.internal.repository.Archive.Os;
+import com.android.sdklib.io.IFileOp;
import com.android.sdklib.repository.PkgProps;
import com.android.sdklib.repository.SdkAddonConstants;
import com.android.sdklib.repository.SdkRepoConstants;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.w3c.dom.Node;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
@@ -57,6 +61,13 @@ public abstract class Package implements IDescription, Comparable<Package> {
private final Archive[] mArchives;
private final SdkSource mSource;
+
+ // figure if we'll need to set the unix permissions
+ private static final boolean sUsingUnixPerm =
+ SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_DARWIN ||
+ SdkConstants.CURRENT_PLATFORM == SdkConstants.PLATFORM_LINUX;
+
+
/**
* Enum for the result of {@link Package#canBeUpdatedBy(Package)}. This used so that we can
* differentiate between a package that is totally incompatible, and one that is the same item
@@ -548,6 +559,38 @@ public abstract class Package implements IDescription, Comparable<Package> {
}
/**
+ * Hook called right after a file has been unzipped (during an install).
+ * <p/>
+ * The base class implementation makes sure to properly adjust set executable
+ * permission on Linux and MacOS system if the zip entry was marked as +x.
+ *
+ * @param archive The archive that is being installed.
+ * @param monitor The {@link ITaskMonitor} to display errors.
+ * @param fileOp The {@link IFileOp} used by the archive installer.
+ * @param unzippedFile The file that has just been unzipped in the install temp directory.
+ * @param zipEntry The {@link ZipArchiveEntry} that has just been unzipped.
+ */
+ public void postUnzipFileHook(
+ Archive archive,
+ ITaskMonitor monitor,
+ IFileOp fileOp,
+ File unzippedFile,
+ ZipArchiveEntry zipEntry) {
+
+ // if needed set the permissions.
+ if (sUsingUnixPerm && fileOp.isFile(unzippedFile)) {
+ // get the mode and test if it contains the executable bit
+ int mode = zipEntry.getUnixMode();
+ if ((mode & 0111) != 0) {
+ try {
+ fileOp.setExecutablePermission(unzippedFile);
+ } catch (IOException ignore) {}
+ }
+ }
+
+ }
+
+ /**
* Hook called right after an archive has been installed.
*
* @param archive The archive that has been installed.
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SourcePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SourcePackage.java
index ad92294..1eb00e1 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SourcePackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SourcePackage.java
@@ -24,8 +24,10 @@ import com.android.sdklib.SdkConstants;
import com.android.sdklib.SdkManager;
import com.android.sdklib.internal.repository.Archive.Arch;
import com.android.sdklib.internal.repository.Archive.Os;
+import com.android.sdklib.io.IFileOp;
import com.android.sdklib.repository.SdkRepoConstants;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.w3c.dom.Node;
import java.io.File;
@@ -268,6 +270,25 @@ public class SourcePackage extends Package implements IPackageVersion {
return folder;
}
+ /**
+ * Set all the files from a source package as read-only
+ * so that users don't end up modifying sources by mistake in Eclipse.
+ */
+ @Override
+ public void postUnzipFileHook(
+ Archive archive,
+ ITaskMonitor monitor,
+ IFileOp fileOp,
+ File unzippedFile,
+ ZipArchiveEntry zipEntry) {
+ super.postUnzipFileHook(archive, monitor, fileOp, unzippedFile, zipEntry);
+
+ if (fileOp.isFile(unzippedFile) &&
+ !SdkConstants.FN_SOURCE_PROP.equals(unzippedFile.getName())) {
+ fileOp.setReadOnly(unzippedFile);
+ }
+ }
+
@Override
public boolean sameItemAs(Package pkg) {
if (pkg instanceof SourcePackage) {
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java
index 9f8d600..a0fc8e3 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/FileOp.java
@@ -170,6 +170,14 @@ public class FileOp implements IFileOp {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setReadOnly(File file) {
+ file.setReadOnly();
+ }
+
+ /**
* Copies a binary file.
*
* @param source the source file to copy.
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/IFileOp.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/IFileOp.java
index e9dcb0e..b0d442b 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/io/IFileOp.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/io/IFileOp.java
@@ -54,6 +54,13 @@ public interface IFileOp {
public abstract void setExecutablePermission(File file) throws IOException;
/**
+ * Sets the file or directory as read-only.
+ *
+ * @param file The file or directory to set permissions on.
+ */
+ public abstract void setReadOnly(File file);
+
+ /**
* Copies a binary file.
*
* @param source the source file to copy.
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/ArchiveInstallerTest.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/ArchiveInstallerTest.java
index 6b7ff11..91fc2e6 100755
--- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/ArchiveInstallerTest.java
+++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/internal/repository/ArchiveInstallerTest.java
@@ -66,13 +66,11 @@ public class ArchiveInstallerTest extends TestCase {
return file;
}
-
@Override
protected boolean unzipFolder(
+ ArchiveReplacement archiveInfo,
File archiveFile,
- long compressedSize,
File unzipDestFolder,
- String pkgName,
ITaskMonitor monitor) {
// Claim the unzip works if the input archiveFile is one we know about
// and the destination actually exists.
diff --git a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/io/MockFileOp.java b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/io/MockFileOp.java
index c4d4254..05cf666 100755
--- a/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/io/MockFileOp.java
+++ b/sdkmanager/libs/sdklib/tests/src/com/android/sdklib/io/MockFileOp.java
@@ -183,6 +183,14 @@ public class MockFileOp implements IFileOp {
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setReadOnly(File file) {
+ // pass
+ }
+
+ /**
* Copies a binary file.
*
* @param source the source file to copy.
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
index 5801aca..9cf96f3 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
@@ -502,17 +502,19 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
// on a sub-thread but that doesn't seem cross-platform safe. We shouldn't
// have a lot of error logging, so this should be acceptable. If not, we could
// cache the visibility state.
- mShell.getDisplay().syncExec(new Runnable() {
- @Override
- public void run() {
- if (!mLogWindow.isVisible()) {
- // Don't toggle the window visibility directly.
- // Instead use the same action as the log-toggle button
- // so that the button's state be kept in sync.
- onToggleLogWindow();
+ if (mShell != null && !mShell.isDisposed()) {
+ mShell.getDisplay().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (!mLogWindow.isVisible()) {
+ // Don't toggle the window visibility directly.
+ // Instead use the same action as the log-toggle button
+ // so that the button's state be kept in sync.
+ onToggleLogWindow();
+ }
}
- }
- });
+ });
+ }
}
};
@@ -606,8 +608,10 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
private void onToggleLogWindow() {
// toggle visibility
- mLogWindow.setVisible(!mLogWindow.isVisible());
- mButtonShowLog.setState(mLogWindow.isVisible() ? 1 : 0);
+ if (!mButtonShowLog.isDisposed()) {
+ mLogWindow.setVisible(!mLogWindow.isVisible());
+ mButtonShowLog.setState(mLogWindow.isVisible() ? 1 : 0);
+ }
}
private void onStopSelected() {