use of com.liferay.ide.project.core.BinaryProjectRecord in project liferay-ide by liferay.
the class ProjectImportUtil method isValidLiferayPlugin.
/**
* This method is used to validate whether the given plugin binary is a valid
* Liferay Plugin Archieve
*
* @param binaryFile
* - the binary file to be validated
* @return
*/
public static boolean isValidLiferayPlugin(File binaryFile) {
boolean valid = false;
JarFile pluginBinary = null;
try {
pluginBinary = new JarFile(binaryFile);
BinaryProjectRecord tempRecord = new BinaryProjectRecord(binaryFile);
// Check for liferay-plugin-package.properties or liferay-plugin-package.xml
String packagePrpoertiesLocation = getConfigFileLocation(ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_FILE);
JarEntry lfrPluginPkgPropsEntry = pluginBinary.getJarEntry(packagePrpoertiesLocation);
String packagePrpoertiesXMLLocation = getConfigFileLocation(ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_XML_FILE);
JarEntry lfrPluginPkgXmlEntry = pluginBinary.getJarEntry(packagePrpoertiesXMLLocation);
if ((lfrPluginPkgPropsEntry != null) || (lfrPluginPkgXmlEntry != null)) {
valid = true;
}
if (tempRecord.isHook()) {
JarEntry jar = pluginBinary.getJarEntry(getConfigFileLocation(ILiferayConstants.LIFERAY_HOOK_XML_FILE));
valid = valid && (jar != null);
} else if (tempRecord.isLayoutTpl()) {
JarEntry jar = pluginBinary.getJarEntry(getConfigFileLocation(ILiferayConstants.LIFERAY_LAYOUTTPL_XML_FILE));
valid = valid || (jar != null);
} else if (tempRecord.isPortlet()) {
JarEntry jar = pluginBinary.getJarEntry(getConfigFileLocation(ILiferayConstants.LIFERAY_PORTLET_XML_FILE));
valid = valid && (jar != null);
} else if (tempRecord.isTheme()) {
JarEntry jar = pluginBinary.getJarEntry(getConfigFileLocation(ILiferayConstants.LIFERAY_LOOK_AND_FEEL_XML_FILE));
valid = valid || (jar != null);
}
if (!valid) {
return valid;
} else {
// check if its a valid web Archieve
JarEntry jar = pluginBinary.getJarEntry(getConfigFileLocation(ILiferayConstants.WEB_XML_FILE));
valid = valid || jar != null;
}
} catch (IOException ioe) {
valid = false;
} finally {
if (pluginBinary != null) {
try {
pluginBinary.close();
} catch (IOException ioe) {
}
}
}
return valid;
}
use of com.liferay.ide.project.core.BinaryProjectRecord in project liferay-ide by liferay.
the class BinaryProjectImportWizardPage method createBinaryLocationField.
protected void createBinaryLocationField(Composite parent) {
Label label = new Label(parent, SWT.NONE);
label.setText(Msgs.binaryPluginFile);
label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
binariesLocation = SWTUtil.createSingleText(parent, 1);
binariesLocation.addModifyListener(new ModifyListener() {
@Override
public void modifyText(ModifyEvent e) {
if (binariesLocation.isFocusControl() && CoreUtil.isNullOrEmpty(binariesLocation.getText())) {
setErrorMessage("Select a binary to import.");
getDataModel().setProperty(SELECTED_PROJECTS, null);
} else {
File binaryFile = new File(binariesLocation.getText());
if (ProjectImportUtil.isValidLiferayPlugin(binaryFile)) {
selectedBinary = new BinaryProjectRecord(new File(binariesLocation.getText()));
getDataModel().setProperty(SELECTED_PROJECTS, new Object[] { selectedBinary });
} else {
setErrorMessage(Msgs.selectValidLiferayPluginBinary);
getDataModel().setProperty(SELECTED_PROJECTS, null);
}
}
}
});
Button browse = SWTUtil.createButton(parent, Msgs.browse);
browse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
doBrowse();
}
});
}
use of com.liferay.ide.project.core.BinaryProjectRecord in project liferay-ide by liferay.
the class ProjectImportUtil method createSDKPluginProject.
/**
* @param dataModel
* @param pluginBinaryRecord
* @param liferaySDK
* @return
* @throws IOException
*/
public static ProjectRecord createSDKPluginProject(BridgedRuntime bridgedRuntime, BinaryProjectRecord pluginBinaryRecord, SDK liferaySDK) throws IOException {
ProjectRecord projectRecord = null;
if (!pluginBinaryRecord.isConflicts()) {
String displayName = pluginBinaryRecord.getDisplayName();
File binaryFile = pluginBinaryRecord.getBinaryFile();
IPath projectPath = null;
IPath sdkPluginProjectFolder = liferaySDK.getLocation();
// IDE-110 IDE-648
String webappRootFolder = null;
IProgressMonitor npm = new NullProgressMonitor();
ArrayList<String> arguments = new ArrayList<>();
arguments.add(displayName);
arguments.add(displayName);
if (pluginBinaryRecord.isHook()) {
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.HOOK_PLUGIN_PROJECT_FOLDER);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "hook", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.HOOK_PLUGIN_SDK_CONFIG_FOLDER;
} else if (pluginBinaryRecord.isPortlet()) {
IPortletFramework[] portletFrameworks = ProjectCore.getPortletFrameworks();
String portletFrameworkName = null;
for (int i = 0; i < portletFrameworks.length; i++) {
IPortletFramework portletFramework = portletFrameworks[i];
if (portletFramework.isDefault() && !portletFramework.isAdvanced()) {
portletFrameworkName = portletFramework.getShortName();
break;
}
}
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.PORTLET_PLUGIN_PROJECT_FOLDER);
arguments.add(portletFrameworkName);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "portlet", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.PORTLET_PLUGIN_SDK_CONFIG_FOLDER;
} else if (pluginBinaryRecord.isTheme()) {
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.THEME_PLUGIN_PROJECT_FOLDER);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "theme", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.THEME_PLUGIN_SDK_CONFIG_FOLDER;
} else if (pluginBinaryRecord.isLayoutTpl()) {
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_FOLDER);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "layouttpl", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.LAYOUTTPL_PLUGIN_SDK_CONFIG_FOLDER;
} else if (pluginBinaryRecord.isExt()) {
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.EXT_PLUGIN_PROJECT_FOLDER);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "ext", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.EXT_PLUGIN_SDK_CONFIG_FOLDER;
} else if (pluginBinaryRecord.isWeb()) {
sdkPluginProjectFolder = sdkPluginProjectFolder.append(ISDKConstants.WEB_PLUGIN_PROJECT_FOLDER);
try {
projectPath = liferaySDK.createNewProject(displayName, arguments, "web", sdkPluginProjectFolder.toOSString(), npm);
} catch (CoreException ce) {
ProjectCore.logError(ce);
}
webappRootFolder = IPluginFacetConstants.WEB_PLUGIN_SDK_CONFIG_FOLDER;
}
// Extract the contents
File webappRoot = new File(projectPath.toFile(), webappRootFolder);
ZipUtil.unzip(binaryFile, webappRoot);
// IDE-569 check to see if the project already has .project
File projectFile = new File(projectPath.toFile(), ".project");
if (FileUtil.exists(projectFile)) {
projectRecord = new ProjectRecord(projectFile);
} else {
projectRecord = new ProjectRecord(projectPath.toFile());
}
}
return projectRecord;
}
use of com.liferay.ide.project.core.BinaryProjectRecord in project liferay-ide by liferay.
the class BinaryProjectImportWizardPage method doBrowse.
protected void doBrowse() {
FileDialog fd = new FileDialog(getShell(), SWT.OPEN);
fd.setFilterExtensions(ISDKConstants.BINARY_PLUGIN_EXTENSIONS);
String filterPath = binariesLocation.getText();
if (filterPath != null) {
fd.setFilterPath(filterPath);
fd.setText(NLS.bind(Msgs.selectLiferayPluginBinaryFolderPath, filterPath));
} else {
fd.setText(Msgs.selectLiferayPluginBinaryFolder);
}
if (CoreUtil.isNullOrEmpty(binariesLocation.getText())) {
fd.setFilterPath(binariesLocation.getText());
}
String binaryfile = fd.open();
if (!CoreUtil.isNullOrEmpty(binaryfile)) {
binariesLocation.setText(binaryfile);
File binaryFile = new File(binaryfile);
if (ProjectImportUtil.isValidLiferayPlugin(binaryFile)) {
selectedBinary = new BinaryProjectRecord(new File(binaryfile));
getDataModel().setProperty(SELECTED_PROJECTS, new Object[] { selectedBinary });
} else {
setErrorMessage(Msgs.selectValidLiferayPluginBinary);
}
}
}
use of com.liferay.ide.project.core.BinaryProjectRecord in project liferay-ide by liferay.
the class BinaryProjectsImportWizardPage method handleSelectAll.
@Override
protected void handleSelectAll(SelectionEvent e) {
for (int i = 0; i < selectedProjects.length; i++) {
BinaryProjectRecord binaryProject = (BinaryProjectRecord) selectedProjects[i];
if (binaryProject.isConflicts()) {
projectsList.setChecked(binaryProject, false);
} else {
projectsList.setChecked(binaryProject, true);
}
}
getDataModel().setProperty(SELECTED_PROJECTS, projectsList.getCheckedElements());
validatePage(true);
// setPageComplete(projectsList.getCheckedElements().length >
// 0);
}
Aggregations