Search in sources :

Example 1 with ProjectName

use of com.liferay.ide.project.core.model.ProjectName 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 2 with ProjectName

use of com.liferay.ide.project.core.model.ProjectName in project liferay-ide by liferay.

the class GradleProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
    IStatus retval = Status.OK_STATUS;
    String projectName = op.getProjectName().content();
    IPath location = PathBridge.create(op.getLocation().content());
    String className = op.getComponentName().content();
    String serviceName = op.getServiceName().content();
    String packageName = op.getPackageName().content();
    ElementList<PropertyKey> propertyKeys = op.getPropertyKeys();
    List<String> properties = new ArrayList<>();
    for (PropertyKey propertyKey : propertyKeys) {
        properties.add(propertyKey.getName().content(true) + "=" + propertyKey.getValue().content(true));
    }
    File targetDir = location.toFile();
    targetDir.mkdirs();
    String projectTemplateName = op.getProjectTemplateName().content();
    StringBuilder sb = new StringBuilder();
    sb.append("create ");
    sb.append("-d \"");
    sb.append(targetDir.getAbsolutePath());
    sb.append("\" ");
    sb.append("-t ");
    sb.append(projectTemplateName);
    sb.append(" ");
    if (className != null) {
        sb.append("-c ");
        sb.append(className);
        sb.append(" ");
    }
    if (serviceName != null) {
        sb.append("-s ");
        sb.append(serviceName);
        sb.append(" ");
    }
    if (packageName != null) {
        sb.append("-p ");
        sb.append(packageName);
        sb.append(" ");
    }
    sb.append("\"");
    sb.append(projectName);
    sb.append("\" ");
    try {
        BladeCLI.execute(sb.toString());
        ElementList<ProjectName> projectNames = op.getProjectNames();
        projectNames.insert().setName(projectName);
        if (projectTemplateName.equals("service-builder")) {
            projectNames.insert().setName(projectName + "-api");
            projectNames.insert().setName(projectName + "-service");
        }
        IPath projectLocation = location;
        String lastSegment = location.lastSegment();
        if ((location != null) && (location.segmentCount() > 0)) {
            if (!lastSegment.equals(projectName)) {
                projectLocation = location.append(projectName);
            }
        }
        boolean hasGradleWorkspace = LiferayWorkspaceUtil.hasGradleWorkspace();
        boolean useDefaultLocation = op.getUseDefaultLocation().content(true);
        boolean inWorkspacePath = false;
        IProject liferayWorkspaceProject = LiferayWorkspaceUtil.getWorkspaceProject();
        if (hasGradleWorkspace && (liferayWorkspaceProject != null) && !useDefaultLocation) {
            IPath workspaceLocation = liferayWorkspaceProject.getLocation();
            if (workspaceLocation != null) {
                inWorkspacePath = workspaceLocation.isPrefixOf(projectLocation);
            }
        }
        if ((hasGradleWorkspace && useDefaultLocation) || inWorkspacePath) {
            GradleUtil.refreshGradleProject(liferayWorkspaceProject);
        } else {
            GradleUtil.importGradleProject(projectLocation.toFile(), monitor);
        }
    } catch (Exception e) {
        retval = GradleCore.createErrorStatus("can't create module project.", e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ProjectName(com.liferay.ide.project.core.model.ProjectName) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) File(java.io.File) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey)

Example 3 with ProjectName

use of com.liferay.ide.project.core.model.ProjectName in project liferay-ide by liferay.

the class LiferayMavenModuleProjectProvider method createNewProject.

@Override
public IStatus createNewProject(NewLiferayModuleProjectOp op, IProgressMonitor monitor) throws CoreException {
    IStatus retval = Status.OK_STATUS;
    String projectName = op.getProjectName().content();
    IPath location = PathBridge.create(op.getLocation().content());
    String className = op.getComponentName().content();
    String serviceName = op.getServiceName().content();
    String packageName = op.getPackageName().content();
    ElementList<PropertyKey> propertyKeys = op.getPropertyKeys();
    List<String> properties = new ArrayList<>();
    for (PropertyKey propertyKey : propertyKeys) {
        properties.add(propertyKey.getName().content(true) + "=" + propertyKey.getValue().content(true));
    }
    File targetDir = location.toFile();
    targetDir.mkdirs();
    String projectTemplateName = op.getProjectTemplateName().content();
    StringBuilder sb = new StringBuilder();
    sb.append("create ");
    sb.append("-d \"");
    sb.append(targetDir.getAbsolutePath());
    sb.append("\" ");
    sb.append("-b ");
    sb.append("maven ");
    sb.append("-t ");
    sb.append(projectTemplateName);
    sb.append(" ");
    if (className != null) {
        sb.append("-c ");
        sb.append(className);
        sb.append(" ");
    }
    if (serviceName != null) {
        sb.append("-s ");
        sb.append(serviceName);
        sb.append(" ");
    }
    if (packageName != null) {
        sb.append("-p ");
        sb.append(packageName);
        sb.append(" ");
    }
    sb.append("\"");
    sb.append(projectName);
    sb.append("\" ");
    try {
        BladeCLI.execute(sb.toString());
        ElementList<ProjectName> projectNames = op.getProjectNames();
        projectNames.insert().setName(projectName);
        if (projectTemplateName.equals("service-builder")) {
            projectNames.insert().setName(projectName + "-api");
            projectNames.insert().setName(projectName + "-service");
        }
        IPath projectLocation = location;
        String lastSegment = location.lastSegment();
        if ((location != null) && (location.segmentCount() > 0)) {
            if (!lastSegment.equals(projectName)) {
                projectLocation = location.append(projectName);
            }
        }
        MavenUtil.importProject(projectLocation.toPortableString(), monitor);
    } catch (Exception e) {
        retval = ProjectCore.createErrorStatus("can't create module project.", e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) ProjectName(com.liferay.ide.project.core.model.ProjectName) ArrayList(java.util.ArrayList) File(java.io.File) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey) CoreException(org.eclipse.core.runtime.CoreException)

Example 4 with ProjectName

use of com.liferay.ide.project.core.model.ProjectName in project liferay-ide by liferay.

the class NewLiferayModuleProjectWizard method performPostFinish.

@Override
protected void performPostFinish() {
    super.performPostFinish();
    final List<IProject> projects = new ArrayList<>();
    final NewLiferayModuleProjectOp op = element().nearest(NewLiferayModuleProjectOp.class);
    ElementList<ProjectName> projectNames = op.getProjectNames();
    for (ProjectName projectName : projectNames) {
        final IProject newProject = CoreUtil.getProject(projectName.getName().content());
        if (newProject != null) {
            projects.add(newProject);
        }
    }
    for (final IProject project : projects) {
        try {
            addToWorkingSets(project);
        } catch (Exception ex) {
            ProjectUI.logError("Unable to add project to working set", ex);
        }
    }
    if (ListUtil.isNotEmpty(projects)) {
        IProject finalProject = projects.get(0);
        openLiferayPerspective(finalProject);
    }
}
Also used : ProjectName(com.liferay.ide.project.core.model.ProjectName) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject)

Example 5 with ProjectName

use of com.liferay.ide.project.core.model.ProjectName in project liferay-ide by liferay.

the class NewLiferayPluginProjectWizard method performPostFinish.

@Override
protected void performPostFinish() {
    super.performPostFinish();
    final List<IProject> projects = new ArrayList<>();
    final NewLiferayPluginProjectOp op = element().nearest(NewLiferayPluginProjectOp.class);
    ElementList<ProjectName> projectNames = op.getProjectNames();
    for (ProjectName projectName : projectNames) {
        final IProject newProject = CoreUtil.getProject(projectName.getName().content());
        if (newProject != null) {
            projects.add(newProject);
        }
    }
    for (final IProject project : projects) {
        try {
            addToWorkingSets(project);
        } catch (Exception ex) {
            ProjectUI.logError("Unable to add project to working set", ex);
        }
    }
    final IProject finalProject = projects.get(0);
    openLiferayPerspective(finalProject);
    _showInAntView(finalProject);
    checkAndConfigureIvy(finalProject);
    // check if a new portlet wizard is needed, available for portlet projects.
    final boolean createNewPortlet = op.getCreateNewPortlet().content();
    if (createNewPortlet && PluginType.portlet.equals(op.getPluginType().content())) {
        final IPortletFramework portletFramework = op.getPortletFramework().content();
        String wizardId = null;
        if ("mvc".equals(portletFramework.getShortName())) {
            wizardId = "com.liferay.ide.portlet.ui.newPortletWizard";
        } else if ("jsf-2.x".equals(portletFramework.getShortName())) {
            wizardId = "com.liferay.ide.portlet.ui.newJSFPortletWizard";
        } else if ("vaadin".equals(portletFramework.getShortName())) {
            wizardId = "com.liferay.ide.portlet.vaadin.ui.newVaadinPortletWizard";
        }
        if (wizardId != null) {
            _openNewPortletWizard(wizardId, finalProject);
        }
    }
}
Also used : IPortletFramework(com.liferay.ide.project.core.IPortletFramework) ProjectName(com.liferay.ide.project.core.model.ProjectName) ArrayList(java.util.ArrayList) NewLiferayPluginProjectOp(com.liferay.ide.project.core.model.NewLiferayPluginProjectOp) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException)

Aggregations

ProjectName (com.liferay.ide.project.core.model.ProjectName)7 ArrayList (java.util.ArrayList)6 IProject (org.eclipse.core.resources.IProject)6 CoreException (org.eclipse.core.runtime.CoreException)5 File (java.io.File)4 IPath (org.eclipse.core.runtime.IPath)4 IStatus (org.eclipse.core.runtime.IStatus)3 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)2 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)2 PluginType (com.liferay.ide.project.core.model.PluginType)2 PropertyKey (com.liferay.ide.project.core.modules.PropertyKey)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 NewLiferayProfile (com.liferay.ide.project.core.model.NewLiferayProfile)1 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)1 SDK (com.liferay.ide.sdk.core.SDK)1 PortalBundle (com.liferay.ide.server.core.portal.PortalBundle)1 Properties (java.util.Properties)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1