Skip to content

Commit

Permalink
Add CLASS location in java provider
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Manuel Leflet Estrada <[email protected]>
  • Loading branch information
jmle committed Jan 20, 2025
1 parent 2f9344a commit 07620a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
18 changes: 18 additions & 0 deletions demo-output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
- Language=Golang
- License=Apache
violations:
annotation-on-any-class-01:
description: '@Singleton found at class level'
category: mandatory
labels:
- konveyor.io/source=spring-boot2
- konveyor.io/target=spring-boot3+
incidents:
- uri: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
message: |
A `@Singleton` annotation has been found annotating some class.
codeSnip: " 1 package com.example.apps;\n 2 \n 3 import javax.ejb.SessionBean;\n 4 import javax.ejb.Singleton;\n 5 \n 6 @Singleton\n 7 public abstract class Bean implements SessionBean {\n 8 \n 9 }\n"
lineNumber: 7
variables:
file: file:///examples/java/example/src/main/java/com/example/apps/Bean.java
kind: Class
name: Bean
package: com.example.apps
effort: 1
builtin-inclusion-test-json:
description: |
This is same as java-io-file-usage but for the builtin providers. There are multiple instances of the same incidents in different directories.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ var locationToCode = map[string]int{
"annotation": 4,
"implements_type": 5,
// Not Implemented
"enum_constant": 6,
"enum": 6,
"return_type": 7,
"import": 8,
"variable_declaration": 9,
"type": 10,
"package": 11,
"field": 12,
"method": 13,
"class": 14,
}

type javaProvider struct {
Expand Down Expand Up @@ -389,6 +390,7 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
"-Dosgi.checkConfiguration=true",
fmt.Sprintf("-Dosgi.sharedConfiguration.area=%s", sharedConfigPath),
"-Dosgi.sharedConfiguration.area.readOnly=true",
//"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:1044",
"-Dosgi.configuration.cascaded=true",
"-Xms1g",
"-XX:MaxRAMPercentage=70.0",
Expand All @@ -399,7 +401,6 @@ func (p *javaProvider) Init(ctx context.Context, log logr.Logger, config provide
"-Djava.net.useSystemProxies=true",
"-configuration", "./",
"-data", workspace,
//"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:1044",
}

if val, ok := config.ProviderSpecificConfig[JVM_MAX_MEM_INIT_OPTION].(string); ok && val != "" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,31 +77,19 @@ func (p *javaServiceClient) Evaluate(ctx context.Context, cap string, conditionI

incidents := []provider.IncidentContext{}
switch locationToCode[strings.ToLower(cond.Referenced.Location)] {
case 0:
case 0, 3, 4, 6, 10, 11, 12, 13, 14:
// Filter handle for type, find all the referneces to this type.
incidents, err = p.filterDefault(symbols)
case 1, 5:
incidents, err = p.filterTypesInheritance(symbols)
case 2:
incidents, err = p.filterMethodSymbols(symbols)
case 3:
incidents, err = p.filterDefault(symbols)
case 4:
incidents, err = p.filterDefault(symbols)
case 7:
incidents, err = p.filterMethodSymbols(symbols)
case 8:
incidents, err = p.filterModulesImports(symbols)
case 9:
incidents, err = p.filterVariableDeclaration(symbols)
case 10:
incidents, err = p.filterDefault(symbols)
case 11:
incidents, err = p.filterDefault(symbols)
case 12:
incidents, err = p.filterDefault(symbols)
case 13:
incidents, err = p.filterDefault(symbols)
default:

}
Expand Down
16 changes: 16 additions & 0 deletions rule-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -419,3 +419,19 @@
location: IMPLEMENTS_TYPE
filepaths: "{{class.Filepaths}}"
from: class

- ruleID: annotation-on-any-class-01
category: mandatory
effort: 1
labels:
- konveyor.io/source=spring-boot2
- konveyor.io/target=spring-boot3+
when:
java.referenced:
pattern: '*'
location: CLASS
annotated:
pattern: javax.ejb.Singleton
description: "@Singleton found at class level"
message: |
A `@Singleton` annotation has been found annotating some class.

0 comments on commit 07620a7

Please sign in to comment.