KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > fetch > COPYFetchTasksFactory


1 /**********************************************************************
2  * Copyright (c) 2004, 2006 Eclipse Foundation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * Gunnar Wagenknecht - Initial API and implementation
10  * IBM Corporation - Initial API and implementation
11  **********************************************************************/

12 package org.eclipse.pde.internal.build.fetch;
13
14 import java.util.Map JavaDoc;
15 import java.util.Properties JavaDoc;
16 import org.eclipse.core.runtime.*;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.pde.build.IAntScript;
19 import org.eclipse.pde.build.IFetchFactory;
20 import org.eclipse.pde.internal.build.*;
21
22 /**
23  * An <code>IFetchFactory</code> that fetches features and plugins by
24  * copying from a specific location (id: <code>COPY</code>).
25  * <p>
26  * Map file arguments:
27  * <code>&lt;ROOT_LOCATION&gt;[,&lt;ELEMENT_LOCATION&gt;]</code>
28  * <dl>
29  * <dt>ROOT_LOCATION</dt>
30  * <dd>The ROOT_LOCATION (eg. <code>/source/eclipse</code>, or
31  * <code>D:/dev/myproduct</code>) is used as root path to determine the
32  * location to fetch. It can be overwritten via the
33  * <code>fetchTag</code> to fetch from another location (for example, on a different machine).</dd>
34  * </dl>
35  * <dt>ELEMENT_LOCATION</dt>
36  * <dd>A path withing the ROOT_LOCATION (eg.
37  * <code>org.eclipse.sdk-feature/features/org.eclipse.rcp</code>) to retrive
38  * the element from if it is not within the root. If this is not provided the
39  * default path will be used which simply maps to the element name.</dd>
40  * </dl>
41  * </p>
42  */

43 public class COPYFetchTasksFactory implements IFetchFactory, IPDEBuildConstants {
44     public static final String JavaDoc ID = "COPY"; //$NON-NLS-1$
45

46     private static final String JavaDoc SEPARATOR = ","; //$NON-NLS-1$
47
private static final String JavaDoc OVERRIDE_TAG = ID;
48
49     //COPY specific keys used in the map being passed around.
50
private static final String JavaDoc KEY_PATH = "path"; //$NON-NLS-1$
51
private static final String JavaDoc KEY_ROOT = "root"; //$NON-NLS-1$
52

53     public void generateRetrieveElementCall(Map JavaDoc entryInfos, IPath destination, IAntScript script) {
54         String JavaDoc element = (String JavaDoc) entryInfos.get(KEY_ELEMENT_NAME);
55
56         // we directly copy the disc content into the destination
57
String JavaDoc root = (String JavaDoc) entryInfos.get(KEY_ROOT);
58         String JavaDoc path = (String JavaDoc) entryInfos.get(KEY_PATH);
59         IPath sourcePath = new Path(root);
60         if (path != null) {
61             sourcePath = sourcePath.append(path);
62         } else {
63             sourcePath = sourcePath.append(element);
64         }
65
66         printCopyTask(null, destination.toString(), new String JavaDoc[] {sourcePath.toString()}, false, true, script);
67     }
68
69     public void generateRetrieveFilesCall(final Map JavaDoc entryInfos, IPath destination, final String JavaDoc[] files, IAntScript script) {
70         String JavaDoc root = (String JavaDoc) entryInfos.get(KEY_ROOT);
71         String JavaDoc path = (String JavaDoc) entryInfos.get(KEY_PATH);
72
73         for (int i = 0; i < files.length; i++) {
74             String JavaDoc file = files[i];
75             IPath filePath = new Path(root);
76             if (path != null) {
77                 filePath = filePath.append(path).append(file);
78             } else {
79                 filePath = filePath.append((String JavaDoc) entryInfos.get(KEY_ELEMENT_NAME)).append(file);
80             }
81             printCopyTask(filePath.toString(), destination.toString(), null, true, true, script);
82         }
83     }
84
85     public void addTargets(IAntScript script) {
86         // no additional targets
87
}
88
89     public void parseMapFileEntry(String JavaDoc repoSpecificentry, Properties JavaDoc overrideTags, Map JavaDoc entryInfos) throws CoreException {
90         String JavaDoc[] arguments = Utils.getArrayFromStringWithBlank(repoSpecificentry, SEPARATOR);
91         if (arguments.length < 1) {
92             String JavaDoc message = NLS.bind(Messages.error_incorrectDirectoryEntry, entryInfos.get(KEY_ELEMENT_NAME));
93             throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
94         }
95
96         String JavaDoc overrideTag = overrideTags != null ? overrideTags.getProperty(OVERRIDE_TAG) : null;
97         entryInfos.put(KEY_ROOT, (null == overrideTag || overrideTag.trim().length() == 0) ? arguments[0] : overrideTag);
98         entryInfos.put(KEY_PATH, (arguments.length > 1 && arguments[1].trim().length() > 0) ? arguments[1] : null);
99     }
100
101     /**
102      * Print a <code>copy</code> task to the script. The source file is specified
103      * by the <code>file</code> OR the <code>dirs</code> parameter.
104      * The destination directory is specified by the <code>todir</code> parameter.
105      * @param file the source file
106      * @param todir the destination directory
107      * @param dirs the directories to copy
108      * @param overwrite indicates if existing files should be overwritten
109      * @param script the script to print to
110      */

111     private void printCopyTask(String JavaDoc file, String JavaDoc todir, String JavaDoc[] dirs, boolean failOnError, boolean overwrite, IAntScript script) {
112         script.printTabs();
113         script.print("<copy"); //$NON-NLS-1$
114
script.printAttribute("file", file, false); //$NON-NLS-1$
115
script.printAttribute("todir", todir, false); //$NON-NLS-1$
116
script.printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
117
script.printAttribute("overwrite", overwrite ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
118

119         if (dirs == null)
120             script.println("/>"); //$NON-NLS-1$
121
else {
122             script.println(">"); //$NON-NLS-1$
123
for (int i = 0; i < dirs.length; i++) {
124                 script.printTabs();
125                 script.print("\t<fileset"); //$NON-NLS-1$
126
script.printAttribute("dir", dirs[i], true); //$NON-NLS-1$
127
script.println("/>"); //$NON-NLS-1$
128
}
129             script.println("</copy>"); //$NON-NLS-1$
130
}
131     }
132 }
133
Popular Tags