Search in sources :

Example 6 with IWebProject

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

the class NewPortletWizard method openJavaClass.

@Override
protected void openJavaClass() {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(getDataModel().getStringProperty(PROJECT_NAME));
    if (getDataModel().getBooleanProperty(USE_DEFAULT_PORTLET_CLASS)) {
        try {
            String jspsFolder = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);
            // IDE-110 IDE-648
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                IFile viewFile = defaultDocroot.getFile(new Path(jspsFolder + "/view.jsp"));
                if (viewFile.exists()) {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                    IDE.openEditor(page, viewFile, true);
                    return;
                }
            }
        } catch (Exception e) {
        // eat this exception this is just best effort
        }
    } else {
        Map<String, String> settings = new Hashtable<>();
        settings.put(CleanUpConstants.ORGANIZE_IMPORTS, CleanUpOptions.TRUE);
        ImportsCleanUp importsCleanUp = new ImportsCleanUp(settings);
        ICleanUp[] cleanUps = { importsCleanUp };
        IJavaProject javaProject = JavaCore.create(project);
        try {
            IType type = javaProject.findType(getDataModel().getStringProperty(INewJavaClassDataModelProperties.QUALIFIED_CLASS_NAME));
            ICompilationUnit cu = (ICompilationUnit) type.getParent();
            ICompilationUnit[] units = { cu };
            RefactoringExecutionStarter.startCleanupRefactoring(units, cleanUps, false, getShell(), false, "organize imports");
        } catch (Exception e) {
        }
        super.openJavaClass();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) ICleanUp(org.eclipse.jdt.ui.cleanup.ICleanUp) IWebProject(com.liferay.ide.core.IWebProject) Hashtable(java.util.Hashtable) ImportsCleanUp(org.eclipse.jdt.internal.ui.fix.ImportsCleanUp) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) IType(org.eclipse.jdt.core.IType) IWorkbench(org.eclipse.ui.IWorkbench) IJavaProject(org.eclipse.jdt.core.IJavaProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with IWebProject

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

the class PluginClasspathContainer method createContextClasspathEntry.

protected IClasspathEntry createContextClasspathEntry(String context) {
    IClasspathEntry entry = null;
    IFile serviceJar = ComponentUtil.findServiceJarForContext(context);
    if (serviceJar.exists()) {
        IWebProject webproject = LiferayCore.create(IWebProject.class, serviceJar.getProject());
        if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
            IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
            IFolder serviceFolder = defaultDocroot.getFolder(new Path("WEB-INF/service"));
            if (serviceFolder.exists()) {
                entry = createClasspathEntry(serviceJar.getLocation(), serviceFolder.getLocation());
            }
        }
        if (entry == null) {
            entry = createClasspathEntry(serviceJar.getLocation(), null);
        }
    }
    if (entry == null) {
        IProject project = this.javaProject.getProject();
        SDK sdk = SDKUtil.getSDK(project);
        IPath sdkLocation = sdk.getLocation();
        String type = StringPool.EMPTY;
        if (ProjectUtil.isPortletProject(project)) {
            type = "portlets";
        } else if (ProjectUtil.isHookProject(project)) {
            type = "hooks";
        } else if (ProjectUtil.isExtProject(project)) {
            type = "ext";
        }
        IPath contextPath = sdkLocation.append(type).append(context);
        String libFolder = ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/lib";
        IPath serviceJarPath = contextPath.append(libFolder).append(context + "-service.jar");
        if (serviceJarPath.toFile().exists()) {
            IPath servicePath = serviceJarPath.removeLastSegments(2).append("service");
            entry = createClasspathEntry(serviceJarPath, servicePath.toFile().exists() ? servicePath : null);
        }
    }
    return entry;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IWebProject(com.liferay.ide.core.IWebProject) SDK(com.liferay.ide.sdk.core.SDK) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with IWebProject

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

the class PluginPackageResourceListener method shouldProcessResourceDelta.

protected boolean shouldProcessResourceDelta(IResourceDelta delta) {
    IPath fullPath = delta.getFullPath();
    if ((fullPath.lastSegment() == null) || !fullPath.lastSegment().equals(ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_FILE)) {
        return false;
    }
    IProject project = CoreUtil.getLiferayProject(delta.getResource());
    IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
    if (lrproject == null) {
        return false;
    }
    Path path = new Path("WEB-INF/" + ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_FILE);
    IResource propertiesFile = lrproject.findDocrootResource(path);
    if (FileUtil.notExists(propertiesFile)) {
        return false;
    }
    IPath filePath = propertiesFile.getFullPath();
    return filePath.equals(fullPath);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 9 with IWebProject

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

the class NewJSFPortletWizard method openJavaClass.

@Override
protected void openJavaClass() {
    if (getDataModel().getBooleanProperty(CREATE_JSPS)) {
        try {
            String jspsFolder = getDataModel().getStringProperty(CREATE_JSPS_FOLDER);
            String projectName = getDataModel().getStringProperty(PROJECT_NAME);
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IProject project = workspace.getRoot().getProject(projectName);
            // IDE-110 IDE-648
            IWebProject webproject = LiferayCore.create(IWebProject.class, project);
            if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
                IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                Path path = new Path(jspsFolder + "/view.xhtml");
                IFile viewFile = defaultDocroot.getFile(path);
                if (viewFile.exists()) {
                    IWorkbench workbench = PlatformUI.getWorkbench();
                    IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
                    IDE.openEditor(page, viewFile, true);
                    return;
                }
            }
        } catch (Exception e) {
        // best effort
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IWorkbench(org.eclipse.ui.IWorkbench) IFile(org.eclipse.core.resources.IFile) IWebProject(com.liferay.ide.core.IWebProject) IWorkspace(org.eclipse.core.resources.IWorkspace) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with IWebProject

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

the class RemoteJSPBreakpointProvider method addBreakpoint.

@Override
public IStatus addBreakpoint(IDocument document, IEditorInput input, int editorLineNumber, int offset) throws CoreException {
    // check if there is a valid position to set breakpoint
    int pos = getValidPosition(document, editorLineNumber);
    IStatus status = null;
    if (pos >= 0) {
        IResource res = getResourceFromInput(input);
        if (res != null) {
            String path = null;
            // IDE-648 IDE-110
            // get docroot relative path
            final IWebProject lrproject = LiferayCore.create(IWebProject.class, res.getProject());
            if (lrproject != null) {
                final IFolder webappRoot = lrproject.getDefaultDocrootFolder();
                if (webappRoot != null && webappRoot.exists()) {
                    IPath relativePath = res.getFullPath().makeRelativeTo(webappRoot.getFullPath());
                    if (relativePath != null && relativePath.segmentCount() > 0) {
                        // $NON-NLS-1$
                        path = "/" + relativePath.toPortableString();
                    }
                }
                IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", res.getName(), path, getClassPattern(res), editorLineNumber, pos, pos, 0, true, null);
                if (point == null) {
                    status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null);
                }
            }
        } else if (input instanceof IStorageEditorInput) {
            // For non-resources, use the workspace root and a coordinated
            // attribute that is used to
            // prevent unwanted (breakpoint) markers from being loaded
            // into the editors.
            res = ResourcesPlugin.getWorkspace().getRoot();
            String id = input.getName();
            if (input instanceof IStorageEditorInput && ((IStorageEditorInput) input).getStorage() != null && ((IStorageEditorInput) input).getStorage().getFullPath() != null) {
                id = ((IStorageEditorInput) input).getStorage().getFullPath().toString();
            }
            Map attributes = new HashMap();
            attributes.put(StructuredResourceMarkerAnnotationModel.SECONDARY_ID_KEY, id);
            String path = null;
            IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", input.getName(), path, getClassPattern(res), editorLineNumber, pos, pos, 0, true, // $NON-NLS-1$
            attributes);
            if (point == null) {
                // $NON-NLS-1$
                status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null);
            }
        }
    } else {
        status = new Status(IStatus.INFO, JSPUIPlugin.ID, IStatus.INFO, JSPUIMessages.BreakpointNotAllowed, null);
    }
    if (status == null) {
        status = new Status(IStatus.OK, JSPUIPlugin.ID, IStatus.OK, JSPUIMessages.OK, null);
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStorageEditorInput(org.eclipse.ui.IStorageEditorInput) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) IWebProject(com.liferay.ide.core.IWebProject) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) HashMap(java.util.HashMap) Map(java.util.Map) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IResource(org.eclipse.core.resources.IResource) 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