Skip to content

Commit

Permalink
logic: Add support for Java Standard 16 to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
petermost committed Nov 7, 2023
1 parent d3f8811 commit f8748a1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion java_indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.24.0</version>
<version>3.35.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.platform</groupId>
Expand Down
13 changes: 12 additions & 1 deletion java_indexer/src/main/java/com/sourcetrail/JavaIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public static void clearCaches()

private static String convertLanguageStandard(String s)
{
// Must be in sync with 'SourceGroupSettingsWithJavaStandard::getAvailableJavaStandards'
switch (s)
{
case "1":
Expand Down Expand Up @@ -215,8 +216,18 @@ private static String convertLanguageStandard(String s)
case "14":
return JavaCore.VERSION_14;
case "15":
default:
return JavaCore.VERSION_15;
case "16":
return JavaCore.VERSION_16;
case "17":
return JavaCore.VERSION_17;
case "18":
return JavaCore.VERSION_18;
case "19":
return JavaCore.VERSION_19;
case "20":
default:
return JavaCore.VERSION_20;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ void SourceGroupSettingsWithJavaStandard::setJavaStandard(const std::wstring& st

std::vector<std::wstring> SourceGroupSettingsWithJavaStandard::getAvailableJavaStandards() const
{
// Must be in sync with 'JavaIndexer.convertLanguageStandard'.
return {
L"20",
L"19",
L"18",
L"17",
L"16",
L"15",
L"14",
L"13",
Expand All @@ -38,7 +44,8 @@ std::vector<std::wstring> SourceGroupSettingsWithJavaStandard::getAvailableJavaS
L"4",
L"3",
L"2",
L"1"};
L"1"
};
}

bool SourceGroupSettingsWithJavaStandard::equals(const SourceGroupSettingsBase* other) const
Expand Down
28 changes: 13 additions & 15 deletions src/lib_java/data/parser/java/JavaEnvironmentFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,32 @@ void JavaEnvironmentFactory::createInstance(std::string classPath, std::string&

s_classPath = classPath;

const int optionCount = 2;

JavaVM* jvm = nullptr; // Pointer to the JVM (Java Virtual Machine)
JNIEnv* env = nullptr; // Pointer to native interface

JavaVMInitArgs vm_args; // Initialization arguments
JavaVMOption* options = new JavaVMOption[optionCount]; // JVM invocation options
std::vector<JavaVMOption> options; // JVM invocation options
std::string classPathOption = "-Djava.class.path=" + classPath;
options[0].optionString = const_cast<char*>(classPathOption.c_str());
options[1].optionString = const_cast<char*>("-Xms64m");
options.push_back({ const_cast<char*>(classPathOption.c_str()) });
options.push_back({ const_cast<char*>("-Xms64m") });

// Use this option to allow attaching a debugger:
//options.push_back({ const_cast<char*>("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8000") });
//
// use these options to enable profiling in VisualVM
// options[2].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote");
// options[3].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.port=9010");
// options[4].optionString =
// const_cast<char*>("-Dcom.sun.management.jmxremote.local.only=false"); options[5].optionString
// = const_cast<char*>("-Dcom.sun.management.jmxremote.authenticate=false");
// options[6].optionString = const_cast<char*>("-Dcom.sun.management.jmxremote.ssl=false");
//options.push_back({ const_cast<char*>("-Dcom.sun.management.jmxremote") });
//options.push_back({ const_cast<char*>("-Dcom.sun.management.jmxremote.port=9010") });
//options.push_back({ const_cast<char*>("-Dcom.sun.management.jmxremote.local.only=false") });
//options.push_back({ const_cast<char*>("-Dcom.sun.management.jmxremote.authenticate=false") });
//options.push_back({ const_cast<char*>("-Dcom.sun.management.jmxremote.ssl=false") });

vm_args.version = JNI_VERSION_1_8;
vm_args.nOptions = optionCount;
vm_args.options = options;
vm_args.nOptions = static_cast<jint>(options.size());
vm_args.options = options.data();
vm_args.ignoreUnrecognized = false; // invalid options make the JVM init fail

jint rc = createInstanceFunction(&jvm, (void**)&env, &vm_args);

delete[] options;

if (rc != JNI_OK)
{
if (rc == JNI_EVERSION)
Expand Down

0 comments on commit f8748a1

Please sign in to comment.