01: /*******************************************************************************
02: * Copyright (c) 2000, 2004 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM - Initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.build.tasks;
11:
12: import java.io.File;
13: import org.apache.tools.ant.Task;
14:
15: /**
16: * Internal task.
17: * Replace the version numbers of plugin.xml, fragment.xml and manifest.mf.
18: * @since 3.0
19: */
20: public class GenericVersionReplacer extends Task {
21: private static final String FRAGMENT = "fragment.xml"; //$NON-NLS-1$
22: private static final String PLUGIN = "plugin.xml"; //$NON-NLS-1$
23: private static final String MANIFEST = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
24: private String rootPath;
25: private String version;
26:
27: public void execute() {
28: File root = new File(rootPath);
29: if (root.exists() && root.isFile()
30: && root.getName().equals(MANIFEST)) {
31: callManifestModifier(rootPath);
32: return;
33: }
34:
35: File foundFile = new File(root, PLUGIN);
36: if (foundFile.exists() && foundFile.isFile())
37: callPluginVersionModifier(foundFile.getAbsolutePath(),
38: PLUGIN);
39: foundFile = new File(root, FRAGMENT);
40: if (foundFile.exists() && foundFile.isFile())
41: callPluginVersionModifier(foundFile.getAbsolutePath(),
42: FRAGMENT);
43:
44: foundFile = new File(root, MANIFEST);
45: if (foundFile.exists() && foundFile.isFile())
46: callManifestModifier(foundFile.getAbsolutePath());
47: }
48:
49: private void callPluginVersionModifier(String path, String input) {
50: PluginVersionReplaceTask modifier = new PluginVersionReplaceTask();
51: modifier.setProject(getProject());
52: modifier.setPluginFilePath(path);
53: modifier.setVersionNumber(version);
54: modifier.setInput(input);
55: modifier.execute();
56: }
57:
58: private void callManifestModifier(String path) {
59: ManifestModifier modifier = new ManifestModifier();
60: modifier.setProject(getProject());
61: modifier.setManifestLocation(path);
62: modifier.setKeyValue("Bundle-Version|" + version); //$NON-NLS-1$
63: modifier.execute();
64: }
65:
66: /**
67: * Set the path where the file to be replaced is contained.
68: * @param location path to the folder containing the file that needs to be replaced or the file path
69: */
70: public void setPath(String location) {
71: this .rootPath = location;
72: }
73:
74: /**
75: * Set the new version.
76: * @param version the version that will be set in the manifest file.
77: */
78: public void setVersion(String version) {
79: this.version = version;
80: }
81: }
|