use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.
the class ImportLiferayWorkspaceOpMethods method execute.
public static Status execute(ImportLiferayWorkspaceOp op, ProgressMonitor pm) {
IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
monitor.beginTask("Importing Liferay Workspace project...", 100);
Status retval = null;
try {
op.setProjectProvider(op.getBuildType().content());
NewLiferayWorkspaceProjectProvider<NewLiferayWorkspaceOp> provider = op.getProjectProvider().content(true);
org.eclipse.sapphire.modeling.Path workspaceLocation = op.getWorkspaceLocation().content();
String location = workspaceLocation.toOSString();
LiferayWorkspaceUtil.clearWorkspace(location);
boolean initBundle = op.getProvisionLiferayBundle().content();
boolean hasBundlesDir = op.getHasBundlesDir().content();
String bundleUrl = op.getBundleUrl().content(false);
IStatus importStatus;
if (initBundle && !hasBundlesDir) {
importStatus = provider.importProject(location, monitor, true, bundleUrl);
} else {
importStatus = provider.importProject(location, monitor, false, null);
}
retval = StatusBridge.create(importStatus);
if (!retval.ok() || (retval.exception() != null)) {
return retval;
}
if (initBundle || hasBundlesDir) {
String serverRuntimeName = op.getServerName().content();
IPath bundlesLocation = null;
String buildType = op.getBuildType().content();
if (buildType.equals("gradle-liferay-workspace")) {
bundlesLocation = LiferayWorkspaceUtil.getHomeLocation(location);
} else {
bundlesLocation = new Path(location).append("bundles");
}
if ((bundlesLocation != null) && bundlesLocation.toFile().exists()) {
ServerUtil.addPortalRuntimeAndServer(serverRuntimeName, bundlesLocation, monitor);
}
}
} catch (Exception e) {
String msg = "import Liferay Workspace project error";
ProjectCore.logError(msg, e);
retval = Status.createErrorStatus(msg, e);
}
return retval;
}
use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.
the class ImportWorkspaceLocationValidationService method compute.
@Override
protected Status compute() {
Status retval = Status.createOkStatus();
try {
if (LiferayWorkspaceUtil.hasWorkspace()) {
return Status.createErrorStatus(LiferayWorkspaceUtil.hasLiferayWorkspaceMsg);
}
} catch (CoreException ce) {
return Status.createErrorStatus(LiferayWorkspaceUtil.multiWorkspaceErrorMsg);
}
Value<Path> workspaceLocation = _op().getWorkspaceLocation();
Path currentProjectLocation = workspaceLocation.content(true);
if ((currentProjectLocation != null) && !currentProjectLocation.isEmpty()) {
String currentPath = currentProjectLocation.toOSString();
IStatus validPathStatus = ProjectImportUtil.validatePath(currentPath);
if (!validPathStatus.isOK()) {
return Status.createErrorStatus(validPathStatus.getMessage());
}
if (LiferayWorkspaceUtil.getWorkspaceType(currentPath) == null) {
return Status.createErrorStatus("Invalid Liferay Workspace");
}
String projectName = currentProjectLocation.lastSegment();
if (CoreUtil.getProject(projectName).exists()) {
return Status.createErrorStatus("A project with that name already exists.");
}
}
return retval;
}
use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.
the class NewLiferayWorkspaceOpMethods method execute.
public static Status execute(NewLiferayWorkspaceOp op, ProgressMonitor pm) {
IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
monitor.beginTask("Creating Liferay Workspace project...", 100);
Status retval = null;
try {
String wsName = op.getWorkspaceName().content();
NewLiferayProjectProvider<NewLiferayWorkspaceOp> provider = op.getProjectProvider().content(true);
IStatus status = provider.createNewProject(op, monitor);
retval = StatusBridge.create(status);
if (!retval.ok()) {
return retval;
}
org.eclipse.sapphire.modeling.Path parent = op.getLocation().content();
String location = parent.append(wsName).toPortableString();
boolean initBundle = op.getProvisionLiferayBundle().content();
if (initBundle) {
String serverRuntimeName = op.getServerName().content();
IPath bundlesLocation = null;
String projectProvider = op.getProjectProvider().text();
if (projectProvider.equals("gradle-liferay-workspace")) {
bundlesLocation = LiferayWorkspaceUtil.getHomeLocation(location);
} else {
bundlesLocation = new Path(location).append("bundles");
}
if (bundlesLocation.toFile().exists()) {
ServerUtil.addPortalRuntimeAndServer(serverRuntimeName, bundlesLocation, monitor);
}
}
} catch (Exception e) {
String msg = "Error creating Liferay Workspace project.";
ProjectCore.logError(msg, e);
return Status.createErrorStatus(msg, e);
}
if (retval.ok()) {
_updateBuildPrefs(op);
}
return retval;
}
use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.
the class NewLiferayComponentOpTests method testNewLiferayComponentActionCommandPortlet.
@Test
public void testNewLiferayComponentActionCommandPortlet() throws Exception {
NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();
op.setProjectName("action-command-test");
op.setProjectTemplateName("activator");
op.setProjectProvider("gradle-module");
Status modulePorjectStatus = NewLiferayModuleProjectOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
assertTrue(modulePorjectStatus.ok());
IProject modProject = CoreUtil.getProject(op.getProjectName().content());
modProject.open(new NullProgressMonitor());
NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
cop.setProjectName(op.getProjectName().content());
cop.setComponentClassTemplateName("PortletActionCommand");
Status status = NewLiferayComponentOpMethods.execute(cop, ProgressMonitorBridge.create(new NullProgressMonitor()));
assertEquals(Status.createOkStatus(), status);
IFile javaFile = modProject.getFile("/src/main/java/action/command/test/ActionCommandTestActionCommand.java");
assertTrue(javaFile.exists());
String javaFileContent = FileUtil.readContents(javaFile.getLocation().toFile(), true);
assertTrue(javaFileContent.contains("javax.portlet.name=action_command_test_ActionCommandTestPortlet"));
assertTrue(javaFileContent.contains("mvc.command.name=greet"));
IFile initFile = modProject.getFile("/src/main/resources/META-INF/resources/actioncommandtestportletactioncommand/init.ftl");
assertTrue(initFile.exists());
IFile viewFile = modProject.getFile("/src/main/resources/META-INF/resources/actioncommandtestportletactioncommand/view.ftl");
assertTrue(viewFile.exists());
}
use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.
the class NewLiferayComponentOpTests method testNewLiferayComponentProjectValidation.
@Test
public void testNewLiferayComponentProjectValidation() throws Exception {
deleteAllWorkspaceProjects();
NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
Status projectValidationStatus = cop.getProjectName().validation();
assertEquals("No suitable Liferay module project.", projectValidationStatus.message());
NewLiferayModuleProjectOp pop = NewLiferayModuleProjectOp.TYPE.instantiate();
pop.setProjectName("testProjectValidation");
pop.setProjectTemplateName("portlet");
pop.setProjectProvider("gradle-module");
Status moduleProjectStatus = NewLiferayModuleProjectOpMethods.execute(pop, ProgressMonitorBridge.create(new NullProgressMonitor()));
assertTrue(moduleProjectStatus.ok());
IProject modProject = CoreUtil.getProject(pop.getProjectName().content());
modProject.open(new NullProgressMonitor());
IFile bndFile = modProject.getFile("bnd.bnd");
bndFile.delete(true, true, new NullProgressMonitor());
cop.setProjectName(pop.getProjectName().content());
projectValidationStatus = cop.getProjectName().validation();
assertEquals("Can't find bnd.bnd file in the project.", projectValidationStatus.message());
}
Aggregations