Login | Register
My pages Projects Community openCollabNet

Discussions > Commits > svn commit: r101 - trunk/externalTools/MetricsGather: . src src/foo src/metrics

argouml-spl
Discussion topic

Back to topic list

svn commit: r101 - trunk/externalTools/MetricsGather: . src src/foo src/metrics

Author marcusvnac
Full name Marcus Vinícius de Ávila Couto
Date 2010-08-11 17:25:36 PDT
Message Author: marcusvnac
Date: 2010-08-11 17:25:35-0700
New Revision: 101

Added:
   trunk/externalTools/​MetricsGather/.class​path
   trunk/externalTools/​MetricsGather/.proje​ct
   trunk/externalTools/​MetricsGather/src/
   trunk/externalTools/​MetricsGather/src/fo​o/
   trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​ (contents, props changed)
   trunk/externalTools/​MetricsGather/src/fo​o/Log.java (contents, props changed)
   trunk/externalTools/​MetricsGather/src/fo​o/Main.java (contents, props changed)
   trunk/externalTools/​MetricsGather/src/me​trics/
   trunk/externalTools/​MetricsGather/src/me​trics/Metric.java (contents, props changed)
   trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java (contents, props changed)
   trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java (contents, props changed)
   trunk/externalTools/​MetricsGather/src/me​trics/SubMetric.java​ (contents, props changed)

Log:
Initial import. This software gather metrics from ArgoUML-SPL.

Added: trunk/externalTools/​MetricsGather/.class​path
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/.classpath​?view=markup&pat​hrev=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/.class​path 2010-08-11 17:25:35-0700
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jd​t.launching.JRE_CONT​AINER"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>

Added: trunk/externalTools/​MetricsGather/.proje​ct
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/.project?v​iew=markup&pathr​ev=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/.proje​ct 2010-08-11 17:25:35-0700
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>MetricsG​ather</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.ecli​pse.jdt.core.javabui​lder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.ec​lipse.jdt.core.javan​ature</nature>​
+ </natures>
+</projectDescription>

Added: trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/foo/Ga​therMetrics.java?vie​w=markup&pathrev​=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​ 2010-08-11 17:25:35-0700
@@ -0,0 +1,105 @@
+package foo;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FilenameFilter;
+import java.io.IOException;
+
+import metrics.MetricsProcessor;
+
+
+public class GatherMetrics {
+
+ /**
+ * Diretório raiz (onde se inicia a varredura).
+ * */
+ private String rootDir;
+
+ private MetricsProcessor metricsProcessor;
+
+ /**
+ * Filtro para não listar diretórios iniciados com '.'
+ * */
+ FilenameFilter dirFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return (!name.startsWith(".") && !name.endsWith(".properties") && !name.endsWith(".xml")
+ && !name.endsWith(".launch") && !name.endsWith(".log") && !name.endsWith(".txt")
+ && !name.endsWith(".ico") && !name.endsWith(".bat") && !name.endsWith(".sh")
+ && !name.endsWith(".MF") && !name.endsWith(".ini") && !name.endsWith(".class")
+ && !name.endsWith(".java") && !name.startsWith("build") && !name.equals("META-INF")
+ && !name.equals("lib") && !name.equals("bin") && !name.equals("templates")
+ && !name.equals("staging"));
+ }
+ };
+
+ /**
+ * Filtro para listar apenas os arquivos .java
+ * */
+ FilenameFilter javaFileFilter = new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".java");
+ }
+ };
+
+ /**
+ * Construtor padrão
+ * @param rootDir Diretório raiz (onde se inicia a varredura).
+ */
+ public GatherMetrics(String rootDir) {
+ this.rootDir = rootDir.replace("\\", File.separator);
+ metricsProcessor = new MetricsProcessor();
+ }
+
+ /**
+ * Colhe as métricas e as salva em arquivo.
+ * @param filename Nome do arquivo que conterá as métricas
+ */
+ public void gatherMetrics(String filename) {
+ this.listDir(new File(rootDir));
+ metricsProcessor.pro​cessGatheredMetrics(​);
+ metricsProcessor.sav​eGatheredMetrics(fil​ename);
+ }
+
+ private void listDir(File dir) {
+ if (dir.isDirectory()) {
+ listDirFiles(dir);
+ String[] children = dir.list(dirFilter);
+ for (int i=0; i<children.length; i++) {
+ listDir(new File(dir, children[i]));
+ }
+ }
+ }
+
+ private void listDirFiles(File dir) {
+ Log.debug(dir.toString());
+ String[] children = dir.list(javaFileFilter);
+ for (int i=0; i<children.length; i++) {
+ Log.debug(children[i]);
+ processFile(new File(dir, children[i]));
+ }
+ }
+
+ private void processFile(File file) {
+ try {
+ BufferedReader br = new BufferedReader(new FileReader(file));
+
+ while (br.ready()) {
+ String line = br.readLine().trim();
+ if (line.contains(Metri​csProcessor.IDENTIFI​ER)) {
+ metricsProcessor.ins​ertMetric(line);
+ }
+ }
+ br.close();
+ } catch (FileNotFoundException e) {
+ Log.error(e.getMessage());
+ e.printStackTrace();
+ } catch (IOException e) {
+ Log.error(e.getMessage());
+ e.printStackTrace();
+ }
+
+ }
+}
+
\ No newline at end of file

Added: trunk/externalTools/​MetricsGather/src/fo​o/Log.java
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/foo/Lo​g.java?view=markup​&pathrev=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/fo​o/Log.java 2010-08-11 17:25:35-0700
@@ -0,0 +1,28 @@
+package foo;
+
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+
+public class Log {
+ /** Mascara com a formatação de data. */
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+
+ /**
+ * @return a data atual formatada de acordo com o {@link #DATE_FORMAT}
+ */
+ private static String getDate() {
+ return "[" + Log.DATE_FORMAT.form​at(Calendar.getInsta​nce().getTime()) + "] ";
+ }
+
+ public static void info(String msg) {
+ System.out.println(L​og.getDate() + "[INFO] " + msg);
+ }
+
+ public static void debug(String msg) {
+ //System.out.println​(Log.getDate() + "[DEBUG] " + msg);
+ }
+
+ public static void error(String msg) {
+ System.err.println(L​og.getDate() + "[ERROR] " + msg);
+ }
+}

Added: trunk/externalTools/​MetricsGather/src/fo​o/Main.java
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/foo/Ma​in.java?view=markup​&pathrev=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/fo​o/Main.java 2010-08-11 17:25:35-0700
@@ -0,0 +1,19 @@
+package foo;
+
+
+public class Main {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ String outputFilename = "..\\metrics.csv";
+ Log.info("Starting gattering metrics");
+
+ GatherMetrics rd = new GatherMetrics("..\​..\\workspace-arg​ouml-spl");
+ rd.gatherMetrics(out​putFilename);
+
+ Log.info("End of gattering metrics. File " + outputFilename + " generated.");
+ }
+
+}

Added: trunk/externalTools/​MetricsGather/src/me​trics/Metric.java
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/Metric.java?view=m​arkup&pathrev=10​1
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/me​trics/Metric.java 2010-08-11 17:25:35-0700
@@ -0,0 +1,40 @@
+package metrics;
+
+public class Metric {
+
+ /**
+ * Nome da feature a qual se refere a metrica;
+ */
+ private final String feature;
+
+ /**
+ * Array contendo o tipo de métrica: Granularidade ou Localização.
+ */
+ private SubMetric[] subMetrics;
+
+ /**
+ * Retorna o nome da feature
+ * @return Nome da feature.
+ */
+ public String getFeature() {
+ return feature;
+ }
+
+ public Metric(String feature) {
+ this.subMetrics = new SubMetric[2];
+ this.subMetrics[Metr​icTypeEnum.GRAN.ordi​nal()] = new SubMetric();
+ this.subMetrics[Metr​icTypeEnum.LOCAL.ord​inal()] = new SubMetric();
+
+ this.feature = feature;
+ }
+
+ public SubMetric getSubMetric(MetricTypeEnum typeEnum) {
+ return this.subMetrics[type​Enum.ordinal()];
+ }
+
+ public void storeMetric(MetricTypeEnum metricType, String subMetric, Integer value) {
+ this.subMetrics[metr​icType.ordinal()].ad​dValue(subMetric, value);
+
+ }
+
+}

Added: trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/MetricTypeEnum.jav​a?view=markup&pa​threv=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java 2010-08-11 17:25:35-0700
@@ -0,0 +1,41 @@
+package metrics;
+
+public enum MetricTypeEnum {
+ GRAN(MetricsProcesso​r.GRAN_IDENTIFIER), LOCAL(MetricsProcess​or.LOCAL_IDENTIFIER)​;
+
+ /** Origem da venda.*/
+ private final String metricIdentifier;
+
+ /**
+ * Construtor protegido.
+ * @param saleOrigin origem da venda.
+ */
+ private MetricTypeEnum(String metricIdentifier) {
+ this.metricIdentifier = metricIdentifier;
+ }
+
+ /**
+ * Retorna a origem da venda.
+ * @return saleOrigin.
+ */
+ public String getMetricIdentifier() {
+ return this.metricIdentifier;
+ }
+
+ public static MetricTypeEnum getByIdentifier(String metricIdentifier) {
+ if (MetricTypeEnum.GRAN​.getMetricIdentifier​().equals(metricIden​tifier)) {
+ return MetricTypeEnum.GRAN;
+ } else {
+ return MetricTypeEnum.LOCAL;
+ }
+ }
+
+ public static MetricTypeEnum getByOrd(Integer ord) {
+ if (MetricTypeEnum.GRAN.ordinal() == ord) {
+ return MetricTypeEnum.GRAN;
+ } else {
+ return MetricTypeEnum.LOCAL;
+ }
+ }
+
+}

Added: trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/MetricsProcessor.j​ava?view=markup&​pathrev=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java 2010-08-11 17:25:35-0700
@@ -0,0 +1,178 @@
+package metrics;
+
+import java.io.BufferedWriter;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Vector;
+
+import foo.Log;
+
+public class MetricsProcessor {
+ /**
+ * Identificador de anotação de métrica.
+ */
+ public static String IDENTIFIER = "//@#$LPS-";
+
+ /**
+ * Identificador de tipo anotação de métrica de granularidade.
+ */
+ public static String GRAN_IDENTIFIER = "GranularityType";
+
+ /**
+ * Identificador de tipo anotação de métrica de localozação.
+ */
+ public static String LOCAL_IDENTIFIER = "Localization";
+
+ /**
+ * Map para armazenar as métricas de granularidade.
+ */
+ private Map<String, Integer> granMetrics;
+ /**
+ * Map para armazenar as métricas de localização.
+ */
+ private Map<String, Integer> localMetrics;
+
+ /**
+ * Vetor que armazena as métricas processadas
+ */
+ private Vector<Metric> metrics;
+
+ /**
+ * Construtor padrão.
+ */
+ public MetricsProcessor(){
+ granMetrics = new HashMap<String, Integer>();
+ localMetrics = new HashMap<String, Integer>();
+ metrics = new Vector<Metric>();
+ }
+
+ /**
+ * Contabilizar as métricas por tipo.
+ * @param line linha lida da classe Java.
+ * @param metricType Tipo de métrica. {@link #GRAN_IDENTIFIER} {@link #LOCAL_IDENTIFIER}
+ */
+ private void insertMetric(String line, String metricType) {
+ Map<String, Integer> metricMap;
+ if (MetricsProcessor.GR​AN_IDENTIFIER.equals​(metricType)) {
+ metricMap = granMetrics;
+ } else {
+ metricMap = localMetrics;
+ }
+
+ Integer value = 1;
+ if (metricMap.containsKey(line)) {
+ value = metricMap.get(line);
+ value++;
+ }
+ metricMap.put(line, value);
+ }
+
+ /**
+ * Contabiliza a métrica encontrada na linha do arquivo Java.
+ * @param line linha lida da classe Java.
+ */
+ public void insertMetric(String line) {
+ if (line.contains(Metri​csProcessor.GRAN_IDE​NTIFIER)) {
+ insertMetric(line, MetricsProcessor.GRA​N_IDENTIFIER);
+ } else if (line.contains(Metri​csProcessor.LOCAL_ID​ENTIFIER)) {
+ insertMetric(line, MetricsProcessor.LOC​AL_IDENTIFIER);
+ } else {
+ Log.info("Identificador inválido. Dados: " + line);
+ }
+ }
+
+ /**
+ * Retorna o índice da feature no Vetor de metricas. Caso a feature não exista no vetor, ela será inserida.
+ * @param feature Nome da feature
+ * @return índice da feature no vetor de metricas
+ */
+ private Integer getFeatureMetricIndex(String feature) {
+ Integer index = -1;
+ for (int i = 0; i < metrics.size(); i++) {
+ Metric m = (Metric) metrics.get(i);
+ if (m.getFeature().equa​ls(feature)) {
+ index = i;
+ }
+ }
+ if (index == -1) {
+ metrics.add(new Metric(feature));
+ index = metrics.size()-1;
+ }
+ return index;
+ }
+
+ public boolean processGatheredMetrics() {
+ boolean result = this.processGathered​Metrics(granMetrics)​;
+ result = result && this.processGathered​Metrics(localMetrics​);
+ return result;
+ }
+
+ private boolean processGatheredMetri​cs(Map<String, Integer> metricMap) {
+ try {
+ Set<String> keySet = metricMap.keySet();
+ for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
+ String key = iterator.next();
+ if(key != null) {
+ Log.debug(key + " - " + metricMap.get(key));
+
+ String feature = key.substring(key.in​dexOf("-")+1, key.indexOf(":"));
+ String[] metricsTypeAndSubType = key.substring(key.in​dexOf(":")+1).split(​":");
+ Integer featureIndex = getFeatureMetricIndex(feature);
+ Metric metric = metrics.get(featureIndex);
+ metric.storeMetric(M​etricTypeEnum.getByI​dentifier(metricsTyp​eAndSubType[0]),
+ metricsTypeAndSubType[1], metricMap.get(key));
+ }
+ }
+ return true;
+ } catch (Exception e) {
+ Log.error(e.getMessage());
+ return false;
+ }
+ }
+
+ public void saveGatheredMetrics(String filename) {
+ String separator = ",";
+ try {
+ PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
+ pw.println("FEATURE" + separator + "TIPO_METRICA" + separator + "METRICA" + separator + "VALOR");
+
+ for (Iterator<Metric> it = metrics.iterator(); it.hasNext();) {
+ Metric metric = (Metric) it.next();
+
+ for (int i=0; i< MetricTypeEnum.values().length; i++) {
+ // processar métricas de granularidade
+ Set<String> keySet = metric.getSubMetric(​MetricTypeEnum.getBy​Ord(i)).getValues().​keySet();
+ for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
+ String key = iterator.next();
+ if(key != null) {
+ StringBuilder textOutput = new StringBuilder();
+ textOutput.append(me​tric.getFeature());
+ textOutput.append(separator);
+ textOutput.append(Me​tricTypeEnum.getByOr​d(i).getMetricIdenti​fier());
+ textOutput.append(separator);
+ textOutput.append(key);
+ textOutput.append(separator);
+ textOutput.append(me​tric.getSubMetric(Me​tricTypeEnum.getByOr​d(i)).getValues().ge​t(key));
+ pw.println(textOutput);
+ }
+ }
+ pw.flush();
+ }
+ }
+ pw.close();
+
+ } catch (FileNotFoundException e) {
+ Log.error(e.getMessage());
+ e.printStackTrace();
+ } catch (IOException e) {
+ Log.error(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+}

Added: trunk/externalTools/​MetricsGather/src/me​trics/SubMetric.java​
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/SubMetric.java?vie​w=markup&pathrev​=101
====================​====================​====================​==================
--- (empty file)
+++ trunk/externalTools/​MetricsGather/src/me​trics/SubMetric.java​ 2010-08-11 17:25:35-0700
@@ -0,0 +1,28 @@
+package metrics;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class SubMetric {
+ /**
+ * Tipo da medição efetuada para a métrica.
+ */
+ private Map<String, Integer> metricSubType;
+
+ public SubMetric() {
+ this.metricSubType = new HashMap<String, Integer>();
+ }
+
+ /**
+ * Insere submétrica com valor
+ * @param subMetric submétrica da métrica.
+ */
+ public void addValue(String subMetric, Integer value) {
+ metricSubType.put(subMetric, value);
+ }
+
+ public Map<String, Integer> getValues() {
+ return this.metricSubType;
+ }
+
+}

« Previous message in topic | 1 of 1 | Next message in topic »

Messages

Show all messages in topic

svn commit: r101 - trunk/externalTools/MetricsGather: . src src/foo src/metrics marcusvnac Marcus Vinícius de Ávila Couto 2010-08-11 17:25:36 PDT
Messages per page: