Skip to content

Commit

Permalink
Generate table decorations showing removals
Browse files Browse the repository at this point in the history
Also show a decoration summary for each column header.
  • Loading branch information
merks committed Feb 18, 2024
1 parent f634d76 commit 78b4f81
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 42 deletions.
Expand Up @@ -24,6 +24,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
Expand All @@ -46,6 +47,16 @@
*/
public class UpdateSiteIndexGenerator
{
/**
* The decorator used for indicating a version update.
*/
public static final String UPDATED_DECORATOR = "\u2b06";

/**
* The decorator used for indicating a removed bundle.
*/
public static final String REMOVED_DECORATOR = "\u232b";

/**
* The ordered folders that will be indexed.
*/
Expand Down Expand Up @@ -1044,6 +1055,78 @@ public String getTableChildFolderName()
return folder.getParent().getFileName() + "/" + getFolderName();
}

/**
* Returns decorations to indicate what types of updates are available in this table column.
* @return decorations to indicate what types of updates are available in this table column.
*/
public String getTableChildFolderDecoration(UpdateSiteIndexGenerator tableParent)
{
List<UpdateSiteIndexGenerator> tableChildren = tableParent.getTableChildren();
int index = tableChildren.indexOf(this);
if (index + 1 == tableChildren.size())
{
return "";
}

boolean updated = false;
boolean removed = false;

LOOP: //
for (String bsn : tableParent.getTableBundles())
{
Map<String, Set<IInstallableUnit>> bsns = tableParent.table.get(this);
if (bsns != null)
{
Set<IInstallableUnit> olderVersions;
Map<String, Set<IInstallableUnit>> olderBSNs = tableParent.table.get(tableChildren.get(index + 1));
if (olderBSNs != null)
{
olderVersions = olderBSNs.get(bsn);
}
else
{
olderVersions = null;
}

Set<IInstallableUnit> versions = bsns.get(bsn);

if (!Objects.equals(versions, olderVersions))
{
if (versions == null)
{
removed = true;
}
else
{
updated = true;
}
}

if (removed && updated)
{
break LOOP;
}
}
}

if (updated || removed)
{
StringBuilder result = new StringBuilder();
result.append("&nbsp;");
if (updated)
{
result.append("<b>" + UPDATED_DECORATOR + "</b>");
}
if (removed)
{
result.append("<b>" + REMOVED_DECORATOR + "</b>");
}
return result.toString();
}

return "";
}

/**
* Returns the sites for which a summary column is generated in the table summary.
* @return the sites for which a summary column is generated in the table summary.
Expand Down Expand Up @@ -1127,7 +1210,14 @@ public String getVersions(String bsn, UpdateSiteIndexGenerator child)
}

Set<IInstallableUnit> versions = bsns.get(bsn);
if (versions != null)
if (versions == null)
{
if (olderVersions != null)
{
return "<b>" + REMOVED_DECORATOR + "</b>";
}
}
else
{
return versions.stream().map(it ->
{
Expand Down Expand Up @@ -1162,7 +1252,7 @@ else if (segment.length() >= 8)

if (olderVersions != null && !olderVersions.contains(it))
{
result.append("&nbsp;<b>\u2b06</b>");
result.append("&nbsp;<b>" + UPDATED_DECORATOR + "</b>");
}

MavenDescriptor descriptor = UpdateSiteGenerator.MavenDescriptor.create(it);
Expand Down
Expand Up @@ -11,6 +11,8 @@
package org.eclipse.justj.p2;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class UpdateSiteTable
{
Expand Down Expand Up @@ -43,24 +45,28 @@ public static synchronized UpdateSiteTable create(String lineSeparator)
protected final String TEXT_17 = "\" alt=\"\"/>" + NL + " <br/>";
protected final String TEXT_18 = NL + " <p>This is a tabular summary of the bundle versions available in the p2 update sites for ";
protected final String TEXT_19 = ".</p>";
protected final String TEXT_20 = NL + " <p>A version decorated with &#x2b06; indicates a version increase relative to the next/older column.</p>";
protected final String TEXT_21 = NL + " <p>Where applicable, each version is link to the Maven Central source.</p>";
protected final String TEXT_22 = NL + NL + " <table>" + NL;
protected final String TEXT_23 = NL + " <tr>" + NL + " <th>Bundle Symbolic Name</th>";
protected final String TEXT_24 = NL + " <th><a href=\"";
protected final String TEXT_25 = "</a></th>";
protected final String TEXT_26 = NL + " </tr>";
protected final String TEXT_27 = NL + " <tr>" + NL + " <td>";
protected final String TEXT_28 = "</td>";
protected final String TEXT_29 = NL + " <td>";
protected final String TEXT_30 = NL + " </table>";
protected final String TEXT_31 = NL + " </div>" + NL + " </div>" + NL + " </main>" + NL + " </body>" + NL + "</html>";
protected final String TEXT_20 = NL + " <p>A column header or version decorated with <b>";
protected final String TEXT_21 = "</b> indicates a version increase relative to the next/older column.</p>";
protected final String TEXT_22 = NL + " <p>A cell decorated with <b>";
protected final String TEXT_23 = "</b> indicates a removal relative to the next/older column.</p>";
protected final String TEXT_24 = NL + " <p>Where applicable, each version is link to the Maven Central source.</p>";
protected final String TEXT_25 = NL + NL + " <table>" + NL + "" + NL + " <tr>" + NL + " <th>Bundle Symbolic Name</th>";
protected final String TEXT_26 = NL + " <th><a href=\"";
protected final String TEXT_27 = "</a>";
protected final String TEXT_28 = "</th>";
protected final String TEXT_29 = NL + " </tr>";
protected final String TEXT_30 = NL + " <tr>" + NL + " <td>";
protected final String TEXT_31 = "</td>";
protected final String TEXT_32 = NL + " <td>";
protected final String TEXT_33 = NL + " </table>" + NL + " </div>" + NL + " </div>" + NL + " </main>" + NL + " </body>" + NL + "</html>";

public String generate(Object argument)
{
final StringBuffer stringBuffer = new StringBuffer();
UpdateSiteIndexGenerator parent = (UpdateSiteIndexGenerator)argument;
String title = parent.getTableTitle();
List<UpdateSiteIndexGenerator> tableChildren = parent.getTableChildren();
Map<UpdateSiteIndexGenerator, String> decorators = tableChildren.stream().collect(Collectors.toMap(Function.identity(), child -> child.getTableChildFolderDecoration(parent)));
stringBuffer.append(TEXT_1);
stringBuffer.append(title);
stringBuffer.append(TEXT_2);
Expand Down Expand Up @@ -103,37 +109,43 @@ public String generate(Object argument)
stringBuffer.append(parent.getProjectLabel());
stringBuffer.append(TEXT_19);
if (parent.getTableChildren().size() > 1) {
if (decorators.values().stream().anyMatch(decorator -> decorator.contains(UpdateSiteIndexGenerator.UPDATED_DECORATOR))) {
stringBuffer.append(TEXT_20);
}
if (parent.hasMavenDescriptors()) {
stringBuffer.append(UpdateSiteIndexGenerator.UPDATED_DECORATOR);
stringBuffer.append(TEXT_21);
}
if (decorators.values().stream().anyMatch(decorator -> decorator.contains(UpdateSiteIndexGenerator.REMOVED_DECORATOR))) {
stringBuffer.append(TEXT_22);
{
List<UpdateSiteIndexGenerator> tableChildren = parent.getTableChildren();
stringBuffer.append(UpdateSiteIndexGenerator.REMOVED_DECORATOR);
stringBuffer.append(TEXT_23);
for (UpdateSiteIndexGenerator tableChild : tableChildren) {
}
}
if (parent.hasMavenDescriptors()) {
stringBuffer.append(TEXT_24);
}
stringBuffer.append(TEXT_25);
for (UpdateSiteIndexGenerator tableChild : tableChildren) {
stringBuffer.append(TEXT_26);
stringBuffer.append(parent.getRelativeIndexURL(tableChild));
stringBuffer.append(TEXT_12);
stringBuffer.append(tableChild.getTableChildFolderName());
stringBuffer.append(TEXT_25);
stringBuffer.append(TEXT_27);
stringBuffer.append(decorators.get(tableChild));
stringBuffer.append(TEXT_28);
}
stringBuffer.append(TEXT_26);
stringBuffer.append(TEXT_29);
for (String bsn : parent.getTableBundles()) {
stringBuffer.append(TEXT_27);
stringBuffer.append(TEXT_30);
stringBuffer.append(parent.getShortBSN(bsn));
stringBuffer.append(TEXT_28);
stringBuffer.append(TEXT_31);
for (UpdateSiteIndexGenerator tableChild : tableChildren) {
stringBuffer.append(TEXT_29);
stringBuffer.append(TEXT_32);
stringBuffer.append(parent.getVersions(bsn, tableChild));
stringBuffer.append(TEXT_28);
}
stringBuffer.append(TEXT_26);
stringBuffer.append(TEXT_31);
}
stringBuffer.append(TEXT_30);
stringBuffer.append(TEXT_29);
}
stringBuffer.append(TEXT_31);
stringBuffer.append(TEXT_33);
return stringBuffer.toString();
}
}
30 changes: 17 additions & 13 deletions plugins/org.eclipse.justj.p2/templates/table.html.jet
Expand Up @@ -8,9 +8,11 @@ https://www.eclipse.org/legal/epl-2.0/

SPDX-License-Identifier: EPL-2.0
--%>
<%@jet package="org.eclipse.justj.p2" class="UpdateSiteTable" imports="java.util.*"%>
<%@jet package="org.eclipse.justj.p2" class="UpdateSiteTable" imports="java.util.* java.util.function.Function java.util.stream.Collectors"%>
<%UpdateSiteIndexGenerator parent = (UpdateSiteIndexGenerator)argument;
String title = parent.getTableTitle();%>
String title = parent.getTableTitle();
List<UpdateSiteIndexGenerator> tableChildren = parent.getTableChildren();
Map<UpdateSiteIndexGenerator, String> decorators = tableChildren.stream().collect(Collectors.toMap(Function.identity(), child -> child.getTableChildFolderDecoration(parent)));%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -103,32 +105,34 @@ SPDX-License-Identifier: EPL-2.0
<%}%>
<p>This is a tabular summary of the bundle versions available in the p2 update sites for <%=parent.getProjectLabel()%>.</p>
<%if (parent.getTableChildren().size() > 1) {%>
<p>A version decorated with &#x2b06; indicates a version increase relative to the next/older column.</p>
<%if (decorators.values().stream().anyMatch(decorator -> decorator.contains(UpdateSiteIndexGenerator.UPDATED_DECORATOR))) {%>
<p>A column header or version decorated with <b><%=UpdateSiteIndexGenerator.UPDATED_DECORATOR%></b> indicates a version increase relative to the next/older column.</p>
<%}%>
<%if (decorators.values().stream().anyMatch(decorator -> decorator.contains(UpdateSiteIndexGenerator.REMOVED_DECORATOR))) {%>
<p>A cell decorated with <b><%=UpdateSiteIndexGenerator.REMOVED_DECORATOR%></b> indicates a removal relative to the next/older column.</p>
<%}%>
<%}%>
<%if (parent.hasMavenDescriptors()) {%>
<p>Where applicable, each version is link to the Maven Central source.</p>
<%}%>

<table>

<%{
List<UpdateSiteIndexGenerator> tableChildren = parent.getTableChildren();%>
<tr>
<th>Bundle Symbolic Name</th>
<%for (UpdateSiteIndexGenerator tableChild : tableChildren) {%>
<th><a href="<%=parent.getRelativeIndexURL(tableChild)%>"><%=tableChild.getTableChildFolderName()%></a></th>
<%}%>
<%for (UpdateSiteIndexGenerator tableChild : tableChildren) {%>
<th><a href="<%=parent.getRelativeIndexURL(tableChild)%>"><%=tableChild.getTableChildFolderName()%></a><%=decorators.get(tableChild)%></th>
<%}%>
</tr>
<%for (String bsn : parent.getTableBundles()) {%>
<%for (String bsn : parent.getTableBundles()) {%>
<tr>
<td><%=parent.getShortBSN(bsn)%></td>
<%for (UpdateSiteIndexGenerator tableChild : tableChildren) {%>
<%for (UpdateSiteIndexGenerator tableChild : tableChildren) {%>
<td><%=parent.getVersions(bsn, tableChild)%></td>
<%}%>
</tr>
<%}%>
</table>
</tr>
<%}%>
</table>
</div>
</div>
</main>
Expand Down

0 comments on commit 78b4f81

Please sign in to comment.