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

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

Introduction

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

Prototype

void setOptions(Map<String, String> newOptions);

Source Link

Document

Sets the project custom options.

Usage

From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.BuildPathSupport.java

License:Open Source License

public static void setEEComplianceOptions(IJavaProject javaProject, String eeID, String newProjectCompliance) {
    IExecutionEnvironment ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeID);
    if (ee != null) {
        Map<String, String> options = javaProject.getOptions(false);
        Map<String, String> eeOptions = getEEOptions(ee);
        if (eeOptions != null) {
            for (int i = 0; i < PREFS_COMPLIANCE.length; i++) {
                String option = PREFS_COMPLIANCE[i];
                options.put(option, eeOptions.get(option));
            }/*from ww  w .  j a  v  a2s  .  c  o m*/

            if (newProjectCompliance != null) {
                JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options
            }

            String option = JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE;
            String inlineJSR = eeOptions.get(option);
            if (inlineJSR != null) {
                options.put(option, inlineJSR);
            }

            javaProject.setOptions(options);
        }
    }
}

From source file:at.bestsolution.javafx.ide.jdt.internal.NewJavaProjectService.java

License:Open Source License

public static void flush(List<CPListElement> classPathEntries, IPath outputLocation, IJavaProject javaProject,
        String newProjectCompliance, IProgressMonitor monitor)
        throws CoreException, OperationCanceledException {
    IProject project = javaProject.getProject();
    IPath projPath = project.getFullPath();

    IPath oldOutputLocation;/*w ww.j av  a 2s.c o m*/
    try {
        oldOutputLocation = javaProject.getOutputLocation();
    } catch (CoreException e) {
        oldOutputLocation = projPath.append(
                "bin"/*PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME)*/);
    }

    if (oldOutputLocation.equals(projPath) && !outputLocation.equals(projPath)) {
        if (BuildPathsBlock.hasClassfiles(project)) {
            //            if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(false, projPath)) {
            BuildPathsBlock.removeOldClassfiles(project);
            //            }
        }
    } else if (!outputLocation.equals(oldOutputLocation)) {
        IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation);
        if (folder.exists()) {
            if (folder.members().length == 0) {
                BuildPathsBlock.removeOldClassfiles(folder);
            } else {
                //               if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell()).doQuery(folder.isDerived(), oldOutputLocation)) {
                BuildPathsBlock.removeOldClassfiles(folder);
                //               }
            }
        }
    }

    monitor.worked(1);

    IWorkspaceRoot fWorkspaceRoot = ResourcesPlugin.getWorkspace().getRoot();

    //create and set the output path first
    if (!fWorkspaceRoot.exists(outputLocation)) {
        IFolder folder = fWorkspaceRoot.getFolder(outputLocation);
        CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
    } else {
        monitor.worked(1);
    }
    if (monitor.isCanceled()) {
        throw new OperationCanceledException();
    }

    int nEntries = classPathEntries.size();
    IClasspathEntry[] classpath = new IClasspathEntry[nEntries];
    int i = 0;

    for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) {
        CPListElement entry = iter.next();
        classpath[i] = entry.getClasspathEntry();
        i++;

        IResource res = entry.getResource();
        //1 tick
        if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) {
            CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }

        //3 ticks
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT);
            if (folderOutput != null && folderOutput.segmentCount() > 1) {
                IFolder folder = fWorkspaceRoot.getFolder(folderOutput);
                CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
            } else {
                monitor.worked(1);
            }

            IPath path = entry.getPath();
            if (projPath.equals(path)) {
                monitor.worked(2);
                continue;
            }

            if (projPath.isPrefixOf(path)) {
                path = path.removeFirstSegments(projPath.segmentCount());
            }
            IFolder folder = project.getFolder(path);
            IPath orginalPath = entry.getOrginalPath();
            if (orginalPath == null) {
                if (!folder.exists()) {
                    //New source folder needs to be created
                    if (entry.getLinkTarget() == null) {
                        CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2));
                    } else {
                        folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                new SubProgressMonitor(monitor, 2));
                    }
                }
            } else {
                if (projPath.isPrefixOf(orginalPath)) {
                    orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount());
                }
                IFolder orginalFolder = project.getFolder(orginalPath);
                if (entry.getLinkTarget() == null) {
                    if (!folder.exists()) {
                        //Source folder was edited, move to new location
                        IPath parentPath = entry.getPath().removeLastSegments(1);
                        if (projPath.isPrefixOf(parentPath)) {
                            parentPath = parentPath.removeFirstSegments(projPath.segmentCount());
                        }
                        if (parentPath.segmentCount() > 0) {
                            IFolder parentFolder = project.getFolder(parentPath);
                            if (!parentFolder.exists()) {
                                CoreUtility.createFolder(parentFolder, true, true,
                                        new SubProgressMonitor(monitor, 1));
                            } else {
                                monitor.worked(1);
                            }
                        } else {
                            monitor.worked(1);
                        }
                        orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1));
                    }
                } else {
                    if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) {
                        orginalFolder.delete(true, new SubProgressMonitor(monitor, 1));
                        folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                new SubProgressMonitor(monitor, 1));
                    }
                }
            }
        } else {
            if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                IPath path = entry.getPath();
                if (!path.equals(entry.getOrginalPath())) {
                    String eeID = JavaRuntime.getExecutionEnvironmentId(path);
                    if (eeID != null) {
                        BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance);
                        newProjectCompliance = null; // don't set it again below
                    }
                }
                if (newProjectCompliance != null) {
                    Map<String, String> options = javaProject.getOptions(false);
                    JavaModelUtil.setComplianceOptions(options, newProjectCompliance);
                    JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options
                    javaProject.setOptions(options);
                }
            }
            monitor.worked(3);
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }
    }

    javaProject.setRawClasspath(classpath, outputLocation, new SubProgressMonitor(monitor, 2));
}

From source file:ca.mcgill.cs.swevo.ppa.ui.PPAJavaProjectHelper.java

License:Open Source License

public void createProject() throws CoreException, InterruptedException {
    try {//from   w  w w.  j a va2 s  .com
        if (fCurrProject == null) {
            updateProject();
        }
        configureJavaProject();

        if (!fKeepContent) {
            String compliance = fFirstPage.getCompilerCompliance();
            if (compliance != null) {
                IJavaProject project = JavaCore.create(fCurrProject);
                Map options = project.getOptions(false);
                JavaModelUtil.setComplianceOptions(options, compliance);
                JavaModelUtil.setDefaultClassfileOptions(options, compliance);
                project.setOptions(options);
            }
        }
    } finally {
        fCurrProject = null;
        if (fIsAutobuild != null) {
            CoreUtility.setAutoBuilding(fIsAutobuild.booleanValue());
            fIsAutobuild = null;
        }
    }
}

From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java

License:Open Source License

/**
 * Makes the given project use JDK 6 (or more specifically,
 * {@link AdtConstants#COMPILER_COMPLIANCE_PREFERRED} as the compilation
 * target, regardless of what the default IDE JDK level is, provided a JRE
 * of the given level is installed.//from  w w w .j a  v  a2 s  .  c o m
 *
 * @param javaProject the Java project
 * @throws CoreException if the IDE throws an exception setting the compiler
 *             level
 */
@SuppressWarnings("restriction") // JDT API for setting compliance options
public static void enforcePreferredCompilerCompliance(@NonNull IJavaProject javaProject) throws CoreException {
    String compliance = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
    if (compliance == null || JavaModelUtil.isVersionLessThan(compliance, COMPILER_COMPLIANCE_PREFERRED)) {
        IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
        for (int i = 0; i < types.length; i++) {
            IVMInstallType type = types[i];
            IVMInstall[] installs = type.getVMInstalls();
            for (int j = 0; j < installs.length; j++) {
                IVMInstall install = installs[j];
                if (install instanceof IVMInstall2) {
                    IVMInstall2 install2 = (IVMInstall2) install;
                    // Java version can be 1.6.0, and preferred is 1.6
                    if (install2.getJavaVersion().startsWith(COMPILER_COMPLIANCE_PREFERRED)) {
                        Map<String, String> options = javaProject.getOptions(false);
                        JavaCore.setComplianceOptions(COMPILER_COMPLIANCE_PREFERRED, options);
                        JavaModelUtil.setDefaultClassfileOptions(options, COMPILER_COMPLIANCE_PREFERRED);
                        javaProject.setOptions(options);
                        return;
                    }
                }
            }
        }
    }
}

From source file:com.redhat.ceylon.eclipse.code.preferences.CeylonBuildPathsBlock.java

License:Open Source License

private static void setOptionsFromJavaProject(IJavaProject javaProject, String newProjectCompliance) {
    @SuppressWarnings("unchecked")
    Map<String, String> options = javaProject.getOptions(false);
    JavaModelUtil.setComplianceOptions(options, newProjectCompliance);
    JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options
    javaProject.setOptions(options);
}

From source file:com.redhat.ceylon.eclipse.code.wizard.BuildPathsBlock.java

License:Open Source License

/**
 * Sets the configured build path and output location to the given Java project.
 * If the project already exists, only build paths are updated.
 * <p>//from  w  w  w .  jav a 2 s .  co m
 * If the classpath contains an Execution Environment entry, the EE's compiler compliance options
 * are used as project-specific options (unless the classpath already contained the same Execution Environment)
 * 
 * @param classPathEntries the new classpath entries (list of {@link CPListElement})
 * @param javaOutputLocation the output location
 * @param javaProject the Java project
 * @param newProjectCompliance compliance to set for a new project, can be <code>null</code>
 * @param monitor a progress monitor, or <code>null</code>
 * @throws CoreException if flushing failed
 * @throws OperationCanceledException if flushing has been cancelled
 */
public static void flush(List<CPListElement> classPathEntries, IPath javaOutputLocation,
        IJavaProject javaProject, String newProjectCompliance, IProgressMonitor monitor)
        throws CoreException, OperationCanceledException {
    if (monitor == null) {
        monitor = new NullProgressMonitor();
    }
    monitor.setTaskName(NewWizardMessages.BuildPathsBlock_operationdesc_java);
    monitor.beginTask("", classPathEntries.size() * 4 + 4); //$NON-NLS-1$
    try {
        IProject project = javaProject.getProject();
        IPath projPath = project.getFullPath();

        IPath oldOutputLocation;
        try {
            oldOutputLocation = javaProject.getOutputLocation();
        } catch (CoreException e) {
            oldOutputLocation = projPath.append(
                    PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME));
        }

        if (oldOutputLocation.equals(projPath) && !javaOutputLocation.equals(projPath)) {
            if (BuildPathsBlock.hasClassfiles(project)) {
                if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell())
                        .doQuery(false, projPath)) {
                    BuildPathsBlock.removeOldClassfiles(project);
                }
            }
        } else if (!javaOutputLocation.equals(oldOutputLocation)) {
            IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(oldOutputLocation);
            if (folder.exists()) {
                if (folder.members().length == 0) {
                    BuildPathsBlock.removeOldClassfiles(folder);
                } else {
                    if (BuildPathsBlock.getRemoveOldBinariesQuery(JavaPlugin.getActiveWorkbenchShell())
                            .doQuery(folder.isDerived(), oldOutputLocation)) {
                        BuildPathsBlock.removeOldClassfiles(folder);
                    }
                }
            }
        }

        //TODO: more robust clean up the "old" ceylon output location!
        project.getFolder("modules").delete(true, monitor);

        monitor.worked(1);

        IWorkspaceRoot fWorkspaceRoot = JavaPlugin.getWorkspace().getRoot();

        //create and set the output path first
        if (!fWorkspaceRoot.exists(javaOutputLocation)) {
            CoreUtility.createDerivedFolder(fWorkspaceRoot.getFolder(javaOutputLocation), true, true,
                    new SubProgressMonitor(monitor, 1));
        } else {
            monitor.worked(1);
        }
        if (monitor.isCanceled()) {
            throw new OperationCanceledException();
        }

        int nEntries = classPathEntries.size();
        IClasspathEntry[] classpath = new IClasspathEntry[nEntries];
        int i = 0;

        for (Iterator<CPListElement> iter = classPathEntries.iterator(); iter.hasNext();) {
            CPListElement entry = iter.next();
            classpath[i] = entry.getClasspathEntry();
            i++;

            IResource res = entry.getResource();
            //1 tick
            if (res instanceof IFolder && entry.getLinkTarget() == null && !res.exists()) {
                CoreUtility.createFolder((IFolder) res, true, true, new SubProgressMonitor(monitor, 1));
            } else {
                monitor.worked(1);
            }

            //3 ticks
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                IPath folderOutput = (IPath) entry.getAttribute(CPListElement.OUTPUT);
                if (folderOutput != null && folderOutput.segmentCount() > 1) {
                    IFolder folder = fWorkspaceRoot.getFolder(folderOutput);
                    CoreUtility.createDerivedFolder(folder, true, true, new SubProgressMonitor(monitor, 1));
                } else {
                    monitor.worked(1);
                }

                IPath path = entry.getPath();
                if (projPath.equals(path)) {
                    monitor.worked(2);
                    continue;
                }

                if (projPath.isPrefixOf(path)) {
                    path = path.removeFirstSegments(projPath.segmentCount());
                }
                IFolder folder = project.getFolder(path);
                IPath orginalPath = entry.getOrginalPath();
                if (orginalPath == null) {
                    if (!folder.exists()) {
                        //New source folder needs to be created
                        if (entry.getLinkTarget() == null) {
                            CoreUtility.createFolder(folder, true, true, new SubProgressMonitor(monitor, 2));
                        } else {
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 2));
                        }
                    }
                } else {
                    if (projPath.isPrefixOf(orginalPath)) {
                        orginalPath = orginalPath.removeFirstSegments(projPath.segmentCount());
                    }
                    IFolder orginalFolder = project.getFolder(orginalPath);
                    if (entry.getLinkTarget() == null) {
                        if (!folder.exists()) {
                            //Source folder was edited, move to new location
                            IPath parentPath = entry.getPath().removeLastSegments(1);
                            if (projPath.isPrefixOf(parentPath)) {
                                parentPath = parentPath.removeFirstSegments(projPath.segmentCount());
                            }
                            if (parentPath.segmentCount() > 0) {
                                IFolder parentFolder = project.getFolder(parentPath);
                                if (!parentFolder.exists()) {
                                    CoreUtility.createFolder(parentFolder, true, true,
                                            new SubProgressMonitor(monitor, 1));
                                } else {
                                    monitor.worked(1);
                                }
                            } else {
                                monitor.worked(1);
                            }
                            orginalFolder.move(entry.getPath(), true, true, new SubProgressMonitor(monitor, 1));
                        }
                    } else {
                        if (!folder.exists() || !entry.getLinkTarget().equals(entry.getOrginalLinkTarget())) {
                            orginalFolder.delete(true, new SubProgressMonitor(monitor, 1));
                            folder.createLink(entry.getLinkTarget(), IResource.ALLOW_MISSING_LOCAL,
                                    new SubProgressMonitor(monitor, 1));
                        }
                    }
                }
            } else {
                if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    IPath path = entry.getPath();
                    if (!path.equals(entry.getOrginalPath())) {
                        String eeID = JavaRuntime.getExecutionEnvironmentId(path);
                        if (eeID != null) {
                            BuildPathSupport.setEEComplianceOptions(javaProject, eeID, newProjectCompliance);
                            newProjectCompliance = null; // don't set it again below
                        }
                    }
                    if (newProjectCompliance != null) {
                        Map<String, String> options = javaProject.getOptions(false);
                        JavaModelUtil.setComplianceOptions(options, newProjectCompliance);
                        JavaModelUtil.setDefaultClassfileOptions(options, newProjectCompliance); // complete compliance options
                        javaProject.setOptions(options);
                    }
                }
                monitor.worked(3);
            }
            if (monitor.isCanceled()) {
                throw new OperationCanceledException();
            }
        }

        javaProject.setRawClasspath(classpath, javaOutputLocation, new SubProgressMonitor(monitor, 2));
    } finally {
        monitor.done();
    }
}

From source file:com.sabre.buildergenerator.TestHelper.java

License:Open Source License

/**
 * @param projectName name of the project
 * @param sourcePath e.g. "src"/*from  ww w.j a v  a2s .  c  om*/
 * @param javaVMVersion e.g. JavaCore.VERSION_1_6; null indicates default
 * @param targetPlatform e.g. JavaCore.VERSION_1_5; must not be null
 * @throws CoreException error
 * @throws JavaModelException error
 */
@SuppressWarnings("unchecked")
public static IJavaProject createJavaProject(String projectName, String sourcePath, String javaVMVersion,
        String targetPlatform) throws CoreException, JavaModelException {
    // create project
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    project.create(null);
    project.open(null);

    // create source folder
    IPath srcPath = new Path(sourcePath);
    IFolder srcFolder = project.getFolder(srcPath);
    srcFolder.create(true, true, null);

    // class path
    IClasspathEntry sourceEntry = JavaCore.newSourceEntry(project.getFullPath().append(srcPath));

    IClasspathEntry[] jreLibrary = null;
    if (javaVMVersion != null) {
        vmType: for (IVMInstallType vmInstallType : JavaRuntime.getVMInstallTypes()) {
            for (IVMInstall vmInstall : vmInstallType.getVMInstalls()) {
                if (javaVMVersion.equals(((AbstractVMInstall) vmInstall).getJavaVersion())) {
                    IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER);
                    IPath vmPath = containerPath.append(vmInstall.getVMInstallType().getId())
                            .append(vmInstall.getName());
                    jreLibrary = new IClasspathEntry[] { JavaCore.newContainerEntry(vmPath) };
                    break vmType;
                }
            }
        }
    }
    if (jreLibrary == null) {
        jreLibrary = PreferenceConstants.getDefaultJRELibrary();
    }

    // create java project
    IJavaProject javaProject = JavaCore.create(project);
    IProjectDescription description = project.getDescription();
    String[] natureIds = description.getNatureIds();
    String[] newNatureIds = new String[natureIds.length + 1];
    System.arraycopy(natureIds, 0, newNatureIds, 0, natureIds.length);
    newNatureIds[newNatureIds.length - 1] = JavaCore.NATURE_ID;
    description.setNatureIds(newNatureIds);
    project.setDescription(description, null);

    // create binary folder
    String binName = PreferenceConstants.getPreferenceStore().getString(PreferenceConstants.SRCBIN_BINNAME);
    IFolder binFolder = project.getFolder(binName);
    binFolder.create(IResource.FORCE | IResource.DERIVED, true, null);
    binFolder.setDerived(true);

    project.refreshLocal(IResource.DEPTH_INFINITE, null);

    // set project class path
    javaProject.setRawClasspath(merge(jreLibrary, new IClasspathEntry[] { sourceEntry }),
            binFolder.getFullPath(), null);

    // set options
    Map<String, String> options = javaProject.getOptions(true);
    options.put(JavaCore.COMPILER_COMPLIANCE, targetPlatform);
    options.put(JavaCore.COMPILER_SOURCE, targetPlatform);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, targetPlatform);
    options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
    javaProject.setOptions(options);

    return javaProject;
}

From source file:com.siteview.mde.internal.core.ClasspathComputer.java

License:Open Source License

/**
 * Sets compiler compliance options on the given project to match the default compliance settings
 * for the specified execution environment. Only sets options that do not already have an explicit
 * setting based on the given override flag.
 * <p>/*from  www. j a v  a  2 s .co m*/
 * If the specified execution environment is <code>null</code> and override is <code>true</code>,
 * all compliance options are removed from the options map before applying to the project.
 * </p>
 * @param project project to set compiler compliance options for
 * @param eeId execution environment identifier, or <code>null</code>
 * @param overrideExisting whether to override a setting if already present
 */
public static void setComplianceOptions(IJavaProject project, String eeId, boolean overrideExisting) {
    Map projectMap = project.getOptions(false);
    IExecutionEnvironment ee = null;
    Map options = null;
    if (eeId != null) {
        ee = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
        if (ee != null) {
            options = ee.getComplianceOptions();
        }
    }
    if (options == null) {
        if (overrideExisting && projectMap.size() > 0) {
            projectMap.remove(JavaCore.COMPILER_COMPLIANCE);
            projectMap.remove(JavaCore.COMPILER_SOURCE);
            projectMap.remove(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM);
            projectMap.remove(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER);
            projectMap.remove(JavaCore.COMPILER_PB_ENUM_IDENTIFIER);
        } else {
            return;
        }
    } else {
        String compliance = (String) options.get(JavaCore.COMPILER_COMPLIANCE);
        Iterator iterator = options.entrySet().iterator();
        while (iterator.hasNext()) {
            Entry entry = (Entry) iterator.next();
            String option = (String) entry.getKey();
            String value = (String) entry.getValue();
            if (JavaCore.VERSION_1_3.equals(compliance) || JavaCore.VERSION_1_4.equals(compliance)) {
                if (JavaCore.COMPILER_PB_ASSERT_IDENTIFIER.equals(option)
                        || JavaCore.COMPILER_PB_ENUM_IDENTIFIER.equals(option)) {
                    // for 1.3 & 1.4 projects, only override the existing setting if the default setting
                    // is a greater severity than the existing setting
                    setMinimumCompliance(projectMap, option, value, overrideExisting);
                } else {
                    setCompliance(projectMap, option, value, overrideExisting);
                }
            } else {
                setCompliance(projectMap, option, value, overrideExisting);
            }
        }
    }

    project.setOptions(projectMap);

}

From source file:de.plugins.eclipse.depclipse.testcommons.TestingEnvironment.java

License:Open Source License

public IPath addProject(String projectName, String compliance) {
    checkAssertion("a workspace must be open", this.isOpen); //$NON-NLS-1$
    IProject project = createProject(projectName);
    String compilerVersion = null;
    compilerVersion = CompilerOptions.VERSION_1_6;
    IJavaProject javaProject = JavaCore.create(project);
    Map<String, String> options = new HashMap<String, String>();
    options.put(CompilerOptions.OPTION_Compliance, compilerVersion);
    options.put(CompilerOptions.OPTION_Source, compilerVersion);
    options.put(CompilerOptions.OPTION_TargetPlatform, compilerVersion);
    javaProject.setOptions(options);
    return project.getFullPath();
}

From source file:edu.brown.cs.bubbles.bedrock.BedrockProject.java

License:Open Source License

@SuppressWarnings("unchecked")
private boolean setProjectPreferences(IProject ip, Element xml) {
    Map<Object, Object> opts;
    IJavaProject ijp = null;

    if (ip != null) {
        ijp = JavaCore.create(ip);//from w w w . j  a  v  a  2 s .  co m
        if (ijp == null)
            return false;
        opts = ijp.getOptions(false);
    } else
        opts = JavaCore.getOptions();

    for (Element opt : IvyXml.children(xml, "OPTION")) {
        String nm = IvyXml.getAttrString(opt, "NAME");
        String vl = IvyXml.getAttrString(opt, "VALUE");
        opts.put(nm, vl);
    }

    if (ijp != null) {
        ijp.setOptions(opts);
    } else {
        Hashtable<?, ?> nopts = new Hashtable<Object, Object>(opts);
        JavaCore.setOptions(nopts);
    }

    return true;
}