Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java plugin #557

Open
wants to merge 140 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
43792f1
Added frame (copied dummy) of Java parser.
intjftw Nov 25, 2020
334e31e
Create and fill model directory, and fill parser/src directory in the…
Wrathan Dec 2, 2020
30f57a4
Most database connections created, Entity's structure optimized.
Wrathan Dec 8, 2020
3961e95
Merge remote-tracking branch 'upstream/master' into java_plugin
Wrathan Feb 14, 2021
c04c3bf
Rewrite Java specific strings and variable names.
Wrathan Mar 6, 2021
6da5f76
Merge remote-tracking branch 'upstream/master' into java_plugin
Wrathan Mar 6, 2021
e4f826d
Pulled currently necessary dependencies, and set package info in .jav…
Wrathan Mar 6, 2021
de3932b
Function skeletons to 'visit' functions have been written to all poss…
Wrathan Mar 7, 2021
9d08b02
Java code rearranged to the correct form.
Wrathan Mar 7, 2021
d368ea9
Basics of installing the Java plugin into CodeCompass
Wrathan Mar 16, 2021
b3ad1e4
CMakeLists files for model.
intjftw Mar 19, 2021
dbf0bda
Basics of configuring CMake files for Java plugin.
Wrathan Mar 24, 2021
5789d9e
Commented unnecessary parts from the service's CMakeList.
intjftw Mar 24, 2021
aec44b7
Added missing Java dependencies.
Wrathan Mar 30, 2021
8a12fd7
Generating files with Thrift for the Java plugin.
Wrathan Mar 30, 2021
c78306f
JavaHandler created.
Wrathan Mar 31, 2021
91fe93d
JavaHandler's path modified.
Wrathan Apr 4, 2021
733883c
Double inclusion fixed.
Wrathan Apr 4, 2021
c59280e
C++ and Java files separated.
Wrathan Apr 4, 2021
edb302d
Run javaparser.jar with Boost.
Wrathan Apr 15, 2021
713098c
Added more dependencies (json.simple and Eclipse dependencies).
Wrathan Apr 26, 2021
b624d72
Process compilation database in the Java plugin, and start the ASTVis…
Wrathan Apr 26, 2021
30b7244
Argument name corrected.
Wrathan Apr 26, 2021
f2b3a00
ASTParser object created, when first time a Java file found, after th…
Wrathan May 5, 2021
713cd36
Trying to add xml to javamodel.jar. (Does not work yet)
Wrathan May 26, 2021
3b08d29
Adding persistence.xml to model jar file.
intjftw May 26, 2021
fde8139
EntityManager for Persistence created. (Does not connecting to the da…
Wrathan Jun 16, 2021
eb39cc8
Dummyparser's elements remaned back to dummyparser. (Accidentally, re…
Wrathan Jun 17, 2021
ea87076
EntityManager connect into the postgresql database. (Raw version, par…
Wrathan Jun 17, 2021
2c2d634
Modified database schema.
Wrathan Jun 24, 2021
3b1784b
Process database properties. (Only for pgsql yet.)
Wrathan Jun 24, 2021
ec4ba1e
Applying coding conventions in C++ files.
intjftw Jun 28, 2021
d1efda0
Merge branch 'Ericsson:master' into java_plugin
Wrathan Jun 29, 2021
814b2b9
Set up EntityManager for SQLite, refining EMFactory.java
Wrathan Jun 29, 2021
4485ae7
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Wrathan Jun 29, 2021
f772c84
Try to fix error on Ubuntu 18.04.
Wrathan Jun 30, 2021
3fa3139
Persist JPA objects.
Wrathan Jul 12, 2021
306b799
Set Enum values into JavaAstNode's rows, separate JavaConstructor and…
Jul 28, 2021
1f8f571
JavaEnum, JavaEnumConstants and JavaEnum_enumConstrants tables filled…
Aug 2, 2021
e59ab77
Trying to fill File table with java files.
Aug 12, 2021
f471bf3
JavaDocComment table partially filled, JavaVariable_parameters and Ja…
Aug 19, 2021
f1eacfc
Add java.util.logging.Logger
Aug 31, 2021
d766c15
Tried to use _ctx.srcMgr.getFile()
Aug 31, 2021
4b3837e
Including generated database files.
intjftw Sep 1, 2021
68754d2
Fill BuildAction table.
Sep 1, 2021
02fe74e
Add Thrift support for Java plugin.
Sep 7, 2021
c32f0eb
File id passed into Java side. Method invocations and class instance …
Sep 16, 2021
81fc826
Thrift: setArgs(), getArgs() functions, CmdArgs structure added. Run …
Sep 21, 2021
2c6f3fd
Java parser throws Thrift exception if parsing failed.
Sep 21, 2021
3ff3c3a
BuildSource and BuildAction table filled, and binary files uploaded i…
Sep 22, 2021
ab4018a
Merge branch 'Ericsson:master' into java_plugin
Wrathan Sep 27, 2021
457cfc5
Add service skeleton fot Java plugin. Add Thrift exception handling f…
Sep 29, 2021
c3f80e0
Try to register Java service into the system
Sep 30, 2021
6884dc6
Separate logger from parser into a standalone folder.
Oct 4, 2021
ffdd0eb
Extend InfoTrees with id.
Oct 6, 2021
84ea4c0
Set up Thrift communication between C++ and Java (Passing database ar…
Oct 6, 2021
baa07de
Started to implement Java service operations.
Oct 15, 2021
b62c410
InfoTree: Usages of Methods partially filled.
Oct 16, 2021
d148a32
Add JavaRelation table.
Oct 17, 2021
b428219
Use Paths.get() instead of Path.of() to prevent CI to fail on Ubuntu …
Oct 17, 2021
0034a3c
Use Paths.get() instead of Path.of() to prevent CI to fail on Ubuntu …
Oct 17, 2021
1195677
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Oct 17, 2021
410baba
Connect into Java parser server and Java service server as soon as po…
Oct 18, 2021
5fd3e9f
Fill "Definition", "Declaration" and "Calls of this" nodes in InfoTree.
Oct 18, 2021
2ec9998
Fill "Properties", nodes in InfoTree. (Name, Qualified Name, Qualifie…
Oct 19, 2021
bcd0caa
Fill "Properties", nodes in InfoTree. (Name, Qualified Name, Qualifie…
Oct 19, 2021
8231c50
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Oct 19, 2021
b360b87
Fill "Properties", nodes in InfoTree. (Name, Qualified Name, Qualifie…
Oct 19, 2021
fffdaf3
Fill JavaRecord table, fix the error of entity hashes of constructors.
Oct 19, 2021
462a060
Insert Type information into InfoTree
Oct 19, 2021
1a23df7
Hide Thrift messages from console while the socket tries to connect i…
Oct 21, 2021
7fd9cd1
MethodDeclaration's visit() method refined, 'entityHash' of methods r…
Oct 22, 2021
94df446
Parse method and constructor local variables and show them in InfoTree.
Oct 25, 2021
22919e1
Add 'Return type'/'Type' into InfoTree.
Oct 26, 2021
3c82b06
Add 'Chis calls', 'Caller', 'Callee' into InfoTree.
Oct 27, 2021
9771d0a
Fixed start column's position.
Oct 27, 2021
c85ab2d
Java query methods moved into JavaQueryFactory.
Oct 27, 2021
c9d6c4f
Create and fill JavaMemberType table.
Oct 28, 2021
c49ab28
Add 'Data member' and 'Method' nodes into InfoTree ('Constructor' and…
Oct 28, 2021
721de37
Fix the value JavaEnumConstant's "value" column
Oct 28, 2021
7560bcc
Add 'Constructor' node into InfoTree. Add 'package-private' option in…
Oct 28, 2021
d2c3b44
Add 'Constructor' node into InfoTree. Add 'package-private' option in…
Oct 28, 2021
dfbd897
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Oct 28, 2021
3379a35
Distinguish Enums and Classes in SimpleType parsing.
Oct 29, 2021
9e7fdd1
Add 'Enum constant' node and append 'Constructor', 'Data member' and …
Oct 29, 2021
162e0c9
Parse variable usages, and add the related 'Reads' and 'Writes' nodes…
Oct 31, 2021
3f9d64e
Parse and show Java enum constants' usage.
Oct 31, 2021
7e5f092
Fixed 'isAbstract' parsing and add 'isFinal' field into JavaRecord ta…
Oct 31, 2021
25a4fe2
Parse information about visibility for all nodes that is possible and…
Nov 1, 2021
c1b139c
Refine AstVisitor.java
Nov 1, 2021
5b87176
Parse Lambda functions, catch clause variables, loop variables (and s…
Nov 1, 2021
e01d185
Fill JavaInheritance table. Add 'Inherits from' and 'Inherited by' no…
Nov 2, 2021
d34297b
Parse super constructor calls (and automatically show them in Info Tr…
Nov 2, 2021
ec36126
Drop Java-related tables at the start of reparsing (Incremental parsi…
Nov 3, 2021
2dfd0a5
Parse method references (and show them in Info Tree).
Nov 3, 2021
b8769d3
Create JavaRelation table and fill it with method relations. Parse ov…
Nov 5, 2021
6cb7798
Parse override status for implementations. Create RelationCollector.j…
Nov 6, 2021
c0fb7e7
Java parser refined
Nov 7, 2021
51eaa0b
Escape "<" and ">" characters in parameter nodes.
Nov 8, 2021
3de525a
Get IProblems from actual CompilationUnit and fill BuildAction table …
Nov 8, 2021
0d60e7c
Fix wrong result in 'Callee' and 'This calls' nodes (position info wa…
Nov 9, 2021
cc67c3c
Implement getAstNodeInfo() and getSourceText() functions in Java serv…
Nov 9, 2021
f6a3758
Add diagram-specific function skeletons, fix the entityHash error in …
Nov 11, 2021
131c7e5
Bugfix: Type and Return type nodes not shown in Info Tree dou to a qu…
Nov 11, 2021
ecdc6b9
Separate implementations az overrides in parsing, and in Info Tree too.
Nov 12, 2021
4ddafbb
Merge branch 'master' of https://github.com/Ericsson/CodeCompass into…
Nov 12, 2021
84b5931
Add Code Bytes for Java into GUI.
Nov 12, 2021
3003d37
Add Code Bytes for Java into GUI.
Nov 12, 2021
afcd54e
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Nov 12, 2021
8409b85
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Nov 12, 2021
d4a6284
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Nov 12, 2021
5801085
Add information about defined sub-nodes in the case of enums, types, …
Nov 14, 2021
1d8718d
Fix variable names.
Nov 15, 2021
36a5240
Add exception handling for committing into the database, and revert t…
Nov 18, 2021
2ea7bc3
Drop Java-related tables before parsing.
Nov 18, 2021
09633bc
Fix the bug of lambda method definitions.
Nov 27, 2021
99eeb18
Fix a bug of generic's usages by always show generic parameters in ty…
Nov 28, 2021
4eee343
Multi-thread parsing for Java compile commands.
Nov 29, 2021
d6aa417
Multi-thread parsing for Java compile commands.
Nov 29, 2021
912eea7
Merge remote-tracking branch 'origin/java_plugin' into java_plugin
Nov 29, 2021
d241b9a
Merge branch 'Ericsson:master' into java_plugin
Wrathan Nov 30, 2021
6475340
Parse and show Java initializers.
Dec 2, 2021
2b5d300
Parse inner classes correctly and show them in Info Tree.
Dec 3, 2021
b7b304f
Fixing minor bugs, modify CMake configuration to generate the right j…
Dec 4, 2021
e34ffc0
Implement jar decompiling and parsing. (without classpath yet)
Dec 6, 2021
a6b151f
Parsing classpath for jar parsing from the jar's MANIFEST.MF file. Fi…
Dec 7, 2021
9c6a28d
Show inner enums in types, and inner types in enums in Info Tree.
Dec 8, 2021
c437e10
Group inner types in Info Tree by visibility
Dec 8, 2021
5cc687c
Make Thrift methods not synchronized to highly increase parser's spee…
Dec 9, 2021
db62899
Update log4j version due to a security issue.
Dec 14, 2021
853b718
Fixing minor issues to prevent race conditions
Dec 14, 2021
edf7be6
Ignore array type's fields (length field).
Dec 14, 2021
e582634
Add missing Java dependency
Dec 14, 2021
7ed1f9b
Minor fixes
Dec 14, 2021
e10c230
Bug fix: parsing of variable usages of variables with primitive type …
Dec 14, 2021
ffdbd2c
Remove bugfix, because it wont solve the problem
Dec 15, 2021
1bb0f42
Bugfix: Parse array's 'length' property
Dec 15, 2021
b2cab25
Remove runtime information about parsing and decompiling jar files
Dec 15, 2021
f5cde28
Adding unzip to dependencies in docker images and GitHub CI.
intjftw Feb 3, 2022
1d6f0be
Introduce new entity hash strategy for generic types.
Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
run: >
sudo apt-get install -y git cmake make g++ gcc-7-plugin-dev libboost-all-dev
llvm-10-dev clang-10 libclang-10-dev default-jdk libssl1.0-dev libgraphviz-dev
libmagic-dev libgit2-dev ctags libgtest-dev npm libldap2-dev
libmagic-dev libgit2-dev ctags libgtest-dev npm libldap2-dev unzip

- name: Install Postgresql Ubuntu 18
if: ${{ matrix.os == 'ubuntu-18.04' && matrix.db == 'postgresql' }}
Expand Down Expand Up @@ -127,7 +127,7 @@ jobs:
run: >
sudo apt-get install -y git cmake make g++ libboost-all-dev llvm-10-dev clang-10
libclang-10-dev odb libodb-dev thrift-compiler libthrift-dev default-jdk libssl-dev
libgraphviz-dev libmagic-dev libgit2-dev ctags libgtest-dev npm libldap2-dev
libgraphviz-dev libmagic-dev libgit2-dev ctags libgtest-dev npm libldap2-dev unzip

- name: Install Postgresql Ubuntu 20
if: ${{ matrix.os == 'ubuntu-20.04' && matrix.db == 'postgresql' }}
Expand Down Expand Up @@ -256,7 +256,7 @@ jobs:
sudo apt-get install -y git cmake make g++ gcc-7-plugin-dev libgraphviz-dev
libboost-filesystem-dev libboost-log-dev libboost-program-options-dev
llvm-10-dev clang-10 libclang-10-dev default-jre libssl1.0-dev libmagic-dev
libgit2-dev ctags libgtest-dev libldap-2.4-2
libgit2-dev ctags libgtest-dev libldap-2.4-2 unzip

- name: Install Postgresql Ubuntu 18
if: ${{ matrix.os == 'ubuntu-18.04' && matrix.db == 'postgresql' }}
Expand Down Expand Up @@ -296,7 +296,7 @@ jobs:
libboost-log-dev libboost-program-options-dev llvm-10-dev clang-10
libclang-10-dev libgraphviz-dev libgtest-dev odb libodb-dev
libthrift-dev default-jre libssl1.1 libmagic-dev libgit2-dev ctags
libldap-2.4-2
libldap-2.4-2 unzip

- name: Install Postgresql Ubuntu 20
if: ${{ matrix.os == 'ubuntu-20.04' && matrix.db == 'postgresql' }}
Expand Down
1 change: 1 addition & 0 deletions docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN set -x && apt-get update -qq \
cmake make \
default-jdk \
ctags \
unzip \
gcc-9 gcc-9-plugin-dev g++-9 \
libboost-filesystem-dev \
libboost-log-dev \
Expand Down
1 change: 1 addition & 0 deletions docker/runtime/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ RUN set -x && apt-get update -qq && \
libldap-2.4-2 \
libmagic-dev \
libthrift-dev \
unzip \
ctags && \
apt-get clean && \
rm -rf /var/lib/apt/lists/ && \
Expand Down
Binary file added lib/java/commons-io-2.8.0.jar
Binary file not shown.
Binary file added lib/java/eclipselink-2.7.8.jar
Binary file not shown.
Binary file added lib/java/jakarta.persistence-api-2.2.3.jar
Binary file not shown.
Binary file added lib/java/log4j-1.2-api-2.15.0.jar
Binary file not shown.
Binary file removed lib/java/log4j-1.2.17.jar
Binary file not shown.
Binary file added lib/java/log4j-api-2.15.0.jar
Binary file not shown.
Binary file added lib/java/log4j-core-2.15.0.jar
Binary file not shown.
Binary file added lib/java/log4j-slf4j-impl-2.15.0.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lib/java/postgresql-42.2.22.jar
Binary file not shown.
Binary file added lib/java/procyon-compilertools-0.5.36.jar
Binary file not shown.
Binary file added lib/java/procyon-core-0.5.36.jar
Binary file not shown.
Binary file removed lib/java/slf4j-log4j12-1.7.25.jar
Binary file not shown.
Binary file added lib/java/sqlite-jdbc-3.34.0.jar
Binary file not shown.
1 change: 1 addition & 0 deletions plugins/cpp/webgui/js/cppInfoTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ function (model, viewHandler, util) {
}

var cppInfoTree = {
id: 'cpp-infotree',
render : function (elementInfo) {
var ret = [];

Expand Down
2 changes: 1 addition & 1 deletion plugins/dummy/parser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include_directories(
${PROJECT_SOURCE_DIR}/parser/include)

add_library(dummyparser SHARED
src/dummyparser.cpp)
src/dummyparser.cpp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unnecessary.


target_compile_options(dummyparser PUBLIC -Wno-unknown-pragmas)

Expand Down
2 changes: 1 addition & 1 deletion plugins/dummy/service/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ add_library(dummythrift STATIC
target_compile_options(dummythrift PUBLIC -fPIC)

add_library(dummyservice SHARED
src/dummyservice.cpp
src/javaservice.cpp
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be changed,

src/plugin.cpp)

target_compile_options(dummyservice PUBLIC -Wno-unknown-pragmas)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <service/dummyservice.h>
#include <service/javaservice.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be changed,

#include <util/dbutil.h>

namespace cc
Expand Down
2 changes: 1 addition & 1 deletion plugins/dummy/service/src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <webserver/pluginhelper.h>

#include <service/dummyservice.h>
#include <service/javaservice.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be changed,


/* These two methods are used by the plugin manager to allow dynamic loading
of CodeCompass Service plugins. Clang (>= version 6.0) gives a warning that
Expand Down
7 changes: 7 additions & 0 deletions plugins/java/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
add_subdirectory(logger)
add_subdirectory(model)
add_subdirectory(parser)
# add_subdirectory(test)
add_subdirectory(service)

install_webplugin(webgui)
12 changes: 12 additions & 0 deletions plugins/java/logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(CMAKE_JAVA_INCLUDE_PATH
${PROJECT_SOURCE_DIR}/lib/java/*
${PLUGIN_DIR}/lib/java/*)

add_jar(javalogger
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/Logger.java
META-INF/logging.properties
MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/META-INF/MANIFEST.MF
OUTPUT_NAME javalogger)

install_jar(javalogger "${INSTALL_JAVA_LIB_DIR}")
25 changes: 25 additions & 0 deletions plugins/java/logger/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;

public abstract class Logger {
public static final java.util.logging.Logger LOGGER = initLogger();

private static java.util.logging.Logger initLogger() {
InputStream stream = Logger.class.getClassLoader().
getResourceAsStream("META-INF/logging.properties");

try {
LogManager.getLogManager().readConfiguration(stream);
return java.util.logging.Logger.getLogger(Logger.class.getName());

} catch (IOException e) {
System.err.println(
"Logger initialization for Java plugin has been failed."
);
}
return null;
}
}
6 changes: 6 additions & 0 deletions plugins/java/logger/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Manifest-Version: 1.0
Class-Path: log4j-1.2-api-2.15.0.jar
log4j-api-2.15.0.jar
log4j-core-2.15.0.jar
slf4j-api-1.7.25.jar
log4j-slf4j-impl-2.15.0.jar
5 changes: 5 additions & 0 deletions plugins/java/logger/META-INF/logging.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
handlers= java.util.logging.ConsoleHandler
.level= INFO
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format=[%4$s] %5$s%6$s%n
39 changes: 39 additions & 0 deletions plugins/java/model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
set(CMAKE_JAVA_INCLUDE_PATH
${PROJECT_SOURCE_DIR}/lib/java/*
${PLUGIN_DIR}/lib/java/*)

set(CMAKE_JAVA_COMPILE_FLAGS
${CMAKE_JAVA_COMPILE_FLAGS}
-sourcepath ${CMAKE_CURRENT_SOURCE_DIR}:${PLUGIN_DIR})

add_jar(javamodel
SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/enums/AstType.java
${CMAKE_CURRENT_SOURCE_DIR}/enums/InitializerKind.java
${CMAKE_CURRENT_SOURCE_DIR}/enums/MemberTypeKind.java
${CMAKE_CURRENT_SOURCE_DIR}/enums/RelationKind.java
${CMAKE_CURRENT_SOURCE_DIR}/enums/SymbolType.java
${CMAKE_CURRENT_SOURCE_DIR}/enums/Visibility.java
${CMAKE_CURRENT_SOURCE_DIR}/EMFactory.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaAnnotation.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaAstNode.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaConstructor.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaDocComment.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaEntity.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaEnum.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaEnumConstant.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaMethod.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaImport.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaInheritance.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaInitializer.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaMemberType.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaRecord.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaRelation.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaTypedEntity.java
${CMAKE_CURRENT_SOURCE_DIR}/JavaVariable.java
META-INF/persistence.xml
MANIFEST ${CMAKE_CURRENT_SOURCE_DIR}/META-INF/MANIFEST.MF
INCLUDE_JARS javalogger
OUTPUT_NAME javamodel)

install_jar(javamodel "${INSTALL_JAVA_LIB_DIR}")
96 changes: 96 additions & 0 deletions plugins/java/model/EMFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package model;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.spi.PersistenceUnitTransactionType;
import java.util.Arrays;
import java.util.HashMap;
import java.util.logging.Level;

import static logger.Logger.LOGGER;
import static org.eclipse.persistence.config.PersistenceUnitProperties.*;

public class EMFactory {
private final EntityManagerFactory emf;

public EMFactory(String rawDbContext, boolean dropAndCreateTables) {
this.emf =
Persistence.createEntityManagerFactory(
"ParserPU",
initProperties(rawDbContext, dropAndCreateTables)
);


if (dropAndCreateTables) {
emf.getMetamodel().getEntities().forEach(
e ->
LOGGER.log(
Level.INFO,
String.join(" ", "Dropping table", e.getName())
)
);
}
}

public EntityManager createEntityManager()
{
return emf.createEntityManager();
}

private HashMap<String, Object> initProperties(
String rawDbContext, boolean dropAndCreateTables)
{
HashMap<String, Object> properties = new HashMap<>();
String[] splitByColon = rawDbContext.split(":");
String dbType = splitByColon[0];
String contextString = splitByColon[1];
boolean isSqlite = dbType.equals("sqlite");
String driver =
isSqlite ? "org.sqlite.JDBC" : "org.postgresql.Driver";
String[] contextList = contextString.split(";");
HashMap<String, String> contextMap = new HashMap<>();

if (dropAndCreateTables) {
properties.put("eclipselink.ddl-generation", "drop-and-create-tables");
} else {
properties.put("eclipselink.ddl-generation", "create-tables");
}


properties.put(
TRANSACTION_TYPE,
PersistenceUnitTransactionType.RESOURCE_LOCAL.name()
);

Arrays.stream(contextList).forEach(c -> {
String[] splitContext = c.split("=");
contextMap.put(splitContext[0], splitContext[1]);
});

String connString =
isSqlite ?
"jdbc:" + "sqlite" + ":/" +
contextMap.get("database")
.replaceFirst("^~", System.getProperty("user.home"))
:
"jdbc:" + "postgresql" + "://" +
contextMap.get("host") + ":" +
contextMap.get("port") + "/" +
contextMap.get("database");

properties.put(JDBC_DRIVER, driver);
properties.put(JDBC_URL, connString);

if (!isSqlite) {
properties.put(JDBC_USER, contextMap.get("user"));
properties.put(JDBC_PASSWORD, contextMap.get("password"));
}

return properties;
}

public EntityManagerFactory getEmf() {
return emf;
}
}
8 changes: 8 additions & 0 deletions plugins/java/model/JavaAnnotation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package model;

import javax.persistence.*;

@Entity
@Table(name = "\"JavaAnnotation\"")
public class JavaAnnotation extends JavaEntity {
}
Loading