Search in sources :

Example 1 with JsonSchemaService

use of com.jetbrains.jsonSchema.ide.JsonSchemaService in project intellij-community by JetBrains.

the class JsonSchemaConfigurable method doValidation.

private void doValidation() throws ConfigurationException {
    final File file = new File(myProject.getBasePath(), myView.getSchemaSubPath());
    VirtualFile vFile = null;
    if (!file.exists() || (vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file)) == null) {
        throw new ConfigurationException((!StringUtil.isEmptyOrSpaces(myDisplayName) ? (myDisplayName + ": ") : "") + "Schema file does not exist");
    }
    final String filename = file.getName();
    if (StringUtil.isEmptyOrSpaces(myDisplayName))
        throw new ConfigurationException(filename + ": Schema name is empty");
    if (StringUtil.isEmptyOrSpaces(myView.getSchemaSubPath()))
        throw new ConfigurationException(filename + ": Schema path is empty");
    final CollectConsumer<String> collectConsumer = new CollectConsumer<>();
    final JsonSchemaService service = JsonSchemaService.Impl.get(myProject);
    if (service != null && !service.isSchemaFile(vFile, collectConsumer)) {
        final String message;
        if (collectConsumer.getResult().isEmpty())
            message = filename + ": Can not read JSON schema from file (Unknown reason)";
        else
            message = filename + ": Can not read JSON schema from file: " + StringUtil.join(collectConsumer.getResult(), "; ");
        logErrorForUser(message);
        throw new RuntimeConfigurationWarning(message);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConfigurationException(com.intellij.openapi.options.ConfigurationException) CollectConsumer(com.intellij.util.CollectConsumer) RuntimeConfigurationWarning(com.intellij.execution.configurations.RuntimeConfigurationWarning) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) JsonSchemaService(com.jetbrains.jsonSchema.ide.JsonSchemaService)

Example 2 with JsonSchemaService

use of com.jetbrains.jsonSchema.ide.JsonSchemaService in project intellij-community by JetBrains.

the class JsonSchemaMappingsConfigurable method apply.

@Override
public void apply() throws ConfigurationException {
    final List<JsonSchemaMappingsConfigurationBase.SchemaInfo> uiList = getUiList(true);
    validate(uiList);
    final Map<String, JsonSchemaMappingsConfigurationBase.SchemaInfo> projectMap = new HashMap<>();
    for (JsonSchemaMappingsConfigurationBase.SchemaInfo info : uiList) {
        if (!info.isApplicationLevel()) {
            projectMap.put(info.getName(), info);
        }
    }
    if (myProject != null) {
        JsonSchemaMappingsProjectConfiguration.getInstance(myProject).setState(projectMap);
    }
    final Project[] projects = ProjectManager.getInstance().getOpenProjects();
    for (Project project : projects) {
        final JsonSchemaService service = JsonSchemaService.Impl.get(project);
        if (service != null)
            service.reset();
    }
    if (myProject != null) {
        DaemonCodeAnalyzer.getInstance(myProject).restart();
        EditorNotifications.getInstance(myProject).updateAllNotifications();
    }
}
Also used : Project(com.intellij.openapi.project.Project) JsonSchemaService(com.jetbrains.jsonSchema.ide.JsonSchemaService)

Aggregations

JsonSchemaService (com.jetbrains.jsonSchema.ide.JsonSchemaService)2 RuntimeConfigurationWarning (com.intellij.execution.configurations.RuntimeConfigurationWarning)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 CollectConsumer (com.intellij.util.CollectConsumer)1 File (java.io.File)1