Search in sources :

Example 1 with JstdRunSettings

use of com.google.jstestdriver.idea.execution.settings.JstdRunSettings in project intellij-plugins by JetBrains.

the class JstdRunConfiguration method readExternal.

@Override
public void readExternal(Element element) throws InvalidDataException {
    super.readExternal(element);
    JstdRunSettings runSettings = JstdRunSettingsSerializationUtils.readFromXml(element);
    setRunSettings(runSettings);
}
Also used : JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings)

Example 2 with JstdRunSettings

use of com.google.jstestdriver.idea.execution.settings.JstdRunSettings in project intellij-plugins by JetBrains.

the class JstdRunConfigurationProducer method buildRunSettingsContext.

@Nullable
private static JstdRunSettings buildRunSettingsContext(@Nullable Location<?> location) {
    if (location != null) {
        PsiElement element = location.getPsiElement();
        JstdRunSettings runSettings = findJstdRunSettings(element);
        if (runSettings != null) {
            return runSettings;
        }
    }
    return null;
}
Also used : JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with JstdRunSettings

use of com.google.jstestdriver.idea.execution.settings.JstdRunSettings in project intellij-plugins by JetBrains.

the class JstdRunConfigurationRefactoringHandler method getRefactoringElementListener.

@Nullable
public static RefactoringElementListener getRefactoringElementListener(@NotNull JstdRunConfiguration configuration, @Nullable PsiElement element) {
    VirtualFile fileAtElement = PsiUtilBase.asVirtualFile(element);
    if (fileAtElement == null) {
        return null;
    }
    JstdRunSettings settings = configuration.getRunSettings();
    String path = fileAtElement.getPath();
    if (settings.getTestType() == TestType.ALL_CONFIGS_IN_DIRECTORY) {
        String allInDirectory = FileUtil.toSystemIndependentName(settings.getDirectory());
        if (allInDirectory.equals(path)) {
            return new FilePathRefactoringElementListener(configuration, false, false, true);
        }
    } else {
        String jsFilePath = FileUtil.toSystemIndependentName(settings.getJsFilePath());
        if (jsFilePath.equals(path)) {
            return new FilePathRefactoringElementListener(configuration, false, true, false);
        }
        String configFilePath = FileUtil.toSystemIndependentName(settings.getConfigFile());
        if (configFilePath.equals(path)) {
            return new FilePathRefactoringElementListener(configuration, true, false, false);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with JstdRunSettings

use of com.google.jstestdriver.idea.execution.settings.JstdRunSettings in project intellij-plugins by JetBrains.

the class JstdRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(JstdRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Project project = configuration.getProject();
    if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
        return false;
    }
    RunConfiguration original = context.getOriginalConfiguration(null);
    if (original != null && !ConfigurationTypeUtil.equals(original.getType(), JstdConfigurationType.getInstance())) {
        return false;
    }
    long startTimeNano = System.nanoTime();
    @SuppressWarnings({ "unchecked" }) JstdRunSettings settings = buildRunSettingsContext(context.getLocation());
    if (settings == null) {
        logDoneCreateConfigurationByElement(startTimeNano, "1");
        return false;
    }
    if (settings.getConfigFile().isEmpty()) {
        JstdRunSettings clonedSettings = configuration.getRunSettings();
        JstdRunSettings.Builder builder = new JstdRunSettings.Builder(settings);
        builder.setConfigFile(clonedSettings.getConfigFile());
        settings = builder.build();
    }
    configuration.setRunSettings(settings);
    String configurationName = configuration.resetGeneratedName();
    configuration.setName(configurationName);
    logDoneCreateConfigurationByElement(startTimeNano, "3");
    return true;
}
Also used : Project(com.intellij.openapi.project.Project) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings)

Example 5 with JstdRunSettings

use of com.google.jstestdriver.idea.execution.settings.JstdRunSettings in project intellij-plugins by JetBrains.

the class JstdRunConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(JstdRunConfiguration configuration, ConfigurationContext context) {
    Project project = configuration.getProject();
    if (!JstdSettingsUtil.areJstdConfigFilesInProjectCached(project)) {
        return false;
    }
    JstdRunSettings patternRunSettings = buildRunSettingsContext(context.getLocation());
    if (patternRunSettings == null) {
        return false;
    }
    JstdRunSettings candidateRunSettings = configuration.getRunSettings();
    TestType patternTestType = patternRunSettings.getTestType();
    if (patternTestType != candidateRunSettings.getTestType()) {
        return false;
    }
    if (patternTestType == TestType.ALL_CONFIGS_IN_DIRECTORY) {
        File dir1 = new File(patternRunSettings.getDirectory());
        File dir2 = new File(candidateRunSettings.getDirectory());
        if (dir1.isDirectory() && dir2.isDirectory() && FileUtil.filesEqual(dir1, dir2)) {
            return true;
        }
    } else if (patternTestType == TestType.CONFIG_FILE) {
        File configFilePattern = new File(patternRunSettings.getConfigFile());
        File configFileCandidate = new File(candidateRunSettings.getConfigFile());
        if (configFilePattern.isFile() && configFileCandidate.isFile() && FileUtil.filesEqual(configFilePattern, configFileCandidate)) {
            return true;
        }
    } else if (patternTestType == TestType.JS_FILE || patternTestType == TestType.TEST_CASE || patternTestType == TestType.TEST_METHOD) {
        File patternJsFile = new File(patternRunSettings.getJsFilePath());
        File candidateJsFile = new File(candidateRunSettings.getJsFilePath());
        boolean eq = candidateJsFile.isFile() && FileUtil.filesEqual(patternJsFile, candidateJsFile);
        if (patternTestType == TestType.TEST_CASE) {
            eq = eq && patternRunSettings.getTestCaseName().equals(candidateRunSettings.getTestCaseName());
        }
        if (patternTestType == TestType.TEST_METHOD) {
            eq = eq && patternRunSettings.getTestCaseName().equals(candidateRunSettings.getTestCaseName());
            eq = eq && patternRunSettings.getTestMethodName().equals(candidateRunSettings.getTestMethodName());
        }
        if (eq) {
            return true;
        }
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) TestType(com.google.jstestdriver.idea.execution.settings.TestType) JstdRunSettings(com.google.jstestdriver.idea.execution.settings.JstdRunSettings) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) JSFile(com.intellij.lang.javascript.psi.JSFile) File(java.io.File)

Aggregations

JstdRunSettings (com.google.jstestdriver.idea.execution.settings.JstdRunSettings)5 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Nullable (org.jetbrains.annotations.Nullable)2 TestType (com.google.jstestdriver.idea.execution.settings.TestType)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 JSFile (com.intellij.lang.javascript.psi.JSFile)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 File (java.io.File)1