Search in sources :

Example 31 with ILiferayProject

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

the class PortalFilterNamesPossibleValuesService method compute.

@Override
protected void compute(Set<String> values) {
    if (_servletFilterNames == null) {
        Element element = context().find(Element.class);
        IFile hookFile = element.adapt(IFile.class);
        if (hookFile != null) {
            try {
                ILiferayProject liferayProject = LiferayCore.create(hookFile.getProject());
                if (liferayProject != null) {
                    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
                    if (portal != null) {
                        IPath appServerPortalDir = portal.getAppServerPortalDir();
                        if (appServerPortalDir != null) {
                            _servletFilterNames = ServerUtil.getServletFilterNames(appServerPortalDir);
                        }
                    }
                }
            } catch (Exception e) {
            }
        }
    }
    if (_servletFilterNames != null) {
        Collections.addAll(values, _servletFilterNames);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) Element(org.eclipse.sapphire.Element) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 32 with ILiferayProject

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

the class CustomJspPossibleValuesService method compute.

@Override
protected void compute(final Set<String> values) {
    if (_possibleValues == null) {
        IProject project = project();
        ILiferayProject liferayProject = LiferayCore.create(project);
        if (liferayProject != null) {
            ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
            if (portal != null) {
                _portalDir = new Path(portal.getAppServerPortalDir().toPortableString());
                if (_portalDir != null) {
                    File portalDirFile = _portalDir.toFile();
                    File htmlDirFile = new File(portalDirFile, "html");
                    List<File> fileValues = new LinkedList<>();
                    if (FileUtil.exists(htmlDirFile)) {
                        _findJSPFiles(new File[] { htmlDirFile }, fileValues);
                    } else {
                        File[] files = portalDirFile.listFiles(_jspfilter);
                        _findJSPFiles(files, fileValues);
                    }
                    _possibleValues = fileValues.toArray(new File[0]);
                }
            }
        }
    }
    if (_possibleValues != null) {
        for (File file : _possibleValues) {
            values.add(new Path(file.getAbsolutePath()).makeRelativeTo(_portalDir).toPortableString());
        }
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList)

Example 33 with ILiferayProject

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

the class BuildLanguageJob method runBuildLang.

protected void runBuildLang(IProgressMonitor monitor) throws CoreException {
    ILiferayProject liferayProject = LiferayCore.create(_getProject());
    if (liferayProject == null) {
        throw new CoreException(PortletCore.createErrorStatus(NLS.bind(Msgs.couldNotCreateLiferayProject, _getProject())));
    }
    IProjectBuilder builder = liferayProject.adapt(IProjectBuilder.class);
    if (builder == null) {
        throw new CoreException(PortletCore.createErrorStatus(NLS.bind(Msgs.couldNotCreateProjectBuilder, _getProject())));
    }
    monitor.worked(50);
    IStatus retval = builder.buildLang(langFile, monitor);
    if (retval == null) {
        retval = PortletCore.createErrorStatus(NLS.bind(Msgs.errorRunningBuildLang, _getProject()));
    }
    try {
        _getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (Exception e) {
        PortletCore.logError(e);
    }
    _getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
    try {
        _getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (Exception e) {
        PortletCore.logError(e);
    }
    if ((retval == null) || !retval.isOK()) {
        throw new CoreException(retval);
    }
    monitor.worked(90);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ILiferayProject(com.liferay.ide.core.ILiferayProject) IProjectBuilder(com.liferay.ide.project.core.IProjectBuilder) CoreException(org.eclipse.core.runtime.CoreException)

Example 34 with ILiferayProject

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

the class NewPortletClassDataModelProvider method getEntryCategories.

protected Properties getEntryCategories() {
    // removed if not null return directly, because it won't update when switch
    // projects of different portal versions
    ILiferayProject liferayProject = LiferayCore.create(getProject());
    if (liferayProject == null) {
        try {
            liferayProject = LiferayCore.create(getRuntime());
        } catch (CoreException ce) {
            PortletCore.logError(ce);
        }
    }
    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    if (portal != null) {
        return portal.getPortletEntryCategories();
    } else {
        return null;
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 35 with ILiferayProject

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

the class NewPortletClassDataModelProvider method getDefaultProperty.

@Override
public Object getDefaultProperty(String propertyName) {
    if (SUPERCLASS.equals(propertyName)) {
        return QUALIFIED_MVC_PORTLET;
    } else if (CONSTRUCTOR.equals(propertyName)) {
        return false;
    } else if (INIT_OVERRIDE.equals(propertyName) || DOVIEW_OVERRIDE.equals(propertyName)) {
        return true;
    } else if (DESTROY_OVERRIDE.equals(propertyName)) {
        return false;
    } else if (JAVA_PACKAGE.equals(propertyName)) {
        return "com.test";
    } else if (CLASS_NAME.equals(propertyName)) {
        return "NewPortlet";
    } else if (PORTLET_NAME.equals(propertyName) || LIFERAY_PORTLET_NAME.equals(propertyName)) {
        return getPortletNameFromClassName(getStringProperty(CLASS_NAME));
    } else if (DISPLAY_NAME.equals(propertyName) || TITLE.equals(propertyName) || SHORT_TITLE.equals(propertyName)) {
        return _getDisplayNameFromPortletName(getStringProperty(PORTLET_NAME));
    } else if (KEYWORDS.equals(propertyName)) {
        return StringPool.EMPTY;
    } else if (INIT_PARAMS.equals(propertyName)) {
        return getInitParams();
    } else if (VIEW_MODE.equals(propertyName)) {
        return true;
    } else if (CREATE_JSPS.equals(propertyName)) {
        return true;
    } else if (CREATE_JSPS_FOLDER.equals(propertyName)) {
        if (getBooleanProperty(CREATE_NEW_PORTLET_CLASS)) {
            String tempStr = getProperty(CLASS_NAME).toString();
            String property = tempStr.toLowerCase();
            return "/html/" + property.replaceAll(_PORTLET_SUFFIX_PATTERN, "");
        } else {
            String tempStr = getProperty(PORTLET_NAME).toString();
            String property = tempStr.toLowerCase();
            return "/html/" + property.replaceAll(_PORTLET_SUFFIX_PATTERN, "");
        }
    } else if (ICON_FILE.equals(propertyName)) {
        return "/icon.png";
    } else if (CREATE_RESOURCE_BUNDLE_FILE.equals(propertyName)) {
        return false;
    } else if (CREATE_RESOURCE_BUNDLE_FILE_PATH.equals(propertyName)) {
        return "content/Language.properties";
    } else if (ALLOW_MULTIPLE.equals(propertyName)) {
        return false;
    } else if (CSS_FILE.equals(propertyName)) {
        return "/css/main.css";
    } else if (JAVASCRIPT_FILE.equals(propertyName)) {
        return "/js/main.js";
    } else if (CSS_CLASS_WRAPPER.equals(propertyName)) {
        String property = getProperty(PORTLET_NAME).toString();
        return property.toLowerCase() + "-portlet";
    } else if (ID.equals(propertyName)) {
        return getProperty(PORTLET_NAME);
    } else if (CATEGORY.equals(propertyName)) {
        return "category.sample";
    } else if (ENTRY_CATEGORY.equals(propertyName)) {
        return "category.my";
    } else if (ENTRY_WEIGHT.equals(propertyName)) {
        return "1.5";
    } else if (ENTRY_CLASS_NAME.equals(propertyName)) {
        return getStringProperty(CLASS_NAME) + "ControlPanelEntry";
    } else if (SHOW_NEW_CLASS_OPTION.equals(propertyName)) {
        return true;
    } else if (CREATE_NEW_PORTLET_CLASS.equals(propertyName)) {
        return true;
    } else if (USE_DEFAULT_PORTLET_CLASS.equals(propertyName)) {
        return false;
    } else if (QUALIFIED_CLASS_NAME.equals(propertyName)) {
        if (getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
            return QUALIFIED_MVC_PORTLET;
        }
    } else if (PROJECT_NAME.equals(propertyName) && (initialProject != null)) {
        return initialProject.getName();
    } else if (INIT_PARAMETER_NAME.equals(propertyName)) {
        String initParameterName = "template";
        ILiferayProject liferayProject = LiferayCore.create(getProject());
        ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
        if (portal != null) {
            String version = portal.getVersion();
            if (version != null) {
                Version portalVersion = Version.parseVersion(version);
                if (CoreUtil.compareVersions(portalVersion, ILiferayConstants.V610) < 0) {
                    initParameterName = "jsp";
                }
                return initParameterName;
            }
        }
    }
    return super.getDefaultProperty(propertyName);
}
Also used : Version(org.osgi.framework.Version) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Aggregations

ILiferayProject (com.liferay.ide.core.ILiferayProject)45 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)29 IProject (org.eclipse.core.resources.IProject)21 IPath (org.eclipse.core.runtime.IPath)18 IFile (org.eclipse.core.resources.IFile)17 CoreException (org.eclipse.core.runtime.CoreException)15 ArrayList (java.util.ArrayList)9 IFolder (org.eclipse.core.resources.IFolder)8 Version (org.osgi.framework.Version)8 IOException (java.io.IOException)7 File (java.io.File)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 IProjectBuilder (com.liferay.ide.project.core.IProjectBuilder)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IStatus (org.eclipse.core.runtime.IStatus)4 Path (org.eclipse.core.runtime.Path)4 IWebProject (com.liferay.ide.core.IWebProject)3 Hook (com.liferay.ide.hook.core.model.Hook)3 IMavenProjectFacade (org.eclipse.m2e.core.project.IMavenProjectFacade)3