Maven: fix for unresolved schema file (15493)
[fedora-idea.git] / plugins / maven / src / main / java / org / jetbrains / idea / maven / dom / MavenSchemaProvider.java
blob360c6a53c60dba17428747cda1f140754544a139
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.maven.dom;
18 import com.intellij.javaee.ExternalResourceManager;
19 import com.intellij.javaee.ExternalResourceManagerEx;
20 import com.intellij.javaee.ResourceRegistrar;
21 import com.intellij.javaee.StandardResourceProvider;
22 import com.intellij.openapi.vfs.VfsUtil;
23 import com.intellij.openapi.vfs.VirtualFile;
24 import org.jetbrains.annotations.NotNull;
26 public class MavenSchemaProvider implements StandardResourceProvider {
27 public static final String MAVEN_PROJECT_SCHEMA_URL = "http://maven.apache.org/xsd/maven-4.0.0.xsd";
28 public static final String MAVEN_PROFILES_SCHEMA_URL = "http://maven.apache.org/xsd/profiles-1.0.0.xsd";
29 public static final String MAVEN_SETTINGS_SCHEMA_URL = "http://maven.apache.org/xsd/settings-1.0.0.xsd";
31 public void registerResources(ResourceRegistrar registrar) {
32 registrar.addStdResource("http://maven.apache.org/maven-v4_0_0.xsd", "maven-4.0.0.xsd", getClass());
33 registrar.addStdResource(MAVEN_PROJECT_SCHEMA_URL, "maven-4.0.0.xsd", getClass());
35 registrar.addStdResource(MAVEN_PROFILES_SCHEMA_URL, "profiles-1.0.0.xsd", getClass());
36 registrar.addStdResource(MAVEN_SETTINGS_SCHEMA_URL, "settings-1.0.0.xsd", getClass());
39 @NotNull
40 public static VirtualFile getSchemaFile(@NotNull String url) {
41 String location = ((ExternalResourceManagerEx)ExternalResourceManager.getInstance()).getStdResource(url, null);
42 assert location != null : "cannot find a standard resource for " + url;
44 VirtualFile result = VfsUtil.findRelativeFile(location, null);
45 assert result != null : "cannot find a schema file for URL: " + url + " location: " + location;
47 return result;