mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly determine antfile path for the 'ant' task (IDEA-72209)
This commit is contained in:
@@ -15,9 +15,11 @@
|
||||
*/
|
||||
package com.intellij.lang.ant.dom;
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.util.xml.Attribute;
|
||||
import com.intellij.util.xml.Convert;
|
||||
import com.intellij.util.xml.ConvertContext;
|
||||
import com.intellij.util.xml.GenericAttributeValue;
|
||||
|
||||
/**
|
||||
@@ -25,9 +27,10 @@ import com.intellij.util.xml.GenericAttributeValue;
|
||||
* Date: Aug 3, 2010
|
||||
*/
|
||||
public abstract class AntDomAnt extends AntDomElement {
|
||||
|
||||
public static final String DEFAULT_ANTFILE_NAME = "build.xml";
|
||||
|
||||
@Attribute("antfile")
|
||||
@Convert(value = AntPathValidatingConverter.class)
|
||||
@Convert(value = AntFilePathConverter.class)
|
||||
public abstract GenericAttributeValue<PsiFileSystemItem> getAntFilePath();
|
||||
|
||||
@Attribute("dir")
|
||||
@@ -53,4 +56,33 @@ public abstract class AntDomAnt extends AntDomElement {
|
||||
@Attribute("usenativebasedir")
|
||||
@Convert(value = AntBooleanConverterDefaultFalse.class)
|
||||
public abstract GenericAttributeValue<Boolean> isUseNativeBasedir();
|
||||
|
||||
public static class AntFilePathConverter extends AntPathConverter {
|
||||
public AntFilePathConverter() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
protected String getPathResolveRoot(ConvertContext context, AntDomProject antProject) {
|
||||
final AntDomAnt antElement = context.getInvocationElement().getParentOfType(AntDomAnt.class, false);
|
||||
if (antElement != null) {
|
||||
PsiFileSystemItem dir = antElement.getAntFileDir().getValue();
|
||||
if (dir == null) {
|
||||
if (antElement.isInheritAllProperties().getValue()) {
|
||||
dir = antProject.getProjectBasedir();
|
||||
}
|
||||
}
|
||||
if (dir != null) {
|
||||
final VirtualFile vFile = dir.getVirtualFile();
|
||||
if (vFile != null) {
|
||||
return vFile.getPath();
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.getPathResolveRoot(context, antProject);
|
||||
}
|
||||
|
||||
protected String getAttributeDefaultValue(ConvertContext context, GenericAttributeValue attribValue) {
|
||||
return DEFAULT_ANTFILE_NAME;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.intellij.pom.references.PomService;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.xml.XmlElement;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
@@ -67,6 +68,24 @@ public abstract class AntDomProject extends AntDomNamedElement implements Proper
|
||||
@Convert(value = AntPathConverter.class)
|
||||
public abstract GenericAttributeValue<PsiFileSystemItem> getBasedir();
|
||||
|
||||
@Nullable
|
||||
public final PsiFileSystemItem getProjectBasedir() {
|
||||
final PsiFileSystemItem basedir = getBasedir().getValue();
|
||||
if (basedir != null) {
|
||||
return basedir;
|
||||
}
|
||||
final XmlTag tag = getXmlTag();
|
||||
final VirtualFile containingFile = tag.getContainingFile().getOriginalFile().getVirtualFile();
|
||||
if (containingFile == null) {
|
||||
return null;
|
||||
}
|
||||
final VirtualFile parent = containingFile.getParent();
|
||||
if (parent == null) {
|
||||
return null;
|
||||
}
|
||||
return PsiManager.getInstance(tag.getProject()).findDirectory(parent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public final String getProjectBasedirPath() {
|
||||
final String basedir = getBasedir().getStringValue();
|
||||
|
||||
@@ -51,7 +51,10 @@ public class AntPathConverter extends Converter<PsiFileSystemItem> implements Cu
|
||||
if (attribValue == null) {
|
||||
return null;
|
||||
}
|
||||
final String path = attribValue.getStringValue();
|
||||
String path = attribValue.getStringValue();
|
||||
if (path == null) {
|
||||
path = getAttributeDefaultValue(context, attribValue);
|
||||
}
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -61,7 +64,7 @@ public class AntPathConverter extends Converter<PsiFileSystemItem> implements Cu
|
||||
if (antProject == null) {
|
||||
return null;
|
||||
}
|
||||
file = new File(getPathResolveRoot(antProject), path);
|
||||
file = new File(getPathResolveRoot(context, antProject), path);
|
||||
}
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(file.getAbsolutePath()));
|
||||
if (vFile == null) {
|
||||
@@ -81,10 +84,15 @@ public class AntPathConverter extends Converter<PsiFileSystemItem> implements Cu
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getPathResolveRoot(AntDomProject antProject) {
|
||||
protected String getPathResolveRoot(ConvertContext context, AntDomProject antProject) {
|
||||
return antProject.getProjectBasedirPath();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getAttributeDefaultValue(ConvertContext context, GenericAttributeValue attribValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(@Nullable PsiFileSystemItem file, ConvertContext context) {
|
||||
final GenericAttributeValue attribValue = context.getInvocationElement().getParentOfType(GenericAttributeValue.class, false);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.lang.ant.dom;
|
||||
|
||||
import com.intellij.util.xml.ConvertContext;
|
||||
import com.intellij.util.xml.GenericAttributeValue;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class AntPathRelativeToAntFileConverter extends AntPathConverter {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String getPathResolveRoot(AntDomProject antProject) {
|
||||
protected String getPathResolveRoot(ConvertContext context, AntDomProject antProject) {
|
||||
return antProject.getContainingFileDir();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user