fixes for sigar, get pid, and unit tests

This commit is contained in:
Greg DiCristofaro 2022-11-16 09:02:59 -05:00
parent 55db946b0d
commit 0f6cefbcb5
10 changed files with 18 additions and 74 deletions

View File

@ -32,13 +32,16 @@ import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import javax.swing.filechooser.FileSystemView;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.openide.modules.InstalledFileLocator;
import org.openide.modules.Places;
import org.openide.util.NbBundle;
@ -535,16 +538,12 @@ public class PlatformUtil {
public static synchronized long[] getJavaPIDs(String argsSubQuery) {
try {
if (isWindowsOS()) {
Process process = Runtime.getRuntime().exec("wmic process where \"name='java.exe' AND commandline LIKE '%" + argsSubQuery + "%'\" get ProcessID");
BufferedReader reader
= new BufferedReader(new InputStreamReader(process.getInputStream()));
List<String> lines = new ArrayList<>();
String line = null;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
return lines.stream().skip(1).map(ln -> {
ProcessBuilder pb = new ProcessBuilder("wmic process where \"name='java.exe' AND commandline LIKE '%" + argsSubQuery + "%'\" get ProcessID");
String output = IOUtils.toString(pb.start().getInputStream(), StandardCharsets.UTF_8);
String[] lines = output.split("\\r?\\n");
return Stream.of(lines).skip(1).map(ln -> {
if (ln == null || ln.trim().isEmpty()) {
return null;
}
@ -561,14 +560,9 @@ public class PlatformUtil {
} else {
String sigarRegexQuery = argsSubQuery == null ? "" : argsSubQuery.replaceAll("_", ".").replaceAll("%", ".*");
Process process = Runtime.getRuntime().exec("ps -ef | grep -E 'java.*" + sigarRegexQuery + "'");
BufferedReader reader
= new BufferedReader(new InputStreamReader(process.getInputStream()));
List<String> lines = new ArrayList<>();
String line = null;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
ProcessBuilder pb = new ProcessBuilder("ps -ef | grep -E 'java.*" + sigarRegexQuery + "'");
String output = IOUtils.toString(pb.start().getInputStream(), StandardCharsets.UTF_8);
List<String> lines = Arrays.asList(output.split("\\r?\\n"));
if (lines.size() > 0) {
// ignore last one as it will be the same as this command

View File

@ -1,13 +1,7 @@
<project name="NativeCoreLibs">
<target name="build-native-libs" description="build native library dependencies">
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.dylib"/>
</patternset> -->
</unzip>
</target>
</project>

View File

@ -1,13 +1,7 @@
<project name="NativeCoreLibs">
<target name="build-native-libs" description="build native library dependencies">
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.so"/>
</patternset> -->
</unzip>
</target>
</project>

View File

@ -1,13 +1,7 @@
<project name="NativeCoreLibs">
<target name="build-native-libs" description="build native library dependencies">
<!-- sigar: note, matching jar is pulled with ivy -->
<mkdir dir="${lib.dir}"/>
<unzip src="${thirdparty.dir}/sigar/1.6.4/sigar-native.zip" dest="${lib.dir}" >
<!-- get all, rely on jna to locate <patternset>
<include name="**/*.dll"/>
</patternset> -->
</unzip>
</target>
</project>

View File

@ -41,9 +41,6 @@
<dependency conf="autopsy_core->default" org="net.htmlparser.jericho" name="jericho-html" rev="3.4"/>
<dependency conf="autopsy_core->default" org="com.fasterxml.jackson.dataformat" name="jackson-dataformat-csv" rev="2.13.2"/>
<!-- process and system monitoring, note: matching native libs pulled from thirdparty -->
<dependency conf="autopsy_core->default" org="org.fusesource" name="sigar" rev="1.6.4" />
<!-- better image resizing -->
<dependency conf="autopsy_core->default" org="org.imgscalr" name="imgscalr-lib" rev="4.2" />

View File

@ -109,7 +109,6 @@ file.reference.protobuf-java-3.19.4.jar=release/modules/ext/protobuf-java-3.19.4
file.reference.protobuf-java-util-3.19.4.jar=release/modules/ext/protobuf-java-util-3.19.4.jar
file.reference.re2j-1.5.jar=release/modules/ext/re2j-1.5.jar
file.reference.reload4j-1.2.19.jar=release/modules/ext/reload4j-1.2.19.jar
file.reference.sigar-1.6.4.jar=release/modules/ext/sigar-1.6.4.jar
file.reference.slf4j-api-1.7.36.jar=release/modules/ext/slf4j-api-1.7.36.jar
file.reference.slf4j-reload4j-1.7.36.jar=release/modules/ext/slf4j-reload4j-1.7.36.jar
file.reference.threetenbp-1.5.2.jar=release/modules/ext/threetenbp-1.5.2.jar

View File

@ -445,17 +445,6 @@
<package>org.freedesktop.gstreamer.message</package>
<package>org.freedesktop.gstreamer.query</package>
<package>org.freedesktop.gstreamer.webrtc</package>
<package>org.hyperic.jni</package>
<package>org.hyperic.sigar</package>
<package>org.hyperic.sigar.cmd</package>
<package>org.hyperic.sigar.jmx</package>
<package>org.hyperic.sigar.pager</package>
<package>org.hyperic.sigar.ptql</package>
<package>org.hyperic.sigar.shell</package>
<package>org.hyperic.sigar.test</package>
<package>org.hyperic.sigar.util</package>
<package>org.hyperic.sigar.vmware</package>
<package>org.hyperic.sigar.win32</package>
<package>org.imgscalr</package>
<package>org.joda.time</package>
<package>org.joda.time.base</package>
@ -926,10 +915,6 @@
<runtime-relative-path>ext/reload4j-1.2.19.jar</runtime-relative-path>
<binary-origin>release/modules/ext/reload4j-1.2.19.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/sigar-1.6.4.jar</runtime-relative-path>
<binary-origin>release/modules/ext/sigar-1.6.4.jar</binary-origin>
</class-path-extension>
<class-path-extension>
<runtime-relative-path>ext/slf4j-api-1.7.36.jar</runtime-relative-path>
<binary-origin>release/modules/ext/slf4j-api-1.7.36.jar</binary-origin>

View File

@ -4,4 +4,3 @@ OpenIDE-Module-Long-Description=\
The libraries can also be imported by other modules.
OpenIDE-Module-Name=Autopsy-CoreLibs
OpenIDE-Module-Short-Description=Autopsy Core module external libraries
SigarLoader.linkErr.msg=Could not load sigar library for your environment (non-critical), OS-level metrics will be unavailable.

View File

@ -88,25 +88,13 @@
<!-- This target is similar to the regular test target that calls test on all nbm's,
but this target excludes the Testing nbm which runs the regression tests -->
<target name="test-no-regression" depends="build" description="Runs tests for all modules in the suite excluding the regression tests of the Testing NBM.">
<!--taken from https://stackoverflow.com/a/10859103; remove "Testing" from the modules and provide 'modulesNoTesting' as result. -->
<property name="modulesBeforeChange" value="${modules}"/>
<script language="javascript">
<![CDATA[
var before = project.getProperty("modulesBeforeChange");
var separator = ":";
var testingNbm = "Testing";
var beforeSplit = before.split(separator);
var items = [];
for (var i = 0; i < beforeSplit.length; i++) {
if (beforeSplit[i].toUpperCase() !== testingNbm.toUpperCase()) {
items.push(beforeSplit[i]);
}
}
var itemsJoined = items.join(separator);
project.setNewProperty("modulesNoTesting", itemsJoined);
]]>
</script>
<!--taken from https://stackoverflow.com/a/1176101/2375948 ; remove "Testing" from the modules and provide 'modulesNoTesting' as result. -->
<propertyregex property="modulesNoTesting"
input="${modules}"
regexp="Testing[;:]?"
replace=""
global="true" />
<sortsuitemodules unsortedmodules="${modulesNoTesting}" sortedmodulesproperty="modules.test.sorted" sorttests="true"/>
<!-- continue on fail -->
<property name="continue.after.failing.tests" value="true"/>

Binary file not shown.