use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.
the class AddHookOperation method createLanguageProperties.
protected IStatus createLanguageProperties(IDataModel dm) {
IProject project = getTargetProject();
String contentFolderStr = dm.getStringProperty(CONTENT_FOLDER);
IPath contentFolderPath = new Path(contentFolderStr);
if (!contentFolderStr.startsWith("/")) {
IFolder sourceFolder = CoreUtil.getSourceFolders(JavaCore.create(project)).get(0);
contentFolderPath = sourceFolder.getFullPath().append(contentFolderStr);
}
IWorkspaceRoot root = project.getWorkspace().getRoot();
IFolder contentFolder = root.getFolder(contentFolderPath);
try {
CoreUtil.prepareFolder(contentFolder);
} catch (CoreException ce) {
return HookCore.createErrorStatus(ce);
}
List<String[]> languagePropertiesFiles = (List<String[]>) dm.getProperty(LANGUAGE_PROPERTIES_ITEMS);
if (languagePropertiesFiles != null) {
for (String[] languagePropertyFile : languagePropertiesFiles) {
try {
if (!languagePropertyFile[0].contains("*")) {
IFile createdFile = ProjectUtil.createEmptyProjectFile(languagePropertyFile[0], contentFolder);
if (createdFile != null) {
Set<IFile> languageFilesCreated = (Set<IFile>) dm.getProperty(LANGUAGE_PROPERTIES_FILES_CREATED);
languageFilesCreated.add(createdFile);
dm.setProperty(LANGUAGE_PROPERTIES_FILES_CREATED, languageFilesCreated);
}
}
} catch (Exception e) {
HookCore.logError(e);
}
}
}
HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
Set<IFile> languageFilesCreated = (Set<IFile>) dm.getProperty(LANGUAGE_PROPERTIES_FILES_CREATED);
// need to get file paths relative to package root
List<String> languageProperties = new ArrayList<>();
IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
if (packRoot != null) {
for (IFile languageFile : languageFilesCreated) {
if (packRoot.getPath().isPrefixOf(languageFile.getFullPath())) {
IPath fullPath = languageFile.getFullPath();
String languageProperty = fullPath.makeRelativeTo(packRoot.getPath()).toPortableString();
languageProperties.add(languageProperty);
}
}
}
IStatus status = hookDescHelper.addLanguageProperties(languageProperties);
return status;
}
use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.
the class AddHookOperation method createCustomJSPs.
protected IStatus createCustomJSPs(IDataModel dm) {
IProject project = getTargetProject();
IFolder defaultWebappRootFolder = LiferayCore.create(IWebProject.class, project).getDefaultDocrootFolder();
String customJSPsFolder = dm.getStringProperty(CUSTOM_JSPS_FOLDER);
IPath fullPath = defaultWebappRootFolder.getFullPath();
String customFolderValue = fullPath.append(customJSPsFolder).toPortableString();
IWorkspaceRoot root = project.getWorkspace().getRoot();
IFolder customFolder = root.getFolder(new Path(customFolderValue));
try {
CoreUtil.prepareFolder(customFolder);
} catch (CoreException ce) {
return HookCore.createErrorStatus(ce);
}
List<String[]> customJsps = (List<String[]>) dm.getProperty(CUSTOM_JSPS_ITEMS);
ILiferayProject liferayProject = LiferayCore.create(getTargetProject());
ILiferayPortal portal = liferayProject.adapt(ILiferayPortal.class);
IStatus status = null;
if (portal != null) {
IPath portalDir = portal.getAppServerPortalDir();
if ((customJsps != null) && (portalDir != null)) {
for (String[] customJsp : customJsps) {
try {
IFile copiedFile = copyPortalJSPToProject(portalDir, customJsp[0], customFolder);
if (copiedFile != null) {
Set<IFile> jspFilesCreated = (Set<IFile>) dm.getProperty(CUSTOM_JSPS_FILES_CREATED);
jspFilesCreated.add(copiedFile);
dm.setProperty(CUSTOM_JSPS_FILES_CREATED, jspFilesCreated);
}
} catch (Exception e) {
HookCore.logError(e);
}
}
}
HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
status = hookDescHelper.setCustomJSPDir(model);
if (model.getBooleanProperty(DISABLE_CUSTOM_JSP_FOLDER_VALIDATION)) {
HookUtil.configureJSPSyntaxValidationExclude(getTargetProject(), customFolder, true);
}
} else {
status = HookCore.createErrorStatus("Could not get portal info from project " + project.getName());
}
return status;
}
use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.
the class AddHookOperation method createDefaultHookDescriptorFile.
protected void createDefaultHookDescriptorFile(IFile hookDescriptorFile) throws BadLocationException, CoreException, TemplateException, UnsupportedEncodingException {
HookDescriptorHelper helper = new HookDescriptorHelper(getTargetProject());
helper.createDefaultDescriptor();
}
use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.
the class AddHookOperation method createPortalProperties.
protected IStatus createPortalProperties(IDataModel dm) {
IProject project = getTargetProject();
String portalPropertiesFile = dm.getStringProperty(PORTAL_PROPERTIES_FILE);
// check to see if we have an existing file to read in
IPath portalPropertiesPath = new Path(portalPropertiesFile);
if (!portalPropertiesFile.startsWith("/")) {
IFolder sourceFolder = CoreUtil.getSourceFolders(JavaCore.create(project)).get(0);
portalPropertiesPath = sourceFolder.getFullPath().append(portalPropertiesFile);
}
IPath propertiesFilesPath = portalPropertiesPath.makeRelativeTo(project.getFullPath());
IFile propertiesFile = project.getFile(propertiesFilesPath);
Properties properties = new Properties();
if (FileUtil.exists(propertiesFile)) {
try {
properties.load(propertiesFile.getContents());
} catch (Exception e) {
return HookCore.createErrorStatus(e);
}
}
List<String[]> actionItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_ACTION_ITEMS);
if (actionItems != null) {
for (String[] actionItem : actionItems) {
properties.put(actionItem[0], actionItem[1]);
}
}
List<String[]> overrideItems = (List<String[]>) dm.getProperty(PORTAL_PROPERTIES_OVERRIDE_ITEMS);
if (overrideItems != null) {
for (String[] overrideItem : overrideItems) {
properties.put(overrideItem[0], overrideItem[1]);
}
}
StringBufferOutputStream buffer = new StringBufferOutputStream();
try {
properties.store(buffer, StringPool.EMPTY);
} catch (IOException ioe) {
return HookCore.createErrorStatus(ioe);
}
try {
ByteArrayInputStream bis = new ByteArrayInputStream(buffer.toString().getBytes("UTF-8"));
if (propertiesFile.exists()) {
propertiesFile.setContents(bis, IResource.FORCE, null);
} else {
CoreUtil.prepareFolder((IFolder) propertiesFile.getParent());
propertiesFile.create(bis, true, null);
}
} catch (Exception e) {
return HookCore.createErrorStatus(e);
}
HookDescriptorHelper hookDescHelper = new HookDescriptorHelper(getTargetProject());
String propertiesClasspath = null;
IPackageFragmentRoot packRoot = (IPackageFragmentRoot) model.getProperty(INewJavaClassDataModelProperties.JAVA_PACKAGE_FRAGMENT_ROOT);
if ((packRoot != null) && packRoot.getPath().isPrefixOf(propertiesFile.getFullPath())) {
IPath fullPath = propertiesFile.getFullPath();
propertiesClasspath = fullPath.makeRelativeTo(packRoot.getPath()).toPortableString();
}
IStatus status = hookDescHelper.setPortalProperties(model, propertiesClasspath);
return status;
}
use of com.liferay.ide.hook.core.dd.HookDescriptorHelper in project liferay-ide by liferay.
the class NewHookDataModelProvider method getDefaultProperty.
@Override
public Object getDefaultProperty(String propertyName) {
if (CUSTOM_JSPS_FOLDER.equals(propertyName)) {
// check to see if there is an existing hook descriptor and read
// custom_jsps out of that
IProject targetProject = getTargetProject();
IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
if (webproject != null) {
IFolder defaultWebappRootFolder = webproject.getDefaultDocrootFolder();
String defaultWebappRootPath = defaultWebappRootFolder.getFullPath().toPortableString();
if (targetProject != null) {
HookDescriptorHelper hookDescriptorHelper = new HookDescriptorHelper(targetProject);
String customJspFolder = hookDescriptorHelper.getCustomJSPFolder(getDataModel());
if (customJspFolder != null) {
// folder should be relative to the web app folder root
// IDE-110 IDE-648
IFolder defaultDocroot = webproject.getDefaultDocrootFolder();
if (defaultDocroot != null) {
IPath defaultDocrootPath = defaultDocroot.getFullPath();
String containerFullPath = defaultDocrootPath.append(customJspFolder).toPortableString();
int index = containerFullPath.indexOf(defaultWebappRootPath);
if (index != -1) {
int beginIndex = index + defaultWebappRootPath.length();
containerFullPath = containerFullPath.substring(beginIndex);
}
return containerFullPath;
}
}
if (defaultWebappRootFolder != null) {
return "/META-INF/custom_jsps";
}
}
}
} else if (PORTAL_PROPERTIES_FILE.equals(propertyName)) {
IProject targetProject = getTargetProject();
List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
if ((targetProject != null) && ListUtil.isNotEmpty(sources)) {
IPath sourcePath = sources.get(0).getFullPath();
return sourcePath.append("portal.properties").toPortableString();
}
} else if (CONTENT_FOLDER.equals(propertyName)) {
IProject targetProject = getTargetProject();
List<IFolder> sources = CoreUtil.getSourceFolders(JavaCore.create(targetProject));
if ((targetProject != null) && !sources.isEmpty()) {
IPath sourcePath = sources.get(0).getFullPath();
return sourcePath.append("content").toPortableString();
}
} else if (SELECTED_PROJECT.equals(propertyName)) {
IProject targetProject = getTargetProject();
if (targetProject != null) {
return targetProject.getName();
}
} else if (WEB_ROOT_FOLDER.equals(propertyName)) {
IProject targetProject = getTargetProject();
IWebProject webproject = LiferayCore.create(IWebProject.class, targetProject);
if ((targetProject != null) && (webproject != null)) {
return webproject.getDefaultDocrootFolder().getName();
}
} else if (propertyName.equals(PROJECT)) {
return getTargetProject();
} else if (propertyName.equals(SOURCE_FOLDER)) {
IFolder sourceFolder = getDefaultJavaSourceFolder();
if (FileUtil.exists(sourceFolder)) {
return sourceFolder.getFullPath().toPortableString();
}
} else if (propertyName.equals(JAVA_SOURCE_FOLDER)) {
return getJavaSourceFolder();
} else if (propertyName.equals(JAVA_PACKAGE_FRAGMENT_ROOT)) {
return getJavaPackageFragmentRoot();
} else if (CUSTOM_JSPS_FILES_CREATED.equals(propertyName)) {
return new HashSet<>();
} else if (LANGUAGE_PROPERTIES_FILES_CREATED.equals(propertyName)) {
return new HashSet<>();
} else if (DISABLE_CUSTOM_JSP_FOLDER_VALIDATION.equals(propertyName)) {
return true;
}
return super.getDefaultProperty(propertyName);
}
Aggregations