|
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><ROOT_LOCATION>[,<ELEMENT_LOCATION>]</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 |
} |