Search in sources :

Example 16 with SDK

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

the class SDKLocationListener method updateLocation.

public static void updateLocation(NewLiferayPluginProjectOp op) {
    Path newLocationBase = null;
    Path sdkLocation = op.getSdkLocation().content(true);
    if (sdkLocation == null) {
        return;
    }
    SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
    op.setImportProjectStatus(false);
    if (sdk == null) {
        return;
    }
    switch(op.getPluginType().content(true)) {
        case portlet:
        case servicebuilder:
            newLocationBase = sdkLocation.append("portlets");
            break;
        case ext:
            newLocationBase = sdkLocation.append("ext");
            break;
        case hook:
            newLocationBase = sdkLocation.append("hooks");
            break;
        case layouttpl:
            newLocationBase = sdkLocation.append("layouttpl");
            break;
        case theme:
            newLocationBase = sdkLocation.append("themes");
            break;
        case web:
            newLocationBase = sdkLocation.append("webs");
            break;
    }
    if (newLocationBase != null) {
        NewLiferayPluginProjectOpMethods.updateLocation(op, newLocationBase);
    }
}
Also used : Path(org.eclipse.sapphire.modeling.Path) SDK(com.liferay.ide.sdk.core.SDK)

Example 17 with SDK

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

the class ProjectNameValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayPluginProjectOp op = _op();
    NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
    if (provider.getShortName().equals("ant")) {
        SDK sdk = null;
        try {
            sdk = SDKUtil.getWorkspaceSDK();
            if (sdk != null) {
                IStatus sdkStatus = sdk.validate();
                if (!sdkStatus.isOK()) {
                    retval = Status.createErrorStatus(sdkStatus.getChildren()[0].getMessage());
                }
            }
        } catch (CoreException ce) {
            retval = Status.createErrorStatus(ce);
        }
    }
    String currentProjectName = op.getProjectName().content();
    if (currentProjectName != null) {
        IStatus nameStatus = CoreUtil.getWorkspace().validateName(currentProjectName, IResource.PROJECT);
        if (!nameStatus.isOK()) {
            retval = StatusBridge.create(nameStatus);
        } else if (_isInvalidProjectName(op)) {
            Boolean projectImported = op.getImportProjectStatus().content();
            if (projectImported == false) {
                retval = Status.createErrorStatus("A project with that name already exists.");
            }
        } else if (_isAntProject(op) && _isSuffixOnly(currentProjectName)) {
            retval = Status.createErrorStatus("A project name cannot only be a type suffix.");
        } else if (!_hasValidDisplayName(currentProjectName)) {
            retval = Status.createErrorStatus("The project name is invalid.");
        } else if (_isMavenProject(op) && !_isValidMavenProjectName(currentProjectName)) {
            retval = Status.createErrorStatus("The project name is invalid for a maven project");
        } else {
            Path currentProjectLocation = op.getLocation().content(true);
            if ((currentProjectName != null) && (currentProjectLocation != null)) {
                String currentPath = currentProjectLocation.toOSString();
                IPath osPath = org.eclipse.core.runtime.Path.fromOSString(currentPath);
                IStatus projectStatus = provider.validateProjectLocation(currentProjectName, osPath);
                if (!projectStatus.isOK()) {
                    retval = StatusBridge.create(projectStatus);
                }
            }
        }
    }
    op.getSdkLocation().refresh();
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) SDK(com.liferay.ide.sdk.core.SDK)

Example 18 with SDK

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

the class LiferayProjectPropertyPage method createInfoGroup.

protected void createInfoGroup(final Composite parent) {
    new Label(parent, SWT.LEFT).setText(Msgs.liferayPluginTypeLabel);
    final Text pluginTypeLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
    pluginTypeLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(getFacetedProject());
    if (liferayFacet != null) {
        pluginTypeLabel.setText(liferayFacet.getLabel());
    }
    final IProject proj = getProject();
    if ((proj != null) && ProjectUtil.isLiferayFacetedProject(proj)) {
        try {
            if (!ProjectUtil.isMavenProject(proj)) {
                final SDK projectSdk = SDKUtil.getSDK(getProject());
                new Label(parent, SWT.LEFT).setText(Msgs.liferaySdkLabel);
                _sdkLabel = new Text(parent, SWT.READ_ONLY | SWT.BORDER);
                if (projectSdk != null) {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    _sdkLabel.setText(projectSdk.getName());
                } else {
                    _sdkLabel.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 1, 1));
                    _sdkLabel.setText("");
                    final Hyperlink link = new Hyperlink(parent, SWT.NULL);
                    link.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 1, 1));
                    link.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
                    link.setUnderlined(true);
                    link.setText(Msgs.changeliferaySdk);
                    link.addHyperlinkListener(new HyperlinkAdapter() {

                        public void linkActivated(HyperlinkEvent e) {
                            String dialogId = new String("com.liferay.ide.project.ui.dialog.SelectPluginsSDKDialog");
                            final LiferayPluginSDKOp op = (LiferayPluginSDKOp) (LiferayPluginSDKOp.TYPE.instantiate().initialize());
                            DefinitionLoader sdefLoader = DefinitionLoader.context(getClass()).sdef(dialogId);
                            final Reference<DialogDef> dialogRef = sdefLoader.dialog("ConfigureLiferaySDK");
                            final SapphireDialog dialog = new SapphireDialog(UIUtil.getActiveShell(), op, dialogRef);
                            dialog.setBlockOnOpen(true);
                            final int result = dialog.open();
                            if (result != SapphireDialog.CANCEL) {
                                _sdkLabel.setText(op.getPluginsSDKName().content());
                            }
                        }
                    });
                }
                if (CoreUtil.compareVersions(new Version(projectSdk.getVersion()), ILiferayConstants.V700) < 0) {
                    new Label(parent, SWT.LEFT).setText(Msgs.liferayRuntimeLabel);
                    _runtimeCombo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
                    _runtimeCombo.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
                    String currentRuntimeName = null;
                    try {
                        ILiferayRuntime liferayRuntime = ServerUtil.getLiferayRuntime(getProject());
                        if (liferayRuntime != null) {
                            currentRuntimeName = liferayRuntime.getRuntime().getName();
                        }
                    } catch (Exception e) {
                        ProjectUI.logError("Could not determine liferay runtime", e);
                    }
                    List<String> runtimeNames = new ArrayList<>();
                    int selectionIndex = -1;
                    for (IRuntime runtime : ServerCore.getRuntimes()) {
                        if (ServerUtil.isLiferayRuntime(runtime) && FileUtil.exists(runtime.getLocation()) && (LiferayServerCore.newPortalBundle(runtime.getLocation()) == null)) {
                            runtimeNames.add(runtime.getName());
                            if (runtime.getName().equals(currentRuntimeName)) {
                                selectionIndex = runtimeNames.size() - 1;
                            }
                        }
                    }
                    if (ListUtil.isEmpty(runtimeNames)) {
                        runtimeNames.add("No Liferay runtimes available.");
                    }
                    _runtimeCombo.setItems(runtimeNames.toArray(new String[0]));
                    if (selectionIndex > -1) {
                        _runtimeCombo.select(selectionIndex);
                    }
                }
            }
        } catch (Exception e) {
            ProjectUI.logError("Could not determine whether its a maven project ", e);
        }
    }
}
Also used : HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Reference(org.eclipse.sapphire.ui.def.DefinitionLoader.Reference) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) LiferayPluginSDKOp(com.liferay.ide.project.core.model.LiferayPluginSDKOp) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) BackingStoreException(org.osgi.service.prefs.BackingStoreException) IRuntime(org.eclipse.wst.server.core.IRuntime) Version(org.osgi.framework.Version) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ILiferayRuntime(com.liferay.ide.server.core.ILiferayRuntime) GridData(org.eclipse.swt.layout.GridData) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) SDK(com.liferay.ide.sdk.core.SDK) SapphireDialog(org.eclipse.sapphire.ui.forms.swt.SapphireDialog) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 19 with SDK

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

the class IvyUtil method addIvyLibrary.

public static IvyClasspathContainer addIvyLibrary(IProject project, IProgressMonitor monitor) {
    final String projectName = project.getName();
    final IJavaProject javaProject = JavaCore.create(project);
    final IvyClasspathContainerConfiguration conf = new IvyClasspathContainerConfiguration(javaProject, ISDKConstants.IVY_XML_FILE, true);
    final ClasspathSetup classpathSetup = new ClasspathSetup();
    conf.setAdvancedProjectSpecific(false);
    conf.setClasspathSetup(classpathSetup);
    conf.setClassthProjectSpecific(false);
    conf.setConfs(Collections.singletonList("*"));
    conf.setMappingProjectSpecific(false);
    conf.setSettingsProjectSpecific(true);
    SDK sdk = SDKUtil.getSDK(project);
    final SettingsSetup settingsSetup = new SettingsSetup();
    IPath ivyFilePath = sdk.getLocation().append(ISDKConstants.IVY_SETTINGS_XML_FILE);
    if (ivyFilePath.toFile().exists()) {
        StringBuilder builder = new StringBuilder();
        builder.append("${");
        builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
        builder.append(":");
        builder.append(projectName);
        builder.append("}/");
        builder.append(ISDKConstants.IVY_SETTINGS_XML_FILE);
        settingsSetup.setIvySettingsPath(builder.toString());
    }
    StringBuilder builder = new StringBuilder();
    builder.append("${");
    builder.append(ISDKConstants.VAR_NAME_LIFERAY_SDK_DIR);
    builder.append(":");
    builder.append(projectName);
    builder.append("}/.ivy");
    settingsSetup.setIvyUserDir(builder.toString());
    conf.setIvySettingsSetup(settingsSetup);
    final IPath path = conf.getPath();
    final IClasspathAttribute[] atts = conf.getAttributes();
    final IClasspathEntry ivyEntry = JavaCore.newContainerEntry(path, null, atts, false);
    final IVirtualComponent virtualComponent = ComponentCore.createComponent(project);
    try {
        IClasspathEntry[] entries = javaProject.getRawClasspath();
        List<IClasspathEntry> newEntries = new ArrayList<>(Arrays.asList(entries));
        IPath runtimePath = getDefaultRuntimePath(virtualComponent, ivyEntry);
        // add the deployment assembly config to deploy ivy container to /WEB-INF/lib
        final IClasspathEntry cpeTagged = modifyDependencyPath(ivyEntry, runtimePath);
        newEntries.add(cpeTagged);
        entries = (IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]);
        javaProject.setRawClasspath(entries, javaProject.getOutputLocation(), monitor);
        IvyClasspathContainer ivycp = IvyClasspathContainerHelper.getContainer(path, javaProject);
        return ivycp;
    } catch (JavaModelException jme) {
        ProjectUI.logError("Unable to add Ivy library container", jme);
    }
    return null;
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) ClasspathSetup(org.apache.ivyde.eclipse.cp.ClasspathSetup) IvyClasspathContainer(org.apache.ivyde.eclipse.cp.IvyClasspathContainer) IClasspathAttribute(org.eclipse.jdt.core.IClasspathAttribute) IJavaProject(org.eclipse.jdt.core.IJavaProject) SettingsSetup(org.apache.ivyde.eclipse.cp.SettingsSetup) IvyClasspathContainerConfiguration(org.apache.ivyde.eclipse.cp.IvyClasspathContainerConfiguration) SDK(com.liferay.ide.sdk.core.SDK) IVirtualComponent(org.eclipse.wst.common.componentcore.resources.IVirtualComponent)

Example 20 with SDK

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

the class SDKCommandAction method run.

@Override
public void run(IAction action) {
    if (fSelection instanceof IStructuredSelection) {
        Object[] elems = ((IStructuredSelection) fSelection).toArray();
        IFile buildXmlFile = null;
        IProject project = null;
        Object elem = elems[0];
        if (elem instanceof IFile) {
            buildXmlFile = (IFile) elem;
            project = buildXmlFile.getProject();
        } else if (elem instanceof IProject) {
            project = (IProject) elem;
            buildXmlFile = project.getFile("build.xml");
        }
        if (buildXmlFile.exists()) {
            final IProject p = project;
            final IFile buildFile = buildXmlFile;
            new Job(p.getName() + " : " + getSDKCommand()) {

                @Override
                protected IStatus run(IProgressMonitor monitor) {
                    try {
                        SDK sdk = SDKUtil.getSDK(p);
                        ILiferayProject liferayProject = LiferayCore.create(p);
                        if (liferayProject != null) {
                            sdk.runCommand(p, buildFile, getSDKCommand(), null, monitor);
                            p.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                        }
                    } catch (Exception e) {
                        return ProjectUI.createErrorStatus("Error running SDK command " + getSDKCommand(), e);
                    }
                    return Status.OK_STATUS;
                }
            }.schedule();
        }
    }
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) ILiferayProject(com.liferay.ide.core.ILiferayProject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SDK(com.liferay.ide.sdk.core.SDK) Job(org.eclipse.core.runtime.jobs.Job) IProject(org.eclipse.core.resources.IProject)

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