Search in sources :

Example 16 with IWebProject

use of com.liferay.ide.core.IWebProject 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)

Example 17 with IWebProject

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

the class ThemePluginPublisher method addThemeModule.

protected void addThemeModule(ServerBehaviourDelegate delegate, IModule module) throws CoreException {
    IProject project = module.getProject();
    // check to make sure they have a look-and-feel.xml file
    // IDE-110 IDE-648
    IWebProject webproject = LiferayCore.create(IWebProject.class, project);
    if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
        IFolder webappRoot = webproject.getDefaultDocrootFolder();
        if ((webappRoot != null) && webappRoot.exists()) {
            if (!(webappRoot.exists(new Path("WEB-INF/" + ILiferayConstants.LIFERAY_LOOK_AND_FEEL_XML_FILE))) || !(webappRoot.exists(new Path("css")))) {
                ThemeCSSBuilder.compileTheme(project);
                ((ILiferayServerBehavior) delegate).redeployModule(new IModule[] { module });
            }
        } else {
            ThemeCore.logError("Could not add theme module: webappRoot not found");
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) ILiferayServerBehavior(com.liferay.ide.server.core.ILiferayServerBehavior) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 18 with IWebProject

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

the class ThemePluginFacetInstall method execute.

@Override
public void execute(IProject project, IProjectFacetVersion fv, Object config, IProgressMonitor monitor) throws CoreException {
    super.execute(project, fv, config, monitor);
    IDataModel model = (IDataModel) config;
    IDataModel masterModel = (IDataModel) model.getProperty(FacetInstallDataModelProvider.MASTER_PROJECT_DM);
    if ((masterModel != null) && masterModel.getBooleanProperty(CREATE_PROJECT_OPERATION)) {
        /*
			 * // get the template zip for theme and extract into the project
			 * SDK sdk = getSDK(); String themeName =
			 * this.masterModel.getStringProperty( THEME_NAME ); // FIX IDE-450
			 * if( themeName.endsWith( ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX
			 * ) ) { themeName = themeName.substring( 0, themeName.indexOf(
			 * ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX ) ); } // END FIX
			 * IDE-450 String displayName = this.masterModel.getStringProperty(
			 * DISPLAY_NAME ); IPath newThemePath = sdk.createNewThemeProject(
			 * themeName, displayName ); processNewFiles( newThemePath.append(
			 * themeName + ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX ) ); //
			 * cleanup files FileUtil.deleteDir( newThemePath.toFile(), true );
			 */
        // IDE-1122 SDK creating project has been moved to Class
        // NewPluginProjectWizard
        String themeName = this.masterModel.getStringProperty(THEME_NAME);
        IPath projectTempPath = (IPath) masterModel.getProperty(PROJECT_TEMP_PATH);
        processNewFiles(projectTempPath.append(themeName + ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX));
        FileUtil.deleteDir(projectTempPath.toFile(), true);
        // End IDE-1122
        // delete META-INF
        CoreUtil.deleteResource(project.findMember(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/META-INF"));
    } else if (shouldSetupDefaultOutputLocation()) {
        setupDefaultOutputLocation();
    }
    if (shouldConfigureDeploymentAssembly()) {
        // IDE-565
        configureDeploymentAssembly(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER, DEFAULT_DEPLOY_PATH);
    }
    IWebProject lrproject = new PluginsSDKBundleProject(project, null);
    IResource libRes = lrproject.findDocrootResource(new Path("WEB-INF/lib"));
    if (FileUtil.exists(libRes)) {
        IFolder libFolder = (IFolder) libRes;
        IResource[] libFiles = libFolder.members(true);
        if (ListUtil.isEmpty(libFiles)) {
            libRes.delete(true, monitor);
        }
    }
    if (shouldUpdateBuildXml()) {
        updateBuildXml(project);
    }
    if (shouldInstallThemeBuilder()) {
        installThemeBuilder(this.project);
    }
    try {
        this.project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (Exception e) {
        ThemeCore.logError(e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) PluginsSDKBundleProject(com.liferay.ide.project.core.PluginsSDKBundleProject) IWebProject(com.liferay.ide.core.IWebProject) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) IResource(org.eclipse.core.resources.IResource) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) IFolder(org.eclipse.core.resources.IFolder)

Example 19 with IWebProject

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

the class NewLiferayPluginProjectOpBase method testDontIncludeSampleCodeServiceBuilder.

@Test
public void testDontIncludeSampleCodeServiceBuilder() throws Exception {
    if (shouldSkipBundleTests())
        return;
    // test service-builder project
    NewLiferayPluginProjectOp op = newProjectOp("test-dont-include-sample-code-service-builder");
    op.setIncludeSampleCode(false);
    op.setPluginType(PluginType.servicebuilder);
    IProject project = createAntProject(op);
    IWebProject webProject = LiferayCore.create(IWebProject.class, project);
    IFile portletXml = webProject.getDescriptorFile(ILiferayConstants.PORTLET_XML_FILE);
    IFile liferayPortletXml = webProject.getDescriptorFile(ILiferayConstants.LIFERAY_PORTLET_XML_FILE);
    IFile liferayDisplayXml = webProject.getDescriptorFile(ILiferayConstants.LIFERAY_DISPLAY_XML_FILE);
    IFile serviceXml = webProject.getDescriptorFile(ILiferayConstants.SERVICE_XML_FILE);
    assertNotNull(portletXml);
    assertNotNull(liferayPortletXml);
    assertNotNull(liferayDisplayXml);
    assertNotNull(serviceXml);
    assertEquals(0, countElements(portletXml, "portlet"));
    assertEquals(0, countElements(liferayPortletXml, "portlet"));
    assertEquals(0, countElements(liferayDisplayXml, "category"));
    assertEquals(0, countElements(serviceXml, "entity"));
}
Also used : IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 20 with IWebProject

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

the class LiferayMavenProjectConfigurator method configure.

@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.beginTask(NLS.bind(Msgs.configuringLiferayProject, request.getProject()), 100);
    Plugin liferayMavenPlugin = MavenUtil.getPlugin(request.getMavenProjectFacade(), ILiferayMavenConstants.LIFERAY_MAVEN_PLUGIN_KEY, monitor);
    if (!_shouldConfigure(liferayMavenPlugin, request)) {
        monitor.done();
        return;
    }
    IProject project = request.getProject();
    IFile pomFile = project.getFile(IMavenConstants.POM_FILE_NAME);
    IFacetedProject facetedProject = ProjectFacetsManager.create(project, false, monitor);
    _removeLiferayMavenMarkers(project);
    monitor.worked(25);
    MavenProject mavenProject = request.getMavenProject();
    List<MavenProblemInfo> errors = _findLiferayMavenPluginProblems(request, monitor);
    if (ListUtil.isNotEmpty(errors)) {
        try {
            markerManager.addErrorMarkers(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, errors);
        } catch (CoreException ce) {
        // no need to log this error its just best effort
        }
    }
    monitor.worked(25);
    MavenProblemInfo installProblem = null;
    if (_shouldInstallNewLiferayFacet(facetedProject)) {
        installProblem = _installNewLiferayFacet(facetedProject, request, monitor);
    }
    if (_shouldAddLiferayNature(mavenProject, facetedProject)) {
        LiferayNature.addLiferayNature(project, monitor);
    }
    monitor.worked(25);
    if (installProblem != null) {
        this.markerManager.addMarker(pomFile, ILiferayMavenConstants.LIFERAY_MAVEN_MARKER_CONFIGURATION_WARNING_ID, installProblem.getMessage(), installProblem.getLocation().getLineNumber(), IMarker.SEVERITY_WARNING);
    } else {
        String pluginType = MavenUtil.getLiferayMavenPluginType(mavenProject);
        // IDE-817 we need to mak sure that on deployment it will have the correct
        // suffix for project name
        IVirtualComponent projectComponent = ComponentCore.createComponent(project);
        try {
            if (projectComponent != null) {
                String deployedName = projectComponent.getDeployedName();
                Matcher m = _versionPattern.matcher(deployedName);
                if (m.matches()) {
                    deployedName = m.group(1);
                    configureDeployedName(project, deployedName);
                }
                if (pluginType != null) {
                    String pluginTypeSuffix = "-" + pluginType;
                    String deployedFileName = project.getName() + pluginTypeSuffix;
                    if ((deployedName == null) || ((deployedName != null) && !deployedName.endsWith(pluginTypeSuffix))) {
                        configureDeployedName(project, deployedFileName);
                    }
                    String oldContextRoot = ComponentUtilities.getServerContextRoot(project);
                    if ((oldContextRoot == null) || ((oldContextRoot != null) && !oldContextRoot.endsWith(pluginTypeSuffix))) {
                        IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(LiferayMavenCore.PLUGIN_ID);
                        boolean setMavenPluginSuffix = prefs.getBoolean(LiferayMavenCore.PREF_ADD_MAVEN_PLUGIN_SUFFIX, false);
                        if (setMavenPluginSuffix) {
                            ComponentUtilities.setServerContextRoot(project, deployedFileName);
                        }
                    }
                }
            }
        } catch (Exception e) {
            LiferayMavenCore.logError("Unable to configure deployed name for project " + project.getName(), e);
        }
        if (ILiferayMavenConstants.THEME_PLUGIN_TYPE.equals(pluginType)) {
            IVirtualComponent component = ComponentCore.createComponent(project, true);
            if (component != null) {
                // make sure to update the main deployment folder
                WarPluginConfiguration config = new WarPluginConfiguration(mavenProject, project);
                String warSourceDirectory = config.getWarSourceDirectory();
                IFolder contentFolder = project.getFolder(warSourceDirectory);
                IPath warPath = _rootPath.append(contentFolder.getProjectRelativePath());
                IPath themeFolder = _rootPath.append(getThemeTargetFolder(mavenProject, project));
                // add a link to our m2e-liferay/theme-resources folder into deployment assembly
                WTPProjectsUtil.insertLinkBefore(project, themeFolder, warPath, _rootPath, monitor);
            }
        }
    }
    if ((project != null) && ProjectUtil.isHookProject(project)) {
        HookDescriptorHelper hookDescriptor = new HookDescriptorHelper(project);
        String customJSPFolder = hookDescriptor.getCustomJSPFolder(null);
        if (customJSPFolder != null) {
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder docFolder = webproject.getDefaultDocrootFolder();
                IPath newPath = Path.fromOSString(customJSPFolder);
                IPath pathValue = docFolder.getFullPath().append(newPath);
                boolean disableCustomJspValidation = LiferayMavenCore.getPreferenceBoolean(LiferayMavenCore.PREF_DISABLE_CUSTOM_JSP_VALIDATION);
                if (disableCustomJspValidation) {
                    HookUtil.configureJSPSyntaxValidationExclude(project, project.getFolder(pathValue.makeRelativeTo(project.getFullPath())), true);
                }
            }
        }
    }
    monitor.worked(25);
    monitor.done();
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) Matcher(java.util.regex.Matcher) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) IWebProject(com.liferay.ide.core.IWebProject) WarPluginConfiguration(org.eclipse.m2e.wtp.WarPluginConfiguration) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) MavenProblemInfo(org.eclipse.m2e.core.internal.markers.MavenProblemInfo) MavenProject(org.apache.maven.project.MavenProject) CoreException(org.eclipse.core.runtime.CoreException) HookDescriptorHelper(com.liferay.ide.hook.core.dd.HookDescriptorHelper) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent) Plugin(org.apache.maven.model.Plugin) 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