@appthreat/atom 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1 +1,73 @@
1
- console.log("atom plugins check");
1
+ #!/usr/bin/env node
2
+
3
+ const os = require("os");
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { spawnSync } = require("child_process");
7
+ const isWin = require("os").platform() === "win32";
8
+ const LOG4J_CONFIG = path.join(__dirname, "plugins", "log4j2.xml");
9
+ const ATOM_HOME = path.join(__dirname, "plugins", "atom-1.0.0");
10
+ const APP_LIB_DIR = path.join(__dirname, "plugins", "atom-1.0.0", "lib");
11
+ const freeMemoryGB = Math.floor(os.freemem() / 1024 / 1024 / 1024);
12
+ const JAVA_OPTS = `${
13
+ process.env.JAVA_OPTS || ""
14
+ } -Xms${freeMemoryGB}G -Xmx${freeMemoryGB}G`;
15
+ const APP_MAIN_CLASS = "io.appthreat.atom.Atom";
16
+ let APP_CLASSPATH = path.join(APP_LIB_DIR, "io.appthreat.atom-1.0.0.jar");
17
+ let JAVACMD = "java";
18
+ if (process.env.JAVA_HOME) {
19
+ JAVACMD = path.join(
20
+ process.env.JAVA_HOME,
21
+ "bin",
22
+ "java" + (isWin ? ".exe" : "")
23
+ );
24
+ }
25
+ const getAllFiles = (dir, extn, files, result, regex) => {
26
+ regex = regex || new RegExp(`\\.jar$`);
27
+ files = files || fs.readdirSync(dir);
28
+ for (let i = 0; i < files.length; i++) {
29
+ let file = path.join(dir, files[i]);
30
+ if (fs.statSync(file).isDirectory()) {
31
+ // Ignore directories
32
+ const dirName = path.basename(file);
33
+ if (
34
+ dirName.startsWith(".") ||
35
+ IGNORE_DIRS.includes(dirName.toLowerCase())
36
+ ) {
37
+ continue;
38
+ }
39
+ try {
40
+ result = getAllFiles(file, extn, fs.readdirSync(file), result, regex);
41
+ } catch (error) {
42
+ continue;
43
+ }
44
+ } else {
45
+ if (regex.test(file) && !file.includes("io.appthreat.atom-1.0.0.jar")) {
46
+ result.push(file);
47
+ }
48
+ }
49
+ }
50
+ return result;
51
+ };
52
+
53
+ const atomLibs = getAllFiles(APP_LIB_DIR, ".jar", undefined, [APP_CLASSPATH]);
54
+ const argv = process.argv.slice(2);
55
+ const args = [
56
+ "-cp",
57
+ atomLibs.join(path.delimiter),
58
+ `-Dlog4j.configurationFile=${LOG4J_CONFIG}`,
59
+ APP_MAIN_CLASS,
60
+ ...argv
61
+ ];
62
+ const env = {
63
+ ...process.env,
64
+ JAVA_OPTS
65
+ };
66
+ const cwd = process.env.ATOM_CWD || process.cwd();
67
+ spawnSync(JAVACMD, args, {
68
+ encoding: "utf-8",
69
+ env,
70
+ cwd,
71
+ stdio: "inherit",
72
+ stderr: "inherit"
73
+ });
package/package.json CHANGED
@@ -1,11 +1,8 @@
1
1
  {
2
2
  "name": "@appthreat/atom",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "Create atom (⚛) representation for your application, packages and libraries",
5
5
  "main": "index.js",
6
- "bin": {
7
- "atom": "./plugins/atom-1.0.0/bin/atom"
8
- },
9
6
  "scripts": {
10
7
  "pretty": "prettier --write *.js --trailing-comma=none"
11
8
  },
@@ -200,9 +200,9 @@ process_args () {
200
200
 
201
201
  -java-home) require_arg path "$1" "$2" && jre=`eval echo $2` && java_cmd="$jre/bin/java" && shift 2 ;;
202
202
 
203
- -D*|-agentlib*|-XX*) addJava "$1" && shift ;;
204
- -J*) addJava "${1:2}" && shift ;;
205
- *) addResidual "$1" && shift ;;
203
+ -D*|-agentlib*|-agentpath*|-javaagent*|-XX*) addJava "$1" && shift ;;
204
+ -J*) addJava "${1:2}" && shift ;;
205
+ *) addResidual "$1" && shift ;;
206
206
  esac
207
207
  done
208
208
 
@@ -246,6 +246,16 @@ run() {
246
246
  mainclass=("${app_mainclass[@]}")
247
247
  fi
248
248
 
249
+ # Fallback to custom mainclass if main class is not provided (this is the case if the JAR contains multiple apps)
250
+ if [ "$app_mainclass" = "" ] || [ $custom_mainclass ];then
251
+ if [ "$custom_mainclass" = "" ]; then
252
+ echo "You need to pass -main argument."
253
+ exit 1
254
+ fi
255
+
256
+ app_mainclass=$custom_mainclass
257
+ fi
258
+
249
259
  # Now we check to see if there are any java opts on the environment. These get listed first, with the script able to override them.
250
260
  if [[ "$JAVA_OPTS" != "" ]]; then
251
261
  java_opts="${JAVA_OPTS}"
@@ -273,7 +283,7 @@ loadConfigFile() {
273
283
  }
274
284
 
275
285
  # Now check to see if it's a good enough version
276
- # TODO - Check to see if we have a configured default java version, otherwise use 1.6
286
+ # TODO - Check to see if we have a configured default java version, otherwise use 1.8
277
287
  java_version_check() {
278
288
  readonly java_version=$("$java_cmd" -version 2>&1 | awk -F '"' '/version/ {print $2}')
279
289
  if [[ "$java_version" == "" ]]; then
@@ -287,10 +297,10 @@ java_version_check() {
287
297
  if [[ "$major" -eq "1" ]]; then
288
298
  local major=$(echo "$java_version" | cut -d'.' -f2)
289
299
  fi
290
- if [[ "$major" -lt "6" ]]; then
300
+ if [[ "$major" -lt "8" ]]; then
291
301
  echo
292
302
  echo The java installation you have is not up to date
293
- echo $app_name requires at least version 1.6+, you have
303
+ echo $app_name requires at least version 1.8+, you have
294
304
  echo version $java_version
295
305
  echo
296
306
  echo Please go to http://www.java.com/getjava/ and download
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Configuration status="ERROR">
3
+ <Appenders>
4
+ <Console name="Console" target="SYSTEM_ERR">
5
+ <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} %p %c{0}: %msg%n"/>
6
+ </Console>
7
+ </Appenders>
8
+ <Loggers>
9
+ <Root level="ERROR">
10
+ <AppenderRef ref="Console" />
11
+ </Root>
12
+ </Loggers>
13
+ </Configuration>