Search in sources :

Example 86 with DateFormat

use of java.text.DateFormat in project gitblit by gitblit.

the class ActivityUtils method getRecentActivity.

/**
	 * Gets the recent activity from the repositories for the last daysBack days
	 * on the specified branch.
	 *
	 * @param settings
	 *            the runtime settings
	 * @param repositoryManager
	 *            the repository manager
	 * @param models
	 *            the list of repositories to query
	 * @param daysBack
	 *            the number of days back from Now to collect
	 * @param objectId
	 *            the branch to retrieve. If this value is null or empty all
	 *            branches are queried.
	 * @param timezone
	 *            the timezone for aggregating commits
	 * @return
	 */
public static List<Activity> getRecentActivity(IStoredSettings settings, IRepositoryManager repositoryManager, List<RepositoryModel> models, int daysBack, String objectId, TimeZone timezone) {
    // Activity panel shows last daysBack of activity across all
    // repositories.
    Date thresholdDate = new Date(System.currentTimeMillis() - daysBack * TimeUtils.ONEDAY);
    // Build a map of DailyActivity from the available repositories for the
    // specified threshold date.
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.setTimeZone(timezone);
    Calendar cal = Calendar.getInstance();
    cal.setTimeZone(timezone);
    // aggregate author exclusions
    Set<String> authorExclusions = new TreeSet<String>();
    authorExclusions.addAll(settings.getStrings(Keys.web.metricAuthorExclusions));
    for (RepositoryModel model : models) {
        if (!ArrayUtils.isEmpty(model.metricAuthorExclusions)) {
            authorExclusions.addAll(model.metricAuthorExclusions);
        }
    }
    Map<String, Activity> activity = new HashMap<String, Activity>();
    for (RepositoryModel model : models) {
        if (!model.isShowActivity()) {
            // skip this repository
            continue;
        }
        if (model.hasCommits && model.lastChange.after(thresholdDate)) {
            if (model.isCollectingGarbage) {
                continue;
            }
            Repository repository = repositoryManager.getRepository(model.name);
            List<String> branches = new ArrayList<String>();
            if (StringUtils.isEmpty(objectId)) {
                for (RefModel local : JGitUtils.getLocalBranches(repository, true, -1)) {
                    if (!local.getDate().after(thresholdDate)) {
                        // branch not recently updated
                        continue;
                    }
                    branches.add(local.getName());
                }
            } else {
                branches.add(objectId);
            }
            for (String branch : branches) {
                String shortName = branch;
                if (shortName.startsWith(Constants.R_HEADS)) {
                    shortName = shortName.substring(Constants.R_HEADS.length());
                }
                List<RepositoryCommit> commits = CommitCache.instance().getCommits(model.name, repository, branch, thresholdDate);
                if (model.maxActivityCommits > 0 && commits.size() > model.maxActivityCommits) {
                    // trim commits to maximum count
                    commits = commits.subList(0, model.maxActivityCommits);
                }
                for (RepositoryCommit commit : commits) {
                    Date date = commit.getCommitDate();
                    String dateStr = df.format(date);
                    if (!activity.containsKey(dateStr)) {
                        // Normalize the date to midnight
                        cal.setTime(date);
                        cal.set(Calendar.HOUR_OF_DAY, 0);
                        cal.set(Calendar.MINUTE, 0);
                        cal.set(Calendar.SECOND, 0);
                        cal.set(Calendar.MILLISECOND, 0);
                        Activity a = new Activity(cal.getTime());
                        a.excludeAuthors(authorExclusions);
                        activity.put(dateStr, a);
                    }
                    activity.get(dateStr).addCommit(commit);
                }
            }
            // close the repository
            repository.close();
        }
    }
    List<Activity> recentActivity = new ArrayList<Activity>(activity.values());
    return recentActivity;
}
Also used : RefModel(com.gitblit.models.RefModel) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Activity(com.gitblit.models.Activity) RepositoryModel(com.gitblit.models.RepositoryModel) RepositoryCommit(com.gitblit.models.RepositoryCommit) Date(java.util.Date) Repository(org.eclipse.jgit.lib.Repository) TreeSet(java.util.TreeSet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 87 with DateFormat

use of java.text.DateFormat in project gitblit by gitblit.

the class TicketNotifier method formatLastChange.

protected String formatLastChange(TicketModel ticket) {
    Change lastChange = ticket.changes.get(ticket.changes.size() - 1);
    UserModel user = getUserModel(lastChange.author);
    // define the fields we do NOT want to see in an email notification
    Set<TicketModel.Field> fieldExclusions = new HashSet<TicketModel.Field>();
    fieldExclusions.addAll(Arrays.asList(Field.watchers, Field.voters));
    StringBuilder sb = new StringBuilder();
    boolean newTicket = lastChange.isStatusChange() && Status.New == lastChange.getStatus();
    boolean isFastForward = true;
    List<RevCommit> commits = null;
    DiffStat diffstat = null;
    String pattern;
    if (lastChange.hasPatchset()) {
        // patchset uploaded
        Patchset patchset = lastChange.patchset;
        String base = "";
        // determine the changed paths
        Repository repo = null;
        try {
            repo = repositoryManager.getRepository(ticket.repository);
            if (patchset.isFF() && (patchset.rev > 1)) {
                // fast-forward update, just show the new data
                isFastForward = true;
                Patchset prev = ticket.getPatchset(patchset.number, patchset.rev - 1);
                base = prev.tip;
            } else {
                // proposal OR non-fast-forward update
                isFastForward = false;
                base = patchset.base;
            }
            diffstat = DiffUtils.getDiffStat(repo, base, patchset.tip);
            commits = JGitUtils.getRevLog(repo, base, patchset.tip);
        } catch (Exception e) {
            Logger.getLogger(getClass()).error("failed to get changed paths", e);
        } finally {
            if (repo != null) {
                repo.close();
            }
        }
        String compareUrl = ticketService.getCompareUrl(ticket, base, patchset.tip);
        if (newTicket) {
            // new proposal
            pattern = "**{0}** is proposing a change.";
            sb.append(MessageFormat.format(pattern, user.getDisplayName()));
            fieldExclusions.add(Field.status);
            fieldExclusions.add(Field.title);
            fieldExclusions.add(Field.body);
        } else {
            // describe the patchset
            if (patchset.isFF()) {
                pattern = "**{0}** added {1} {2} to patchset {3}.";
                sb.append(MessageFormat.format(pattern, user.getDisplayName(), patchset.added, patchset.added == 1 ? "commit" : "commits", patchset.number));
            } else {
                pattern = "**{0}** uploaded patchset {1}. *({2})*";
                sb.append(MessageFormat.format(pattern, user.getDisplayName(), patchset.number, patchset.type.toString().toUpperCase()));
            }
        }
        sb.append(HARD_BRK);
        sb.append(MessageFormat.format("{0} {1}, {2} {3}, <span style=\"color:darkgreen;\">+{4} insertions</span>, <span style=\"color:darkred;\">-{5} deletions</span> from {6}. [compare]({7})", commits.size(), commits.size() == 1 ? "commit" : "commits", diffstat.paths.size(), diffstat.paths.size() == 1 ? "file" : "files", diffstat.getInsertions(), diffstat.getDeletions(), isFastForward ? "previous revision" : "merge base", compareUrl));
        // note commit additions on a rebase,if any
        switch(lastChange.patchset.type) {
            case Rebase:
                if (lastChange.patchset.added > 0) {
                    sb.append(SOFT_BRK);
                    sb.append(MessageFormat.format("{0} {1} added.", lastChange.patchset.added, lastChange.patchset.added == 1 ? "commit" : "commits"));
                }
                break;
            default:
                break;
        }
        sb.append(HARD_BRK);
    } else if (lastChange.isStatusChange()) {
        if (newTicket) {
            fieldExclusions.add(Field.status);
            fieldExclusions.add(Field.title);
            fieldExclusions.add(Field.body);
            pattern = "**{0}** created this ticket.";
            sb.append(MessageFormat.format(pattern, user.getDisplayName()));
        } else if (lastChange.hasField(Field.mergeSha)) {
            // closed by merged
            pattern = "**{0}** closed this ticket by merging {1} to {2}.";
            // identify patchset that closed the ticket
            String merged = ticket.mergeSha;
            for (Patchset patchset : ticket.getPatchsets()) {
                if (patchset.tip.equals(ticket.mergeSha)) {
                    merged = patchset.toString();
                    break;
                }
            }
            sb.append(MessageFormat.format(pattern, user.getDisplayName(), merged, ticket.mergeTo));
        } else {
            // workflow status change by user
            pattern = "**{0}** changed the status of this ticket to **{1}**.";
            sb.append(MessageFormat.format(pattern, user.getDisplayName(), lastChange.getStatus().toString().toUpperCase()));
        }
        sb.append(HARD_BRK);
    } else if (lastChange.hasReview()) {
        // review
        Review review = lastChange.review;
        pattern = "**{0}** has reviewed patchset {1,number,0} revision {2,number,0}.";
        sb.append(MessageFormat.format(pattern, user.getDisplayName(), review.patchset, review.rev));
        sb.append(HARD_BRK);
        String d = settings.getString(Keys.web.datestampShortFormat, "yyyy-MM-dd");
        String t = settings.getString(Keys.web.timeFormat, "HH:mm");
        DateFormat df = new SimpleDateFormat(d + " " + t);
        List<Change> reviews = ticket.getReviews(ticket.getPatchset(review.patchset, review.rev));
        sb.append("| Date | Reviewer      | Score | Description  |\n");
        sb.append("| :--- | :------------ | :---: | :----------- |\n");
        for (Change change : reviews) {
            String name = change.author;
            UserModel u = userManager.getUserModel(change.author);
            if (u != null) {
                name = u.getDisplayName();
            }
            String score;
            switch(change.review.score) {
                case approved:
                    score = MessageFormat.format(addPattern, change.review.score.getValue());
                    break;
                case vetoed:
                    score = MessageFormat.format(delPattern, Math.abs(change.review.score.getValue()));
                    break;
                default:
                    score = "" + change.review.score.getValue();
            }
            String date = df.format(change.date);
            sb.append(String.format("| %1$s | %2$s | %3$s | %4$s |\n", date, name, score, change.review.score.toString()));
        }
        sb.append(HARD_BRK);
    } else if (lastChange.hasComment()) {
        // comment update
        sb.append(MessageFormat.format("**{0}** commented on this ticket.", user.getDisplayName()));
        sb.append(HARD_BRK);
    } else if (lastChange.hasReference()) {
        // reference update
        String type = "?";
        switch(lastChange.reference.getSourceType()) {
            case Commit:
                {
                    type = "commit";
                }
                break;
            case Ticket:
                {
                    type = "ticket";
                }
                break;
            default:
                {
                }
                break;
        }
        sb.append(MessageFormat.format("**{0}** referenced this ticket in {1} {2}", type, lastChange.toString()));
        sb.append(HARD_BRK);
    } else {
        // general update
        pattern = "**{0}** has updated this ticket.";
        sb.append(MessageFormat.format(pattern, user.getDisplayName()));
        sb.append(HARD_BRK);
    }
    // ticket link
    sb.append(MessageFormat.format("[view ticket {0,number,0}]({1})", ticket.number, ticketService.getTicketUrl(ticket)));
    sb.append(HARD_BRK);
    if (newTicket) {
        // ticket title
        sb.append(MessageFormat.format("### {0}", ticket.title));
        sb.append(HARD_BRK);
        // ticket description, on state change
        if (StringUtils.isEmpty(ticket.body)) {
            sb.append("<span style=\"color: #888;\">no description entered</span>");
        } else {
            sb.append(ticket.body);
        }
        sb.append(HARD_BRK);
        sb.append(HR);
    }
    // field changes
    if (lastChange.hasFieldChanges()) {
        Map<Field, String> filtered = new HashMap<Field, String>();
        for (Map.Entry<Field, String> fc : lastChange.fields.entrySet()) {
            if (!fieldExclusions.contains(fc.getKey())) {
                // field is included
                filtered.put(fc.getKey(), fc.getValue());
            }
        }
        // sort by field ordinal
        List<Field> fields = new ArrayList<Field>(filtered.keySet());
        Collections.sort(fields);
        if (filtered.size() > 0) {
            sb.append(HARD_BRK);
            sb.append("| Field Changes               ||\n");
            sb.append("| ------------: | :----------- |\n");
            for (Field field : fields) {
                String value;
                if (filtered.get(field) == null) {
                    value = "";
                } else {
                    value = filtered.get(field).replace("\r\n", "<br/>").replace("\n", "<br/>").replace("|", "&#124;");
                }
                sb.append(String.format("| **%1$s:** | %2$s |\n", field.name(), value));
            }
            sb.append(HARD_BRK);
        }
    }
    // new comment
    if (lastChange.hasComment()) {
        sb.append(HR);
        sb.append(lastChange.comment.text);
        sb.append(HARD_BRK);
    }
    // insert the patchset details and review instructions
    if (lastChange.hasPatchset() && ticket.isOpen()) {
        if (commits != null && commits.size() > 0) {
            // append the commit list
            String title = isFastForward ? "Commits added to previous patchset revision" : "All commits in patchset";
            sb.append(MessageFormat.format("| {0} |||\n", title));
            sb.append("| SHA | Author | Title |\n");
            sb.append("| :-- | :----- | :---- |\n");
            for (RevCommit commit : commits) {
                sb.append(MessageFormat.format("| {0} | {1} | {2} |\n", commit.getName(), commit.getAuthorIdent().getName(), StringUtils.trimString(commit.getShortMessage(), Constants.LEN_SHORTLOG).replace("|", "&#124;")));
            }
            sb.append(HARD_BRK);
        }
        if (diffstat != null) {
            // append the changed path list
            String title = isFastForward ? "Files changed since previous patchset revision" : "All files changed in patchset";
            sb.append(MessageFormat.format("| {0} |||\n", title));
            sb.append("| :-- | :----------- | :-: |\n");
            for (PathChangeModel path : diffstat.paths) {
                String add = MessageFormat.format(addPattern, path.insertions);
                String del = MessageFormat.format(delPattern, path.deletions);
                String diff = null;
                switch(path.changeType) {
                    case ADD:
                        diff = add;
                        break;
                    case DELETE:
                        diff = del;
                        break;
                    case MODIFY:
                        if (path.insertions > 0 && path.deletions > 0) {
                            // insertions & deletions
                            diff = add + "/" + del;
                        } else if (path.insertions > 0) {
                            // just insertions
                            diff = add;
                        } else {
                            // just deletions
                            diff = del;
                        }
                        break;
                    default:
                        diff = path.changeType.name();
                        break;
                }
                sb.append(MessageFormat.format("| {0} | {1} | {2} |\n", getChangeType(path.changeType), path.name, diff));
            }
            sb.append(HARD_BRK);
        }
        sb.append(formatPatchsetInstructions(ticket, lastChange.patchset));
    }
    return sb.toString();
}
Also used : HashMap(java.util.HashMap) DiffStat(com.gitblit.utils.DiffUtils.DiffStat) ArrayList(java.util.ArrayList) Patchset(com.gitblit.models.TicketModel.Patchset) Review(com.gitblit.models.TicketModel.Review) UserModel(com.gitblit.models.UserModel) Field(com.gitblit.models.TicketModel.Field) HashSet(java.util.HashSet) RevCommit(org.eclipse.jgit.revwalk.RevCommit) PathChangeModel(com.gitblit.models.PathModel.PathChangeModel) TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) IOException(java.io.IOException) Repository(org.eclipse.jgit.lib.Repository) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 88 with DateFormat

use of java.text.DateFormat in project gitblit by gitblit.

the class ReflogPanel method setup.

protected void setup(List<RefLogEntry> changes) {
    ListDataProvider<RefLogEntry> dp = new ListDataProvider<RefLogEntry>(changes);
    DataView<RefLogEntry> changeView = new DataView<RefLogEntry>("change", dp) {

        private static final long serialVersionUID = 1L;

        @Override
        public void populateItem(final Item<RefLogEntry> changeItem) {
            final RefLogEntry change = changeItem.getModelObject();
            String dateFormat = app().settings().getString(Keys.web.datetimestampLongFormat, "EEEE, MMMM d, yyyy HH:mm Z");
            TimeZone timezone = getTimeZone();
            DateFormat df = new SimpleDateFormat(dateFormat);
            df.setTimeZone(timezone);
            Calendar cal = Calendar.getInstance(timezone);
            String fullRefName = change.getChangedRefs().get(0);
            String shortRefName = fullRefName;
            String ticketId = null;
            boolean isTag = false;
            boolean isTicket = false;
            if (shortRefName.startsWith(Constants.R_TICKET)) {
                ticketId = fullRefName.substring(Constants.R_TICKET.length());
                shortRefName = MessageFormat.format(getString("gb.ticketN"), ticketId);
                isTicket = true;
            } else if (shortRefName.startsWith(Constants.R_HEADS)) {
                shortRefName = shortRefName.substring(Constants.R_HEADS.length());
            } else if (shortRefName.startsWith(Constants.R_TAGS)) {
                shortRefName = shortRefName.substring(Constants.R_TAGS.length());
                isTag = true;
            }
            String fuzzydate;
            TimeUtils tu = getTimeUtils();
            Date changeDate = change.date;
            if (TimeUtils.isToday(changeDate, timezone)) {
                fuzzydate = tu.today();
            } else if (TimeUtils.isYesterday(changeDate, timezone)) {
                fuzzydate = tu.yesterday();
            } else {
                // calculate a fuzzy time ago date
                cal.setTime(changeDate);
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                cal.set(Calendar.MILLISECOND, 0);
                Date date = cal.getTime();
                fuzzydate = getTimeUtils().timeAgo(date);
            }
            changeItem.add(new Label("whenChanged", fuzzydate + ", " + df.format(changeDate)));
            Label changeIcon = new Label("changeIcon");
            if (Type.DELETE.equals(change.getChangeType(fullRefName))) {
                WicketUtils.setCssClass(changeIcon, "iconic-trash-stroke");
            } else if (isTag) {
                WicketUtils.setCssClass(changeIcon, "iconic-tag");
            } else if (isTicket) {
                WicketUtils.setCssClass(changeIcon, "fa fa-ticket");
            } else {
                WicketUtils.setCssClass(changeIcon, "iconic-upload");
            }
            changeItem.add(changeIcon);
            if (change.user.username.equals(change.user.emailAddress) && change.user.emailAddress.indexOf('@') > -1) {
                // username is an email address - 1.2.1 push log bug
                changeItem.add(new Label("whoChanged", change.user.getDisplayName()));
            } else if (change.user.username.equals(UserModel.ANONYMOUS.username)) {
                // anonymous change
                changeItem.add(new Label("whoChanged", getString("gb.anonymousUser")));
            } else {
                // link to user account page
                changeItem.add(new LinkPanel("whoChanged", null, change.user.getDisplayName(), UserPage.class, WicketUtils.newUsernameParameter(change.user.username)));
            }
            boolean isDelete = false;
            boolean isRewind = false;
            String what;
            String by = null;
            switch(change.getChangeType(fullRefName)) {
                case CREATE:
                    if (isTag) {
                        // new tag
                        what = getString("gb.pushedNewTag");
                    } else {
                        // new branch
                        what = getString("gb.pushedNewBranch");
                    }
                    break;
                case DELETE:
                    isDelete = true;
                    if (isTag) {
                        what = getString("gb.deletedTag");
                    } else {
                        what = getString("gb.deletedBranch");
                    }
                    break;
                case UPDATE_NONFASTFORWARD:
                    isRewind = true;
                default:
                    what = MessageFormat.format(change.getCommitCount() > 1 ? getString("gb.pushedNCommitsTo") : getString("gb.pushedOneCommitTo"), change.getCommitCount());
                    if (change.getAuthorCount() == 1) {
                        by = MessageFormat.format(getString("gb.byOneAuthor"), change.getAuthorIdent().getName());
                    } else {
                        by = MessageFormat.format(getString("gb.byNAuthors"), change.getAuthorCount());
                    }
                    break;
            }
            changeItem.add(new Label("whatChanged", what));
            changeItem.add(new Label("byAuthors", by).setVisible(!StringUtils.isEmpty(by)));
            changeItem.add(new Label("refRewind", getString("gb.rewind")).setVisible(isRewind));
            if (isDelete) {
                // can't link to deleted ref
                changeItem.add(new Label("refChanged", shortRefName));
            } else if (isTag) {
                // link to tag
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TagPage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
            } else if (isTicket) {
                // link to ticket
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TicketsPage.class, WicketUtils.newObjectParameter(change.repository, ticketId)));
            } else {
                // link to tree
                changeItem.add(new LinkPanel("refChanged", null, shortRefName, TreePage.class, WicketUtils.newObjectParameter(change.repository, fullRefName)));
            }
            int maxCommitCount = 5;
            List<RepositoryCommit> commits = change.getCommits();
            if (commits.size() > maxCommitCount) {
                commits = new ArrayList<RepositoryCommit>(commits.subList(0, maxCommitCount));
            }
            // compare link
            String compareLinkText = null;
            if ((change.getCommitCount() <= maxCommitCount) && (change.getCommitCount() > 1)) {
                compareLinkText = MessageFormat.format(getString("gb.viewComparison"), commits.size());
            } else if (change.getCommitCount() > maxCommitCount) {
                int diff = change.getCommitCount() - maxCommitCount;
                compareLinkText = MessageFormat.format(diff > 1 ? getString("gb.nMoreCommits") : getString("gb.oneMoreCommit"), diff);
            }
            if (StringUtils.isEmpty(compareLinkText)) {
                changeItem.add(new Label("compareLink").setVisible(false));
            } else {
                String endRangeId = change.getNewId(fullRefName);
                String startRangeId = change.getOldId(fullRefName);
                changeItem.add(new LinkPanel("compareLink", null, compareLinkText, ComparePage.class, WicketUtils.newRangeParameter(change.repository, startRangeId, endRangeId)));
            }
            ListDataProvider<RepositoryCommit> cdp = new ListDataProvider<RepositoryCommit>(commits);
            DataView<RepositoryCommit> commitsView = new DataView<RepositoryCommit>("commit", cdp) {

                private static final long serialVersionUID = 1L;

                @Override
                public void populateItem(final Item<RepositoryCommit> commitItem) {
                    final RepositoryCommit commit = commitItem.getModelObject();
                    // author gravatar
                    commitItem.add(new AvatarImage("commitAuthor", commit.getAuthorIdent(), null, 16, false));
                    // merge icon
                    if (commit.getParentCount() > 1) {
                        commitItem.add(WicketUtils.newImage("commitIcon", "commit_merge_16x16.png"));
                    } else {
                        commitItem.add(WicketUtils.newBlankImage("commitIcon"));
                    }
                    // short message
                    String shortMessage = commit.getShortMessage();
                    String trimmedMessage = shortMessage;
                    if (commit.getRefs() != null && commit.getRefs().size() > 0) {
                        trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG_REFS);
                    } else {
                        trimmedMessage = StringUtils.trimString(shortMessage, Constants.LEN_SHORTLOG);
                    }
                    LinkPanel shortlog = new LinkPanel("commitShortMessage", "list", trimmedMessage, CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
                    if (!shortMessage.equals(trimmedMessage)) {
                        WicketUtils.setHtmlTooltip(shortlog, shortMessage);
                    }
                    commitItem.add(shortlog);
                    // commit hash link
                    int hashLen = app().settings().getInteger(Keys.web.shortCommitIdLength, 6);
                    LinkPanel commitHash = new LinkPanel("hashLink", null, commit.getName().substring(0, hashLen), CommitPage.class, WicketUtils.newObjectParameter(change.repository, commit.getName()));
                    WicketUtils.setCssClass(commitHash, "shortsha1");
                    WicketUtils.setHtmlTooltip(commitHash, commit.getName());
                    commitItem.add(commitHash);
                }
            };
            changeItem.add(commitsView);
        }
    };
    add(changeView);
}
Also used : ListDataProvider(org.apache.wicket.markup.repeater.data.ListDataProvider) Label(org.apache.wicket.markup.html.basic.Label) RefLogEntry(com.gitblit.models.RefLogEntry) TimeUtils(com.gitblit.utils.TimeUtils) Item(org.apache.wicket.markup.repeater.Item) TreePage(com.gitblit.wicket.pages.TreePage) Calendar(java.util.Calendar) ComparePage(com.gitblit.wicket.pages.ComparePage) RepositoryCommit(com.gitblit.models.RepositoryCommit) Date(java.util.Date) DataView(org.apache.wicket.markup.repeater.data.DataView) TimeZone(java.util.TimeZone) TicketsPage(com.gitblit.wicket.pages.TicketsPage) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 89 with DateFormat

use of java.text.DateFormat in project gitblit by gitblit.

the class FilterableRepositoryList method onInitialize.

@Override
protected void onInitialize() {
    super.onInitialize();
    String id = getId();
    String ngCtrl = id + "Ctrl";
    String ngList = id + "List";
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("ngCtrl", ngCtrl);
    values.put("ngList", ngList);
    // use Freemarker to setup an AngularJS/Wicket html snippet
    FreemarkerPanel panel = new FreemarkerPanel("listComponent", "FilterableRepositoryList.fm", values);
    panel.setParseGeneratedMarkup(true);
    panel.setRenderBodyOnly(true);
    add(panel);
    // add the Wicket controls that are referenced in the snippet
    String listTitle = StringUtils.isEmpty(title) ? getString("gb.repositories") : title;
    panel.add(new Label(ngList + "Title", MessageFormat.format("{0} ({1})", listTitle, repositories.size())));
    if (StringUtils.isEmpty(iconClass)) {
        panel.add(new Label(ngList + "Icon").setVisible(false));
    } else {
        Label icon = new Label(ngList + "Icon");
        WicketUtils.setCssClass(icon, iconClass);
        panel.add(icon);
    }
    if (allowCreate) {
        panel.add(new LinkPanel(ngList + "Button", "btn btn-mini", getString("gb.newRepository"), app().getNewRepositoryPage()));
    } else {
        panel.add(new Label(ngList + "Button").setVisible(false));
    }
    String format = app().settings().getString(Keys.web.datestampShortFormat, "MM/dd/yy");
    final DateFormat df = new SimpleDateFormat(format);
    df.setTimeZone(getTimeZone());
    // prepare the simplified repository models list
    List<RepoListItem> list = new ArrayList<RepoListItem>();
    for (RepositoryModel repo : repositories) {
        String name = StringUtils.stripDotGit(repo.name);
        String path = "";
        if (name.indexOf('/') > -1) {
            path = name.substring(0, name.lastIndexOf('/') + 1);
            name = name.substring(name.lastIndexOf('/') + 1);
        }
        RepoListItem item = new RepoListItem();
        item.n = name;
        item.p = path;
        item.r = repo.name;
        item.i = repo.description;
        item.s = app().repositories().getStarCount(repo);
        item.t = getTimeUtils().timeAgo(repo.lastChange);
        item.d = df.format(repo.lastChange);
        item.c = StringUtils.getColor(StringUtils.stripDotGit(repo.name));
        if (!repo.isBare) {
            item.y = 3;
        } else if (repo.isMirror) {
            item.y = 2;
        } else if (repo.isFork()) {
            item.y = 1;
        } else {
            item.y = 0;
        }
        list.add(item);
    }
    // inject an AngularJS controller with static data
    NgController ctrl = new NgController(ngCtrl);
    ctrl.addVariable(ngList, list);
    add(new HeaderContributor(ctrl));
}
Also used : NgController(com.gitblit.wicket.ng.NgController) HashMap(java.util.HashMap) Label(org.apache.wicket.markup.html.basic.Label) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) FreemarkerPanel(com.gitblit.wicket.freemarker.FreemarkerPanel) HeaderContributor(org.apache.wicket.behavior.HeaderContributor) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 90 with DateFormat

use of java.text.DateFormat in project gephi by gephi.

the class ExporterGEXF method getDateTime.

private String getDateTime() {
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    return dateFormat.format(date);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Aggregations

DateFormat (java.text.DateFormat)646 SimpleDateFormat (java.text.SimpleDateFormat)486 Date (java.util.Date)315 ParseException (java.text.ParseException)132 Calendar (java.util.Calendar)78 Test (org.junit.Test)69 ArrayList (java.util.ArrayList)48 IOException (java.io.IOException)43 File (java.io.File)31 HashMap (java.util.HashMap)27 GregorianCalendar (java.util.GregorianCalendar)24 TimeZone (java.util.TimeZone)23 Locale (java.util.Locale)18 Timestamp (java.sql.Timestamp)17 List (java.util.List)14 InputStream (java.io.InputStream)12 DateTime (org.joda.time.DateTime)11 Map (java.util.Map)10 Matcher (java.util.regex.Matcher)8 TestBean (org.springframework.tests.sample.beans.TestBean)8