aporter1117 / sonarqube

0 stars 0 forks source link

Powershell script not working as expected. If input file is not formatted perfectly data and cell do not match #1

Open aporter1117 opened 7 years ago

aporter1117 commented 7 years ago

* Powershell script Begin*** $input = Get-Content input.txt $array = @() $RecordPosition = 1 $input | foreach-object { $writeobj = $false $obj = New-Object System.Object

If ($_ -like '*Not assigned*') {
    #$writeobj = $true
    #Write-Output "Next Line"
}
If ($_ -like '*`t*') {
    #$RecordPosition += $RecordPosition
    #Write-Output "Skip Tab"
}
If ($RecordPosition -eq 12) {
    $R12 = $_
    $RecordPosition = 13
    #Write-Output "Twelve" 
}
    If ($RecordPosition -eq 11) {
    $R11 = $_
    $RecordPosition = 12
    #Write-Output "Eleven" 
    $writeobj = $true
    #Write-Output "Next Line"
}
    If ($RecordPosition -eq 10) {
    $TimeToFix = $_
    $RecordPosition = 11
    #Write-Output "Ten" 
}
If ($RecordPosition -eq 9) {
    $Owner = $_
    $RecordPosition = 10
    #Write-Output "Nine" 
}
If ($RecordPosition -eq 8) {
    $Status = ($_.SubString(1))
    $RecordPosition = 9
    #Write-Output "Eight" 
}
If ($RecordPosition -eq 7) {
    $Severity = ($_.SubString(1))
    $RecordPosition = 8
    #Write-Output "Seven" 
}
If ($RecordPosition -eq 6) {
    $Type = $_
    $RecordPosition = 7
    #Write-Output "Six" 
}    
If ($RecordPosition -eq 5) {
    $R5 = $_
    $RecordPosition = 6
    #Write-Output "Five" 
}
If ($RecordPosition -eq 4) {
    $R4 = $_
    $RecordPosition = 5
    #Write-Output "Four" 
}
If ($RecordPosition -eq 3) {
    $Line = $_
    $RecordPosition = 4
    #Write-Output "Three" 
}
If ($RecordPosition -eq 2) {
    $Vulnerability = $_
    $RecordPosition = 3
    #Write-Output "Two" 
}    
If ($_ -like '*Java ::*') {
    $Source = ($_.SubString(1))
    $RecordPosition = 2
    #Write-Output "One-source" 
} Elseif ($_ -like '*SonarQube Scanner*') {
    $Source = $_
    $RecordPosition = 2
    #Write-Output "One-source" 
} Elseif ($_ -like '*.java*') {
    $Source = $_
    $RecordPosition = 2
    #Write-Output "One-source" 
}       
If ($RecordPosition -eq 1) {
    #$Source = " "
    $RecordPosition = 3
    $Vulnerability = $_
    #Write-Output "One-other" 
}
If ($writeobj){
    $obj | Add-Member -type NoteProperty -name File -value $Source
    $obj | Add-Member -type NoteProperty -name Vulnerability -value $Vulnerability
    $obj | Add-Member -type NoteProperty -name Line -value $Line
    #$obj | Add-Member -type NoteProperty -name R4 -value $R4
    #$obj | Add-Member -type NoteProperty -name R5 -value $R5
    $obj | Add-Member -type NoteProperty -name Type -value $Type
    $obj | Add-Member -type NoteProperty -name Severity -value $Severity
    $obj | Add-Member -type NoteProperty -name Status -value $Status
    $obj | Add-Member -type NoteProperty -name Owner -value $Owner
    $obj | Add-Member -type NoteProperty -name TimeToFix -value $TimeToFix
    #$obj | Add-Member -type NoteProperty -name R11 -value $R11
    #$obj | Add-Member -type NoteProperty -name R12 -value $R12
    $array += $obj
    $RecordPosition = 1
    $writeobj = $false

}

} $array | Export-Csv -path output$(((get-date).ToUniversalTime()).ToString("yyyyMMddThhmmssZ")).csv -NoTypeInformation ***** Powershell Script Ends ****

*****Example input file Starts here * Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile1.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L51

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

 Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile2.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L43

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

 Java :: Test_Trunk :: SonarQube Scanner src/Test/Testfile3.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L43

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

 Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile4.java
Equality tests should not be made with floating point values.  7 days ago  L86

Bug  misra  Critical
 Open
Not assigned
5min effort

 Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile5.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L65

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L83

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L86

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

 Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile6.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L108

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L110

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L131

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L133

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L158

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L160

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L185

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L214

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L237

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L263

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L265

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

 Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java
Define and throw a dedicated exception instead of using a generic one.  7 days ago  L31

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L146

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L199

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L293

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

Define and throw a dedicated exception instead of using a generic one.  7 days ago  L310

Vulnerability  cwe, error-handling  Critical
 Open
Not assigned
20min effort

*****Example input file Ends here * ***Expected output example Start****

File Name Type Severity Line Solution Time to Fix Status Assigned  Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java Vulnerabilty Critical L31 Define and throw a dedicated exception instead of using a generic one. 20min effort Open Not assigned  Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java Vulnerabilty Critical L146 Define and throw a dedicated exception instead of using a generic one. 20min effort Open Not assigned  Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java Vulnerabilty Critical L199 Define and throw a dedicated exception instead of using a generic one. 20min effort Open Not assigned  Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java Vulnerabilty Critical L293 Define and throw a dedicated exception instead of using a generic one. 20min effort Open Not assigned  Java :: Test_Trunk :: SonarQube Scanner  src/Test/Testfile7.java Vulnerabilty Critical L310 Define and throw a dedicated exception instead of using a generic one. 20min effort Open Not assigned

** Expected out example End *****

aporter1117 commented 7 years ago

Expected output: image