Search in sources :

Example 1 with PropertyKey

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

use of com.liferay.ide.project.core.modules.PropertyKey in project liferay-ide by liferay.

the class AbstractLiferayComponentTemplate method initializeOperation.

protected void initializeOperation(NewLiferayComponentOp op) {
    projectName = op.getProjectName().content(true);
    packageName = op.getPackageName().content(true);
    componentClassName = op.getComponentClassName().content(true);
    IComponentTemplate<NewLiferayComponentOp> componentTemplate = op.getComponentClassTemplateName().content(true);
    templateName = componentTemplate.getShortName();
    serviceName = op.getServiceName().content(true);
    modelClass = op.getModelClass().content(true);
    componentNameWithoutTemplateName = componentClassName.replace(templateName, "");
    if (modelClass != null) {
        int modeClassPos = modelClass.lastIndexOf(".");
        simpleModelClass = modelClass.substring(modeClassPos + 1);
    }
    ElementList<PropertyKey> propertyKeys = op.getPropertyKeys();
    for (int i = 0; i < propertyKeys.size(); i++) {
        PropertyKey propertyKey = propertyKeys.get(i);
        StringBuilder sb = new StringBuilder();
        sb.append(propertyKey.getName().content(true));
        sb.append("=");
        sb.append(propertyKey.getValue().content(true));
        if (i != (propertyKeys.size() - 1)) {
            sb.append(",");
        } else {
            sb.append("");
        }
        properties.add(sb.toString());
    }
}
Also used : NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey)

Example 3 with PropertyKey

use of com.liferay.ide.project.core.modules.PropertyKey in project liferay-ide by liferay.

the class NewLiferayModuleProjectOpTests method testNewLiferayModuleProjectNewProperties.

@Test
public void testNewLiferayModuleProjectNewProperties() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();
    op.setProjectName("test-properties-in-portlet");
    op.setProjectTemplateName("portlet");
    op.setComponentName("Test");
    PropertyKey pk = op.getPropertyKeys().insert();
    pk.setName("property-test-key");
    pk.setValue("property-test-value");
    Status exStatus = NewLiferayModuleProjectOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertEquals("OK", exStatus.message());
    IProject modPorject = CoreUtil.getProject(op.getProjectName().content());
    modPorject.open(new NullProgressMonitor());
    SearchFilesVisitor sv = new SearchFilesVisitor();
    List<IFile> searchFiles = sv.searchFiles(modPorject, "TestPortlet.java");
    IFile componentClassFile = searchFiles.get(0);
    assertEquals(componentClassFile.exists(), true);
    String actual = CoreUtil.readStreamToString(componentClassFile.getContents());
    assertTrue(actual, actual.contains("\"property-test-key=property-test-value\""));
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) SearchFilesVisitor(com.liferay.ide.project.core.util.SearchFilesVisitor) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 4 with PropertyKey

use of com.liferay.ide.project.core.modules.PropertyKey in project liferay-ide by liferay.

the class NewLiferayModuleProjectOpTests method testNewLiferayPortletProviderNewProperties.

@Test
public void testNewLiferayPortletProviderNewProperties() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();
    op.setProjectName("test-properties-in-portlet-provider");
    op.setComponentName("Test");
    op.setProjectTemplateName("portlet-provider");
    PropertyKey pk = op.getPropertyKeys().insert();
    pk.setName("property-test-key");
    pk.setValue("property-test-value");
    Status exStatus = NewLiferayModuleProjectOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertTrue(exStatus.message(), exStatus.ok());
    IProject modPorject = CoreUtil.getProject(op.getProjectName().content());
    modPorject.open(new NullProgressMonitor());
    IFile testAddPortletProvider = modPorject.getFile("src/main/java/test/properties/in/portlet/provider/portlet/TestAddPortletProvider.java");
    assertTrue(testAddPortletProvider.exists());
    SearchFilesVisitor sv = new SearchFilesVisitor();
    List<IFile> searchFiles = sv.searchFiles(modPorject, "TestAddPortletProvider.java");
    IFile componentClassFile = searchFiles.get(0);
    assertEquals(componentClassFile.exists(), true);
    String actual = CoreUtil.readStreamToString(componentClassFile.getContents());
    assertTrue(actual.contains("property-test-key=property-test-value"));
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) SearchFilesVisitor(com.liferay.ide.project.core.util.SearchFilesVisitor) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 5 with PropertyKey

use of com.liferay.ide.project.core.modules.PropertyKey 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)

Aggregations

PropertyKey (com.liferay.ide.project.core.modules.PropertyKey)6 IProject (org.eclipse.core.resources.IProject)4 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)3 SearchFilesVisitor (com.liferay.ide.project.core.util.SearchFilesVisitor)3 IFile (org.eclipse.core.resources.IFile)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 Status (org.eclipse.sapphire.modeling.Status)3 Test (org.junit.Test)3 ProjectName (com.liferay.ide.project.core.model.ProjectName)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 NewLiferayComponentOp (com.liferay.ide.project.core.modules.NewLiferayComponentOp)1