Login | Register
My pages Projects Community openCollabNet

Discussions > Commits > svn commit: r118 - trunk/externalTools/MetricsGather/src: foo metrics util

argouml-spl
Discussion topic

Back to topic list

svn commit: r118 - trunk/externalTools/MetricsGather/src: foo metrics util

Author marcusvnac
Full name Marcus Vinícius de Ávila Couto
Date 2010-09-15 16:37:10 PDT
Message Author: marcusvnac
Date: 2010-09-15 16:37:09-0700
New Revision: 118

Added:
   trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java
      - copied, changed from r117, /trunk/externalTools​/MetricsGather/src/f​oo/GatherMetrics.jav​a
   trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a
      - copied, changed from r117, /trunk/externalTools​/MetricsGather/src/m​etrics/MetricTypeEnu​m.java
   trunk/externalTools/​MetricsGather/src/ut​il/
   trunk/externalTools/​MetricsGather/src/ut​il/Log.java
      - copied, changed from r101, /trunk/externalTools​/MetricsGather/src/f​oo/Log.java
Removed:
   trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​
   trunk/externalTools/​MetricsGather/src/fo​o/Log.java
   trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java
Modified:
   trunk/externalTools/​MetricsGather/src/fo​o/Main.java
   trunk/externalTools/​MetricsGather/src/me​trics/Metric.java
   trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java

Log:
Add to calculate OR and AND metric.

Removed: 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​=117

Removed: 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=117

Modified: 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=diff​&pathrev=118&r1​=117&r2=118
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/fo​o/Main.java (original)
+++ trunk/externalTools/​MetricsGather/src/fo​o/Main.java 2010-09-15 16:37:09-0700
@@ -1,5 +1,8 @@
 package foo;
 
+import util.Log;
+import metrics.GatherMetrics;
+
 
 public class Main {
 

Copied: trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java (from r117, /trunk/externalTools​/MetricsGather/src/f​oo/GatherMetrics.jav​a)
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/GatherMetrics.java​?view=diff&pathr​ev=118&r1=117​&r2=118
====================​====================​====================​==================
--- /trunk/externalTools​/MetricsGather/src/f​oo/GatherMetrics.jav​a (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java 2010-09-15 16:37:09-0700
@@ -1,4 +1,4 @@
-package foo;
+package metrics;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -7,7 +7,9 @@
 import java.io.FilenameFilter;
 import java.io.IOException;
 
-import metrics.MetricsProcessor;
+import util.Log;
+
+
 
 
 public class GatherMetrics {
@@ -35,12 +37,6 @@
                     && !name.equals("lib") && !name.equals("bin") && !name.equals("templates")
                     && !name.equals("staging") && !name.equals("tests") && !name.equals("argouml-build")
                     && !name.equals("argoum​l-core-tools") && !name.equals("argoum​l-core-infra")
- /*
- && !name.equals("argoum​l-core-diagrams-sequ​ence2")
- && !name.equals("argoum​l-core-model")
- && !name.equals("argoum​l-core-model-euml")
- && !name.equals("argoum​l-core-model-mdr")
- && !name.equals("argouml-app")*/
                     );
             }
         };
@@ -51,7 +47,6 @@
     FilenameFilter javaFileFilter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
             return name.endsWith(".java");
- //&& name.equals("Designer.java");
             }
         };
         

Modified: 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=d​iff&pathrev=118​&r1=117&r2=11​8
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/Metric.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/Metric.java 2010-09-15 16:37:09-0700
@@ -1,5 +1,9 @@
 package metrics;
 
+/**
+ * Representa uma métrica, contendo suas submétricas e valores
+ * @author Marcus
+ */
 public class Metric {
     
     /**
@@ -20,21 +24,35 @@
         return feature;
     }
 
+ /**
+ * Construtor padrão.
+ * @param feature nome da 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.subMetrics = new SubMetric[MetricType​.values().length-1];​
+ for (int i=0; i<this.subMetrics.length; i++) {
+ this.subMetrics[i] = new SubMetric();
+ }
         this.feature = feature;
     }
     
- public SubMetric getSubMetric(MetricTypeEnum typeEnum) {
+ /**
+ * Retorna a submétrica.
+ * @param typeEnum tipo da métrica a retornar.
+ * @return submétroca encontada.
+ */
+ public SubMetric getSubMetric(MetricType typeEnum) {
         return this.subMetrics[type​Enum.ordinal()];
     }
     
- public void storeMetric(MetricTypeEnum metricType, String subMetric, Integer value) {
+ /**
+ * Armazena uma submétrica para a métrica.
+ * @param metricType Tipo da métrica.
+ * @param subMetric Tipo da submétrica.
+ * @param value Valor da submétrica.
+ */
+ public void storeMetric(MetricType metricType, String subMetric, Integer value) {
         this.subMetrics[metr​icType.ordinal()].ad​dValue(subMetric, value);
         
     }
-
 }

Copied: trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a (from r117, /trunk/externalTools​/MetricsGather/src/m​etrics/MetricTypeEnu​m.java)
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/metric​s/MetricType.java?vi​ew=diff&pathrev=​118&r1=117&r​2=118
====================​====================​====================​==================
--- /trunk/externalTools​/MetricsGather/src/m​etrics/MetricTypeEnu​m.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a 2010-09-15 16:37:09-0700
@@ -1,45 +1,39 @@
 package metrics;
 
-public enum MetricTypeEnum {
- GRAN(MetricsProcesso​r.GRAN_IDENTIFIER), LOCAL(MetricsProcess​or.LOCAL_IDENTIFIER)​, LOC(MetricsProcessor​.LOC_METRIC);
+/**
+ * Representa os tipos de métricas a serem contabilizadas.
+ * @author Marcus
+ *
+ */
+public enum MetricType {
+ GRANULARITY("GranularityType"), LOCALIZATION("Localization"), OR("OR"), AND("AND"), LOC("LOC");
     
      /** Origem da venda.*/
- private final String metricIdentifier;
-
+ private final String identifier;
+
     /**
      * Construtor protegido.
      * @param saleOrigin origem da venda.
      */
- private MetricTypeEnum(String metricIdentifier) {
- this.metricIdentifier = metricIdentifier;
+ private MetricType(String identifier) {
+ this.identifier = identifier;
     }
 
     /**
- * Retorna a origem da venda.
- * @return saleOrigin.
+ * Retorna o identificador da Métrica.
+ * @return Identificador da métrica.
      */
- public String getMetricIdentifier() {
- return this.metricIdentifier;
+ public String getIdentifier() {
+ return this.identifier;
     }
     
- public static MetricTypeEnum getByIdentifier(String metricIdentifier) {
- if (MetricTypeEnum.GRAN​.getMetricIdentifier​().equals(metricIden​tifier)) {
- return MetricTypeEnum.GRAN;
- } else if (MetricTypeEnum.LOCA​L.getMetricIdentifie​r().equals(metricIde​ntifier)) {
- return MetricTypeEnum.LOCAL;
- } else {
- return MetricTypeEnum.LOC;
+ public static MetricType getByIdentifier(String identifier) {
+ for (int i=0; i<MetricType.valu​es().length; i++) {
+ MetricType metricType = MetricType.values()[i];
+ if (metricType.getIdent​ifier().equals(ident​ifier)) {
+ return metricType;
+ }
         }
+ return null;
     }
-
- public static MetricTypeEnum getByOrd(Integer ord) {
- if (MetricTypeEnum.GRAN.ordinal() == ord) {
- return MetricTypeEnum.GRAN;
- } else if (MetricTypeEnum.LOCAL.ordinal() == ord) {
- return MetricTypeEnum.LOCAL;
- } else {
- return MetricTypeEnum.LOC;
- }
- }
-
 }

Removed: 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=117

Modified: 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=diff&pa​threv=118&r1=117​&r2=118
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java 2010-09-15 16:37:09-0700
@@ -11,31 +11,17 @@
 import java.util.Set;
 import java.util.Vector;
 
-import foo.Log;
+import util.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";
-
- /**
- * Identificador de métrica do tipo LOC
- */
- public static String LOC_METRIC = "LOC";
+ public static final String IDENTIFIER = "//@#$LPS-";
     
     /**
- * Último token lido.
+ * Informa se iniciou-se um comentário.
      */
     private boolean startComment;
     
@@ -46,7 +32,11 @@
     /**
      * Map para armazenar as métricas de localização.
      */
- private Map<String, Integer> localMetrics;
+ private Map<String, Integer> localMetrics;
+ /**
+ * Map para armazenar outras métricas.
+ */
+ private Map<String, Integer> otherMetrics;
     
     /**
      * Vetor que armazena as métricas processadas
@@ -64,6 +54,7 @@
     public MetricsProcessor(){
         granMetrics = new HashMap<String, Integer>();
         localMetrics = new HashMap<String, Integer>();
+ otherMetrics = new HashMap<String, Integer>();
         metrics = new Vector<Metric>();
         locMetric = new Integer(0);
         startComment = false;
@@ -74,15 +65,17 @@
      * @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) {
- if (MetricsProcessor.LO​C_METRIC.equals(metr​icType)) {
+ private void insertMetric(String line, MetricType metricType) {
+ if (MetricType.LOC.equa​ls(metricType)) {
             locMetric++;
         } else {
             Map<String, Integer> metricMap;
- if (MetricsProcessor.GR​AN_IDENTIFIER.equals​(metricType)) {
+ if (MetricType.GRANULAR​ITY.equals(metricTyp​e)) {
                 metricMap = granMetrics;
- } else {
+ } else if(MetricType.LOCALI​ZATION.equals(metric​Type)) {
                 metricMap = localMetrics;
+ } else {
+ metricMap = otherMetrics;
             }
 
             Integer value = 1;
@@ -114,7 +107,7 @@
         if (startComment) {
             return true;
         } else {
- return (line.startsWith("/") || line.startsWith("*") || line.length() == 0);
+ return (line.startsWith("//") || line.startsWith("*") || line.isEmpty());
         }
     }
     
@@ -125,21 +118,38 @@
     public void insertMetric(String line) {
         
         line = line.trim();
+ // Common Metrics
         if (line.contains(Metri​csProcessor.IDENTIFI​ER)) {
- 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);
+ if (line.contains(Metri​cType.GRANULARITY.ge​tIdentifier())) {
+ insertMetric(line, MetricType.GRANULARITY);
+ } else if (line.contains(Metri​cType.LOCALIZATION.g​etIdentifier())) {
+ insertMetric(line, MetricType.LOCALIZATION);
             } else{
                 Log.info("Identificador inválido. Dados: " + line);
- }
+ }
+ // LOC Metric
         } else if (!isCommentOrBlankLine(line)) {
- insertMetric(line, MetricsProcessor.LOC_METRIC);
+ insertMetric(line, MetricType.LOC);
+ // AND e OR Metrics
+ } else if (line.matches("//#if defined\\(.*\\) (and|or) defined\\(.*\\)")) {
+ String feature1 = line.substring(line.​indexOf("(")+1, line.indexOf(")"));
+ String feature2 = line.substring(line.​lastIndexOf("(")+1, line.lastIndexOf(")"));
+ String auxLine1 = "//@#$LPS-"+feature1+":%s:N/A";
+ String auxLine2 = "//@#$LPS-"+feature2+":%s:N/A";
+
+ if (line.toLowerCase().​contains(MetricType.​OR.getIdentifier().t​oLowerCase())) {
+ insertMetric(String.​format(auxLine1, MetricType.OR.getIdentifier()), MetricType.OR);
+ insertMetric(String.​format(auxLine2, MetricType.OR.getIdentifier()), MetricType.OR);
+ } else {
+ insertMetric(String.​format(auxLine1, MetricType.AND.getId​entifier()), MetricType.AND);
+ insertMetric(String.​format(auxLine2, MetricType.AND.getId​entifier()), MetricType.AND);
+ }
         }
     }
     
     /**
- * Retorna o índice da feature no Vetor de metricas. Caso a feature não exista no vetor, ela será inserida.
+ * 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
      */
@@ -158,12 +168,22 @@
         return index;
     }
     
+ /**
+ * Processa as métricas colhidas.
+ * @return <code>true</code> se processamento correto, <false> caso contrário.
+ */
     public boolean processGatheredMetrics() {
- boolean result = this.processGathered​Metrics(granMetrics)​;
+ boolean result = this.processGathered​Metrics(otherMetrics​);
+ result = result && this.processGathered​Metrics(granMetrics)​;
         result = result && this.processGathered​Metrics(localMetrics​);
         return result;
     }
     
+ /**
+ * Processa as métricas colhidas.
+ * @param metricMap Map contendo as métricas
+ * @return <code>true</code> se processamento correto, <false> caso contrário.
+ */
     private boolean processGatheredMetri​cs(Map<String, Integer> metricMap) {
         try {
             Set<String> keySet = metricMap.keySet();
@@ -176,7 +196,7 @@
                      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]),
+ metric.storeMetric(M​etricType.getByIdent​ifier(metricsTypeAnd​SubType[0]),
                              metricsTypeAndSubType[1], metricMap.get(key));
                  }
              }
@@ -187,6 +207,10 @@
         }
     }
     
+ /**
+ * Salva as métricas em arquivo, no formado CSV.
+ * @param filename nome do arquivo.
+ */
     public void saveGatheredMetrics(String filename) {
         String separator = ",";
         try {
@@ -196,7 +220,7 @@
              StringBuilder textOutput = new StringBuilder();
              textOutput.append("TODAS");
              textOutput.append(separator);
- textOutput.append(Me​tricTypeEnum.LOC.get​MetricIdentifier());​
+ textOutput.append(Me​tricType.LOC.getIden​tifier());
              textOutput.append(separator);
              textOutput.append("N/A");
              textOutput.append(separator);
@@ -205,21 +229,19 @@
 
              for (Iterator<Metric> it = metrics.iterator(); it.hasNext();) {
                  Metric metric = (Metric) it.next();
-
- for (int i=0; i<=MetricTypeEnum​.LOCAL.ordinal(); i++) {
- // processar métricas de granularidade
- Set<String> keySet = metric.getSubMetric(​MetricTypeEnum.getBy​Ord(i)).getValues().​keySet();
+ for (int i=0; i<MetricType.valu​es().length-1; i++) {
+ Set<String> keySet = metric.getSubMetric(​MetricType.values()[​i]).getValues().keyS​et();
                      for (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
                          String key = iterator.next();
                          if(key != null) {
                              textOutput = new StringBuilder();
                              textOutput.append(me​tric.getFeature());
                              textOutput.append(separator);
- textOutput.append(Me​tricTypeEnum.getByOr​d(i).getMetricIdenti​fier());
+ textOutput.append(Me​tricType.values()[i]​.getIdentifier());
                              textOutput.append(separator);
                              textOutput.append(key);
                              textOutput.append(separator);
- textOutput.append(me​tric.getSubMetric(Me​tricTypeEnum.getByOr​d(i)).getValues().ge​t(key));
+ textOutput.append(me​tric.getSubMetric(Me​tricType.values()[i]​).getValues().get(ke​y));
                              pw.println(textOutput);
                          }
                      }

Copied: trunk/externalTools/​MetricsGather/src/ut​il/Log.java (from r101, /trunk/externalTools​/MetricsGather/src/f​oo/Log.java)
Url: http://argouml-spl.t​igris.org/source/bro​wse/argouml-spl/trun​k/externalTools/Metr​icsGather/src/util/L​og.java?view=diff​&pathrev=118&r1​=101&r2=118
====================​====================​====================​==================
--- /trunk/externalTools​/MetricsGather/src/f​oo/Log.java (original)
+++ trunk/externalTools/​MetricsGather/src/ut​il/Log.java 2010-09-15 16:37:09-0700
@@ -1,8 +1,11 @@
-package foo;
+package util;
 
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
-
+/**
+ * Simples geração da log da aplicação
+ * @author Marcus
+ */
 public class Log {
      /** Mascara com a formatação de data. */
     private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
@@ -14,14 +17,26 @@
         return "[" + Log.DATE_FORMAT.form​at(Calendar.getInsta​nce().getTime()) + "] ";
     }
     
+ /**
+ * Gera um log informativo.
+ * @param msg Mensagem do log.
+ */
     public static void info(String msg) {
         System.out.println(L​og.getDate() + "[INFO] " + msg);
     }
-
+
+ /**
+ * Gera um log para debug.
+ * @param msg Mensagem do log.
+ */
     public static void debug(String msg) {
         //System.out.println​(Log.getDate() + "[DEBUG] " + msg);
     }
-
+
+ /**
+ * Gera um log de erro.
+ * @param msg Mensagem do log.
+ */
     public static void error(String msg) {
         System.err.println(L​og.getDate() + "[ERROR] " + msg);
     }

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

Messages

Show all messages in topic

svn commit: r118 - trunk/externalTools/MetricsGather/src: foo metrics util marcusvnac Marcus Vinícius de Ávila Couto 2010-09-15 16:37:10 PDT
Messages per page: