Login | Register
My pages Projects Community openCollabNet

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

argouml-spl
Discussion topic

Back to topic list

svn commit: r125 - trunk/externalTools/MetricsGather/src/metrics

Author marcusvnac
Full name Marcus Vinícius de Ávila Couto
Date 2010-09-24 17:46:02 PDT
Message Author: marcusvnac
Date: 2010-09-24 17:46:02-0700
New Revision: 125

Modified:
   trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java
   trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a
   trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java

Log:
Add package and class counter.

Modified: trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java
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=125&r1=124​&r2=125
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/GatherMetrics.​java 2010-09-24 17:46:02-0700
@@ -18,10 +18,19 @@
      * Diretório raiz (onde se inicia a varredura).
      * */
     private String rootDir;
-
+
+ /**
+ * Processador de métricas.
+ */
     private MetricsProcessor metricsProcessor;
     
     /**
+ * Contador de pacotes Java
+ */
+ private static Integer PACKAGE_COUNTER;
+
+
+ /**
      * Filtro de diretórios.
      * */
     FilenameFilter dirFilter = new FilenameFilter() {
@@ -57,6 +66,7 @@
     public GatherMetrics(String rootDir) {
         this.rootDir = rootDir.replace("\\", File.separator);
         metricsProcessor = new MetricsProcessor();
+ PACKAGE_COUNTER = 0;
     }
     
     /**
@@ -64,7 +74,8 @@
      * @param filename Nome do arquivo que conterá as métricas
      */
     public void gatherMetrics(String filename) {
- this.listDir(new File(rootDir));
+ this.listDir(new File(rootDir));
+ metricsProcessor.ins​ertMetric(MetricType​.PACKAGE_NUMBER, PACKAGE_COUNTER);
         metricsProcessor.pro​cessGatheredMetrics(​);
         metricsProcessor.sav​eGatheredMetrics(fil​ename);
     }
@@ -81,17 +92,21 @@
     
     private void listDirFiles(File dir) {
         Log.debug(dir.toString());
- String[] children = dir.list(javaFileFilter);
- for (int i=0; i<children.length; i++) {
+ String[] children = dir.list(javaFileFilter);
+ int i;
+ for (i=0; i<children.length; i++) {
             Log.debug(children[i]);
             processFile(new File(dir, children[i]));
         }
+ // Se foi processado algum arquivo do diretório, considerar o pacote
+ if (i > 0) {
+ PACKAGE_COUNTER++;
+ }
     }
     
     private void processFile(File file) {
         try {
- BufferedReader br = new BufferedReader(new FileReader(file));
-
+ BufferedReader br = new BufferedReader(new FileReader(file));
             while (br.ready()) {
                 metricsProcessor.ins​ertMetric(br.readLin​e().trim());
             }

Modified: trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a
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=​125&r1=124&r​2=125
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricType.jav​a 2010-09-24 17:46:02-0700
@@ -6,7 +6,8 @@
  *
  */
 public enum MetricType {
- GRANULARITY("GranularityType"), LOCALIZATION("Localization"), OR("OR"), AND("AND"), LOC("LOC");
+ GRANULARITY("GranularityType"), LOCALIZATION("Localization"), OR("OR"), AND("AND"),
+ CLASS_NUMBER("#Classes"), PACKAGE_NUMBER("#Pacotes"), LOC("LOC");
     
      /** Origem da venda.*/
     private final String identifier;

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=125&r1=124​&r2=125
====================​====================​====================​==================
--- trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java (original)
+++ trunk/externalTools/​MetricsGather/src/me​trics/MetricsProcess​or.java 2010-09-24 17:46:02-0700
@@ -49,6 +49,16 @@
     private Integer locMetric;
     
     /**
+ * Contador de classes
+ */
+ private static Integer CLASS_COUNTER;
+
+ /**
+ * String para criação de métricas que não estão mapeadas diretamente nas classes.
+ */
+ private static final String FAKEMETRICIDENTIFIER = "//@#$LPS-%s:%s:N/A";
+
+ /**
      * Construtor padrão.
      */
     public MetricsProcessor(){
@@ -56,14 +66,25 @@
         localMetrics = new HashMap<String, Integer>();
         otherMetrics = new HashMap<String, Integer>();
         metrics = new Vector<Metric>();
- locMetric = new Integer(0);
+ locMetric = 0;
         startComment = false;
+ CLASS_COUNTER = 0;
+ }
+
+ /**
+ * Insere uma métrica já contabilizada
+ * @param line Indentificador da linha, para processamento posterior
+ * @param metricType Tipo da métrica
+ * @param value Valor calculado
+ */
+ private void insertMetric(String line, MetricType metricType, Integer value) {
+ otherMetrics.put(line, value);
     }
     
     /**
      * 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}
+ * @param metricType Tipo de métrica.
      */
     private void insertMetric(String line, MetricType metricType) {
         if (MetricType.LOC.equa​ls(metricType)) {
@@ -112,39 +133,53 @@
     }
     
     /**
+ * Insere uma métrica que não depende do conteúdo do arquivo Java.
+ * @param metricType Tipo da métrica.
+ * @param line Valor da métrica
+ */
+ public void insertMetric(MetricType metricType, Integer value) {
+ insertMetric(String.​format(FAKEMETRICIDE​NTIFIER, "TODAS", metricType.getIdentifier()), metricType, value);
+ }
+
+ /**
      * Contabiliza a métrica encontrada na linha do arquivo Java.
- * @param line linha lida da classe Java.
+ * @param value linha lida da classe Java.
      */
- public void insertMetric(String line) {
-
- line = line.trim();
+ public void insertMetric(String value) {
+ value = value.trim();
         // Common Metrics
- if (line.contains(Metri​csProcessor.IDENTIFI​ER)) {
- 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);
+ if (value.contains(Metr​icsProcessor.IDENTIF​IER)) {
+ if (value.contains(Metr​icType.GRANULARITY.g​etIdentifier())) {
+ insertMetric(value, MetricType.GRANULARITY);
+ } else if (value.contains(Metr​icType.LOCALIZATION.​getIdentifier())) {
+ insertMetric(value, MetricType.LOCALIZATION);
             } else{
- Log.info("Identificador inválido. Dados: " + line);
+ Log.info("Identificador inválido. Dados: " + value);
             }
- // LOC Metric
- } else if (!isCommentOrBlankLine(line)) {
- 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";
+ else if (value.matches("//#if defined\\(.*\\) (and|or) defined\\(.*\\)")) {
+ String feature1 = value.substring(valu​e.indexOf("(")+1, value.indexOf(")"));
+ String feature2 = value.substring(valu​e.lastIndexOf("(")+1​, value.lastIndexOf(")"));
                 
- 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);
+ if (value.toLowerCase()​.contains(MetricType​.OR.getIdentifier().​toLowerCase())) {
+ insertMetric(String.​format(FAKEMETRICIDE​NTIFIER, feature1, MetricType.OR.getIdentifier()), MetricType.OR);
+ insertMetric(String.​format(FAKEMETRICIDE​NTIFIER, feature2, 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);
+ insertMetric(String.​format(FAKEMETRICIDE​NTIFIER, feature1, MetricType.AND.getId​entifier()), MetricType.AND);
+ insertMetric(String.​format(FAKEMETRICIDE​NTIFIER, feature2, MetricType.AND.getId​entifier()), MetricType.AND);
             }
- }
+ }
+ // LOC Metric
+ else if (!isCommentOrBlankLine(value)) {
+ insertMetric(value, MetricType.LOC);
+ // Contabilizar classes
+ if (value.matches("(pri​vate|public|protecte​d){0,1}.*class .*")) {
+ CLASS_COUNTER++;
+ }
+ }
+
+
     }
     
     /**
@@ -173,6 +208,9 @@
      * @return <code>true</code> se processamento correto, <false> caso contrário.
      */
     public boolean processGatheredMetrics() {
+ // Inserir métrica que contabiliza o número de classes
+ insertMetric(MetricT​ype.CLASS_NUMBER, CLASS_COUNTER);
+ // Processar demais métricas.
         boolean result = this.processGathered​Metrics(otherMetrics​);
         result = result && this.processGathered​Metrics(granMetrics)​;
         result = result && this.processGathered​Metrics(localMetrics​);

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

Messages

Show all messages in topic

svn commit: r125 - trunk/externalTools/MetricsGather/src/metrics marcusvnac Marcus Vinícius de Ávila Couto 2010-09-24 17:46:02 PDT
Messages per page: