Search in sources :

Example 41 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class NewHookDataModelProvider method validate.

@Override
public IStatus validate(String propertyName) {
    boolean is70 = false;
    try {
        SDK sdk = SDKUtil.getWorkspaceSDK();
        if (sdk != null) {
            Version version = new Version(sdk.getVersion());
            Version sdk70 = ILiferayConstants.V700;
            if (CoreUtil.compareVersions(version, sdk70) >= 0) {
                is70 = true;
            }
        }
    } catch (CoreException ce) {
    }
    if (CUSTOM_JSPS_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
        String jspFolder = getStringProperty(CUSTOM_JSPS_FOLDER);
        if (CoreUtil.isNullOrEmpty(jspFolder)) {
            return HookCore.createErrorStatus(Msgs.customJSPsFolderNotConfigured);
        }
        IProject project = getTargetProject();
        IWebProject webproject = LiferayCore.create(IWebProject.class, project);
        if (webproject != null) {
            IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
            IPath defaultWebappRootFolderPath = defaultWebappRootFolder.getFullPath();
            String jspFolderPath = defaultWebappRootFolderPath.append(jspFolder).toPortableString();
            IStatus validateStatus = CoreUtil.getWorkspace().validatePath(jspFolderPath, IResource.FOLDER);
            if (!validateStatus.isOK()) {
                return HookCore.createErrorStatus(validateStatus.getMessage());
            }
        }
    } else if (CUSTOM_JSPS_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
        Object jspItems = getProperty(CUSTOM_JSPS_ITEMS);
        if (jspItems instanceof List) {
            if (((List) jspItems).size() > 0) {
                String[][] jspArrays = ((List<String[]>) jspItems).toArray(new String[0][]);
                for (int i = 0; i < jspArrays.length; i++) {
                    String[] comp1 = jspArrays[i];
                    for (int j = i + 1; j < jspArrays.length; j++) {
                        String[] comp2 = jspArrays[j];
                        if (comp1[0].equals(comp2[0])) {
                            return HookCore.createWarnStatus("Shouldn't add same jsp file.");
                        }
                    }
                }
                return Status.OK_STATUS;
            }
        }
        return HookCore.createErrorStatus(Msgs.specifyOneJSP);
    } else if (PORTAL_PROPERTIES_FILE.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
        String portalPropertiesFile = getStringProperty(PORTAL_PROPERTIES_FILE);
        if (CoreUtil.isNullOrEmpty(portalPropertiesFile)) {
            return HookCore.createErrorStatus(Msgs.portalPropertiesFileNotConfigured);
        }
        IPath portalPropertiesPath = Path.fromPortableString(portalPropertiesFile);
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if (portalPropertiesFile.startsWith("/")) {
            for (IFolder sourceFolder : sources) {
                IPath sourceFolderPath = sourceFolder.getFullPath();
                if (sourceFolderPath.isPrefixOf(portalPropertiesPath)) {
                    return Status.OK_STATUS;
                }
            }
            return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
        } else {
            return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
        }
    } else if (PORTAL_PROPERTIES_ACTION_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
        // if we have valid actions items or property overrides then we
        // don't need an error
        IStatus actionItemsStatus = validateListItems(PORTAL_PROPERTIES_ACTION_ITEMS);
        IStatus propertyOverridesStatus = validateListItems(PORTAL_PROPERTIES_OVERRIDE_ITEMS);
        if (actionItemsStatus.isOK() || propertyOverridesStatus.isOK()) {
            return Status.OK_STATUS;
        } else {
            return HookCore.createErrorStatus(Msgs.specifyOneEventActionProperty);
        }
    } else if (SERVICES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_SERVICES)) {
        IStatus itemsStatus = validateListItems(SERVICES_ITEMS);
        if (itemsStatus.isOK()) {
            return Status.OK_STATUS;
        } else {
            return HookCore.createErrorStatus(Msgs.specifyOneService);
        }
    } else if (CONTENT_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        String contentFolder = getStringProperty(CONTENT_FOLDER);
        if (CoreUtil.isNullOrEmpty(contentFolder)) {
            return HookCore.createErrorStatus(Msgs.contentFolderNotConfigured);
        }
        IPath contentPath = Path.fromPortableString(contentFolder);
        IProject targetProject = getTargetProject();
        List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
        if (contentFolder.startsWith("/")) {
            for (IFolder sourceFolder : sources) {
                IPath sourcePath = sourceFolder.getFullPath();
                if (sourcePath.isPrefixOf(contentPath)) {
                    return Status.OK_STATUS;
                }
            }
            return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
        } else {
            return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
        }
    } else if (LANGUAGE_PROPERTIES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        Object propertiesItems = getProperty(LANGUAGE_PROPERTIES_ITEMS);
        if (propertiesItems instanceof List) {
            List jsps = (List) propertiesItems;
            if (ListUtil.isNotEmpty(jsps)) {
                return Status.OK_STATUS;
            }
        }
        return HookCore.createErrorStatus(Msgs.specifyOneLanguagePropertyFile);
    } else if (is70 && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
        return HookCore.createErrorStatus(Msgs.noSupportInSDK70);
    }
    return super.validate(propertyName);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Version(org.osgi.framework.Version) List(java.util.List) SDK(com.liferay.ide.sdk.core.SDK) IFolder(org.eclipse.core.resources.IFolder)

Example 42 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class JSFPortletFramework method postProjectCreated.

@Override
public IStatus postProjectCreated(IProject project, String frameworkName, String portletName, IProgressMonitor monitor) {
    /*
		 * we need to copy the original web.xml from the project template
		 * because of bugs in the JSF facet installer will overwrite our web.xml
		 * that comes with in the template
		 */
    super.postProjectCreated(project, frameworkName, portletName, monitor);
    SDK sdk = SDKUtil.getSDK(project);
    if (sdk != null) {
        try {
            // TODO IDE-648
            IPath location = sdk.getLocation().append("tools/portlet_" + frameworkName + "_tmpl/docroot/WEB-INF/web.xml");
            File originalWebXmlFile = location.toFile();
            if (originalWebXmlFile.exists()) {
                final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
                if (webproject != null) {
                    IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
                    try (InputStream newInputStream = Files.newInputStream(originalWebXmlFile.toPath())) {
                        defaultDocroot.getFile("WEB-INF/web.xml").setContents(newInputStream, IResource.FORCE, null);
                    }
                }
            }
        } catch (Exception e) {
            return PortletCore.createErrorStatus("Could not copy original web.xml from JSF template in SDK.", e);
        }
    }
    try {
        IFolder docroot = CoreUtil.getDefaultDocrootFolder(project);
        IFolder views = docroot.getFolder("views");
        if (views.exists()) {
            views.move(docroot.getFolder("WEB-INF/views").getFullPath(), true, monitor);
            IFile portletXml = docroot.getFile("WEB-INF/portlet.xml");
            File portletXmlFile = portletXml.getLocation().toFile();
            String contents = FileUtil.readContents(portletXmlFile, true);
            if (contents.contains("init-param")) {
                contents = contents.replaceAll("/views/view.xhtml", "/WEB-INF/views/view.xhtml");
                portletXml.setContents(new ByteArrayInputStream(contents.getBytes("UTF-8")), IResource.FORCE, null);
            }
        }
    } catch (Exception e) {
        return PortletCore.createErrorStatus(e);
    }
    return Status.OK_STATUS;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) IWebProject(com.liferay.ide.core.IWebProject) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SDK(com.liferay.ide.sdk.core.SDK) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 43 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class PortalDeployExcludesSection method _handleAdd.

private void _handleAdd() {
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    String[] excludeJars = model.getPortalDeloyExcludesJars();
    IProject project = getProject();
    IFolder docroot = CoreUtil.getDefaultDocrootFolder(project);
    SDK sdk = SDKUtil.getSDK(project);
    IPath sdkLocation = sdk.getLocation();
    String type;
    if (ProjectUtil.isPortletProject(project)) {
        type = "portlets";
    } else if (ProjectUtil.isHookProject(project)) {
        type = "hooks";
    } else if (ProjectUtil.isWebProject(project)) {
        type = "webs";
    } else {
        type = StringPool.EMPTY;
    }
    IPath serviceJarPath = sdkLocation.append(type).append(docroot.getFullPath());
    if (serviceJarPath != null) {
        Shell shell = getPage().getShell();
        PortalJarViewerFilter filter = new PortalJarViewerFilter(serviceJarPath.toFile(), new String[] { "WEB-INF", "WEB-INF/lib" }, excludeJars);
        ExternalFileSelectionDialog dialog = new ExternalFileSelectionDialog(shell, filter, true, false);
        dialog.setInput(serviceJarPath.toFile());
        dialog.create();
        if (dialog.open() == Window.OK) {
            Object[] selectedFiles = dialog.getResult();
            try {
                for (int i = 0; i < selectedFiles.length; i++) {
                    File jar = (File) selectedFiles[i];
                    if (jar.exists()) {
                        model.addPortalDeployExcludeJar(jar.getName());
                    }
                }
            } catch (Exception e) {
            }
        }
    } else {
        MessageDialog.openInformation(getPage().getShell(), Msgs.liferayPluginPackageEditor, Msgs.notDeterminePortalDirectory);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) IProject(org.eclipse.core.resources.IProject) ExternalFileSelectionDialog(com.liferay.ide.ui.wizard.ExternalFileSelectionDialog) Shell(org.eclipse.swt.widgets.Shell) PluginPackageModel(com.liferay.ide.portlet.core.PluginPackageModel) IPluginPackageModel(com.liferay.ide.portlet.core.IPluginPackageModel) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 44 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class LiferayProjectImportDataModelProvider method validate.

@Override
public IStatus validate(String name) {
    if (PROJECT_LOCATION.equals(name)) {
        String projectLocation = getStringProperty(PROJECT_LOCATION);
        ProjectRecord record = ProjectUtil.getProjectRecordForDir(projectLocation);
        if (record != null) {
            String projectName = record.getProjectName();
            IProject existingProject = CoreUtil.getWorkspaceRoot().getProject(projectName);
            if (FileUtil.exists(existingProject)) {
                return ProjectCore.createErrorStatus(Msgs.projectNameExists);
            }
            File projectDir = record.getProjectLocation().toFile();
            // go up to the SDK level
            SDK sdk = SDKUtil.getSDKFromProjectDir(projectDir);
            if (sdk != null) {
                return Status.OK_STATUS;
            } else {
                return ProjectCore.createErrorStatus(Msgs.projectNotLocated);
            }
        }
        return ProjectCore.createErrorStatus(Msgs.invalidProjectLocation);
    } else if (SDK_VERSION.equals(name)) {
        IStatus locationStatus = validate(PROJECT_LOCATION);
        if (locationStatus.isOK()) {
            Version version = new Version(getStringProperty(SDK_VERSION));
            if (CoreUtil.compareVersions(version, SDKManager.getLeastValidVersion()) >= 0) {
                return Status.OK_STATUS;
            } else {
                return ProjectCore.createErrorStatus(Msgs.invalidPluginSDKVersion + SDKManager.getLeastValidVersion());
            }
        } else {
            return locationStatus;
        }
    } else if (PLUGIN_TYPE.equals(name)) {
        if (ProjectUtil.isLiferayPluginType(getStringProperty(PLUGIN_TYPE))) {
            return Status.OK_STATUS;
        } else {
            return ProjectCore.createErrorStatus(Msgs.invalidLiferayPluginType);
        }
    } else if (FACET_RUNTIME.equals(name)) {
        Object runtime = getProperty(FACET_RUNTIME);
        if (!(runtime instanceof BridgedRuntime)) {
            return ProjectCore.createErrorStatus(Msgs.validLiferayRuntimeSelected);
        } else {
            return Status.OK_STATUS;
        }
    } else if (FACET_PROJECT_NAME.equals(name)) {
        return Status.OK_STATUS;
    }
    return super.validate(name);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Version(org.osgi.framework.Version) BridgedRuntime(org.eclipse.wst.common.project.facet.core.runtime.internal.BridgedRuntime) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 45 with SDK

use of com.liferay.ide.sdk.core.SDK in project liferay-ide by liferay.

the class LiferayProjectImportOperation method execute.

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    ProjectRecord projectRecord = (ProjectRecord) getDataModel().getProperty(PROJECT_RECORD);
    if (projectRecord == null) {
        return ProjectCore.createErrorStatus("Project record to import is null.");
    }
    File projectDir = projectRecord.getProjectLocation().toFile();
    SDK sdk = SDKUtil.getSDKFromProjectDir(projectDir);
    if ((sdk != null) && !(SDKManager.getInstance().containsSDK(sdk))) {
        SDKManager.getInstance().addSDK(sdk);
    }
    IRuntime runtime = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
    try {
        ProjectImportUtil.importProject(projectRecord, runtime, sdk.getLocation().toOSString(), monitor);
    } catch (CoreException ce) {
        return ProjectCore.createErrorStatus(ce);
    }
    return Status.OK_STATUS;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Aggregations

SDK (com.liferay.ide.sdk.core.SDK)75 IPath (org.eclipse.core.runtime.IPath)41 CoreException (org.eclipse.core.runtime.CoreException)29 IStatus (org.eclipse.core.runtime.IStatus)26 IProject (org.eclipse.core.resources.IProject)24 Path (org.eclipse.sapphire.modeling.Path)16 File (java.io.File)15 IFile (org.eclipse.core.resources.IFile)14 Path (org.eclipse.core.runtime.Path)14 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)12 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)11 Version (org.osgi.framework.Version)11 IOException (java.io.IOException)9 Status (org.eclipse.sapphire.modeling.Status)9 IFolder (org.eclipse.core.resources.IFolder)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 IWebProject (com.liferay.ide.core.IWebProject)4 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)4 PluginType (com.liferay.ide.project.core.model.PluginType)4