Login | Register
My pages Projects Community openCollabNet

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

argouml-spl
Discussion topic

Back to topic list

svn commit: r117 - trunk/externalTools/MetricsGather/src: foo metrics

Author marcusvnac
Full name Marcus Vinícius de Ávila Couto
Date 2010-09-11 17:25:51 PDT
Message Author: marcusvnac
Date: 2010-09-11 17:25:50-0700
New Revision: 117

Modified:
   trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​
   trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java
   trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java

Log:
Enabling gathering LOC metric

Modified: 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=diff&pathrev=1​17&r1=116&r2​=117
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​ (original)
+++ trunk/externalTools/​MetricsGather/src/fo​o/GatherMetrics.java​ 2010-09-11 17:25:50-0700
@@ -20,17 +20,28 @@
     private MetricsProcessor metricsProcessor;
     
     /**
- * Filtro para não listar diretórios iniciados com '.'
+ * Filtro de diretórios.
      * */
     FilenameFilter dirFilter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
- return (!name.startsWith(".") && !name.endsWith(".properties") && !name.endsWith(".xml")
+ name = name.toLowerCase();
+ return (!name.startsWith(".") && !name.startsWith("build")
+ && !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.endsWith(".mf") && !name.endsWith(".ini") && !name.endsWith(".class")
+ && !name.endsWith(".java") && !name.endsWith(".html") && !name.endsWith(".gif")
+ && !name.equals("meta-inf")
                     && !name.equals("lib") && !name.equals("bin") && !name.equals("templates")
- && !name.equals("staging"));
+ && !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")*/
+ );
             }
         };
 
@@ -40,6 +51,7 @@
     FilenameFilter javaFileFilter = new FilenameFilter() {
         public boolean accept(File dir, String name) {
             return name.endsWith(".java");
+ //&& name.equals("Designer.java");
             }
         };
         
@@ -86,10 +98,7 @@
             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);
- }
+ metricsProcessor.ins​ertMetric(br.readLin​e().trim());
             }
             br.close();
         } catch (FileNotFoundException e) {

Modified: 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=diff&path​rev=117&r1=116​&r2=117
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricTypeEnum​.java 2010-09-11 17:25:50-0700
@@ -1,7 +1,7 @@
 package metrics;
 
 public enum MetricTypeEnum {
- GRAN(MetricsProcesso​r.GRAN_IDENTIFIER), LOCAL(MetricsProcess​or.LOCAL_IDENTIFIER)​;
+ GRAN(MetricsProcesso​r.GRAN_IDENTIFIER), LOCAL(MetricsProcess​or.LOCAL_IDENTIFIER)​, LOC(MetricsProcessor​.LOC_METRIC);
     
      /** Origem da venda.*/
     private final String metricIdentifier;
@@ -25,17 +25,21 @@
     public static MetricTypeEnum getByIdentifier(String metricIdentifier) {
         if (MetricTypeEnum.GRAN​.getMetricIdentifier​().equals(metricIden​tifier)) {
             return MetricTypeEnum.GRAN;
- } else {
+ } else if (MetricTypeEnum.LOCA​L.getMetricIdentifie​r().equals(metricIde​ntifier)) {
             return MetricTypeEnum.LOCAL;
+ } else {
+ return MetricTypeEnum.LOC;
         }
     }
 
- public static MetricTypeEnum getByOrd(Integer ord) {
+ public static MetricTypeEnum getByOrd(Integer ord) {
         if (MetricTypeEnum.GRAN.ordinal() == ord) {
             return MetricTypeEnum.GRAN;
- } else {
+ } else if (MetricTypeEnum.LOCAL.ordinal() == ord) {
             return MetricTypeEnum.LOCAL;
- }
+ } else {
+ return MetricTypeEnum.LOC;
+ }
     }
     
 }

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=117&r1=116​&r2=117
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java 2010-09-11 17:25:50-0700
@@ -28,6 +28,16 @@
      * 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";
+
+ /**
+ * Último token lido.
+ */
+ private boolean startComment;
     
     /**
      * Map para armazenar as métricas de granularidade.
@@ -43,6 +53,11 @@
      */
     private Vector<Metric> metrics;
     
+ /**
+ * Armazena métrica LOC.
+ */
+ private Integer locMetric;
+
     /**
      * Construtor padrão.
      */
@@ -50,6 +65,8 @@
         granMetrics = new HashMap<String, Integer>();
         localMetrics = new HashMap<String, Integer>();
         metrics = new Vector<Metric>();
+ locMetric = new Integer(0);
+ startComment = false;
     }
     
     /**
@@ -58,33 +75,67 @@
      * @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++;
+ if (MetricsProcessor.LO​C_METRIC.equals(metr​icType)) {
+ locMetric++;
+ } else {
+ 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);
         }
- metricMap.put(line, value);
     }
     
     /**
+ * Verifica se a linha é um comentário ou linha em branco
+ * @param line linha a ser verificada
+ * @return <code>true</code> se a linha for comentário ou branco,
+ * <code>false</code> caso contrário.
+ */
+ private boolean isCommentOrBlankLine(String line) {
+ if (line.startsWith("/*")) {
+ if (line.endsWith("*/")) {
+ return true;
+ }
+ startComment = true;
+ return true;
+ } else if (startComment && line.endsWith("*/")) {
+ startComment = false;
+ return true;
+ }
+ if (startComment) {
+ return true;
+ } else {
+ return (line.startsWith("/") || line.startsWith("*") || line.length() == 0);
+ }
+ }
+
+ /**
      * 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);
- }
+
+ line = line.trim();
+ 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);
+ } else{
+ Log.info("Identificador inválido. Dados: " + line);
+ }
+ } else if (!isCommentOrBlankLine(line)) {
+ insertMetric(line, MetricsProcessor.LOC_METRIC);
+ }
     }
     
     /**
@@ -141,17 +192,27 @@
         try {
              PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(filename)));
              pw.println("FEATURE" + separator + "TIPO_METRICA" + separator + "METRICA" + separator + "VALOR");
+ // Gravar LOC
+ StringBuilder textOutput = new StringBuilder();
+ textOutput.append("TODAS");
+ textOutput.append(separator);
+ textOutput.append(Me​tricTypeEnum.LOC.get​MetricIdentifier());​
+ textOutput.append(separator);
+ textOutput.append("N/A");
+ textOutput.append(separator);
+ textOutput.append(th​is.locMetric);
+ pw.println(textOutput);
 
              for (Iterator<Metric> it = metrics.iterator(); it.hasNext();) {
                  Metric metric = (Metric) it.next();
                  
- for (int i=0; i< MetricTypeEnum.values().length; i++) {
+ 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 (Iterator<String> iterator = keySet.iterator(); iterator.hasNext();) {
                          String key = iterator.next();
                          if(key != null) {
- StringBuilder textOutput = new StringBuilder();
+ textOutput = new StringBuilder();
                              textOutput.append(me​tric.getFeature());
                              textOutput.append(separator);
                              textOutput.append(Me​tricTypeEnum.getByOr​d(i).getMetricIdenti​fier());

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

Messages

Show all messages in topic

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