<%-- CDDL HEADER START The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. See LICENSE.txt included in this distribution for the specific language governing permissions and limitations under the License. When distributing Covered Code, include this CDDL HEADER in each file and include the License file at LICENSE.txt. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] CDDL HEADER END Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved. Portions Copyright 2011 Jens Elkner. Portions Copyright (c) 2020, Chris Fraire . --%> <%@page errorPage="error.jsp" import=" java.io.ByteArrayInputStream, java.io.OutputStream, java.io.InputStream, java.nio.charset.StandardCharsets, org.suigeneris.jrcs.diff.delta.Chunk, org.suigeneris.jrcs.diff.delta.Delta, org.opengrok.indexer.analysis.AbstractAnalyzer, org.opengrok.web.DiffData, org.opengrok.web.DiffType" %> <%! private String getAnnotateRevision(DiffData data) { if (data.getType() == DiffType.OLD || data.getType() == DiffType.NEW) { String rev = data.getRev(data.getType() == DiffType.NEW ? 1 : 0); return ""; } return ""; } %> <% { PageConfig cfg = PageConfig.get(request); cfg.addScript("diff"); cfg.checkSourceRootExistence(); /** * This block must be the first block before any other output in the * response. * * If there is already any output written into the response, and we * use the same response and reset the content and the headers then we have * a collision with the response streams and the "getOutputStream() has * already been called" exception occurs. */ DiffData data = cfg.getDiffData(); request.setAttribute("diff.jsp-data", data); if (data.getType() == DiffType.TEXT && request.getParameter("action") != null && request.getParameter("action").equals("download")) { try (OutputStream o = response.getOutputStream()) { for (int i = 0; i < data.getRevision().size(); i++) { Delta d = data.getRevision().getDelta(i); try (InputStream in = new ByteArrayInputStream(d.toString().getBytes(StandardCharsets.UTF_8))) { response.setHeader("content-disposition", "attachment; filename=" + cfg.getResourceFile().getName() + "@" + data.getRev(0) + "-" + data.getRev(1) + ".diff"); byte[] buffer = new byte[8192]; int nr; while ((nr = in.read(buffer)) > 0) { o.write(buffer, 0, nr); } } } o.flush(); o.close(); return; } } } %><%@ include file="mast.jsp" %><% /* ---------------------- diff.jsp start --------------------- */ { PageConfig cfg = PageConfig.get(request); DiffData data = (DiffData) request.getAttribute("diff.jsp-data"); // the data is never null as the getDiffData always return valid object if (data.getErrorMsg() != null) { %>

Error:

<%= data.getErrorMsg() %>

<% } else if (data.getGenre() == AbstractAnalyzer.Genre.IMAGE) { String link = request.getContextPath() + Prefix.DOWNLOAD_P + Util.htmlize(cfg.getPath()); %>
<%= data.getFilename() %> (revision <%= data.getRev(0) %>) <%= data.getFilename() %> (revision <%= data.getRev(1) %>)
previous image new image
<% } else if (data.getGenre() != AbstractAnalyzer.Genre.PLAIN && data.getGenre() != AbstractAnalyzer.Genre.HTML) { String link = request.getContextPath() + Prefix.DOWNLOAD_P + Util.htmlize(cfg.getPath()); %>
Diffs for binary files cannot be displayed! Files are <%= data.getFilename() %>(revision <%= data.getRev(0) %>) and <%= data.getFilename() %>(revision <%= data.getRev(1) %>).
<% } else if (data.getRevision().size() == 0) { %> <%= getAnnotateRevision(data) %> No differences found!<% } else { //-------- Do THE DIFFS ------------ int ln1 = 0; int ln2 = 0; String rp1 = data.getParam(0); String rp2 = data.getParam(1); String reqURI = request.getRequestURI(); String[] file1 = data.getFile(0); String[] file2 = data.getFile(1); DiffType type = data.getType(); boolean full = data.isFull(); %> <%= getAnnotateRevision(data) %>
Deleted Added
<% for (DiffType t : DiffType.values()) { if (type == t) { %> <%= t.toString() %><% if (t == DiffType.OLD) { %> ( <%= data.getRev(0) %> )<% } else if (t == DiffType.NEW) { %> ( <%= data.getRev(1) %> )<% } %><% } else { %> <%= t.toString() %> <% if (t == DiffType.OLD) { %> ( <%= data.getRev(0) %> )<% } else if (t == DiffType.NEW) { %> ( <%= data.getRev(1) %> )<% } %><% } } %>
<% if (!full) { %> full compact<% } else { %> full compact<% } %>jumper download diff<% %>
<% if (type == DiffType.SIDEBYSIDE || type == DiffType.UNIFIED) { %><% if (type == DiffType.SIDEBYSIDE) { %> <% } %> <% } for (int i=0; i < data.getRevision().size(); i++) { Delta d = data.getRevision().getDelta(i); if (type == DiffType.TEXT) { %><%= Util.htmlize(d.toString()) %><% } else { Chunk c1 = d.getOriginal(); Chunk c2 = d.getRevised(); int cn1 = c1.first(); int cl1 = c1.last(); int cn2 = c2.first(); int cl2 = c2.last(); int i1 = cn1, i2 = cn2; StringBuilder bl1 = new StringBuilder(80); StringBuilder bl2 = new StringBuilder(80); for (; i1 <= cl1 && i2 <= cl2; i1++, i2++) { String[] ss = Util.diffline( new StringBuilder(file1[i1]), new StringBuilder(file2[i2])); file1[i1] = ss[0]; file2[i2] = ss[1]; } // deleted for (; i1 <= cl1; i1++) { bl1.setLength(0); bl1.append(""); Util.htmlize(file1[i1], bl1); file1[i1] = bl1.append("").toString(); } // added for (; i2 <= cl2; i2++) { bl2.setLength(0); bl2.append(""); Util.htmlize(file2[i2], bl2); file2[i2] = bl2.append("").toString(); } if (type == DiffType.UNIFIED) { // UDIFF if (cn1 > ln1 || cn2 > ln2) { %> <% ln1 = cn1; } if (cn1 <= cl1) { %> <% } if (cn2 <= cl2) { %> <% } } else if (type == DiffType.SIDEBYSIDE) { // SDIFF if (cn1 > ln1 || cn2 > ln2) { %> <% } %> <% // OLD } else if (type == DiffType.OLD) { // OLD if (cn1 > ln1) { if (full || cn1 - ln1 < 20) { for (int j = ln1; j < cn1; j++) { %><%= ++ln1 %><%= Util.htmlize(file1[j]) %>
<% } } else { for (int j = ln1; j < ln1 + 8; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } %>
--- <%= cn1 - ln1 - 16 %> unchanged lines hidden (view full) ---

<% ln1 = cn1 - 8; for (int j = ln1; j < cn1; j++) { %><%= ++ln1 %><%= Util.htmlize(file1[j]) %>
<% } } } for (int j = cn1; j <= cl1 ; j++) { %><%= ++ln1 %><%= file1[j] %>
<% } if (full) { %><% } // NEW } else if (type == DiffType.NEW) { if (cn2 > ln2) { if (full || cn2 - ln2 < 20) { for (int j = ln2; j < cn2 ; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } else { for (int j = ln2; j < ln2 + 8; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= cn2 - ln2 - 16 %> unchanged lines hidden (view full) ---

<% ln2 = cn2 - 8; for (int j = ln2; j < cn2; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } } for (int j = cn2; j <= cl2 ; j++) { %><%= ++ln2 %><%= file2[j] %>
<% } if (full) { %><% } } } // else } // for // deltas done, dump the remaining if (file1.length >= ln1) { if (type == DiffType.SIDEBYSIDE) { if (full || file1.length - ln1 < 20) { %>
<%= data.getFilename() %> (<%= data.getRev(0) %>) <%= data.getFilename() %> (<%= data.getRev(1) %>)
<% if (full || (cn2 - ln2 < 20)) { for (int j = ln2; j < cn2; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } else { for (int j = ln2; j < ln2 + 8; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= cn2 - ln2 - 16 %> unchanged lines hidden (view full) ---

<% ln2 = cn2 - 8; for (int j = ln2; j < cn2; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } %>
<% for (int j = cn1; j <= cl1 ; j++) { %><%= ++ln1 %><%= file1[j] %>
<% } %>
<% for (int j = cn2; j < cl2; j++) { %><%= ++ln2 %><%= file2[j] %>
<% } %><%= ++ln2 %><%= file2[cl2] %><% if(full) { %><% } %>
<% if (full || cn2 - ln2 < 20) { for (int j = ln1; j < cn1; j++) { %><%= ++ln1 %><%= Util.htmlize(file1[j]) %>
<% } %>
<% for (int j = ln2; j < cn2 ; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } else { for (int j = ln1; j < ln1 + 8; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } %>
--- <%= cn1 - ln1 - 16 %> unchanged lines hidden (view full) ---

<% ln1 = cn1 - 8; for (int j = ln1; j < cn1; j++) { %><%= ++ln1 %><%= Util.htmlize(file1[j]) %>
<% } %>
<% for (int j = ln2; j < ln2 + 8; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= cn2 - ln2 - 16 %> unchanged lines hidden (view full) ---

<% ln2 = cn2 - 8; for (int j = ln2; j < cn2; j++) { %><%= ++ln2 %><%= Util.htmlize(file2[j]) %>
<% } } %>
<% for (int j = cn1; j <= cl1; j++) { %><%= ++ln1 %><%= file1[j] %>
<% } %>
<% for (int j = cn2; j <= cl2; j++) { %><%= ++ln2 %><%= file2[j] %>
<% } %>
<% for (int j = ln1; j < file1.length ; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } %>
<% for (int j = ln2; j < file2.length ; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
<% } else { %> <% for (int j = ln1; j < ln1 + 8 ; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } %>
--- <%= file1.length - ln1 - 8 %> unchanged lines hidden --- <% for (int j = ln2; j < ln2 + 8 ; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= file1.length - ln1 - 8 %> unchanged lines hidden --- <% } } else if (type == DiffType.UNIFIED) { if (full || file2.length - ln2 < 20) { %> <% for (int j = ln2; j < file2.length ; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %> <% } else { %> <% for (int j = ln2; j < ln2 + 8 ; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= file2.length - ln2 - 8 %> unchanged lines hidden --- <% } } else if (type == DiffType.OLD) { if (full || file1.length - ln1 < 20) { for (int j = ln1; j < file1.length ; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } } else { for (int j = ln1; j < ln1 + 8 ; j++) { %><%= j+1 %><%= Util.htmlize(file1[j]) %>
<% } %>
--- <%= file1.length - ln1 - 8 %> unchanged lines hidden ---
<% } } else if (type == DiffType.NEW) { if (full || file2.length - ln2 < 20) { for (int j = ln2; j < file2.length ; j++) { %><%= j+1 %><%=Util.htmlize(file2[j])%>
<% } } else { for (int j = ln2; j < ln2 + 8 ; j++) { %><%= j+1 %><%= Util.htmlize(file2[j]) %>
<% } %>
--- <%= file2.length - ln2 - 8 %> unchanged lines hidden ---
<% } } } //----DIFFS Done-------- %>
<% } } /* ---------------------- diff.jsp end --------------------- */ %><%@ include file="foot.jspf" %>