Search in sources :

Example 11 with ILiferayPortal

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

the class LiferayPropertiesSourceViewerConfiguration method getContentAssistant.

@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
    if (_propKeys == null) {
        IEditorInput input = getEditor().getEditorInput();
        // first fine runtime location to get properties definitions
        IPath appServerPortalDir = _getAppServerPortalDir(input);
        String propertiesEntry = _getPropertiesEntry(input);
        PropKey[] keys = null;
        if ((appServerPortalDir != null) && appServerPortalDir.toFile().exists()) {
            try {
                JarFile jar = new JarFile(appServerPortalDir.append("WEB-INF/lib/portal-impl.jar").toFile());
                ZipEntry lang = jar.getEntry(propertiesEntry);
                keys = _parseKeys(jar.getInputStream(lang));
                jar.close();
            } catch (Exception e) {
                LiferayUIPlugin.logError("Unable to get portal properties file", e);
            }
        } else {
            return _assitant;
        }
        Object adapter = input.getAdapter(IFile.class);
        if (adapter instanceof IFile && _isHookProject(((IFile) adapter).getProject())) {
            ILiferayProject liferayProject = LiferayCore.create(((IFile) adapter).getProject());
            ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
            if (portal != null) {
                Set<String> hookProps = new HashSet<>();
                Collections.addAll(hookProps, portal.getHookSupportedProperties());
                List<PropKey> filtered = new ArrayList<>();
                for (PropKey pk : keys) {
                    if (hookProps.contains(pk.getKey())) {
                        filtered.add(pk);
                    }
                }
                keys = filtered.toArray(new PropKey[0]);
            }
        }
        _propKeys = keys;
    }
    if ((_propKeys != null) && (_assitant == null)) {
        ContentAssistant ca = new ContentAssistant() {

            @Override
            public IContentAssistProcessor getContentAssistProcessor(String contentType) {
                return new LiferayPropertiesContentAssistProcessor(_propKeys, contentType);
            }
        };
        ca.setInformationControlCreator(getInformationControlCreator(sourceViewer));
        _assitant = ca;
    }
    return _assitant;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) IContentAssistant(org.eclipse.jface.text.contentassist.IContentAssistant) ContentAssistant(org.eclipse.jface.text.contentassist.ContentAssistant) IOException(java.io.IOException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) ILiferayProject(com.liferay.ide.core.ILiferayProject) PropKey(com.liferay.ide.ui.editor.LiferayPropertiesContentAssistProcessor.PropKey) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Example 12 with ILiferayPortal

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

the class ServerUtil method getPortalDir.

public static IPath getPortalDir(IProject project) {
    IPath retval = null;
    final ILiferayProject liferayProject = LiferayCore.create(project);
    if (liferayProject != null) {
        final ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
        if (portal != null) {
            retval = portal.getAppServerPortalDir();
        }
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) ILiferayPortal(com.liferay.ide.core.ILiferayPortal)

Example 13 with ILiferayPortal

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

the class VersionsTests method testFindLiferayVersionByProperties.

@Test
public void testFindLiferayVersionByProperties() throws Exception {
    IProject project = importProject("projects/versions/properties-portlet/pom.xml");
    assertNotNull(project);
    IMavenProjectFacade facade = MavenPlugin.getMavenProjectRegistry().create(project, monitor);
    assertNotNull(facade);
    final ILiferayProject lrproject = LiferayCore.create(project);
    assertNotNull(lrproject);
    final ILiferayPortal portal = lrproject.adapt(ILiferayPortal.class);
    assertNotNull(portal);
    assertEquals("6.2.1", portal.getVersion());
}
Also used : ILiferayProject(com.liferay.ide.core.ILiferayProject) IMavenProjectFacade(org.eclipse.m2e.core.project.IMavenProjectFacade) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 14 with ILiferayPortal

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

the class ThemeCSSBuilder method applyDiffsDeltaToDocroot.

protected void applyDiffsDeltaToDocroot(IResourceDelta delta, IContainer docroot, IProgressMonitor monitor) {
    int deltaKind = delta.getKind();
    switch(deltaKind) {
        case IResourceDelta.REMOVED_PHANTOM:
            break;
    }
    IPath path = CoreUtil.getResourceLocation(docroot);
    ILiferayProject liferayProject = LiferayCore.create(getProject());
    String themeParent = liferayProject.getProperty("theme.parent", "_styled");
    ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
    if (portal != null) {
        IPath themesPath = portal.getAppServerPortalDir().append("html/themes");
        List<IPath> restorePaths = new ArrayList<>();
        for (int i = 0; i < IPluginProjectDataModelProperties.THEME_PARENTS.length; i++) {
            if (IPluginProjectDataModelProperties.THEME_PARENTS[i].equals(themeParent)) {
                restorePaths.add(themesPath.append(IPluginProjectDataModelProperties.THEME_PARENTS[i]));
            } else {
                if (ListUtil.isNotEmpty(restorePaths)) {
                    restorePaths.add(themesPath.append(IPluginProjectDataModelProperties.THEME_PARENTS[i]));
                }
            }
        }
        new Job("publish theme delta") {

            @Override
            protected IStatus run(IProgressMonitor monitor) {
                _buildHelper.publishDelta(delta, path, restorePaths.toArray(new IPath[0]), monitor);
                try {
                    docroot.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                } catch (Exception e) {
                    ThemeCore.logError(e);
                }
                return Status.OK_STATUS;
            }
        }.schedule();
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ILiferayProject(com.liferay.ide.core.ILiferayProject) ArrayList(java.util.ArrayList) Job(org.eclipse.core.runtime.jobs.Job) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 15 with ILiferayPortal

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

the class ThemeCSSBuilder method ensureLookAndFeelFileExists.

public static void ensureLookAndFeelFileExists(IProject project) throws CoreException {
    // IDE-110 IDE-648
    IWebProject lrProject = LiferayCore.create(IWebProject.class, project);
    if (lrProject == null) {
        return;
    }
    IFile lookAndFeelFile = null;
    IResource res = lrProject.findDocrootResource(new Path("WEB-INF/" + ILiferayConstants.LIFERAY_LOOK_AND_FEEL_XML_FILE));
    if (res instanceof IFile && res.exists()) {
        lookAndFeelFile = (IFile) res;
    }
    if (lookAndFeelFile == null) {
        // need to generate a new lnf file in deafult docroot
        String id = project.getName().replaceAll(ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX, StringPool.EMPTY);
        IResource propertiesFileRes = lrProject.findDocrootResource(new Path("WEB-INF/" + ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_FILE));
        String name = id;
        if (propertiesFileRes instanceof IFile && propertiesFileRes.exists()) {
            Properties props = new Properties();
            try {
                IFile propsFile = (IFile) propertiesFileRes;
                InputStream contents = propsFile.getContents();
                props.load(contents);
                contents.close();
                String nameValue = props.getProperty("name");
                if (!CoreUtil.isNullOrEmpty(nameValue)) {
                    name = nameValue;
                }
                ThemeDescriptorHelper themeDescriptorHelper = new ThemeDescriptorHelper(project);
                ILiferayProject lProject = lrProject;
                ILiferayPortal portal = lProject.adapt(ILiferayPortal.class);
                String version = "6.2.0";
                if (portal != null) {
                    version = portal.getVersion();
                }
                String themeType = lProject.getProperty("theme.type", "vm");
                themeDescriptorHelper.createDefaultFile(lrProject.getDefaultDocrootFolder().getFolder("WEB-INF"), version, id, name, themeType);
            } catch (IOException ioe) {
                ThemeCore.logError("Unable to load plugin package properties.", ioe);
            }
        }
    }
}
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) InputStream(java.io.InputStream) ILiferayProject(com.liferay.ide.core.ILiferayProject) IOException(java.io.IOException) Properties(java.util.Properties) IPluginProjectDataModelProperties(com.liferay.ide.project.core.facet.IPluginProjectDataModelProperties) ThemeDescriptorHelper(com.liferay.ide.theme.core.operation.ThemeDescriptorHelper) ILiferayPortal(com.liferay.ide.core.ILiferayPortal) IResource(org.eclipse.core.resources.IResource)

Aggregations

ILiferayPortal (com.liferay.ide.core.ILiferayPortal)32 ILiferayProject (com.liferay.ide.core.ILiferayProject)29 IPath (org.eclipse.core.runtime.IPath)13 IFile (org.eclipse.core.resources.IFile)10 IProject (org.eclipse.core.resources.IProject)10 CoreException (org.eclipse.core.runtime.CoreException)8 IOException (java.io.IOException)7 Version (org.osgi.framework.Version)7 ArrayList (java.util.ArrayList)4 IWebProject (com.liferay.ide.core.IWebProject)3 Hook (com.liferay.ide.hook.core.model.Hook)3 File (java.io.File)3 Properties (java.util.Properties)3 JarFile (java.util.jar.JarFile)3 Path (org.eclipse.core.runtime.Path)3 InputStream (java.io.InputStream)2 HashSet (java.util.HashSet)2 ZipEntry (java.util.zip.ZipEntry)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2