Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/jdiff/APIDiff.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jdiff;

import java.util.*;
import com.sun.javadoc.*;

/**
* The class contains the changes between two API objects; packages added,
Expand Down
1 change: 0 additions & 1 deletion src/jdiff/ClassDiff.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jdiff;

import java.util.*;
import com.sun.javadoc.*;

/**
* The changes between two classes.
Expand Down
156 changes: 103 additions & 53 deletions src/jdiff/JDiff.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,77 @@
package jdiff;

import com.sun.javadoc.*;

import java.util.*;
import java.io.*;
import java.lang.reflect.*; // Used for invoking Javadoc indirectly
import java.lang.Runtime;
import java.lang.Process;

import jdk.javadoc.doclet.Doclet;
import jdk.javadoc.doclet.DocletEnvironment;
import jdk.javadoc.doclet.Reporter;

import javax.lang.model.SourceVersion;

/**
* Generates HTML describing the changes between two sets of Java source code.
*
* See the file LICENSE.txt for copyright details.
* @author Matthew Doar, [email protected].
*/
public class JDiff extends Doclet {
public class JDiff implements Doclet {

private Reporter reporter;
private Locale locale;

public enum LanguageVersion {
JAVA_1_5
}

public static LanguageVersion languageVersion(){
return LanguageVersion.JAVA_1_5;
}
}

@Override
public void init(Locale locale, Reporter reporter) {
this.locale = locale;
this.reporter = reporter;
Options.reset();
Options.setReporter(reporter);
}

@Override
public String getName() {
return "JDiff";
}

@Override
public Set<Doclet.Option> getSupportedOptions() {
return new LinkedHashSet<Doclet.Option>(Options.getSupportedOptions());
}

@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}

@Override
public boolean run(DocletEnvironment environment) {
if (!Options.processPendingOptions(reporter)) {
return false;
}
if (environment != null) {
System.out.println("JDiff: doclet started ...");
}
return startGeneration(environment);
}

/**
* Doclet-mandated start method. Everything begins here.
*
* @param root a RootDoc object passed by Javadoc
* @return true if document generation succeeds
*/
public static boolean start(RootDoc root) {
public static boolean start(DocletEnvironment root) {
if (root != null)
System.out.println("JDiff: doclet started ...");
JDiff jd = new JDiff();
Expand All @@ -35,27 +81,31 @@ public static boolean start(RootDoc root) {
/**
* Generate the summary of the APIs.
*
* @param root the RootDoc object passed by Javadoc
* @param root the DocletEnvironment object passed by Javadoc
* @return true if no problems encountered within JDiff
*/
protected boolean startGeneration(RootDoc newRoot) {
protected boolean startGeneration(DocletEnvironment root) {
long startTime = System.currentTimeMillis();

// Open the file where the XML representing the API will be stored.
// and generate the XML for the API into it.
if (writeXML) {
RootDocToXML.writeXML(newRoot);
if (root == null) {
System.out.println("Error: no DocletEnvironment available for XML generation");
return false;
}
RootDocToXML.writeXML(root);
}

if (compareAPIs) {
String tempOldFileName = oldFileName;
if (oldDirectory != null) {
tempOldFileName = oldDirectory;
if (!tempOldFileName.endsWith(JDiff.DIR_SEP)) {
tempOldFileName += JDiff.DIR_SEP;
}
tempOldFileName += oldFileName;
}
String tempOldFileName = oldFileName;
if (oldDirectory != null) {
tempOldFileName = oldDirectory;
if (!tempOldFileName.endsWith(JDiff.DIR_SEP)) {
tempOldFileName += JDiff.DIR_SEP;
}
tempOldFileName += oldFileName;
}

// Check the file for the old API exists
File f = new File(tempOldFileName);
Expand All @@ -65,13 +115,13 @@ protected boolean startGeneration(RootDoc newRoot) {
}
// Check the file for the new API exists

String tempNewFileName = newFileName;
String tempNewFileName = newFileName;
if (newDirectory != null) {
tempNewFileName = newDirectory;
if (!tempNewFileName.endsWith(JDiff.DIR_SEP)) {
tempNewFileName += JDiff.DIR_SEP;
}
tempNewFileName += newFileName;
tempNewFileName = newDirectory;
if (!tempNewFileName.endsWith(JDiff.DIR_SEP)) {
tempNewFileName += JDiff.DIR_SEP;
}
tempNewFileName += newFileName;
}
f = new File(tempNewFileName);
if (!f.exists()) {
Expand All @@ -84,20 +134,20 @@ protected boolean startGeneration(RootDoc newRoot) {
System.out.print("JDiff: reading the old API in from file '" + tempOldFileName + "'...");
// Read the file in, but do not add any text to the global comments
API oldAPI = XMLToAPI.readFile(tempOldFileName, false, oldFileName);

// Read the file where the XML representing the new API is stored
// and create an API object for it.
System.out.print("JDiff: reading the new API in from file '" + tempNewFileName + "'...");
// Read the file in, and do add any text to the global comments
API newAPI = XMLToAPI.readFile(tempNewFileName, true, newFileName);

// Compare the old and new APIs.
APIComparator comp = new APIComparator();

comp.compareAPIs(oldAPI, newAPI);

// Read the file where the XML for comments about the changes between
// the old API and new API is stored and create a Comments object for
// the old API and new API is stored and create a Comments object for
// it. The Comments object may be null if no file exists.
int suffix = oldFileName.lastIndexOf('.');
String commentsFileName = "user_comments_for_" + oldFileName.substring(0, suffix);
Expand All @@ -110,16 +160,16 @@ protected boolean startGeneration(RootDoc newRoot) {
Comments existingComments = Comments.readFile(commentsFileName);
if (existingComments == null)
System.out.println(" (the comments file will be created)");

// Generate an HTML report which summarises all the API differences.
HTMLReportGenerator reporter = new HTMLReportGenerator();
reporter.generate(comp, existingComments);

// Emit messages about which comments are now unused and
// which are new.
Comments newComments = reporter.getNewComments();
Comments.noteDifferences(existingComments, newComments);

// Write the new comments out to the same file, with unused comments
// now commented out.
System.out.println("JDiff: writing the comments out to file '" + commentsFileName + "'...");
Expand All @@ -128,15 +178,15 @@ protected boolean startGeneration(RootDoc newRoot) {

System.out.print("JDiff: finished (took " + (System.currentTimeMillis() - startTime)/1000 + "s");
if (writeXML)
System.out.println(", not including scanning the source files).");
System.out.println(", not including scanning the source files).");
else if (compareAPIs)
System.out.println(").");
return true;
}

//
// Option processing
//
//

/**
* This method is called by Javadoc to
Expand All @@ -155,18 +205,18 @@ public static int optionLength(String option) {
* Javadoc invokes this method with an array of options-arrays.
*
* @param options an array of String arrays, one per option
* @param reporter a DocErrorReporter for generating error messages
* @param reporter a Reporter for generating error messages
* @return true if no errors were found, and all options are
* valid
*/
public static boolean validOptions(String[][] options,
DocErrorReporter reporter) {
public static boolean validOptions(String[][] options,
Reporter reporter) {
return Options.validOptions(options, reporter);
}
/**

/**
* This method is only called when running JDiff as a standalone
* application, and uses ANT to execute the build configuration in the
* application, and uses ANT to execute the build configuration in the
* XML configuration file passed in.
*/
public static void main(String[] args) {
Expand All @@ -187,16 +237,16 @@ public static void main(String[] args) {
return;
}

/**
/**
* Display usage information for JDiff.
*/
public static void showUsage() {
System.out.println("usage: java jdiff.JDiff [-version] [-buildfile <XML configuration file>]");
System.out.println("If no build file is specified, the local build.xml file is used.");
}

/**
* Invoke ANT by reflection.
/**
* Invoke ANT by reflection.
*
* @return The integer return code from running ANT.
*/
Expand Down Expand Up @@ -237,27 +287,27 @@ public static int runAnt(String[] args) {
return -1;
}

/**
/**
* The name of the file where the XML representing the old API is
* stored.
* stored.
*/
static String oldFileName = "old_java.xml";

/**
/**
* The name of the directory where the XML representing the old API is
* stored.
* stored.
*/
static String oldDirectory = null;

/**
* The name of the file where the XML representing the new API is
* stored.
/**
* The name of the file where the XML representing the new API is
* stored.
*/
static String newFileName = "new_java.xml";

/**
* The name of the directory where the XML representing the new API is
* stored.
/**
* The name of the directory where the XML representing the new API is
* stored.
*/
static String newDirectory = null;

Expand All @@ -267,8 +317,8 @@ public static int runAnt(String[] args) {
/** If set, then read in two XML files and compare their APIs. */
static boolean compareAPIs = false;

/**
* The file separator for the local filesystem, forward or backward slash.
/**
* The file separator for the local filesystem, forward or backward slash.
*/
static String DIR_SEP = System.getProperty("file.separator");

Expand Down
1 change: 0 additions & 1 deletion src/jdiff/MemberDiff.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jdiff;

import java.util.*;
import com.sun.javadoc.*;

/**
* The changes between two class constructor, method or field members.
Expand Down
Loading