Search in sources :

Example 21 with IWebProject

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);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 22 with IWebProject

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) FormatProcessorXML(org.eclipse.wst.xml.core.internal.provisional.format.FormatProcessorXML)

Example 23 with IWebProject

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]);
}
Also used : IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) ArrayList(java.util.ArrayList)

Example 24 with IWebProject

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;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) IFolder(org.eclipse.core.resources.IFolder)

Example 25 with IWebProject

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;
        }
    };
}
Also used : ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) IWebProject(com.liferay.ide.core.IWebProject) Viewer(org.eclipse.jface.viewers.Viewer) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IWebProject (com.liferay.ide.core.IWebProject)46 IFolder (org.eclipse.core.resources.IFolder)31 IFile (org.eclipse.core.resources.IFile)27 IProject (org.eclipse.core.resources.IProject)25 IPath (org.eclipse.core.runtime.IPath)24 Path (org.eclipse.core.runtime.Path)20 CoreException (org.eclipse.core.runtime.CoreException)15 IResource (org.eclipse.core.resources.IResource)10 IStatus (org.eclipse.core.runtime.IStatus)6 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 SDK (com.liferay.ide.sdk.core.SDK)4 Path (org.eclipse.sapphire.modeling.Path)4 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)3 InputStream (java.io.InputStream)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 HookDescriptorHelper (com.liferay.ide.hook.core.dd.HookDescriptorHelper)2 Hook (com.liferay.ide.hook.core.model.Hook)2 File (java.io.File)2