Example #1
0
  public void execute() {
    try {
      // Only execute the reports for the profiler if the snapshot interval is set
      long snapshptInterval = Configuration.getConfiguration().getSnapshotInterval();
      logger.error("Reporter : ");
      if (snapshptInterval < 0) {
        return;
      }
      try {
        // Write the style sheet first
        File file = new File("./" + IConstants.STYLE_SHEET_FILE);
        if (!file.exists()) {
          InputStream inputStream =
              Reporter.class.getResourceAsStream(IConstants.REPORT_STYLE_SHEET);
          Toolkit.setContents(file, Toolkit.getContents(inputStream).toByteArray());
        }
      } catch (Exception e) {
        logger.error("Exception writing the style sheet : ", e);
      }

      String html = methodSeries(dataBase);
      writeReport(IConstants.METHOD_SERIES_FILE, html);
    } catch (Exception e) {
      logger.error("Exception writing the reports", e);
    }
    super.execute();
  }
 /**
  * Clears the data in the database.
  *
  * @param dataBase the database to truncate
  */
 @SuppressWarnings("unchecked")
 public static synchronized void clear(IDataBase dataBase) {
   Project<?, ?> project =
       (Project<?, ?>) dataBase.find(Project.class, Toolkit.hash(Project.class.getName()));
   if (project != null) {
     dataBase.remove(Project.class, project.getId());
   }
   List<Package> packages = dataBase.find(Package.class);
   for (Composite<?, ?> composite : packages) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Class> classes = dataBase.find(Class.class);
   for (Composite composite : classes) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Method> methods = dataBase.find(Method.class);
   for (Composite composite : methods) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Line> lines = dataBase.find(Line.class);
   for (Composite composite : lines) {
     dataBase.remove(composite.getClass(), composite.getId());
   }
   List<Snapshot> snapshots = dataBase.find(Snapshot.class);
   for (Snapshot snapshot : snapshots) {
     dataBase.remove(Snapshot.class, snapshot.getId());
   }
 }
 @SuppressWarnings("unchecked")
 private static synchronized void collectEfferentAndAfferent(Class klass, List<Package> packages) {
   List<Efferent> efferents = klass.getEfferent();
   for (Efferent efferent : efferents) {
     String efferentPackage = Toolkit.replaceAll(efferent.getName(), "<e:", "");
     efferentPackage = Toolkit.replaceAll(efferent.getName(), ">", "");
     for (Package pakkage : packages) {
       List<Class> children = pakkage.getChildren();
       for (Class child : children) {
         List<Afferent> afferents = child.getAfferent();
         for (Afferent afferent : afferents) {
           String afferentPackage = Toolkit.replaceAll(afferent.getName(), "<a:", "");
           afferentPackage = Toolkit.replaceAll(afferent.getName(), ">", "");
           if (efferentPackage.equals(afferentPackage)) {
             Collector.collectEfferentAndAfferent(klass.getName(), child.getName());
           }
         }
       }
     }
   }
 }
Example #4
0
 /**
  * Writes the report data to the file system.
  *
  * @param name the name of the report
  * @param html the html to write in the file
  */
 private void writeReport(String name, String html) {
   try {
     File file = new File(name);
     if (!file.getParentFile().exists()) {
       //noinspection ResultOfMethodCallIgnored
       file.getParentFile().mkdirs();
     }
     if (!file.exists()) {
       //noinspection ResultOfMethodCallIgnored
       file.createNewFile();
     }
     logger.error("Writing report : " + file.getAbsolutePath());
     Toolkit.setContents(file, html.getBytes(IConstants.ENCODING));
   } catch (Exception e) {
     logger.error("Exception writing report : " + name, e);
   }
 }
Example #5
0
  protected String buildGraph(String seriesDirectory, Method<?, ?> method, List<Double> datas) {
    XYSeries series = new XYSeries("XYGraph", false, false);

    double snapshot = 0;
    for (Double data : datas) {
      double seconds = TimeUnit.NANOSECONDS.toSeconds(data.intValue());
      series.add(snapshot++, seconds);
    }

    XYSeriesCollection seriesCollection = new XYSeriesCollection();
    seriesCollection.addSeries(series);
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            null,
            "Snapshots",
            "Time",
            seriesCollection,
            PlotOrientation.VERTICAL,
            false,
            false,
            false);
    chart.setTitle(new TextTitle(method.getName(), new Font("Arial", Font.BOLD, 11)));

    XYPlot xyPlot = chart.getXYPlot();
    NumberAxis yAxis = (NumberAxis) xyPlot.getRangeAxis();
    yAxis.setAutoRange(true);
    yAxis.setAutoRangeIncludesZero(true);

    NumberAxis xAxis = (NumberAxis) xyPlot.getDomainAxis();
    xAxis.setAutoRange(true);
    xAxis.setAutoRangeIncludesZero(true);
    // xAxis.setTickUnit(new NumberTickUnit(1));

    StringBuilder builder = new StringBuilder(method.getClassName());
    builder.append(method.getName());
    builder.append(method.getDescription());

    String fileName = Long.toString(Toolkit.hash(builder.toString()));
    fileName += ".jpeg";

    File chartSeriesDirectory = new File(IConstants.chartDirectory, seriesDirectory);
    File chartFile = new File(chartSeriesDirectory, fileName);
    try {
      if (!IConstants.chartDirectory.exists()) {
        //noinspection ResultOfMethodCallIgnored
        IConstants.chartDirectory.mkdirs();
      }
      if (!chartSeriesDirectory.exists()) {
        //noinspection ResultOfMethodCallIgnored
        chartSeriesDirectory.mkdirs();
      }
      if (!chartFile.exists()) {
        //noinspection ResultOfMethodCallIgnored
        chartFile.createNewFile();
      }
      ChartUtilities.saveChartAsJPEG(chartFile, chart, 450, 150);
      builder = new StringBuilder(IConstants.CHARTS);
      builder.append(File.separatorChar);
      builder.append(seriesDirectory);
      builder.append(File.separatorChar);
      builder.append(fileName);

      return builder.toString();
    } catch (Exception e) {
      logger.error("Exception generating the graph", e);
    }
    return null;
  }
 /**
  * Dumps the database to the output stream.
  *
  * @param dataBase the database to dump
  * @param criteria the criteria to match if the data for the composite must be written to the
  *     output
  */
 @SuppressWarnings("unchecked")
 public static synchronized void dump(IDataBase dataBase, ICriteria criteria, String message) {
   if (message != null) {
     logger.warn(message);
   }
   try {
     Object object = dataBase.find(Project.class, Toolkit.hash(Project.class.getName()));
     logger.info(object.toString());
     Project<?, ?> project =
         (Project<?, ?>) dataBase.find(Project.class, Toolkit.hash(Project.class.getName()));
     if (project != null) {
       logger.warn("Project : " + project.getName());
     }
   } catch (Exception e) {
     logger.error("Exception dumping the data for the project object.", e);
   }
   try {
     List<Package> packages = dataBase.find(Package.class);
     for (Package<?, ?> pakkage : packages) {
       log(
           criteria,
           pakkage,
           1,
           pakkage.getId()
               + " : "
               + pakkage.getName()
               + ", coverage : "
               + pakkage.getCoverage()
               + ", complexity : "
               + pakkage.getComplexity()
               + ", stability : "
               + pakkage.getStability());
       for (Class<?, ?> klass : ((List<Class<?, ?>>) pakkage.getChildren())) {
         log(
             criteria,
             klass,
             2,
             " : id : "
                 + klass.getId()
                 + " : name : "
                 + klass.getName()
                 + " : coverage : "
                 + klass.getCoverage()
                 + ", complexity : "
                 + klass.getComplexity()
                 + ", outer class : "
                 + klass.getOuterClass()
                 + ", outer method : "
                 + klass.getOuterMethod()
                 + ", lines : "
                 + klass.getChildren().size()
                 + ", inner classes : "
                 + klass.getInnerClasses());
         List<Efferent> efferents = klass.getEfferent();
         List<Afferent> afferents = klass.getAfferent();
         for (Efferent efferent : efferents) {
           log(criteria, efferent, 4, efferent.getName());
         }
         for (Afferent afferent : afferents) {
           log(criteria, afferent, 4, afferent.getName());
         }
         for (Method<?, ?> method : ((List<Method<?, ?>>) klass.getChildren())) {
           log(
               criteria,
               method,
               3,
               method.getId()
                   + " : name : "
                   + method.getName()
                   + " : description : "
                   + method.getDescription()
                   + " : coverage : "
                   + method.getCoverage()
                   + ", complexity : "
                   + method.getComplexity()
                   + ", start time : "
                   + method.getStartTime()
                   + ", end time : "
                   + method.getEndTime());
           for (Line<?, ?> line : ((List<Line<?, ?>>) method.getChildren())) {
             log(
                 criteria,
                 line,
                 4,
                 line.getId()
                     + " : number : "
                     + line.getNumber()
                     + ", counter : "
                     + line.getCounter());
           }
         }
       }
     }
   } catch (Exception e) {
     logger.error("Exception dumping the data for the database.", e);
   }
 }