Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 123618 Details for
Bug 220647
[native] Support for file manipulation actions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Take 2 - CopyAction and CleanupcopyAction for o.e.e.p2.touchpoint.natives
TouchpointNativesPatch_Jan24.txt (text/plain), 14.68 KB, created by
Henrik Lindberg
on 2009-01-23 20:33:43 EST
(
hide
)
Description:
Take 2 - CopyAction and CleanupcopyAction for o.e.e.p2.touchpoint.natives
Filename:
MIME Type:
Creator:
Henrik Lindberg
Created:
2009-01-23 20:33:43 EST
Size:
14.68 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.touchpoint.natives >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.touchpoint.natives/plugin.xml,v >retrieving revision 1.6 >diff -u -r1.6 plugin.xml >--- plugin.xml 27 Nov 2008 00:00:52 -0000 1.6 >+++ plugin.xml 24 Jan 2009 01:32:16 -0000 >@@ -75,4 +75,26 @@ > version="1.0.0"> > </action> > </extension> >+ <extension >+ point="org.eclipse.equinox.p2.engine.actions"> >+ <action >+ class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CopyAction" >+ description="copy(source,target[,overwrite])" >+ name="copy" >+ touchpointType="org.eclipse.equinox.p2.native" >+ touchpointVersion="1.0.0" >+ version="1.0.0"> >+ </action> >+ </extension> >+ <extension >+ point="org.eclipse.equinox.p2.engine.actions"> >+ <action >+ class="org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupcopyAction" >+ description="cleanupcopy(source,target)" >+ name="cleanupcopy" >+ touchpointType="org.eclipse.equinox.p2.native" >+ touchpointVersion="1.0.0" >+ version="1.0.0"> >+ </action> >+ </extension> > </plugin> >Index: src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java,v >retrieving revision 1.1 >diff -u -r1.1 ActionConstants.java >--- src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java 10 Nov 2008 19:27:23 -0000 1.1 >+++ src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/ActionConstants.java 24 Jan 2009 01:32:16 -0000 >@@ -17,4 +17,7 @@ > public static final String PARM_LINK_NAME = "linkName"; //$NON-NLS-1$ > public static final String PARM_LINK_TARGET = "linkTarget"; //$NON-NLS-1$ > public static final String PARM_LINK_FORCE = "force"; //$NON-NLS-1$ >+ public static final String PARM_COPY_TARGET = "target"; //$NON-NLS-1$ >+ public static final String PARM_COPY_SOURCE = "source"; //$NON-NLS-1$ >+ public static final String PARM_COPY_OVERWRITE = "overwrite"; //$NON-NLS-1$ > } >Index: src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java,v >retrieving revision 1.2 >diff -u -r1.2 Messages.java >--- src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java 8 Apr 2008 21:23:41 -0000 1.2 >+++ src/org/eclipse/equinox/internal/p2/touchpoint/natives/Messages.java 24 Jan 2009 01:32:16 -0000 >@@ -27,5 +27,6 @@ > public static String unzipping; > public static String restoring; > public static String param_not_set; >+ public static String copy_failed; > > } >Index: src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties >=================================================================== >RCS file: /cvsroot/rt/org.eclipse.equinox/p2/bundles/org.eclipse.equinox.p2.touchpoint.natives/src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties,v >retrieving revision 1.3 >diff -u -r1.3 messages.properties >--- src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties 10 Nov 2008 19:27:24 -0000 1.3 >+++ src/org/eclipse/equinox/internal/p2/touchpoint/natives/messages.properties 24 Jan 2009 01:32:16 -0000 >@@ -16,5 +16,6 @@ > artifact_repo_not_found=The artifact repository manager could not be found. > could_not_obtain_download_cache=Could not obtain the download cache location. > download_cache_not_writeable=Agent download cache not writeable: {0}. >+copy_failed=I/O Error while copying {0} - see details. > > >Index: src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java >diff -N src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CopyAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,175 @@ >+/******************************************************************************* >+ * Copyright (c) 2009 Cloudsmith Inc. and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Cloudsmith Inc. - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.p2.touchpoint.natives.actions; >+ >+import java.io.*; >+import java.util.ArrayList; >+import java.util.Map; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.equinox.internal.p2.engine.Profile; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.*; >+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository; >+import org.eclipse.equinox.internal.provisional.p2.core.ProvisionException; >+import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >+import org.eclipse.osgi.util.NLS; >+ >+/** >+ * Copies from PARM_COPY_SOURCE to PARAM_COPY_TARGET >+ * The optional parameter PARAM_COPY_OVERWRITE overwrites and existing file if set to true, else >+ * and existing file with the same name is an error. The default is false. >+ * If the source is a directory, a merge copy to the target is performed. >+ * Copy will copy files and directories (recursively). >+ * >+ * @author henrik.lindberg@cloudsmith.com >+ */ >+public class CopyAction extends ProvisioningAction { >+ public static final String ID = "cp"; //$NON-NLS-1$ >+ >+ public IStatus execute(Map parameters) { >+ return copy(parameters); >+ } >+ >+ public static IStatus copy(Map parameters) { >+ String target = (String) parameters.get(ActionConstants.PARM_COPY_TARGET); >+ if (target == null) >+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_TARGET, ID), null); >+ >+ String source = (String) parameters.get(ActionConstants.PARM_COPY_SOURCE); >+ if (source == null) >+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.param_not_set, ActionConstants.PARM_COPY_SOURCE, ID), null); >+ >+ String overwrite = (String) parameters.get(ActionConstants.PARM_COPY_OVERWRITE); >+ Profile profile = (Profile) parameters.get(ActionConstants.PARM_PROFILE); >+ IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU); >+ >+ String originalSource = source; >+ if (source.equals(ActionConstants.PARM_ARTIFACT)) { >+ //TODO: fix wherever this occurs -- investigate as this is probably not desired >+ if (iu.getArtifacts() == null || iu.getArtifacts().length == 0) >+ return Status.OK_STATUS; >+ >+ IArtifactKey artifactKey = iu.getArtifacts()[0]; >+ >+ IFileArtifactRepository downloadCache; >+ try { >+ downloadCache = Util.getDownloadCacheRepo(); >+ } catch (ProvisionException e) { >+ return e.getStatus(); >+ } >+ File fileLocation = downloadCache.getArtifactFile(artifactKey); >+ if ((fileLocation == null) || !fileLocation.exists()) >+ return Util.createError(NLS.bind(Messages.artifact_not_available, artifactKey)); >+ source = fileLocation.getAbsolutePath(); >+ } >+ >+ File sourceFile = new File(source); >+ File targetFile = new File(target); >+ File[] copiedFiles = null; >+ try { >+ copiedFiles = mergeCopy(sourceFile, targetFile, Boolean.valueOf(overwrite).booleanValue()); >+ } catch (IOException e) { >+ return new Status(IStatus.ERROR, Activator.ID, IStatus.OK, NLS.bind(Messages.copy_failed, sourceFile.getPath()), e); >+ } >+ // keep copied file in the profile as memento for CleanupCopy >+ StringBuffer copiedFileNameBuffer = new StringBuffer(); >+ for (int i = 0; i < copiedFiles.length; i++) >+ copiedFileNameBuffer.append(copiedFiles[i].getAbsolutePath()).append(ActionConstants.PIPE); >+ >+ profile.setInstallableUnitProperty(iu, "copied" + ActionConstants.PIPE + originalSource + ActionConstants.PIPE + target, copiedFileNameBuffer.toString()); //$NON-NLS-1$ >+ >+ return Status.OK_STATUS; >+ } >+ >+ public IStatus undo(Map parameters) { >+ return CleanupcopyAction.cleanupcopy(parameters); >+ } >+ >+ /** >+ * Merge-copy file or directory. >+ * @param source >+ * @param target >+ * @param overwrite >+ * @throws IOException >+ */ >+ private static File[] mergeCopy(File source, File target, boolean overwrite) throws IOException { >+ ArrayList copiedFiles = new ArrayList(); >+ xcopy(copiedFiles, source, target, overwrite); >+ return (File[]) copiedFiles.toArray(new File[copiedFiles.size()]); >+ } >+ >+ /** >+ * Merge-copy file or directory. >+ * @param copiedFiles - ArrayList where copied files are collected >+ * @param source >+ * @param target >+ * @param overwrite >+ * @throws IOException >+ */ >+ private static void xcopy(ArrayList copiedFiles, File source, File target, boolean overwrite) throws IOException { >+ if (!source.exists()) >+ throw new IOException("Source: " + source + "does not exists"); //$NON-NLS-1$//$NON-NLS-2$ >+ >+ if (source.isDirectory()) { >+ if (target.exists() && target.isFile()) { >+ if (!overwrite) >+ throw new IOException("Target: " + target + " already exists"); //$NON-NLS-1$//$NON-NLS-2$ >+ target.delete(); >+ } >+ if (!target.exists()) >+ target.mkdirs(); >+ copiedFiles.add(target); >+ File[] children = source.listFiles(); >+ for (int i = 0; i < children.length; i++) >+ xcopy(copiedFiles, children[i], new File(target, children[i].getName()), overwrite); >+ return; >+ } else if (target.exists() && !overwrite) >+ throw new IOException("Target: " + target + " already exists"); //$NON-NLS-1$//$NON-NLS-2$ >+ >+ InputStream input = null; >+ OutputStream output = null; >+ try { >+ input = new BufferedInputStream(new FileInputStream(source)); >+ output = new BufferedOutputStream(new FileOutputStream(target)); >+ >+ byte[] buffer = new byte[8192]; >+ int bytesRead = 0; >+ while ((bytesRead = input.read(buffer)) != -1) >+ output.write(buffer, 0, bytesRead); >+ } catch (IOException e) { >+ // get the original IOException to the log >+ e.printStackTrace(); >+ throw new IOException("Error while copying:" + source.getAbsolutePath()); //$NON-NLS-1$ >+ } finally { >+ if (input != null) { >+ try { >+ input.close(); >+ } catch (IOException e) { >+ // Don't stop because of this - but log it >+ System.err.println("Exception while trying to close input stream on: " + source.getAbsolutePath()); //$NON-NLS-1$ >+ e.printStackTrace(); >+ } >+ } >+ if (output != null) { >+ try { >+ output.close(); >+ } catch (IOException e) { >+ // Don't stop because of this - but log it >+ System.err.println("Exception while trying to close output stream on: " + target.getAbsolutePath()); //$NON-NLS-1$ >+ e.printStackTrace(); >+ } >+ } >+ } >+ copiedFiles.add(target); >+ } >+} >Index: src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java >diff -N src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/p2/touchpoint/natives/actions/CleanupcopyAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,74 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.internal.p2.touchpoint.natives.actions; >+ >+import java.io.File; >+import java.util.*; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.Messages; >+import org.eclipse.equinox.internal.p2.touchpoint.natives.Util; >+import org.eclipse.equinox.internal.provisional.p2.engine.IProfile; >+import org.eclipse.equinox.internal.provisional.p2.engine.ProvisioningAction; >+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit; >+import org.eclipse.osgi.util.NLS; >+ >+public class CleanupcopyAction extends ProvisioningAction { >+ >+ public static final String ACTION_CLEANUPCOPY = "cleanupcopy"; //$NON-NLS-1$ >+ >+ public IStatus execute(Map parameters) { >+ return cleanupcopy(parameters); >+ } >+ >+ public IStatus undo(Map parameters) { >+ return CopyAction.copy(parameters); >+ } >+ >+ public static IStatus cleanupcopy(Map parameters) { >+ String source = (String) parameters.get(ActionConstants.PARM_SOURCE); >+ if (source == null) >+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_SOURCE, ACTION_CLEANUPCOPY)); >+ String target = (String) parameters.get(ActionConstants.PARM_TARGET); >+ if (target == null) >+ return Util.createError(NLS.bind(Messages.param_not_set, ActionConstants.PARM_TARGET, ACTION_CLEANUPCOPY)); >+ >+ IInstallableUnit iu = (IInstallableUnit) parameters.get(ActionConstants.PARM_IU); >+ IProfile profile = (IProfile) parameters.get(ActionConstants.PARM_PROFILE); >+ >+ String copied = profile.getInstallableUnitProperty(iu, "copied" + ActionConstants.PIPE + source + ActionConstants.PIPE + target); //$NON-NLS-1$ >+ >+ if (copied == null) >+ return Status.OK_STATUS; >+ >+ StringTokenizer tokenizer = new StringTokenizer(copied, ActionConstants.PIPE); >+ List directories = new ArrayList(); >+ while (tokenizer.hasMoreTokens()) { >+ String fileName = tokenizer.nextToken(); >+ File file = new File(fileName); >+ if (!file.exists()) >+ continue; >+ >+ if (file.isDirectory()) >+ directories.add(file); >+ else >+ file.delete(); >+ } >+ >+ for (Iterator it = directories.iterator(); it.hasNext();) { >+ File directory = (File) it.next(); >+ directory.delete(); >+ } >+ >+ return Status.OK_STATUS; >+ } >+ >+} >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 220647
:
123614
|
123617
| 123618