From d9f09480a4494cf91cc8bc2cc9dceb461fadbe21 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 3 Aug 2010 16:14:33 +0400 Subject: [PATCH] "ant" task support --- .../lang/ant/dom/AntBooleanConverter.java | 53 ++++++++++++++++++ .../dom/AntBooleanConverterDefaultFalse.java | 27 +++++++++ .../dom/AntBooleanConverterDefaultTrue.java | 27 +++++++++ .../com/intellij/lang/ant/dom/AntDomAnt.java | 55 +++++++++++++++++++ .../intellij/lang/ant/dom/AntDomExtender.java | 1 + .../lang/ant/dom/AntDomFileReferenceSet.java | 26 ++++++--- 6 files changed, 181 insertions(+), 8 deletions(-) create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverter.java create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultFalse.java create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultTrue.java create mode 100644 plugins/ant/src/com/intellij/lang/ant/dom/AntDomAnt.java diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverter.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverter.java new file mode 100644 index 000000000000..b502973ae793 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverter.java @@ -0,0 +1,53 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.dom; + +import com.intellij.util.xml.ConvertContext; +import com.intellij.util.xml.Converter; +import com.intellij.util.xml.GenericAttributeValue; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.Nullable; + +/** + * @author Eugene Zhuravlev + * Date: Aug 3, 2010 + */ +public class AntBooleanConverter extends Converter { + public final Boolean DEFAULT_VALUE; + + public AntBooleanConverter() { + DEFAULT_VALUE = null; + } + + public AntBooleanConverter(boolean defaultValue) { + DEFAULT_VALUE = Boolean.valueOf(defaultValue); + } + + public Boolean fromString(@Nullable @NonNls String s, ConvertContext context) { + if (s == null || s.length() == 0) { + return DEFAULT_VALUE; + } + return "true".equalsIgnoreCase(s) || "true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s); + } + + public String toString(@Nullable Boolean aBoolean, ConvertContext context) { + final GenericAttributeValue attribValue = context.getInvocationElement().getParentOfType(GenericAttributeValue.class, false); + if (attribValue == null) { + return null; + } + return attribValue.getRawText(); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultFalse.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultFalse.java new file mode 100644 index 000000000000..8c48503851a6 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultFalse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.dom; + +/** + * @author Eugene Zhuravlev + * Date: Aug 3, 2010 + */ +public class AntBooleanConverterDefaultFalse extends AntBooleanConverter { + + public AntBooleanConverterDefaultFalse() { + super(false); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultTrue.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultTrue.java new file mode 100644 index 000000000000..160fc2561596 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntBooleanConverterDefaultTrue.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.dom; + +/** + * @author Eugene Zhuravlev + * Date: Aug 3, 2010 + */ +public class AntBooleanConverterDefaultTrue extends AntBooleanConverter { + + public AntBooleanConverterDefaultTrue() { + super(true); + } +} diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAnt.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAnt.java new file mode 100644 index 000000000000..472935f230a6 --- /dev/null +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomAnt.java @@ -0,0 +1,55 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.lang.ant.dom; + +import com.intellij.psi.PsiFileSystemItem; +import com.intellij.util.xml.Attribute; +import com.intellij.util.xml.Convert; +import com.intellij.util.xml.GenericAttributeValue; + +/** + * @author Eugene Zhuravlev + * Date: Aug 3, 2010 + */ +public abstract class AntDomAnt extends AntDomElement { + + @Attribute("antfile") + @Convert(value = AntPathConverter.class) + public abstract GenericAttributeValue getAntFilePath(); + + @Attribute("dir") + @Convert(value = AntPathConverter.class) + public abstract GenericAttributeValue getAntFileDir(); + + @Attribute("target") + public abstract GenericAttributeValue getDefaultTarget(); + + @Attribute("output") + @Convert(value = AntPathConverter.class) + public abstract GenericAttributeValue getOutputtFileName(); + + @Attribute("inheritAll") + @Convert(value = AntBooleanConverterDefaultTrue.class) + public abstract GenericAttributeValue isInheritAllProperties(); + + @Attribute("inheritRefs") + @Convert(value = AntBooleanConverterDefaultFalse.class) + public abstract GenericAttributeValue isInheritRefsProperties(); + + @Attribute("useNativeBasedir") + @Convert(value = AntBooleanConverterDefaultFalse.class) + public abstract GenericAttributeValue isUseNativeBasedir(); +} diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java index 7b1cf46911ba..bf3464d7f415 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java @@ -51,6 +51,7 @@ public class AntDomExtender extends DomExtender{ TAG_MAPPING.put("macrodef", AntDomMacroDef.class); TAG_MAPPING.put("scriptdef", AntDomScriptDef.class); TAG_MAPPING.put("antlib", AntDomAntlib.class); + TAG_MAPPING.put("ant", AntDomAnt.class); } public void registerExtensions(@NotNull AntDomElement antDomElement, @NotNull DomExtensionsRegistrar registrar) { diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java index fe9edce90f21..e9c0f9bc7e88 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomFileReferenceSet.java @@ -93,7 +93,7 @@ public class AntDomFileReferenceSet extends FileReferenceSet { } return FileUtil.isAbsolute(pathString); } - // todo: correct context for "output" attribute file reference of the "ant" task + @NotNull public Collection computeDefaultContexts() { final AntDomElement element = myValue.getParentOfType(AntDomElement.class, false); @@ -109,15 +109,25 @@ public class AntDomFileReferenceSet extends FileReferenceSet { } } else { - final String basedir; - if (element instanceof AntDomIncludingDirective) { - basedir = containingProject.getContainingFileDir(); + + if (element instanceof AntDomAnt) { + final PsiFileSystemItem dirValue = ((AntDomAnt)element).getAntFileDir().getValue(); + if (dirValue instanceof PsiDirectory) { + root = dirValue.getVirtualFile(); + } } - else { - basedir = containingProject.getContextAntProject().getProjectBasedirPath(); + + if (root == null) { + final String basedir; + if (element instanceof AntDomIncludingDirective) { + basedir = containingProject.getContainingFileDir(); + } + else { + basedir = containingProject.getContextAntProject().getProjectBasedirPath(); + } + assert basedir != null; + root = LocalFileSystem.getInstance().findFileByPath(basedir); } - assert basedir != null; - root = LocalFileSystem.getInstance().findFileByPath(basedir); } if (root != null) {