use of com.liferay.ide.project.core.model.PluginType 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;
}
use of com.liferay.ide.project.core.model.PluginType in project liferay-ide by liferay.
the class ArchetypeDefaultValueService method compute.
@Override
protected String compute() {
NewLiferayPluginProjectOp op = _op();
PluginType pluginType = op.getPluginType().content();
String frameworkType = null;
if (pluginType.equals(PluginType.portlet)) {
IPortletFramework portletFramework = op.getPortletFramework().content();
if (portletFramework.isRequiresAdvanced()) {
IPortletFramework framework = op.getPortletFrameworkAdvanced().content();
frameworkType = framework.getShortName();
} else {
frameworkType = portletFramework.getShortName();
}
} else {
frameworkType = pluginType.name();
}
frameworkType = frameworkType.replaceAll("_", "-");
NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
return provider.getData("archetypeGAV", String.class, frameworkType).get(0);
}
use of com.liferay.ide.project.core.model.PluginType in project liferay-ide by liferay.
the class ProjectUtil method createNewSDKProject.
public static IProject createNewSDKProject(ProjectRecord projectRecord, IPath sdkLocation, IProgressMonitor monitor, NewLiferayPluginProjectOp op) throws CoreException {
IDataModel newProjectDataModel = DataModelFactory.createDataModel(new PluginFacetProjectCreationDataModelProvider());
// we are importing so set flag to not create anything
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.CREATE_PROJECT_OPERATION, false);
IDataModel nestedModel = newProjectDataModel.getNestedModel(IPluginProjectDataModelProperties.NESTED_PROJECT_DM);
// using sdk location
nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, true);
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_SDK_LOCATION, false);
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_WORKSPACE_LOCATION, true);
setGenerateDD(newProjectDataModel, false);
IPath webXmlPath = projectRecord.getProjectLocation().append(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/web.xml");
File webXmlFile = webXmlPath.toFile();
if (projectRecord.getProjectName().endsWith(ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_PORTLET, true);
if (FileUtil.notExists(webXmlFile)) {
createDefaultWebXml(webXmlFile, projectRecord.getProjectName());
}
} else if (projectRecord.getProjectName().endsWith(ISDKConstants.HOOK_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_HOOK, true);
if (FileUtil.notExists(webXmlFile)) {
createDefaultWebXml(webXmlFile, projectRecord.getProjectName());
}
} else if (projectRecord.getProjectName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
Path path = new Path(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/ext-web/docroot/WEB-INF/web.xml");
webXmlPath = webXmlPath.removeLastSegments(3).append(path);
webXmlFile = webXmlPath.toFile();
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_EXT, true);
if (FileUtil.notExists(webXmlFile)) {
createDefaultWebXml(webXmlPath.toFile(), projectRecord.getProjectName());
}
} else if (projectRecord.getProjectName().endsWith(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_LAYOUTTPL, true);
} else if (projectRecord.getProjectName().endsWith(ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_THEME, true);
} else if (projectRecord.getProjectName().endsWith(ISDKConstants.WEB_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_WEB, true);
}
IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy) newProjectDataModel.getProperty(IFacetProjectCreationDataModelProperties.FACETED_PROJECT_WORKING_COPY);
fpwc.setProjectName(projectRecord.getProjectName());
IPath projectLocation = projectRecord.getProjectLocation();
String projectDirName = projectLocation.lastSegment();
// for now always set a project location (so it can be used by facet install methods) may be unset later
fpwc.setProjectLocation(projectRecord.getProjectLocation());
String pluginType = null;
if (op != null) {
PluginType type = op.getPluginType().content();
pluginType = type.name();
if (PluginType.theme.name().equals(pluginType)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_PARENT, op.getThemeParent().content(true));
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_TEMPLATE_FRAMEWORK, op.getThemeFramework().content(true));
}
} else {
pluginType = guessPluginType(fpwc);
}
SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), projectRecord);
if ((op != null) && PluginType.portlet.name().equals(pluginType)) {
IPortletFramework portletFramework = op.getPortletFramework().content(true);
portletFramework.configureNewProject(newProjectDataModel, fpwc);
}
// if project is located in natural workspace location then don't need to set a project location
IPath rootLocation = CoreUtil.getWorkspaceRoot().getLocation();
if (rootLocation.append(projectDirName).equals(projectLocation)) {
fpwc.setProjectLocation(null);
}
fpwc.commitChanges(monitor);
CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);
SDKUtil.openAsProject(sdk);
}
}, monitor);
return fpwc.getProject();
}
use of com.liferay.ide.project.core.model.PluginType in project liferay-ide by liferay.
the class PluginTypeValidationService method compute.
@Override
protected Status compute() {
Status retval = Status.createOkStatus();
NewLiferayPluginProjectOp op = _op();
try {
SDK sdk = SDKUtil.getWorkspaceSDK();
if (sdk == null) {
Path sdkLocation = op.getSdkLocation().content();
if (sdkLocation != null) {
sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
}
}
PluginType pluginType = op.getPluginType().content();
if (sdk != null) {
if (pluginType.equals(PluginType.web) && !supportsTypePlugin(op, "web")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating new web type plugins. ");
sb.append("");
sb.append("Please configure version 7.0 or greater.");
return Status.createErrorStatus(sb.toString());
} else if (pluginType.equals(PluginType.theme) && !supportsTypePlugin(op, "theme")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating theme type plugins. ");
sb.append("");
sb.append("Please configure version 6.2 or less or using gulp way.");
return Status.createErrorStatus(sb.toString());
} else if (pluginType.equals(PluginType.ext) && !supportsTypePlugin(op, "ext")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating ext type plugins. ");
sb.append("");
sb.append("Please try to confirm whether sdk has ext folder.");
return Status.createErrorStatus(sb.toString());
}
} else if (pluginType.equals(PluginType.ext) && !supportsTypePlugin(op, "ext")) {
retval = Status.createErrorStatus("New ext plugins with maven build type are no longer supported.");
}
} catch (CoreException ce) {
}
return retval;
}
use of com.liferay.ide.project.core.model.PluginType in project liferay-ide by liferay.
the class SDKLocationValidationService method compute.
@Override
protected Status compute() {
NewLiferayPluginProjectOp op = _op();
NewLiferayProjectProvider<NewLiferayPluginProjectOp> provider = op.getProjectProvider().content();
if (!provider.getShortName().equals("ant")) {
return Status.createOkStatus();
}
int countPossibleWorkspaceSDKProjects = SDKUtil.countPossibleWorkspaceSDKProjects();
if (countPossibleWorkspaceSDKProjects > 1) {
return StatusBridge.create(ProjectCore.createErrorStatus("This workspace has more than one SDK."));
}
Path sdkLocation = op.getSdkLocation().content(true);
if ((sdkLocation == null) || sdkLocation.isEmpty()) {
return StatusBridge.create(ProjectCore.createErrorStatus("This sdk location is empty."));
}
SDK sdk = SDKUtil.createSDKFromLocation(PathBridge.create(sdkLocation));
if (sdk != null) {
IStatus status = sdk.validate(true);
if (!status.isOK()) {
return StatusBridge.create(status);
}
} else {
return StatusBridge.create(ProjectCore.createErrorStatus("This sdk location is not correct."));
}
Path projectLocation = op.getLocation().content();
String projectName = op.getProjectName().content();
IPath projectPath = PathBridge.create(projectLocation);
if (FileUtil.exists(projectPath)) {
return StatusBridge.create(ProjectCore.createErrorStatus("Project(" + projectName + ") is existed in sdk folder, please set new project name."));
}
PluginType pluginType = op.getPluginType().content();
if (pluginType.equals(PluginType.web) && !supportsTypePlugin(op, "web")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating new web type plugins. ");
sb.append("");
sb.append("Please configure version 7.0 or greater.");
return Status.createErrorStatus(sb.toString());
} else if (pluginType.equals(PluginType.theme) && !supportsTypePlugin(op, "theme")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating theme type plugins. ");
sb.append("");
sb.append("Please configure version 6.2 or less or using gulp way.");
return Status.createErrorStatus(sb.toString());
} else if (pluginType.equals(PluginType.portlet)) {
IPortletFramework portletFramework = op.getPortletFramework().content();
Version requiredVersion = new Version(portletFramework.getRequiredSDKVersion());
Version sdkVersion = new Version(sdk.getVersion());
if (CoreUtil.compareVersions(requiredVersion, sdkVersion) > 0) {
StringBuilder sb = new StringBuilder();
sb.append("Selected portlet framework requires SDK version at least ");
sb.append("");
sb.append(requiredVersion);
return Status.createErrorStatus(sb.toString());
}
} else if (pluginType.equals(PluginType.ext) && !supportsTypePlugin(op, "ext")) {
StringBuilder sb = new StringBuilder();
sb.append("The selected Plugins SDK does not support creating ext type plugins. ");
sb.append("");
sb.append("Please try to confirm whether sdk has ext folder.");
return Status.createErrorStatus(sb.toString());
}
return Status.createOkStatus();
}
Aggregations