Search in sources :

Example 26 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class NewHookDataModelProvider method validate.

@Override
public IStatus validate(String propertyName) {
    boolean is70 = false;
    try {
        SDK sdk = SDKUtil.getWorkspaceSDK();
        if (sdk != null) {
            Version version = new Version(sdk.getVersion());
            Version sdk70 = ILiferayConstants.V700;
            if (CoreUtil.compareVersions(version, sdk70) >= 0) {
                is70 = true;
            }
        }
    } catch (CoreException ce) {
    }
    if (CUSTOM_JSPS_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
        String jspFolder = getStringProperty(CUSTOM_JSPS_FOLDER);
        if (CoreUtil.isNullOrEmpty(jspFolder)) {
            return HookCore.createErrorStatus(Msgs.customJSPsFolderNotConfigured);
        }
        IProject project = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, project);
        if (webproject != null) {
            IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
            IPath defaultWebappRootFolderPath = defaultWebappRootFolder.getFullPath();
            String jspFolderPath = defaultWebappRootFolderPath.append(jspFolder).toPortableString();
            IStatus validateStatus = CoreUtil.getWorkspace().validatePath(jspFolderPath, IResource.FOLDER);
            if (!validateStatus.isOK()) {
                return HookCore.createErrorStatus(validateStatus.getMessage());
            }
        }
    } else if (CUSTOM_JSPS_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
        Object jspItems = getProperty(CUSTOM_JSPS_ITEMS);
        if (jspItems instanceof List) {
            if (((List) jspItems).size() > 0) {
                String[][] jspArrays = ((List<String[]>) jspItems).toArray(new String[0][]);
                for (int i = 0; i < jspArrays.length; i++) {
                    String[] comp1 = jspArrays[i];
                    for (int j = i + 1; j < jspArrays.length; j++) {
                        String[] comp2 = jspArrays[j];
                        if (comp1[0].equals(comp2[0])) {
                            return HookCore.createWarnStatus("Shouldn't add same jsp file.");
                        }
                    }
                }
                return Status.OK_STATUS;
            }
        }
        return HookCore.createErrorStatus(Msgs.specifyOneJSP);
    } else if (PORTAL_PROPERTIES_FILE.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
        String portalPropertiesFile = getStringProperty(PORTAL_PROPERTIES_FILE);
        if (CoreUtil.isNullOrEmpty(portalPropertiesFile)) {
            return HookCore.createErrorStatus(Msgs.portalPropertiesFileNotConfigured);
        }
        IPath portalPropertiesPath = Path.fromPortableString(portalPropertiesFile);
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if (portalPropertiesFile.startsWith("/")) {
            for (IFolder sourceFolder : sources) {
                IPath sourceFolderPath = sourceFolder.getFullPath();
                if (sourceFolderPath.isPrefixOf(portalPropertiesPath)) {
                    return Status.OK_STATUS;
                }
            }
            return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
        } else {
            return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
        }
    } else if (PORTAL_PROPERTIES_ACTION_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
        // if we have valid actions items or property overrides then we
        // don't need an error
        IStatus actionItemsStatus = validateListItems(PORTAL_PROPERTIES_ACTION_ITEMS);
        IStatus propertyOverridesStatus = validateListItems(PORTAL_PROPERTIES_OVERRIDE_ITEMS);
        if (actionItemsStatus.isOK() || propertyOverridesStatus.isOK()) {
            return Status.OK_STATUS;
        } else {
            return HookCore.createErrorStatus(Msgs.specifyOneEventActionProperty);
        }
    } else if (SERVICES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_SERVICES)) {
        IStatus itemsStatus = validateListItems(SERVICES_ITEMS);
        if (itemsStatus.isOK()) {
            return Status.OK_STATUS;
        } else {
            return HookCore.createErrorStatus(Msgs.specifyOneService);
        }
    } else if (CONTENT_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        String contentFolder = getStringProperty(CONTENT_FOLDER);
        if (CoreUtil.isNullOrEmpty(contentFolder)) {
            return HookCore.createErrorStatus(Msgs.contentFolderNotConfigured);
        }
        IPath contentPath = Path.fromPortableString(contentFolder);
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if (contentFolder.startsWith("/")) {
            for (IFolder sourceFolder : sources) {
                IPath sourcePath = sourceFolder.getFullPath();
                if (sourcePath.isPrefixOf(contentPath)) {
                    return Status.OK_STATUS;
                }
            }
            return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
        } else {
            return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
        }
    } else if (LANGUAGE_PROPERTIES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        Object propertiesItems = getProperty(LANGUAGE_PROPERTIES_ITEMS);
        if (propertiesItems instanceof List) {
            List jsps = (List) propertiesItems;
            if (ListUtil.isNotEmpty(jsps)) {
                return Status.OK_STATUS;
            }
        }
        return HookCore.createErrorStatus(Msgs.specifyOneLanguagePropertyFile);
    } else if (is70 && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        return HookCore.createErrorStatus(Msgs.noSupportInSDK70);
    }
    return super.validate(propertyName);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Version(org.osgi.framework.Version) List(java.util.List) SDK(com.liferay.ide.sdk.core.SDK) IFolder(org.eclipse.core.resources.IFolder)

Example 27 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class CreateDirectoryActionHandler method run.

@Override
protected Object run(Presentation context) {
    try {
        Element element = getModelElement();
        IProject project = element.adapt(IProject.class);
        CustomJspDir customJspDir = (CustomJspDir) element;
        Path customJspDirValue = customJspDir.getValue().content(false);
        if (customJspDirValue == null) {
            customJspDirValue = customJspDir.getValue().content(true);
            customJspDir.setValue(customJspDirValue);
        }
        customJspDir.setValue(customJspDirValue);
        RelativePathService service = property().service(RelativePathService.class);
        Path absolutePath = service.convertToAbsolute(customJspDirValue);
        if (FileUtil.notExists(absolutePath)) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFolder customJspFolder = defaultDocroot.getFolder(new org.eclipse.core.runtime.Path(customJspDirValue.toPortableString()));
                CoreUtil.makeFolders(customJspFolder);
                // force a refresh of validation
                customJspDir.setValue((Path) null);
                customJspDir.setValue(customJspDirValue);
                refreshEnablementState();
            }
        }
    } catch (Exception e) {
        HookUI.logError(e);
    }
    return null;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) IWebProject(com.liferay.ide.core.IWebProject) Element(org.eclipse.sapphire.Element) RelativePathService(org.eclipse.sapphire.services.RelativePathService) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 28 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class AddHookOperation method checkDescriptorFile.

protected IStatus checkDescriptorFile(IProject project) {
    IWebProject webproject = LiferayCore.create(IWebProject.class, project);
    if ((webproject == null) || (webproject.getDefaultDocrootFolder() == null)) {
        return HookCore.createErrorStatus("Could not find webapp root folder.");
    }
    IFolder webappRoot = webproject.getDefaultDocrootFolder();
    // IDE-648 IDE-110
    Path path = new Path("WEB-INF/" + ILiferayConstants.LIFERAY_HOOK_XML_FILE);
    IFile hookDescriptorFile = webappRoot.getFile(path);
    if (FileUtil.notExists(hookDescriptorFile)) {
        try {
            createDefaultHookDescriptorFile(hookDescriptorFile);
        } catch (Exception ex) {
            return HookCore.createErrorStatus(ex);
        }
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) CoreException(org.eclipse.core.runtime.CoreException) TemplateException(org.eclipse.jface.text.templates.TemplateException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IFolder(org.eclipse.core.resources.IFolder)

Example 29 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class DocrootRelativePathService method roots.

@Override
public List<Path> roots() {
    List<Path> roots = new ArrayList<>();
    Hook hook = context(Hook.class);
    if (hook != null) {
        IProject project = hook.adapt(IProject.class);
        // IDE-110
        IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
        if (lrproject != null) {
            IFolder defaultDocroot = lrproject.getDefaultDocrootFolder();
            if (FileUtil.exists(defaultDocroot)) {
                roots.add(new Path(defaultDocroot.getLocation().toPortableString()));
            }
        }
    }
    return roots;
}
Also used : Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) IWebProject(com.liferay.ide.core.IWebProject) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 30 with IWebProject

use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.

the class JSFPortletFramework method postProjectCreated.

@Override
public IStatus postProjectCreated(IProject project, String frameworkName, String portletName, IProgressMonitor monitor) {
    /*
		 * we need to copy the original web.xml from the project template
		 * because of bugs in the JSF facet installer will overwrite our web.xml
		 * that comes with in the template
		 */
    super.postProjectCreated(project, frameworkName, portletName, monitor);
    SDK sdk = SDKUtil.getSDK(project);
    if (sdk != null) {
        try {
            // TODO IDE-648
            IPath location = sdk.getLocation().append("tools/portlet_" + frameworkName + "_tmpl/docroot/WEB-INF/web.xml");
            File originalWebXmlFile = location.toFile();
            if (originalWebXmlFile.exists()) {
                final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                if (webproject != null) {
                    IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                    try (InputStream newInputStream = Files.newInputStream(originalWebXmlFile.toPath())) {
                        defaultDocroot.getFile("WEB-INF/web.xml").setContents(newInputStream, IResource.FORCE, null);
                    }
                }
            }
        } catch (Exception e) {
            return PortletCore.createErrorStatus("Could not copy original web.xml from JSF template in SDK.", e);
        }
    }
    try {
        IFolder docroot = CoreUtil.getDefaultDocrootFolder(project);
        IFolder views = docroot.getFolder("views");
        if (views.exists()) {
            views.move(docroot.getFolder("WEB-INF/views").getFullPath(), true, monitor);
            IFile portletXml = docroot.getFile("WEB-INF/portlet.xml");
            File portletXmlFile = portletXml.getLocation().toFile();
            String contents = FileUtil.readContents(portletXmlFile, true);
            if (contents.contains("init-param")) {
                contents = contents.replaceAll("/views/view.xhtml", "/WEB-INF/views/view.xhtml");
                portletXml.setContents(new ByteArrayInputStream(contents.getBytes("UTF-8")), IResource.FORCE, null);
            }
        }
    } catch (Exception e) {
        return PortletCore.createErrorStatus(e);
    }
    return Status.OK_STATUS;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) IWebProject(com.liferay.ide.core.IWebProject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SDK(com.liferay.ide.sdk.core.SDK) IFile(org.eclipse.core.resources.IFile) File(java.io.File) 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