use of com.github.cameltooling.idea.service.CamelService in project camel-idea-plugin by camel-tooling.
the class CamelDebuggerRunner method canRun.
@Override
public boolean canRun(@NotNull String executorId, @NotNull RunProfile profile) {
CamelPreferenceService preferenceService = ServiceManager.getService(CamelPreferenceService.class);
if (!preferenceService.isEnableCamelDebugger()) {
return false;
}
if (profile instanceof RunConfigurationBase) {
try {
final RunConfigurationBase base = (RunConfigurationBase) profile;
final Project project = base.getProject();
final CamelService camelService = project.getService(CamelService.class);
if (camelService != null) {
boolean isDebug = executorId.equals(DefaultDebugExecutor.EXECUTOR_ID);
boolean isCamelPresent = camelService.isCamelPresent();
boolean canRun = isDebug && isCamelPresent;
LOG.debug("Executor ID is " + executorId + " ; Camel present = " + camelService.isCamelPresent() + " ; canRun is " + canRun);
return canRun;
}
} catch (Exception e) {
LOG.debug("Camel Debugger cannot run", e);
return false;
}
}
LOG.debug("Camel Debugger cannot run, profile is not RunConfiguration");
return false;
}
use of com.github.cameltooling.idea.service.CamelService in project camel-idea-plugin by camel-tooling.
the class CamelEvaluateAction method update.
@Override
public void update(@NotNull final AnActionEvent event) {
super.update(event);
if (event.getPresentation().isEnabledAndVisible()) {
final Project project = event.getProject();
final CamelService camelService = project.getService(CamelService.class);
event.getPresentation().setEnabled(camelService.isCamelPresent());
event.getPresentation().setVisible(camelService.isCamelPresent());
}
}
use of com.github.cameltooling.idea.service.CamelService in project camel-idea-plugin by camel-tooling.
the class CamelSetValueAction method update.
@Override
public void update(@NotNull final AnActionEvent event) {
super.update(event);
if (event.getPresentation().isEnabledAndVisible()) {
final Project project = event.getProject();
final CamelService camelService = project.getService(CamelService.class);
event.getPresentation().setEnabled(camelService.isCamelPresent());
event.getPresentation().setVisible(camelService.isCamelPresent());
}
}
use of com.github.cameltooling.idea.service.CamelService in project camel-idea-plugin by camel-tooling.
the class CamelJSonPathAnnotator method validateText.
/**
* Validate jsonpath expression. eg jsonpath("$.store.book[?(@.price < 10)]")
* if the expression is not valid a error annotation is created and highlight the invalid value.
*/
void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull String text) {
// only validate if the element is jsonpath element
if (getCamelIdeaUtils().isCamelExpression(element, "jsonpath")) {
CamelCatalog catalogService = ServiceManager.getService(element.getProject(), CamelCatalogService.class).get();
CamelService camelService = ServiceManager.getService(element.getProject(), CamelService.class);
// must have camel-json library
boolean jsonLib = camelService.containsLibrary("camel-jsonpath", false);
if (!jsonLib) {
camelService.showMissingJSonPathJarNotification(element.getProject());
return;
}
try {
// need to use the classloader that can load classes from the project
ClassLoader loader = camelService.getProjectClassloader();
if (loader != null) {
LanguageValidationResult result;
boolean predicate = getCamelIdeaUtils().isCamelExpressionUsedAsPredicate(element, "jsonpath");
if (predicate) {
LOG.debug("Inspecting jsonpath predicate: " + text);
result = catalogService.validateLanguagePredicate(loader, "jsonpath", text);
} else {
LOG.debug("Inspecting jsonpath expression: " + text);
result = catalogService.validateLanguageExpression(loader, "jsonpath", text);
}
if (!result.isSuccess()) {
String error = result.getShortError();
if ("[null]".equals(error)) {
return;
}
if (error == null) {
error = result.getError();
}
TextRange range = element.getTextRange();
if (result.getIndex() > 0) {
range = getAdjustedTextRange(element, range, text, result);
}
holder.newAnnotation(HighlightSeverity.ERROR, error).range(range).create();
}
}
} catch (Throwable e) {
LOG.warn("Error inspecting Camel jsonpath: " + text, e);
}
}
}
use of com.github.cameltooling.idea.service.CamelService in project camel-idea-plugin by camel-tooling.
the class CamelSimpleAnnotator method validateText.
/**
* Validate simple expression. eg simple("${body}")
* if the expression is not valid a error annotation is created and highlight the invalid value.
*/
void validateText(@NotNull PsiElement element, @NotNull AnnotationHolder holder, @NotNull String text) {
// we only want to evaluate if there is a simple function as plain text without functions dont make sense to validate
boolean hasSimple = text.contains("${") || text.contains("$simple{");
if (hasSimple && getCamelIdeaUtils().isCamelExpression(element, "simple")) {
CamelCatalog catalogService = ServiceManager.getService(element.getProject(), CamelCatalogService.class).get();
CamelService camelService = ServiceManager.getService(element.getProject(), CamelService.class);
boolean predicate = false;
try {
// need to use the classloader that can load classes from the camel-core
ClassLoader loader = camelService.getCamelCoreClassloader();
if (loader != null) {
LanguageValidationResult result;
predicate = getCamelIdeaUtils().isCamelExpressionUsedAsPredicate(element, "simple");
if (predicate) {
LOG.debug("Validate simple predicate: " + text);
result = catalogService.validateLanguagePredicate(loader, "simple", text);
} else {
LOG.debug("Validate simple expression: " + text);
result = catalogService.validateLanguageExpression(loader, "simple", text);
}
if (!result.isSuccess()) {
String error = result.getShortError();
if ("[null]".equals(error)) {
return;
}
TextRange range = element.getTextRange();
if (result.getIndex() > 0) {
range = getAdjustedTextRange(element, range, text, result);
}
holder.newAnnotation(HighlightSeverity.ERROR, error).range(range).create();
}
}
} catch (Throwable e) {
LOG.warn("Error validating Camel simple " + (predicate ? "predicate" : "expression") + ": " + text, e);
}
}
}
Aggregations