The Unified and Autonomous Development Platform
add loc and sloc
steveb7bc727ee955
diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/FileBlob.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/FileBlob.javaindex 2aa7b35313..97b41ed0c7 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/FileBlob.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/FileBlob.java@@ -3,6 +3,7 @@ package com.pmease.gitop.web.page.project.source.blob;import java.io.File;import java.io.IOException;import java.nio.charset.Charset;+import java.util.Collections;import java.util.List;import javax.annotation.Nullable;@@ -25,6 +26,8 @@ import org.gitective.core.CommitUtils;import com.google.common.base.Optional;import com.google.common.base.Preconditions;+import com.google.common.base.Throwables;+import com.google.common.io.CharStreams;import com.ibm.icu.text.CharsetDetector;import com.ibm.icu.text.CharsetMatch;import com.pmease.commons.git.Git;@@ -208,6 +211,21 @@ public class FileBlob {return mode == FileMode.EXECUTABLE_FILE;}+// private static final Splitter LINE_SPLITTER = Splitter.on(Pattern.compile("\r\n|\n|\r"));++ public List<String> getLines() {+ if (isLarge() || !isText() || data == null) {+ Collections.emptyList();+ }++ try {+ return CharStreams.readLines(+ CharStreams.newReaderSupplier(getStringContent()));+ } catch (IOException e) {+ throw Throwables.propagate(e);+ }+ }+public String getObjectId() {return objectId;}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.html b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.htmlindex 39c2f9614f..2d4e00898e 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.html+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.html@@ -4,7 +4,7 @@<div class="blob-head clearfix"><div class="left blob-meta"><span><i class="icon" wicket:id="typeicon"></i> <span wicket:id="mode"></span></span>- <span>36 lines (31 sloc)</span>+ <span><wicket:container wicket:id="loc"></wicket:container> lines (<wicket:container wicket:id="sloc"></wicket:container> sloc)</span><span wicket:id="size"></span></div><div class="right blob-actions btn-toolbar">diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.javaindex 76633ef5a9..140fe7ef0b 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/SourceBlobPanel.java@@ -2,6 +2,7 @@ package com.pmease.gitop.web.page.project.source.blob;import java.util.List;+import org.apache.commons.lang3.StringUtils;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;@@ -71,6 +72,32 @@ public class SourceBlobPanel extends AbstractSourcePagePanel {}));+ add(new Label("loc", new AbstractReadOnlyModel<Integer>() {++ @Override+ public Integer getObject() {+ return getBlob().getLines().size();+ }++ }));++ add(new Label("sloc", new AbstractReadOnlyModel<Integer>() {++ @Override+ public Integer getObject() {+ List<String> lines = getBlob().getLines();+ int sloc = 0;+ for (String each : lines) {+ if (!StringUtils.isEmpty(each)) {+ sloc++;+ }+ }++ return sloc;+ }++ }));+BlobRenderer renderer = getRenderer();add(renderer.render("body", blobModel));}diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.javaindex 584d0ffc3b..f73a225ab0 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/page/project/source/blob/renderer/TextBlobPanel.java@@ -1,5 +1,7 @@package com.pmease.gitop.web.page.project.source.blob.renderer;+import java.util.List;+import org.apache.wicket.behavior.AttributeAppender;import org.apache.wicket.markup.html.basic.Label;import org.apache.wicket.markup.html.panel.Panel;@@ -7,8 +9,6 @@ import org.apache.wicket.model.AbstractReadOnlyModel;import org.apache.wicket.model.IModel;import org.apache.wicket.util.string.Strings;-import com.google.common.base.Splitter;-import com.google.common.collect.Iterables;import com.pmease.gitop.web.page.project.source.blob.FileBlob;import com.pmease.gitop.web.service.impl.Language;import com.pmease.gitop.web.util.MimeTypeUtils;@@ -28,9 +28,8 @@ public class TextBlobPanel extends Panel {@Overridepublic String getObject() {- String content = getBlob().getStringContent();- Iterable<String> it = Splitter.on("\n").split(content);- int size = Iterables.size(it);+ List<String> lines = getBlob().getLines();+ int size = lines.size();StringBuffer sb = new StringBuffer();for (int i = 0; i < size; i++) {int lineno = i + 1;diff --git a/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/TikaFileTypeRegistry.java b/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/TikaFileTypeRegistry.javaindex 62f3ea7984..5c34d3b6a8 100644--- a/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/TikaFileTypeRegistry.java+++ b/gitop.web/src/main/java/com/pmease/gitop/web/service/impl/TikaFileTypeRegistry.java@@ -84,9 +84,7 @@ public class TikaFileTypeRegistry implements FileTypeRegistry {"image/bmp","image/png","image/jpeg",- "image/gif",- "image/x-xbitmap", // xbm- "image/x-xpixmap" // xpm+ "image/gif");