Search in sources :

Example 1 with ConfigFile

use of com.intellij.util.descriptors.ConfigFile in project intellij-community by JetBrains.

the class DeploymentUtilImpl method checkConfigFile.

public void checkConfigFile(final ConfigFile descriptor, final CompileContext compileContext, final Module module) {
    if (new File(VfsUtil.urlToPath(descriptor.getUrl())).exists()) {
        String message = getConfigFileErrorMessage(descriptor);
        if (message != null) {
            final String moduleDescription = ModuleType.get(module).getName() + " '" + module.getName() + '\'';
            compileContext.addMessage(CompilerMessageCategory.ERROR, CompilerBundle.message("message.text.compiling.module.message", moduleDescription, message), descriptor.getUrl(), -1, -1);
        }
    } else {
        DeploymentUtil.getInstance().reportDeploymentDescriptorDoesNotExists(descriptor, compileContext, module);
    }
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) ConfigFile(com.intellij.util.descriptors.ConfigFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile)

Example 2 with ConfigFile

use of com.intellij.util.descriptors.ConfigFile in project intellij-community by JetBrains.

the class PluginModuleType method getPluginXml.

@Nullable
public static XmlFile getPluginXml(Module module) {
    if (module == null)
        return null;
    if (!isOfType(module)) {
        for (final ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
            for (final SourceFolder folder : entry.getSourceFolders(JavaModuleSourceRootTypes.PRODUCTION)) {
                final VirtualFile file = folder.getFile();
                if (file == null)
                    continue;
                final String packagePrefix = folder.getPackagePrefix();
                final String prefixPath = packagePrefix.isEmpty() ? "" : packagePrefix.replace('.', '/') + '/';
                final String relativePath = prefixPath + PluginDescriptorConstants.PLUGIN_XML_PATH;
                final VirtualFile pluginXmlVF = file.findFileByRelativePath(relativePath);
                if (pluginXmlVF != null) {
                    final PsiFile psiFile = PsiManager.getInstance(module.getProject()).findFile(pluginXmlVF);
                    if (psiFile instanceof XmlFile) {
                        return (XmlFile) psiFile;
                    }
                }
            }
        }
        return null;
    }
    final PluginBuildConfiguration buildConfiguration = PluginBuildConfiguration.getInstance(module);
    if (buildConfiguration == null)
        return null;
    final ConfigFile configFile = buildConfiguration.getPluginXmlConfigFile();
    return configFile != null ? configFile.getXmlFile() : null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SourceFolder(com.intellij.openapi.roots.SourceFolder) XmlFile(com.intellij.psi.xml.XmlFile) ConfigFile(com.intellij.util.descriptors.ConfigFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) PluginBuildConfiguration(org.jetbrains.idea.devkit.build.PluginBuildConfiguration) PsiFile(com.intellij.psi.PsiFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ConfigFile

use of com.intellij.util.descriptors.ConfigFile in project intellij-plugins by JetBrains.

the class StrutsFrameworkSupportProvider method onFacetCreated.

@Override
protected void onFacetCreated(final StrutsFacet strutsFacet, final ModifiableRootModel modifiableRootModel, final FrameworkVersion version) {
    final Module module = strutsFacet.getModule();
    StartupManager.getInstance(module.getProject()).runWhenProjectIsInitialized(() -> DumbService.getInstance(module.getProject()).runWhenSmart(() -> {
        final VirtualFile[] sourceRoots = ModuleRootManager.getInstance(module).getSourceRoots();
        if (sourceRoots.length <= 0) {
            return;
        }
        final PsiDirectory directory = PsiManager.getInstance(module.getProject()).findDirectory(sourceRoots[0]);
        if (directory == null || directory.findFile(StrutsConstants.STRUTS_XML_DEFAULT_FILENAME) != null) {
            return;
        }
        final StrutsFileTemplateProvider templateProvider = new StrutsFileTemplateProvider(module);
        final FileTemplate strutsXmlTemplate = templateProvider.determineFileTemplate(directory.getProject());
        try {
            final StrutsFacetConfiguration strutsFacetConfiguration = strutsFacet.getConfiguration();
            // create empty struts.xml & fileset with all found struts-*.xml files (struts2.jar, plugins)
            final PsiElement psiElement = FileTemplateUtil.createFromTemplate(strutsXmlTemplate, StrutsConstants.STRUTS_XML_DEFAULT_FILENAME, null, directory);
            final Set<StrutsFileSet> empty = Collections.emptySet();
            final StrutsFileSet fileSet = new StrutsFileSet(StrutsFileSet.getUniqueId(empty), StrutsFileSet.getUniqueName("Default File Set", empty), strutsFacetConfiguration);
            fileSet.addFile(((XmlFile) psiElement).getVirtualFile());
            final StrutsConfigsSearcher searcher = new StrutsConfigsSearcher(module);
            DumbService.getInstance(module.getProject()).runWhenSmart(() -> searcher.search());
            final MultiMap<VirtualFile, PsiFile> jarConfigFiles = searcher.getJars();
            for (final VirtualFile virtualFile : jarConfigFiles.keySet()) {
                final Collection<PsiFile> psiFiles = jarConfigFiles.get(virtualFile);
                for (final PsiFile psiFile : psiFiles) {
                    fileSet.addFile(psiFile.getVirtualFile());
                }
            }
            strutsFacetConfiguration.getFileSets().add(fileSet);
            // create filter & mapping in web.xml (if present)
            new WriteCommandAction.Simple(modifiableRootModel.getProject()) {

                protected void run() throws Throwable {
                    final WebFacet webFacet = strutsFacet.getWebFacet();
                    final ConfigFile configFile = webFacet.getWebXmlDescriptor();
                    if (configFile == null)
                        return;
                    final XmlFile webXmlFile = configFile.getXmlFile();
                    final WebApp webApp = JamCommonUtil.getRootElement(webXmlFile, WebApp.class, null);
                    if (webApp == null)
                        return;
                    if (!FileModificationService.getInstance().prepareFileForWrite(webXmlFile))
                        return;
                    final Filter strutsFilter = webApp.addFilter();
                    strutsFilter.getFilterName().setStringValue("struts2");
                    @NonNls final String filterClass = templateProvider.is21orNewer() ? StrutsConstants.STRUTS_2_1_FILTER_CLASS : StrutsConstants.STRUTS_2_0_FILTER_CLASS;
                    strutsFilter.getFilterClass().setStringValue(filterClass);
                    final FilterMapping filterMapping = webApp.addFilterMapping();
                    filterMapping.getFilterName().setValue(strutsFilter);
                    filterMapping.addUrlPattern().setStringValue("/*");
                }
            }.execute();
            final NotificationListener showFacetSettingsListener = new NotificationListener() {

                public void hyperlinkUpdate(@NotNull final Notification notification, @NotNull final HyperlinkEvent event) {
                    if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                        notification.expire();
                        ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
                    }
                }
            };
            Notifications.Bus.notify(new Notification("Struts 2", "Struts 2 Setup", "Struts 2 Facet has been created, please check <a href=\"more\">created fileset</a>", NotificationType.INFORMATION, showFacetSettingsListener), module.getProject());
        } catch (Exception e) {
            LOG.error("error creating struts.xml from template", e);
        }
    }));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) HyperlinkEvent(javax.swing.event.HyperlinkEvent) FileTemplate(com.intellij.ide.fileTemplates.FileTemplate) FilterMapping(com.intellij.javaee.model.xml.web.FilterMapping) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) Notification(com.intellij.notification.Notification) StrutsFileTemplateProvider(com.intellij.struts2.StrutsFileTemplateProvider) MultiMap(com.intellij.util.containers.MultiMap) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) ConfigFile(com.intellij.util.descriptors.ConfigFile) StrutsConfigsSearcher(com.intellij.struts2.facet.ui.StrutsConfigsSearcher) Filter(com.intellij.javaee.model.xml.web.Filter) Collection(java.util.Collection) Module(com.intellij.openapi.module.Module) WebFacet(com.intellij.javaee.web.facet.WebFacet) WebApp(com.intellij.javaee.model.xml.web.WebApp) NotificationListener(com.intellij.notification.NotificationListener)

Aggregations

PsiFile (com.intellij.psi.PsiFile)3 XmlFile (com.intellij.psi.xml.XmlFile)3 ConfigFile (com.intellij.util.descriptors.ConfigFile)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 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 Notification (com.intellij.notification.Notification)1 NotificationListener (com.intellij.notification.NotificationListener)1 Module (com.intellij.openapi.module.Module)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 SourceFolder (com.intellij.openapi.roots.SourceFolder)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 StrutsFileTemplateProvider (com.intellij.struts2.StrutsFileTemplateProvider)1 StrutsConfigsSearcher (com.intellij.struts2.facet.ui.StrutsConfigsSearcher)1 StrutsFileSet (com.intellij.struts2.facet.ui.StrutsFileSet)1 MultiMap (com.intellij.util.containers.MultiMap)1