Search in sources :

Example 1 with CamelService

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;
}
Also used : RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) Project(com.intellij.openapi.project.Project) CamelService(com.github.cameltooling.idea.service.CamelService) CamelPreferenceService(com.github.cameltooling.idea.service.CamelPreferenceService) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with CamelService

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());
    }
}
Also used : Project(com.intellij.openapi.project.Project) CamelService(com.github.cameltooling.idea.service.CamelService)

Example 3 with CamelService

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());
    }
}
Also used : Project(com.intellij.openapi.project.Project) CamelService(com.github.cameltooling.idea.service.CamelService)

Example 4 with CamelService

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);
        }
    }
}
Also used : CamelCatalog(org.apache.camel.catalog.CamelCatalog) CamelCatalogService(com.github.cameltooling.idea.service.CamelCatalogService) LanguageValidationResult(org.apache.camel.catalog.LanguageValidationResult) CamelService(com.github.cameltooling.idea.service.CamelService) TextRange(com.intellij.openapi.util.TextRange)

Example 5 with CamelService

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);
        }
    }
}
Also used : CamelCatalog(org.apache.camel.catalog.CamelCatalog) CamelCatalogService(com.github.cameltooling.idea.service.CamelCatalogService) LanguageValidationResult(org.apache.camel.catalog.LanguageValidationResult) CamelService(com.github.cameltooling.idea.service.CamelService) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

CamelService (com.github.cameltooling.idea.service.CamelService)14 CamelCatalogService (com.github.cameltooling.idea.service.CamelCatalogService)5 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 Project (com.intellij.openapi.project.Project)4 CamelCatalog (org.apache.camel.catalog.CamelCatalog)4 LanguageValidationResult (org.apache.camel.catalog.LanguageValidationResult)4 Module (com.intellij.openapi.module.Module)3 CamelPreferenceService (com.github.cameltooling.idea.service.CamelPreferenceService)2 ExecutionException (com.intellij.execution.ExecutionException)2 RunConfigurationBase (com.intellij.execution.configurations.RunConfigurationBase)2 Library (com.intellij.openapi.roots.libraries.Library)2 TextRange (com.intellij.openapi.util.TextRange)2 IElementType (com.intellij.psi.tree.IElementType)2 File (java.io.File)2 CamelMessageInfo (com.github.cameltooling.idea.runner.debugger.stack.CamelMessageInfo)1 DebuggerManagerEx (com.intellij.debugger.DebuggerManagerEx)1 DefaultDebugEnvironment (com.intellij.debugger.DefaultDebugEnvironment)1 DebugProcessImpl (com.intellij.debugger.engine.DebugProcessImpl)1 JavaDebugProcess (com.intellij.debugger.engine.JavaDebugProcess)1