@dxworks/insider 2.9.1
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/.github/workflows/build.yml +19 -0
- package/.github/workflows/release-docs.yml +15 -0
- package/.github/workflows/release-voyager.yml +57 -0
- package/.github/workflows/release.yml +102 -0
- package/Dockerfile +8 -0
- package/README.md +89 -0
- package/TODO.txt +7 -0
- package/bin/insider.bat +1 -0
- package/bin/insider.sh +1 -0
- package/build.gradle +55 -0
- package/config/.ignore +4 -0
- package/config/comments.json +71 -0
- package/config/fingerprints/_anomalies-full.json +116 -0
- package/config/fingerprints/_extLibs.json +2555 -0
- package/config/fingerprints/code_smells.json +94 -0
- package/config/fingerprints/generated_code.json +17 -0
- package/config/fingerprints/libraries.json +4667 -0
- package/config/ignoredImports.txt +0 -0
- package/config/insider-conf.properties +3 -0
- package/config/rules/cloud_services/ad_networks.json +50 -0
- package/config/rules/cloud_services/bigdata.json +21 -0
- package/config/rules/cloud_services/cloud_hosting.json +398 -0
- package/config/rules/cloud_services/data_storage.json +291 -0
- package/config/rules/cloud_services/ecommerce.json +45 -0
- package/config/rules/cloud_services/socialmedia.json +82 -0
- package/config/rules/cloud_services/web_analytics.json +108 -0
- package/config/rules/components/active_content.json +157 -0
- package/config/rules/components/load_dll.json +66 -0
- package/config/rules/cryptography/algorithm_implementation.json +62 -0
- package/config/rules/cryptography/certificate.json +199 -0
- package/config/rules/cryptography/ciphers.json +174 -0
- package/config/rules/cryptography/crypto_currency.json +32 -0
- package/config/rules/cryptography/encoding.json +20 -0
- package/config/rules/cryptography/extended.json +220 -0
- package/config/rules/cryptography/external_libraries.json +141 -0
- package/config/rules/cryptography/hash_algorithm.json +98 -0
- package/config/rules/cryptography/key_derivation.json +65 -0
- package/config/rules/cryptography/protocol.json +156 -0
- package/config/rules/cryptography/random.json +97 -0
- package/config/rules/cryptography/weakssl.json +206 -0
- package/config/rules/data_handling/compressed_files.json +18 -0
- package/config/rules/data_handling/database.json +361 -0
- package/config/rules/data_handling/deserialization.json +296 -0
- package/config/rules/data_handling/json_parsing.json +49 -0
- package/config/rules/data_handling/media_parsing.json +33 -0
- package/config/rules/data_handling/pastebin.json +18 -0
- package/config/rules/data_handling/xml_parsing.json +168 -0
- package/config/rules/data_types/financial.json +106 -0
- package/config/rules/data_types/media.json +48 -0
- package/config/rules/data_types/secrets.json +91 -0
- package/config/rules/data_types/sensitive.json +176 -0
- package/config/rules/device_permissions/IOSPermissions.json +240 -0
- package/config/rules/device_permissions/UWP.json +221 -0
- package/config/rules/device_permissions/android_intents.json +599 -0
- package/config/rules/frameworks/PHP.json +172 -0
- package/config/rules/frameworks/build.json +189 -0
- package/config/rules/frameworks/c.json +45 -0
- package/config/rules/frameworks/csharp-nonMS.json +19 -0
- package/config/rules/frameworks/java.json +291 -0
- package/config/rules/frameworks/javascript.json +318 -0
- package/config/rules/frameworks/logging.json +103 -0
- package/config/rules/frameworks/microsoft.json +257 -0
- package/config/rules/frameworks/python.json +274 -0
- package/config/rules/frameworks/ruby.json +53 -0
- package/config/rules/frameworks/rust.json +77 -0
- package/config/rules/general/OSS_license.json +146 -0
- package/config/rules/general/code_metrics.json +132 -0
- package/config/rules/general/dependencies.json +199 -0
- package/config/rules/general/hygiene.json +47 -0
- package/config/rules/general/platforms.json +283 -0
- package/config/rules/general/solutioninfo.json +378 -0
- package/config/rules/infrastructure/hashicorp_packers_tmpl.json +18 -0
- package/config/rules/infrastructure/hashicorp_terraform_tmpl.json +19 -0
- package/config/rules/infrastructure/microsoft_arm_tmpl.json +198 -0
- package/config/rules/networkcomms/outbound_network.json +429 -0
- package/config/rules/os/acl.json +250 -0
- package/config/rules/os/dynamic_execution.json +359 -0
- package/config/rules/os/file_io.json +468 -0
- package/config/rules/os/process.json +179 -0
- package/config/rules/os/setenv.json +270 -0
- package/config/rules/os/system_registry.json +237 -0
- package/config/rules/os/user_accts.json +34 -0
- package/config/rules/security_feature/authentication.json +387 -0
- package/config/rules/security_feature/authorization.json +148 -0
- package/config/rules/test_frameworks/cpp_testing.json +194 -0
- package/config/rules/test_frameworks/go_testing.json +18 -0
- package/config/rules/test_frameworks/java_testing.json +720 -0
- package/config/rules/test_frameworks/javascript_testing.json +724 -0
- package/config/rules/test_frameworks/objectiveC_testing.json +146 -0
- package/config/rules/test_frameworks/php_testing.json +156 -0
- package/config/rules/test_frameworks/powershell_testing.json +17 -0
- package/config/rules/test_frameworks/python_testing.json +108 -0
- package/config/rules/test_frameworks/ruby_testing.json +114 -0
- package/config/rules/tools/pipeline.json +195 -0
- package/config/rules/webapp/comms.json +89 -0
- package/config/rules/webapp/headers.json +178 -0
- package/config/rules/webapp/media.json +56 -0
- package/config/rules/webapp/sessions.json +228 -0
- package/config/rules/webapp/storage.json +215 -0
- package/dist/config/.ignore +4 -0
- package/dist/config/comments.json +71 -0
- package/dist/config/fingerprints/_anomalies-full.json +116 -0
- package/dist/config/fingerprints/_extLibs.json +2555 -0
- package/dist/config/fingerprints/code_smells.json +94 -0
- package/dist/config/fingerprints/generated_code.json +17 -0
- package/dist/config/fingerprints/libraries.json +4667 -0
- package/dist/config/ignoredImports.txt +0 -0
- package/dist/config/insider-conf.properties +3 -0
- package/dist/config/rules/cloud_services/ad_networks.json +50 -0
- package/dist/config/rules/cloud_services/bigdata.json +21 -0
- package/dist/config/rules/cloud_services/cloud_hosting.json +398 -0
- package/dist/config/rules/cloud_services/data_storage.json +291 -0
- package/dist/config/rules/cloud_services/ecommerce.json +45 -0
- package/dist/config/rules/cloud_services/socialmedia.json +82 -0
- package/dist/config/rules/cloud_services/web_analytics.json +108 -0
- package/dist/config/rules/components/active_content.json +157 -0
- package/dist/config/rules/components/load_dll.json +66 -0
- package/dist/config/rules/cryptography/algorithm_implementation.json +62 -0
- package/dist/config/rules/cryptography/certificate.json +199 -0
- package/dist/config/rules/cryptography/ciphers.json +174 -0
- package/dist/config/rules/cryptography/crypto_currency.json +32 -0
- package/dist/config/rules/cryptography/encoding.json +20 -0
- package/dist/config/rules/cryptography/extended.json +220 -0
- package/dist/config/rules/cryptography/external_libraries.json +141 -0
- package/dist/config/rules/cryptography/hash_algorithm.json +98 -0
- package/dist/config/rules/cryptography/key_derivation.json +65 -0
- package/dist/config/rules/cryptography/protocol.json +156 -0
- package/dist/config/rules/cryptography/random.json +97 -0
- package/dist/config/rules/cryptography/weakssl.json +206 -0
- package/dist/config/rules/data_handling/compressed_files.json +18 -0
- package/dist/config/rules/data_handling/database.json +361 -0
- package/dist/config/rules/data_handling/deserialization.json +296 -0
- package/dist/config/rules/data_handling/json_parsing.json +49 -0
- package/dist/config/rules/data_handling/media_parsing.json +33 -0
- package/dist/config/rules/data_handling/pastebin.json +18 -0
- package/dist/config/rules/data_handling/xml_parsing.json +168 -0
- package/dist/config/rules/data_types/financial.json +106 -0
- package/dist/config/rules/data_types/media.json +48 -0
- package/dist/config/rules/data_types/secrets.json +91 -0
- package/dist/config/rules/data_types/sensitive.json +176 -0
- package/dist/config/rules/device_permissions/IOSPermissions.json +240 -0
- package/dist/config/rules/device_permissions/UWP.json +221 -0
- package/dist/config/rules/device_permissions/android_intents.json +599 -0
- package/dist/config/rules/frameworks/PHP.json +172 -0
- package/dist/config/rules/frameworks/build.json +189 -0
- package/dist/config/rules/frameworks/c.json +45 -0
- package/dist/config/rules/frameworks/csharp-nonMS.json +19 -0
- package/dist/config/rules/frameworks/java.json +291 -0
- package/dist/config/rules/frameworks/javascript.json +318 -0
- package/dist/config/rules/frameworks/logging.json +103 -0
- package/dist/config/rules/frameworks/microsoft.json +257 -0
- package/dist/config/rules/frameworks/python.json +274 -0
- package/dist/config/rules/frameworks/ruby.json +53 -0
- package/dist/config/rules/frameworks/rust.json +77 -0
- package/dist/config/rules/general/OSS_license.json +146 -0
- package/dist/config/rules/general/code_metrics.json +132 -0
- package/dist/config/rules/general/dependencies.json +199 -0
- package/dist/config/rules/general/hygiene.json +47 -0
- package/dist/config/rules/general/platforms.json +283 -0
- package/dist/config/rules/general/solutioninfo.json +378 -0
- package/dist/config/rules/infrastructure/hashicorp_packers_tmpl.json +18 -0
- package/dist/config/rules/infrastructure/hashicorp_terraform_tmpl.json +19 -0
- package/dist/config/rules/infrastructure/microsoft_arm_tmpl.json +198 -0
- package/dist/config/rules/networkcomms/outbound_network.json +429 -0
- package/dist/config/rules/os/acl.json +250 -0
- package/dist/config/rules/os/dynamic_execution.json +359 -0
- package/dist/config/rules/os/file_io.json +468 -0
- package/dist/config/rules/os/process.json +179 -0
- package/dist/config/rules/os/setenv.json +270 -0
- package/dist/config/rules/os/system_registry.json +237 -0
- package/dist/config/rules/os/user_accts.json +34 -0
- package/dist/config/rules/security_feature/authentication.json +387 -0
- package/dist/config/rules/security_feature/authorization.json +148 -0
- package/dist/config/rules/test_frameworks/cpp_testing.json +194 -0
- package/dist/config/rules/test_frameworks/go_testing.json +18 -0
- package/dist/config/rules/test_frameworks/java_testing.json +720 -0
- package/dist/config/rules/test_frameworks/javascript_testing.json +724 -0
- package/dist/config/rules/test_frameworks/objectiveC_testing.json +146 -0
- package/dist/config/rules/test_frameworks/php_testing.json +156 -0
- package/dist/config/rules/test_frameworks/powershell_testing.json +17 -0
- package/dist/config/rules/test_frameworks/python_testing.json +108 -0
- package/dist/config/rules/test_frameworks/ruby_testing.json +114 -0
- package/dist/config/rules/tools/pipeline.json +195 -0
- package/dist/config/rules/webapp/comms.json +89 -0
- package/dist/config/rules/webapp/headers.json +178 -0
- package/dist/config/rules/webapp/media.json +56 -0
- package/dist/config/rules/webapp/sessions.json +228 -0
- package/dist/config/rules/webapp/storage.json +215 -0
- package/dist/index.js +13 -0
- package/dist/insider.jar +0 -0
- package/dist/insider.js +7 -0
- package/dist/lib.js +21 -0
- package/docs/config/config.md +3 -0
- package/docs/config/ignore.md +3 -0
- package/docs/config/languages.md +3 -0
- package/docs/index.md +58 -0
- package/dxworks-site.json +13 -0
- package/gradle.properties +0 -0
- package/gradlew +240 -0
- package/gradlew.bat +91 -0
- package/insider/README.md +89 -0
- package/insider/config/.ignore +4 -0
- package/insider/config/comments.json +71 -0
- package/insider/config/fingerprints/_anomalies-full.json +116 -0
- package/insider/config/fingerprints/_extLibs.json +2555 -0
- package/insider/config/fingerprints/code_smells.json +94 -0
- package/insider/config/fingerprints/generated_code.json +17 -0
- package/insider/config/fingerprints/libraries.json +4667 -0
- package/insider/config/ignoredImports.txt +0 -0
- package/insider/config/insider-conf.properties +3 -0
- package/insider/config/rules/cloud_services/ad_networks.json +50 -0
- package/insider/config/rules/cloud_services/bigdata.json +21 -0
- package/insider/config/rules/cloud_services/cloud_hosting.json +398 -0
- package/insider/config/rules/cloud_services/data_storage.json +291 -0
- package/insider/config/rules/cloud_services/ecommerce.json +45 -0
- package/insider/config/rules/cloud_services/socialmedia.json +82 -0
- package/insider/config/rules/cloud_services/web_analytics.json +108 -0
- package/insider/config/rules/components/active_content.json +157 -0
- package/insider/config/rules/components/load_dll.json +66 -0
- package/insider/config/rules/cryptography/algorithm_implementation.json +62 -0
- package/insider/config/rules/cryptography/certificate.json +199 -0
- package/insider/config/rules/cryptography/ciphers.json +174 -0
- package/insider/config/rules/cryptography/crypto_currency.json +32 -0
- package/insider/config/rules/cryptography/encoding.json +20 -0
- package/insider/config/rules/cryptography/extended.json +220 -0
- package/insider/config/rules/cryptography/external_libraries.json +141 -0
- package/insider/config/rules/cryptography/hash_algorithm.json +98 -0
- package/insider/config/rules/cryptography/key_derivation.json +65 -0
- package/insider/config/rules/cryptography/protocol.json +156 -0
- package/insider/config/rules/cryptography/random.json +97 -0
- package/insider/config/rules/cryptography/weakssl.json +206 -0
- package/insider/config/rules/data_handling/compressed_files.json +18 -0
- package/insider/config/rules/data_handling/database.json +361 -0
- package/insider/config/rules/data_handling/deserialization.json +296 -0
- package/insider/config/rules/data_handling/json_parsing.json +49 -0
- package/insider/config/rules/data_handling/media_parsing.json +33 -0
- package/insider/config/rules/data_handling/pastebin.json +18 -0
- package/insider/config/rules/data_handling/xml_parsing.json +168 -0
- package/insider/config/rules/data_types/financial.json +106 -0
- package/insider/config/rules/data_types/media.json +48 -0
- package/insider/config/rules/data_types/secrets.json +91 -0
- package/insider/config/rules/data_types/sensitive.json +176 -0
- package/insider/config/rules/device_permissions/IOSPermissions.json +240 -0
- package/insider/config/rules/device_permissions/UWP.json +221 -0
- package/insider/config/rules/device_permissions/android_intents.json +599 -0
- package/insider/config/rules/frameworks/PHP.json +172 -0
- package/insider/config/rules/frameworks/build.json +189 -0
- package/insider/config/rules/frameworks/c.json +45 -0
- package/insider/config/rules/frameworks/csharp-nonMS.json +19 -0
- package/insider/config/rules/frameworks/java.json +291 -0
- package/insider/config/rules/frameworks/javascript.json +318 -0
- package/insider/config/rules/frameworks/logging.json +103 -0
- package/insider/config/rules/frameworks/microsoft.json +257 -0
- package/insider/config/rules/frameworks/python.json +274 -0
- package/insider/config/rules/frameworks/ruby.json +53 -0
- package/insider/config/rules/frameworks/rust.json +77 -0
- package/insider/config/rules/general/OSS_license.json +146 -0
- package/insider/config/rules/general/code_metrics.json +132 -0
- package/insider/config/rules/general/dependencies.json +199 -0
- package/insider/config/rules/general/hygiene.json +47 -0
- package/insider/config/rules/general/platforms.json +283 -0
- package/insider/config/rules/general/solutioninfo.json +378 -0
- package/insider/config/rules/infrastructure/hashicorp_packers_tmpl.json +18 -0
- package/insider/config/rules/infrastructure/hashicorp_terraform_tmpl.json +19 -0
- package/insider/config/rules/infrastructure/microsoft_arm_tmpl.json +198 -0
- package/insider/config/rules/networkcomms/outbound_network.json +429 -0
- package/insider/config/rules/os/acl.json +250 -0
- package/insider/config/rules/os/dynamic_execution.json +359 -0
- package/insider/config/rules/os/file_io.json +468 -0
- package/insider/config/rules/os/process.json +179 -0
- package/insider/config/rules/os/setenv.json +270 -0
- package/insider/config/rules/os/system_registry.json +237 -0
- package/insider/config/rules/os/user_accts.json +34 -0
- package/insider/config/rules/security_feature/authentication.json +387 -0
- package/insider/config/rules/security_feature/authorization.json +148 -0
- package/insider/config/rules/test_frameworks/cpp_testing.json +194 -0
- package/insider/config/rules/test_frameworks/go_testing.json +18 -0
- package/insider/config/rules/test_frameworks/java_testing.json +720 -0
- package/insider/config/rules/test_frameworks/javascript_testing.json +724 -0
- package/insider/config/rules/test_frameworks/objectiveC_testing.json +146 -0
- package/insider/config/rules/test_frameworks/php_testing.json +156 -0
- package/insider/config/rules/test_frameworks/powershell_testing.json +17 -0
- package/insider/config/rules/test_frameworks/python_testing.json +108 -0
- package/insider/config/rules/test_frameworks/ruby_testing.json +114 -0
- package/insider/config/rules/tools/pipeline.json +195 -0
- package/insider/config/rules/webapp/comms.json +89 -0
- package/insider/config/rules/webapp/headers.json +178 -0
- package/insider/config/rules/webapp/media.json +56 -0
- package/insider/config/rules/webapp/sessions.json +228 -0
- package/insider/config/rules/webapp/storage.json +215 -0
- package/insider/insider.bat +1 -0
- package/insider/insider.jar +0 -0
- package/insider/insider.sh +1 -0
- package/insider/languages.yml +3988 -0
- package/instrument.yml +37 -0
- package/languages.yml +3988 -0
- package/lib/index.js +13 -0
- package/lib/insider.js +7 -0
- package/lib/lib.js +21 -0
- package/lombok.config +2 -0
- package/mkdocs.yml +18 -0
- package/package.json +51 -0
- package/releaseNotes/v2.6.0.md +1 -0
- package/releaseNotes/v2.7.1.md +1 -0
- package/settings.gradle +2 -0
- package/src/main/java/org/dxworks/insider/ChronosTag.java +14 -0
- package/src/main/java/org/dxworks/insider/Insider.java +214 -0
- package/src/main/java/org/dxworks/insider/InsiderAnalysis.java +7 -0
- package/src/main/java/org/dxworks/insider/InsiderFile.java +125 -0
- package/src/main/java/org/dxworks/insider/InsiderOptions.java +78 -0
- package/src/main/java/org/dxworks/insider/InsiderResult.java +15 -0
- package/src/main/java/org/dxworks/insider/application/inspector/CodeRuleExtractor.java +14 -0
- package/src/main/java/org/dxworks/insider/application/inspector/CommentRuleExtractor.java +14 -0
- package/src/main/java/org/dxworks/insider/application/inspector/FileRuleExtractor.java +14 -0
- package/src/main/java/org/dxworks/insider/application/inspector/RuleExtractor.java +11 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/Comment.java +18 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/CommentPattern.java +44 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/Condition.java +15 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/InsiderPattern.java +149 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/PatternMatch.java +23 -0
- package/src/main/java/org/dxworks/insider/application/inspector/dtos/Rule.java +61 -0
- package/src/main/java/org/dxworks/insider/application/inspector/services/CommentService.java +165 -0
- package/src/main/java/org/dxworks/insider/application/inspector/services/RuleService.java +54 -0
- package/src/main/java/org/dxworks/insider/commands/AddCommand.java +125 -0
- package/src/main/java/org/dxworks/insider/commands/AllFilesCommand.java +4 -0
- package/src/main/java/org/dxworks/insider/commands/ConvertCommand.java +55 -0
- package/src/main/java/org/dxworks/insider/commands/DetectCommand.java +42 -0
- package/src/main/java/org/dxworks/insider/commands/DiagnoseCommand.java +74 -0
- package/src/main/java/org/dxworks/insider/commands/ExtractCommand.java +35 -0
- package/src/main/java/org/dxworks/insider/commands/FindCommand.java +102 -0
- package/src/main/java/org/dxworks/insider/commands/HelpCommand.java +56 -0
- package/src/main/java/org/dxworks/insider/commands/IndentationCount.java +69 -0
- package/src/main/java/org/dxworks/insider/commands/InsiderCommand.java +71 -0
- package/src/main/java/org/dxworks/insider/commands/InspectCommand.java +98 -0
- package/src/main/java/org/dxworks/insider/commands/MeasureCommand.java +47 -0
- package/src/main/java/org/dxworks/insider/commands/NoFilesCommand.java +4 -0
- package/src/main/java/org/dxworks/insider/commands/VersionCommand.java +34 -0
- package/src/main/java/org/dxworks/insider/configuration/InsiderConfiguration.java +123 -0
- package/src/main/java/org/dxworks/insider/constants/InsiderConstants.java +19 -0
- package/src/main/java/org/dxworks/insider/depext/AbstractImportsProcessor.java +57 -0
- package/src/main/java/org/dxworks/insider/depext/CPPImportsProcessor.java +55 -0
- package/src/main/java/org/dxworks/insider/depext/CSharpImportsProcessor.java +53 -0
- package/src/main/java/org/dxworks/insider/depext/DependencyExtractor.java +105 -0
- package/src/main/java/org/dxworks/insider/depext/ImportItem.java +19 -0
- package/src/main/java/org/dxworks/insider/depext/ImportResult.java +32 -0
- package/src/main/java/org/dxworks/insider/depext/JavastackImportsProcessor.java +88 -0
- package/src/main/java/org/dxworks/insider/depext/VBImportsProcessor.java +41 -0
- package/src/main/java/org/dxworks/insider/exceptions/InsiderException.java +7 -0
- package/src/main/java/org/dxworks/insider/library/detector/C_ImportsContainer.java +73 -0
- package/src/main/java/org/dxworks/insider/library/detector/ImportsContainer.java +122 -0
- package/src/main/java/org/dxworks/insider/library/detector/JavaImportsContainer.java +63 -0
- package/src/main/java/org/dxworks/insider/library/detector/LibraryDetector.java +150 -0
- package/src/main/java/org/dxworks/insider/library/detector/LibraryDetectorLanguage.java +6 -0
- package/src/main/java/org/dxworks/insider/library/detector/model/PackagingUnit.java +26 -0
- package/src/main/java/org/dxworks/insider/technology/finder/LinguistService.java +79 -0
- package/src/main/java/org/dxworks/insider/technology/finder/converters/XmlToJsonConverter.java +41 -0
- package/src/main/java/org/dxworks/insider/technology/finder/exceptions/FingerprintParseException.java +7 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/Technology.java +73 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/json/JsonConfigurationDTO.java +14 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/json/TechnologyJsonDTO.java +66 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/CategoryXmlDTO.java +21 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/ConfigurationDataXmlDTO.java +17 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/FingerprintXmlDTO.java +17 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/LanguageXmlDTO.java +20 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/LanguagesXmlDTO.java +18 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/TechnologyXmlDTO.java +19 -0
- package/src/main/java/org/dxworks/insider/technology/finder/model/xml/old/XmlConfigurationDTO.java +17 -0
- package/src/main/java/org/dxworks/insider/technology/finder/parsers/FingerprintsParser.java +14 -0
- package/src/main/java/org/dxworks/insider/technology/finder/parsers/FingerprintsXmlParser.java +57 -0
- package/src/main/java/org/dxworks/insider/technology/finder/parsers/JavaLibrariesCsvParser.java +71 -0
- package/src/main/java/org/dxworks/insider/technology/finder/parsers/JsonFingerprintParser.java +58 -0
- package/src/main/java/org/dxworks/insider/utils/FileUtils.java +45 -0
- package/src/main/java/org/dxworks/insider/utils/ImportUtils.java +21 -0
- package/src/main/java/org/dxworks/insider/utils/LibraryImport.java +17 -0
- package/src/main/java/org/dxworks/insider/utils/LibraryImportInOtherTechnology.java +30 -0
- package/src/main/java/org/dxworks/insider/utils/MapUtils.java +19 -0
- package/src/main/resources/insider-version +1 -0
- package/src/test/java/org/dxworks/insider/application/inspector/services/CommentServiceTest.java +40 -0
- package/src/test/java/org/dxworks/insider/technology/finder/parsers/FingerprintsXmlParserTest.java +15 -0
- package/src/test/java/org/dxworks/insider/utils/FileUtilsTest.java +31 -0
- package/src/test/java/org/dxworks/insider/utils/ImportUtilsTest.java +24 -0
- package/src/test/java/org/dxworks/insider/utils/transformers/JsonToCsvTransformerTest.java +18 -0
- package/src/test/resources/Test1.java +21 -0
- package/src/test/resources/Test2.java +21 -0
- package/src/test/resources/cobol/CM201M.CBL +88 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.dtos;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
4
|
+
import lombok.AllArgsConstructor;
|
|
5
|
+
import lombok.Data;
|
|
6
|
+
import lombok.NoArgsConstructor;
|
|
7
|
+
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.List;
|
|
10
|
+
|
|
11
|
+
import static java.util.regex.Pattern.*;
|
|
12
|
+
|
|
13
|
+
@Data
|
|
14
|
+
@NoArgsConstructor
|
|
15
|
+
@AllArgsConstructor
|
|
16
|
+
public
|
|
17
|
+
class CommentPattern {
|
|
18
|
+
private String pattern;
|
|
19
|
+
private List<String> modifiers;
|
|
20
|
+
|
|
21
|
+
@JsonIgnore
|
|
22
|
+
private int regexFlags = -1;
|
|
23
|
+
|
|
24
|
+
public int createModifier() {
|
|
25
|
+
if (regexFlags != -1)
|
|
26
|
+
return regexFlags;
|
|
27
|
+
|
|
28
|
+
regexFlags = 0;
|
|
29
|
+
|
|
30
|
+
if (modifiers == null)
|
|
31
|
+
modifiers = new ArrayList<>();
|
|
32
|
+
|
|
33
|
+
if (modifiers.contains("i"))
|
|
34
|
+
regexFlags = regexFlags | CASE_INSENSITIVE;
|
|
35
|
+
|
|
36
|
+
if (modifiers.contains("d"))
|
|
37
|
+
regexFlags = regexFlags | DOTALL;
|
|
38
|
+
|
|
39
|
+
if (modifiers.contains("m"))
|
|
40
|
+
regexFlags = regexFlags | MULTILINE;
|
|
41
|
+
|
|
42
|
+
return regexFlags;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.dtos;
|
|
2
|
+
|
|
3
|
+
import lombok.AllArgsConstructor;
|
|
4
|
+
import lombok.Data;
|
|
5
|
+
import lombok.NoArgsConstructor;
|
|
6
|
+
|
|
7
|
+
@Data
|
|
8
|
+
@NoArgsConstructor
|
|
9
|
+
@AllArgsConstructor
|
|
10
|
+
public class Condition {
|
|
11
|
+
private InsiderPattern pattern;
|
|
12
|
+
private String search_in;
|
|
13
|
+
private boolean negate_finding;
|
|
14
|
+
private String _comment;
|
|
15
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.dtos;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
4
|
+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
5
|
+
import lombok.AllArgsConstructor;
|
|
6
|
+
import lombok.Data;
|
|
7
|
+
import lombok.NoArgsConstructor;
|
|
8
|
+
import lombok.extern.slf4j.Slf4j;
|
|
9
|
+
import org.apache.commons.lang.math.IntRange;
|
|
10
|
+
import org.dxworks.insider.InsiderFile;
|
|
11
|
+
|
|
12
|
+
import java.util.ArrayList;
|
|
13
|
+
import java.util.Arrays;
|
|
14
|
+
import java.util.Collections;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.regex.Matcher;
|
|
17
|
+
import java.util.regex.Pattern;
|
|
18
|
+
import java.util.regex.PatternSyntaxException;
|
|
19
|
+
import java.util.stream.Collectors;
|
|
20
|
+
import static java.util.regex.Pattern.*;
|
|
21
|
+
|
|
22
|
+
@Slf4j
|
|
23
|
+
@Data
|
|
24
|
+
@NoArgsConstructor
|
|
25
|
+
@AllArgsConstructor
|
|
26
|
+
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
27
|
+
public class InsiderPattern {
|
|
28
|
+
private static final String REGEX_WORD = "regex-word";
|
|
29
|
+
|
|
30
|
+
private String pattern;
|
|
31
|
+
private String type;
|
|
32
|
+
private String confidence;
|
|
33
|
+
private List<String> modifiers;
|
|
34
|
+
private List<String> scopes;
|
|
35
|
+
private String _comment;
|
|
36
|
+
private boolean hasErrors = false;
|
|
37
|
+
@JsonIgnore
|
|
38
|
+
private int regexFlags = -1;
|
|
39
|
+
|
|
40
|
+
public List<PatternMatch> getMatches(InsiderFile file, List<IntRange> commentRanges) {
|
|
41
|
+
if (hasErrors)
|
|
42
|
+
return Collections.emptyList();
|
|
43
|
+
|
|
44
|
+
if (scopes.contains("all") || scopes.containsAll(Arrays.asList("code", "comment"))) {
|
|
45
|
+
return matchesInEntireFile(file);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
List<PatternMatch> matches = new ArrayList<>();
|
|
49
|
+
|
|
50
|
+
if (scopes.contains("code")) {
|
|
51
|
+
matches.addAll(getCodeMatches(file, commentRanges));
|
|
52
|
+
}
|
|
53
|
+
if (scopes.contains("comment")) {
|
|
54
|
+
matches.addAll(getCommentMatches(file, commentRanges));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return matches;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public void transformPattern() {
|
|
61
|
+
if (REGEX_WORD.equals(type))
|
|
62
|
+
transformPatternIfWord();
|
|
63
|
+
if ("string".equals(type)) {
|
|
64
|
+
pattern = Pattern.quote(pattern);
|
|
65
|
+
pattern = String.format("\\b(%s)\\b", pattern);
|
|
66
|
+
}
|
|
67
|
+
if ("substring".equals(type))
|
|
68
|
+
pattern = Pattern.quote(pattern);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private List<PatternMatch> matchesInEntireFile(InsiderFile file) {
|
|
72
|
+
List<PatternMatch> matches = new ArrayList<>();
|
|
73
|
+
try {
|
|
74
|
+
Matcher matcher = Pattern.compile(pattern, createModifier()).matcher(file.getContent());
|
|
75
|
+
while (matcher.find()) {
|
|
76
|
+
int start = matcher.start();
|
|
77
|
+
int end = matcher.end();
|
|
78
|
+
PatternMatch patternMatch = createPatternMatch(start, end, file);
|
|
79
|
+
matches.add(patternMatch);
|
|
80
|
+
}
|
|
81
|
+
} catch (PatternSyntaxException e) {
|
|
82
|
+
hasErrors = true;
|
|
83
|
+
System.out.println();
|
|
84
|
+
log.error("Could not compile pattern '{}' due to: {}", pattern, e.getMessage());
|
|
85
|
+
}
|
|
86
|
+
return matches;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private int createModifier() {
|
|
90
|
+
if(regexFlags != -1)
|
|
91
|
+
return regexFlags;
|
|
92
|
+
|
|
93
|
+
regexFlags = 0 ;
|
|
94
|
+
|
|
95
|
+
if(modifiers == null)
|
|
96
|
+
modifiers = new ArrayList<>();
|
|
97
|
+
|
|
98
|
+
if(modifiers.contains("i"))
|
|
99
|
+
regexFlags = regexFlags | CASE_INSENSITIVE;
|
|
100
|
+
|
|
101
|
+
if(modifiers.contains("d"))
|
|
102
|
+
regexFlags = regexFlags | DOTALL;
|
|
103
|
+
|
|
104
|
+
if(modifiers.contains("m"))
|
|
105
|
+
regexFlags = regexFlags | MULTILINE;
|
|
106
|
+
|
|
107
|
+
return regexFlags;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private List<PatternMatch> getCommentMatches(InsiderFile file, List<IntRange> commentRanges) {
|
|
111
|
+
return matchesInEntireFile(file).stream()
|
|
112
|
+
.filter(patternMatch -> isInComment(patternMatch, commentRanges))
|
|
113
|
+
.collect(Collectors.toList());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private boolean isInComment(PatternMatch patternMatch, List<IntRange> commentRanges) {
|
|
117
|
+
return commentRanges.stream().anyMatch(range -> range.containsRange(patternMatch.getAbsoluteRange()));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private boolean isOutsideOfComment(PatternMatch patternMatch, List<IntRange> commentRanges) {
|
|
121
|
+
return commentRanges.stream().noneMatch(range -> range.overlapsRange(patternMatch.getAbsoluteRange()));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private List<PatternMatch> getCodeMatches(InsiderFile file, List<IntRange> commentRanges) {
|
|
125
|
+
return matchesInEntireFile(file).stream()
|
|
126
|
+
.filter(patternMatch -> isOutsideOfComment(patternMatch, commentRanges))
|
|
127
|
+
.collect(Collectors.toList());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private PatternMatch createPatternMatch(int start, int end, InsiderFile file) {
|
|
131
|
+
return PatternMatch.builder()
|
|
132
|
+
.globalStartIndex(start)
|
|
133
|
+
.globalEndIndex(end)
|
|
134
|
+
.startIndex(file.getLineIndexFromFileIndex(start))
|
|
135
|
+
.endIndex(file.getLineIndexFromFileIndex(end))
|
|
136
|
+
.startLine(file.getLineNumberOfAbsoluteCharacterIndex(start))
|
|
137
|
+
.endLine(file.getLineNumberOfAbsoluteCharacterIndex(end))
|
|
138
|
+
.matchContent(file.getContent().substring(start, end))
|
|
139
|
+
.build();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private void transformPatternIfWord() {
|
|
143
|
+
if (pattern.contains("\\b")) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
pattern = String.format("\\b(%s)\\b", pattern);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.dtos;
|
|
2
|
+
|
|
3
|
+
import lombok.AllArgsConstructor;
|
|
4
|
+
import lombok.Builder;
|
|
5
|
+
import lombok.Data;
|
|
6
|
+
import org.apache.commons.lang.math.IntRange;
|
|
7
|
+
|
|
8
|
+
@Data
|
|
9
|
+
@Builder
|
|
10
|
+
@AllArgsConstructor
|
|
11
|
+
public class PatternMatch {
|
|
12
|
+
private String matchContent;
|
|
13
|
+
private int startLine;
|
|
14
|
+
private int endLine;
|
|
15
|
+
private int globalStartIndex;
|
|
16
|
+
private int globalEndIndex;
|
|
17
|
+
private int startIndex;
|
|
18
|
+
private int endIndex;
|
|
19
|
+
|
|
20
|
+
public IntRange getAbsoluteRange() {
|
|
21
|
+
return new IntRange(globalEndIndex, globalEndIndex);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.dtos;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
4
|
+
import lombok.AllArgsConstructor;
|
|
5
|
+
import lombok.Data;
|
|
6
|
+
import lombok.NoArgsConstructor;
|
|
7
|
+
import org.apache.commons.collections4.CollectionUtils;
|
|
8
|
+
import org.apache.commons.lang.math.IntRange;
|
|
9
|
+
import org.dxworks.insider.InsiderFile;
|
|
10
|
+
import org.dxworks.insider.InsiderResult;
|
|
11
|
+
import org.dxworks.insider.technology.finder.LinguistService;
|
|
12
|
+
|
|
13
|
+
import java.util.Collections;
|
|
14
|
+
import java.util.List;
|
|
15
|
+
import java.util.stream.Collectors;
|
|
16
|
+
|
|
17
|
+
@Data
|
|
18
|
+
@NoArgsConstructor
|
|
19
|
+
@AllArgsConstructor
|
|
20
|
+
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
21
|
+
public class Rule {
|
|
22
|
+
private String name;
|
|
23
|
+
private String id;
|
|
24
|
+
private String description;
|
|
25
|
+
private List<String> applies_to;
|
|
26
|
+
private List<String> tags;
|
|
27
|
+
private String severity;
|
|
28
|
+
private List<InsiderPattern> patterns;
|
|
29
|
+
private List<String> overrides;
|
|
30
|
+
private List<Condition> conditions;
|
|
31
|
+
private String _comment;
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
public List<InsiderResult> analyze(InsiderFile file, List<IntRange> commentRanges) {
|
|
35
|
+
if (appliesTo(file)) {
|
|
36
|
+
List<PatternMatch> matches = patterns.parallelStream()
|
|
37
|
+
.flatMap(pattern -> pattern.getMatches(file, commentRanges).stream())
|
|
38
|
+
.collect(Collectors.toList());
|
|
39
|
+
|
|
40
|
+
if (matches.size() > 0)
|
|
41
|
+
return tags.stream()
|
|
42
|
+
.map(tag -> InsiderResult.builder()
|
|
43
|
+
.file(file.getFullyQualifiedName())
|
|
44
|
+
.category("")
|
|
45
|
+
.name(tag)
|
|
46
|
+
.value(matches.size())
|
|
47
|
+
.build())
|
|
48
|
+
.collect(Collectors.toList());
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Collections.emptyList();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public boolean appliesTo(InsiderFile insiderFile) {
|
|
55
|
+
return CollectionUtils.isEmpty(applies_to) || LinguistService.getInstance().hasAcceptedExtension(insiderFile, applies_to);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public void transformPatterns() {
|
|
59
|
+
patterns.forEach(InsiderPattern::transformPattern);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.services;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
|
4
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
|
+
import lombok.extern.slf4j.Slf4j;
|
|
6
|
+
import org.apache.commons.lang.math.IntRange;
|
|
7
|
+
import org.dxworks.insider.InsiderFile;
|
|
8
|
+
import org.dxworks.insider.application.inspector.dtos.Comment;
|
|
9
|
+
import org.dxworks.insider.exceptions.InsiderException;
|
|
10
|
+
import org.dxworks.insider.technology.finder.LinguistService;
|
|
11
|
+
|
|
12
|
+
import java.io.IOException;
|
|
13
|
+
import java.nio.file.Paths;
|
|
14
|
+
import java.util.ArrayList;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.regex.Matcher;
|
|
17
|
+
import java.util.regex.Pattern;
|
|
18
|
+
import java.util.stream.Collectors;
|
|
19
|
+
|
|
20
|
+
@Slf4j
|
|
21
|
+
public class CommentService {
|
|
22
|
+
|
|
23
|
+
private static final String COMMENTS_FILE_NAME = "comments.json";
|
|
24
|
+
private static CommentService _instance = null;
|
|
25
|
+
|
|
26
|
+
private List<Comment> comments;
|
|
27
|
+
|
|
28
|
+
private CommentService() {
|
|
29
|
+
loadComments();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static CommentService getInstance() {
|
|
33
|
+
if (_instance == null)
|
|
34
|
+
_instance = new CommentService();
|
|
35
|
+
return _instance;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public void loadComments() {
|
|
39
|
+
ObjectMapper objectMapper = new ObjectMapper();
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
comments = objectMapper.readValue(Paths.get("config", COMMENTS_FILE_NAME).toFile(), new TypeReference<List<Comment>>() {
|
|
43
|
+
});
|
|
44
|
+
} catch (IOException e) {
|
|
45
|
+
throw new InsiderException(
|
|
46
|
+
"Could not load comment configuration from file. Please make sure a file called "
|
|
47
|
+
+ COMMENTS_FILE_NAME + " exists in the Insider config directory.", e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public List<IntRange> extractInlineCommentLines(InsiderFile file) {
|
|
52
|
+
List<IntRange> inlineComments = new ArrayList<>();
|
|
53
|
+
|
|
54
|
+
Comment commentStyle = getCommentForFile(file);
|
|
55
|
+
if (commentStyle != null) {
|
|
56
|
+
String inlineCommentPrefix = commentStyle.getInline();
|
|
57
|
+
if (inlineCommentPrefix != null) {
|
|
58
|
+
Matcher matcher = Pattern.compile(inlineCommentPrefix).matcher(file.getContent());
|
|
59
|
+
while (matcher.find()) {
|
|
60
|
+
int start = matcher.start();
|
|
61
|
+
inlineComments.add(new IntRange(start, file.getLineBreaks().get(file.getLineNumberOfAbsoluteCharacterIndex(start)).intValue()));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
commentStyle.getInlinePatterns().forEach(it -> {
|
|
65
|
+
Matcher matcher = Pattern.compile(it.getPattern(), it.createModifier()).matcher(file.getContent());
|
|
66
|
+
while (matcher.find()) {
|
|
67
|
+
int start = matcher.start();
|
|
68
|
+
inlineComments.add(new IntRange(start, file.getLineBreaks().get(file.getLineNumberOfAbsoluteCharacterIndex(start)).intValue()));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return inlineComments;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private Comment getCommentForFile(InsiderFile file) {
|
|
77
|
+
List<String> languages = LinguistService.getInstance().getLanguagesForFile(file);
|
|
78
|
+
|
|
79
|
+
return comments.stream().filter(comment -> comment.getLanguages().stream().anyMatch(languages::contains)).findFirst().orElse(null);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public List<IntRange> extractMultilineCommentLines(InsiderFile file) {
|
|
83
|
+
List<IntRange> multilineCommentLinePairs = new ArrayList<>();
|
|
84
|
+
|
|
85
|
+
Comment commentStyle = getCommentForFile(file);
|
|
86
|
+
if (commentStyle != null) {
|
|
87
|
+
String multilineCommentPrefix = commentStyle.getPreffix();
|
|
88
|
+
String multilineCommentSuffix = commentStyle.getSuffix();
|
|
89
|
+
if (multilineCommentPrefix != null && multilineCommentSuffix != null) {
|
|
90
|
+
List<IntRange> enclosingQuotes = new ArrayList<>();
|
|
91
|
+
String content = file.getContent();
|
|
92
|
+
|
|
93
|
+
List<Integer> quotesIndex = getIndexesForSubstring(file.getContent(), "\"");
|
|
94
|
+
if (quotesIndex.size() % 2 == 0) {
|
|
95
|
+
for (int i = 0; i < quotesIndex.size(); i += 2) {
|
|
96
|
+
enclosingQuotes.add(new IntRange(quotesIndex.get(i), quotesIndex.get(i + 1)));
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
log.warn("Could not get Quotes because we found odd number of quotes in file: " + file.getPath());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
List<Integer> prefixCommentIndexes = getIndexesForSubstring(content, "/*").stream()
|
|
103
|
+
.filter(index -> isNotInQuotes(index, enclosingQuotes))
|
|
104
|
+
.collect(Collectors.toList());
|
|
105
|
+
List<Integer> suffixCommentIndexes = getIndexesForSubstring(content, "*/").stream()
|
|
106
|
+
.filter(index -> isNotInQuotes(index, enclosingQuotes))
|
|
107
|
+
.collect(Collectors.toList());
|
|
108
|
+
|
|
109
|
+
if (prefixCommentIndexes.size() != suffixCommentIndexes.size()) {
|
|
110
|
+
log.warn("Comments not well matched for file: " + file.getPath() + "!\nPrefix indexes: " + prefixCommentIndexes + "\nSuffix indexes: " + suffixCommentIndexes);
|
|
111
|
+
}
|
|
112
|
+
for (int i = 0; i < Math.min(prefixCommentIndexes.size(), suffixCommentIndexes.size()); i++) {
|
|
113
|
+
multilineCommentLinePairs.add(new IntRange(prefixCommentIndexes.get(i), suffixCommentIndexes.get(i)));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return multilineCommentLinePairs;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private boolean isNotInQuotes(Integer index, List<IntRange> enclosingQuotes) {
|
|
121
|
+
return enclosingQuotes.stream().anyMatch(interval -> interval.containsInteger(index));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
private List<Integer> getIndexesForSubstring(String content, String substring) {
|
|
125
|
+
List<Integer> globalIndexes = new ArrayList<>();
|
|
126
|
+
int index = 0;
|
|
127
|
+
while (index != -1) {
|
|
128
|
+
index = content.indexOf(substring, index);
|
|
129
|
+
if (index != -1) {
|
|
130
|
+
if (substring.equals("\"")) {
|
|
131
|
+
if (content.charAt(index - 1) == '\'' && content.charAt(index + 1) == '\'');
|
|
132
|
+
}
|
|
133
|
+
else if (substring.equals("/*")) {
|
|
134
|
+
if (index - 1 == -1) {
|
|
135
|
+
globalIndexes.add(index);
|
|
136
|
+
}
|
|
137
|
+
else if (content.charAt(index - 1) == '"' || content.charAt(index + 1) == '"');
|
|
138
|
+
}
|
|
139
|
+
else if (substring.equals("*/")) {
|
|
140
|
+
if (index - 1 == -1) {
|
|
141
|
+
globalIndexes.add(index);
|
|
142
|
+
}
|
|
143
|
+
else if (content.charAt(index - 1) == '"' || content.charAt(index + 1) == '"');
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
globalIndexes.add(index);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
index++;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return globalIndexes;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private int getBackslashesBeforeQuote(String content, int quoteIndex) {
|
|
156
|
+
String substringToQuote = content.substring(0, quoteIndex);
|
|
157
|
+
int numberOfBackslashes = 0;
|
|
158
|
+
for (int i = substringToQuote.length() - 1; i >= 0; i--) {
|
|
159
|
+
if (substringToQuote.charAt(i) == '\\')
|
|
160
|
+
numberOfBackslashes++;
|
|
161
|
+
else break;
|
|
162
|
+
}
|
|
163
|
+
return numberOfBackslashes;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
package org.dxworks.insider.application.inspector.services;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
|
4
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
|
+
import lombok.extern.slf4j.Slf4j;
|
|
6
|
+
import org.dxworks.insider.application.inspector.dtos.Rule;
|
|
7
|
+
|
|
8
|
+
import java.io.IOException;
|
|
9
|
+
import java.nio.file.Files;
|
|
10
|
+
import java.nio.file.Path;
|
|
11
|
+
import java.nio.file.Paths;
|
|
12
|
+
import java.util.ArrayList;
|
|
13
|
+
import java.util.List;
|
|
14
|
+
import java.util.stream.Collectors;
|
|
15
|
+
import java.util.stream.Stream;
|
|
16
|
+
|
|
17
|
+
@Slf4j
|
|
18
|
+
public class RuleService {
|
|
19
|
+
|
|
20
|
+
public List<Rule> getRuleFromFiles(List<String> ruleFiles) {
|
|
21
|
+
|
|
22
|
+
List<Path> ruleFilePaths = ruleFiles.stream()
|
|
23
|
+
.map(Paths::get)
|
|
24
|
+
.flatMap(fileOrFolder -> {
|
|
25
|
+
if (Files.isDirectory(fileOrFolder)) {
|
|
26
|
+
return getAllRuleFilesFromFolder(fileOrFolder);
|
|
27
|
+
} else return Stream.of(fileOrFolder);
|
|
28
|
+
}).collect(Collectors.toList());
|
|
29
|
+
|
|
30
|
+
return ruleFilePaths.stream()
|
|
31
|
+
.flatMap(ruleFile -> getRulesFromFile(ruleFile).stream())
|
|
32
|
+
.collect(Collectors.toList());
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private Stream<Path> getAllRuleFilesFromFolder(Path fileOrFolder) {
|
|
36
|
+
try {
|
|
37
|
+
return Files.walk(fileOrFolder).filter(path -> path.getFileName().toString().endsWith(".json"));
|
|
38
|
+
} catch (IOException e) {
|
|
39
|
+
e.printStackTrace();
|
|
40
|
+
}
|
|
41
|
+
return Stream.empty();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private List<Rule> getRulesFromFile(Path ruleFilePath) {
|
|
45
|
+
ObjectMapper objectMapper = new ObjectMapper();
|
|
46
|
+
try {
|
|
47
|
+
return objectMapper.readValue(ruleFilePath.toFile(), new TypeReference<>() {
|
|
48
|
+
});
|
|
49
|
+
} catch (IOException e) {
|
|
50
|
+
log.warn("Could not read rule file!", e);
|
|
51
|
+
}
|
|
52
|
+
return new ArrayList<>();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
package org.dxworks.insider.commands;
|
|
2
|
+
|
|
3
|
+
import lombok.extern.slf4j.Slf4j;
|
|
4
|
+
import org.dxworks.insider.InsiderFile;
|
|
5
|
+
import org.dxworks.insider.technology.finder.model.Technology;
|
|
6
|
+
import org.dxworks.insider.technology.finder.parsers.JavaLibrariesCsvParser;
|
|
7
|
+
import org.dxworks.insider.technology.finder.parsers.JsonFingerprintParser;
|
|
8
|
+
import org.dxworks.insider.utils.ImportUtils;
|
|
9
|
+
import org.dxworks.insider.utils.LibraryImport;
|
|
10
|
+
import org.dxworks.insider.utils.LibraryImportInOtherTechnology;
|
|
11
|
+
|
|
12
|
+
import java.io.IOException;
|
|
13
|
+
import java.nio.file.Paths;
|
|
14
|
+
import java.util.ArrayList;
|
|
15
|
+
import java.util.Collections;
|
|
16
|
+
import java.util.List;
|
|
17
|
+
import java.util.stream.Collectors;
|
|
18
|
+
|
|
19
|
+
import static org.dxworks.insider.constants.InsiderConstants.STARS;
|
|
20
|
+
|
|
21
|
+
@Slf4j
|
|
22
|
+
public class AddCommand extends ConvertCommand {
|
|
23
|
+
|
|
24
|
+
@Override
|
|
25
|
+
public boolean parse(List<String> args) {
|
|
26
|
+
return super.parse(args) && sourceFile.endsWith(".csv") && targetFile.endsWith(".json");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@Override
|
|
30
|
+
public void execute(List<InsiderFile> insiderFiles, List<String> args) {
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
JsonFingerprintParser jsonFingerprintParser = new JsonFingerprintParser();
|
|
34
|
+
List<Technology> jsonTechnologies = jsonFingerprintParser.parseTechnologiesFile(targetFile);
|
|
35
|
+
|
|
36
|
+
JavaLibrariesCsvParser javaLibrariesCsvParser = new JavaLibrariesCsvParser();
|
|
37
|
+
List<Technology> csvTechnologies = javaLibrariesCsvParser.parseTechnologiesFile(sourceFile);
|
|
38
|
+
|
|
39
|
+
List<LibraryImport> importsAddedToExistingTechnology = new ArrayList<>();
|
|
40
|
+
List<LibraryImport> importsAddedToNewTechnology = new ArrayList<>();
|
|
41
|
+
List<LibraryImport> identicalImportsAlreadyInFile = new ArrayList<>();
|
|
42
|
+
List<LibraryImportInOtherTechnology> importsAlreadyInFileWithDifferentTechnology = new ArrayList<>();
|
|
43
|
+
List<Technology> newlyCreatedTechnologies = new ArrayList<>();
|
|
44
|
+
|
|
45
|
+
csvTechnologies.forEach(technology -> {
|
|
46
|
+
List<String> fingerprints = technology.getFingerprints();
|
|
47
|
+
fingerprints.forEach(fingerPrint -> {
|
|
48
|
+
LibraryImport libraryImport = new LibraryImport(ImportUtils.unwrapImportPackage(fingerPrint), technology.getName());
|
|
49
|
+
Technology tech = jsonTechnologies.stream().filter(t -> t.getFingerprints().contains(fingerPrint)).findFirst().orElse(null);
|
|
50
|
+
if (tech != null) { //fingerprint already exists in JSON file
|
|
51
|
+
if (technology.getName().equalsIgnoreCase(tech.getName())) {
|
|
52
|
+
identicalImportsAlreadyInFile.add(libraryImport);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
importsAlreadyInFileWithDifferentTechnology.add(new LibraryImportInOtherTechnology(ImportUtils.unwrapImportPackage(fingerPrint), technology.getName(), tech.getName()));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
// fingerprint does not exist
|
|
59
|
+
Technology sameTech = jsonTechnologies.stream().filter(t -> t.getName().equalsIgnoreCase(technology.getName())).findFirst().orElse(null);
|
|
60
|
+
if (sameTech == null) { //adding to new technology
|
|
61
|
+
Technology newTechnology = new Technology(technology.getCategory(), technology.getName(), technology.getLanguages(), technology.getExtensions(), Collections.singletonList(fingerPrint));
|
|
62
|
+
newlyCreatedTechnologies.add(newTechnology);
|
|
63
|
+
jsonTechnologies.add(newTechnology);
|
|
64
|
+
importsAddedToNewTechnology.add(libraryImport);
|
|
65
|
+
} else {
|
|
66
|
+
List<String> oldFps = sameTech.getFingerprints();
|
|
67
|
+
List<String> newFps = new ArrayList<>(oldFps);
|
|
68
|
+
newFps.add(fingerPrint);
|
|
69
|
+
sameTech.setFingerprints(newFps);
|
|
70
|
+
if (newlyCreatedTechnologies.contains(sameTech)) {
|
|
71
|
+
importsAddedToNewTechnology.add(libraryImport);
|
|
72
|
+
} else {
|
|
73
|
+
importsAddedToExistingTechnology.add(libraryImport);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
jsonFingerprintParser.writeTechnologiesToFile(jsonTechnologies, Paths.get(targetFile));
|
|
80
|
+
|
|
81
|
+
printFingerPrintReport(identicalImportsAlreadyInFile, "Fingerprints already present in file to the same Technology (No action taken):");
|
|
82
|
+
printFingerPrintsReport(importsAlreadyInFileWithDifferentTechnology);
|
|
83
|
+
printFingerPrintReport(importsAddedToNewTechnology, "Fingerprints added to a new Technology:");
|
|
84
|
+
printFingerPrintReport(importsAddedToExistingTechnology, "Fingerprints added to an existing Technology:");
|
|
85
|
+
} catch (IOException e) {
|
|
86
|
+
log.error("Could not transform file!", e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private void printFingerPrintsReport(List<LibraryImportInOtherTechnology> importsAlreadyInFileWithDifferentTechnology) {
|
|
91
|
+
System.out.println(STARS);
|
|
92
|
+
System.out.println("Fingerprints already present in file, but mapped to a different Technology (No action taken):");
|
|
93
|
+
System.out.println();
|
|
94
|
+
if (importsAlreadyInFileWithDifferentTechnology.isEmpty())
|
|
95
|
+
System.out.println("None Detected");
|
|
96
|
+
else
|
|
97
|
+
System.out.println(importsAlreadyInFileWithDifferentTechnology.stream()
|
|
98
|
+
.map(libraryImport -> "\t" + String.join(", ", libraryImport.get_import(), libraryImport.getLibrary(), libraryImport.getOtherTechnology()))
|
|
99
|
+
.collect(Collectors.joining("\n")));
|
|
100
|
+
System.out.println();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private void printFingerPrintReport(List<LibraryImport> identicalImportsAlreadyInFile, String headerMessage) {
|
|
104
|
+
System.out.println(headerMessage);
|
|
105
|
+
System.out.println(STARS);
|
|
106
|
+
System.out.println();
|
|
107
|
+
if (identicalImportsAlreadyInFile.isEmpty())
|
|
108
|
+
System.out.println("None Detected");
|
|
109
|
+
else
|
|
110
|
+
System.out.println(identicalImportsAlreadyInFile.stream()
|
|
111
|
+
.map(libraryImport -> "\t" + String.join(", ", libraryImport.get_import(), libraryImport.getLibrary()))
|
|
112
|
+
.collect(Collectors.joining("\n")));
|
|
113
|
+
System.out.println();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@Override
|
|
117
|
+
public String usage() {
|
|
118
|
+
return "insider add <path_to_csv> <path_to_json>";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@Override
|
|
122
|
+
public String getName() {
|
|
123
|
+
return ADD;
|
|
124
|
+
}
|
|
125
|
+
}
|