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);
}
}
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;
}
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);
}
}));
}
Aggregations