Code Monkey home page Code Monkey logo

sourcehawk's Introduction

sourcehawk's People

Contributors

amyschoen avatar brianwyka avatar ctoestreich avatar hmatt1 avatar pkn4645 avatar

Watchers

 avatar

sourcehawk's Issues

SonarCloud Scans Failing

Scans are failing with errors due to projects not existing on server side.

Error:  Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project sourcehawk: Could not find a default branch to fall back on. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project sourcehawk: Could not find a default branch to fall back on.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Caused by: org.apache.maven.plugin.MojoExecutionException: Could not find a default branch to fall back on.
    at org.sonarsource.scanner.maven.bootstrap.ScannerBootstrapper.execute (ScannerBootstrapper.java:67)
    at org.sonarsource.scanner.maven.SonarQubeMojo.execute (SonarQubeMojo.java:104)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:50)
Caused by: org.sonar.api.utils.MessageException: Could not find a default branch to fall back on.

install failed

install failed.

# curl -sL https://raw.githubusercontent.com/optum/sourcehawk/main/install-linux.sh | bash
Downloading Sourcehawk binary...
Installing...
/usr/bin/sourcehawk: line 1: Not: command not found
/usr/bin/sourcehawk: line 1: Not: command not found

# cat /etc/redhat-release 
CentOS Linux release 7.8.2003 (Core)

# bash -x install-linux.sh 
++ curl -sI https://github.com/optum/sourcehawk/releases/latest
++ grep -i location
++ awk -F/ '{ printf "%s", $NF }'
++ tr -d '\r\n'
+ VERSION=v0.5.0socket-worker-5029ae85.js
++ uname -m
+ ARCH=x86_64
+ DOWNLOAD_URL=https://github.com/optum/sourcehawk/releases/download/v0.5.0socket-worker-5029ae85.js/sourcehawk-linux-x86_64
+ INSTALL_LOCATION=/usr/bin
+ INSTALL_PATH=/usr/bin/sourcehawk
+ '[' '!' -w /usr/bin ']'
+ echo 'Downloading Sourcehawk binary...'
Downloading Sourcehawk binary...
+ curl -sLk https://github.com/optum/sourcehawk/releases/download/v0.5.0socket-worker-5029ae85.js/sourcehawk-linux-x86_64 -o /usr/bin/sourcehawk
+ echo Installing...
Installing...
+ chmod +x /usr/bin/sourcehawk
+ sourcehawk -V
/usr/bin/sourcehawk: line 1: Not: command not found
+ sourcehawk --help
/usr/bin/sourcehawk: line 1: Not: command not found

Sourcehawk Homebrew Exec Format Error

When upgrading to Sourcehawk 0.7.1, the binary is not executable, and then when chmod +x,:

Zsh

zsh: exec format error: sourcehawk

Bash

bash: /usr/local/bin/sourcehawk: cannot execute binary file

Support validation via a web service, like a function.

Assuming I want to validate a particular yaml or json file against a schema. If I have a webservice that accepts a payload with the yaml/json, the web service returns a 2XX for succes and 4xx for failure, Sourcehawk could record the result appropriately. This would open many doors for possible scans/validations.

Support Local Config Locations After Remote Config Executed

Consider the below scenario.

The desired outcome is that org/repob config locations would be evaluated as https://raw.githubusercontent.com/org/repob/.sourcehawk/config.yml

org/repoa

sourcehawk.yml

config-locations:
  - https://raw.githubusercontent.com/org/repob/sourcehawk.yml

org/repob

sourcehawk.yml

config-locations:
  - .sourcehawk/config.yml

.sourcehawk/config.yml

[Airbrake] Airbrake demo - Brian Wyka

Airbrake error: #3830
Airbrake project: sourcehawk

Error type: java.lang.IllegalStateException
Error message: Airbrake demo - Brian Wyka
Where: <no information>
Occurred at: Mar 04, 2022 16:54:21 UTC
First seen at: Mar 04, 2022 16:54:20 UTC
Occurrences: 12 (0 since last deploy on <no information>)
Severity: error

URL: <no information>
File: classes/com/optum/sourcehawk/cli/Sourcehawk.class

Backtrace:

classes/com/optum/sourcehawk/cli/Sourcehawk.class:50:in main
com.optum.sourcehawk.cli.Sourcehawk$main:-1:in call
test-classes/com/optum/sourcehawk/cli/SourcehawkSpec.class:52:in $spock_feature_1_3
jdk.internal.reflect.NativeMethodAccessorImpl:-2:in invoke0
jdk.internal.reflect.NativeMethodAccessorImpl:62:in invoke
jdk.internal.reflect.DelegatingMethodAccessorImpl:43:in invoke
java.lang.reflect.Method:566:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/util/ReflectionUtil.class:198:in invokeMethod
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/model/MethodInfo.class:47:in lambda$new$0
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/model/MethodInfo.class:148:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:409:in invokeRaw
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:392:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:326:in runFeatureMethod
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/IterationNode.class:48:in execute
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/IterationNode.class:11:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:139:in lambda$executeRecursively$5
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/ThrowableCollector.class:73:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:129:in lambda$executeRecursively$7
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/SpockNode.class:40:in sneakyInvoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/IterationNode.class:63:in lambda$around$0
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:238:in lambda$createMethodInfoForDoRunIteration$5
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/model/MethodInfo.class:148:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:409:in invokeRaw
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:392:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:220:in runIteration
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/IterationNode.class:63:in around
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/IterationNode.class:11:in around
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:127:in lambda$executeRecursively$8
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/ThrowableCollector.class:73:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:126:in executeRecursively
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:84:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/SameThreadHierarchicalTestExecutorService.class:32:in submit
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask$DefaultDynamicTestExecutor.class:212:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask$DefaultDynamicTestExecutor.class:192:in execute
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/ParameterizedFeatureChildExecutor.class:53:in execute
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformParameterizedSpecRunner.class:186:in runIterations
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformParameterizedSpecRunner.class:45:in runParameterizedFeature
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/ParameterizedFeatureNode.class:40:in execute
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/ParameterizedFeatureNode.class:16:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:139:in lambda$executeRecursively$5
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/ThrowableCollector.class:73:in execute
junit-platform-engine-1.7.2.jar!/org/junit/platform/engine/support/hierarchical/NodeTestTask.class:129:in lambda$executeRecursively$7
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/SpockNode.class:40:in sneakyInvoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/FeatureNode.class:29:in lambda$around$0
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:201:in lambda$createMethodInfoForDoRunFeature$4
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/model/MethodInfo.class:148:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:409:in invokeRaw
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:392:in invoke
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/PlatformSpecRunner.class:194:in runFeature
spock-core-2.0-groovy-3.0.jar!/org/spockframework/runtime/FeatureNode.class:29:in around
...

Visit Airbrake error to view the full backtrace.

Add support to flatten configs locally

This feature should work just like the maven flatten pom where all remote hierarchy configs are YAML merged down to the single output that will be used.

Should support output to:

  • Console
  • File system

Explore TOML for Configuration Format

Example Config

File name: sourcehawk.toml

config-locations = [
    "https://raw.githubusercontent.com/optum/sourcehawk-parent/.sourcehawk/config.toml"
]

[[file-protocols]]
repository-path = "lombok.config"
severity = "ERROR"

[[file-protocols.enforcers]]
enforcer = "STRING_PROPERTY_EQUALS"
name = "config.stopBubbling"
value = true

[[file-protocols.enforcers]]
enforcer = "string-property-equals"
name = "lombok.addLombokGeneratedAnnotation"
value = true

Links

Decouple Tests From Remote Config Locations

Need to replace tests that reference remote config locations with mock server implementations to avoid flaky tests.

For example:

config-locations:
  - https://raw.githubusercontent.com/optum/sourcehawk-parent/main/.sourcehawk/config.yml

Would be replaced with:

config-locations:
  - http://localhost:8080/optum/sourcehawk-parent/main/.sourcehawk/config.yml

And a mock server would be setup during test to respond with required content...

Create Windows Executable

The windows executable should be created.

Prerequisites

The native-image jar needs to be build with Java11 and the GraalVM Java11 distro needs to be used to compile it into a native-image.

Notes

Necessary github worfklows are already defined (and commented out).

Support glob pattern for fix command

Similar to the scan command, support glob pattern matching when performing a fix command.

Implementation to be completed here:

if (fileResolverOptional.isPresent()) {
// TODO: handle glob patterns
val fileInputStreamOptional = repositoryFileReader.read(fileProtocol.getRepositoryPath());
if (fileInputStreamOptional.isPresent()) {
try (val fileInputStream = fileInputStreamOptional.get()) {
fileProtocolFixResults.add(FixResultFactory.resolverResult(fileProtocol, fileResolverOptional.get().resolve(fileInputStream, fixWriter), dryRun));
} catch (final IOException e) {
val message = String.format("Error fixing file protocol: %s", e.getMessage());
fileProtocolFixResults.add(FixResultFactory.error(fileProtocol.getRepositoryPath(), message));
}
} else {
fileProtocolFixResults.add(FixResultFactory.fileNotFound(fileProtocol));
break;
}
} else {

Comparable example:

val repositoryPaths = FileUtils.find(execOptions.getRepositoryRoot().toString(), fileProtocol.getRepositoryPath())
.map(Path::toAbsolutePath)
.map(Path::toString)
.map(absoluteRepositoryFilePath -> FileUtils.deriveRelativePath(execOptions.getRepositoryRoot().toString(), absoluteRepositoryFilePath))
.collect(Collectors.toSet());
if (repositoryPaths.isEmpty()) {
fileProtocolScanResults.add(ScanResultFactory.fileNotFound(execOptions, fileProtocol));
} else {
val severity = Severity.parse(fileProtocol.getSeverity());
for (val repositoryPath: repositoryPaths) {
try (val fileInputStream = repositoryFileReader.read(repositoryPath).orElseThrow(() -> new IOException("File not found"))) {
val enforcerResult = fileEnforcer.enforce(fileInputStream);
fileProtocolScanResults.add(ScanResultFactory.enforcerResult(execOptions, repositoryPath, severity, enforcerResult));
}
}

Setup Airbrake for your Java application

Installation

Install option 1: Maven

Add the javabrake dependency through your IDE or directly to your pom.xml file:

<dependency>
  <groupId>io.airbrake</groupId>
  <artifactId>javabrake</artifactId>
  <version>0.2.3</version>
</dependency>

Install option 2: Gradle

Add javabrake to your Gradle dependencies:

compile 'io.airbrake:javabrake:0.2.3'

Install option 3: Ivy

Add javabrake to your Ivy dependencies:

<dependency org='io.airbrake' name='javabrake' rev='0.2.3'>
  <artifact name='javabrake' ext='pom'></artifact>
</dependency>

Configuration

Import the javabrake library and copy the three configuration lines into your
app to send all uncaught exceptions to Airbrake:

(You can find your project ID and API key in your project's settings)

// Import the library:
import io.airbrake.javabrake.Notifier;

public class ExampleApp {
  public static void main(String[] args) {

    // Copy configuration lines:
    int projectId = <Your project ID>;
    String projectKey = "<Your project API KEY>";
    Notifier notifier = new Notifier(projectId, projectKey);
  }
}

Example of reporting a caught exception:

try {
  int i = 1/0;
} catch (ArithmeticException e) {
  notifier.report(e);
}

Full documentation

Visit our official GitHub repo for advanced information and integrations like log4j, log4j2, and logback.

Docker command does not run on M1 Mac

The following error is produced on a MacBook M1 when running

docker run -v "$(pwd):/home/sourcehawk" optumopensource/sourcehawk:0.6.0 scan

WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
qemu: uncaught target signal 11 (Segmentation fault) - core dumped

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.