Skip to content

Commit

Permalink
opengrok web project code smell fixes (#4457)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Gino Augustine <[email protected]>
  • Loading branch information
ginoaugustine authored Oct 26, 2023
1 parent 781cced commit 2f0c0f8
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 177 deletions.
13 changes: 8 additions & 5 deletions opengrok-web/src/main/java/org/opengrok/web/Scripts.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import java.util.List;
import java.util.Map;
import java.util.NavigableSet;
import java.util.Optional;
import java.util.TreeMap;
import java.util.TreeSet;

import org.jetbrains.annotations.NotNull;
import org.webjars.WebJarAssetLocator;

/**
Expand Down Expand Up @@ -116,9 +118,9 @@ public String toHtml() {
putFromWebJar("jquery", "3.6.4/jquery.min.js", 10);
putjs("jquery-ui", "js/jquery-ui-1.12.1-custom", 11);
putFromWebJar("jquery-tablesorter", "2.31.3/dist/js/jquery.tablesorter.min.js", 12);
putjs("tablesorter-parsers", "js/tablesorter-parsers-0.0.3", 13, true);
putjs("searchable-option-list", "js/searchable-option-list-2.0.15", 14, true);
putjs("utils", "js/utils-0.0.46", 15, true);
putjs("tablesorter-parsers", "js/tablesorter-parsers-0.0.4", 13, true);
putjs("searchable-option-list", "js/searchable-option-list-2.0.16", 14, true);
putjs("utils", "js/utils-0.0.47", 15, true);
putjs("repos", "js/repos-0.0.3", 20, true);
putjs("diff", "js/diff-0.0.5", 20, true);
putjs("jquery-caret", "js/jquery.caret-1.5.2", 25);
Expand Down Expand Up @@ -203,7 +205,7 @@ public boolean isEmpty() {
* @see List#iterator()
*/
@Override
public Iterator<Script> iterator() {
public @NotNull Iterator<Script> iterator() {
return outputScripts.iterator();
}

Expand All @@ -216,7 +218,8 @@ public Iterator<Script> iterator() {
* @return true if script was added; false otherwise
*/
public boolean addScript(String contextPath, String scriptName, Type type) {
contextPath = contextPath == null || contextPath.isEmpty() ? "/" : contextPath + "/";
contextPath = Optional.ofNullable(contextPath)
.orElse("").concat("/");
if (type == Type.DEBUG && SCRIPTS.containsKey(scriptName + DEBUG_SUFFIX)) {
addScript(contextPath, scriptName + DEBUG_SUFFIX);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
public class StatisticsFilter implements Filter {

static final String REQUESTS_METRIC = "requests";
private static final String CATEGORY_TAG = "category";

private final DistributionSummary requests = Metrics.getPrometheusRegistry().summary(REQUESTS_METRIC);

Expand Down Expand Up @@ -76,7 +77,7 @@ private void measure(HttpServletResponse httpResponse, HttpServletRequest httpRe
category = getCategory(httpReq, config);

Timer categoryTimer = Timer.builder("requests.latency").
tags("category", category, "code", String.valueOf(httpResponse.getStatus())).
tags(CATEGORY_TAG, category, "code", String.valueOf(httpResponse.getStatus())).
register(Metrics.getPrometheusRegistry());
categoryTimer.record(duration);

Expand All @@ -85,12 +86,12 @@ private void measure(HttpServletResponse httpResponse, HttpServletRequest httpRe
if (helper != null && registry != null) {
if (helper.getHits() == null || helper.getHits().length == 0) {
Timer.builder("search.latency").
tags("category", "ui", "outcome", "empty").
tags(CATEGORY_TAG, "ui", "outcome", "empty").
register(registry).
record(duration);
} else {
Timer.builder("search.latency").
tags("category", "ui", "outcome", "success").
tags(CATEGORY_TAG, "ui", "outcome", "success").
register(registry).
record(duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@
import java.io.IOException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -74,8 +76,9 @@
public class ProjectsController {

private static final Logger LOGGER = LoggerFactory.getLogger(ProjectsController.class);
private static final String NO_REPO_LOG_MSG = "no repositories found for project ''{0}''";

public static final String PROJECTS_PATH = "/projects";
public static final String PROJECTS_PATH = "projects";

private final RuntimeEnvironment env = RuntimeEnvironment.getInstance();

Expand Down Expand Up @@ -131,19 +134,14 @@ private void addProjectWorkHorse(String projectName) {
List<RepositoryInfo> allrepos = env.getRepositories();
synchronized (allrepos) {
// newly added repository
for (RepositoryInfo repo : repos) {
if (!allrepos.contains(repo)) {
allrepos.add(repo);
}
}
repos.stream()
.filter(repo -> !allrepos.contains(repo))
.forEach(allrepos::add);
// deleted repository
if (map.containsKey(project)) {
for (RepositoryInfo repo : map.get(project)) {
if (!repos.contains(repo)) {
allrepos.remove(repo);
}
}
}
Optional.ofNullable(map.get(project))
.stream().flatMap(Collection::stream)
.filter(repo -> !repos.contains(repo))
.forEach(allrepos::remove);
}

map.put(project, repos);
Expand Down Expand Up @@ -249,7 +247,7 @@ private void deleteProjectDataWorkHorse(Project project, boolean clearHistoryGur

List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project);
if (repos == null || repos.isEmpty()) {
LOGGER.log(Level.INFO, "no repositories found for project ''{0}''", projectName);
LOGGER.log(Level.INFO, NO_REPO_LOG_MSG, projectName);
return;
}

Expand All @@ -274,7 +272,7 @@ public Response deleteAnnotationCache(@Context HttpServletRequest request,
Project project = getProjectFromName(projectNameParam);
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project);
if (repos == null || repos.isEmpty()) {
LOGGER.log(Level.INFO, "no repositories found for project ''{0}''", project.getName());
LOGGER.log(Level.INFO, NO_REPO_LOG_MSG, project.getName());
return null;
}

Expand Down Expand Up @@ -307,7 +305,7 @@ public Response deleteHistoryCache(@Context HttpServletRequest request,
Project project = getProjectFromName(projectNameParam);
List<RepositoryInfo> repos = env.getProjectRepositoriesMap().get(project);
if (repos == null || repos.isEmpty()) {
LOGGER.log(Level.INFO, "no repositories found for project ''{0}''", project.getName());
LOGGER.log(Level.INFO, NO_REPO_LOG_MSG, project.getName());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void addSearchCountsQueries(final List<String> urls) {
}
}
} catch (MalformedURLException e) {
logger.log(Level.WARNING, "Could not add search counts for " + urlStr, e);
logger.log(Level.WARNING, e, () -> "Could not add search counts for " + urlStr);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public void filter(final ContainerRequestContext context) {
if (!isPathAuthorized(path, request)) {
// TODO: this should probably update statistics for denied requests like in AuthorizationFilter
context.abortWith(Response.status(Response.Status.FORBIDDEN).build());
return; // for good measure
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

.ac_results ul {
width: 100%;
list-style-position: outside;
list-style: none;
list-style-position: outside;
padding: 0;
margin: 0;
}
Expand Down
1 change: 0 additions & 1 deletion opengrok-web/src/main/webapp/default/jquery.combo.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
cursor: pointer;
height: 25px;
width: 22px;
cursor: pointer;
}

.combo_td2 img {
Expand Down
39 changes: 0 additions & 39 deletions opengrok-web/src/main/webapp/default/mandoc-1.0.0.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ table.head { width: 100%;
td.head-vol { text-align: center; }
td.head-rtitle {
text-align: right; }
span.Nd { }

table.foot { width: 100%;
border-top: 1px dotted #808080;
Expand All @@ -85,44 +84,30 @@ h2.Ss { margin-top: 2ex;
margin-left: -2ex;
font-size: 105%; }
div.Pp { margin: 1ex 0ex; }
a.Sx { }
a.Xr { }

/* Displays and lists. */

div.Bd { }
div.D1 { margin-left: 5ex; }

ul.Bl-bullet { list-style-type: disc;
padding-left: 1em; }
li.It-bullet { }
ul.Bl-dash { list-style-type: none;
padding-left: 0em; }
li.It-dash:before {
content: "\2014 "; }
ul.Bl-item { list-style-type: none;
padding-left: 0em; }
li.It-item { }
ul.Bl-compact > li {
margin-top: 0ex; }

ol.Bl-enum { padding-left: 2em; }
li.It-enum { }
ol.Bl-compact > li {
margin-top: 0ex; }

dl.Bl-diag { }
dt.It-diag { }
dd.It-diag { margin-left: 0ex; }
b.It-diag { font-style: normal; }
dl.Bl-hang { }
dt.It-hang { }
dd.It-hang { margin-left: 10.2ex; }
dl.Bl-inset { }
dt.It-inset { }
dd.It-inset { margin-left: 0ex; }
dl.Bl-ohang { }
dt.It-ohang { }
dd.It-ohang { margin-left: 0ex; }
dl.Bl-tag { margin-left: 10.2ex; }
dt.It-tag { float: left;
Expand All @@ -139,41 +124,24 @@ dd.It-tag { clear: right;
dl.Bl-compact > dt {
margin-top: 0ex; }

table.Bl-column { }
tr.It-column { }
td.It-column { margin-top: 1em; }
table.Bl-compact > tbody > tr > td {
margin-top: 0ex; }

cite.Rs { font-style: normal;
font-weight: normal; }
span.RsA { }
i.RsB { font-weight: normal; }
span.RsC { }
span.RsD { }
i.RsI { font-weight: normal; }
i.RsJ { font-weight: normal; }
span.RsN { }
span.RsO { }
span.RsP { }
span.RsQ { }
span.RsR { }
span.RsT { text-decoration: underline; }
a.RsU { }
span.RsV { }

span.eqn { }
table.tbl { }

/* Semantic markup for command line utilities. */

table.Nm { }
b.Nm { font-style: normal; }
b.Fl { font-style: normal; }
b.Cm { font-style: normal; }
var.Ar { font-style: italic;
font-weight: normal; }
span.Op { }
b.Ic { font-style: normal; }
code.Ev { font-style: normal;
font-weight: normal;
Expand All @@ -182,9 +150,7 @@ i.Pa { font-weight: normal; }

/* Semantic markup for function libraries. */

span.Lb { }
b.In { font-style: normal; }
a.In { }
b.Fd { font-style: normal; }
var.Ft { font-style: italic;
font-weight: normal; }
Expand All @@ -204,14 +170,9 @@ code.Er { font-style: normal;

/* Various semantic markup. */

span.An { }
a.Lk { }
a.Mt { }
b.Cd { font-style: normal; }
i.Ad { font-weight: normal; }
b.Ms { font-style: normal; }
span.St { }
a.Ux { }

/* Physical markup. */

Expand Down
8 changes: 0 additions & 8 deletions opengrok-web/src/main/webapp/default/print-1.0.2.css
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ label {
display: block;
}

#page { }

.error { /* error messages */
color: #a52a2a;
}
Expand Down Expand Up @@ -335,9 +333,6 @@ table#dirlist { /* the "Name" column */


/* file display */
#src {
}

#src pre {
margin: 0;
font-size: small;
Expand Down Expand Up @@ -422,9 +417,6 @@ a.xsr { /* subroutine */ color: #00f; font-weight: bold;
}

/* search result page */
#results {
}

#results p { /* pagetitle and slider */
padding: 0.1em;
}
Expand Down
Loading

0 comments on commit 2f0c0f8

Please sign in to comment.