KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > build > tasks > GenericVersionReplacer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation 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  * IBM - Initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.build.tasks;
12
13 import java.io.File JavaDoc;
14 import org.apache.tools.ant.Task;
15
16 /**
17  * Internal task.
18  * Replace the version numbers of plugin.xml, fragment.xml and manifest.mf.
19  * @since 3.0
20  */

21 public class GenericVersionReplacer extends Task {
22     private static final String JavaDoc FRAGMENT = "fragment.xml"; //$NON-NLS-1$
23
private static final String JavaDoc PLUGIN = "plugin.xml"; //$NON-NLS-1$
24
private static final String JavaDoc MANIFEST = "META-INF/MANIFEST.MF"; //$NON-NLS-1$
25
private String JavaDoc rootPath;
26     private String JavaDoc version;
27
28     public void execute() {
29         File JavaDoc root = new File JavaDoc(rootPath);
30         if (root.exists() && root.isFile() && root.getName().equals(MANIFEST)) {
31             callManifestModifier(rootPath);
32             return;
33         }
34
35         File JavaDoc foundFile = new File JavaDoc(root, PLUGIN);
36         if (foundFile.exists() && foundFile.isFile())
37             callPluginVersionModifier(foundFile.getAbsolutePath(), PLUGIN);
38         foundFile = new File JavaDoc(root, FRAGMENT);
39         if (foundFile.exists() && foundFile.isFile())
40             callPluginVersionModifier(foundFile.getAbsolutePath(), FRAGMENT);
41
42         foundFile = new File JavaDoc(root, MANIFEST);
43         if (foundFile.exists() && foundFile.isFile())
44             callManifestModifier(foundFile.getAbsolutePath());
45     }
46
47     private void callPluginVersionModifier(String JavaDoc path, String JavaDoc input) {
48         PluginVersionReplaceTask modifier = new PluginVersionReplaceTask();
49         modifier.setProject(getProject());
50         modifier.setPluginFilePath(path);
51         modifier.setVersionNumber(version);
52         modifier.setInput(input);
53         modifier.execute();
54     }
55
56     private void callManifestModifier(String JavaDoc path) {
57         ManifestModifier modifier = new ManifestModifier();
58         modifier.setProject(getProject());
59         modifier.setManifestLocation(path);
60         modifier.setKeyValue("Bundle-Version|" + version); //$NON-NLS-1$
61
modifier.execute();
62     }
63
64     /**
65      * Set the path where the file to be replaced is contained.
66      * @param location path to the folder containing the file that needs to be replaced or the file path
67      */

68     public void setPath(String JavaDoc location) {
69         this.rootPath = location;
70     }
71
72     /**
73      * Set the new version.
74      * @param version the version that will be set in the manifest file.
75      */

76     public void setVersion(String JavaDoc version) {
77         this.version = version;
78     }
79 }
80
Popular Tags