Example usage for org.eclipse.jdt.core IJavaProject getProject

List of usage examples for org.eclipse.jdt.core IJavaProject getProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject getProject.

Prototype

IProject getProject();

Source Link

Document

Returns the IProject on which this IJavaProject was created.

Usage

From source file:com.liferay.ide.project.ui.migration.RunMigrationToolAction.java

License:Open Source License

@Override
public void run() {
    final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(shell);

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            final IJavaProject javaProject = (IJavaProject) selectedProjects[0];
            final ISelection selection = new StructuredSelection(javaProject.getProject());

            try {
                UIUtil.executeCommand("com.liferay.ide.project.ui.migrateProject", selection);
            } catch (ExecutionException | NotDefinedException | NotEnabledException | NotHandledException e) {
                ProjectUI.createErrorStatus("Error in migrate command", e);
            }//w ww . jav  a  2  s .  c o  m
        }
    }
}

From source file:com.liferay.ide.project.ui.upgrade.AbstractLiferayTableViewCustomPart.java

License:Open Source License

protected List<IProject> getSelectedProjects() {
    List<IProject> projects = new ArrayList<>();

    final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(
            Display.getCurrent().getActiveShell());

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    projects.add(p.getProject());
                }/*from w  ww.j a  v a2s.co  m*/
            }
        }
    }
    return projects;
}

From source file:com.liferay.ide.project.ui.upgrade.action.BuildServiceActionHandler.java

License:Open Source License

@Override
protected Object run(Presentation context) {
    List<IProject> projects = getServiceBuilderProjects();

    CustomProjectSelectionDialog dialog = new CustomProjectSelectionDialog(UIUtil.getActiveShell());

    dialog.setProjects(projects);//w w w .  j  a  va 2 s  .  c om

    List<IProject> liferayServiceProjects = new ArrayList<>();

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    liferayServiceProjects.add(p.getProject());
                }
            }
        }
    }

    try {
        PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    for (IProject project : liferayServiceProjects) {
                        deleteLegacyFiles(project, monitor);

                        SDK sdk = SDKUtil.getSDK(project);

                        sdk.runCommand(project, project.getFile("build.xml"),
                                ISDKConstants.TARGET_BUILD_SERVICE, null, monitor);

                        project.refreshLocal(IResource.DEPTH_INFINITE, monitor);

                        IConsole console = CompileAction.getConsole("build-service");

                        if (console != null) {
                            ProcessConsole pc = (ProcessConsole) console;

                            if (pc.getDocument().get().contains("BUILD FAILED")) {
                                return;
                            }
                        }
                    }
                } catch (CoreException e) {
                }
            }
        });
    } catch (Exception e) {
    }

    return null;
}

From source file:com.liferay.ide.project.ui.upgrade.animated.BuildPage.java

License:Open Source License

private List<IProject> getSelectedProjects() {
    List<IProject> projects = new ArrayList<>();

    final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(
            Display.getCurrent().getActiveShell());

    if (dialog.open() == Window.OK) {
        Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    projects.add(p.getProject());
                }/*from  ww w  .  j  a  v  a2  s . c  o m*/
            }
        }
    }

    return projects;
}

From source file:com.liferay.ide.project.ui.upgrade.animated.BuildServicePage.java

License:Open Source License

public BuildServicePage(Composite parent, int style, LiferayUpgradeDataModel dataModel) {
    super(parent, style, dataModel, BUILDSERVICE_PAGE_ID, true);

    Button buildServiceButton = new Button(this, SWT.PUSH);

    buildServiceButton.setText("Build Services");

    buildServiceButton.addSelectionListener(new SelectionAdapter() {

        private void deleteLegacyFiles(IProject project, IProgressMonitor monitor) {
            try {
                String relativePath = "/docroot/WEB-INF/src/META-INF";
                IFile portletSpringXML = project.getFile(relativePath + "/portlet-spring.xml");
                IFile shardDataSourceSpringXML = project
                        .getFile(relativePath + "/shard-data-source-spring.xml");

                if (portletSpringXML.exists()) {
                    portletSpringXML.delete(true, monitor);
                }// ww  w.  ja  va2 s . c o  m

                if (shardDataSourceSpringXML.exists()) {
                    shardDataSourceSpringXML.delete(true, monitor);
                }

                // for 6.2 maven project
                IFolder metaInfFolder = project.getFolder("/src/main/resources/META-INF/");

                if (metaInfFolder.exists()) {
                    metaInfFolder.delete(true, monitor);
                }
            } catch (CoreException e) {
                ProjectUI.logError(e);
            }
        }

        private List<IProject> getServiceBuilderProjects() {
            List<IProject> results = new ArrayList<IProject>();

            IProject[] projects = CoreUtil.getAllProjects();

            for (IProject project : projects) {
                IFile serviceFile = project.getFile("/docroot/WEB-INF/service.xml");

                if (!serviceFile.exists()) {
                    serviceFile = project.getFile("src/main/webapp/WEB-INF/service.xml");
                }

                if (serviceFile.exists()) {
                    results.add(project);
                }
            }

            return results;
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            List<IProject> projects = getServiceBuilderProjects();

            CustomProjectSelectionDialog dialog = new CustomProjectSelectionDialog(UIUtil.getActiveShell());

            dialog.setProjects(projects);

            URL imageUrl = ProjectUI.getDefault().getBundle().getEntry("/icons/e16/service.png");
            Image serviceXmlImage = ImageDescriptor.createFromURL(imageUrl).createImage();

            dialog.setImage(serviceXmlImage);
            dialog.setTitle("Liferay Service Project");
            dialog.setMessage("Select Liferay Service Project");

            List<IProject> liferayServiceProjects = new ArrayList<>();

            if (dialog.open() == Window.OK) {
                final Object[] selectedProjects = dialog.getResult();

                if (selectedProjects != null) {
                    for (Object project : selectedProjects) {
                        if (project instanceof IJavaProject) {
                            IJavaProject p = (IJavaProject) project;
                            liferayServiceProjects.add(p.getProject());
                        }
                    }
                }
            }

            try {
                PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() {

                    public void run(IProgressMonitor monitor)
                            throws InvocationTargetException, InterruptedException {
                        try {
                            for (IProject project : liferayServiceProjects) {
                                deleteLegacyFiles(project, monitor);

                                final ILiferayProject liferayProject = LiferayCore.create(project);

                                if (liferayProject != null) {
                                    IProjectBuilder builder = liferayProject.adapt(IProjectBuilder.class);

                                    builder.buildService(monitor);
                                }

                                IConsole console = CompileAction.getConsole("build-service");

                                if (console != null) {
                                    ProcessConsole pc = (ProcessConsole) console;

                                    if (pc.getDocument().get().contains("BUILD FAILED")) {
                                        return;
                                    }
                                }
                            }
                        } catch (CoreException e) {
                        }
                    }
                });
            } catch (Exception e1) {
            }
        }
    });
}

From source file:com.liferay.ide.project.ui.upgrade.animated.CustomJspPage.java

License:Open Source License

private void runConvertAction() {
    CustomProjectSelectionDialog dialog = new CustomProjectSelectionDialog(UIUtil.getActiveShell());

    dialog.setProjects(getHookProjects());
    URL imageUrl = ProjectUI.getDefault().getBundle().getEntry("/icons/e16/hook.png");
    Image hookImage = ImageDescriptor.createFromURL(imageUrl).createImage();

    dialog.setImage(hookImage);/*from   w w w. java  2  s  . co  m*/
    dialog.setTitle("Custom JSP Hook Project");
    dialog.setMessage("Select Custom JSP Hook Project");

    List<IProject> hookProjects = new ArrayList<>();

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    hookProjects.add(p.getProject());
                }
            }
        }
    }

    int size = hookProjects.size();

    if (size < 1) {
        return;
    }

    String[] sourcePaths = new String[size];

    for (int i = 0; i < size; i++) {
        sourcePaths[i] = hookProjects.get(i).getLocation().toOSString();
    }

    CustomJspConverter converter = new CustomJspConverter();

    IRuntime liferay70Runtime = getLiferay70Runtime();

    if (liferay70Runtime == null) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Convert Error",
                "Couldn't find Liferay 7.x Runtime.");

        return;
    }

    String liferay62ServerLocation = getLiferay62ServerLocation();

    if (liferay62ServerLocation == null) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), "Convert Error",
                "Couldn't find Liferay 6.2 Runtime.");

        return;
    }

    converter.setLiferay70Runtime(liferay70Runtime);
    converter.setLiferay62ServerLocation(liferay62ServerLocation);
    converter.setUi(this);

    String targetPath = dataModel.getConvertedProjectLocation().content().toPortableString();

    boolean isLiferayWorkapce = false;

    if (targetPath.equals(defaultLocation) && hasLiferayWorkspace) {
        isLiferayWorkapce = true;
    }

    converter.doExecute(sourcePaths, targetPath, isLiferayWorkapce);
}

From source file:com.liferay.ide.project.ui.upgrade.animated.LayoutTemplatePage.java

License:Open Source License

@Override
protected List<IProject> getSelectedProjects() {
    List<IProject> projects = new ArrayList<>();

    final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(
            Display.getCurrent().getActiveShell(), new LayoutProjectViewerFilter());

    URL imageUrl = ProjectUI.getDefault().getBundle().getEntry("/icons/e16/layout.png");
    Image layouttplImage = ImageDescriptor.createFromURL(imageUrl).createImage();

    dialog.setImage(layouttplImage);/* ww  w . j  a va  2  s. co m*/
    dialog.setTitle("Layout Template Project");
    dialog.setMessage("Select Layout Template Project");

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    projects.add(p.getProject());
                }
            }
        }
    }

    return projects;
}

From source file:com.liferay.ide.project.ui.upgrade.LiferayLayouttplUpgradeTableViewCustomPart.java

License:Open Source License

@Override
protected List<IProject> getSelectedProjects() {
    List<IProject> projects = new ArrayList<>();

    final JavaProjectSelectionDialog dialog = new JavaProjectSelectionDialog(
            Display.getCurrent().getActiveShell(), new LayoutProjectViewerFilter());

    if (dialog.open() == Window.OK) {
        final Object[] selectedProjects = dialog.getResult();

        if (selectedProjects != null) {
            for (Object project : selectedProjects) {
                if (project instanceof IJavaProject) {
                    IJavaProject p = (IJavaProject) project;
                    projects.add(p.getProject());
                }//from w w  w .  j a v  a2  s . co  m
            }
        }
    }

    return projects;
}

From source file:com.liferay.ide.project.ui.wizard.PluginClasspathContainerPage.java

License:Open Source License

public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) {
    this.ownerProject = (project == null ? null : project.getProject());
}

From source file:com.liferay.ide.server.remote.ModuleTraverser.java

License:Open Source License

private static Map getComponentClasspathDependencies(final IJavaProject javaProject, final boolean isWebApp)
        throws CoreException {

    // get the raw entries
    final Map referencedRawEntries = getRawComponentClasspathDependencies(javaProject);
    final Map<IClasspathEntry, IClasspathAttribute> validRawEntries = new HashMap<IClasspathEntry, IClasspathAttribute>();

    // filter out non-valid referenced raw entries
    final Iterator i = referencedRawEntries.keySet().iterator();
    while (i.hasNext()) {
        final IClasspathEntry entry = (IClasspathEntry) i.next();
        final IClasspathAttribute attrib = (IClasspathAttribute) referencedRawEntries.get(entry);
        if (isValid(entry, attrib, isWebApp, javaProject.getProject())) {
            validRawEntries.put(entry, attrib);
        }//from  w  w w  .  j a  v  a2 s. c  o  m
    }

    // if we have no valid raw entries, return empty map
    if (validRawEntries.isEmpty()) {
        return Collections.EMPTY_MAP;
    }

    // XXX Would like to replace the code below with use of a public JDT API that returns
    // the raw IClasspathEntry for a given resolved IClasspathEntry (see see https://bugs.eclipse.org/bugs/show_bug.cgi?id=183995)
    // The code must currently leverage IPackageFragmentRoot to determine this
    // mapping and, because IPackageFragmentRoots do not maintain IClasspathEntry data, a prior
    // call is needed to getResolvedClasspath() and the resolved IClasspathEntries have to be stored in a Map from IPath-to-IClasspathEntry to
    // support retrieval using the resolved IPackageFragmentRoot

    // retrieve the resolved classpath
    final IClasspathEntry[] entries = javaProject.getResolvedClasspath(true);
    final Map<IPath, IClasspathEntry> pathToResolvedEntry = new HashMap<IPath, IClasspathEntry>();

    // store in a map from path to entry
    for (int j = 0; j < entries.length; j++) {
        pathToResolvedEntry.put(entries[j].getPath(), entries[j]);
    }

    final Map<IClasspathEntry, IClasspathAttribute> referencedEntries = new LinkedHashMap<IClasspathEntry, IClasspathAttribute>();

    // grab all IPackageFragmentRoots
    final IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
    for (int j = 0; j < roots.length; j++) {
        final IPackageFragmentRoot root = roots[j];
        final IClasspathEntry rawEntry = root.getRawClasspathEntry();

        // is the raw entry valid?
        IClasspathAttribute attrib = validRawEntries.get(rawEntry);
        if (attrib == null) {
            continue;
        }

        final IPath pkgFragPath = root.getPath();
        final IClasspathEntry resolvedEntry = pathToResolvedEntry.get(pkgFragPath);
        final IClasspathAttribute resolvedAttrib = checkForComponentDependencyAttribute(resolvedEntry,
                DEPENDECYATTRIBUTETYPE_DEPENDENCY_OR_NONDEPENDENCY);
        // attribute for the resolved entry must either be unspecified or it must be the
        // dependency attribute for it to be included
        if (resolvedAttrib == null || resolvedAttrib.getName().equals(CLASSPATH_COMPONENT_DEPENDENCY)) {
            // filter out resolved entry if it doesn't pass the validation rules
            if (isValid(resolvedEntry, resolvedAttrib != null ? resolvedAttrib : attrib, isWebApp,
                    javaProject.getProject())) {
                if (resolvedAttrib != null) {
                    // if there is an attribute on the sub-entry, use that
                    attrib = resolvedAttrib;
                }
                referencedEntries.put(resolvedEntry, attrib);
            }
        }
    }

    return referencedEntries;
}