aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xeclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/FileStoreAdapter.java160
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java49
-rwxr-xr-xsdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SamplePackage.java22
3 files changed, 229 insertions, 2 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/FileStoreAdapter.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/FileStoreAdapter.java
new file mode 100755
index 0000000..0f4e87e
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/FileStoreAdapter.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
+ *
+ * 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.ide.eclipse.adt.internal.wizards.newproject;
+
+import org.eclipse.core.filesystem.IFileInfo;
+import org.eclipse.core.filesystem.IFileStore;
+import org.eclipse.core.filesystem.IFileSystem;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+
+/**
+ * IFileStore implementation that delegates to the give {@link IFileStore}.
+ * This makes it easier to just override a single method from a store.
+ */
+class FileStoreAdapter implements IFileStore {
+
+ private final IFileStore mStore;
+
+ public FileStoreAdapter(IFileStore store) {
+ mStore = store;
+ }
+
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object getAdapter(Class adapter) {
+ return mStore.getAdapter(adapter);
+ }
+
+ @Override
+ public IFileInfo[] childInfos(int options, IProgressMonitor monitor) throws CoreException {
+ return mStore.childInfos(options, monitor);
+ }
+
+ @Override
+ public String[] childNames(int options, IProgressMonitor monitor)
+ throws CoreException {
+ return mStore.childNames(options, monitor);
+ }
+
+ @Override
+ public IFileStore[] childStores(int options, IProgressMonitor monitor) throws CoreException {
+ return mStore.childStores(options, monitor);
+ }
+
+ @Override
+ public void copy(IFileStore destination, int options, IProgressMonitor monitor)
+ throws CoreException {
+ mStore.copy(destination, options, monitor);
+ }
+
+ @Override
+ public void delete(int options, IProgressMonitor monitor) throws CoreException {
+ mStore.delete(options, monitor);
+ }
+
+ @Override
+ public IFileInfo fetchInfo() {
+ return mStore.fetchInfo();
+ }
+
+ @Override
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
+ return mStore.fetchInfo(options, monitor);
+ }
+
+ @Deprecated
+ @Override
+ public IFileStore getChild(IPath path) {
+ return mStore.getChild(path);
+ }
+
+ @Override
+ public IFileStore getFileStore(IPath path) {
+ return mStore.getFileStore(path);
+ }
+
+ @Override
+ public IFileStore getChild(String name) {
+ return mStore.getChild(name);
+ }
+
+ @Override
+ public IFileSystem getFileSystem() {
+ return mStore.getFileSystem();
+ }
+
+ @Override
+ public String getName() {
+ return mStore.getName();
+ }
+
+ @Override
+ public IFileStore getParent() {
+ return mStore.getParent();
+ }
+
+ @Override
+ public boolean isParentOf(IFileStore other) {
+ return mStore.isParentOf(other);
+ }
+
+ @Override
+ public IFileStore mkdir(int options, IProgressMonitor monitor) throws CoreException {
+ return mStore.mkdir(options, monitor);
+ }
+
+ @Override
+ public void move(IFileStore destination, int options, IProgressMonitor monitor)
+ throws CoreException {
+ mStore.move(destination, options, monitor);
+ }
+
+ @Override
+ public InputStream openInputStream(int options, IProgressMonitor monitor)
+ throws CoreException {
+ return mStore.openInputStream(options, monitor);
+ }
+
+ @Override
+ public OutputStream openOutputStream(int options, IProgressMonitor monitor)
+ throws CoreException {
+ return mStore.openOutputStream(options, monitor);
+ }
+
+ @Override
+ public void putInfo(IFileInfo info, int options, IProgressMonitor monitor)
+ throws CoreException {
+ mStore.putInfo(info, options, monitor);
+ }
+
+ @Override
+ public File toLocalFile(int options, IProgressMonitor monitor) throws CoreException {
+ return mStore.toLocalFile(options, monitor);
+ }
+
+ @Override
+ public URI toURI() {
+ return mStore.toURI();
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java
index b3af633..97da3ab 100644
--- a/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java
+++ b/eclipse/plugins/com.android.ide.eclipse.adt/src/com/android/ide/eclipse/adt/internal/wizards/newproject/NewProjectCreator.java
@@ -36,6 +36,7 @@ import com.android.sdklib.IAndroidTarget;
import com.android.sdklib.SdkConstants;
import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.filesystem.IFileSystem;
import org.eclipse.core.resources.IContainer;
@@ -1027,12 +1028,56 @@ public class NewProjectCreator {
IProgressMonitor monitor) throws CoreException {
// Copy the sampleDir into the project directory recursively
IFileSystem fileSystem = EFS.getLocalFileSystem();
- IFileStore sourceDir = fileSystem.getStore(sampleDir.toURI());
- IFileStore destDir = fileSystem.getStore(AdtUtils.getAbsolutePath(project));
+ IFileStore sourceDir = new ReadWriteFileStore(
+ fileSystem.getStore(sampleDir.toURI()));
+ IFileStore destDir = new ReadWriteFileStore(
+ fileSystem.getStore(AdtUtils.getAbsolutePath(project)));
sourceDir.copy(destDir, EFS.OVERWRITE, null);
}
/**
+ * In a sample we never duplicate source files as read-only.
+ * This creates a store that read files attributes and doesn't set the r-o flag.
+ */
+ private static class ReadWriteFileStore extends FileStoreAdapter {
+
+ public ReadWriteFileStore(IFileStore store) {
+ super(store);
+ }
+
+ // Override when reading attributes
+ @Override
+ public IFileInfo fetchInfo(int options, IProgressMonitor monitor) throws CoreException {
+ IFileInfo info = super.fetchInfo(options, monitor);
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
+ return info;
+ }
+
+ // Override when writing attributes
+ @Override
+ public void putInfo(IFileInfo info, int options, IProgressMonitor storeMonitor)
+ throws CoreException {
+ info.setAttribute(EFS.ATTRIBUTE_READ_ONLY, false);
+ super.putInfo(info, options, storeMonitor);
+ }
+
+ @Deprecated
+ @Override
+ public IFileStore getChild(IPath path) {
+ IFileStore child = super.getChild(path);
+ if (!(child instanceof ReadWriteFileStore)) {
+ child = new ReadWriteFileStore(child);
+ }
+ return child;
+ }
+
+ @Override
+ public IFileStore getChild(String name) {
+ return new ReadWriteFileStore(super.getChild(name));
+ }
+ }
+
+ /**
* Adds a file to the root of the project
* @param project the project to add the file to.
* @param source the file to add. It'll keep the same filename once copied into the project.
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SamplePackage.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SamplePackage.java
index 0462a9d..9b2daf7 100755
--- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SamplePackage.java
+++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/SamplePackage.java
@@ -23,9 +23,11 @@ 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.SdkRepoConstants;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.w3c.dom.Node;
import java.io.File;
@@ -367,6 +369,26 @@ public class SamplePackage extends MinToolsPackage
}
/**
+ * Set all the files from a sample package as read-only so that
+ * users don't end up modifying sources by mistake in Eclipse
+ * (samples are copied if using the NPW > Create from sample.)
+ */
+ @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);
+ }
+ }
+
+ /**
* Reads the hash from the properties file, if it exists.
* Returns null if something goes wrong, e.g. there's no property file or
* it doesn't contain our hash. Returns an empty string if the hash wasn't