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.google.appengine.eclipse.core.sdk.GaeSdkTest.java

License:Open Source License

/**
 * Tests {@link GaeSdk#findSdkFor(IJavaProject)} when the project is using raw
 * jars./*from w  w w.j  a v  a2s. c om*/
 *
 * FIXME: This test has been disabled until
 * http://code.google.com/p/google-plugin-for-eclipse/issues/detail?id=8
 * is fixed.
 */
// public void testFindSdkFor_UsingRawJars() throws JavaModelException {
// GaeSdk defaultSdk = GaePreferences.getDefaultSdk();
// IClasspathEntry[] classpathEntries = defaultSdk.getClasspathEntries();
// for (IClasspathEntry classpathEntry : classpathEntries) {
// JavaProjectUtilities.addRawClassPathEntry(javaProject, classpathEntry);
// }
//
// GaeSdk detectedSdk = GaeSdk.findSdkFor(javaProject);
// assertEquals(classpathEntries, detectedSdk.getClasspathEntries());
// }
@Override
protected void setUp() throws Exception {
    GaeSdkTestUtilities.addDefaultSdk();
    IJavaProject findJavaProject = JavaProjectUtilities.findJavaProject(getName());
    if (findJavaProject != null) {
        findJavaProject.getProject().delete(true, null);
    }
    javaProject = PluginTestUtils.createProject(getName());
}

From source file:com.google.appengine.eclipse.core.validators.GaeProjectValidator.java

License:Open Source License

@SuppressWarnings("unchecked")
private boolean validateUsingJava16OrNewer(IJavaProject javaProject) throws CoreException {
    IVMInstall3 vm = (IVMInstall3) JavaRuntime.getVMInstall(javaProject);
    if (vm == null) {
        // No VM is configured; wait until one is configured before warning user
        return true;
    }/*from  ww w . java 2s  . co m*/

    // This property maps to the JRE version, which is what App Engine checks
    // against
    String vmVersionSysProp = "java.specification.version";
    Map<String, String> sysPropValues = vm.evaluateSystemProperties(new String[] { vmVersionSysProp }, null);
    String vmVersion = sysPropValues.get(vmVersionSysProp);
    if (StringUtilities.isEmpty(vmVersion)) {
        AppEngineCorePluginLog.logWarning("Checking JRE version but the system property is empty.");
        // Assume it passes
        return true;
    }

    String[] vmVersionComponents = vmVersion.split("\\.");
    if (vmVersionComponents.length >= 2) {
        if (vmVersionComponents[0].equals("1")) {
            try {
                int minorVersion = Integer.parseInt(vmVersionComponents[1]);
                if (minorVersion < 6) {
                    MarkerUtilities.createQuickFixMarker(PROBLEM_MARKER_ID,
                            AppEngineProblemType.JAVA15_DEPRECATED, null, javaProject.getProject());
                    return false;
                }
            } catch (NumberFormatException e) {
                AppEngineCorePluginLog.logWarning(e, "Unexpected JRE version.");
            }
        }
    }

    return true;
}

From source file:com.google.appengine.eclipse.core.validators.java.GaeChecker.java

License:Open Source License

/**
 * Returns a {@link CategorizedProblem} for each use of a JRE type that is not
 * supported by the Google App Engine, and for each import from
 * com.google.appengine.repackaged. Package declarations are ignored.
 * // w w  w .  j  a  v  a  2 s . com
 * @param compilationUnit {@link CompilationUnit} to check
 * @param javaProject project that owns the {@link CompilationUnit}
 * @return {@link CategorizedProblem} for each use of a JRE type that is not
 *         supported by the Google App Engine and for each import from
 *         com.google.appengine.repackaged
 */
public static List<CategorizedProblem> check(CompilationUnit compilationUnit, IJavaProject javaProject) {
    List<CategorizedProblem> problems = new ArrayList<CategorizedProblem>();
    IProject project = javaProject.getProject();
    GaeProject gaeProject = GaeProject.create(project);
    GaeSdk sdk = gaeProject.getSdk();
    if (sdk != null && sdk.validate().isOK()) {
        GaeValidationVisitor visitor = new GaeValidationVisitor(gaeProject, problems);
        compilationUnit.accept(visitor);
    } else {
        // This will be caught by GAE project validation
    }
    return problems;
}

From source file:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

@Override
public void cleanStarting(IJavaProject project) {
    // Cancel the current validation job.
    synchronized (this) {
        Job buildJob = validationJobs.get(project.getProject());
        if (buildJob != null) {
            buildJob.cancel();/*from w ww. ja  v a2 s.c  o m*/
        }
    }
}

From source file:com.google.appengine.eclipse.core.validators.java.JavaCompilationParticipant.java

License:Open Source License

@Override
public boolean isActive(IJavaProject project) {
    return GaeNature.isGaeProject(project.getProject());
}

From source file:com.google.appengine.eclipse.core.validators.java.PluginTestUtils.java

License:Open Source License

public static GaeProject createGaeProject(String projectName) throws CoreException {

    IJavaProject javaProject = createProject(projectName);
    IProject project = javaProject.getProject();

    GaeNature.addNatureToProject(project);
    GaeProject gaeProject = GaeProject.create(project);

    try {/* www. j ava  2  s  . c  o  m*/
        WebAppUtilities.setDefaultWarSettings(project);

        UpdateWebInfFolderCommand webInfLibUpdateCommand = new AppEngineUpdateWebInfFolderCommand(javaProject,
                GaePreferences.getDefaultSdk());
        AppEngineUpdateProjectSdkCommand command = new AppEngineUpdateProjectSdkCommand(javaProject, null,
                GaePreferences.getDefaultSdk(), UpdateType.DEFAULT_CONTAINER, webInfLibUpdateCommand);
        command.execute();
    } catch (FileNotFoundException e) {
        throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
    } catch (BackingStoreException e) {
        throw new CoreException(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
    }

    // FIXME: Need to refactor all of this; it is also present in
    // AddNatureToProjectAction.perform
    // setOutputLocationToWarDir(gaeProject);

    return gaeProject;
}

From source file:com.google.appengine.eclipse.webtools.facet.AbstractJpaFacetHelper.java

License:Open Source License

public static void jobDisableDataNucleus(final IJavaProject javaProject) {
    Job job = new WorkspaceJob("") {
        @Override/* w  ww.  j  av a2 s.co m*/
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                // RemoveBuilder internally runs a job locked on the workspace root
                // Locking our DisableDataNucleus job on this project results in:
                // java.lang.IllegalArgumentException: Attempted to beginRule: R/,
                // does not match outer scope rule: P/foo
                // Hence our job should also run locked on the workspace root
                BuilderUtilities.removeBuilderFromProject(javaProject.getProject(),
                        GaeNature.CLASS_ENHANCER_BUILDER);
                GaeProjectProperties.setGaeDatanucleusEnabled(javaProject.getProject(), false);
                GaeSdk sdk = GaeSdk.findSdkFor(javaProject);
                (new AppEngineUpdateWebInfFolderCommand(javaProject, sdk)).execute();
                return Status.OK_STATUS;
            } catch (CoreException e) {
                // Log and continue
                AppEngineWtpPlugin.getLogger().logError(e);
                return e.getStatus();
            } catch (BackingStoreException e) {
                // Log and continue
                AppEngineWtpPlugin.getLogger().logError(e);
                return StatusUtilities.newErrorStatus(e, AppEngineWtpPlugin.PLUGIN_ID);
            } catch (FileNotFoundException e) {
                // Log and continue
                AppEngineWtpPlugin.getLogger().logError(e);
                return StatusUtilities.newErrorStatus(e, AppEngineWtpPlugin.PLUGIN_ID);
            }
        }
    };
    // Lock on workspace root
    job.setRule(javaProject.getProject().getWorkspace().getRoot());
    job.schedule();
}

From source file:com.google.appengine.eclipse.webtools.facet.AbstractJpaFacetHelper.java

License:Open Source License

public static void jobUpdatePersistenceAndWebInf(final IJavaProject javaProject,
        final PersistenceXmlUpdater updater) {
    Job job = new WorkspaceJob("") {
        @Override//from w ww.  java2  s  .c  om
        public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
                updater.updateConnection(javaProject);
                copyJpaLibraryToWebInf(javaProject);
                return Status.OK_STATUS;
            } catch (CoreException e) {
                // Log and continue
                AppEngineWtpPlugin.getLogger().logError(e);
                return e.getStatus();
            } catch (IOException e) {
                // Log and continue
                AppEngineWtpPlugin.getLogger().logError(e);
                return StatusUtilities.newErrorStatus(e, AppEngineWtpPlugin.PLUGIN_ID);
            }
        }
    };
    // Lock on project
    job.setRule(javaProject.getProject());
    job.schedule();
}

From source file:com.google.appengine.eclipse.webtools.facet.AbstractJpaFacetHelper.java

License:Open Source License

private static void copyJpaLibraryToWebInf(IJavaProject javaProject)
        throws CoreException, FileNotFoundException {
    IProject project = javaProject.getProject();
    if (!WebAppUtilities.hasManagedWarOut(project)) {
        // Nothing to do if project war directory is not managed
        return;//from  w  ww.jav  a  2  s . co m
    }

    // Get WEB-INF/lib folder (create if it doesn't exist)
    IFolder webInfLibFolder = WebAppUtilities.getWebInfLib(project);
    ResourceUtils.createFolderStructure(project, webInfLibFolder.getProjectRelativePath());

    // Copy jars to WEB-INF/lib
    List<IClasspathEntry> cpes = ClasspathUtil.getClasspathEntries(project,
            ProjectFacetsManager.getProjectFacet(FACET_JPT_JPA));
    for (IClasspathEntry cpe : cpes) {
        for (IPackageFragmentRoot fragment : javaProject.findPackageFragmentRoots(cpe)) {
            File srcFile = fragment.getPath().toFile();
            IFile destFile = webInfLibFolder.getFile(srcFile.getName());
            if (!destFile.exists()) {
                destFile.create(new FileInputStream(srcFile), true, null);
            }
        }
    }
}

From source file:com.google.devtools.bazel.e4b.BazelProjectSupport.java

License:Open Source License

private static void createClasspath(IPath root, List<String> paths, IJavaProject javaProject,
        int javaLanguageLevel) throws CoreException {
    String name = root.lastSegment();
    IFolder base = javaProject.getProject().getFolder(name);
    if (!base.isLinked()) {
        base.createLink(root, IResource.NONE, null);
    }//  w  w  w. j  av a 2s.  c  o m
    List<IClasspathEntry> list = new LinkedList<>();
    for (String path : paths) {
        IPath workspacePath = base.getFullPath().append(path);
        list.add(JavaCore.newSourceEntry(workspacePath));
    }
    list.add(JavaCore.newContainerEntry(new Path(BazelClasspathContainer.CONTAINER_NAME)));

    list.add(JavaCore.newContainerEntry(new Path(STANDARD_VM_CONTAINER_PREFIX + javaLanguageLevel)));
    IClasspathEntry[] newClasspath = list.toArray(new IClasspathEntry[0]);
    javaProject.setRawClasspath(newClasspath, null);
}