Thursday, November 3, 2011

Change set getter....

Tool for Fetching the files changed in an activity from clearcase.

/**
** Author : Yogesh Gandhi 
**/

package changeset;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;



public class myFrame extends JFrame {

    JLabel lblViewName  = new JLabel("View Name");
    JLabel lblActivityName  = new JLabel("Activity Name");
    JLabel lblDataVOB  = new JLabel("Datavob");
    JTextField  txtViewName = new JTextField("yogesh_bankmed_cod_payout", 30);
    JTextField  txtActivityName = new JTextField("P_1783_312227_LastPageIssue_InitiateCalculationScreen", 30);
    JTextField  txtDataVOB = new JTextField("pay_datavob", 30);
    JButton jbutton = new JButton("Get Change List");
 public myFrame(String title) {
        super(title);
        jbutton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                String filePath="C:\\temp.txt";
                String viewName = txtViewName.getText();
                String activityName = txtActivityName.getText();
                String datavob = txtDataVOB.getText();
                String command = "cleartool lsactivity -l " +
                                 viewName + "@\\" +
                                 datavob + " activity \"" +
                                 activityName+"\"";
                String steps[]= new String[3];
                steps[0]="cmd.exe";
                steps[1]="/C";
                steps[2]=command ;
                Process proc=null;
                Process proc2=null;
                try
                {
                    proc=Runtime.getRuntime().exec(steps, null, new File("M:\\"+viewName));//, envp);
                    InputStream stdin = proc.getInputStream();
                    InputStreamReader isr = new InputStreamReader(stdin);
                    BufferedReader br = new BufferedReader(isr);
                    String line = null;
                    StringBuffer bf = new StringBuffer("");
                    Set files = new HashSet();
                    while ( (line = br.readLine()) != null)
                    {
                        if(line.indexOf("@@")!=-1)
                        {
                            line = line.substring(0, line.indexOf("@@"));
                            files.add(line + "\r\n");
                        }
                        else
                        {
                            bf.append(line+"\r\n");
                        }
                    }
                    int exitVal = proc.waitFor();
                    if(proc!=null)
                    {
                        proc.exitValue();
                    }
                    write2File(bf.toString(), files, filePath);
                    proc2 = Runtime.getRuntime().exec("notepad.exe "+filePath);

                    System.out.println("Process exitValue: " + exitVal);

                }
                catch(Exception ee)
                {
                    if(proc!=null)
                    {
                        proc.destroy();
                    }
                    JOptionPane.showMessageDialog(null, ee.getMessage());
                    ee.printStackTrace();;
                }
                finally
                {
                    if(proc!=null)
                    {
                        proc.destroy();
                    }
                    System.exit(0);
                }

            }
        });

        getContentPane().setLayout(new FlowLayout());
  getContentPane().add(lblViewName);
        getContentPane().add(txtViewName);
        getContentPane().add(lblActivityName);
        getContentPane().add(txtActivityName);
        getContentPane().add(lblDataVOB);
        getContentPane().add(txtDataVOB);
        getContentPane().add(jbutton);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
  this.setSize(350, 300);
  setVisible(true);
 }

    private void write2File(String content, Set set, String filePath) throws Exception
    {
        FileWriter writer = new FileWriter(new File(filePath));
        writer.write(content);
        Iterator it = set.iterator();
        while(it.hasNext())
        {
            writer.write(it.next().toString());
        }
        writer.flush();
        writer.close();
    }
    /**
     *
     * @param args
     */
    public static void main(String[] args)
    {
  new myFrame("Developed by Yogesh Gandhi");
    }
}

No comments:

Post a Comment