mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
IDEA-77160 ${env.PATH} variable highlighted as red error
This commit is contained in:
@@ -298,13 +298,6 @@ public class MavenDomUtil {
|
||||
return children[index];
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PropertiesFile getPropertiesFile(@NotNull Project project, @NotNull String fileName) {
|
||||
VirtualFile file = MavenPropertiesVirtualFileSystem.getInstance().findFileByPath(fileName);
|
||||
if (file == null) return null;
|
||||
return getPropertiesFile(project, file);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PropertiesFile getPropertiesFile(@NotNull Project project, @NotNull VirtualFile file) {
|
||||
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
|
||||
@@ -312,12 +305,6 @@ public class MavenDomUtil {
|
||||
return (PropertiesFile)psiFile;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IProperty findProperty(@NotNull Project project, @NotNull String fileName, @NotNull String propName) {
|
||||
PropertiesFile propertiesFile = getPropertiesFile(project, fileName);
|
||||
return propertiesFile == null ? null : propertiesFile.findPropertyByKey(propName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IProperty findProperty(@NotNull Project project, @NotNull VirtualFile file, @NotNull String propName) {
|
||||
PropertiesFile propertiesFile = getPropertiesFile(project, file);
|
||||
|
||||
+8
-6
@@ -185,21 +185,22 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
|
||||
if (result != null) return result;
|
||||
}
|
||||
|
||||
IProperty property = MavenDomUtil.findProperty(myProject, MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, myText);
|
||||
MavenPropertiesVirtualFileSystem mavenPropertiesVirtualFileSystem = MavenPropertiesVirtualFileSystem.getInstance();
|
||||
|
||||
IProperty property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, myText);
|
||||
if (property != null) return property.getPsiElement();
|
||||
|
||||
if (myText.startsWith("env.")) {
|
||||
property = MavenDomUtil.findProperty(myProject, MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE,
|
||||
myText.substring("env.".length()));
|
||||
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, myText.substring("env.".length()));
|
||||
if (property != null) return property.getPsiElement();
|
||||
}
|
||||
|
||||
String textWithEnv = "env." + myText;
|
||||
|
||||
property = MavenDomUtil.findProperty(myProject, MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE, textWithEnv);
|
||||
property = mavenPropertiesVirtualFileSystem.findSystemProperty(myProject, textWithEnv);
|
||||
if (property != null) return property.getPsiElement();
|
||||
|
||||
property = MavenDomUtil.findProperty(myProject, MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE, textWithEnv);
|
||||
property = mavenPropertiesVirtualFileSystem.findEnvProperty(myProject, textWithEnv);
|
||||
if (property != null) return property.getPsiElement();
|
||||
|
||||
if (!hasPrefix) {
|
||||
@@ -390,7 +391,8 @@ public class MavenPropertyPsiReference extends MavenPsiReference {
|
||||
}
|
||||
|
||||
private void collectSystemEnvProperties(String propertiesFileName, @Nullable String prefix, List<Object> result) {
|
||||
PropertiesFile file = MavenDomUtil.getPropertiesFile(myProject, propertiesFileName);
|
||||
VirtualFile virtualFile = MavenPropertiesVirtualFileSystem.getInstance().findFileByPath(propertiesFileName);
|
||||
PropertiesFile file = MavenDomUtil.getPropertiesFile(myProject, virtualFile);
|
||||
collectPropertiesFileVariants(file, prefix, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -203,29 +203,6 @@ public class MavenUtil {
|
||||
Notifications.Bus.notify(new Notification(MAVEN_NOTIFICATION_GROUP, title, e.getMessage(), NotificationType.ERROR), project);
|
||||
}
|
||||
|
||||
public static Properties getSystemProperties() {
|
||||
Properties result = (Properties)System.getProperties().clone();
|
||||
for (String each : new THashSet<String>((Set)result.keySet())) {
|
||||
if (each.startsWith("idea.")) {
|
||||
result.remove(each);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Properties getEnvProperties() {
|
||||
Properties reuslt = new Properties();
|
||||
for (Map.Entry<String, String> each : System.getenv().entrySet()) {
|
||||
if (isMagicalProperty(each.getKey())) continue;
|
||||
reuslt.put(each.getKey(), each.getValue());
|
||||
}
|
||||
return reuslt;
|
||||
}
|
||||
|
||||
private static boolean isMagicalProperty(String key) {
|
||||
return key.startsWith("=");
|
||||
}
|
||||
|
||||
public static File getPluginSystemDir(String folder) {
|
||||
// PathManager.getSystemPath() may return relative path
|
||||
return new File(PathManager.getSystemPath(), "Maven" + "/" + folder).getAbsoluteFile();
|
||||
|
||||
+56
-14
@@ -15,16 +15,19 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.vfs;
|
||||
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.openapi.vfs.ex.dummy.DummyFileSystem;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil;
|
||||
import org.jetbrains.idea.maven.dom.MavenDomUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenPropertiesVirtualFileSystem extends DummyFileSystem {
|
||||
@NonNls public static final String PROTOCOL = "maven-properties";
|
||||
@@ -34,7 +37,8 @@ public class MavenPropertiesVirtualFileSystem extends DummyFileSystem {
|
||||
|
||||
public static final String[] PROPERTIES_FILES = new String[]{SYSTEM_PROPERTIES_FILE, ENV_PROPERTIES_FILE};
|
||||
|
||||
private final Map<String, VirtualFile> myFiles = new THashMap<String, VirtualFile>();
|
||||
private VirtualFile mySystemPropertiesFile;
|
||||
private VirtualFile myEnvPropertiesFile;
|
||||
|
||||
public static MavenPropertiesVirtualFileSystem getInstance() {
|
||||
return (MavenPropertiesVirtualFileSystem)VirtualFileManager.getInstance().getFileSystem(PROTOCOL);
|
||||
@@ -45,27 +49,65 @@ public class MavenPropertiesVirtualFileSystem extends DummyFileSystem {
|
||||
return PROTOCOL;
|
||||
}
|
||||
|
||||
public VirtualFile getSystemPropertiesFile() {
|
||||
if (mySystemPropertiesFile == null) {
|
||||
Properties systemProperties = new Properties();
|
||||
|
||||
for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
|
||||
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
|
||||
String key = (String)entry.getKey();
|
||||
if (!key.startsWith("idea.")) {
|
||||
systemProperties.setProperty(key, (String)entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mySystemPropertiesFile = new MavenPropertiesVirtualFile(SYSTEM_PROPERTIES_FILE, systemProperties, this);
|
||||
}
|
||||
|
||||
return mySystemPropertiesFile;
|
||||
}
|
||||
|
||||
public VirtualFile getEnvPropertiesFile() {
|
||||
if (myEnvPropertiesFile == null) {
|
||||
Properties envProperties = new Properties();
|
||||
|
||||
for (Map.Entry<String, String> each : System.getenv().entrySet()) {
|
||||
if (each.getKey().startsWith("=")) continue;
|
||||
envProperties.setProperty(each.getKey(), SystemInfo.isWindows ? each.getValue().toUpperCase() : each.getValue());
|
||||
}
|
||||
|
||||
myEnvPropertiesFile = new MavenPropertiesVirtualFile(ENV_PROPERTIES_FILE, envProperties, this);
|
||||
}
|
||||
|
||||
return myEnvPropertiesFile;
|
||||
}
|
||||
|
||||
//@Override
|
||||
//public boolean isPhysical() {
|
||||
// return false;
|
||||
//}
|
||||
|
||||
public synchronized VirtualFile findFileByPath(@NotNull @NonNls String path) {
|
||||
VirtualFile result = myFiles.get(path);
|
||||
if (result != null) return result;
|
||||
|
||||
result = createFile(path);
|
||||
if (result != null) {
|
||||
myFiles.put(path, result);
|
||||
if (path.equals(SYSTEM_PROPERTIES_FILE)) {
|
||||
return getSystemPropertiesFile();
|
||||
}
|
||||
return result;
|
||||
|
||||
if (path.equals(ENV_PROPERTIES_FILE)) {
|
||||
return getEnvPropertiesFile();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private VirtualFile createFile(String path) {
|
||||
if (SYSTEM_PROPERTIES_FILE.equals(path)) return new MavenPropertiesVirtualFile(path, MavenUtil.getSystemProperties(), this);
|
||||
if (ENV_PROPERTIES_FILE.equals(path)) return new MavenPropertiesVirtualFile(path, MavenUtil.getEnvProperties(), this);
|
||||
return null;
|
||||
public IProperty findSystemProperty(Project project, @NotNull String propertyName) {
|
||||
return MavenDomUtil.findProperty(project, getSystemPropertiesFile(), propertyName);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public IProperty findEnvProperty(Project project, @NotNull String propertyName) {
|
||||
return MavenDomUtil.findProperty(project, getEnvPropertiesFile(), propertyName);
|
||||
}
|
||||
|
||||
//protected void deleteFile(Object requestor, VirtualFile vFile) throws IOException {
|
||||
|
||||
+46
-6
@@ -15,9 +15,13 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.dom;
|
||||
|
||||
import com.intellij.lang.properties.IProperty;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomProfiles;
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomProfilesModel;
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomSettingsModel;
|
||||
@@ -689,9 +693,7 @@ public class MavenPropertyCompletionAndResolutionTest extends MavenDomTestCase {
|
||||
|
||||
"<name>${<caret>user.home}</name>");
|
||||
|
||||
assertResolved(myProjectPom, MavenDomUtil.findProperty(myProject,
|
||||
MavenPropertiesVirtualFileSystem.SYSTEM_PROPERTIES_FILE,
|
||||
"user.home").getPsiElement());
|
||||
assertResolved(myProjectPom, MavenPropertiesVirtualFileSystem.getInstance().findSystemProperty(myProject, "user.home").getPsiElement());
|
||||
}
|
||||
|
||||
public void testEnvProperties() throws Exception {
|
||||
@@ -701,9 +703,47 @@ public class MavenPropertyCompletionAndResolutionTest extends MavenDomTestCase {
|
||||
|
||||
"<name>${<caret>env." + getEnvVar() + "}</name>");
|
||||
|
||||
assertResolved(myProjectPom, MavenDomUtil.findProperty(myProject,
|
||||
MavenPropertiesVirtualFileSystem.ENV_PROPERTIES_FILE,
|
||||
getEnvVar()).getPsiElement());
|
||||
assertResolved(myProjectPom, MavenPropertiesVirtualFileSystem.getInstance().findEnvProperty(myProject, getEnvVar()).getPsiElement());
|
||||
}
|
||||
|
||||
public void testUpperCaseEnvPropertiesOnWindows() throws Exception {
|
||||
if (!SystemInfo.isWindows) return;
|
||||
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
|
||||
"<name>${<caret>env.PATH}</name>");
|
||||
|
||||
PsiReference ref = getReferenceAtCaret(myProjectPom);
|
||||
assertNotNull(ref);
|
||||
|
||||
PsiElement resolved = ref.resolve();
|
||||
assertEquals(System.getenv("Path"), ((IProperty)resolved).getValue());
|
||||
}
|
||||
|
||||
public void testCaseInsencitiveOnWindows() throws Exception {
|
||||
if (!SystemInfo.isWindows) return;
|
||||
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
|
||||
"<name>${<caret>env.PaTH}</name>");
|
||||
|
||||
assertUnresolved(myProjectPom);
|
||||
}
|
||||
|
||||
public void testNotUpperCaseEnvPropertiesOnWindows() throws Exception {
|
||||
if (!SystemInfo.isWindows) return;
|
||||
|
||||
createProjectPom("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>" +
|
||||
|
||||
"<name>${<caret>env.Path}</name>");
|
||||
|
||||
assertUnresolved(myProjectPom);
|
||||
}
|
||||
|
||||
public void testHighlightUnresolvedProperties() throws Exception {
|
||||
|
||||
+1
-1
@@ -1294,7 +1294,7 @@ public class MavenProjectReaderTest extends MavenTestCase {
|
||||
}
|
||||
|
||||
public void testActivatingProfilesByEnvProperty() throws Exception {
|
||||
String value = MavenUtil.getEnvProperties().getProperty(getEnvVar());
|
||||
String value = System.getenv(getEnvVar());
|
||||
|
||||
createProjectPom("<profiles>" +
|
||||
" <profile>" +
|
||||
|
||||
Reference in New Issue
Block a user