Search in sources :

Example 1 with SDK

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

the class PortalDeployExcludesSection method createJarsArray.

protected void createJarsArray() {
    _fJars = new Vector<>();
    PluginPackageModel model = (PluginPackageModel) getPage().getModel();
    String[] excludeJars = model.getPortalDeloyExcludesJars();
    IProject project = getProject();
    IFolder docroot = CoreUtil.getDefaultDocrootFolder(project);
    if ((docroot == null) || ProjectUtil.isMavenProject(project) || ProjectUtil.isExtProject(project)) {
        TablePart tablePart = getTablePart();
        tablePart.setButtonEnabled(_ADD_INDEX, false);
        return;
    }
    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 excludeJarPath = sdkLocation.append(type).append(docroot.getFullPath());
    if (excludeJarPath != null) {
        for (String excludeJar : excludeJars) {
            if (excludeJar.startsWith("**/WEB-INF/lib/")) {
                excludeJar = excludeJar.substring(excludeJar.lastIndexOf("/"));
            }
            File jarFile = new File(excludeJarPath.append("WEB-INF/lib").toFile(), excludeJar.trim());
            if (jarFile.isFile() && jarFile.exists()) {
                _fJars.add(jarFile);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) PluginPackageModel(com.liferay.ide.portlet.core.PluginPackageModel) IPluginPackageModel(com.liferay.ide.portlet.core.IPluginPackageModel) TablePart(com.liferay.ide.ui.form.TablePart) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with SDK

use of com.liferay.ide.sdk.core.SDK 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 3 with SDK

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

the class PluginsSDKRuntimeProject method getSDK.

protected SDK getSDK() {
    SDK retval = null;
    // try to determine SDK based on project location
    IPath path = getProject().getRawLocation();
    IPath sdkLocation = path.removeLastSegments(2);
    retval = SDKManager.getInstance().getSDK(sdkLocation);
    if (retval == null) {
        retval = SDKUtil.createSDKFromLocation(sdkLocation);
        SDKManager.getInstance().addSDK(retval);
    }
    return retval;
}
Also used : IPath(org.eclipse.core.runtime.IPath) SDK(com.liferay.ide.sdk.core.SDK)

Example 4 with SDK

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

the class PluginsSDKRuntimeProject method getOutputs.

public Collection<IFile> getOutputs(boolean build, IProgressMonitor monitor) throws CoreException {
    Collection<IFile> outputs = new HashSet<>();
    if (build) {
        getProject().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor);
        SDK sdk = SDKUtil.getSDK(getProject());
        IStatus warStatus = sdk.war(getProject(), null, true, monitor);
        if (warStatus.isOK()) {
        }
    }
    return outputs;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) SDK(com.liferay.ide.sdk.core.SDK) HashSet(java.util.HashSet)

Example 5 with SDK

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

the class SDKBuildPropertiesResourceListener method processPropertiesFileChanged.

protected void processPropertiesFileChanged(IFile deltaFile) throws CoreException {
    IProject deltaProject = deltaFile.getProject();
    SDK sdk = SDKUtil.createSDKFromLocation(deltaProject.getLocation());
    if (sdk == null) {
        return;
    }
    IMarker[] problemMarkers = MarkerUtil.findMarkers(deltaFile.getProject(), IMarker.PROBLEM, _MARKER_ID_SDK_PROPERTIES_INVALID);
    IStatus sdkStatus = sdk.validate(true);
    if (sdkStatus.isOK()) {
        if (ListUtil.isNotEmpty(problemMarkers)) {
            MarkerUtil.clearMarkers(deltaFile.getProject(), IMarker.PROBLEM, _MARKER_ID_SDK_PROPERTIES_INVALID);
        }
        for (IProject project : CoreUtil.getAllProjects()) {
            if (SDKUtil.isSDKProject(project) && sdk.getLocation().isPrefixOf(project.getLocation())) {
                Job job = new WorkspaceJob("Updating dependencies " + project.getName()) {

                    @Override
                    public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
                        ClasspathUtil.updateRequestContainer(project);
                        return Status.OK_STATUS;
                    }
                };
                job.schedule();
            }
        }
    } else {
        IStatus[] statuses = sdkStatus.getChildren();
        for (IMarker marker : problemMarkers) {
            boolean canDelete = true;
            String message = (String) marker.getAttribute(IMarker.MESSAGE);
            for (IStatus status : statuses) {
                if (status.getMessage().equals(message)) {
                    canDelete = false;
                    break;
                }
            }
            if (canDelete) {
                marker.delete();
            }
        }
        for (IStatus status : statuses) {
            boolean canAdd = true;
            for (IMarker marker : problemMarkers) {
                if (marker.exists()) {
                    String message = (String) marker.getAttribute(IMarker.MESSAGE);
                    if (status.getMessage().equals(message)) {
                        canAdd = false;
                        break;
                    }
                }
            }
            if (canAdd) {
                MarkerUtil.setMarker(deltaFile, IMarker.PROBLEM, IMarker.SEVERITY_ERROR, status.getMessage(), deltaFile.getFullPath().toPortableString(), _MARKER_ID_SDK_PROPERTIES_INVALID);
            }
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) SDK(com.liferay.ide.sdk.core.SDK) IMarker(org.eclipse.core.resources.IMarker) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) 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