Search in sources :

Example 1 with HookDescriptorHelper

use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.

the class AddHookOperation method createLanguageProperties.

protected IStatus createLanguageProperties(IDataModel dm) {
    IProject project = getTargetProject();
    String contentFolderStr = dm.getStringProperty(CONTENT_FOLDER);
    IPath contentFolderPath = new Path(contentFolderStr);
    if (!contentFolderStr.startsWith("/")) {
        IFolder sourceFolder = CoreUtil.getSourceFolders(JavaCore.create(project)).get(0);
        contentFolderPath = sourceFolder.getFullPath().append(contentFolderStr);
    }
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    IFolder contentFolder = root.getFolder(contentFolderPath);
    try {
        CoreUtil.prepareFolder(contentFolder);
    } catch (CoreException ce) {
        return HookCore.createErrorStatus(ce);
    }
    List<String[]> languagePropertiesFiles = (List<String[]>) dm.getProperty(LANGUAGE_PROPERTIES_ITEMS);
    if (languagePropertiesFiles != null) {
        for (String[] languagePropertyFile : languagePropertiesFiles) {
            try {
                if (!languagePropertyFile[0].contains("*")) {
                    IFile createdFile = ProjectUtil.createEmptyProjectFile(languagePropertyFile[0], contentFolder);
                    if (createdFile != null) {
                        Set<IFile> languageFilesCreated = (Set<IFile>) dm.getProperty(LANGUAGE_PROPERTIES_FILES_CREATED);
                        languageFilesCreated.add(createdFile);
                        dm.setProperty(LANGUAGE_PROPERTIES_FILES_CREATED, languageFilesCreated);
                    }
                }
            } catch (Exception e) {
                HookCore.logError(e);
            }
        }
    }
    HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
    Set<IFile> languageFilesCreated = (Set<IFile>) dm.getProperty(LANGUAGE_PROPERTIES_FILES_CREATED);
    // need to get file paths relative to package root
    List<String> languageProperties = new ArrayList<>();
    IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
    if (packRoot != null) {
        for (IFile languageFile : languageFilesCreated) {
            if (packRoot.getPath().isPrefixOf(languageFile.getFullPath())) {
                IPath fullPath = languageFile.getFullPath();
                String languageProperty = fullPath.makeRelativeTo(packRoot.getPath()).toPortableString();
                languageProperties.add(languageProperty);
            }
        }
    }
    IStatus status = hookDescHelper.addLanguageProperties(languageProperties);
    return status;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Set(java.util.Set) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) 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) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) ArrayList(java.util.ArrayList) List(java.util.List) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with HookDescriptorHelper

use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.

the class AddHookOperation method createCustomJSPs.

protected IStatus createCustomJSPs(IDataModel dm) {
    IProject project = getTargetProject();
    IFolder defaultWebappRootFolder = LiferayCore.create(IWebProject.class, project).getDefaultDocrootFolder();
    String customJSPsFolder = dm.getStringProperty(CUSTOM_JSPS_FOLDER);
    IPath fullPath = defaultWebappRootFolder.getFullPath();
    String customFolderValue = fullPath.append(customJSPsFolder).toPortableString();
    IWorkspaceRoot root = project.getWorkspace().getRoot();
    IFolder customFolder = root.getFolder(new Path(customFolderValue));
    try {
        CoreUtil.prepareFolder(customFolder);
    } catch (CoreException ce) {
        return HookCore.createErrorStatus(ce);
    }
    List<String[]> customJsps = (List<String[]>) dm.getProperty(CUSTOM_JSPS_ITEMS);
    ILiferayProject liferayProject = LiferayCore.create(getTargetProject());
    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    IStatus status = null;
    if (portal != null) {
        IPath portalDir = portal.getAppServerPortalDir();
        if ((customJsps != null) && (portalDir != null)) {
            for (String[] customJsp : customJsps) {
                try {
                    IFile copiedFile = copyPortalJSPToProject(portalDir, customJsp[0], customFolder);
                    if (copiedFile != null) {
                        Set<IFile> jspFilesCreated = (Set<IFile>) dm.getProperty(CUSTOM_JSPS_FILES_CREATED);
                        jspFilesCreated.add(copiedFile);
                        dm.setProperty(CUSTOM_JSPS_FILES_CREATED, jspFilesCreated);
                    }
                } catch (Exception e) {
                    HookCore.logError(e);
                }
            }
        }
        HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
        status = hookDescHelper.setCustomJSPDir(model);
        if (model.getBooleanProperty(DISABLE_CUSTOM_JSP_FOLDER_VALIDATION)) {
            HookUtil.configureJSPSyntaxValidationExclude(getTargetProject(), customFolder, true);
        }
    } else {
        status = HookCore.createErrorStatus("Could not get portal info from project " + project.getName());
    }
    return status;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) Set(java.util.Set) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) 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) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) ILiferayProject(com.liferay.ide.core.ILiferayProject) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) ArrayList(java.util.ArrayList) List(java.util.List) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with HookDescriptorHelper

use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.

the class AddHookOperation method createDefaultHookDescriptorFile.

protected void createDefaultHookDescriptorFile(IFile hookDescriptorFile) throws BadLocationException, CoreException, TemplateException, UnsupportedEncodingException {
    HookDescriptorHelper helper = new HookDescriptorHelper(getTargetProject());
    helper.createDefaultDescriptor();
}
Also used : HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper)

Example 4 with HookDescriptorHelper

use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.

the class AddHookOperation method createPortalProperties.

protected IStatus createPortalProperties(IDataModel dm) {
    IProject project = getTargetProject();
    String portalPropertiesFile = dm.getStringProperty(PORTAL_PROPERTIES_FILE);
    // check to see if we have an existing file to read in
    IPath portalPropertiesPath = new Path(portalPropertiesFile);
    if (!portalPropertiesFile.startsWith("/")) {
        IFolder sourceFolder = CoreUtil.getSourceFolders(JavaCore.create(project)).get(0);
        portalPropertiesPath = sourceFolder.getFullPath().append(portalPropertiesFile);
    }
    IPath propertiesFilesPath = portalPropertiesPath.makeRelativeTo(project.getFullPath());
    IFile propertiesFile = project.getFile(propertiesFilesPath);
    Properties properties = new Properties();
    if (FileUtil.exists(propertiesFile)) {
        try {
            properties.load(propertiesFile.getContents());
        } catch (Exception e) {
            return HookCore.createErrorStatus(e);
        }
    }
    List<String[]> actionItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_ACTION_ITEMS);
    if (actionItems != null) {
        for (String[] actionItem : actionItems) {
            properties.put(actionItem[0], actionItem[1]);
        }
    }
    List<String[]> overrideItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_OVERRIDE_ITEMS);
    if (overrideItems != null) {
        for (String[] overrideItem : overrideItems) {
            properties.put(overrideItem[0], overrideItem[1]);
        }
    }
    StringBufferOutputStream buffer = new StringBufferOutputStream();
    try {
        properties.store(buffer, StringPool.EMPTY);
    } catch (IOException ioe) {
        return HookCore.createErrorStatus(ioe);
    }
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(buffer.toString().getBytes("UTF-8"));
        if (propertiesFile.exists()) {
            propertiesFile.setContents(bis, IResource.FORCE, null);
        } else {
            CoreUtil.prepareFolder((IFolder) propertiesFile.getParent());
            propertiesFile.create(bis, true, null);
        }
    } catch (Exception e) {
        return HookCore.createErrorStatus(e);
    }
    HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
    String propertiesClasspath = null;
    IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
    if ((packRoot != null) && packRoot.getPath().isPrefixOf(propertiesFile.getFullPath())) {
        IPath fullPath = propertiesFile.getFullPath();
        propertiesClasspath = fullPath.makeRelativeTo(packRoot.getPath()).toPortableString();
    }
    IStatus status = hookDescHelper.setPortalProperties(model, propertiesClasspath);
    return status;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IOException(java.io.IOException) Properties(java.util.Properties) INewJavaClassDataModelProperties(org.eclipse.jst.j2ee.internal.common.operations.INewJavaClassDataModelProperties) IProject(org.eclipse.core.resources.IProject) 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) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ByteArrayInputStream(java.io.ByteArrayInputStream) StringBufferOutputStream(com.liferay.ide.core.StringBufferOutputStream) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) ArrayList(java.util.ArrayList) List(java.util.List) IFolder(org.eclipse.core.resources.IFolder)

Example 5 with HookDescriptorHelper

use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.

the class NewHookDataModelProvider method getDefaultProperty.

@Override
public Object getDefaultProperty(String propertyName) {
    if (CUSTOM_JSPS_FOLDER.equals(propertyName)) {
        // check to see if there is an existing hook descriptor and read
        // custom_jsps out of that
        IProject targetProject = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
        if (webproject != null) {
            IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
            String defaultWebappRootPath = defaultWebappRootFolder.getFullPath().toPortableString();
            if (targetProject != null) {
                HookDescriptorHelper hookDescriptorHelper = new HookDescriptorHelper(targetProject);
                String customJspFolder = hookDescriptorHelper.getCustomJSPFolder(getDataModel());
                if (customJspFolder != null) {
                    // folder should be relative to the web app folder root
                    // IDE-110 IDE-648
                    IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                    if (defaultDocroot != null) {
                        IPath defaultDocrootPath = defaultDocroot.getFullPath();
                        String containerFullPath = defaultDocrootPath.append(customJspFolder).toPortableString();
                        int index = containerFullPath.indexOf(defaultWebappRootPath);
                        if (index != -1) {
                            int beginIndex = index + defaultWebappRootPath.length();
                            containerFullPath = containerFullPath.substring(beginIndex);
                        }
                        return containerFullPath;
                    }
                }
                if (defaultWebappRootFolder != null) {
                    return "/META-INF/custom_jsps";
                }
            }
        }
    } else if (PORTAL_PROPERTIES_FILE.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if ((targetProject != null) && ListUtil.isNotEmpty(sources)) {
            IPath sourcePath = sources.get(0).getFullPath();
            return sourcePath.append("portal.properties").toPortableString();
        }
    } else if (CONTENT_FOLDER.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if ((targetProject != null) && !sources.isEmpty()) {
            IPath sourcePath = sources.get(0).getFullPath();
            return sourcePath.append("content").toPortableString();
        }
    } else if (SELECTED_PROJECT.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        if (targetProject != null) {
            return targetProject.getName();
        }
    } else if (WEB_ROOT_FOLDER.equals(propertyName)) {
        IProject targetProject = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
        if ((targetProject != null) && (webproject != null)) {
            return webproject.getDefaultDocrootFolder().getName();
        }
    } else if (propertyName.equals(PROJECT)) {
        return getTargetProject();
    } else if (propertyName.equals(SOURCE_FOLDER)) {
        IFolder sourceFolder = getDefaultJavaSourceFolder();
        if (FileUtil.exists(sourceFolder)) {
            return sourceFolder.getFullPath().toPortableString();
        }
    } else if (propertyName.equals(JAVA_SOURCE_FOLDER)) {
        return getJavaSourceFolder();
    } else if (propertyName.equals(JAVA_PACKAGE_FRAGMENT_ROOT)) {
        return getJavaPackageFragmentRoot();
    } else if (CUSTOM_JSPS_FILES_CREATED.equals(propertyName)) {
        return new HashSet<>();
    } else if (LANGUAGE_PROPERTIES_FILES_CREATED.equals(propertyName)) {
        return new HashSet<>();
    } else if (DISABLE_CUSTOM_JSP_FOLDER_VALIDATION.equals(propertyName)) {
        return true;
    }
    return super.getDefaultProperty(propertyName);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) List(java.util.List) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder) HashSet(java.util.HashSet)

Aggregations

HookDescriptorHelper (com.liferay.ide.hook.core.dd.HookDescriptorHelper)8 IFolder (org.eclipse.core.resources.IFolder)6 IPath (org.eclipse.core.runtime.IPath)6 List (java.util.List)5 IProject (org.eclipse.core.resources.IProject)5 ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 CoreException (org.eclipse.core.runtime.CoreException)4 IStatus (org.eclipse.core.runtime.IStatus)4 IWebProject (com.liferay.ide.core.IWebProject)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 ExecutionException (org.eclipse.core.commands.ExecutionException)3 Path (org.eclipse.core.runtime.Path)3 BadLocationException (org.eclipse.jface.text.BadLocationException)3 TemplateException (org.eclipse.jface.text.templates.TemplateException)3 Set (java.util.Set)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)1