Search in sources :

Example 6 with ProjectRecord

use of com.liferay.ide.project.core.ProjectRecord in project liferay-ide by liferay.

the class SDKProjectsImportWizardPage method getProjectRecords.

public Object[] getProjectRecords() {
    List projectRecords = new ArrayList();
    for (int i = 0; i < selectedProjects.length; i++) {
        ProjectRecord projectRecord = (ProjectRecord) selectedProjects[i];
        if (isProjectInWorkspace(projectRecord.getProjectName())) {
            projectRecord.setHasConflicts(true);
        }
        projectRecords.add(selectedProjects[i]);
    }
    return (ProjectRecord[]) projectRecords.toArray(new ProjectRecord[projectRecords.size()]);
}
Also used : ArrayList(java.util.ArrayList) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with ProjectRecord

use of com.liferay.ide.project.core.ProjectRecord in project liferay-ide by liferay.

the class SDKProjectsImportWizardPage method updateProjectsList.

public void updateProjectsList(final String path) {
    if ((path == null) || (path.length() == 0)) {
        setMessage(Msgs.importProjectsDescription);
        selectedProjects = new ProjectRecord[0];
        projectsList.refresh(true);
        projectsList.setCheckedElements(selectedProjects);
        setPageComplete(ListUtil.isNotEmpty(projectsList.getCheckedElements()));
        lastPath = path;
        return;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    if (path.equals(lastPath) && (lastModified == modified)) {
        return;
    }
    lastPath = path;
    lastModified = modified;
    final boolean dirSelected = true;
    try {
        getContainer().run(true, true, new IRunnableWithProgress() {

            /*
					 * (non-Javadoc)
					 *
					 * @see IRunnableWithProgress#run(org
					 * .eclipse.core.runtime.IProgressMonitor)
					 */
            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Msgs.searchingMessage, 100);
                selectedProjects = new ProjectRecord[0];
                Collection<File> eclipseProjectFiles = new ArrayList<>();
                Collection<File> liferayProjectDirs = new ArrayList<>();
                monitor.worked(10);
                if (dirSelected && directory.isDirectory()) {
                    if (!ProjectUtil.collectSDKProjectsFromDirectory(eclipseProjectFiles, liferayProjectDirs, directory, null, true, monitor)) {
                        return;
                    }
                    selectedProjects = new ProjectRecord[eclipseProjectFiles.size() + liferayProjectDirs.size()];
                    int index = 0;
                    monitor.worked(50);
                    monitor.subTask(Msgs.processingMessage);
                    for (File eclipseProjectFile : eclipseProjectFiles) {
                        selectedProjects[index++] = new ProjectRecord(eclipseProjectFile);
                    }
                    for (File liferayProjectDir : liferayProjectDirs) {
                        selectedProjects[index++] = new ProjectRecord(liferayProjectDir);
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException ite) {
        ProjectUI.logError(ite);
    } catch (InterruptedException ie) {
    }
    projectsList.refresh(true);
    Object[] projects = getProjectRecords();
    boolean displayWarning = false;
    for (int i = 0; i < projects.length; i++) {
        ProjectRecord projectRecord = (ProjectRecord) projects[i];
        if (projectRecord.hasConflicts()) {
            displayWarning = true;
            projectsList.setGrayed(projects[i], true);
        }
    // else {
    // projectsList.setChecked(projects[i], true);
    // }
    }
    if (displayWarning) {
        setMessage(Msgs.projectsInWorkspace, WARNING);
    } else {
        setMessage(Msgs.importProjectsDescription);
    }
    setPageComplete(ListUtil.isNotEmpty(projectsList.getCheckedElements()));
    if (selectedProjects.length == 0) {
        setMessage(Msgs.noProjectsToImport, WARNING);
    }
    Object[] checkedProjects = projectsList.getCheckedElements();
    if (ListUtil.isNotEmpty(checkedProjects)) {
        selectedProjects = new ProjectRecord[checkedProjects.length];
        for (int i = 0; i < checkedProjects.length; i++) {
            selectedProjects[i] = (ProjectRecord) checkedProjects[i];
        }
        getDataModel().setProperty(SELECTED_PROJECTS, selectedProjects);
    }
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) Collection(java.util.Collection) File(java.io.File)

Example 8 with ProjectRecord

use of com.liferay.ide.project.core.ProjectRecord in project liferay-ide by liferay.

the class SDKProjectsImportWizardPage method handleCheckStateChangedEvent.

protected void handleCheckStateChangedEvent(CheckStateChangedEvent event) {
    ProjectRecord element = (ProjectRecord) event.getElement();
    if (element.hasConflicts()) {
        projectsList.setChecked(element, false);
    }
    getDataModel().setProperty(SELECTED_PROJECTS, projectsList.getCheckedElements());
    setPageComplete(ListUtil.isNotEmpty(projectsList.getCheckedElements()));
}
Also used : ProjectRecord(com.liferay.ide.project.core.ProjectRecord)

Example 9 with ProjectRecord

use of com.liferay.ide.project.core.ProjectRecord in project liferay-ide by liferay.

the class ImportSDKProjectsCheckboxCustomPart method _updateProjectsList.

private ProjectRecord[] _updateProjectsList(final String path) {
    if ((path == null) || (path.length() == 0)) {
        selectedProjects = new ProjectRecord[0];
        return null;
    }
    final File directory = new File(path);
    long modified = directory.lastModified();
    lastModified = modified;
    final boolean dirSelected = true;
    try {
        selectedProjects = new ProjectRecord[0];
        Collection<File> eclipseProjectFiles = new ArrayList<>();
        Collection<File> liferayProjectDirs = new ArrayList<>();
        if (dirSelected && directory.isDirectory()) {
            if (!ProjectUtil.collectSDKProjectsFromDirectory(eclipseProjectFiles, liferayProjectDirs, directory, null, true, new NullProgressMonitor())) {
                return null;
            }
            selectedProjects = new ProjectRecord[eclipseProjectFiles.size() + liferayProjectDirs.size()];
            int index = 0;
            for (File eclipseProjectFile : eclipseProjectFiles) {
                selectedProjects[index++] = new ProjectRecord(eclipseProjectFile);
            }
            for (File liferayProjectDir : liferayProjectDirs) {
                selectedProjects[index++] = new ProjectRecord(liferayProjectDir);
            }
        }
    } catch (Exception e) {
        ProjectUI.logError(e);
    }
    Object[] projects = _getProjectRecords();
    return (ProjectRecord[]) projects;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ArrayList(java.util.ArrayList) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) File(java.io.File)

Example 10 with ProjectRecord

use of com.liferay.ide.project.core.ProjectRecord 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)

Aggregations

ProjectRecord (com.liferay.ide.project.core.ProjectRecord)17 File (java.io.File)10 ArrayList (java.util.ArrayList)6 IProject (org.eclipse.core.resources.IProject)6 IPath (org.eclipse.core.runtime.IPath)6 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 BinaryProjectRecord (com.liferay.ide.project.core.BinaryProjectRecord)4 SDK (com.liferay.ide.sdk.core.SDK)3 JarFile (java.util.jar.JarFile)3 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URL (java.net.URL)2 List (java.util.List)2 Path (org.eclipse.core.runtime.Path)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 IRuntime (org.eclipse.wst.server.core.IRuntime)2 IPortletFramework (com.liferay.ide.project.core.IPortletFramework)1 Collection (java.util.Collection)1