use of com.intellij.javaee.web.facet.WebFacet in project intellij-plugins by JetBrains.
the class DispatchPathResultContributor method createReferences.
public boolean createReferences(@NotNull final PsiElement psiElement, @NotNull final List<PsiReference> references, final boolean soft) {
final String packageNamespace = getNamespace(psiElement);
if (packageNamespace == null) {
// XML error
return false;
}
final WebFacet webFacet = WebUtil.getWebFacet(psiElement);
if (webFacet == null) {
// setup error, web-facet must be present in current or dependent module
return false;
}
final FileReferenceSet fileReferenceSet = FileReferenceSet.createSet(psiElement, soft, false, true);
FileReferenceSetHelper.addWebDirectoryAndCurrentNamespaceAsRoots(psiElement, packageNamespace, webFacet, fileReferenceSet);
fileReferenceSet.setEmptyPathAllowed(false);
Collections.addAll(references, fileReferenceSet.getAllReferences());
return false;
}
use of com.intellij.javaee.web.facet.WebFacet in project intellij-plugins by JetBrains.
the class Struts2TilesModelProvider method computeModels.
@NotNull
public Collection<TilesModel> computeModels(@NotNull final Module module) {
final Project project = module.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
// struts2-tiles plugin must be available
final PsiClass strutsTilesListenerClass = facade.findClass(STRUTS_TILES_LISTENER_CLASS, moduleScope);
if (strutsTilesListenerClass == null) {
return Collections.emptyList();
}
final PsiClass tilesListenerClass = facade.findClass(TilesConstants.TILES_LISTENER, moduleScope);
final StrutsPluginDomFactory<TilesDefinitions, TilesModel> factory = StrutsProjectComponent.getInstance(project).getTilesFactory();
final Set<TilesModel> struts2TilesModels = new HashSet<>();
final Consumer<Set<XmlFile>> consumer = definitions -> {
final DomFileElement<TilesDefinitions> domFileElement = factory.createMergedModelRoot(definitions);
if (domFileElement != null) {
struts2TilesModels.add(new TilesModelImpl(definitions, domFileElement, STRUTS2_TILES_MODEL));
}
};
final WebDirectoryUtil webDirectoryUtil = WebDirectoryUtil.getWebDirectoryUtil(project);
final Collection<WebFacet> webFacets = WebFacet.getInstances(module);
for (final WebFacet webFacet : webFacets) {
final WebApp webApp = webFacet.getRoot();
if (webApp == null) {
continue;
}
// determine configured tiles config files
@NonNls final Set<String> tilesConfigNames = findConfiguredTilesPaths(webApp);
// no configured paths? use default
if (tilesConfigNames.isEmpty()) {
tilesConfigNames.add(DEFAULT_TILES_XML);
}
// resolve to XmlFile
final Set<XmlFile> tilesFileSet = new HashSet<>();
for (final String tilesPath : tilesConfigNames) {
final PsiElement tilesXmlFile = webDirectoryUtil.findFileByPath(tilesPath, webFacet);
if (tilesXmlFile instanceof XmlFile) {
tilesFileSet.add((XmlFile) tilesXmlFile);
}
}
final List<Listener> listenerList = webApp.getListeners();
for (final Listener listener : listenerList) {
final PsiClass listenerClass = listener.getListenerClass().getValue();
if (strutsTilesListenerClass.equals(listenerClass) || Comparing.equal(tilesListenerClass, listenerClass)) {
consumer.consume(tilesFileSet);
}
}
}
return struts2TilesModels;
}
use of com.intellij.javaee.web.facet.WebFacet in project intellij-plugins by JetBrains.
the class Struts2ProjectDescriptorBuilder method configureModule.
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
super.configureModule(module, model, contentEntry);
if (addStrutsLibrary) {
BasicLightHighlightingTestCase.addStrutsJars(module, model);
}
if (addJ2eeLibrary) {
PsiTestUtil.addLibrary(module, model, "JavaEE", PathManager.getHomePath() + "/lib/", "javaee.jar", "javase-javax.jar");
}
for (LibraryDefinition library : libraries) {
BasicLightHighlightingTestCase.addLibrary(module, model, library.groupId, library.artifactIds);
}
final WebFacet webFacet = FacetUtil.addFacet(module, WebFacetType.getInstance());
if (addStrutsFacet) {
FacetManager.getInstance(module).addFacet(StrutsFacetType.getInstance(), "struts2", webFacet);
}
if (webXmlUrl != null) {
final VirtualFile root = model.getSourceRoots()[0];
webFacet.addWebRoot(root, "/");
final ConfigFileInfoSet descriptors = webFacet.getDescriptorsContainer().getConfiguration();
descriptors.addConfigFile(DeploymentDescriptorsConstants.WEB_XML_META_DATA, webXmlUrl);
for (String url : ModuleRootManager.getInstance(module).getSourceRootUrls()) {
webFacet.addWebSourceRoot(url);
}
}
for (Callback callback : callbacks) {
callback.configureModule(module, model, contentEntry);
}
}
use of com.intellij.javaee.web.facet.WebFacet in project intellij-plugins by JetBrains.
the class StrutsResultResolvingTest method performSetUp.
@Override
protected void performSetUp() throws Exception {
final WebFacet webFacet = ContainerUtil.getFirstItem(WebFacet.getInstances(myModule));
assert webFacet != null;
webFacet.addWebRoot(VfsUtilCore.pathToUrl(getTestDataPath() + "/jsp"), "/");
webFacet.addWebRoot(VfsUtilCore.pathToUrl(getTestDataPath() + "/jsp2"), "2ndWebRoot");
}
use of com.intellij.javaee.web.facet.WebFacet in project intellij-plugins by JetBrains.
the class StrutsConstantManagerImpl method getStringValue.
/**
* Returns the plain String value for the given constant.
*
* @param context Current context.
* @param strutsModel StrutsModel.
* @param name Name of constant.
* @return {@code null} if no value could be resolved.
*/
@Nullable
private static String getStringValue(@NotNull final PsiFile context, @NotNull final StrutsModel strutsModel, @NotNull @NonNls final String name) {
final Project project = context.getProject();
final Module module = ModuleUtilCore.findModuleForPsiElement(context);
assert module != null : context;
// collect all properties with matching key
final List<IProperty> properties = PropertiesImplUtil.findPropertiesByKey(project, name);
String value = null;
// 1. default.properties from struts2-core.jar
final IProperty strutsDefaultProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && virtualFile.getFileSystem() instanceof JarFileSystem && StringUtil.endsWith(virtualFile.getPath(), STRUTS_DEFAULT_PROPERTIES) && ModuleUtilCore.moduleContainsFile(module, virtualFile, true);
});
if (strutsDefaultProperty != null) {
value = strutsDefaultProperty.getValue();
}
// 2. <constant> from StrutsModel
final Condition<Constant> constantNameCondition = constant -> Comparing.equal(constant.getName().getStringValue(), name);
final List<DomFileElement<StrutsRoot>> domFileElements = new ArrayList<>();
collectStrutsXmls(domFileElements, strutsModel, "struts-default.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts-plugin.xml", true);
collectStrutsXmls(domFileElements, strutsModel, "struts.xml", false);
for (final DomFileElement<StrutsRoot> domFileElement : domFileElements) {
final Constant constant = ContainerUtil.find(domFileElement.getRootElement().getConstants(), constantNameCondition);
final String strutsXmlValue = constant != null ? constant.getValue().getStringValue() : null;
if (strutsXmlValue != null) {
value = strutsXmlValue;
}
}
// 3. struts.properties in current module
final IProperty strutsProperty = ContainerUtil.find(properties, property -> {
final VirtualFile virtualFile = property.getPropertiesFile().getVirtualFile();
return virtualFile != null && Comparing.equal(virtualFile.getName(), STRUTS_PROPERTIES_FILENAME) && ModuleUtilCore.moduleContainsFile(module, virtualFile, false);
});
if (strutsProperty != null) {
value = strutsProperty.getValue();
}
// 4. web.xml
final WebFacet webFacet = WebUtil.getWebFacet(context);
if (webFacet == null) {
// should not happen in real projects..
return value;
}
final WebApp webApp = webFacet.getRoot();
if (webApp == null) {
// no web.xml
return value;
}
final Filter filter = ContainerUtil.find(webApp.getFilters(), WEB_XML_STRUTS_FILTER_CONDITION);
if (filter != null) {
final ParamValue initParam = ContainerUtil.find(filter.getInitParams(), (Condition<ParamValue>) paramValue -> Comparing.equal(paramValue.getParamName().getStringValue(), name));
if (initParam != null) {
value = initParam.getParamValue().getStringValue();
}
}
return value;
}
Aggregations