Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
789 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.classpath | ||
.project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="ISO-8859-1"?> | ||
<project name="jsloccount" default="release"> | ||
<description> | ||
JSLoCCount - Calculate size metrics for various languages | ||
Vassilios Karakoidas (vassilios.karakoidas@gmail.com) - http://bkarak.wizhut.com/ | ||
</description> | ||
|
||
<!-- Property Declaration --> | ||
<property name="build" location="${basedir}/build"/> | ||
<property name="src" location="${basedir}/src"/> | ||
|
||
<!-- Compile and produce jar --> | ||
<target name="release"> | ||
<echo>Compiling JSLoCCount ...</echo> | ||
<mkdir dir="${build}" /> | ||
<javac srcdir="${src}" destdir="${build}" source="1.6" target="1.6" debug="off" optimize="on" /> | ||
<jar basedir="${build}" destfile="${basedir}/jsloccount.jar" manifest="${src}/Manifest" /> | ||
</target> | ||
|
||
<target name="clean"> | ||
<echo>Cleaning the mess ...</echo> | ||
<delete file="${basedir}/jsloccount.jar" /> | ||
<delete> | ||
<fileset dir="${build}" includes="**/*"/> | ||
</delete> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Created-By: 1.2 (Sun Microsystems Inc.) | ||
Main-Class: org.jsloc.Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package org.jsloc; | ||
|
||
import org.jsloc.logger.Logger; | ||
import org.jsloc.logger.NativeLogger; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
*/ | ||
public class Configuration { | ||
private final static Configuration defaultInstance; | ||
// | ||
private Logger logger; | ||
|
||
static { | ||
defaultInstance = new Configuration(); | ||
} | ||
|
||
public Configuration() { | ||
this.logger = new NativeLogger(); | ||
} | ||
|
||
public Logger getLogger() { | ||
return logger; | ||
} | ||
|
||
public static Configuration getInstance() { | ||
return defaultInstance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.jsloc; | ||
|
||
import java.io.File; | ||
|
||
import org.jsloc.logger.Logger; | ||
import org.jsloc.output.IkariaOutput; | ||
import org.jsloc.project.ProjectStatistics; | ||
import org.jsloc.resources.Resource; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
* | ||
*/ | ||
public class Main { | ||
|
||
private static void help() { | ||
Logger logger = Configuration.getInstance().getLogger(); | ||
|
||
logger.message("JSLoCcount - Vassilios Karakoidas (bkarak@aueb.gr)\n"); | ||
logger.message("usage:\n"); | ||
logger.message("java -jar jsloccount.jar <directory>\n"); | ||
|
||
logger.message("Supported Languages:\n"); | ||
for ( Resource r : Resource.values() ) { | ||
logger.message("* " + r.toString()); | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
Logger logger = Configuration.getInstance().getLogger(); | ||
|
||
if(args.length == 2) { | ||
if(args[0].compareToIgnoreCase("-d") == 0) { | ||
File f = new File(args[1]); | ||
if(f.exists() && f.isDirectory()) { | ||
for ( File ff : f.listFiles() ) { | ||
if(ff.isDirectory()) { | ||
main(new String[] { ff.getAbsolutePath() }); | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
} | ||
|
||
if(args.length == 1) { | ||
File f = new File(args[0]); | ||
if(f.exists() && f.isDirectory()) { | ||
ProjectStatistics ps = new ProjectStatistics(f); | ||
(new IkariaOutput(ps)).produce(); | ||
} else { | ||
logger.error("ERROR: " + f.getAbsolutePath() + " is not a directory"); | ||
} | ||
|
||
return; | ||
} | ||
|
||
help(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package org.jsloc.logger; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
* | ||
*/ | ||
public interface Logger { | ||
public void message(String msg); | ||
|
||
public void warning(String msg); | ||
|
||
public void error(String msg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jsloc.logger; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
* | ||
*/ | ||
public class NativeLogger implements Logger { | ||
|
||
public NativeLogger() {} | ||
|
||
@Override | ||
public void error(String msg) { | ||
System.out.println(msg); | ||
} | ||
|
||
@Override | ||
public void message(String msg) { | ||
System.out.println(msg); | ||
} | ||
|
||
@Override | ||
public void warning(String msg) { | ||
System.out.println(msg); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.jsloc.output; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
|
||
import org.jsloc.project.ProjectStatistics; | ||
import org.jsloc.resources.Resource; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
* | ||
*/ | ||
public abstract class AbstractOutput { | ||
protected ProjectStatistics projectStatistics; | ||
protected ArrayList<ResourceValue> sortedLoC; | ||
protected ArrayList<ResourceValue> sortedFiles; | ||
|
||
protected AbstractOutput(ProjectStatistics ps) { | ||
this.projectStatistics = ps; | ||
Resource[] langs = ps.getResources(); | ||
|
||
// sort by loc | ||
sortedLoC = new ArrayList<ResourceValue>(); | ||
sortedFiles = new ArrayList<ResourceValue>(); | ||
for ( Resource r : langs ) { | ||
if(r.isText()) { | ||
sortedLoC.add(new ResourceValue(r, ps.getLOC(r))); | ||
} | ||
sortedFiles.add(new ResourceValue(r, ps.getFileCount(r))); | ||
} | ||
Collections.sort(sortedLoC, new ResourceValue()); | ||
Collections.sort(sortedFiles, new ResourceValue()); | ||
} | ||
|
||
public abstract void produce(); | ||
} | ||
|
||
class ResourceValue implements Comparator<ResourceValue> { | ||
private Resource resource; | ||
private long value; | ||
|
||
// Used only for comparator | ||
ResourceValue() { | ||
this.resource = null; | ||
this.value = 0; | ||
} | ||
|
||
ResourceValue(Resource l, long value) { | ||
this.resource = l; | ||
this.value = value; | ||
} | ||
|
||
public Resource getResource() { | ||
return resource; | ||
} | ||
|
||
public long getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public int compare(ResourceValue lvalone, ResourceValue lvaltwo) { | ||
return (new Long(lvaltwo.value)).compareTo(new Long(lvalone.value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jsloc.output; | ||
|
||
import java.io.DataOutputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
|
||
import org.jsloc.project.ProjectStatistics; | ||
import org.jsloc.resources.Resource; | ||
|
||
public class IkariaOutput extends AbstractOutput { | ||
|
||
public IkariaOutput(ProjectStatistics ps) { | ||
super(ps); | ||
} | ||
|
||
public void produce() { | ||
if( sortedFiles.size() > 0) { | ||
Resource r = null; | ||
if (sortedFiles.size() > 2) { | ||
if (sortedFiles.get(0).getResource() == Resource.OTHER ) { | ||
r = sortedFiles.get(1).getResource(); | ||
} else { r = sortedFiles.get(0).getResource(); } | ||
} else { | ||
r = sortedFiles.get(0).getResource(); | ||
} | ||
System.out.println(this.projectStatistics.getProjectName() + ", " + r); | ||
} else { | ||
System.out.println(this.projectStatistics.getProjectName() + " - Unknown"); | ||
} | ||
|
||
StringBuilder strbld = new StringBuilder(); | ||
|
||
strbld.append("Project Name: ").append(this.projectStatistics.getProjectName()).append("\n"); | ||
strbld.append("\nNumber of Files:\n"); | ||
long totalFiles = this.projectStatistics.getTotalFileCount(); | ||
|
||
for ( ResourceValue lv : sortedFiles ) { | ||
if (lv.getResource() == Resource.OTHER) { continue; } | ||
strbld.append(lv.getResource().getName() + ", " + lv.getValue() + " / " + totalFiles).append("\n"); | ||
} | ||
strbld.append(Resource.OTHER.getName() + ", " + this.projectStatistics.getFileCount(Resource.OTHER) + " / " + totalFiles).append("\n"); | ||
|
||
strbld.append("\nNumber of Lines (comments):\n").append("\n"); | ||
for ( ResourceValue lv : sortedLoC ) { | ||
strbld.append(lv.getResource().getName() + ", " + lv.getValue() + " (" + this.projectStatistics.getLOCOM(lv.getResource()) + ")\n"); | ||
} | ||
|
||
try { | ||
DataOutputStream dos = new DataOutputStream(new FileOutputStream(this.projectStatistics.getProjectName() + ".jsloccount")); | ||
dos.writeChars(strbld.toString()); | ||
} catch (IOException ioe) { | ||
// silent resolve | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jsloc.output; | ||
|
||
import org.jsloc.project.ProjectStatistics; | ||
import org.jsloc.resources.Resource; | ||
|
||
/** | ||
* | ||
* | ||
* @author Vassilios Karakoidas (bkarak@aueb.gr) | ||
* | ||
*/ | ||
public class StandardOutput extends AbstractOutput{ | ||
|
||
public StandardOutput(ProjectStatistics ps) { | ||
super(ps); | ||
} | ||
|
||
@Override | ||
public void produce() { | ||
System.out.println("Number of Files:\n"); | ||
long totalFiles = this.projectStatistics.getTotalFileCount(); | ||
|
||
for ( ResourceValue lv : sortedFiles ) { | ||
if (lv.getResource() == Resource.OTHER) { continue; } | ||
System.out.println(lv.getResource().getName() + ", " + lv.getValue() + " / " + totalFiles); | ||
} | ||
System.out.println(Resource.OTHER.getName() + ", " + this.projectStatistics.getFileCount(Resource.OTHER) + " / " + totalFiles); | ||
|
||
System.out.println("\nNumber of Lines (comments):\n"); | ||
for ( ResourceValue lv : sortedLoC ) { | ||
System.out.println(lv.getResource().getName() + ", " + lv.getValue() + " (" + this.projectStatistics.getLOCOM(lv.getResource()) + ")"); | ||
} | ||
} | ||
} |
Oops, something went wrong.