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;
}
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());
}
}
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\""));
}
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"));
}
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;
}
Aggregations