Clean log from parse and parsing interrupted error messages

This commit is contained in:
aboyko
2022-10-07 17:19:02 -04:00
parent 0130203c8f
commit b3b03bfb47
6 changed files with 37 additions and 134 deletions

View File

@@ -47,6 +47,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.java.IClasspathUtil;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
public class ORAstUtils {
@@ -236,7 +237,11 @@ public class ORAstUtils {
jp.setClasspath(classpath);
return jp;
} catch (Exception e) {
log.error("{}", e);
if (isExceptionFromInterrupedThread(e)) {
log.debug("", e);
} else {
log.error("{}", e);
}
return null;
}
}
@@ -293,16 +298,10 @@ public class ORAstUtils {
}
private static void logExceptionWhileParsing(Throwable t) {
if (!(t instanceof JavaParsingException || t instanceof StringIndexOutOfBoundsException)) {
if (t instanceof RuntimeException) {
RuntimeException re = (RuntimeException) t;
if (re.getCause() instanceof ClosedByInterruptException) {
// Parse or scan interrupted
log.debug("", t);
return;
}
}
if (t instanceof JavaParsingException || t instanceof StringIndexOutOfBoundsException || isExceptionFromInterrupedThread(t)) {
// Do not log parse exceptions. Can be too many while user is typing code
log.debug("", t);
} else {
log.error("", t);
}
}
@@ -405,6 +404,19 @@ public class ORAstUtils {
};
}
}
public static boolean isExceptionFromInterrupedThread(Throwable t) {
if (ExceptionUtil.getDeepestCause(t) instanceof InterruptedException) {
return true;
}
if (t instanceof RuntimeException && "Relative paths only".equals(t.getMessage())) {
return true;
}
if (ExceptionUtil.getDeepestCause(t) instanceof ClosedByInterruptException) {
return true;
}
return false;
}
}

View File

@@ -1,31 +0,0 @@
#
# Copyright 2021 the original author or authors.
# <p>
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# <p>
# https://www.apache.org/licenses/LICENSE-2.0
# <p>
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ---
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.SpringBootProperties_3_0
displayName: Migrate Spring Boot properties to 3.0
description: Migrate properties found in `application.properties` and `application.yml`.
recipeList:
- org.openrewrite.properties.ChangePropertyKey:
oldPropertyKey: spring.datasource.initialization-mode
newPropertyKey: spring.sql.init.mode
- org.openrewrite.yaml.ChangePropertyKey:
oldPropertyKey: spring.datasource.schema
newPropertyKey: spring.sql.init.schema-locations
- org.openrewrite.yaml.ChangePropertyKey:
oldPropertyKey: spring.datasource.data
newPropertyKey: spring.sql.init.data-locations

View File

@@ -1,51 +0,0 @@
---
########################################################################################################################
# SpringBoot 3_0
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0
displayName: Upgrade to Spring Boot 3.0 from 2.x
description: 'Upgrade to Spring Boot 3.0 from prior 2.x version.'
recipeList:
# Upgrade 3.0.x from 2.x
- org.openrewrite.java.spring.boot3.MavenPomUpgrade
- org.openrewrite.java.spring.boot3.data.UpgradeSpringData_3_0
- org.openrewrite.java.spring.boot3.Micrometer_3_0
---
########################################################################################################################
# SpringBoot 3_0 Maven Pom
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.MavenPomUpgrade
displayName: Upgrade Maven Pom to Spring Boot 3.0 from 2.x
description: 'Upgrade Maven Pom to Spring Boot 3.0 from prior 2.x version.'
recipeList:
- org.openrewrite.maven.ChangeDependencyClassifier:
groupId: org.ehcache
artifactId: ehcache
newClassifier: jakarta
- org.openrewrite.maven.UpgradeDependencyVersion:
groupId: org.springframework.boot
artifactId: "*"
newVersion: 3.0.0-SNAPSHOT
trustParent: true
- org.openrewrite.maven.UpgradeParentVersion:
groupId: org.springframework.boot
artifactId: spring-boot-starter-parent
newVersion: 3.0.0-SNAPSHOT
- org.openrewrite.maven.ChangePropertyValue:
key: 'java.version'
newValue: 17
addIfMissing: true
---
########################################################################################################################
# Spring Data 3.0 io.micrometer.core.instrument.binder -> io.micrometer.binder
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.Micrometer_3_0
displayName: Micrometer compatible with Boot 3.x
description: Switch to Micrometer compatible with Boot 3.x
recipeList:
- org.openrewrite.java.ChangePackage:
oldPackageName: io.micrometer.core.instrument.binder
newPackageName: io.micrometer.binder
recursive: true

View File

@@ -1,34 +0,0 @@
########################################################################################################################
# Spring Data 3.0
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.data.UpgradeSpringData_3_0
displayName: Upgrade to Spring Data 3.0
description: 'Upgrade to Spring Data to 3.0 from any prior version.'
recipeList:
- org.openrewrite.java.spring.boot3.data.SwitchToJakarta
---
########################################################################################################################
# Spring Data 3.0 javax -> jakarta
type: specs.openrewrite.org/v1beta/recipe
name: org.openrewrite.java.spring.boot3.data.SwitchToJakarta
displayName: Switch to Jakarta JPA
description: 'Switch to Jakarta JPA from Javax'
recipeList:
- org.springframework.ide.vscode.commons.rewrite.maven.ChangeDependencyClassifier:
groupId: org.ehcache
artifactId: ehcache
newClassifier: jakarta
- org.openrewrite.java.ChangePackage:
oldPackageName: javax.persistence
newPackageName: jakarta.persistence
recursive: true
- org.openrewrite.java.ChangePackage:
oldPackageName: javax.validation
newPackageName: jakarta.validation
recursive: true
- org.openrewrite.java.ChangePackage:
oldPackageName: javax.xml.bind
newPackageName: jakarta.xml.bind
recursive: true

View File

@@ -87,8 +87,6 @@ public class RewriteRecipeRepository implements ApplicationContextAware {
private static final Logger log = LoggerFactory.getLogger(RewriteRecipeRepository.class);
private static final String WORKSPACE_EXECUTE_COMMAND = "workspace/executeCommand";
private static final String RECIPES_LOADING_PROGRESS = "loading-rewrite-recipes";
final private SimpleLanguageServer server;
final private Map<String, Recipe> recipes;
@@ -166,8 +164,9 @@ public class RewriteRecipeRepository implements ApplicationContextAware {
}
private synchronized void loadRecipes() {
String taskId = UUID.randomUUID().toString();
try {
server.getProgressService().progressBegin(RECIPES_LOADING_PROGRESS, "Loading Rewrite Recipes", null);
server.getProgressService().progressBegin(taskId, "Loading Rewrite Recipes", null);
log.info("Loading Rewrite Recipes...");
StsEnvironment env = createRewriteEnvironment();
for (Recipe r : env.listRecipes()) {
@@ -198,7 +197,7 @@ public class RewriteRecipeRepository implements ApplicationContextAware {
} catch (Throwable t) {
log.error("", t);
} finally {
server.getProgressService().progressDone(RECIPES_LOADING_PROGRESS);
server.getProgressService().progressDone(taskId);
}
}

View File

@@ -90,12 +90,16 @@ public class RewriteReconciler implements JavaReconciler {
}
}
} catch (Exception e) {
log.error("", e);
if (ORAstUtils.isExceptionFromInterrupedThread(e)) {
log.debug("", e);
} else {
log.error("", e);
}
} finally {
problemCollector.endCollecting();
}
}
private List<ReconcileProblem> createProblems(IDocument doc, FixAssistMarker m, J astNode) {
if (astNode != null) {
Range range = astNode.getMarkers().findFirst(Range.class).orElse(null);
@@ -156,7 +160,11 @@ public class RewriteReconciler implements JavaReconciler {
}
}
} catch (Exception e) {
log.error("", e);
if (ORAstUtils.isExceptionFromInterrupedThread(e)) {
log.debug("", e);
} else {
log.error("", e);
}
}
}
return allProblems;