Search in sources :

Example 1 with BinaryProjectRecord

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;
}
Also used : BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry)

Example 2 with BinaryProjectRecord

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();
        }
    });
}
Also used : ModifyEvent(org.eclipse.swt.events.ModifyEvent) ModifyListener(org.eclipse.swt.events.ModifyListener) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) SelectionEvent(org.eclipse.swt.events.SelectionEvent) File(java.io.File)

Example 3 with BinaryProjectRecord

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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPortletFramework(com.liferay.ide.project.core.IPortletFramework) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) ArrayList(java.util.ArrayList) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 4 with BinaryProjectRecord

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);
        }
    }
}
Also used : BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File)

Example 5 with BinaryProjectRecord

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);
}
Also used : BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord)

Aggregations

BinaryProjectRecord (com.liferay.ide.project.core.BinaryProjectRecord)7 File (java.io.File)4 ArrayList (java.util.ArrayList)2 JarFile (java.util.jar.JarFile)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)1 ProjectRecord (com.liferay.ide.project.core.ProjectRecord)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Collection (java.util.Collection)1 JarEntry (java.util.jar.JarEntry)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 StyledString (org.eclipse.jface.viewers.StyledString)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1