0

I am trying to find out which variables, methods & objects got changed between 2 revisions of a file.

Is it possible to find this out in SVN or using SVNKit by writing a Java Program?

Eg: File1.java

public class File1 {
    String name;
    float rating;
    String teacher;
    int numofstudents;

    public int fees(){
      numofstudents = 26;
      return 500*1.18;
    }
    if (rating < 5){
      int a = numofstudents;
    }
}

File2.java

public class File1 {
String name;
float rating;
String teacher;
int numofstudents;
float marks;

public int fees(){
    numofstudents = 25;
    return 500*1.18;
}

if (rating < 4){
    int a = rating;
}
}

The expected output should be :

"The following values have changed: Variables - numofstudents, a; Methods - fees;

"

By writing normal Java Program, I could print out the differences between the 2 files, but I am unable to print out my expected output

Anamik Adhikary
  • 401
  • 1
  • 8
  • 27
  • why would you need an application for that? any svn plugin comes with a 'compare' functionality – Stultuske Jan 24 '18 at 09:57
  • I couldn't find the output I am expecting from any SVN Plugin. Using the 'compare' functionality I could find the line differences, like which all lines had been added, deleted or modified. I was hoping if I could extract the changed variables from the output to show which variables had changed. – Anamik Adhikary Jan 24 '18 at 10:04
  • what do youmean: "the changed variables"? that is a line of changed code, so it's in the list you automatically get. Just check on what line it is in your local code and scroll to that – Stultuske Jan 24 '18 at 10:08
  • @Stultuske.. I am trying to build a small application that will show the list of all the variables, methods or objects that has been modified between 2 revisions and in which files it has been modified. I am looking to create a table, on which one axis will have the list of the methods, variables and the other axis where all the files will be listed. I am not sure if I am able to express myself clearly. – Anamik Adhikary Jan 24 '18 at 10:16
  • it seems to me you want to keep a "technical log" of changes in the "business logic" ... what good would that do? for documentation? that would imply you would implement logic that isn't documented yet? – Stultuske Jan 24 '18 at 10:19
  • "that would imply you would implement logic that isn't documented yet" - I guess so, as I couldn't find how to do this stuff anywhere online in the last one week. "what good would that do?" - the testing team in my workplace needs it for a faster testing, so that they know exactly where to focus more, to prioritize. – Anamik Adhikary Jan 24 '18 at 10:25
  • actually, you shouldn't. the entire description should be documented in the analysis, otherwise you can go and code anything you want without even knowing whether or not it is what you need. That analysis (including the documentation) you give to your testing team. After all: you could hand them a list with "this has changed", but firstly: your testteam should not be aware of technical issues, secondly: because it "has changed", doesn't mean it "should have changed". – Stultuske Jan 24 '18 at 10:45

1 Answers1

0

I am also working on this area. I am doing this because I need to automate the build process in my project.

you can do this either by svnkit library of java or via calling a command line window from java programme and then run svn command in opened cmd process to determine the difference (provided you are working on windows os...ofcourse).

SVNKIT APPROACH -- I am not able to get the whole working code of getting the difference by svnkit, but i got that below code should be able to get me the difference -

repository.diff(repository.getLocation(), 23180l, 23182l, null, false, SVNDepth.INFINITY, false, null, null);

SVNKit documentation is not that great. I am still searching for working examples.

CALLING SVN COMMAND USING CMD FROM JAVA PROGRAMME APPROACH --

This is working for me. But you must be running this on windows machine where tortoise svn is installed and configured with working user credentials. It is needed because svn command will internally use the saved user credentials while connecting to svn repo.

Below is the command to determine the difference between two revisions (if your file is having changes between provided revisions then this command will show the differences of the file) --

svn diff -r <fromRevisionNo>:<toRevisionNo> <Path of svn branch>

And you can call this command via java programme using below code --

String cmd = "svn diff -r <fromRevisionNo>:<toRevisionNo> <Path of svn branch>";
    Runtime run = Runtime.getRuntime();
    Process pr = run.exec(cmd);
    pr.waitFor();
    BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
    String line = "";
    while ((line=buf.readLine())!=null) {
    System.out.println(line);

With above code we are opening a cmd window from java program and then running the svn command from that.