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 /* 12 * Created on Dec 9, 2003 13 * 14 */ 15 package org.eclipse.releng; 16 17 import org.apache.tools.ant.Task; 18 import org.apache.tools.ant.BuildException; 19 20 import java.util.Vector; 21 import java.io.BufferedReader; 22 import java.io.File; 23 import java.io.FileNotFoundException; 24 import java.io.FileReader; 25 import java.io.IOException; 26 27 /** 28 * @author kmoir 29 * 30 * To change the template for this generated type comment go to Window - 31 * Preferences - Java - Code Generation - Code and Comments 32 */ 33 public class CvsDiffParser extends Task { 34 35 private String mapDiffFile; 36 private Vector updatedMaps; 37 38 /** 39 * 40 */ 41 public CvsDiffParser() { 42 super(); 43 // TODO Auto-generated constructor stub 44 } 45 46 public static void main(String[] args) { 47 48 CvsDiffParser parser = new CvsDiffParser(); 49 parser.setMapDiffFile("d:/junk/cvsDiff.txt"); 50 parser.execute(); 51 } 52 53 public void execute() throws BuildException { 54 parseMapDiffFile(); 55 sendNotice(); 56 } 57 58 /** 59 * @return Returns the mapDiffFile. 60 */ 61 public String getMapDiffFile() { 62 return mapDiffFile; 63 } 64 65 /** 66 * @param mapDiffFile 67 * The mapDiffFile to set. 68 */ 69 public void setMapDiffFile(String mapDiffFile) { 70 this.mapDiffFile = mapDiffFile; 71 } 72 73 private void parseMapDiffFile() { 74 updatedMaps = new Vector(); 75 76 //read the contents of the Diff file, and return contents as a String 77 if (mapDiffFile.length() == 0) 78 updatedMaps=null; 79 80 BufferedReader in = null; 81 String aLine; 82 83 try { 84 in = new BufferedReader(new FileReader(mapDiffFile)); 85 } catch (FileNotFoundException e) { 86 e.printStackTrace(); 87 } 88 89 try { 90 while ((aLine = in.readLine()) != null) { 91 if (aLine.startsWith("RCS file")) { 92 String mapPath = 93 (aLine 94 .substring(aLine.indexOf(":"), aLine.indexOf(","))) 95 .trim(); 96 97 //verification for actual changes in tags base.plugin 98 while ((aLine = in.readLine()) != null && !aLine.startsWith("===")){ 99 if (aLine.startsWith("< plugin")||aLine.startsWith("< fragment")||aLine.startsWith("< feature")||aLine.startsWith("< base.plugin")){ 100 updatedMaps.add(new File(mapPath).getName()); 101 break; 102 } 103 } 104 105 } 106 } 107 } catch (IOException e) { 108 e.printStackTrace(); 109 } 110 } 111 112 private void sendNotice(){ 113 114 if (updatedMaps==null || updatedMaps.size()==0){ 115 throw new BuildException("Build cancelled - map files unchanged."); 116 } 117 118 Mailer mailer = new Mailer(); 119 120 String subject="updated map file listing"; 121 String message ="these map files have been updated for the build:\n\n"; 122 123 for (int i=0; i<updatedMaps.size();i++){ 124 message=message.concat(updatedMaps.elementAt(i).toString()+"\n"); 125 } 126 127 try { 128 mailer.sendMessage(subject,message); 129 } catch (NoClassDefFoundError e){ 130 System.out.println(message); 131 } 132 } 133 } 134