Search in sources :

Example 1 with ProjectRecord

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

the class LiferayLanguageFileEncodingTests method importProject.

private IProject importProject(String path, String name) throws Exception {
    final IPath sdkLocation = SDKManager.getInstance().getDefaultSDK().getLocation();
    final IPath hooksFolder = sdkLocation.append(path);
    final URL hookZipUrl = Platform.getBundle("com.liferay.ide.project.core.tests").getEntry("projects/" + name + ".zip");
    final File hookZipFile = new File(FileLocator.toFileURL(hookZipUrl).getFile());
    ZipUtil.unzip(hookZipFile, hooksFolder.toFile());
    final IPath projectFolder = hooksFolder.append(name);
    assertEquals(true, projectFolder.toFile().exists());
    final ProjectRecord projectRecord = ProjectUtil.getProjectRecordForDir(projectFolder.toOSString());
    assertNotNull(projectRecord);
    final IProject project = ProjectImportUtil.importProject(projectRecord, ServerUtil.getFacetRuntime(getRuntime()), 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject)

Example 2 with ProjectRecord

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

the class ProjectImportUtil method createWorkspaceProjects.

/**
 * This will create the Eclipse Workspace projects
 *
 * @param monitor
 * @throws CoreException
 */
public static void createWorkspaceProjects(Object[] projects, IRuntime runtime, String sdkLocation, IProgressMonitor monitor) throws CoreException {
    List<IProject> createdProjects = new ArrayList<>();
    monitor.beginTask(Msgs.creatingSDKWorkspaceProjects, projects.length);
    if (ListUtil.isNotEmpty(projects)) {
        SDK sdk = SDKManager.getInstance().getSDK(new Path(sdkLocation));
        if (sdk == null) {
            sdk = SDKUtil.createSDKFromLocation(new Path(sdkLocation));
        }
        if ((sdk != null) && sdk.isValid() && !(SDKManager.getInstance().containsSDK(sdk))) {
            SDKManager.getInstance().addSDK(sdk);
        }
    }
    for (int i = 0; i < projects.length; i++) {
        if (projects[i] instanceof ProjectRecord) {
            IProject project = importProject((ProjectRecord) projects[i], runtime, sdkLocation, monitor);
            if (project != null) {
                createdProjects.add(project);
                monitor.worked(createdProjects.size());
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) ArrayList(java.util.ArrayList) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) BinaryProjectRecord(com.liferay.ide.project.core.BinaryProjectRecord) SDK(com.liferay.ide.sdk.core.SDK) IProject(org.eclipse.core.resources.IProject)

Example 3 with ProjectRecord

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

the class ProjectUtil method getProjectRecordForDir.

public static ProjectRecord getProjectRecordForDir(String dir) {
    ProjectRecord projectRecord = null;
    File projectDir = new File(dir);
    if (isLiferaySDKProjectDir(projectDir)) {
        // determine if this is a previous eclipse project or vanilla
        String[] files = projectDir.list();
        for (String file : files) {
            if (IProjectDescription.DESCRIPTION_FILE_NAME.equals(file)) {
                projectRecord = new ProjectRecord(new File(projectDir, file));
            }
        }
        if (projectRecord == null) {
            projectRecord = new ProjectRecord(projectDir);
        }
    }
    return projectRecord;
}
Also used : ProjectRecord(com.liferay.ide.project.core.ProjectRecord) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 4 with ProjectRecord

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

the class XmlTestsBase method importProject.

@Override
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 URL projectZipUrl = Platform.getBundle(bundleId).getEntry("projects/" + projectName + ".zip");
    final File projectZipFile = new File(FileLocator.toFileURL(projectZipUrl).getFile());
    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) IFile(org.eclipse.core.resources.IFile) URL(java.net.URL) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 5 with ProjectRecord

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

the class SDKProjectConvertWizardPage 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() {

            public void run(IProgressMonitor monitor) {
                monitor.beginTask(Msgs.searchingMessage, 100);
                monitor.worked(10);
                if (dirSelected && directory.isDirectory()) {
                    ProjectRecord[] projectToConvert = (ProjectRecord[]) getDataModel().getProperty(SELECTED_PROJECTS);
                    IPath dir = new Path(directory.getPath());
                    if (dir.isPrefixOf(projectToConvert[0].getProjectLocation())) {
                        selectedProjects = projectToConvert;
                    } else {
                        selectedProjects = new ProjectRecord[0];
                    }
                } else {
                    monitor.worked(60);
                }
                monitor.done();
            }
        });
    } catch (InvocationTargetException ite) {
        IDEWorkbenchPlugin.log(ite.getMessage(), ite);
    } catch (InterruptedException ie) {
    }
    projectsList.refresh(true);
    if (ListUtil.isNotEmpty(selectedProjects)) {
        projectsList.setChecked(selectedProjects[0], true);
    }
    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 : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProjectRecord(com.liferay.ide.project.core.ProjectRecord) 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