Search in sources :

Example 1 with ThemeDescriptorHelper

use of com.liferay.ide.theme.core.operation.ThemeDescriptorHelper 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)1 ILiferayProject (com.liferay.ide.core.ILiferayProject)1 IWebProject (com.liferay.ide.core.IWebProject)1 IPluginProjectDataModelProperties (com.liferay.ide.project.core.facet.IPluginProjectDataModelProperties)1 ThemeDescriptorHelper (com.liferay.ide.theme.core.operation.ThemeDescriptorHelper)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1