Skip to content

Commit 817b2d6

Browse files
sahydosahydo
sahydo
authored and
sahydo
committed
Primera versión de ARAT.
Obtiene el valor de las anotaciones por reflexión Genera el reporte con itext5
1 parent 283f65c commit 817b2d6

26 files changed

+821
-0
lines changed

nbproject/project.properties

Whitespace-only changes.

pom.xml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.unicauca</groupId>
5+
<artifactId>arat</artifactId>
6+
<version>1</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>1.8</maven.compiler.source>
11+
<maven.compiler.target>1.8</maven.compiler.target>
12+
</properties>
13+
<dependencies>
14+
<dependency>
15+
<groupId>com.itextpdf</groupId>
16+
<artifactId>itextpdf</artifactId>
17+
<version>5.5.13</version>
18+
</dependency>
19+
<!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports -->
20+
<dependency>
21+
<groupId>net.sf.jasperreports</groupId>
22+
<artifactId>jasperreports</artifactId>
23+
<version>6.6.0</version>
24+
</dependency>
25+
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
26+
<dependency>
27+
<groupId>org.reflections</groupId>
28+
<artifactId>reflections</artifactId>
29+
<version>0.9.9-RC1</version>
30+
</dependency>
31+
<dependency>
32+
<groupId>junit</groupId>
33+
<artifactId>junit</artifactId>
34+
<version>4.12</version>
35+
<scope>test</scope>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.hamcrest</groupId>
39+
<artifactId>hamcrest-core</artifactId>
40+
<version>1.3</version>
41+
<scope>test</scope>
42+
</dependency>
43+
</dependencies>
44+
<name>Architectural Rationale Annotations Tool</name>
45+
<description>Tool to document Architectutal Rationale in the source code with source code annotations.</description>
46+
</project>
25.2 KB
Binary file not shown.

resources/image1.jpg

117 KB
Loading

resources/image2.jpg

38.9 KB
Loading

resources/unicauca.png

25 KB
Loading

results/objects/chapter_title.pdf

1.22 KB
Binary file not shown.

results/tables/image_next_to_text.pdf

121 KB
Binary file not shown.
162 KB
Binary file not shown.

results/tables/list_with_images.pdf

772 Bytes
Binary file not shown.
24.7 KB
Binary file not shown.

results/tables/simple_table11.pdf

1.01 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.unicauca.arat.business.model;
7+
8+
/**
9+
*
10+
* @author sahydo
11+
*/
12+
public class Information {
13+
private String path;
14+
private String name;
15+
private String type;
16+
17+
public Information(String path, String name, String type) {
18+
this.path = path;
19+
this.name = name;
20+
this.type = type;
21+
}
22+
23+
public Information() {
24+
}
25+
26+
public String getPath() {
27+
return path;
28+
}
29+
30+
public void setPath(String path) {
31+
this.path = path;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public String getType() {
43+
return type;
44+
}
45+
46+
public void setType(String type) {
47+
this.type = type;
48+
}
49+
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.unicauca.arat.business.model;
7+
8+
import java.lang.annotation.Documented;
9+
import static java.lang.annotation.ElementType.METHOD;
10+
import static java.lang.annotation.ElementType.PACKAGE;
11+
import static java.lang.annotation.ElementType.TYPE;
12+
import java.lang.annotation.Retention;
13+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
14+
import java.lang.annotation.Target;
15+
16+
/**
17+
*
18+
* @author sahydo
19+
*/
20+
//Para que aparezcan los componentes marcados con esta anotación en el documento generado por javadoc
21+
@Documented
22+
//Retención del archivo de clases en tiempo de ejecución para acceder por Reflección
23+
@Retention(RUNTIME)
24+
//Objetivo de anotación: métodos, clases y clases pagacke-info que representan los paquetes
25+
@Target({METHOD,PACKAGE,TYPE})
26+
public @interface Rationale {
27+
enum AtributoDeCalidad {ADECUACION_FUNCIONAL, EFICIENCIA_DESEMPENIO, COMPATIBILIDAD, USABILIDAD,
28+
FIABILIDAD, SEGURIDAD, MANTENIBILIDAD, PORTABILIDAD}
29+
String id() default "";
30+
boolean hiden() default false;
31+
AtributoDeCalidad[] atributos_de_calidad(); //1
32+
String[] causas();//2
33+
String[] tacticas() default {};//3
34+
String[] patrones() default {};//4
35+
String[] alternativas() default {}; //5
36+
String[] registro_de_decisiones();//6
37+
String[] razones();//7
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.unicauca.arat.business.tools.reporter;
2+
3+
//import java.lang.annotation.Annotation;
4+
import com.unicauca.arat.business.model.Rationale;
5+
import java.lang.reflect.Method;
6+
//import java.util.ArrayList;
7+
import java.util.Set;
8+
9+
import org.reflections.Reflections;
10+
import org.reflections.scanners.MethodAnnotationsScanner;
11+
import org.reflections.scanners.TypeAnnotationsScanner;
12+
import org.reflections.util.ClasspathHelper;
13+
import org.reflections.util.ConfigurationBuilder;
14+
import org.reflections.util.FilterBuilder;
15+
//import org.unicauca.annotations.model.Component;
16+
17+
18+
public class AnnotationsReflection {
19+
private Reflections reflections;
20+
21+
public AnnotationsReflection(String modelPackage){
22+
//Se debe especificar el tipo de scanners que se quieren ejecutar (Type y Method)
23+
//Se debe especificar la url del paquete que se quiere inspeccionar
24+
//se debe agregar un filtro para realizar las busquedas en el paquete
25+
reflections = new Reflections(
26+
new ConfigurationBuilder()
27+
.setUrls(ClasspathHelper.forPackage(modelPackage))
28+
.setScanners(
29+
new TypeAnnotationsScanner(),
30+
new MethodAnnotationsScanner()
31+
)
32+
.filterInputsBy(new FilterBuilder().includePackage(modelPackage))
33+
);
34+
}
35+
public Set<Method> getMethodsAnnotatedWithRationale(){
36+
return reflections.getMethodsAnnotatedWith(Rationale.class);
37+
}
38+
public Set<Class<?>> getClasesAnnotatedWhitRationale(){
39+
return reflections.getTypesAnnotatedWith(Rationale.class);
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.unicauca.arat.business.tools.reporter;
2+
3+
import com.itextpdf.text.Document;
4+
import com.unicauca.arat.business.model.Information;
5+
import com.unicauca.arat.business.model.Rationale;
6+
import java.util.HashMap;
7+
8+
public interface ReportStrategy {
9+
//
10+
public abstract void createTemplate(HashMap<Information,Rationale> rationaleInformation, Document document);
11+
public abstract void createRationaleInfo(Document document, Rationale rationale);
12+
public abstract boolean generateReport(HashMap<Information,Rationale> rationaleInformation,String dest);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.unicauca.arat.business.tools.reporter;
2+
3+
import com.unicauca.arat.business.model.Information;
4+
import com.unicauca.arat.business.model.Rationale;
5+
import java.io.File;
6+
import java.lang.reflect.Method;
7+
import java.util.HashMap;
8+
import java.util.Set;
9+
10+
public class Reporter {
11+
private ReportStrategy reportStrategy;
12+
private AnnotationsReflection reflection;
13+
14+
public Reporter(ReportStrategy reportStrategy, String packageName) {
15+
this.reportStrategy = reportStrategy;
16+
this.reflection = new AnnotationsReflection(packageName);
17+
}
18+
19+
public HashMap<Information,Rationale> getRationaleInformation(){
20+
Set<Class<?>> annotatedClasses = reflection.getClasesAnnotatedWhitRationale();
21+
Set<Method> annotatedMethods = reflection.getMethodsAnnotatedWithRationale();
22+
HashMap<Information,Rationale> data = new HashMap<>();
23+
annotatedMethods.forEach((annotatedMethod) -> {
24+
String aux[] = annotatedMethod.toString().split(" ");
25+
String path = aux[aux.length-1];
26+
String name = annotatedMethod.getName();
27+
String type = annotatedMethod.getClass().getSimpleName();
28+
Information info = new Information(path, name, type);
29+
for (Rationale rationale : annotatedMethod.getAnnotationsByType(Rationale.class)) {
30+
data.put(info, rationale);
31+
}
32+
});
33+
annotatedClasses.forEach((annotatedClass) -> {
34+
String path = annotatedClass.getCanonicalName();
35+
String name = annotatedClass.getSimpleName();
36+
String type = annotatedClass.getClass().getSimpleName();
37+
Information info;
38+
if (name.equals("package-info")) {
39+
info = new Information(path, name, "Package");
40+
}else{
41+
info = new Information(path, name, type);
42+
}
43+
for (Rationale rationale : annotatedClass.getAnnotationsByType(Rationale.class)) {
44+
data.put(info, rationale);
45+
}
46+
});
47+
return data;
48+
}
49+
50+
public boolean createRationaleReport(String nameFile) {
51+
return reportStrategy.generateReport(getRationaleInformation(),setNameFile(nameFile));
52+
}
53+
54+
public void setStrategy(ReportStrategy strategy) {
55+
this.reportStrategy = strategy;
56+
}
57+
58+
59+
private String setNameFile(String nameFile) {
60+
nameFile = "reports/"+nameFile+".pdf";
61+
File file = new File(nameFile);
62+
file.getParentFile().mkdirs();
63+
return nameFile;
64+
}
65+
66+
}

0 commit comments

Comments
 (0)