Search in sources :

Example 1 with StrutsFileSet

use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.

the class Struts2ModelInspection method checkFileElement.

/**
   * Only inspect struts.xml files configured in fileset.
   *
   * @param strutsRootDomFileElement Root element of file to inspect.
   * @param holder                   Holder.
   */
public void checkFileElement(final DomFileElement<StrutsRoot> strutsRootDomFileElement, final DomElementAnnotationHolder holder) {
    final Module module = strutsRootDomFileElement.getModule();
    if (module == null) {
        return;
    }
    final XmlFile xmlFile = strutsRootDomFileElement.getFile();
    final VirtualFile virtualFile = xmlFile.getVirtualFile();
    final Set<StrutsFileSet> fileSets = StrutsManager.getInstance(xmlFile.getProject()).getAllConfigFileSets(module);
    for (final StrutsFileSet strutsFileSet : fileSets) {
        if (strutsFileSet.hasFile(virtualFile)) {
            super.checkFileElement(strutsRootDomFileElement, holder);
            break;
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) Module(com.intellij.openapi.module.Module) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet)

Example 2 with StrutsFileSet

use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.

the class BasicLightHighlightingTestCase method createStrutsFileSet.

/**
   * For files located in JAR: {@code [PATH_TO_JAR]!/[PATH_TO_STRUTS_XML]}.
   *
   * @param strutsXmlPaths Paths to files.
   */
protected void createStrutsFileSet(@NonNls final String... strutsXmlPaths) {
    final StrutsFacet strutsFacet = StrutsFacet.getInstance(myModule);
    assertNotNull(strutsFacet);
    final StrutsFacetConfiguration facetConfiguration = strutsFacet.getConfiguration();
    final StrutsFileSet fileSet = new StrutsFileSet("test", "test", facetConfiguration);
    for (final String fileName : strutsXmlPaths) {
        final VirtualFile file;
        final String path;
        if (fileName.contains("!")) {
            path = PathManager.getHomePath() + TEST_DATA_PATH + "/" + fileName;
            file = JarFileSystem.getInstance().refreshAndFindFileByPath(path);
        } else {
            path = fileName;
            file = myFixture.copyFileToProject(fileName);
        }
        assertNotNull("could not find file: '" + path + "'", file);
        fileSet.addFile(file);
    }
    final Set<StrutsFileSet> strutsFileSetSet = facetConfiguration.getFileSets();
    strutsFileSetSet.add(fileSet);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StrutsFacetConfiguration(com.intellij.struts2.facet.StrutsFacetConfiguration) StrutsFacet(com.intellij.struts2.facet.StrutsFacet) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet)

Example 3 with StrutsFileSet

use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.

the class StrutsFileSetCheckingAnnotator method annotate.

public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
    if (!(psiElement instanceof XmlFile)) {
        return;
    }
    if (psiElement instanceof JspFile) {
        return;
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
    if (module == null) {
        return;
    }
    // do not run when facet not enabled
    if (StrutsFacet.getInstance(module) == null) {
        return;
    }
    final XmlFile xmlFile = (XmlFile) psiElement;
    final Project project = psiElement.getProject();
    final StrutsManager strutsManager = StrutsManager.getInstance(project);
    if (!strutsManager.isStruts2ConfigFile(xmlFile)) {
        return;
    }
    final VirtualFile currentVirtualFile = xmlFile.getVirtualFile();
    assert currentVirtualFile != null;
    final Set<StrutsFileSet> allConfigFileSets = strutsManager.getAllConfigFileSets(module);
    for (final StrutsFileSet configFileSet : allConfigFileSets) {
        if (configFileSet.hasFile(currentVirtualFile)) {
            return;
        }
    }
    final boolean fileSetAvailable = allConfigFileSets.size() != 0;
    final Annotation annotation = holder.createWarningAnnotation(xmlFile, fileSetAvailable ? StrutsBundle.message("annotators.fileset.file.not.registered") : StrutsBundle.message("annotators.fileset.no.file.sets"));
    annotation.setFileLevelAnnotation(true);
    if (fileSetAvailable) {
        final AddToFileSetFix addToFileSetFix = new AddToFileSetFix(xmlFile.getName());
        annotation.registerFix(addToFileSetFix);
    } else {
        annotation.registerFix(new IntentionAction() {

            @SuppressWarnings("DialogTitleCapitalization")
            @NotNull
            public String getText() {
                return StrutsBundle.message("annotators.fileset.edit.facet.settings");
            }

            @NotNull
            public String getFamilyName() {
                return StrutsBundle.message("intentions.family.name");
            }

            public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile psiFile) {
                return true;
            }

            public void invoke(@NotNull final Project project, final Editor editor, final PsiFile psiFile) throws IncorrectOperationException {
                final StrutsFacet strutsFacet = StrutsFacet.getInstance(module);
                assert strutsFacet != null;
                ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
            }

            public boolean startInWriteAction() {
                return false;
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NotNull(org.jetbrains.annotations.NotNull) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) JspFile(com.intellij.psi.jsp.JspFile) BaseIntentionAction(com.intellij.codeInsight.intention.impl.BaseIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module) Editor(com.intellij.openapi.editor.Editor) StrutsFacet(com.intellij.struts2.facet.StrutsFacet)

Example 4 with StrutsFileSet

use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.

the class StrutsModelFactory method computeAllModels.

protected List<StrutsModel> computeAllModels(@NotNull final Module module) {
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final StrutsManager strutsManager = StrutsManager.getInstance(module.getProject());
    final Set<StrutsFileSet> fileSets = strutsManager.getAllConfigFileSets(module);
    final List<StrutsModel> models = new ArrayList<>(fileSets.size());
    for (final StrutsFileSet set : fileSets) {
        if (set.isRemoved()) {
            continue;
        }
        final Set<XmlFile> files = new LinkedHashSet<>(set.getFiles().size());
        for (final VirtualFilePointer filePointer : set.getFiles()) {
            if (!filePointer.isValid())
                continue;
            final VirtualFile file = filePointer.getFile();
            if (file == null) {
                continue;
            }
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile) {
                final StrutsRoot strutsRootDom = getDom((XmlFile) psiFile);
                if (strutsRootDom != null) {
                    files.add((XmlFile) psiFile);
                // TODO           addIncludes(files, strutsRootDom);
                }
            }
        }
        if (!files.isEmpty()) {
            final DomFileElement<StrutsRoot> element = createMergedModelRoot(files);
            final StrutsModel model;
            if (element != null) {
                model = new StrutsModelImpl(element, files);
                models.add(model);
            }
        }
    }
    return models;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) PsiFile(com.intellij.psi.PsiFile) StrutsRoot(com.intellij.struts2.dom.struts.StrutsRoot)

Example 5 with StrutsFileSet

use of com.intellij.struts2.facet.ui.StrutsFileSet in project intellij-plugins by JetBrains.

the class StrutsFacetConfiguration method readExternal.

public void readExternal(final Element element) throws InvalidDataException {
    for (final Object setElement : element.getChildren(FILESET)) {
        final String setName = ((Element) setElement).getAttributeValue(SET_NAME);
        final String setId = ((Element) setElement).getAttributeValue(SET_ID);
        final String removed = ((Element) setElement).getAttributeValue(SET_REMOVED);
        if (setName != null && setId != null) {
            final StrutsFileSet fileSet = new StrutsFileSet(setId, setName, this);
            final List files = ((Element) setElement).getChildren(FILE);
            for (final Object fileElement : files) {
                final String text = ((Element) fileElement).getText();
                fileSet.addFile(text);
            }
            fileSet.setRemoved(Boolean.valueOf(removed));
            myFileSets.add(fileSet);
        }
    }
    // new in X
    final Element propertiesElement = element.getChild(PROPERTIES_KEYS);
    if (propertiesElement != null) {
        final String disabled = propertiesElement.getAttributeValue(PROPERTIES_KEYS_DISABLED);
        myPropertiesKeysDisabled = Boolean.valueOf(disabled);
    }
}
Also used : Element(org.jdom.Element) List(java.util.List) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet)

Aggregations

StrutsFileSet (com.intellij.struts2.facet.ui.StrutsFileSet)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 XmlFile (com.intellij.psi.xml.XmlFile)5 Module (com.intellij.openapi.module.Module)4 PsiFile (com.intellij.psi.PsiFile)4 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)2 JspFile (com.intellij.psi.jsp.JspFile)2 StrutsFacet (com.intellij.struts2.facet.StrutsFacet)2 Element (org.jdom.Element)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 BaseIntentionAction (com.intellij.codeInsight.intention.impl.BaseIntentionAction)1 FileTemplate (com.intellij.ide.fileTemplates.FileTemplate)1 Filter (com.intellij.javaee.model.xml.web.Filter)1 FilterMapping (com.intellij.javaee.model.xml.web.FilterMapping)1 WebApp (com.intellij.javaee.model.xml.web.WebApp)1 WebFacet (com.intellij.javaee.web.facet.WebFacet)1 Annotation (com.intellij.lang.annotation.Annotation)1 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Editor (com.intellij.openapi.editor.Editor)1