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.technophobia.eclipse.project.cache.listener.ClasspathChangedListener.java

License:Open Source License

@Override
public void elementChanged(final ElementChangedEvent event) {
    if (event.getType() == ElementChangedEvent.POST_CHANGE) {
        final IJavaElementDelta delta = event.getDelta();

        if (isDeltaChangeMatchForEvent(delta, FLAGS)) {
            try {
                for (final IJavaProject javaProject : delta.getElement().getJavaModel().getJavaProjects()) {
                    final IProject project = javaProject.getProject();
                    FeatureEditorPlugin.instance().info("Classpath has changed for project " + project);
                    projectChangedNotifier.doCallback(project);
                }//from  w w  w .j ava 2  s .  com
            } catch (final JavaModelException ex) {
                FeatureEditorPlugin.instance()
                        .error("Could not update caches for classpath change with event " + event, ex);
            }
        }
    }
}

From source file:com.technophobia.substeps.classloader.JavaProjectClassLoader.java

License:Open Source License

/**
 * Finds all classpath entries in project
 * /*from   ww w  . j av  a2 s .c o  m*/
 * @param project
 *            The current project
 * @return All classpath entries
 */
private String[] classPathEntriesFor(final IJavaProject project) {
    try {
        return JavaRuntime.computeDefaultRuntimeClassPath(project);
    } catch (final CoreException e) {
        FeatureEditorPlugin.instance().error("Could not get classpath entries for project "
                + project.getProject().getName() + ", returning empty array");
        return new String[0];
    }
}

From source file:com.technophobia.substeps.junit.launcher.migration.SubstepsMigrationDelegate.java

License:Open Source License

/**
 * Returns a resource mapping for the given launch configuration, or
 * <code>null</code> if none.
 * /*from   w w  w  .  j  a va  2 s . co  m*/
 * @param config
 *            working copy
 * @return resource or <code>null</code>
 * @throws CoreException
 *             if an exception occurs mapping resource
 */
private static IResource getResource(final ILaunchConfiguration config) throws CoreException {
    final String projName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME,
            (String) null);
    final String containerHandle = config.getAttribute(SubstepsLaunchConfigurationConstants.ATTR_TEST_CONTAINER,
            (String) null);
    final String typeName = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME,
            (String) null);
    IJavaElement element = null;
    if (containerHandle != null && containerHandle.length() > 0) {
        element = JavaCore.create(containerHandle);
    } else if (projName != null && Path.ROOT.isValidSegment(projName)) {
        final IJavaProject javaProject = getJavaModel().getJavaProject(projName);
        if (javaProject.exists()) {
            if (typeName != null && typeName.length() > 0) {
                element = javaProject.findType(typeName);
            }
            if (element == null) {
                element = javaProject;
            }
        } else {
            final IProject project = javaProject.getProject();
            if (project.exists() && !project.isOpen()) {
                return project;
            }
        }
    }
    IResource resource = null;
    if (element != null) {
        resource = element.getResource();
    }
    return resource;
}

From source file:com.technophobia.substeps.step.ProjectStepImplementationLoader.java

License:Open Source License

private String[] findDependenciesFor(final IJavaProject javaProject) {
    try {// ww w .ja  v  a2s  .  c om
        final IPackageFragmentRoot[] fragmentRoots = javaProject.getPackageFragmentRoots();
        final Collection<String> rootPaths = new ArrayList<String>(fragmentRoots.length);
        for (int i = 0; i < fragmentRoots.length; i++) {
            if (fragmentRoots[i].getKind() == IPackageFragmentRoot.K_BINARY) {
                final String path = getPathFor(fragmentRoots[i]);
                if (path != null) {
                    rootPaths.add(path);
                }
            }
        }
        return rootPaths.toArray(new String[rootPaths.size()]);
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get package fragment roots for project " + javaProject.getProject().getName());
        return new String[0];
    }
}

From source file:com.temenos.ds.op.xtext.generator.tests.MultiGeneratorXtextBuilderParticipantTest.java

License:Open Source License

protected IJavaProject createXtextJavaProject(String name) throws CoreException {
    IJavaProject project = createJavaProject(name);
    addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
    return project;
}

From source file:com.temenos.ds.op.xtext.generator.tests.MultiGeneratorXtextBuilderParticipantTest.java

License:Open Source License

protected IJavaProject createJavaProjectWithRootSrc(String string) throws CoreException {
    IJavaProject project = createJavaProject(string);
    addNature(project.getProject(), XtextProjectHelper.NATURE_ID);
    return project;
}

From source file:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java

License:Open Source License

private IWorkspaceRoot getWorkspaceRoot(final IJavaProject javaProject) {
    IProject _project = javaProject.getProject();
    IWorkspace _workspace = _project.getWorkspace();
    return _workspace.getRoot();
}

From source file:com.thalesgroup.optet.devenv.delivery.USDL.java

License:Open Source License

public IProject getCurrentProject() {
    ISelectionService selectionService = Workbench.getInstance().getActiveWorkbenchWindow()
            .getSelectionService();/*from   www . java2s.  co m*/

    ISelection selection = selectionService.getSelection();

    IProject project = null;
    if (selection instanceof IStructuredSelection) {
        Object element = ((IStructuredSelection) selection).getFirstElement();

        if (element instanceof IResource) {
            project = ((IResource) element).getProject();
        } else if (element instanceof PackageFragmentRootContainer) {
            IJavaProject jProject = ((PackageFragmentRootContainer) element).getJavaProject();
            project = jProject.getProject();
        } else if (element instanceof IJavaElement) {
            IJavaProject jProject = ((IJavaElement) element).getJavaProject();
            project = jProject.getProject();
        }
    }
    return project;
}

From source file:com.threecrickets.creel.eclipse.ClasspathInitializer.java

License:LGPL

public void initialize(IPath path, IJavaProject project) throws CoreException {
    Classpath classpath = new Classpath(project.getProject());
    JavaCore.setClasspathContainer(path, new IJavaProject[] { project },
            new IClasspathContainer[] { classpath }, null);
}

From source file:com.tsc9526.monalisa.orm.generator.DBGeneratorProcessing.java

License:Open Source License

public DBGeneratorProcessing(ProcessingEnvironment processingEnv, TypeElement typeElement) {
    super();/*from  ww  w .j  ava  2  s .c  om*/

    this.processingEnv = processingEnv;
    this.typeElement = typeElement;

    DB db = typeElement.getAnnotation(DB.class);
    if (db == null) {
        throw new RuntimeException("TypeElement without @DB: " + typeElement.toString());
    }
    String dbKey = db.key();
    if (dbKey == null || dbKey.length() < 1) {
        dbKey = typeElement.toString();
    }

    boolean inEclipseIDE = false;
    String projectPath = DbProp.CFG_ROOT_PATH;
    if (MelpEclipse.inEclipseIDE()) {
        if (processingEnv instanceof org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeBuildProcessingEnvImpl) {
            org.eclipse.jdt.core.IJavaProject project = ((org.eclipse.jdt.internal.apt.pluggable.core.dispatch.IdeBuildProcessingEnvImpl) processingEnv)
                    .getJavaProject();
            projectPath = project.getProject().getLocation().toString();

            inEclipseIDE = true;

            DbProp.SET_CFG_ROOT_PATH(projectPath);

            plogger.info("Generate(" + Version.getVersion() + ") files from eclipse project: " + projectPath
                    + " ...");
            plogger.info("Database " + dbKey + ", "
                    + (db.configFile().length() > 0 ? ("Config-file: " + db.configFile()) : (db.url())));
        }
    }

    if (!inEclipseIDE) {
        plogger.info("Generate(" + Version.getVersion() + ") files from dbkey: " + dbKey + "("
                + (db.configFile().length() > 0 ? db.configFile() : db.url()) + "): "
                + new File(DbProp.CFG_ROOT_PATH).getAbsolutePath() + " ...");
    }

    System.setProperty("DB@" + dbKey, projectPath);

    String name = typeElement.getQualifiedName().toString();
    setJavaResourcePackage(name);

    initDbcfg(dbKey, db);

    this.dbmetadata = new DBMetadata(projectPath, javaPackage, dbcfg);
}