use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class NewHookDataModelProvider method validate.
@Override
public IStatus validate(String propertyName) {
boolean is70 = false;
try {
SDK sdk = SDKUtil.getWorkspaceSDK();
if (sdk != null) {
Version version = new Version(sdk.getVersion());
Version sdk70 = ILiferayConstants.V700;
if (CoreUtil.compareVersions(version, sdk70) >= 0) {
is70 = true;
}
}
} catch (CoreException ce) {
}
if (CUSTOM_JSPS_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
String jspFolder = getStringProperty(CUSTOM_JSPS_FOLDER);
if (CoreUtil.isNullOrEmpty(jspFolder)) {
return HookCore.createErrorStatus(Msgs.customJSPsFolderNotConfigured);
}
IProject project = getTargetProject();
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if (webproject != null) {
IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
IPath defaultWebappRootFolderPath = defaultWebappRootFolder.getFullPath();
String jspFolderPath = defaultWebappRootFolderPath.append(jspFolder).toPortableString();
IStatus validateStatus = CoreUtil.getWorkspace().validatePath(jspFolderPath, IResource.FOLDER);
if (!validateStatus.isOK()) {
return HookCore.createErrorStatus(validateStatus.getMessage());
}
}
} else if (CUSTOM_JSPS_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_CUSTOM_JSPS)) {
Object jspItems = getProperty(CUSTOM_JSPS_ITEMS);
if (jspItems instanceof List) {
if (((List) jspItems).size() > 0) {
String[][] jspArrays = ((List<String[]>) jspItems).toArray(new String[0][]);
for (int i = 0; i < jspArrays.length; i++) {
String[] comp1 = jspArrays[i];
for (int j = i + 1; j < jspArrays.length; j++) {
String[] comp2 = jspArrays[j];
if (comp1[0].equals(comp2[0])) {
return HookCore.createWarnStatus("Shouldn't add same jsp file.");
}
}
}
return Status.OK_STATUS;
}
}
return HookCore.createErrorStatus(Msgs.specifyOneJSP);
} else if (PORTAL_PROPERTIES_FILE.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
String portalPropertiesFile = getStringProperty(PORTAL_PROPERTIES_FILE);
if (CoreUtil.isNullOrEmpty(portalPropertiesFile)) {
return HookCore.createErrorStatus(Msgs.portalPropertiesFileNotConfigured);
}
IPath portalPropertiesPath = Path.fromPortableString(portalPropertiesFile);
IProject targetProject = getTargetProject();
List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
if (portalPropertiesFile.startsWith("/")) {
for (IFolder sourceFolder : sources) {
IPath sourceFolderPath = sourceFolder.getFullPath();
if (sourceFolderPath.isPrefixOf(portalPropertiesPath)) {
return Status.OK_STATUS;
}
}
return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
} else {
return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
}
} else if (PORTAL_PROPERTIES_ACTION_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_PORTAL_PROPERTIES)) {
// if we have valid actions items or property overrides then we
// don't need an error
IStatus actionItemsStatus = validateListItems(PORTAL_PROPERTIES_ACTION_ITEMS);
IStatus propertyOverridesStatus = validateListItems(PORTAL_PROPERTIES_OVERRIDE_ITEMS);
if (actionItemsStatus.isOK() || propertyOverridesStatus.isOK()) {
return Status.OK_STATUS;
} else {
return HookCore.createErrorStatus(Msgs.specifyOneEventActionProperty);
}
} else if (SERVICES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_SERVICES)) {
IStatus itemsStatus = validateListItems(SERVICES_ITEMS);
if (itemsStatus.isOK()) {
return Status.OK_STATUS;
} else {
return HookCore.createErrorStatus(Msgs.specifyOneService);
}
} else if (CONTENT_FOLDER.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
String contentFolder = getStringProperty(CONTENT_FOLDER);
if (CoreUtil.isNullOrEmpty(contentFolder)) {
return HookCore.createErrorStatus(Msgs.contentFolderNotConfigured);
}
IPath contentPath = Path.fromPortableString(contentFolder);
IProject targetProject = getTargetProject();
List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
if (contentFolder.startsWith("/")) {
for (IFolder sourceFolder : sources) {
IPath sourcePath = sourceFolder.getFullPath();
if (sourcePath.isPrefixOf(contentPath)) {
return Status.OK_STATUS;
}
}
return HookCore.createErrorStatus(Msgs.pathUnderSourceFolder);
} else {
return HookCore.createWarnStatus(Msgs.appendedToDefaultLocation);
}
} else if (LANGUAGE_PROPERTIES_ITEMS.equals(propertyName) && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
Object propertiesItems = getProperty(LANGUAGE_PROPERTIES_ITEMS);
if (propertiesItems instanceof List) {
List jsps = (List) propertiesItems;
if (ListUtil.isNotEmpty(jsps)) {
return Status.OK_STATUS;
}
}
return HookCore.createErrorStatus(Msgs.specifyOneLanguagePropertyFile);
} else if (is70 && getBooleanProperty(CREATE_LANGUAGE_PROPERTIES)) {
return HookCore.createErrorStatus(Msgs.noSupportInSDK70);
}
return super.validate(propertyName);
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class CreateDirectoryActionHandler method run.
@Override
protected Object run(Presentation context) {
try {
Element element = getModelElement();
IProject project = element.adapt(IProject.class);
CustomJspDir customJspDir = (CustomJspDir) element;
Path customJspDirValue = customJspDir.getValue().content(false);
if (customJspDirValue == null) {
customJspDirValue = customJspDir.getValue().content(true);
customJspDir.setValue(customJspDirValue);
}
customJspDir.setValue(customJspDirValue);
RelativePathService service = property().service(RelativePathService.class);
Path absolutePath = service.convertToAbsolute(customJspDirValue);
if (FileUtil.notExists(absolutePath)) {
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if ((webproject != null) && (webproject.getDefaultDocrootFolder() != null)) {
IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
IFolder customJspFolder = defaultDocroot.getFolder(new org.eclipse.core.runtime.Path(customJspDirValue.toPortableString()));
CoreUtil.makeFolders(customJspFolder);
// force a refresh of validation
customJspDir.setValue((Path) null);
customJspDir.setValue(customJspDirValue);
refreshEnablementState();
}
}
} catch (Exception e) {
HookUI.logError(e);
}
return null;
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class AddHookOperation method checkDescriptorFile.
protected IStatus checkDescriptorFile(IProject project) {
IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if ((webproject == null) || (webproject.getDefaultDocrootFolder() == null)) {
return HookCore.createErrorStatus("Could not find webapp root folder.");
}
IFolder webappRoot = webproject.getDefaultDocrootFolder();
// IDE-648 IDE-110
Path path = new Path("WEB-INF/" + ILiferayConstants.LIFERAY_HOOK_XML_FILE);
IFile hookDescriptorFile = webappRoot.getFile(path);
if (FileUtil.notExists(hookDescriptorFile)) {
try {
createDefaultHookDescriptorFile(hookDescriptorFile);
} catch (Exception ex) {
return HookCore.createErrorStatus(ex);
}
}
return Status.OK_STATUS;
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class DocrootRelativePathService method roots.
@Override
public List<Path> roots() {
List<Path> roots = new ArrayList<>();
Hook hook = context(Hook.class);
if (hook != null) {
IProject project = hook.adapt(IProject.class);
// IDE-110
IWebProject lrproject = LiferayCore.create(IWebProject.class, project);
if (lrproject != null) {
IFolder defaultDocroot = lrproject.getDefaultDocrootFolder();
if (FileUtil.exists(defaultDocroot)) {
roots.add(new Path(defaultDocroot.getLocation().toPortableString()));
}
}
}
return roots;
}
use of com.liferay.ide.core.IWebProject in project liferay-ide by liferay.
the class JSFPortletFramework method postProjectCreated.
@Override
public IStatus postProjectCreated(IProject project, String frameworkName, String portletName, IProgressMonitor monitor) {
/*
* we need to copy the original web.xml from the project template
* because of bugs in the JSF facet installer will overwrite our web.xml
* that comes with in the template
*/
super.postProjectCreated(project, frameworkName, portletName, monitor);
SDK sdk = SDKUtil.getSDK(project);
if (sdk != null) {
try {
// TODO IDE-648
IPath location = sdk.getLocation().append("tools/portlet_" + frameworkName + "_tmpl/docroot/WEB-INF/web.xml");
File originalWebXmlFile = location.toFile();
if (originalWebXmlFile.exists()) {
final IWebProject webproject = LiferayCore.create(IWebProject.class, project);
if (webproject != null) {
IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
try (InputStream newInputStream = Files.newInputStream(originalWebXmlFile.toPath())) {
defaultDocroot.getFile("WEB-INF/web.xml").setContents(newInputStream, IResource.FORCE, null);
}
}
}
} catch (Exception e) {
return PortletCore.createErrorStatus("Could not copy original web.xml from JSF template in SDK.", e);
}
}
try {
IFolder docroot = CoreUtil.getDefaultDocrootFolder(project);
IFolder views = docroot.getFolder("views");
if (views.exists()) {
views.move(docroot.getFolder("WEB-INF/views").getFullPath(), true, monitor);
IFile portletXml = docroot.getFile("WEB-INF/portlet.xml");
File portletXmlFile = portletXml.getLocation().toFile();
String contents = FileUtil.readContents(portletXmlFile, true);
if (contents.contains("init-param")) {
contents = contents.replaceAll("/views/view.xhtml", "/WEB-INF/views/view.xhtml");
portletXml.setContents(new ByteArrayInputStream(contents.getBytes("UTF-8")), IResource.FORCE, null);
}
}
} catch (Exception e) {
return PortletCore.createErrorStatus(e);
}
return Status.OK_STATUS;
}
Aggregations