diff.jsp revision 17b343cecb69da82215b124f39fed80167a6f2bd
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinCDDL HEADER START
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinThe contents of this file are subject to the terms of the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinCommon Development and Distribution License (the "License").
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinYou may not use this file except in compliance with the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinSee LICENSE.txt included in this distribution for the specific
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinlanguage governing permissions and limitations under the License.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinWhen distributing Covered Code, include this CDDL HEADER in each
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfile and include the License file at LICENSE.txt.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinIf applicable, add the following below this CDDL HEADER, with the
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfields enclosed by brackets "[]" replaced with your own identifying
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chininformation: Portions Copyright [yyyy] [name of copyright owner]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinCDDL HEADER END
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinCopyright 2009 Sun Microsystems, Inc. All rights reserved.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinUse is subject to license terms.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinident "@(#)diff.jsp 1.2 05/12/01 SMI"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin--%><%@ page import = "javax.servlet.*,
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin%><%@include file="mast.jsp"%><%!
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinString readableLine(int n) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (n < 10) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return " " + n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif (valid) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin final String rp1 = request.getParameter("r1");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin final String rp2 = request.getParameter("r2");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String srcRoot = environment.getSourceRootFile().getAbsolutePath();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String r1 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String r2 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin File rpath1 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin File rpath2 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String[] tmp=null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (rp1!=null) tmp = rp1.split("@");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp != null && tmp.length == 2) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin rpath1 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r1 = URLDecoder.decode(tmp[1], "UTF-8");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } catch (UnsupportedEncodingException e) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (rp2!=null) tmp = rp2.split("@");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp != null && tmp.length == 2) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (tmp != null && tmp.length == 2) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin rpath2 = new File(srcRoot+URLDecoder.decode(tmp[0], "UTF-8"));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin r2 = URLDecoder.decode(tmp[1], "UTF-8");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } catch (UnsupportedEncodingException e) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (r1 == null || r2 == null || r1.equals("") || r2.equals("") || r1.equals(r2)) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin%><div class="src"><h3 class="error">Error:</h3>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Please pick two revisions to compare the changed from the <a href="<%=context+Constants.histL+path%>">history</a>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin// Error message ask to choose two versions from History log page with link to it
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Genre g = AnalyzerGuru.getGenre(basename);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (g == Genre.PLAIN || g == null || g == Genre.DATA || g == Genre.HTML) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin InputStream in1 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin InputStream in2 = null;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin in1 = HistoryGuru.getInstance().getRevision(rpath1.getParent(), rpath1.getName(), r1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin in2 = HistoryGuru.getInstance().getRevision(rpath2.getParent(), rpath2.getName(), r2);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin } catch (Exception e) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %> <h3 class="error">Error opening revisions!</h3> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (in1 != null && in2 != null) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (g == null) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %> <div id="difftable">
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin <tr><td><img src="<%=context+Constants.rawP+path%>?r=<%=r1%>"/></td><td><img src="<%=context+Constants.rawP+path%>?r=<%=r2%>"/></td></tr></table></div><%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin//--------Do THE DIFFS------------
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ArrayList<String> l1 = new ArrayList<String>();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String line;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin BufferedReader reader1 = new BufferedReader(new InputStreamReader(in1));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin BufferedReader reader2 = new BufferedReader(new InputStreamReader(in2));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while ((line = reader1.readLine()) != null) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin ArrayList<String> l2 = new ArrayList<String>();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while ((line = reader2.readLine()) != null) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Object[] file1 = l1.toArray();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Object[] file2 = l2.toArray();
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin Revision rev = Diff.diff(file1, file2);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(rev.size() == 0) {
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><b>No differences found!</b><%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int ln1 = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin int ln2 = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String format = request.getParameter("format");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(format == null || (!format.equals("o") && !format.equals("n") && !format.equals("u") && !format.equals("t")))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin format = "s";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin String pfull = request.getParameter("full");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin boolean full = pfull != null && pfull.equals("1");
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin pfull = full ? "1" : "0";
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin%><div id="difftable"><div id="diffbar"><span class="tabsel"> <span class="d"> Deleted </span> <span class="a"> Added </span> </span> | <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tabsel"><b>sdiff</b></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=s&full=<%=pfull%>">sdiff</a></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tabsel"><b>udiff</b></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=u&full=<%=pfull%>">udiff</a></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tabsel"><b>text</b></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=t&full=<%=pfull%>">text</a></span> <%
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin %><span class="tabsel"><b>old (<%=r1%>)</b></span> <%
%><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=o&full=<%=pfull%>">old (<%=r1%>)</a></span> <%
if(format.equals("n")) {
%><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=n&full=<%=pfull%>">new (<%=r2%>)</a></span> | <%
%><span class="tab"><a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1"> full </a></span> <span class="tabsel"><b>compact</b></span><%
%><span class="tabsel"><b> full </b> </span> <span class="tab"> <a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=0">compact</a></span><%
if(format.equals("s")) {
for (int i=0; i < rev.size(); i++) {
Delta d = rev.getDelta(i);
if(format.equals("t")) {
Chunk c1 = d.getOriginal();
Chunk c2 = d.getRevised();
int cn1 = c1.first();
int cl1 = c1.last();
int cn2 = c2.first();
int cl2 = c2.last();
file1[h] = Util.htmlize((String)file1[h]);
file2[h] = Util.htmlize((String)file2[h]);
if (format.equals("u")) {
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
} else if(format.equals("s")) {
%><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><br/>--- <b><%=cn1 - ln1 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
%><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
} else if ( format.equals("o")) {
%><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><br/>--- <b><%=cn1 - ln1 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln1%>">view full</a>) --- <br/><br/><%
%><i><%=readableLine(++ln1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
} else if ( format.equals("n")) {
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=readableLine(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/>--- <b><%=cn2 - ln2 - 16%> unchanged lines hidden</b> (<a href="<%=reqURI%>?r1=<%=rp1%>&r2=<%=rp2%>&format=<%=format%>&full=1#<%=ln2%>">view full</a>) --- <br/><br/><%
%><i><%=readableLine(++ln2)%></i><%=Util.htmlize((String)file2[j])%><br/><%
if (file1.length >= ln1) {
if (format.equals("s")) {
if (full || file1.length - ln1 < 20) {
for (int j = ln1; j < file1.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> --- </td><td><%
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/>--- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
} else if (format.equals("u")) {
if (full || file2.length - ln2 < 20) {
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/>--- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---</td></tr></table><%
} else if (format.equals("o")) {
if (full || file1.length - ln1 < 20) {
for (int j = ln1; j < file1.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><i><%=(j+1)%></i><%=Util.htmlize((String)file1[j])%><br/><%
%><br/> --- <b><%=file1.length - ln1 - 8%> unchanged lines hidden</b> ---<br/><%
} else if (format.equals("n")) {
if (full || file2.length - ln2 < 20) {
for (int j = ln2; j < file2.length ; j++) {
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><i><%=(j+1)%></i><%=Util.htmlize((String)file2[j])%><br/><%
%><br/> --- <b><%=file2.length - ln2 - 8%> unchanged lines hidden</b> ---<br/><%
%> <div id="src">Diffs for binary files cannot be displayed! Files are <a href="<%=context+Constants.rawP+path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
<a href="<%=context+Constants.rawP+path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
%><div class="src"><h3 class="error">Error Opening files! <%=Util.htmlize(e.getMessage())%></h3></div><%
in1.close();
in2.close();
} else if (g == Genre.IMAGE) {
<table rules="cols" cellpadding="5"><tr><th><%=basename%> (revision <%=r1%>)</th><th><%=basename%> (revision <%=r2%>)</th></tr>
<tr><td><img src="<%=context+Constants.rawP+path%>?r=<%=r1%>"/></td><td><img src="<%=context+Constants.rawP+path%>?r=<%=r2%>"/></td></tr></table></div><%
%> <div class="src">Diffs for binary files cannot be displayed. Files are <a href="<%=context+Constants.rawP+path%>?r=<%=r1%>"><%=basename%>(revision <%=r1%>)</a> and
<a href="<%=context+Constants.rawP+path%>?r=<%=r2%>"><%=basename%>(revision <%=r2%>)</a>.
%><%@include file="foot.jspf"%><%