Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 34757 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (-1 / +1 lines)
Lines 11-14 Link Here
11
pluginName = Plug-in Development Environment Build Support
11
pluginName = Plug-in Development Environment Build Support
12
providerName = Eclipse.org
12
providerName = Eclipse.org
13
13
14
fetchTaskFactories.name = Fetch Script Factories
14
fetchFactories.name = Fetch Script Factories
(-)plugin.xml (-1 / +4 lines)
Lines 1-7 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<?eclipse version="3.0"?>
2
<?eclipse version="3.0"?>
3
<plugin>
3
<plugin>
4
   <extension-point id="fetchFactories" name="%fetchTaskFactories.name" schema="schema/fetchTaskFactories.exsd"/>
4
   <extension-point id="fetchFactories" name="%fetchFactories.name" schema="schema/fetchFactories.exsd"/>
5
<!-- Tasks -->
5
<!-- Tasks -->
6
   <extension
6
   <extension
7
         point="org.eclipse.ant.core.antTasks">
7
         point="org.eclipse.ant.core.antTasks">
Lines 96-101 Link Here
96
      <factory
96
      <factory
97
            class="org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory"
97
            class="org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory"
98
            id="CVS"/>
98
            id="CVS"/>
99
      <factory
100
            class="org.eclipse.pde.internal.build.fetch.COPYFetchTasksFactory"
101
            id="COPY"/>
99
   </extension>
102
   </extension>
100
   
103
   
101
    <extension
104
    <extension
(-)schema/fetchFactories.exsd (-5 / +5 lines)
Lines 84-96 Link Here
84
      </appInfo>
84
      </appInfo>
85
      <documentation>
85
      <documentation>
86
         &lt;pre&gt;
86
         &lt;pre&gt;
87
&lt;extension point=&quot;org.eclipse.pde.build.fetchTaskFactories&quot;&gt;
87
&lt;extension point=&quot;org.eclipse.pde.build.fetchFactories&quot;&gt;
88
    &lt;factory
89
        class=&quot;org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory&quot;
90
        id=&quot;CVS&quot;/&gt;
88
    &lt;factory
91
    &lt;factory
89
        class=&quot;org.eclipse.pde.internal.build.fetch.COPYFetchTasksFactory&quot;
92
        class=&quot;org.eclipse.pde.internal.build.fetch.COPYFetchTasksFactory&quot;
90
        id=&quot;COPY&quot;/&gt;
93
        id=&quot;COPY&quot;/&gt;
91
      &lt;factory
92
            class=&quot;org.eclipse.pde.internal.build.fetch.CVSFetchTaskFactory&quot;
93
            id=&quot;CVS&quot;/&gt;
94
&lt;/extension&gt;
94
&lt;/extension&gt;
95
&lt;/pre&gt;
95
&lt;/pre&gt;
96
      </documentation>
96
      </documentation>
Lines 101-107 Link Here
101
         <meta.section type="apiInfo"/>
101
         <meta.section type="apiInfo"/>
102
      </appInfo>
102
      </appInfo>
103
      <documentation>
103
      <documentation>
104
         See the org.eclipse.pde.build.IFetchFactory interface.
104
         See the &lt;code&gt;org.eclipse.pde.build.IFetchFactory&lt;/code&gt; interface.
105
      </documentation>
105
      </documentation>
106
   </annotation>
106
   </annotation>
107
107
(-)src/org/eclipse/pde/internal/build/fetch/COPYFetchTasksFactory.java (+177 lines)
Added Link Here
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
 **********************************************************************/
11
package org.eclipse.pde.internal.build.fetch;
12
13
import java.util.*;
14
import org.eclipse.core.runtime.*;
15
import org.eclipse.osgi.util.NLS;
16
import org.eclipse.pde.build.*;
17
import org.eclipse.pde.internal.build.*;
18
19
/**
20
 * An <code>IFetchFactory</code> that fetches features and plugins by
21
 * copying from a specific location (id: <code>COPY</code>).
22
 * <p>
23
 * Map file arguments:
24
 * <code>&lt;ROOT_LOCATION&gt;[,&lt;ELEMENT_LOCATION&gt;]</code>
25
 * <dl>
26
 * <dt>ROOT_LOCATION</dt>
27
 * <dd>The ROOT_LOCATION (eg. <code>/source/eclipse</code>, or
28
 * <code>D:/dev/myproduct</code>) is used as root path to determine the
29
 * location to fetch. It can be overwritten via the
30
 * <code>fetchTag</code> to fetch from another location (for example, on a different machine).</dd>
31
 * </dl>
32
 * <dt>ELEMENT_LOCATION</dt>
33
 * <dd>A path withing the ROOT_LOCATION (eg.
34
 * <code>org.eclipse.sdk-feature/features/org.eclipse.rcp</code>) to retrive
35
 * the element from if it is not within the root. If this is not provided the
36
 * default path will be used which simply maps to the element name.</dd>
37
 * </dl>
38
 * </p>
39
 */
40
public class COPYFetchTasksFactory implements IFetchFactory, IPDEBuildConstants {
41
	public static final String ID = "COPY"; //$NON-NLS-1$
42
43
	private static final String TARGET_GET_FROM_DISC = "FetchFromDisc"; //$NON-NLS-1$
44
	private static final String SEPARATOR = ","; //$NON-NLS-1$
45
	private static final String OVERRIDE_TAG = ID;
46
47
	//COPY specific keys used in the map being passed around.
48
	private static final String KEY_PATH = "path"; //$NON-NLS-1$
49
	private static final String KEY_ROOT = "root"; //$NON-NLS-1$
50
51
	//Properties used in the COPY part of the scripts
52
	private static final String PROP_DESTINATIONFOLDER = "destination"; //$NON-NLS-1$
53
	private static final String PROP_QUIET = "quiet"; //$NON-NLS-1$
54
	private static final String PROP_SOURCEPATH = "sourcePath"; //$NON-NLS-1$
55
	private static final String PROP_FILETOCHECK = "fileToCheck"; //$NON-NLS-1$
56
57
	public void generateRetrieveElementCall(Map entryInfos, IPath destination, IAntScript script) {
58
		String type = (String) entryInfos.get(KEY_ELEMENT_TYPE);
59
		String element = (String) entryInfos.get(KEY_ELEMENT_NAME);
60
61
		Map params = new HashMap(2);
62
		// we directly copy the disc content into the destination
63
		params.put(PROP_DESTINATIONFOLDER, destination.toString());
64
		params.put(PROP_QUIET, "${copy.quiet}"); //$NON-NLS-1$
65
66
		String root = (String) entryInfos.get(KEY_ROOT);
67
		String path = (String) entryInfos.get(KEY_PATH);
68
		IPath sourcePath = new Path(root);
69
		if (path != null) {
70
			sourcePath = sourcePath.append(path);
71
		} else {
72
			sourcePath = sourcePath.append(element);
73
		}
74
		params.put(PROP_SOURCEPATH, sourcePath.toString());
75
76
		IPath locationToCheck = (IPath) destination.clone();
77
		if (type.equals(ELEMENT_TYPE_FEATURE)) {
78
			locationToCheck = locationToCheck.append(Constants.FEATURE_FILENAME_DESCRIPTOR);
79
		} else if (type.equals(ELEMENT_TYPE_PLUGIN)) {
80
			locationToCheck = locationToCheck.append(Constants.PLUGIN_FILENAME_DESCRIPTOR);
81
		} else if (type.equals(ELEMENT_TYPE_FRAGMENT)) {
82
			locationToCheck = locationToCheck.append(Constants.FRAGMENT_FILENAME_DESCRIPTOR);
83
		} else if (type.equals(ELEMENT_TYPE_BUNDLE)) {
84
			locationToCheck = locationToCheck.append(Constants.BUNDLE_FILENAME_DESCRIPTOR);
85
		}
86
		params.put(PROP_FILETOCHECK, locationToCheck.toString());
87
88
		printAvailableTask(locationToCheck.toString(), locationToCheck.toString(), script);
89
		if (type.equals(IFetchFactory.ELEMENT_TYPE_PLUGIN) || type.equals(IFetchFactory.ELEMENT_TYPE_FRAGMENT)) {
90
			printAvailableTask(locationToCheck.toString(), locationToCheck.removeLastSegments(1).append(Constants.BUNDLE_FILENAME_DESCRIPTOR).toString(), script);
91
		}
92
93
		script.printAntCallTask(TARGET_GET_FROM_DISC, true, params);
94
	}
95
96
	public void generateRetrieveFilesCall(final Map entryInfos, IPath destination, final String[] files, IAntScript script) {
97
		String root = (String) entryInfos.get(KEY_ROOT);
98
		String path = (String) entryInfos.get(KEY_PATH);
99
100
		for (int i = 0; i < files.length; i++) {
101
			String file = files[i];
102
			IPath filePath = new Path(root);
103
			if (path != null) {
104
				filePath = filePath.append(path).append(file);
105
			} else {
106
				filePath = filePath.append((String) entryInfos.get(KEY_ELEMENT_NAME)).append(file);
107
			}
108
			printCopyTask(filePath.toString(), destination.toString(), null, false, true, script);
109
		}
110
	}
111
112
	public void addTargets(IAntScript script) {
113
		script.printTargetDeclaration(TARGET_GET_FROM_DISC, null, null, "${" + PROP_FILETOCHECK + "}", null); //$NON-NLS-1$ //$NON-NLS-2$
114
		printCopyTask(null, "${" + PROP_DESTINATIONFOLDER + "}", new String[] {"${" + PROP_SOURCEPATH + "}"}, false, true, script); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 
115
		script.printTargetEnd();
116
	}
117
118
	public void parseMapFileEntry(String repoSpecificentry, Properties overrideTags, Map entryInfos) throws CoreException {
119
		String[] arguments = Utils.getArrayFromStringWithBlank(repoSpecificentry, SEPARATOR);
120
		if (arguments.length < 1) {
121
			String message = NLS.bind(Messages.error_incorrectDirectoryEntry, entryInfos.get(KEY_ELEMENT_NAME));
122
			throw new CoreException(new Status(IStatus.ERROR, PI_PDEBUILD, EXCEPTION_ENTRY_MISSING, message, null));
123
		}
124
125
		String overrideTag = overrideTags.getProperty(OVERRIDE_TAG);
126
		entryInfos.put(KEY_ROOT, (null == overrideTag || overrideTag.trim().length() == 0) ? arguments[0] : overrideTag);
127
		entryInfos.put(KEY_PATH, (arguments.length > 1 && arguments[1].trim().length() > 0) ? arguments[1] : null);
128
	}
129
130
	/**
131
	 * Print the <code>available</code> Ant task to this script. This task sets a property
132
	 * value if the given file exists at runtime.
133
	 * 
134
	 * @param property the property to set
135
	 * @param file the file to look for
136
	 * @param script the script to print to
137
	 */
138
	private void printAvailableTask(String property, String file, IAntScript script) {
139
		script.printTabs();
140
		script.print("<available"); //$NON-NLS-1$
141
		script.printAttribute("property", property, true); //$NON-NLS-1$
142
		script.printAttribute("file", file, false); //$NON-NLS-1$
143
		script.println("/>"); //$NON-NLS-1$
144
	}
145
146
	/**
147
	 * Print a <code>copy</code> task to the script. The source file is specified 
148
	 * by the <code>file</code> OR the <code>dirs</code> parameter. 
149
	 * The destination directory is specified by the <code>todir</code> parameter. 
150
	 * @param file the source file
151
	 * @param todir the destination directory
152
	 * @param dirs the directories to copy
153
	 * @param overwrite indicates if existing files should be overwritten 
154
	 * @param script the script to print to
155
	 */
156
	private void printCopyTask(String file, String todir, String[] dirs, boolean failOnError, boolean overwrite, IAntScript script) {
157
		script.printTabs();
158
		script.print("<copy"); //$NON-NLS-1$
159
		script.printAttribute("file", file, false); //$NON-NLS-1$
160
		script.printAttribute("todir", todir, false); //$NON-NLS-1$
161
		script.printAttribute("failonerror", failOnError ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
162
		script.printAttribute("overwrite", overwrite ? "true" : "false", true); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
163
164
		if (dirs == null)
165
			script.println("/>"); //$NON-NLS-1$
166
		else {
167
			script.println(">"); //$NON-NLS-1$
168
			for (int i = 0; i < dirs.length; i++) {
169
				script.printTabs();
170
				script.print("\t<fileset"); //$NON-NLS-1$
171
				script.printAttribute("dir", dirs[i], true); //$NON-NLS-1$
172
				script.println("/>"); //$NON-NLS-1$
173
			}
174
			script.println("</copy>"); //$NON-NLS-1$
175
		}
176
	}
177
}

Return to bug 34757