use of com.liferay.ide.project.core.IPortletFramework in project liferay-ide by liferay.
the class ProjectUtil method createNewSDKProject.
public static IProject createNewSDKProject(ProjectRecord projectRecord, IRuntime runtime, String sdkLocation, NewLiferayPluginProjectOp op, IProgressMonitor monitor) 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);
if (op != null) {
if (op.getUseDefaultLocation().content(true)) {
// using Eclipse workspace location
nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, true);
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_SDK_LOCATION, false);
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_WORKSPACE_LOCATION, true);
} else {
nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, false);
org.eclipse.sapphire.modeling.Path path = op.getLocation().content(true);
nestedModel.setStringProperty(IPluginProjectDataModelProperties.USER_DEFINED_LOCATION, path.toOSString());
if (!op.getUseDefaultLocation().content(true)) {
newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_CUSTOM_LOCATION, true);
}
}
}
setGenerateDD(newProjectDataModel, false);
IPath webXmlPath = projectRecord.getProjectLocation().append(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/web.xml");
String projectName = projectRecord.getProjectName();
if (projectName.endsWith(ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_PORTLET, true);
if (!(webXmlPath.toFile().exists())) {
createDefaultWebXml(webXmlPath.toFile(), projectRecord.getProjectName());
}
} else if (projectName.endsWith(ISDKConstants.HOOK_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_HOOK, true);
if (!(webXmlPath.toFile().exists())) {
createDefaultWebXml(webXmlPath.toFile(), projectName);
}
} else if (projectName.endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
Path webPath = new Path(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/ext-web/docroot/WEB-INF/web.xml");
webXmlPath = webXmlPath.removeLastSegments(3).append(webPath);
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_EXT, true);
if (!(webXmlPath.toFile().exists())) {
createDefaultWebXml(webXmlPath.toFile(), projectName);
}
} else if (projectName.endsWith(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_LAYOUTTPL, true);
} else if (projectName.endsWith(ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX)) {
newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_THEME, true);
} else if (projectName.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(projectName);
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.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, projectRecord);
String portlet = PluginType.portlet.name();
if ((op != null) && portlet.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 workspaceLocation = CoreUtil.getWorkspaceRoot().getLocation();
if (workspaceLocation.append(projectDirName).equals(projectLocation)) {
fpwc.setProjectLocation(null);
}
fpwc.commitChanges(monitor);
return fpwc.getProject();
}
use of com.liferay.ide.project.core.IPortletFramework in project liferay-ide by liferay.
the class NewLiferayPluginProjectOpBase method testPortletFrameworkValueLabel.
@Test
public void testPortletFrameworkValueLabel() throws Exception {
if (shouldSkipBundleTests())
return;
final NewLiferayPluginProjectOp op = newProjectOp("test-portlet-framework-value-label");
final ValueLabelService vls = op.getPortletFramework().service(ValueLabelService.class);
Set<String> acturalLables = new HashSet<String>();
for (IPortletFramework pf : ProjectCore.getPortletFrameworks()) {
acturalLables.add(vls.provide(pf.getShortName()));
}
assertNotNull(acturalLables);
Set<String> exceptedLables = new HashSet<String>();
exceptedLables.add("Liferay MVC");
exceptedLables.add("JSF 2.x");
exceptedLables.add("Vaadin");
exceptedLables.add("JSF standard");
exceptedLables.add("ICEfaces");
exceptedLables.add("Liferay Faces Alloy");
exceptedLables.add("PrimeFaces");
exceptedLables.add("RichFaces");
exceptedLables.add("Spring MVC");
assertEquals(true, exceptedLables.containsAll(acturalLables));
assertEquals(true, acturalLables.containsAll(exceptedLables));
}
use of com.liferay.ide.project.core.IPortletFramework 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);
}
}
}
use of com.liferay.ide.project.core.IPortletFramework in project liferay-ide by liferay.
the class NewLiferayPluginProjectMavenTests method testPortletFrameworkValidation.
@Test
@Ignore
public void testPortletFrameworkValidation() throws Exception {
if (shouldSkipBundleTests())
return;
NewLiferayPluginProjectOp op = newProjectOp("test-portlet-framework-validation");
op.setPluginType("portlet");
final ValidationService vs = op.getPortletFramework().service(ValidationService.class);
assertEquals(true, vs.validation().ok());
final SDK newSDK = createNewSDK();
newSDK.setVersion("6.0.0");
final IPortletFramework jsf = ProjectCore.getPortletFramework("jsf");
op.setProjectProvider("ant");
op.setPortletFramework("jsf");
assertEquals("Selected portlet framework requires SDK version at least " + jsf.getRequiredSDKVersion(), vs.validation().message());
// Value is not excepted.
/*
* assertEquals( "Selected portlet framework requires SDK version at least " + jsf.getRequiredSDKVersion(),
* op.getPortletFramework().validation().message() );
*/
}
use of com.liferay.ide.project.core.IPortletFramework in project liferay-ide by liferay.
the class NewMavenPluginProjectProvider method createNewProject.
@Override
public IStatus createNewProject(NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
ElementList<ProjectName> projectNames = op.getProjectNames();
IStatus retval = null;
IMavenConfiguration mavenConfiguration = MavenPlugin.getMavenConfiguration();
IMavenProjectRegistry mavenProjectRegistry = MavenPlugin.getMavenProjectRegistry();
IProjectConfigurationManager projectConfigurationManager = MavenPlugin.getProjectConfigurationManager();
String groupId = op.getGroupId().content();
String artifactId = op.getProjectName().content();
String version = op.getArtifactVersion().content();
String javaPackage = op.getGroupId().content();
String activeProfilesValue = op.getActiveProfilesValue().content();
IPortletFramework portletFramework = op.getPortletFramework().content(true);
String frameworkName = NewLiferayPluginProjectOpMethods.getFrameworkName(op);
IPath location = PathBridge.create(op.getLocation().content());
if (location.lastSegment().equals(artifactId)) {
// use parent dir since maven archetype will generate new dir under this
// location
location = location.removeLastSegments(1);
}
String archetypeArtifactId = op.getArchetype().content(true);
Archetype archetype = new Archetype();
String[] gav = archetypeArtifactId.split(":");
String archetypeVersion = gav[gav.length - 1];
archetype.setGroupId(gav[0]);
archetype.setArtifactId(gav[1]);
archetype.setVersion(archetypeVersion);
ArchetypeManager archetypeManager = MavenPluginActivator.getDefault().getArchetypeManager();
ArtifactRepository remoteArchetypeRepository = archetypeManager.getArchetypeRepository(archetype);
Properties properties = new Properties();
try {
List<?> archProps = archetypeManager.getRequiredProperties(archetype, remoteArchetypeRepository, monitor);
if (ListUtil.isNotEmpty(archProps)) {
for (Object prop : archProps) {
if (prop instanceof RequiredProperty) {
RequiredProperty rProp = (RequiredProperty) prop;
Value<PluginType> pluginType = op.getPluginType();
if (pluginType.content().equals(PluginType.theme)) {
String key = rProp.getKey();
if (key.equals("themeParent")) {
properties.put(key, op.getThemeParent().content(true));
} else if (key.equals("themeType")) {
properties.put(key, ThemeUtil.getTemplateExtension(op.getThemeFramework().content(true)));
}
} else {
properties.put(rProp.getKey(), rProp.getDefaultValue());
}
}
}
}
} catch (UnknownArchetype e1) {
LiferayMavenCore.logError("Unable to find archetype required properties", e1);
}
ResolverConfiguration resolverConfig = new ResolverConfiguration();
if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) {
resolverConfig.setSelectedProfiles(activeProfilesValue);
}
ProjectImportConfiguration configuration = new ProjectImportConfiguration(resolverConfig);
List<IProject> newProjects = projectConfigurationManager.createArchetypeProjects(location, archetype, groupId, artifactId, version, javaPackage, properties, configuration, monitor);
if (ListUtil.isNotEmpty(newProjects)) {
op.setImportProjectStatus(true);
for (IProject project : newProjects) {
projectNames.insert().setName(project.getName());
}
}
if (ListUtil.isEmpty(newProjects)) {
retval = LiferayMavenCore.createErrorStatus("New project was not created due to unknown error");
} else {
IProject firstProject = newProjects.get(0);
if (!CoreUtil.isNullOrEmpty(activeProfilesValue)) {
String[] activeProfiles = activeProfilesValue.split(",");
// find all profiles that should go in user settings file
List<NewLiferayProfile> newUserSettingsProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.userSettings);
if (ListUtil.isNotEmpty(newUserSettingsProfiles)) {
String userSettingsFile = mavenConfiguration.getUserSettingsFile();
String userSettingsPath = null;
if (CoreUtil.isNullOrEmpty(userSettingsFile)) {
userSettingsPath = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE.getAbsolutePath();
} else {
userSettingsPath = userSettingsFile;
}
try {
// backup user's settings.xml file
File settingsXmlFile = new File(userSettingsPath);
File backupFile = _getBackupFile(settingsXmlFile);
FileUtils.copyFile(settingsXmlFile, backupFile);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document pomDocument = docBuilder.parse(settingsXmlFile.getCanonicalPath());
for (NewLiferayProfile newProfile : newUserSettingsProfiles) {
MavenUtil.createNewLiferayProfileNode(pomDocument, newProfile);
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(pomDocument);
StreamResult result = new StreamResult(settingsXmlFile);
transformer.transform(source, result);
} catch (Exception e) {
LiferayMavenCore.logError("Unable to save new Liferay profile to user settings.xml.", e);
}
}
// find all profiles that should go in the project pom
List<NewLiferayProfile> newProjectPomProfiles = getNewProfilesToSave(activeProfiles, op.getNewLiferayProfiles(), ProfileLocation.projectPom);
// only need to set the first project as nested projects should pickup the
// parent setting
IMavenProjectFacade newMavenProject = mavenProjectRegistry.getProject(firstProject);
IFile pomFile = newMavenProject.getPom();
IDOMModel domModel = null;
try {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(pomFile);
for (NewLiferayProfile newProfile : newProjectPomProfiles) {
MavenUtil.createNewLiferayProfileNode(domModel.getDocument(), newProfile);
}
domModel.save();
} catch (IOException ioe) {
LiferayMavenCore.logError("Unable to save new Liferay profiles to project pom.", ioe);
} finally {
if (domModel != null) {
domModel.releaseFromEdit();
}
}
for (IProject project : newProjects) {
try {
projectConfigurationManager.updateProjectConfiguration(new MavenUpdateRequest(project, mavenConfiguration.isOffline(), true), monitor);
} catch (Exception e) {
LiferayMavenCore.logError("Unable to update configuration for " + project.getName(), e);
}
}
String pluginVersion = getNewLiferayProfilesPluginVersion(activeProfiles, op.getNewLiferayProfiles(), archetypeVersion);
String archVersion = MavenUtil.getMajorMinorVersionOnly(archetypeVersion);
updateDtdVersion(firstProject, pluginVersion, archVersion);
}
Value<PluginType> pluginType = op.getPluginType();
if (pluginType.content().equals(PluginType.portlet)) {
String portletName = op.getPortletName().content(false);
retval = portletFramework.postProjectCreated(firstProject, frameworkName, portletName, monitor);
}
}
if (retval == null) {
retval = Status.OK_STATUS;
}
return retval;
}
Aggregations