1 11 package org.eclipse.pde.internal.build.tasks; 12 13 import java.io.File ; 14 import org.apache.tools.ant.Task; 15 16 21 public class GenericVersionReplacer extends Task { 22 private static final String FRAGMENT = "fragment.xml"; private static final String PLUGIN = "plugin.xml"; private static final String MANIFEST = "META-INF/MANIFEST.MF"; private String rootPath; 26 private String version; 27 28 public void execute() { 29 File root = new File (rootPath); 30 if (root.exists() && root.isFile() && 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(), PLUGIN); 38 foundFile = new File (root, FRAGMENT); 39 if (foundFile.exists() && foundFile.isFile()) 40 callPluginVersionModifier(foundFile.getAbsolutePath(), FRAGMENT); 41 42 foundFile = new File (root, MANIFEST); 43 if (foundFile.exists() && foundFile.isFile()) 44 callManifestModifier(foundFile.getAbsolutePath()); 45 } 46 47 private void callPluginVersionModifier(String path, String 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 path) { 57 ManifestModifier modifier = new ManifestModifier(); 58 modifier.setProject(getProject()); 59 modifier.setManifestLocation(path); 60 modifier.setKeyValue("Bundle-Version|" + version); modifier.execute(); 62 } 63 64 68 public void setPath(String location) { 69 this.rootPath = location; 70 } 71 72 76 public void setVersion(String version) { 77 this.version = version; 78 } 79 } 80 | Popular Tags |