-
Notifications
You must be signed in to change notification settings - Fork 102
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
base: master
Are you sure you want to change the base?
Java plugin #557
Changes from all commits
43792f1
334e31e
30f57a4
3961e95
c04c3bf
6da5f76
e4f826d
de3932b
9d08b02
d368ea9
b3ad1e4
dbf0bda
5789d9e
aec44b7
8a12fd7
c78306f
91fe93d
733883c
c59280e
edb302d
713098c
b624d72
30b7244
f2b3a00
713cd36
3b08d29
fde8139
eb39cc8
ea87076
2c2d634
3b1784b
ec4ba1e
d1efda0
814b2b9
4485ae7
f772c84
3fa3139
306b799
1f8f571
e59ab77
f471bf3
f1eacfc
d766c15
4b3837e
68754d2
02fe74e
c32f0eb
81fc826
2c6f3fd
3ff3c3a
ab4018a
457cfc5
c3f80e0
6884dc6
ffdd0eb
84ea4c0
baa07de
b62c410
d148a32
b428219
0034a3c
1195677
410baba
5fd3e9f
2ec9998
bcd0caa
8231c50
b360b87
fffdaf3
462a060
1a23df7
7fd9cd1
94df446
22919e1
3c82b06
9771d0a
c85ab2d
c9d6c4f
c49ab28
721de37
7560bcc
d2c3b44
dfbd897
3379a35
9e7fdd1
162e0c9
3f9d64e
7e5f092
25a4fe2
c1b139c
5b87176
e01d185
d34297b
ec36126
2dfd0a5
b8769d3
6cb7798
c0fb7e7
51eaa0b
3de525a
0d60e7c
cc67c3c
f6a3758
131c7e5
ecdc6b9
4ddafbb
84b5931
3003d37
afcd54e
8409b85
d4a6284
5801085
1d8718d
36a5240
2ea7bc3
09633bc
99eeb18
4eee343
d6aa417
912eea7
d241b9a
6475340
2b5d300
b7b304f
e34ffc0
a6b151f
9c6a28d
c437e10
5cc687c
db62899
853b718
edf7be6
e582634
7ed1f9b
e10c230
ffdbd2c
1bb0f42
b2cab25
f5cde28
1d6f0be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ add_library(dummythrift STATIC | |
target_compile_options(dummythrift PUBLIC -fPIC) | ||
|
||
add_library(dummyservice SHARED | ||
src/dummyservice.cpp | ||
src/javaservice.cpp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include <service/dummyservice.h> | ||
#include <service/javaservice.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be changed, |
||
#include <util/dbutil.h> | ||
|
||
namespace cc | ||
|
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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
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) |
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}") |
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; | ||
} | ||
} |
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 |
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 |
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}") |
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; | ||
} | ||
} |
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 { | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unnecessary.