| | |
| | | /*
|
| | | * Copyright 2011 gitblit.com.
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.awt.Color;
|
| | | import java.awt.Dimension;
|
| | | import java.text.MessageFormat;
|
| | | import java.text.ParseException;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import org.apache.wicket.Component;
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.image.ContextImage;
|
| | | import org.apache.wicket.markup.repeater.Item;
|
| | | import org.apache.wicket.markup.repeater.data.DataView;
|
| | | import org.apache.wicket.markup.repeater.data.ListDataProvider;
|
| | | import org.eclipse.jgit.lib.ObjectId;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.markup.html.panel.Fragment;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.wicketstuff.googlecharts.Chart;
|
| | | import org.wicketstuff.googlecharts.ChartAxis;
|
| | | import org.wicketstuff.googlecharts.ChartAxisType;
|
| | | import org.wicketstuff.googlecharts.ChartProvider;
|
| | | import org.wicketstuff.googlecharts.ChartType;
|
| | | import org.wicketstuff.googlecharts.IChartData;
|
| | | import org.wicketstuff.googlecharts.LineStyle;
|
| | | import org.wicketstuff.googlecharts.MarkerType;
|
| | | import org.wicketstuff.googlecharts.ShapeMarker;
|
| | |
|
| | | import com.codecommit.wicket.AbstractChartData;
|
| | | import com.codecommit.wicket.Chart;
|
| | | import com.codecommit.wicket.ChartAxis;
|
| | | import com.codecommit.wicket.ChartAxisType;
|
| | | import com.codecommit.wicket.ChartProvider;
|
| | | import com.codecommit.wicket.ChartType;
|
| | | import com.codecommit.wicket.IChartData;
|
| | | import com.gitblit.StoredSettings;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.Metric;
|
| | | import com.gitblit.models.PathModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.wicket.GitBlitWebApp;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.LinkPanel;
|
| | | import com.gitblit.wicket.RepositoryPage;
|
| | | import com.gitblit.utils.MarkdownUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.models.Metric;
|
| | | import com.gitblit.wicket.models.RefModel;
|
| | | import com.gitblit.wicket.panels.AnnotatedTagLinksPanel;
|
| | | import com.gitblit.wicket.panels.BranchLinksPanel;
|
| | | import com.gitblit.wicket.panels.RefsPanel;
|
| | | import com.gitblit.wicket.panels.ShortLogLinksPanel;
|
| | | import com.gitblit.wicket.panels.TagLinksPanel;
|
| | | import com.gitblit.wicket.panels.BranchesPanel;
|
| | | import com.gitblit.wicket.panels.LogPanel;
|
| | | import com.gitblit.wicket.panels.RepositoryUrlPanel;
|
| | | import com.gitblit.wicket.panels.TagsPanel;
|
| | |
|
| | | public class SummaryPage extends RepositoryPage {
|
| | |
|
| | | public SummaryPage(PageParameters params) {
|
| | | super(params, "summary");
|
| | | |
| | | int numCommitsDef = 20;
|
| | | int numRefsDef = 5;
|
| | | |
| | | int numberCommits = StoredSettings.getInteger("summaryCommitCount", numCommitsDef);
|
| | | super(params);
|
| | |
|
| | | int numberCommits = GitBlit.getInteger(Keys.web.summaryCommitCount, 20);
|
| | | if (numberCommits <= 0) {
|
| | | numberCommits = numCommitsDef;
|
| | | numberCommits = 20;
|
| | | }
|
| | | int numberRefs = GitBlit.getInteger(Keys.web.summaryRefsCount, 5);
|
| | |
|
| | | int numberRefs = StoredSettings.getInteger("summaryRefsCount", numRefsDef);
|
| | | if (numberRefs <= 0) {
|
| | | numberRefs = numRefsDef;
|
| | | }
|
| | | |
| | | Repository r = getRepository();
|
| | | final Map<ObjectId, List<String>> allRefs = JGitUtils.getAllRefs(r);
|
| | | RepositoryModel model = getRepositoryModel();
|
| | |
|
| | | String owner = JGitUtils.getRepositoryOwner(r);
|
| | | GitBlitWebSession session = GitBlitWebSession.get();
|
| | | String lastchange = session.formatDateTimeLong(JGitUtils.getLastChange(r));
|
| | | String cloneurl = GitBlitWebApp.get().getCloneUrl(repositoryName);
|
| | | List<Metric> metrics = null;
|
| | | Metric metricsTotal = null;
|
| | | if (!model.skipSummaryMetrics && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
|
| | | metrics = GitBlit.self().getRepositoryDefaultMetrics(model, r);
|
| | | metricsTotal = metrics.remove(0);
|
| | | }
|
| | |
|
| | | addSyndicationDiscoveryLink();
|
| | |
|
| | | // repository description
|
| | | add(new Label("repositoryDescription", description));
|
| | | add(new Label("repositoryOwner", owner));
|
| | | add(new Label("repositoryLastChange", lastchange));
|
| | | add(new Label("repositoryCloneUrl", cloneurl));
|
| | | add(new Label("repositoryDescription", getRepositoryModel().description));
|
| | | add(new Label("repositoryOwner", getRepositoryModel().owner));
|
| | |
|
| | | // shortlog
|
| | | add(new LinkPanel("shortlog", "title", "shortlog", ShortLogPage.class, newRepositoryParameter()));
|
| | |
|
| | | List<RevCommit> commits = JGitUtils.getRevLog(r, numberCommits);
|
| | | ListDataProvider<RevCommit> dp = new ListDataProvider<RevCommit>(commits);
|
| | | DataView<RevCommit> shortlogView = new DataView<RevCommit>("commit", dp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | | int counter = 0;
|
| | |
|
| | | public void populateItem(final Item<RevCommit> item) {
|
| | | RevCommit entry = item.getModelObject();
|
| | | Date date = JGitUtils.getCommitDate(entry);
|
| | |
|
| | | item.add(createShortlogDateLabel("commitDate", date));
|
| | |
|
| | | String author = entry.getAuthorIdent().getName();
|
| | | item.add(createAuthorLabel("commitAuthor", author));
|
| | |
|
| | | String shortMessage = entry.getShortMessage();
|
| | | String trimmedMessage = trimShortLog(shortMessage);
|
| | | LinkPanel shortlog = new LinkPanel("commitShortMessage", "list subject", trimmedMessage, CommitPage.class, newCommitParameter(entry.getName()));
|
| | | if (!shortMessage.equals(trimmedMessage)) {
|
| | | WicketUtils.setHtmlTitle(shortlog, shortMessage);
|
| | | }
|
| | | item.add(shortlog);
|
| | |
|
| | | item.add(new RefsPanel("commitRefs", entry, allRefs));
|
| | |
|
| | | item.add(new ShortLogLinksPanel("commitLinks", repositoryName, entry.getName()));
|
| | |
|
| | | setAlternatingBackground(item, counter);
|
| | | counter++;
|
| | | }
|
| | | };
|
| | | add(shortlogView);
|
| | | if (commits.size() < numberCommits) {
|
| | | add(new Label("shortlogMore", "").setVisible(false));
|
| | | add(WicketUtils.createTimestampLabel("repositoryLastChange",
|
| | | JGitUtils.getLastChange(r), getTimeZone(), getTimeUtils()));
|
| | | if (metricsTotal == null) {
|
| | | add(new Label("branchStats", ""));
|
| | | } else {
|
| | | add(new LinkPanel("shortlogMore", "link", "more...", ShortLogPage.class, newRepositoryParameter()));
|
| | | add(new Label("branchStats",
|
| | | MessageFormat.format(getString("gb.branchStats"), metricsTotal.count,
|
| | | metricsTotal.tag, getTimeUtils().duration(metricsTotal.duration))));
|
| | | }
|
| | | add(new BookmarkablePageLink<Void>("metrics", MetricsPage.class,
|
| | | WicketUtils.newRepositoryParameter(repositoryName)));
|
| | |
|
| | | // tags
|
| | | List<RefModel> tags = JGitUtils.getTags(r, numberRefs);
|
| | | add(new LinkPanel("tags", "title", "tags", TagsPage.class, newRepositoryParameter()));
|
| | | List<String> repositoryUrls = new ArrayList<String>();
|
| | |
|
| | | ListDataProvider<RefModel> tagsDp = new ListDataProvider<RefModel>(tags);
|
| | | DataView<RefModel> tagView = new DataView<RefModel>("tag", tagsDp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | | int counter = 0;
|
| | |
|
| | | public void populateItem(final Item<RefModel> item) {
|
| | | final RefModel entry = item.getModelObject();
|
| | |
|
| | | item.add(createDateLabel("tagDate", entry.getDate()));
|
| | |
|
| | | item.add(new LinkPanel("tagName", "list name", entry.getDisplayName(), CommitPage.class, newCommitParameter(entry.getCommitId().getName())));
|
| | |
|
| | | if (entry.isAnnotatedTag()) {
|
| | | // annotated tag
|
| | | item.add(new LinkPanel("tagDescription", "list subject", entry.getShortLog(), TagPage.class, newCommitParameter(entry.getObjectId().getName())));
|
| | | item.add(new AnnotatedTagLinksPanel("tagLinks", repositoryName, entry));
|
| | | } else {
|
| | | // simple tag on commit object
|
| | | item.add(new Label("tagDescription", ""));
|
| | | item.add(new TagLinksPanel("tagLinks", repositoryName, entry));
|
| | | }
|
| | |
|
| | | setAlternatingBackground(item, counter);
|
| | | counter++;
|
| | | if (GitBlit.getBoolean(Keys.git.enableGitServlet, true)) {
|
| | | AccessRestrictionType accessRestriction = getRepositoryModel().accessRestriction;
|
| | | switch (accessRestriction) {
|
| | | case NONE:
|
| | | add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
| | | break;
|
| | | case PUSH:
|
| | | add(WicketUtils.newImage("accessRestrictionIcon", "lock_go_16x16.png",
|
| | | getAccessRestrictions().get(accessRestriction)));
|
| | | break;
|
| | | case CLONE:
|
| | | add(WicketUtils.newImage("accessRestrictionIcon", "lock_pull_16x16.png",
|
| | | getAccessRestrictions().get(accessRestriction)));
|
| | | break;
|
| | | case VIEW:
|
| | | add(WicketUtils.newImage("accessRestrictionIcon", "shield_16x16.png",
|
| | | getAccessRestrictions().get(accessRestriction)));
|
| | | break;
|
| | | default:
|
| | | add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
| | | }
|
| | | };
|
| | | add(tagView);
|
| | | if (tags.size() < numberRefs) {
|
| | | add(new Label("allTags", "").setVisible(false));
|
| | | // add the Gitblit repository url
|
| | | repositoryUrls.add(getRepositoryUrl(getRepositoryModel()));
|
| | | } else {
|
| | | add(new LinkPanel("allTags", "link", "all tags...", TagsPage.class, newRepositoryParameter()));
|
| | | add(WicketUtils.newClearPixel("accessRestrictionIcon").setVisible(false));
|
| | | }
|
| | |
|
| | | // branches
|
| | | List<RefModel> branches = new ArrayList<RefModel>();
|
| | | branches.addAll(JGitUtils.getLocalBranches(r, numberRefs));
|
| | | branches.addAll(JGitUtils.getRemoteBranches(r, numberRefs));
|
| | | Collections.sort(branches);
|
| | | Collections.reverse(branches);
|
| | | if (numberRefs > 0 && branches.size() > numberRefs) {
|
| | | branches = new ArrayList<RefModel>(branches.subList(0, numberRefs));
|
| | | }
|
| | |
|
| | | add(new LinkPanel("branches", "title", "branches", BranchesPage.class, newRepositoryParameter()));
|
| | |
|
| | | ListDataProvider<RefModel> branchesDp = new ListDataProvider<RefModel>(branches);
|
| | | DataView<RefModel> branchesView = new DataView<RefModel>("branch", branchesDp) {
|
| | | private static final long serialVersionUID = 1L;
|
| | | int counter = 0;
|
| | |
|
| | | public void populateItem(final Item<RefModel> item) {
|
| | | final RefModel entry = item.getModelObject();
|
| | |
|
| | | item.add(createDateLabel("branchDate", entry.getDate()));
|
| | |
|
| | | item.add(new LinkPanel("branchName", "list name", trimString(entry.getDisplayName(), 28), ShortLogPage.class, newCommitParameter(entry.getName())));
|
| | |
|
| | | item.add(new BranchLinksPanel("branchLinks", repositoryName, entry));
|
| | |
|
| | | setAlternatingBackground(item, counter);
|
| | | counter++;
|
| | | }
|
| | | };
|
| | | add(branchesView);
|
| | | if (branches.size() < numberRefs) {
|
| | | add(new Label("allBranches", "").setVisible(false));
|
| | | } else {
|
| | | add(new LinkPanel("allBranches", "link", "all branches...", BranchesPage.class, newRepositoryParameter()));
|
| | | }
|
| | | repositoryUrls.addAll(GitBlit.self().getOtherCloneUrls(repositoryName));
|
| | |
|
| | | String primaryUrl = ArrayUtils.isEmpty(repositoryUrls) ? "" : repositoryUrls.remove(0);
|
| | | add(new RepositoryUrlPanel("repositoryCloneUrl", primaryUrl));
|
| | |
|
| | | add(new Label("otherUrls", StringUtils.flattenStrings(repositoryUrls, "<br/>"))
|
| | | .setEscapeModelStrings(false));
|
| | |
|
| | | add(new LogPanel("commitsPanel", repositoryName, getRepositoryModel().HEAD, r, numberCommits, 0));
|
| | | add(new TagsPanel("tagsPanel", repositoryName, r, numberRefs).hideIfEmpty());
|
| | | add(new BranchesPanel("branchesPanel", getRepositoryModel(), r, numberRefs).hideIfEmpty());
|
| | |
|
| | | if (getRepositoryModel().showReadme) {
|
| | | String htmlText = null;
|
| | | String markdownText = null;
|
| | | String readme = null;
|
| | | try {
|
| | | RevCommit head = JGitUtils.getCommit(r, null);
|
| | | List<String> markdownExtensions = GitBlit.getStrings(Keys.web.markdownExtensions);
|
| | | List<PathModel> paths = JGitUtils.getFilesInPath(r, null, head); |
| | | for (PathModel path : paths) {
|
| | | if (!path.isTree()) {
|
| | | String name = path.name.toLowerCase();
|
| | |
|
| | | if (name.startsWith("readme")) {
|
| | | if (name.indexOf('.') > -1) {
|
| | | String ext = name.substring(name.lastIndexOf('.') + 1);
|
| | | if (markdownExtensions.contains(ext)) {
|
| | | readme = path.name;
|
| | | break;
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | if (!StringUtils.isEmpty(readme)) {
|
| | | String [] encodings = GitBlit.getEncodings();
|
| | | markdownText = JGitUtils.getStringContent(r, head.getTree(), readme, encodings);
|
| | | htmlText = MarkdownUtils.transformMarkdown(markdownText);
|
| | | }
|
| | | } catch (ParseException p) {
|
| | | markdownText = MessageFormat.format("<div class=\"alert alert-error\"><strong>{0}:</strong> {1}</div>{2}", getString("gb.error"), getString("gb.markdownFailure"), markdownText);
|
| | | htmlText = StringUtils.breakLinesForHtml(markdownText);
|
| | | }
|
| | | Fragment fragment = new Fragment("readme", "markdownPanel");
|
| | | fragment.add(new Label("readmeFile", readme));
|
| | | // Add the html to the page
|
| | | Component content = new Label("readmeContent", htmlText).setEscapeModelStrings(false);
|
| | | fragment.add(content.setVisible(!StringUtils.isEmpty(htmlText)));
|
| | | add(fragment);
|
| | | } else {
|
| | | add(new Label("readme").setVisible(false));
|
| | | }
|
| | |
|
| | | // Display an activity line graph
|
| | | insertActivityGraph(r);
|
| | |
|
| | | // close the repository
|
| | | r.close();
|
| | |
|
| | | // footer
|
| | | addFooter();
|
| | | insertActivityGraph(metrics);
|
| | | }
|
| | |
|
| | | private void insertActivityGraph(Repository r) {
|
| | | if (StoredSettings.getBoolean("generateActivityGraph", true)) {
|
| | | List<Metric> dates = JGitUtils.getDateMetrics(r);
|
| | | IChartData data = getChartData(dates);
|
| | | @Override
|
| | | protected String getPageName() {
|
| | | return getString("gb.summary");
|
| | | }
|
| | |
|
| | | ChartProvider provider = new ChartProvider(new Dimension(400, 80), ChartType.LINE, data);
|
| | | private void insertActivityGraph(List<Metric> metrics) {
|
| | | if ((metrics != null) && (metrics.size() > 0)
|
| | | && GitBlit.getBoolean(Keys.web.generateActivityGraph, true)) {
|
| | | IChartData data = WicketUtils.getChartData(metrics);
|
| | |
|
| | | ChartProvider provider = new ChartProvider(new Dimension(290, 100), ChartType.LINE,
|
| | | data);
|
| | | ChartAxis dateAxis = new ChartAxis(ChartAxisType.BOTTOM);
|
| | | dateAxis.setLabels(new String[] { dates.get(0).name, dates.get(dates.size() / 2).name, dates.get(dates.size() - 1).name });
|
| | | dateAxis.setLabels(new String[] { metrics.get(0).name,
|
| | | metrics.get(metrics.size() / 2).name, metrics.get(metrics.size() - 1).name });
|
| | | provider.addAxis(dateAxis);
|
| | |
|
| | | ChartAxis commitAxis = new ChartAxis(ChartAxisType.LEFT);
|
| | | commitAxis.setLabels(new String[] { "", String.valueOf((int) maxValue(dates)) });
|
| | | commitAxis.setLabels(new String[] { "",
|
| | | String.valueOf((int) WicketUtils.maxValue(metrics)) });
|
| | | provider.addAxis(commitAxis);
|
| | | provider.setLineStyles(new LineStyle[] { new LineStyle(2, 4, 0), new LineStyle(0, 4, 1) });
|
| | | provider.addShapeMarker(new ShapeMarker(MarkerType.CIRCLE, Color.BLUE, 1, -1, 5));
|
| | |
|
| | | add(new Chart("commitsChart", provider));
|
| | | } else {
|
| | | add(new ContextImage("commitsChart", "blank.png")); |
| | | add(WicketUtils.newBlankImage("commitsChart"));
|
| | | }
|
| | | }
|
| | |
|
| | | protected IChartData getChartData(List<Metric> results) {
|
| | | final double[] counts = new double[results.size()];
|
| | | int i = 0;
|
| | | double max = 0;
|
| | | for (Metric m : results) {
|
| | | counts[i++] = m.count;
|
| | | max = Math.max(max, m.count);
|
| | | }
|
| | | final double dmax = max;
|
| | | IChartData data = new AbstractChartData() {
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | public double[][] getData() {
|
| | | return new double[][] { counts };
|
| | | }
|
| | |
|
| | | public double getMax() {
|
| | | return dmax;
|
| | | }
|
| | | };
|
| | | return data;
|
| | | }
|
| | |
|
| | | protected String[] getNames(List<Metric> results) {
|
| | | String[] names = new String[results.size()];
|
| | | for (int i = 0; i < results.size(); i++) {
|
| | | names[i] = results.get(i).name;
|
| | | }
|
| | | return names;
|
| | | }
|
| | |
|
| | | protected double maxValue(List<Metric> metrics) {
|
| | | double max = Double.MIN_VALUE;
|
| | | for (Metric m : metrics) {
|
| | | if (m.count > max) {
|
| | | max = m.count;
|
| | | }
|
| | | }
|
| | | return max;
|
| | | }
|
| | | }
|