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.laex.j2objc.preferences.PackagePrefixPropertyPage.java

License:Open Source License

/**
 * Load properties.//w  ww.j av a2  s  . c  o m
 *
 * @throws CoreException the core exception
 */
private void loadProperties() throws CoreException {
    IJavaProject javaProject = ProjectUtil.getJavaProject(getElement());

    String propertiesFilePath = PropertiesUtil.constructPrefixPropertiesFilePath(javaProject.getProject());
    IFile propertiesFile = javaProject.getProject().getFile(propertiesFilePath);

    if (propertiesFile.exists()) {

        try {
            pkgPrefix.load(propertiesFile.getContents());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }

}

From source file:com.laex.j2objc.preferences.PackagePrefixPropertyPage.java

License:Open Source License

@Override
public boolean performOk() {
    IJavaProject javaProject = (IJavaProject) getElement();

    String propertiesFilePath = getPropertiesFileName(javaProject);
    IFile propertiesFile = javaProject.getProject().getFile(propertiesFilePath);

    if (propertiesFile.exists()) {
        try {/*  w  w  w  . j av a 2  s.c  o m*/
            propertiesFile.delete(true, null);
        } catch (CoreException e) {
            LogUtil.logException(e);
        }
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {
        pkgPrefix.store(baos, "");
        propertiesFile.create(new ByteArrayInputStream(baos.toByteArray()), false, null);
    } catch (IOException e) {
        LogUtil.logException(e);
    } catch (CoreException e) {
        LogUtil.logException(e);
    }

    return super.performOk();
}

From source file:com.legstar.eclipse.plugin.cixscom.wizards.AbstractCixsGeneratorWizardPage.java

License:Open Source License

/**
 * From a Java nature Eclipse project, this utility method retrieves either
 * a java source folder or an associated java output folder for binaries.
 * <p/>/*from   w  w w.  j  a v  a 2s. co m*/
 * The algorithm stops at the first source directory encountered.
 * 
 * @param project the current Eclipse project
 * @param source true if we are looking for a source folder, false for an
 *            output folder
 * @return a java folder (either source or output)
 */
protected File getJavaDir(final IProject project, final boolean source) {
    IJavaProject javaProject = JavaCore.create(project);
    if (javaProject != null) {
        IPath rootPath = javaProject.getProject().getLocation().removeLastSegments(1);

        /*
         * If this is a java project, get first Java source and output
         * folders.
         */
        try {
            IClasspathEntry[] cpe = javaProject.getRawClasspath();
            for (int i = 0; i < cpe.length; i++) {
                if (cpe[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    if (source) {
                        return rootPath.append(cpe[i].getPath()).toFile();
                    } else {
                        if (cpe[i].getOutputLocation() == null) {
                            return rootPath.append(javaProject.getOutputLocation()).toFile();
                        } else {
                            return rootPath.append(cpe[i].getOutputLocation()).toFile();
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            AbstractWizard.errorDialog(getShell(), Messages.generate_error_dialog_title, getPluginId(),
                    Messages.java_location_lookup_failure_msg,
                    NLS.bind(Messages.invalid_java_project_msg, project.getName(), e.getMessage()));
            AbstractWizard.logCoreException(e, getPluginId());
        }
    }
    /*
     * If everything else failed, assume generated artifacts will go to the
     * project root.
     */
    return project.getLocation().toFile();
}

From source file:com.legstar.eclipse.plugin.schemagen.wizards.JavaToXsdWizardPage.java

License:Open Source License

/**
 * Given classpath entries from a java project, populate a list of
 * collections.//from  w w  w  . j a  va 2 s.com
 * 
 * @param selectedPathElementsLocations the output path locations
 * @param classPathEntries the java project class path entries
 * @param javaProject the java project
 * @throws JavaModelException if invalid classpath
 */
private void addPathElements(final List<String> selectedPathElementsLocations,
        final IClasspathEntry[] classPathEntries, final IJavaProject javaProject) throws JavaModelException {

    IClasspathEntry jreEntry = JavaRuntime.getDefaultJREContainerEntry();
    IPath projectPath = javaProject.getProject().getLocation();

    for (int i = 0; i < classPathEntries.length; i++) {
        IClasspathEntry classpathEntry = classPathEntries[i];
        String pathElementLocation = null;
        switch (classpathEntry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            pathElementLocation = classpathEntry.getPath().toOSString();
            break;
        case IClasspathEntry.CPE_CONTAINER:
            /* No need for the default jre */
            if (classpathEntry.equals(jreEntry)) {
                break;
            }
            /* Resolve container into class path entries */
            IClasspathContainer classpathContainer = JavaCore.getClasspathContainer(classpathEntry.getPath(),
                    javaProject);
            addPathElements(selectedPathElementsLocations, classpathContainer.getClasspathEntries(),
                    javaProject);
            break;
        case IClasspathEntry.CPE_VARIABLE:
            pathElementLocation = JavaCore.getResolvedVariablePath(classpathEntry.getPath()).toOSString();
            break;
        case IClasspathEntry.CPE_SOURCE:
            /*
             * If source has no specific output, use the project default
             * one
             */
            IPath outputLocation = classpathEntry.getOutputLocation();
            if (outputLocation == null) {
                outputLocation = javaProject.getOutputLocation();
            }
            pathElementLocation = projectPath.append(outputLocation.removeFirstSegments(1)).toOSString();
            break;
        default:
            break;
        }

        if (pathElementLocation != null && !selectedPathElementsLocations.contains(pathElementLocation)) {
            selectedPathElementsLocations.add(pathElementLocation);
        }
    }
}

From source file:com.liferay.blade.eclipse.provider.WorkspaceHelper.java

License:Open Source License

public IFile createIFile(String projectName, File file) throws CoreException, IOException {
    IJavaProject project = getJavaProject(projectName);

    IFile projectFile = project.getProject().getFile(file.getName());

    final IProgressMonitor npm = new NullProgressMonitor();

    if (projectFile.exists()) {
        projectFile.delete(IFile.FORCE, npm);
    }/* w w  w.ja  v a  2 s .c  o  m*/

    projectFile.create(new ByteArrayInputStream(IO.read(file)), IFile.FORCE, npm);

    return projectFile;
}

From source file:com.liferay.ide.adt.ui.handlers.AddLibraryAndroidSDKLibsHandler.java

License:Open Source License

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IStatus retval = null;/*from ww  w  . ja v  a 2 s  .com*/

    final ISelection selection = HandlerUtil.getCurrentSelection(event);

    if (selection instanceof IStructuredSelection) {
        final IStructuredSelection structuredSelection = (IStructuredSelection) selection;

        Object selected = structuredSelection.getFirstElement();

        IJavaProject project = null;

        if (selected instanceof IResource) {
            project = JavaCore.create(((IResource) selected).getProject());
        } else if (selected instanceof IJavaProject) {
            project = (IJavaProject) selected;
        }

        if (project != null) {
            try {
                final Map<String, File[]> libmap = MobileSDKCore.getLibraryMap();

                final File[] libs = libmap.get("liferay-android-sdk-6.2.0.1");

                final NullProgressMonitor npm = new NullProgressMonitor();

                ADTUtil.addLibsToAndroidProject(project.getProject(), Collections.singletonList(libs), npm);

                project.getProject().refreshLocal(IResource.DEPTH_INFINITE, npm);

                MessageDialog.openInformation(HandlerUtil.getActiveShellChecked(event), "Liferay Mobile SDK",
                        "Successfully added Liferay Android SDK libraries to project.");
            } catch (CoreException e) {
                retval = ADTUI.createErrorStatus("Could not add libraries to Android project", e);
            }
        }
    }

    return retval == null ? Status.OK_STATUS : retval;
}

From source file:com.liferay.ide.adt.ui.wizard.GenerateCustomServicesWizard.java

License:Open Source License

private static String computeSettingsFileName(final IJavaProject project) {
    // Compute a unique path for the settings file based on a hash associated with the project
    final String uniquePath = GenerateCustomServicesWizard.class.getName()
            + project.getProject().getLocationURI().getPath();

    return uniquePath != null ? MiscUtil.createStringDigest(uniquePath) : null;
}

From source file:com.liferay.ide.adt.ui.wizard.GenerateCustomServicesWizard.java

License:Open Source License

private static GenerateCustomServicesOp initElement(IJavaProject project) {
    GenerateCustomServicesOp op = GenerateCustomServicesOp.TYPE.instantiate();

    op.setProjectName(project.getProject().getName());
    applySettings(op);// w w  w.  jav a2s  .  co  m

    return op;
}

From source file:com.liferay.ide.kaleo.core.WorkflowSupportManager.java

License:Open Source License

private void computeClasspath(IJavaProject project, IProgressMonitor monitor) {
    int numEntries = 2;
    IPath runtimeContainerPath = null;/*from  w w w .  ja va  2s  .c  o  m*/

    try {
        String id = this.currentServer.getRuntime().getId();
        runtimeContainerPath = new Path(
                "org.eclipse.jst.server.core.container/com.liferay.ide.eclipse.server.tomcat.runtimeClasspathProvider/"
                        + id);
        numEntries++;
    } catch (Throwable t) {
        // do nothing
    }

    IClasspathEntry[] classpath = new IClasspathEntry[numEntries];
    classpath[0] = JavaCore.newContainerEntry(JavaRuntime.newDefaultJREContainerPath());
    classpath[1] = JavaCore.newSourceEntry(project.getProject().getFolder("src").getFullPath());

    if (runtimeContainerPath != null) {
        classpath[2] = JavaCore.newContainerEntry(runtimeContainerPath);
    }

    try {
        project.setRawClasspath(classpath, monitor);
    } catch (JavaModelException e) {
    }
}

From source file:com.liferay.ide.kaleo.ui.WorkflowProjectAdapterService.java

License:Open Source License

@Override
public <A> A convert(Object object, Class<A> adapterType) {
    A retval = null;//from  w w w  .  j a v a  2 s .  c  om

    if (IProject.class.equals(adapterType)) {
        ISapphirePart sapphirePart = context().find(ISapphirePart.class);

        WorkflowDefinition workflowDefinition = sapphirePart.getLocalModelElement()
                .nearest(WorkflowDefinition.class);

        IFile file = workflowDefinition.adapt(IFile.class);

        if (file != null) {
            retval = adapterType.cast(file.getProject());
        } else {
            // create support project
            WorkflowSupportManager workflowSupportManager = KaleoCore.getDefault().getWorkflowSupportManager();

            IEditorInput editorInput = workflowDefinition.adapt(IEditorInput.class);

            if (editorInput instanceof WorkflowDefinitionEditorInput) {
                WorkflowDefinitionEditorInput workflowInput = (WorkflowDefinitionEditorInput) editorInput;
                IServer server = workflowInput.getWorkflowDefinitionEntry().getParent().getParent();

                workflowSupportManager.setCurrentServer(server);
            }

            IJavaProject supportProject = workflowSupportManager.getSupportProject();

            retval = adapterType.cast(supportProject.getProject());
        }
    }

    return retval;
}