Home | History | Annotate | Download | only in releng
      1 /*******************************************************************************
      2  * Copyright (c) 2000, 2006 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 Corporation - initial API and implementation
     10  *******************************************************************************/
     11 package org.eclipse.releng;
     12 
     13 import org.apache.tools.ant.Task;
     14 import org.apache.tools.ant.BuildException;
     15 import java.io.File;
     16 
     17 /*
     18  * A class that strips version numbers off built plugin directory names.  This
     19  * is helpful when prebuilt plugins are used in generating javadoc (on the
     20  * classpath).
     21  */
     22 
     23 public class VersionNumberStripper extends Task {
     24 
     25 	//the directory containing the directories and files from which to remove version information
     26 	private String directory;
     27 
     28 	public VersionNumberStripper() {
     29 		super();
     30 	}
     31 
     32 	public void setDirectory(String dir){directory=dir;}
     33 
     34 	public String getDirectory(){return directory;}
     35 
     36   	public void execute() throws BuildException {
     37   		setDirectory(directory);
     38   		stripVersions();
     39   	}
     40 
     41 	public static void main(String[] args) {
     42 		new VersionNumberStripper().execute();
     43 	}
     44 
     45 	private void stripVersions(){
     46 		/* rename directories by removing anything from an underscore onward,
     47 		 * assuming that anything following the first
     48 		 * occurence of an underscore is a version number
     49 		 */
     50 
     51 		File file=new File(directory);
     52 
     53 		File [] files = file.listFiles();
     54 
     55 		for (int i=0; i<files.length; i++){
     56 			String absolutePath = files[i].getAbsolutePath();
     57 			String path = absolutePath.substring(0, absolutePath.length()
     58 					- files[i].getName().length());
     59 
     60 			int underScorePos = files[i].getName().indexOf("_");
     61 			int jarExtPos = files[i].getName().indexOf(".jar");
     62 			if (underScorePos != -1) {
     63 				String targetPath;
     64 				if (jarExtPos != -1) {
     65 					targetPath =path
     66 							+ files[i].getName().substring(0, underScorePos)
     67 							+ ".jar";
     68 				} else {
     69 					targetPath = path
     70 							+ files[i].getName().substring(0, underScorePos);
     71 				}
     72 				files[i].renameTo(new File(targetPath));
     73 			}
     74 
     75 		}
     76 	}
     77 }
     78 
     79