Search in sources :

Example 6 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class CustomJspDirListener method handleTypedEvent.

@Override
protected void handleTypedEvent(PropertyContentEvent event) {
    Property prop = event.property();
    Hook hook = prop.element().nearest(Hook.class);
    if (hook != null) {
        if (CustomJspDir.PROP_VALUE.equals(prop.definition())) {
            // IDE-1132, Listen the change of Property CustomJspDir, and refresh the
            // Property CustomJsps.
            hook.property(Hook.PROP_CUSTOM_JSPS).refresh();
        } else if (Hook.PROP_CUSTOM_JSP_DIR.equals(prop.definition())) {
            // IDE-1251 listen for changes to custom_jsp_dir and if it is empty initialize
            // initial content @InitialValue
            CustomJspDir customJspDir = hook.getCustomJspDir().content(false);
            if (customJspDir != null) {
                Value<Path> value = customJspDir.getValue();
                if (value != null) {
                    Path path = value.content(false);
                    if (path == null) {
                        customJspDir.initialize();
                    }
                }
            }
        }
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) Hook(com.liferay.ide.hook.core.model.Hook) Value(org.eclipse.sapphire.Value) CustomJspDir(com.liferay.ide.hook.core.model.CustomJspDir) Property(org.eclipse.sapphire.Property)

Example 7 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class LocaleBundleValidationService method compute.

public Status compute() {
    Element modelElement = context(Element.class);
    if (!modelElement.disposed() && modelElement instanceof SupportedLocales) {
        IProject project = modelElement.adapt(IProject.class);
        Portlet portlet = modelElement.nearest(Portlet.class);
        IWorkspaceRoot wroot = ResourcesPlugin.getWorkspace().getRoot();
        IClasspathEntry[] cpEntries = CoreUtil.getClasspathEntries(project);
        if (cpEntries != null) {
            String locale = modelElement.property(context(ValueProperty.class)).text(false);
            Value<Path> resourceBundle = portlet.getResourceBundle();
            if (locale == null) {
                return Status.createErrorStatus(Resources.localeMustNotEmpty);
            } else {
                String bundleName = resourceBundle.text();
                if ((resourceBundle != null) && (bundleName != null)) {
                    String localeString = PortletUtil.localeString(locale);
                    String ioFileName = PortletUtil.convertJavaToIoFileName(bundleName, RB_FILE_EXTENSION, localeString);
                    for (IClasspathEntry iClasspathEntry : cpEntries) {
                        if (IClasspathEntry.CPE_SOURCE == iClasspathEntry.getEntryKind()) {
                            IPath entryPath = wroot.getFolder(iClasspathEntry.getPath()).getLocation();
                            entryPath = entryPath.append(ioFileName);
                            IFile resourceBundleFile = wroot.getFileForLocation(entryPath);
                            if ((resourceBundleFile != null) && resourceBundleFile.exists()) {
                                return Status.createOkStatus();
                            } else {
                                return Status.createWarningStatus(Resources.bind(StringEscapeUtils.unescapeJava(Resources.noResourceBundle), new Object[] { locale, bundleName, localeString }));
                            }
                        }
                    }
                }
            }
        }
    }
    return Status.createOkStatus();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) Portlet(com.liferay.ide.portlet.core.model.Portlet) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) Element(org.eclipse.sapphire.Element) SupportedLocales(com.liferay.ide.portlet.core.model.SupportedLocales) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot)

Example 8 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class PortletStyleValidationService method compute.

@Override
protected Status compute() {
    Element modelElement = context(Element.class);
    if (!modelElement.disposed() && modelElement instanceof PortletStyleElement) {
        Path path = (Path) modelElement.property(context(ValueProperty.class)).content();
        if (path != null) {
            String name = path.lastSegment();
            IProject project = modelElement.adapt(IProject.class);
            boolean fileExisted = new FileCheckVisitor().checkFiles(project, name);
            if (!fileExisted) {
                return Status.createErrorStatus("File " + path.toPortableString() + " is not existed");
            }
        } else {
            return Status.createErrorStatus("Can not set empty value");
        }
    }
    return Status.createOkStatus();
}
Also used : Path(org.eclipse.sapphire.modeling.Path) PortletStyleElement(com.liferay.ide.portlet.core.lfportlet.model.PortletStyleElement) Element(org.eclipse.sapphire.Element) PortletStyleElement(com.liferay.ide.portlet.core.lfportlet.model.PortletStyleElement) ValueProperty(org.eclipse.sapphire.ValueProperty) IProject(org.eclipse.core.resources.IProject)

Example 9 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class PluginsSDKProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
    ElementList<ProjectName> projectNames = op.getProjectNames();
    PluginType pluginType = op.getPluginType().content(true);
    String originalProjectName = op.getProjectName().content();
    String pluginTypeSuffix = NewLiferayPluginProjectOpMethods.getPluginTypeSuffix(pluginType);
    String fixedProjectName = originalProjectName;
    if (originalProjectName.endsWith(pluginTypeSuffix)) {
        fixedProjectName = originalProjectName.substring(0, originalProjectName.length() - pluginTypeSuffix.length());
    }
    String projectName = fixedProjectName;
    String displayName = op.getDisplayName().content(true);
    boolean separateJRE = true;
    SDK sdk = _getSDK(op);
    if (sdk == null) {
        return ProjectCore.createErrorStatus("Can not get correct SDK for " + fixedProjectName + ", Please check SDK configuration setting.");
    }
    // workingDir should always be the directory of the type of plugin /sdk/portlets/ for a portlet, etc
    String workingDir = null;
    ArrayList<String> arguments = new ArrayList<>();
    arguments.add(projectName);
    arguments.add(displayName);
    boolean hasGradleTools = SDKUtil.hasGradleTools(sdk.getLocation());
    IPath newSDKProjectPath = null;
    IPath path = null;
    switch(pluginType) {
        case servicebuilder:
            op.setPortletFramework("mvc");
        case portlet:
            path = sdk.getLocation().append(ISDKConstants.PORTLET_PLUGIN_PROJECT_FOLDER);
            String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                arguments.add(frameworkName);
                sdk.createNewProject(projectName, arguments, "portlet", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewPortletProject(projectName, displayName, frameworkName, separateJRE, workingDir, null, monitor);
            }
            break;
        case hook:
            path = sdk.getLocation().append(ISDKConstants.HOOK_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "hook", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewHookProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case ext:
            path = sdk.getLocation().append(ISDKConstants.EXT_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "ext", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewExtProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case layouttpl:
            path = sdk.getLocation().append(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "layouttpl", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewLayoutTplProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            IProject layoutProject = ProjectUtil.getProject(projectName);
            if (!LiferayDescriptorHelper.getDescriptorVersion(layoutProject).equals("6.2.0")) {
                IPath projectPath = newSDKProjectPath.append(projectName + pluginTypeSuffix);
                IPath fileWap = projectPath.append("docroot").append("blank_columns.wap.tpl");
                if (FileUtil.exists(fileWap)) {
                    fileWap.toFile().delete();
                }
            }
            break;
        case theme:
            path = sdk.getLocation().append(ISDKConstants.THEME_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "theme", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewThemeProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
        case web:
            path = sdk.getLocation().append(ISDKConstants.WEB_PLUGIN_PROJECT_FOLDER);
            workingDir = path.toOSString();
            if (hasGradleTools) {
                sdk.createNewProject(projectName, arguments, "web", workingDir, monitor);
            } else {
                newSDKProjectPath = sdk.createNewWebProject(projectName, displayName, separateJRE, workingDir, null, monitor);
            }
            break;
    }
    NewLiferayPluginProjectOpMethods.updateLocation(op);
    Path projectLocation = op.getLocation().content();
    if (!hasGradleTools) {
        File projectDir = projectLocation.toFile();
        File projectParent = projectDir.getParentFile();
        projectParent.mkdirs();
        if (FileUtil.notExists(newSDKProjectPath)) {
            return ProjectCore.createErrorStatus("Error create project due to '" + newSDKProjectPath + "' does not exist.");
        }
        File newSDKProjectDir = newSDKProjectPath.toFile();
        try {
            FileUtils.copyDirectory(newSDKProjectDir, projectParent);
            FileUtils.deleteDirectory(newSDKProjectDir);
        } catch (IOException ioe) {
            throw new CoreException(ProjectCore.createErrorStatus(ioe));
        }
    }
    ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectLocation.toOSString());
    IProject newProject = ProjectImportUtil.importProject(projectRecord.getProjectLocation(), monitor, op);
    newProject.open(monitor);
    // need to update project name incase the suffix was not correct
    op.setFinalProjectName(newProject.getName());
    projectNames.insert().setName(op.getFinalProjectName().content());
    _projectCreated(newProject);
    switch(op.getPluginType().content()) {
        case portlet:
            _portletProjectCreated(op, newProject, monitor);
            break;
        case servicebuilder:
            PortalBundle bundle = ServerUtil.getPortalBundle(newProject);
            _serviceBuilderProjectCreated(bundle.getVersion(), newProject, monitor);
            break;
        case theme:
            _themeProjectCreated(newProject);
            break;
        default:
            break;
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IPath(org.eclipse.core.runtime.IPath) ProjectName(com.liferay.ide.project.core.model.ProjectName) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PluginType(com.liferay.ide.project.core.model.PluginType) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) PortalBundle(com.liferay.ide.server.core.portal.PortalBundle) SDK(com.liferay.ide.sdk.core.SDK) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 10 with Path

use of org.eclipse.sapphire.modeling.Path in project liferay-ide by liferay.

the class CreatePortletResourceBundleActionHandler method run.

/**
 * (non-Javadoc)
 *
 * @see
 * org.eclipse.sapphire.ui.SapphireActionHandler#run(org.eclipse.sapphire.ui.
 * SapphireRenderingContext)
 */
@Override
protected Object run(Presentation context) {
    ITextEditor editor = context.part().adapt(ITextEditor.class);
    editor.doSave(new NullProgressMonitor());
    List<IFile> missingRBFiles = new ArrayList<>();
    Portlet portlet = (Portlet) getModelElement();
    IProject project = portlet.adapt(IProject.class);
    Value<Path> resourceBundle = portlet.getResourceBundle();
    String text = resourceBundle.text();
    String defaultRBFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION);
    int index = text.lastIndexOf(".");
    String packageName = "";
    if (index == -1) {
        index = text.length();
        packageName = "";
    } else {
        packageName = text.substring(0, index);
    }
    IFolder rbSourceFolder = getResourceBundleFolderLocation(project, defaultRBFileName);
    IPath entryPath = rbSourceFolder.getLocation();
    PortletInfo portletInfo = portlet.getPortletInfo();
    StringBuilder rbFileBuffer = _buildDefaultRBContent(portletInfo);
    if (!getFileFromClasspath(project, defaultRBFileName)) {
        IFile drbFile = wroot.getFileForLocation(entryPath.append(defaultRBFileName));
        missingRBFiles.add(drbFile);
    }
    // Create bundles for each supported locale for which the resource bundle is
    // missing
    List<SupportedLocales> supportedLocales = portlet.getSupportedLocales();
    for (SupportedLocales iSupportedLocale : supportedLocales) {
        if (iSupportedLocale != null) {
            String locale = PortletUtil.localeString(iSupportedLocale.getSupportedLocale().text());
            String localizedIOFileName = PortletUtil.convertJavaToIoFileName(text, GenericResourceBundlePathService.RB_FILE_EXTENSION, locale);
            if (!getFileFromClasspath(project, localizedIOFileName)) {
                IFile rbFile = wroot.getFileForLocation(entryPath.append(localizedIOFileName));
                missingRBFiles.add(rbFile);
            }
        }
    }
    createFiles(context, project, packageName, missingRBFiles, rbFileBuffer);
    setEnabled(false);
    Portlet p = getModelElement().nearest(Portlet.class);
    for (SupportedLocales sl : p.getSupportedLocales()) {
        Value<String> locale = sl.getSupportedLocale();
        locale.service(LocaleBundleValidationService.class).forceRefresh();
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITextEditor(org.eclipse.ui.texteditor.ITextEditor) IFile(org.eclipse.core.resources.IFile) Portlet(com.liferay.ide.portlet.core.model.Portlet) IPath(org.eclipse.core.runtime.IPath) SupportedLocales(com.liferay.ide.portlet.core.model.SupportedLocales) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) LocaleBundleValidationService(com.liferay.ide.portlet.core.model.internal.LocaleBundleValidationService) PortletInfo(com.liferay.ide.portlet.core.model.PortletInfo) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

Path (org.eclipse.sapphire.modeling.Path)71 IPath (org.eclipse.core.runtime.IPath)37 IStatus (org.eclipse.core.runtime.IStatus)18 Status (org.eclipse.sapphire.modeling.Status)18 IProject (org.eclipse.core.resources.IProject)17 SDK (com.liferay.ide.sdk.core.SDK)16 CoreException (org.eclipse.core.runtime.CoreException)16 IFile (org.eclipse.core.resources.IFile)12 File (java.io.File)9 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)8 ArrayList (java.util.ArrayList)8 IFolder (org.eclipse.core.resources.IFolder)8 Hook (com.liferay.ide.hook.core.model.Hook)6 Element (org.eclipse.sapphire.Element)6 CustomJspDir (com.liferay.ide.hook.core.model.CustomJspDir)5 IWebProject (com.liferay.ide.core.IWebProject)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)4 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 ValueProperty (org.eclipse.sapphire.ValueProperty)3 ILiferayPortal (com.liferay.ide.core.ILiferayPortal)2