Giriş
OpenRewrite bir static kod analiz aracı. Diğer araçlardan farklı olarak sadece rapor üretmiyor aynı zamanda kodu da değiştirebiliyor.
1. dryRun Goal
target/rewrite dizini altında bir patch dosyası oluşturur
2. run Goal
Kodları direkt değiştirir
3. Recipe Listesi
3.1 CommonStaticAnalysis Recipe
Sanırım en işe yarayan recipe'lerden bir tanesi. Bur recipe ile yapılabilecek işlerin listesi burada
Örnek
Şöyle yaparız
<plugin><groupId>org.openrewrite.maven</groupId><artifactId>rewrite-maven-plugin</artifactId><version>5.23.1</version><configuration><activeRecipes><recipe>org.openrewrite.staticanalysis.CommonStaticAnalysis</recipe></activeRecipes></configuration><dependencies><dependency><groupId>org.openrewrite.recipe</groupId><artifactId>rewrite-static-analysis</artifactId><version>1.3.1</version></dependency></dependencies></plugin>
Eğer proje çok büyükse sadece bazı şeyleri çalıştırmak için proje kök dizininde bir tane rewrite.yml dosyası oluştururuz. Şöyle yaparız. Eğer proje multi-module ise yine en tepedeki dizine koymak lazım
--- type: specs.openrewrite.org/v1beta/recipe name: orcun.CommonStaticAnalysis displayName: Common static analysis issues description: Resolve common static analysis issues discovered through 3rd party tools. recipeList: - org.openrewrite.staticanalysis.UseDiamondOperator
<plugin><groupId>org.openrewrite.maven</groupId><artifactId>rewrite-maven-plugin</artifactId><version>5.23.1</version><configuration><activeRecipes><recipe>orcun.CommonStaticAnalysis</recipe></activeRecipes></configuration><dependencies><dependency><groupId>org.openrewrite.recipe</groupId><artifactId>rewrite-static-analysis</artifactId><version>1.3.1</version></dependency></dependencies></plugin>