use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class MavenProjectRemoteServerPublisher method processResourceDeltas.
@Override
public void processResourceDeltas(IModuleResourceDelta[] deltas, ZipOutputStream zip, Map<ZipEntry, String> deleteEntries, String deletePrefix, String deltaPrefix, boolean adjustGMTOffset) throws CoreException, IOException {
for (IModuleResourceDelta delta : deltas) {
IResource deltaResource = (IResource) delta.getModuleResource().getAdapter(IResource.class);
IProject deltaProject = deltaResource.getProject();
IWebProject lrproject = LiferayCore.create(IWebProject.class, deltaProject);
if ((lrproject == null) || (lrproject.getDefaultDocrootFolder() == null)) {
continue;
}
IFolder webappRoot = lrproject.getDefaultDocrootFolder();
int deltaKind = delta.getKind();
IPath deltaFullPath = deltaResource.getFullPath();
boolean deltaZip = false;
IPath deltaPath = null;
if (FileUtil.exists(webappRoot)) {
IPath containerFullPath = webappRoot.getFullPath();
if (containerFullPath.isPrefixOf(deltaFullPath)) {
deltaZip = true;
deltaPath = new Path(deltaPrefix + deltaFullPath.makeRelativeTo(containerFullPath));
}
}
if ((deltaZip == false) && new Path("WEB-INF").isPrefixOf(delta.getModuleRelativePath())) {
List<IFolder> folders = CoreUtil.getSourceFolders(JavaCore.create(deltaProject));
for (IFolder folder : folders) {
IPath folderPath = folder.getFullPath();
if (folderPath.isPrefixOf(deltaFullPath)) {
deltaZip = true;
break;
}
}
}
if ((deltaZip == false) && ((deltaKind == IModuleResourceDelta.ADDED) || (deltaKind == IModuleResourceDelta.CHANGED) || (deltaKind == IModuleResourceDelta.REMOVED))) {
IPath targetPath = JavaCore.create(deltaProject).getOutputLocation();
deltaZip = true;
deltaPath = new Path("WEB-INF/classes").append(deltaFullPath.makeRelativeTo(targetPath));
}
if (deltaZip) {
if ((deltaKind == IModuleResourceDelta.ADDED) || (deltaKind == IModuleResourceDelta.CHANGED)) {
addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
} else if (deltaKind == IModuleResourceDelta.REMOVED) {
addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
} else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
IModuleResourceDelta[] children = delta.getAffectedChildren();
processResourceDeltas(children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
}
}
}
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class HookDescriptorHelper method doSetCustomJSPDir.
public IStatus doSetCustomJSPDir(IDOMDocument document, IDataModel model) {
// <hook> element
Element rootElement = document.getDocumentElement();
String customJSPsFolder = model.getStringProperty(CUSTOM_JSPS_FOLDER);
IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
if (lrproject != null) {
IPath defaultWebappRootFolderFullPath = lrproject.getDefaultDocrootFolder().getFullPath();
String relativeJspFolderPath = ProjectUtil.getRelativePathFromDocroot(lrproject, defaultWebappRootFolderFullPath.append(customJSPsFolder).toPortableString());
Element customJspElement = null;
// check for existing element
NodeList nodeList = rootElement.getElementsByTagName("custom-jsp-dir");
if ((nodeList != null) && (nodeList.getLength() > 0)) {
customJspElement = (Element) nodeList.item(0);
NodeUtil.removeChildren(customJspElement);
Node textNode = document.createTextNode(relativeJspFolderPath);
customJspElement.appendChild(textNode);
} else {
// need to insert customJspElement before any <service>
NodeList serviceTags = rootElement.getElementsByTagName("service");
if ((serviceTags != null) && (serviceTags.getLength() > 0)) {
customJspElement = NodeUtil.insertChildElement(rootElement, serviceTags.item(0), "custom-jsp-dir", relativeJspFolderPath);
} else {
customJspElement = NodeUtil.appendChildElement(rootElement, "custom-jsp-dir", relativeJspFolderPath);
// append a newline text node
rootElement.appendChild(document.createTextNode(System.getProperty("line.separator")));
}
}
// format the new node added to the model;
FormatProcessorXML processor = new FormatProcessorXML();
processor.formatNode(customJspElement);
}
return Status.OK_STATUS;
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class PropertiesUtil method getAllLanguagePropertiesFiles.
/**
* Get all the language properties files referenced from portlet.xml and liferay-hook.xml
*/
public static IFile[] getAllLanguagePropertiesFiles(IProject project) {
List<IFile> retval = new ArrayList<>();
if (!CoreUtil.isLiferayProject(project)) {
project = CoreUtil.getLiferayProject(project);
}
IWebProject webProject = LiferayCore.create(IWebProject.class, project);
if (webProject == null) {
return new IFile[0];
}
IFile[] resourceFiles = getLanguagePropertiesFromPortletXml(webProject.getDescriptorFile(ILiferayConstants.PORTLET_XML_FILE));
IFile[] languageFiles = getLanguagePropertiesFromLiferayHookXml(webProject.getDescriptorFile(ILiferayConstants.LIFERAY_HOOK_XML_FILE));
if (ListUtil.isNotEmpty(resourceFiles)) {
Collections.addAll(retval, resourceFiles);
}
if (ListUtil.isNotEmpty(languageFiles)) {
Collections.addAll(retval, languageFiles);
}
return retval.toArray(new IFile[0]);
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class PropertiesUtil method isLanguagePropertiesFile.
/**
* Check if the file is a language properties file referenced from portlet.xml or liferay-hook.xml
*/
public static boolean isLanguagePropertiesFile(IFile targetFile) {
if (!targetFile.getName().endsWith(PROPERTIES_FILE_SUFFIX)) {
return false;
}
IProject project = CoreUtil.getLiferayProject(targetFile);
if (project == null) {
return false;
}
IWebProject webProject = LiferayCore.create(IWebProject.class, project);
if (webProject == null) {
return false;
}
IFile portletXml = webProject.getDescriptorFile(ILiferayConstants.PORTLET_XML_FILE);
IFile liferayHookXml = webProject.getDescriptorFile(ILiferayConstants.LIFERAY_HOOK_XML_FILE);
IFolder[] srcFolders = webProject.getSourceFolders();
IPath targetFileLocation = targetFile.getLocation();
try {
if (FileUtil.exists(portletXml)) {
String[] resourceBundleValues = _getResourceNodeInfo(portletXml).getResourceBundlePatterns();
for (String resourceBundleValue : resourceBundleValues) {
for (IFolder srcFolder : srcFolders) {
String location = targetFileLocation.makeRelativeTo(srcFolder.getLocation()).toString();
if (location.replace(PROPERTIES_FILE_SUFFIX, "").matches(resourceBundleValue)) {
return true;
}
}
}
String[] supportedLocaleValues = _getResourceNodeInfo(portletXml).getSupportedLocalePatterns();
for (String suportedLocaleValue : supportedLocaleValues) {
for (IFolder srcFolder : srcFolders) {
String location = targetFileLocation.makeRelativeTo(srcFolder.getLocation()).toString();
if (location.replace(PROPERTIES_FILE_SUFFIX, "").matches(suportedLocaleValue)) {
return true;
}
}
}
}
if (FileUtil.exists(liferayHookXml)) {
String[] languagePropertyValues = _getLanguageFileInfo(liferayHookXml).getLanguagePropertyPatterns();
for (String languagePropertyValue : languagePropertyValues) {
for (IFolder srcFolder : srcFolders) {
String location = targetFileLocation.makeRelativeTo(srcFolder.getLocation()).toString();
if (location.replace(PROPERTIES_FILE_SUFFIX, "").matches(languagePropertyValue)) {
return true;
}
}
}
}
} catch (Exception e) {
return false;
}
return false;
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class NewCustomJSPsHookWizardPage method getContainerDialogViewerFilter.
protected ViewerFilter getContainerDialogViewerFilter() {
return new ViewerFilter() {
public boolean select(Viewer viewer, Object parent, Object element) {
if (element instanceof IProject) {
IProject project = (IProject) element;
Object projectName = model.getProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);
return project.getName().equals(projectName);
} else if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
IWebProject webproject = LiferayCore.create(IWebProject.class, folder.getProject());
if (((webproject != null) && webproject.getDefaultDocrootFolder().contains(folder)) || folder.contains(webproject.getDefaultDocrootFolder())) {
return true;
}
}
return false;
}
};
}
Aggregations