Search in sources :

Example 11 with ProjectRecord

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

the class ProjectImportUtil method importProject.

public static IProject importProject(IPath projectdir, IProgressMonitor monitor, NewLiferayPluginProjectOp op) throws CoreException {
    IProject project = null;
    ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectdir.toPortableString());
    File projectDir = projectRecord.getProjectLocation().toFile();
    SDK sdk = SDKUtil.getSDKFromProjectDir(projectDir);
    if (sdk == null) {
        return null;
    }
    if (projectRecord.projectSystemFile != null) {
        try {
            project = ProjectUtil.createExistingProject(projectRecord, sdk.getLocation(), monitor);
        } catch (CoreException ce) {
            throw new CoreException(ProjectCore.createErrorStatus(ce));
        }
    } else if (projectRecord.liferayProjectDir != null) {
        try {
            project = ProjectUtil.createNewSDKProject(projectRecord, sdk.getLocation(), monitor, op);
        } catch (CoreException ce) {
            throw new CoreException(ProjectCore.createErrorStatus(ce));
        }
    }
    File parent = projectdir.removeLastSegments(1).toFile();
    String parentName = parent.getName();
    IProject sdkProject = CoreUtil.getProject(sdk.getName());
    IFolder folder = sdkProject.getFolder(parentName);
    ResourceFilterUtil.addResourceFilter(folder, project.getName(), monitor);
    return project;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) SDK(com.liferay.ide.sdk.core.SDK) JarFile(java.util.jar.JarFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with ProjectRecord

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

the class ProjectImportUtil method validateSDKProjectPath.

public static IStatus validateSDKProjectPath(String currentPath) {
    IStatus retVal = validatePath(currentPath);
    if (!retVal.isOK()) {
        return retVal;
    }
    ProjectRecord record = ProjectUtil.getProjectRecordForDir(currentPath);
    if (record == null) {
        return ProjectCore.createErrorStatus("Invalid project location");
    }
    String projectName = record.getProjectName();
    IProject existingProject = CoreUtil.getWorkspaceRoot().getProject(projectName);
    if (FileUtil.exists(existingProject)) {
        return ProjectCore.createErrorStatus("Project name already exists.");
    }
    File projectDir = record.getProjectLocation().toFile();
    SDK sdk = SDKUtil.getSDKFromProjectDir(projectDir);
    if (sdk == null) {
        return ProjectCore.createErrorStatus("Could not determine SDK from project location " + currentPath);
    }
    try {
        IProject workspaceSdkProject = SDKUtil.getWorkspaceSDKProject();
        if ((workspaceSdkProject != null) && !workspaceSdkProject.getLocation().equals(sdk.getLocation())) {
            return ProjectCore.createErrorStatus("This project has different sdk than current workspace sdk");
        }
    } catch (CoreException ce) {
        return ProjectCore.createErrorStatus("Can't find sdk in workspace");
    }
    return sdk.validate(true);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) SDK(com.liferay.ide.sdk.core.SDK) JarFile(java.util.jar.JarFile) File(java.io.File) IProject(org.eclipse.core.resources.IProject)

Example 13 with ProjectRecord

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

the class ProjectCoreBase method importProject.

protected IProject importProject(String path, String bundleId, String projectName) throws Exception {
    final IPath sdkLocation = SDKManager.getInstance().getDefaultSDK().getLocation();
    final IPath projectFolder = sdkLocation.append(path);
    final File projectZipFile = getProjectZip(bundleId, projectName);
    ZipUtil.unzip(projectZipFile, projectFolder.toFile());
    final IPath projectPath = projectFolder.append(projectName);
    assertEquals(true, projectPath.toFile().exists());
    final ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectPath.toOSString());
    assertNotNull(projectRecord);
    final IRuntime runtime = ServerCore.findRuntime(getRuntimeVersion());
    assertNotNull(runtime);
    final IProject project = ProjectImportUtil.importProject(projectRecord, ServerUtil.getFacetRuntime(runtime), sdkLocation.toOSString(), new NullProgressMonitor());
    assertNotNull(project);
    assertEquals("Expected new project to exist.", true, project.exists());
    return project;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) File(java.io.File) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 14 with ProjectRecord

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

the class SDKProjectConvertWizardPage method createProjectsList.

protected void createProjectsList(Composite workArea) {
    Label title = new Label(workArea, SWT.NONE);
    title.setText(Msgs.importProjectLabel);
    title.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1));
    // Composite listComposite = new Composite(workArea, SWT.NONE);
    // GridLayout layout = new GridLayout();
    // layout.numColumns = 2;
    // layout.marginWidth = 0;
    // layout.makeColumnsEqualWidth = false;
    // listComposite.setLayout(layout);
    // GridData gd = new GridData(GridData.GRAB_HORIZONTAL
    // | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    // gd.grabExcessHorizontalSpace = true;
    // gd.horizontalSpan = 3;
    // listComposite.setLayoutData(gd);
    projectsList = new CheckboxTreeViewer(workArea, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        public void dispose() {
        }

        public Object[] getChildren(Object parentElement) {
            return null;
        }

        public Object[] getElements(Object inputElement) {
            return (Object[]) getDataModel().getProperty(SELECTED_PROJECTS);
        }

        public Object getParent(Object element) {
            return null;
        }

        public boolean hasChildren(Object element) {
            return false;
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(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()));
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 15 with ProjectRecord

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

the class SDKProjectsImportWizardPage method handleSelectAll.

protected void handleSelectAll(SelectionEvent e) {
    for (int i = 0; i < selectedProjects.length; i++) {
        ProjectRecord projectRecord = (ProjectRecord) selectedProjects[i];
        if (projectRecord.hasConflicts()) {
            projectsList.setChecked(projectRecord, false);
        } else {
            projectsList.setChecked(projectRecord, true);
        }
    }
    getDataModel().setProperty(SELECTED_PROJECTS, projectsList.getCheckedElements());
    validatePage(true);
// setPageComplete(projectsList.getCheckedElements().length >
// 0);
}
Also used : ProjectRecord(com.liferay.ide.project.core.ProjectRecord)

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