Projekt

Obecné

Profil

« Předchozí | Další » 

Revize af223c76

Přidáno uživatelem Tomáš Šimandl před více než 5 roky(ů)

Added template for creating of plugins

Zobrazit rozdíly:

plugins/_template/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0"
3
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
    <modelVersion>4.0.0</modelVersion>
6

  
7
    <groupId>com.example.plugin</groupId>
8
    <artifactId>imiger-plugin-template</artifactId>
9
    <version>1.0-SNAPSHOT</version>
10
    <packaging>jar</packaging>
11

  
12
    <properties>
13
        <maven.compiler.source>1.8</maven.compiler.source>
14
        <maven.compiler.target>1.8</maven.compiler.target>
15
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16
    </properties>
17

  
18
    <build>
19
        <plugins>
20
            <plugin>
21
                <groupId>org.apache.maven.plugins</groupId>
22
                <artifactId>maven-assembly-plugin</artifactId>
23
                <configuration>
24
                    <archive>
25
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
26
                    </archive>
27
                    <descriptorRefs>
28
                        <descriptorRef>jar-with-dependencies</descriptorRef>
29
                    </descriptorRefs>
30
                </configuration>
31
                <executions>
32
                    <execution>
33
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
34
                        <phase>package</phase> <!-- bind to the packaging phase -->
35
                        <goals>
36
                            <goal>single</goal>
37
                        </goals>
38
                    </execution>
39
                </executions>
40
            </plugin>
41
        </plugins>
42
    </build>
43

  
44
    <dependencies>
45
        <!-- Lib for JSON handling -->
46
        <dependency>
47
            <groupId>com.google.code.gson</groupId>
48
            <artifactId>gson</artifactId>
49
            <version>2.8.5</version>
50
        </dependency>
51

  
52
        <!-- Lib for loading file -->
53
        <dependency>
54
            <groupId>commons-io</groupId>
55
            <artifactId>commons-io</artifactId>
56
            <version>2.6</version>
57
        </dependency>
58

  
59
        <!-- Libs for Logging -->
60
        <dependency>
61
            <groupId>org.apache.logging.log4j</groupId>
62
            <artifactId>log4j-api</artifactId>
63
            <version>2.11.1</version>
64
        </dependency>
65
        <dependency>
66
            <groupId>org.apache.logging.log4j</groupId>
67
            <artifactId>log4j-core</artifactId>
68
            <version>2.11.1</version>
69
        </dependency>
70

  
71
        <!-- Libs for Unit testing -->
72
        <dependency>
73
            <groupId>org.junit.jupiter</groupId>
74
            <artifactId>junit-jupiter-api</artifactId>
75
            <version>5.3.2</version>
76
            <scope>test</scope>
77
        </dependency>
78
    </dependencies>
79

  
80

  
81
</project>
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/Converter.java
1
package cz.zcu.kiv.imiger.plugin.spade;
2

  
3
import com.google.gson.Gson;
4
import cz.zcu.kiv.imiger.plugin.spade.api.Graph;
5

  
6
public class Converter {
7

  
8
    /**
9
     * Convert input file to RAW JSON and return it.
10
     */
11
    public String getRawJson(String inputFile) {
12

  
13
        Graph graph = new Graph();
14
        return new Gson().toJson(graph);
15
    }
16
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/AttributeDataType.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
public enum AttributeDataType {
4
    NUMBER {
5
        @Override
6
        public String toString() {
7
            return "number";
8
        }
9
    },
10
    DATE {
11
        @Override
12
        public String toString() {
13
            return "date";
14
        }
15
    },
16
    ENUM {
17
        @Override
18
        public String toString() {
19
            return "enum";
20
        }
21
    },
22
    STRING {
23
        @Override
24
        public String toString() {
25
            return "string";
26
        }
27
    };
28

  
29
    public static AttributeDataType getEnum(String value){
30
        switch (value) {
31
            case "number": return AttributeDataType.NUMBER;
32
            case "date": return AttributeDataType.DATE;
33
            case "enum": return AttributeDataType.ENUM;
34
            default: return AttributeDataType.STRING;
35
        }
36
    }
37
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/AttributeType.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
/**
4
 * Class represents one attribute type which is used in input JSON file and in output JSON file (file between frontend
5
 * and backend).
6
 */
7
public class AttributeType {
8
    /** name of attribute */
9
    public String name;
10
    /** data type of attribute */
11
    public AttributeDataType dataType;
12
    /** additional info */
13
    public String text;
14

  
15
    public AttributeType(String name, AttributeDataType dataType, String text) {
16
        this.name = name;
17
        this.dataType = dataType;
18
        this.text = text;
19
    }
20

  
21
    public String getName() {
22
        return name;
23
    }
24

  
25
    public AttributeDataType getDataType() {
26
        return dataType;
27
    }
28

  
29
    public String getText() {
30
        return text;
31
    }
32
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/BaseEdge.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
/**
4
 * Class represents edge. Class contains attributes which are common for input JSON format and for
5
 * output JSON format (JSON between frontend and backend)
6
 */
7
public class BaseEdge {
8
    /** identification number of edge */
9
    private int id;
10
    /** original ID of vertex from edge leads */
11
    private int from;
12
    /** original ID of vertex where edge leads */
13
    private int to;
14
    /** additional info */
15
    private String text;
16

  
17
    public BaseEdge(int id, int from, int to, String text) {
18
        this.id = id;
19
        this.from = from;
20
        this.to = to;
21
        this.text = text;
22
    }
23

  
24
    public int getId() {
25
        return id;
26
    }
27

  
28
    public void setId(int id) {
29
        this.id = id;
30
    }
31

  
32
    public int getFrom() {
33
        return from;
34
    }
35

  
36
    public void setFrom(int from) {
37
        this.from = from;
38
    }
39

  
40
    public int getTo() {
41
        return to;
42
    }
43

  
44
    public void setTo(int to) {
45
        this.to = to;
46
    }
47

  
48
    public String getText() {
49
        return text;
50
    }
51

  
52
    public void setText(String text) {
53
        this.text = text;
54
    }
55

  
56
    /**
57
     * Generate hash code based on attributes {@code from} and {@code to}.
58
     * @return generated hash code.
59
     */
60
    @Override
61
    public int hashCode() {
62
        return from * 100000 + to;
63
    }
64

  
65
    /**
66
     * Two edges are equals where their {@code from} and {@code to} are equals.
67
     *
68
     * @param edge which will be compared with this instance
69
     * @return tru if edges are equal, false otherwise
70
     */
71
    @Override
72
    public boolean equals(Object edge) {
73
        if (!(edge instanceof BaseEdge)) return false;
74

  
75
        BaseEdge cmpEdge = (BaseEdge) edge;
76
        return from == cmpEdge.from && to == cmpEdge.to;
77
    }
78
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/BaseVertex.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
/**
4
 * Class represents vertex. Class contains attributes which are common for input JSON format and for
5
 * output JSON format (JSON between frontend and backend)
6
 */
7
public class BaseVertex {
8

  
9
    /** New generated identification number. */
10
    private int id;
11
    /** Name of vertex. */
12
    private String name;
13
    /** Index of vertex archetype. */
14
    private int archetypeIndex;
15
    /** Additional info. */
16
    private String text;
17

  
18
    public BaseVertex(int id, String name, int archetypeIndex, String text) {
19
        this.id = id;
20
        this.name = name;
21
        this.archetypeIndex = archetypeIndex;
22
        this.text = text;
23
    }
24

  
25
    public int getId() {
26
        return id;
27
    }
28

  
29
    public void setId(int id) {
30
        this.id = id;
31
    }
32

  
33
    public String getName() {
34
        return name;
35
    }
36

  
37
    public void setName(String name) {
38
        this.name = name;
39
    }
40

  
41
    public int getArchetype() {
42
        return archetypeIndex;
43
    }
44

  
45
    public void setArchetype(int archetypeIndex) {
46
        this.archetypeIndex = archetypeIndex;
47
    }
48

  
49
    public String getText() {
50
        return text;
51
    }
52

  
53
    public void setText(String text) {
54
        this.text = text;
55
    }
56

  
57
    /**
58
     * Generate hash code which is based on {@code originalId}.
59
     * @return generated has code
60
     */
61
    @Override
62
    public int hashCode() {
63
        return id;
64
    }
65

  
66
    /**
67
     * Two vertices are equals when their {@code originalId} is equals.
68
     * @param vertex which will be compared with this instance
69
     * @return true if vertices are equal, false otherwise
70
     */
71
    @Override
72
    public boolean equals(Object vertex) {
73
        if (!(vertex instanceof BaseVertex)) return false;
74
        return id == ((BaseVertex) vertex).id;
75
    }
76
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Edge.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
import java.util.List;
4

  
5
/**
6
 * Class represents edge which is used for output JSON format (JSON between frontend and backend).
7
 */
8
public class Edge extends BaseEdge {
9

  
10
    /**
11
     * List of subedgeInfo.
12
     * When two input edges are equals, in output their are in one record and their differences are in subedgeInfo.
13
     */
14
    private List<SubedgeInfo> subedgeInfo;
15

  
16
    /**
17
     * Create new edge.
18
     * @param id new generated identification number
19
     * @param from original ID of vertex from edge leads
20
     * @param to original ID of vertex where edge leads
21
     * @param text additional info
22
     * @param subedgeInfo list which contains differences between equals edges
23
     */
24
    public Edge(int id, int from, int to, String text, List<SubedgeInfo> subedgeInfo) {
25
        super(id, from, to, text);
26
        this.subedgeInfo = subedgeInfo;
27
    }
28

  
29
    public List<SubedgeInfo> getSubedgeInfo(){
30
        return subedgeInfo;
31
    }
32

  
33
    public void setSubedgeInfo(List<SubedgeInfo> subedgeInfo) {
34
        this.subedgeInfo = subedgeInfo;
35
    }
36
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/EdgeArchetype.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
public class EdgeArchetype {
4
    public String name;
5
    public String text;
6

  
7
    public EdgeArchetype(String name, String text) {
8
        this.name = name;
9
        this.text = text;
10
    }
11

  
12
    public String getName() {
13
        return  name;
14
    }
15

  
16
    public String getText() {
17
        return text;
18
    }
19
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Graph.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
import org.apache.logging.log4j.LogManager;
4
import org.apache.logging.log4j.Logger;
5

  
6
import java.util.*;
7

  
8
/**
9
 * Class represents graph with all information about graph plus information about state in which used store graph.
10
 * Class is used for creating of JSON which is send to frontend.
11
 */
12
public class Graph {
13

  
14
    private Set<Vertex> vertices;
15
    private List<Edge> edges;
16
    private List<VertexArchetype> vertexArchetypes;
17
    private List<EdgeArchetype> edgeArchetypes;
18
    private List<AttributeType> attributeTypes;
19
    private Map<String, List<String>> possibleEnumValues;
20

  
21
    private List<Group> groups;
22
    private List<SideBar> sideBar;
23
    private String highlightedVertex; // group-ID, vertex-ID
24
    private String highlightedEdge;
25

  
26
    private static final Logger logger = LogManager.getLogger();
27

  
28
    public Graph() {
29
        vertices = new HashSet<>();
30
        edges = new LinkedList<>();
31
    }
32

  
33
    public List<Edge> getEdges() {
34
        logger.trace("ENTRY");
35
        logger.trace("EXIT");
36
        return edges;
37
    }
38

  
39
    public Set<Vertex> getVertices() {
40
        logger.trace("ENTRY");
41
        logger.trace("EXIT");
42
        return vertices;
43
    }
44

  
45
    public List<VertexArchetype> getVertexArchetypes() {
46
        return vertexArchetypes;
47
    }
48

  
49
    public List<EdgeArchetype> getEdgeArchetypes() {
50
        return edgeArchetypes;
51
    }
52

  
53
    public List<AttributeType> getAttributeTypes() {
54
        return attributeTypes;
55
    }
56

  
57
    public Map<String, List<String>> getPossibleEnumValues() {
58
        return possibleEnumValues;
59
    }
60

  
61
    public List<Group> getGroups() {
62
        return groups;
63
    }
64

  
65
    public List<SideBar> getSideBar() {
66
        return sideBar;
67
    }
68

  
69
    public String getHighlightedVertex() {
70
        return highlightedVertex;
71
    }
72

  
73
    public String getHighlightedEdge() {
74
        return highlightedEdge;
75
    }
76

  
77
    public void setVertexArchetypes(List<VertexArchetype> vertexArchetypes) {
78
        this.vertexArchetypes = vertexArchetypes;
79
    }
80

  
81
    public void setEdgeArchetypes(List<EdgeArchetype> edgeArchetypes) {
82
        this.edgeArchetypes = edgeArchetypes;
83
    }
84

  
85
    public void setAttributeTypes(List<AttributeType> attributeTypes) {
86
        this.attributeTypes = attributeTypes;
87
    }
88

  
89
    public void setPossibleEnumValues(Map<Integer, List<String>> possibleEnumValues) {
90
        this.possibleEnumValues = new HashMap<>();
91
        for (Map.Entry<Integer, List<String>> entry : possibleEnumValues.entrySet()) {
92
            this.possibleEnumValues.put("" + entry.getKey(), entry.getValue());
93
        }
94
    }
95

  
96
    public void setGroups(List<Group> groups) {
97
        this.groups = groups;
98
    }
99

  
100
    public void setSideBar(List<SideBar> sideBar) {
101
        this.sideBar = sideBar;
102
    }
103

  
104
    public void setHighlightedVertex(String highlightedVertex) {
105
        this.highlightedVertex = highlightedVertex;
106
    }
107

  
108
    public void setHighlightedEdge(String highlightedEdge) {
109
        this.highlightedEdge = highlightedEdge;
110
    }
111
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Group.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
/**
7
 * Class represents group of edges and their settings. Used in JSON between frontend and backend.
8
 */
9
public class Group {
10

  
11
    /** Generated id of group. */
12
    private int id;
13
    /** Name of group */
14
    private String name;
15
    /** List of vertices id which belongs to this group */
16
    private List<Integer> verticesId;
17
    /** List of vertices id whose outgoing edges are visible. */
18
    private List<Integer> verticesEdgeFromId;
19
    /** List of vertices id whose incoming edges are visible. */
20
    private List<Integer> verticesEdgeToId;
21
    /** Relative position in graph */
22
    private Position position;
23

  
24
    public Group(int id, String name){
25
        this.id = id;
26
        this.name = name;
27
        this.verticesId = new ArrayList<>();
28
        this.verticesEdgeFromId = new ArrayList<>();
29
        this.verticesEdgeToId = new ArrayList<>();
30
        this.position = null;
31
    }
32

  
33
    public Group(int id, String name, List<Integer> verticesId, List<Integer> verticesEdgeFromId, List<Integer> verticesEdgeToId) {
34
        this.id = id;
35
        this.name = name;
36
        this.verticesId = verticesId;
37
        this.verticesEdgeFromId = verticesEdgeFromId;
38
        this.verticesEdgeToId = verticesEdgeToId;
39
        this.position = null;
40
    }
41

  
42
    public int getId() {
43
        return id;
44
    }
45

  
46
    public void setId(int id) {
47
        this.id = id;
48
    }
49

  
50
    public String getName() {
51
        return name;
52
    }
53

  
54
    public void setName(String name) {
55
        this.name = name;
56
    }
57

  
58
    public List<Integer> getVerticesId() {
59
        return verticesId;
60
    }
61

  
62
    public void setVerticesId(List<Integer> verticesId) {
63
        this.verticesId = verticesId;
64
    }
65

  
66
    public List<Integer> getVerticesEdgeFromId() {
67
        return verticesEdgeFromId;
68
    }
69

  
70
    public void setVerticesEdgeFromId(List<Integer> verticesEdgeFromId) {
71
        this.verticesEdgeFromId = verticesEdgeFromId;
72
    }
73

  
74
    public List<Integer> getVerticesEdgeToId() {
75
        return verticesEdgeToId;
76
    }
77

  
78
    public void setVerticesEdgeToId(List<Integer> verticesEdgeToId) {
79
        this.verticesEdgeToId = verticesEdgeToId;
80
    }
81

  
82
    public void addVertexId(int vertexId){
83
        this.verticesId.add(vertexId);
84
    }
85

  
86
    public void addVetexEdgeToId(int vertexId){
87
        this.verticesEdgeToId.add(vertexId);
88
    }
89

  
90
    public void addVetexEdgeFromId(int vertexId){
91
        this.verticesEdgeFromId.add(vertexId);
92
    }
93

  
94
    public Position getPosition() {
95
        return position;
96
    }
97

  
98
    public void setPosition(Position position) {
99
        this.position = position;
100
    }
101
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Position.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
/**
4
 * Class is used for storing information about vertex/group relative position.
5
 */
6
public class Position {
7

  
8
    /** Relative X position. */
9
    private float x;
10
    /** Relative Y position */
11
    private float y;
12

  
13
    public Position(float x, float y) {
14
        this.x = x;
15
        this.y = y;
16
    }
17

  
18
    public float getX() {
19
        return x;
20
    }
21

  
22
    public void setX(float x) {
23
        this.x = x;
24
    }
25

  
26
    public float getY() {
27
        return y;
28
    }
29

  
30
    public void setY(float y) {
31
        this.y = y;
32
    }
33
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/SideBar.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
/**
4
 * Class store information about item in side bar.
5
 */
6
public class SideBar {
7

  
8
    /** Identification number of vertex or group which was generated in application. */
9
    private int vertexId;
10
    /** Indicates if related vertexes of this item have visible icon which shows relation with this item. */
11
    private boolean isIconsDisplayed;
12

  
13
    public SideBar(int vertexId, boolean isIconsDisplayed) {
14
        this.vertexId = vertexId;
15
        this.isIconsDisplayed = isIconsDisplayed;
16
    }
17

  
18
    public int getVertexId() {
19
        return vertexId;
20
    }
21

  
22
    public void setVertexId(int vertexId) {
23
        this.vertexId = vertexId;
24
    }
25

  
26
    public boolean isIconsDisplayed() {
27
        return isIconsDisplayed;
28
    }
29

  
30
    public void setIconsDisplayed(boolean iconsDisplayed) {
31
        this.isIconsDisplayed = iconsDisplayed;
32
    }
33
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/SubedgeInfo.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
import java.util.List;
4

  
5
public class SubedgeInfo {
6

  
7
    /** Edge archetype index. */
8
    private int archetype;
9
    /** Original id of edge which is taken from input JSON file. */
10
    private int id;
11
    /** List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. */
12
    private List<String[]> attributes;
13

  
14
    /**
15
     * Create new subedgeInfo
16
     * @param id Original id of edge which is taken from input JSON file.
17
     * @param archetype Edge archetype index.
18
     * @param attributes  List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}.
19
     */
20
    public SubedgeInfo(int id, int archetype, List<String[]> attributes) {
21
        this.id = id;
22
        this.archetype = archetype;
23
        this.attributes = attributes;
24
    }
25

  
26
    public int getId() {
27
        return id;
28
    }
29

  
30
    public int getArchetype() {
31
        return archetype;
32
    }
33

  
34
    public List<String[]> getAttributes() {
35
        return attributes;
36
    }
37
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/Vertex.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
import java.util.List;
4

  
5
/**
6
 * Class represents vertex which is used for output JSON format (JSON between frontend and backend)
7
 */
8
public class Vertex extends BaseVertex {
9

  
10
    /** List of all tributes. Every attribute is stored in String array in pair as {attribute name, attribute value}. */
11
    private List<String[]> attributes;
12
    /** Relative position in graph */
13
    private Position position;
14

  
15
    /**
16
     * Create new vertex.
17
     * @param id original identification number from input file
18
     * @param name of vertex
19
     * @param archetypeIndex index of vertex archetype
20
     * @param text additional info
21
     * @param attributes List of all attributes. Every attribute is stored in String array in pair as {attribute name, attribute value}.
22
     */
23
    public Vertex(int id, String name, int archetypeIndex, String text, List<String[]> attributes) {
24
        super(id, name, archetypeIndex, text);
25
        this.attributes = attributes;
26
        this.position = null;
27
    }
28

  
29
    public List<String[]> getAttributes() {
30
        return attributes;
31
    }
32

  
33
    public void setAttributes(List<String[]> attributes) {
34
        this.attributes = attributes;
35
    }
36

  
37
    public Position getPosition() {
38
        return position;
39
    }
40

  
41
    public void setPosition(Position position) {
42
        this.position = position;
43
    }
44
}
plugins/_template/src/main/java/cz/zcu/kiv/imiger/plugin/spade/api/VertexArchetype.java
1
package cz.zcu.kiv.imiger.plugin.spade.api;
2

  
3
public class VertexArchetype {
4
    public String name;
5
    public String text;
6
    public String icon;
7

  
8
    public VertexArchetype(String name, String text, String icon) {
9
        this.name = name;
10
        this.text = text;
11
        this.icon = icon;
12
    }
13

  
14
    public VertexArchetype(String name, String text) {
15
        this(name, text, "");
16
    }
17

  
18
    public String getName() {
19
        return name;
20
    }
21

  
22
    public String getText() {
23
        return text;
24
    }
25

  
26
    public String getIcon() {
27
        return icon;
28
    }
29
}
plugins/_template/src/main/resources/META-INF/MANIFEST.MF
1
Manifest-Version: 1.0
2
Created-By: Apache Maven ${maven.version}
3
Built-By: ${user.name}
4
Build-Jdk: ${java.version}
5
Module-Name: My Convertor
plugins/_template/src/main/resources/log4j2.properties
1
name=PropertiesConfig
2
property.filename = logs
3
appenders = console, file
4

  
5
appender.console.type = Console
6
appender.console.name = STDOUT
7
appender.console.layout.type = PatternLayout
8
appender.console.layout.pattern=%d{yy-MM-dd HH:mm:ss:SSS} %-6p [%c:%M:%L] - %m%n
9

  
10
appender.file.type = File
11
appender.file.name = LOGFILE
12
appender.file.fileName=${filename}/propertieslogs.log
13
appender.file.layout.type=PatternLayout
14
appender.file.layout.pattern=%d{yy-MM-dd HH:mm:ss:SSS} %-6p [%c:%M:%L] - %m%n
15

  
16
rootLogger.level = debug
17
rootLogger.appenderRefs = stdout
18
rootLogger.appenderRef.stdout.ref = STDOUT
plugins/_template/src/test/java/PluginTest.java
1
import org.junit.jupiter.api.Test;
2
import org.junit.platform.commons.util.StringUtils;
3

  
4
import java.io.File;
5
import java.io.FileInputStream;
6
import java.io.IOException;
7
import java.lang.reflect.Method;
8
import java.net.URL;
9
import java.net.URLClassLoader;
10
import java.util.jar.Attributes;
11
import java.util.jar.JarInputStream;
12
import java.util.jar.Manifest;
13

  
14
import static org.junit.jupiter.api.Assertions.*;
15

  
16
/**
17
 * This class is only for testing integrity of Jar file.
18
 * Testing:
19
 *      Jar file can be open
20
 *      Manifest contains Module-Name and it is not blank
21
 *      Manifest contains Module-Class and this class exists in Jar file
22
 *      Given class contains method 'String getRawJson(String)'
23
 *
24
 *
25
 * !!! BEFORE USAGE PLEASE CHANGE VARIABLE 'ARCHIVE_WITH_DEPENDENCIES_PATH' !!!
26
 */
27
class PluginTest {
28

  
29
    private static final String ARCHIVE_WITH_DEPENDENCIES_PATH = "target\\imiger-plugin-template-1.0-SNAPSHOT-jar-with-dependencies.jar";
30

  
31

  
32
    // ========================================= DO NOT CHANGE UNDER THIS LINE =========================================
33

  
34
    private static final String MODULE_CLASS_IDENTIFIER = "Module-Class";
35
    private static final String MODULE_NAME_IDENTIFIER = "Module-Name";
36
    private static final String METHOD_NAME = "getRawJson";
37
    private static final Class METHOD_PARAMETER_CLASS = String.class;
38

  
39
    @Test
40
    void integrityTest() {
41
        try {
42
            File jarFile = new File(ARCHIVE_WITH_DEPENDENCIES_PATH);
43

  
44
            JarInputStream jis = new JarInputStream(new FileInputStream(jarFile));
45
            final Manifest mf = jis.getManifest();
46
            final Attributes attributes = mf.getMainAttributes();
47
            final String moduleClassName = attributes.getValue(MODULE_CLASS_IDENTIFIER);
48
            final String moduleVisibleName = attributes.getValue(MODULE_NAME_IDENTIFIER);
49

  
50
            assertFalse(StringUtils.isBlank(moduleClassName), "Blank module class name given by manifest attribute 'Module-Class'");
51
            assertFalse(StringUtils.isBlank(moduleVisibleName), "Blank module visible name given by manifest attribute 'Module-Name'");
52

  
53
            final ClassLoader loader = URLClassLoader.newInstance(new URL[]{jarFile.toURI().toURL()});
54
            final Class<?> clazz = Class.forName(moduleClassName, true, loader);
55
            // checking if method exists, if not throw exception
56
            Method method = clazz.getMethod(METHOD_NAME, METHOD_PARAMETER_CLASS);
57

  
58

  
59
            assertEquals(String.class, method.getReturnType(), "Invalid method return type.");
60

  
61
        } catch (IOException e){
62
            fail("Can not open given Jar file. Given path is probably incorrect.");
63
        } catch (ClassNotFoundException e) {
64
            fail("Class given by attribute 'Module-Class' in MANIFEST.MF was not found in Jar file.");
65
        } catch (NoSuchMethodException e) {
66
            fail("Class given by attribute 'Module-Class' in MANIFEST.MF do not contains method: String getRawJson(String).");
67
        }
68
    }
69
}

Také k dispozici: Unified diff