}\r
return false;\r
}\r
-\r
- public static RefModel getTicketsBranch(Repository r) {\r
- RefModel ticgitBranch = null;\r
- try {\r
- // search for ticgit branch in local heads\r
- for (RefModel ref : getLocalBranches(r, -1)) {\r
- if (ref.displayName.endsWith("ticgit")) {\r
- ticgitBranch = ref;\r
- break;\r
- }\r
- }\r
-\r
- // search for ticgit branch in remote heads\r
- if (ticgitBranch == null) {\r
- for (RefModel ref : getRemoteBranches(r, -1)) {\r
- if (ref.displayName.endsWith("ticgit")) {\r
- ticgitBranch = ref;\r
- break;\r
- }\r
- }\r
- }\r
- } catch (Throwable t) {\r
- LOGGER.error("Failed to find ticgit branch!", t);\r
- }\r
- return ticgitBranch;\r
- }\r
-\r
- public static List<TicketModel> getTickets(Repository r) {\r
- RefModel ticgitBranch = getTicketsBranch(r);\r
- List<PathModel> paths = getFilesInPath(r, null, ticgitBranch.commit);\r
- List<TicketModel> tickets = new ArrayList<TicketModel>();\r
- for (PathModel ticketFolder : paths) {\r
- if (ticketFolder.isTree()) {\r
- try {\r
- TicketModel t = new TicketModel(ticketFolder.name);\r
- readTicketContents(r, ticgitBranch, t);\r
- tickets.add(t);\r
- } catch (Throwable t) {\r
- LOGGER.error("Failed to get a ticket!", t);\r
- }\r
- }\r
- }\r
- Collections.sort(tickets);\r
- Collections.reverse(tickets);\r
- return tickets;\r
- }\r
-\r
- public static TicketModel getTicket(Repository r, String ticketFolder) {\r
- RefModel ticketsBranch = getTicketsBranch(r);\r
- if (ticketsBranch != null) {\r
- try {\r
- TicketModel ticket = new TicketModel(ticketFolder);\r
- readTicketContents(r, ticketsBranch, ticket);\r
- return ticket;\r
- } catch (Throwable t) {\r
- LOGGER.error("Failed to get ticket " + ticketFolder, t);\r
- }\r
- }\r
- return null;\r
- }\r
-\r
- private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {\r
- List<PathModel> ticketFiles = getFilesInPath(r, ticket.name, ticketsBranch.commit);\r
- for (PathModel file : ticketFiles) {\r
- String content = getRawContentAsString(r, ticketsBranch.commit, file.path).trim();\r
- if (file.name.equals("TICKET_ID")) {\r
- ticket.id = content;\r
- } else if (file.name.equals("TITLE")) {\r
- ticket.title = content;\r
- } else {\r
- String[] chunks = file.name.split("_");\r
- if (chunks[0].equals("ASSIGNED")) {\r
- ticket.handler = content;\r
- } else if (chunks[0].equals("COMMENT")) {\r
- try {\r
- Comment c = new Comment(file.name, content);\r
- ticket.comments.add(c);\r
- } catch (ParseException e) {\r
- e.printStackTrace();\r
- }\r
- } else if (chunks[0].equals("TAG")) {\r
- if (content.startsWith("TAG_")) {\r
- ticket.tags.add(content.substring(4));\r
- } else {\r
- ticket.tags.add(content);\r
- }\r
- } else if (chunks[0].equals("STATE")) {\r
- ticket.state = content;\r
- }\r
- }\r
- }\r
- Collections.sort(ticket.comments);\r
- }\r
-\r
- public static String getTicketContent(Repository r, String filePath) {\r
- RefModel ticketsBranch = getTicketsBranch(r);\r
- if (ticketsBranch != null) {\r
- return getRawContentAsString(r, ticketsBranch.commit, filePath);\r
- }\r
- return "";\r
- }\r
}\r
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.utils;\r
+\r
+import java.text.ParseException;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.List;\r
+\r
+import org.eclipse.jgit.lib.Repository;\r
+import org.slf4j.Logger;\r
+import org.slf4j.LoggerFactory;\r
+\r
+import com.gitblit.models.PathModel;\r
+import com.gitblit.models.RefModel;\r
+import com.gitblit.models.TicketModel;\r
+import com.gitblit.models.TicketModel.Comment;\r
+\r
+public class TicgitUtils {\r
+\r
+ static final Logger LOGGER = LoggerFactory.getLogger(TicgitUtils.class);\r
+\r
+ public static RefModel getTicketsBranch(Repository r) {\r
+ RefModel ticgitBranch = null;\r
+ try {\r
+ // search for ticgit branch in local heads\r
+ for (RefModel ref : JGitUtils.getLocalBranches(r, -1)) {\r
+ if (ref.displayName.endsWith("ticgit")) {\r
+ ticgitBranch = ref;\r
+ break;\r
+ }\r
+ }\r
+\r
+ // search for ticgit branch in remote heads\r
+ if (ticgitBranch == null) {\r
+ for (RefModel ref : JGitUtils.getRemoteBranches(r, -1)) {\r
+ if (ref.displayName.endsWith("ticgit")) {\r
+ ticgitBranch = ref;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ } catch (Throwable t) {\r
+ LOGGER.error("Failed to find ticgit branch!", t);\r
+ }\r
+ return ticgitBranch;\r
+ }\r
+\r
+ public static List<TicketModel> getTickets(Repository r) {\r
+ RefModel ticgitBranch = getTicketsBranch(r);\r
+ List<PathModel> paths = JGitUtils.getFilesInPath(r, null, ticgitBranch.commit);\r
+ List<TicketModel> tickets = new ArrayList<TicketModel>();\r
+ for (PathModel ticketFolder : paths) {\r
+ if (ticketFolder.isTree()) {\r
+ try {\r
+ TicketModel t = new TicketModel(ticketFolder.name);\r
+ readTicketContents(r, ticgitBranch, t);\r
+ tickets.add(t);\r
+ } catch (Throwable t) {\r
+ LOGGER.error("Failed to get a ticket!", t);\r
+ }\r
+ }\r
+ }\r
+ Collections.sort(tickets);\r
+ Collections.reverse(tickets);\r
+ return tickets;\r
+ }\r
+\r
+ public static TicketModel getTicket(Repository r, String ticketFolder) {\r
+ RefModel ticketsBranch = getTicketsBranch(r);\r
+ if (ticketsBranch != null) {\r
+ try {\r
+ TicketModel ticket = new TicketModel(ticketFolder);\r
+ readTicketContents(r, ticketsBranch, ticket);\r
+ return ticket;\r
+ } catch (Throwable t) {\r
+ LOGGER.error("Failed to get ticket " + ticketFolder, t);\r
+ }\r
+ }\r
+ return null;\r
+ }\r
+\r
+ private static void readTicketContents(Repository r, RefModel ticketsBranch, TicketModel ticket) {\r
+ List<PathModel> ticketFiles = JGitUtils\r
+ .getFilesInPath(r, ticket.name, ticketsBranch.commit);\r
+ for (PathModel file : ticketFiles) {\r
+ String content = JGitUtils.getRawContentAsString(r, ticketsBranch.commit, file.path)\r
+ .trim();\r
+ if (file.name.equals("TICKET_ID")) {\r
+ ticket.id = content;\r
+ } else if (file.name.equals("TITLE")) {\r
+ ticket.title = content;\r
+ } else {\r
+ String[] chunks = file.name.split("_");\r
+ if (chunks[0].equals("ASSIGNED")) {\r
+ ticket.handler = content;\r
+ } else if (chunks[0].equals("COMMENT")) {\r
+ try {\r
+ Comment c = new Comment(file.name, content);\r
+ ticket.comments.add(c);\r
+ } catch (ParseException e) {\r
+ e.printStackTrace();\r
+ }\r
+ } else if (chunks[0].equals("TAG")) {\r
+ if (content.startsWith("TAG_")) {\r
+ ticket.tags.add(content.substring(4));\r
+ } else {\r
+ ticket.tags.add(content);\r
+ }\r
+ } else if (chunks[0].equals("STATE")) {\r
+ ticket.state = content;\r
+ }\r
+ }\r
+ }\r
+ Collections.sort(ticket.comments);\r
+ }\r
+\r
+ public static String getTicketContent(Repository r, String filePath) {\r
+ RefModel ticketsBranch = getTicketsBranch(r);\r
+ if (ticketsBranch != null) {\r
+ return JGitUtils.getRawContentAsString(r, ticketsBranch.commit, filePath);\r
+ }\r
+ return "";\r
+ }\r
+}\r
*/\r
package com.gitblit.utils;\r
\r
+import java.util.Calendar;\r
import java.util.Date;\r
\r
public class TimeUtils {\r
\r
public static final long ONEYEAR = ONEDAY * 365L;\r
\r
- @SuppressWarnings("deprecation")\r
public static boolean isToday(Date date) {\r
- Date now = new Date();\r
- return now.getDate() == date.getDate() && now.getMonth() == date.getMonth()\r
- && now.getYear() == date.getYear();\r
+ return (System.currentTimeMillis() - date.getTime()) < ONEDAY; \r
}\r
\r
- @SuppressWarnings("deprecation")\r
public static boolean isYesterday(Date date) {\r
- Date now = new Date();\r
- return now.getDate() == (date.getDate() + 1) && now.getMonth() == date.getMonth()\r
- && now.getYear() == date.getYear();\r
+ Calendar cal = Calendar.getInstance();\r
+ cal.setTime(date);\r
+ cal.add(Calendar.DATE, 1);\r
+ return (System.currentTimeMillis() - cal.getTimeInMillis()) < ONEDAY; \r
}\r
\r
public static String duration(int days) {\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.JGitUtils.SearchType;\r
import com.gitblit.utils.StringUtils;\r
+import com.gitblit.utils.TicgitUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.LinkPanel;\r
List<String> extraPageLinks = new ArrayList<String>();\r
\r
// Conditionally add tickets link\r
- if (model.useTickets && JGitUtils.getTicketsBranch(r) != null) {\r
+ if (model.useTickets && TicgitUtils.getTicketsBranch(r) != null) {\r
extraPageLinks.add("tickets");\r
}\r
\r
\r
import com.gitblit.models.TicketModel;\r
import com.gitblit.models.TicketModel.Comment;\r
-import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
+import com.gitblit.utils.TicgitUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
\r
final String ticketFolder = WicketUtils.getPath(params);\r
\r
Repository r = getRepository();\r
- TicketModel t = JGitUtils.getTicket(r, ticketFolder);\r
+ TicketModel t = TicgitUtils.getTicket(r, ticketFolder);\r
\r
add(new Label("ticketTitle", t.title));\r
add(new Label("ticketId", t.id));\r
import org.apache.wicket.markup.repeater.data.ListDataProvider;\r
\r
import com.gitblit.models.TicketModel;\r
-import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.StringUtils;\r
+import com.gitblit.utils.TicgitUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.LinkPanel;\r
public TicketsPage(PageParameters params) {\r
super(params);\r
\r
- List<TicketModel> tickets = JGitUtils.getTickets(getRepository());\r
+ List<TicketModel> tickets = TicgitUtils.getTickets(getRepository());\r
\r
// header\r
add(new LinkPanel("header", "title", repositoryName, SummaryPage.class,\r
suite.addTestSuite(ByteFormatTest.class);\r
suite.addTestSuite(JGitUtilsTest.class);\r
suite.addTestSuite(DiffUtilsTest.class);\r
+ suite.addTestSuite(MetricUtilsTest.class);\r
+ suite.addTestSuite(TicgitUtilsTest.class);\r
suite.addTestSuite(GitBlitTest.class);\r
return new GitBlitSuite(suite);\r
}\r
import org.eclipse.jgit.revwalk.RevTree;\r
\r
import com.gitblit.GitBlit;\r
-import com.gitblit.models.Metric;\r
import com.gitblit.models.PathModel.PathChangeModel;\r
import com.gitblit.models.RefModel;\r
-import com.gitblit.models.TicketModel;\r
-import com.gitblit.models.TicketModel.Comment;\r
import com.gitblit.utils.JGitUtils;\r
-import com.gitblit.utils.MetricUtils;\r
\r
public class JGitUtilsTest extends TestCase {\r
\r
zipFile.delete();\r
repository.close();\r
}\r
-\r
- public void testMetrics() throws Exception {\r
- Repository repository = GitBlitSuite.getHelloworldRepository();\r
- List<Metric> metrics = MetricUtils.getDateMetrics(repository, true);\r
- repository.close();\r
- assertTrue("No metrics found!", metrics.size() > 0);\r
- }\r
-\r
- public void testTicGit() throws Exception {\r
- Repository repository = GitBlitSuite.getTicgitRepository();\r
- RefModel branch = JGitUtils.getTicketsBranch(repository);\r
- assertTrue("Ticgit branch does not exist!", branch != null);\r
- List<TicketModel> ticketsA = JGitUtils.getTickets(repository);\r
- List<TicketModel> ticketsB = JGitUtils.getTickets(repository);\r
- repository.close();\r
- assertTrue("No tickets found!", ticketsA.size() > 0);\r
- for (int i = 0; i < ticketsA.size(); i++) {\r
- TicketModel ticketA = ticketsA.get(i);\r
- TicketModel ticketB = ticketsB.get(i);\r
- assertTrue("Tickets are not equal!", ticketA.equals(ticketB));\r
- assertFalse(ticketA.equals(""));\r
- assertTrue(ticketA.hashCode() == ticketA.id.hashCode());\r
- for (int j = 0; j < ticketA.comments.size(); j++) {\r
- Comment commentA = ticketA.comments.get(j);\r
- Comment commentB = ticketB.comments.get(j);\r
- assertTrue("Comments are not equal!", commentA.equals(commentB));\r
- assertFalse(commentA.equals(""));\r
- assertTrue(commentA.hashCode() == commentA.text.hashCode());\r
- }\r
- }\r
- }\r
}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import java.util.List;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.eclipse.jgit.lib.Repository;\r
+\r
+import com.gitblit.models.Metric;\r
+import com.gitblit.utils.MetricUtils;\r
+\r
+public class MetricUtilsTest extends TestCase {\r
+\r
+ public void testMetrics() throws Exception {\r
+ Repository repository = GitBlitSuite.getHelloworldRepository();\r
+ List<Metric> metrics = MetricUtils.getDateMetrics(repository, true);\r
+ repository.close();\r
+ assertTrue("No metrics found!", metrics.size() > 0);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/*\r
+ * Copyright 2011 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.tests;\r
+\r
+import java.util.List;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.eclipse.jgit.lib.Repository;\r
+\r
+import com.gitblit.models.RefModel;\r
+import com.gitblit.models.TicketModel;\r
+import com.gitblit.models.TicketModel.Comment;\r
+import com.gitblit.utils.TicgitUtils;\r
+\r
+public class TicgitUtilsTest extends TestCase {\r
+\r
+ public void testTicGit() throws Exception {\r
+ Repository repository = GitBlitSuite.getTicgitRepository();\r
+ RefModel branch = TicgitUtils.getTicketsBranch(repository);\r
+ assertTrue("Ticgit branch does not exist!", branch != null);\r
+ List<TicketModel> ticketsA = TicgitUtils.getTickets(repository);\r
+ List<TicketModel> ticketsB = TicgitUtils.getTickets(repository);\r
+ repository.close();\r
+ assertTrue("No tickets found!", ticketsA.size() > 0);\r
+ for (int i = 0; i < ticketsA.size(); i++) {\r
+ TicketModel ticketA = ticketsA.get(i);\r
+ TicketModel ticketB = ticketsB.get(i);\r
+ assertTrue("Tickets are not equal!", ticketA.equals(ticketB));\r
+ assertFalse(ticketA.equals(""));\r
+ assertTrue(ticketA.hashCode() == ticketA.id.hashCode());\r
+ for (int j = 0; j < ticketA.comments.size(); j++) {\r
+ Comment commentA = ticketA.comments.get(j);\r
+ Comment commentB = ticketB.comments.get(j);\r
+ assertTrue("Comments are not equal!", commentA.equals(commentB));\r
+ assertFalse(commentA.equals(""));\r
+ assertTrue(commentA.hashCode() == commentA.text.hashCode());\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file