Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ repositories {
}
}
maven {
url "https://repository.apache.org/snapshots/"
url = "https://repository.apache.org/snapshots/"
mavenContent {
snapshotsOnly()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
import com.github.cameltooling.idea.service.CamelCatalogService;
import com.github.cameltooling.idea.service.CamelPreferenceService;
import com.github.cameltooling.idea.service.CamelService;
import com.github.cameltooling.idea.util.BeanUtils;
import com.github.cameltooling.idea.util.CamelIdeaUtils;
import com.github.cameltooling.idea.util.IdeaUtils;
import com.intellij.lang.annotation.AnnotationHolder;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlAttributeValue;
Expand Down Expand Up @@ -76,6 +79,14 @@ void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
if ("[null]".equals(error)) {
return;
}
String missingBeanName = extractMissingBeanName(result);
if (missingBeanName != null) {
Module module = ModuleUtilCore.findModuleForPsiElement(element);
boolean beanExists = module != null && BeanUtils.getService().findReferenceableBeanId(module, missingBeanName).isPresent();
if (beanExists) {
return; // camel catalog's validator can't see the beans we can see, let's ignore the error if we known the bean exists
}
}
TextRange range = element.getTextRange();
if (result.getIndex() > 0) {
range = getAdjustedTextRange(element, range, text, result);
Expand All @@ -90,6 +101,23 @@ void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder,
}
}

/**
* This is hoping that the error message will stay the same forever.
* Could be implemented in a different way, see GH issue #1115 - supply list of beans we know to Camel catalog's validator.
*/
private String extractMissingBeanName(LanguageValidationResult result) {
String missingBeanErrorPrefix = "No bean could be found in the registry for: ";
String error = result.getError();
if (error.startsWith(missingBeanErrorPrefix)) {
return error.substring(missingBeanErrorPrefix.length())
.trim()
.split(" ")[0]
.trim();
} else {
return null;
}
}

/**
* Adjust the text range according to the type of ${@link PsiElement}
* @return a new text range
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,40 @@ public void testXmlAnnotatorWithLogValidation() {
myFixture.checkHighlighting(false, false, false, true);
}

public void testMissingBeanErrorFromCatalogValidatorSupressed() {
myFixture.configureByText("test.xml", """
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="testBean" class="java.lang.String"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="testRoute">
<from uri="timer:foo?period=1s"/>
<when>
<simple>${bean:testBean?method=printThread}</simple>
</when>
</route>
</camelContext>
</blueprint>
""");
myFixture.checkHighlighting(false, false, false, true);
}

public void testMissingBeanErrorFromCatalogValidatorNotSupressed() {
myFixture.configureByText("test.xml", """
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<bean id="testBean2" class="java.lang.String"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<route id="testRoute">
<from uri="timer:foo?period=1s"/>
<when>
<simple><error descr="No bean could be found in the registry for: testBean">${bean:testBean?method=printThread}</error></simple>
</when>
</route>
</camelContext>
</blueprint>
""");
myFixture.checkHighlighting(false, false, false, true);
}

private String getJavaWithSimple() {
return "import org.apache.camel.builder.RouteBuilder;\n"
+ "public class MyRouteBuilder extends RouteBuilder {\n"
Expand Down
Loading