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

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

Introduction

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

Prototype

void setOption(String optionName, String optionValue);

Source Link

Document

Helper method for setting one option value only.

Usage

From source file:org.eclipse.contribution.weaving.jdt.tests.WeavingTestCase.java

License:Open Source License

protected IProject createPredefinedProject(final String projectName) throws CoreException, IOException {
    IJavaProject jp = setUpJavaProject(projectName);
    jp.setOption("org.eclipse.jdt.core.compiler.problem.missingSerialVersion", "ignore"); //$NON-NLS-1$ //$NON-NLS-2$
    jp.getProject().build(IncrementalProjectBuilder.FULL_BUILD, null);
    return jp.getProject();
}

From source file:org.eclipse.m2e.jdt.internal.AbstractJavaProjectConfigurator.java

License:Open Source License

public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
    IProject project = request.getProject();

    monitor.setTaskName(Messages.AbstractJavaProjectConfigurator_task_name + project.getName());

    addJavaNature(project, monitor);/*from   w  w w  .j  a  v a2 s  .  c om*/

    IJavaProject javaProject = JavaCore.create(project);

    Map<String, String> options = new HashMap<String, String>();

    addJavaProjectOptions(options, request, monitor);

    IClasspathDescriptor classpath = new ClasspathDescriptor(javaProject);

    addProjectSourceFolders(classpath, request, monitor);

    String environmentId = getExecutionEnvironmentId(options);

    addJREClasspathContainer(classpath, environmentId);

    addMavenClasspathContainer(classpath);

    addCustomClasspathEntries(javaProject, classpath);

    invokeJavaProjectConfigurators(classpath, request, monitor);

    // now apply new configuration

    // A single setOptions call erases everything else from an existing settings file.
    // Must invoke setOption individually to preserve previous options. 
    for (Map.Entry<String, String> option : options.entrySet()) {
        javaProject.setOption(option.getKey(), option.getValue());
    }

    IContainer classesFolder = getOutputLocation(request, project);

    javaProject.setRawClasspath(classpath.getEntries(), classesFolder.getFullPath(), monitor);

    MavenJdtPlugin.getDefault().getBuildpathManager().updateClasspath(project, monitor);
}

From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationModelTests.java

License:Open Source License

public void testConvertedSourceType1() throws CoreException, InterruptedException {
    try {/*  w ww. java 2s  .c  o m*/
        // Resources creation
        IJavaProject p = createJavaProject("P", new String[] { "" },
                new String[] { "JCL15_LIB", ANNOTATION_LIB }, "bin", "1.5");
        p.setOption(NullCompilerOptions.OPTION_AnnotationBasedNullAnalysis, JavaCore.ENABLED);
        p.setOption(NullCompilerOptions.OPTION_NonNullIsDefault, NullCompilerOptions.ENABLED);

        this.createFolder("/P/p1");
        String c1SourceString = "package p1;\n" + "import org.eclipse.jdt.annotation.*;\n"
                + "public class C1 {\n" + "    public String foo(@Nullable Object arg) {\n" + // this is consumed via SourceTypeConverter
                "      return arg == null ? \"\" : arg.toString();\n" + "    }\n" + "}\n";
        this.createFile("/P/p1/C1.java", c1SourceString);

        this.createFolder("/P/p2");
        String c2SourceString = "package p2;\n" + "public class C2 {\n" + "    String bar(p1.C1 c, C2 c2) {;\n"
                + "        return c.foo(null);\n" + // don't complain despite default nonnull, foo has explicit @Nullable
                "    }\n" + "    String foo(Object arg) {\n"
                + "      return arg == null ? null : arg.toString();\n" + "    }\n" + "}\n";
        this.createFile("/P/p2/C2.java", c2SourceString);

        char[] c2SourceChars = c2SourceString.toCharArray();
        this.problemRequestor.initialize(c2SourceChars);

        getCompilationUnit("/P/p2/C2.java").getWorkingCopy(this.wcOwner, null);

        assertProblems("Unexpected problems", "----------\n" + "1. WARNING in /P/p2/C2.java (at line 7)\n"
                + "   return arg == null ? null : arg.toString();\n"
                + "          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"
                + "Potential type mismatch: required \'@NonNull String\' but nullness of the provided value is unknown\n"
                + "----------\n");
    } finally {
        deleteProject("P");
    }
}

From source file:org.eclipse.objectteams.jdt.nullity.tests.NullAnnotationModelTests.java

License:Open Source License

public void testBinaryType1() throws CoreException, InterruptedException, IOException {
    try {//  w  w  w. j av a 2  s. c o  m
        // Resources creation
        IJavaProject p = createJavaProject("P", new String[] { "" },
                new String[] { "JCL15_LIB", ANNOTATION_LIB, testJarPath("example.jar") }, "bin", "1.5");
        p.setOption(NullCompilerOptions.OPTION_AnnotationBasedNullAnalysis, JavaCore.ENABLED);
        p.setOption(NullCompilerOptions.OPTION_NonNullIsDefault, NullCompilerOptions.ENABLED);

        // example.jar contains p1/C1.java just like testConvertedSourceType1()

        this.createFolder("/P/p2");
        String c2SourceString = "package p2;\n" + "public class C2 {\n" + "    String bar(p1.C1 c) {;\n"
                + "        return c.foo(null);\n" + // don't complain despite default nonnull, foo has explicit @Nullable
                "    }\n" + "    String foo(Object arg) {\n"
                + "      return arg == null ? null : arg.toString();\n" + "    }\n" + "}\n";
        this.createFile("/P/p2/C2.java", c2SourceString);

        char[] c2SourceChars = c2SourceString.toCharArray();
        this.problemRequestor.initialize(c2SourceChars);

        getCompilationUnit("/P/p2/C2.java").getWorkingCopy(this.wcOwner, null);

        assertProblems("Unexpected problems", "----------\n" + "1. WARNING in /P/p2/C2.java (at line 7)\n"
                + "   return arg == null ? null : arg.toString();\n"
                + "          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"
                + "Potential type mismatch: required \'@NonNull String\' but nullness of the provided value is unknown\n"
                + "----------\n");
    } finally {
        deleteProject("P");
    }
}

From source file:org.eclipse.objectteams.otdt.core.ext.OTREContainer.java

License:Open Source License

/**
 * Adds the ObjectTeams classes to the given JavaProject's classpath,
 * and ensures the Java compliance is >= 1.5
 * Handles both variants, OTRE and OTDRE.
 *//*www . j  ava2  s .c o  m*/
public static void initializeOTJProject(IProject project) throws CoreException {
    if (project == null) {
        return;
    }

    if (project.hasNature(JavaCore.NATURE_ID)) {
        IJavaProject javaPrj = (IJavaProject) project.getNature(JavaCore.NATURE_ID);
        IClasspathEntry[] classpath = javaPrj.getRawClasspath();

        if (!isOTREAlreadyInClasspath(classpath)) {
            addOTREToClasspath(javaPrj, classpath);
        }
        String javaVersion = javaPrj.getOption(JavaCore.COMPILER_COMPLIANCE, true);
        if (javaVersion.compareTo(JavaCore.VERSION_1_5) < 0) {
            javaPrj.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
            javaPrj.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
            javaPrj.setOption(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
            javaPrj.setOption(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.pde.ui.OTPluginProject.java

License:Open Source License

public static void makeOTPlugin(IProject project) throws CoreException {
    addOTNatureAndBuilder(project);/* w w  w .  j a v a  2  s  .  c o m*/
    OTREContainer.initializeOTJProject(project);
    // require base-imports for base classes per default:
    IJavaProject javaProject = JavaCore.create(project);
    String value = javaProject.getOption(OTDTPlugin.OT_COMPILER_BINDING_CONVENTIONS, true);
    if (!value.equals(JavaCore.ERROR))
        javaProject.setOption(OTDTPlugin.OT_COMPILER_BINDING_CONVENTIONS, JavaCore.ERROR);
}

From source file:org.eclipse.objectteams.otdt.test.builder.OTEquinoxBuilderTests.java

License:Open Source License

public void testBaseImportNoAspectBinding() throws CoreException, IOException {
    IJavaProject trac18b = fileManager.setUpJavaProject("Trac18b");
    env.addProject(trac18b.getProject());
    IJavaProject aspectPlugin = fileManager.setUpJavaProject("MissingAspectBinding");
    aspectPlugin.setOption("org.eclipse.objectteams.otdt.compiler.problem.binding_conventions", "error");
    env.addProject(aspectPlugin.getProject());
    fullBuild();// w  w  w .ja v a  2s .  c  o m
    expectingNoProblemsFor(trac18b.getPath());
    expectingOnlySpecificProblemsFor(aspectPlugin.getPath(), new Problem[] { new Problem("",
            "Illegal base import: no aspect binding declared for team MissingAspectBindingTeam or any nested team (OT/Equinox).",
            aspectPlugin.getPath().append(new Path("src/MissingAspectBindingTeam.java")), 12, 34,
            CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_ERROR) });
    // now fix it:
    fileManager.replaceWorkspaceFile("MissingAspectBinding/plugin-corrected.xml", aspectPlugin, "plugin.xml");
    incrementalBuild();
    expectingNoProblemsFor(trac18b.getPath());
    expectingNoProblemsFor(aspectPlugin.getPath());
}

From source file:org.eclipse.objectteams.otdt.test.builder.OTEquinoxBuilderTests.java

License:Open Source License

public void testBaseImportTwoAspectBindings() throws CoreException, IOException {
    IJavaProject trac213b1 = fileManager.setUpJavaProject("Trac213b1");
    env.addProject(trac213b1.getProject());
    IJavaProject trac213b2 = fileManager.setUpJavaProject("Trac213b2");
    env.addProject(trac213b2.getProject());
    fullBuild();// w ww.  ja  va  2 s.c o m

    // initially only an empty team
    IJavaProject aspectPlugin = fileManager.setUpJavaProject("Trac213a");
    aspectPlugin.setOption("org.eclipse.objectteams.otdt.compiler.problem.binding_conventions", "error");
    env.addProject(aspectPlugin.getProject());
    fullBuild();

    // now add content to the team, binding to Trac213b1:
    fileManager.replaceWorkspaceFile("Trac213a/auxil/TheTeam_step1.java", aspectPlugin,
            "src/trac213a/TheTeam.java");

    incrementalBuild();
    expectingNoProblemsFor(trac213b1.getPath());
    expectingNoProblemsFor(trac213b2.getPath());
    expectingNoProblemsFor(aspectPlugin.getPath());

    // now add content to the team, binding to Trac213b2:
    fileManager.replaceWorkspaceFile("Trac213a/auxil/plugin_step2.xml", aspectPlugin, "plugin.xml");
    fileManager.replaceWorkspaceFile("Trac213a/auxil/TheTeam_step2.java", aspectPlugin,
            "src/trac213a/TheTeam.java");

    incrementalBuild();
    expectingNoProblemsFor(trac213b1.getPath());
    expectingNoProblemsFor(trac213b2.getPath());
    expectingNoProblemsFor(aspectPlugin.getPath());
}

From source file:org.eclipse.objectteams.otdt.test.builder.OTEquinoxBuilderTests.java

License:Open Source License

public void testWrongBaseImport1() throws CoreException, IOException {
    IJavaProject trac18b = fileManager.setUpJavaProject("Trac18b");
    env.addProject(trac18b.getProject());
    IJavaProject aspectPlugin = fileManager.setUpJavaProject("WrongBaseImport1");
    aspectPlugin.setOption("org.eclipse.objectteams.otdt.compiler.problem.binding_conventions", "error");
    env.addProject(aspectPlugin.getProject());
    fullBuild();// w w  w  .ja  v a  2  s  . c o  m
    expectingNoProblemsFor(trac18b.getPath());
    expectingOnlySpecificProblemsFor(aspectPlugin.getPath(), new Problem[] { new Problem("",
            "Illegal base import: this package is not provided by the declared base plug-in(s) Trac18b (OT/Equinox).",
            aspectPlugin.getPath().append(new Path("src/WrongBaseImportTeam1.java")), 12, 63,
            CategorizedProblem.CAT_CODE_STYLE, IMarker.SEVERITY_ERROR) });
}

From source file:org.eclipse.objectteams.otdt.test.builder.OTEquinoxBuilderTests.java

License:Open Source License

public void testWrongBaseImport2() throws CoreException, IOException {
    IJavaProject trac18b = fileManager.setUpJavaProject("Trac18b");
    env.addProject(trac18b.getProject());
    IJavaProject aspectPlugin = fileManager.setUpJavaProject("WrongBaseImport2");
    aspectPlugin.setOption("org.eclipse.objectteams.otdt.compiler.problem.binding_conventions", "error");
    env.addProject(aspectPlugin.getProject());
    fullBuild();/*from  w  ww .ja v  a 2s . co  m*/
    expectingNoProblemsFor(trac18b.getPath());
    expectingOnlySpecificProblemsFor(aspectPlugin.getPath(), new Problem[] { new Problem("",
            "Illegal base import: this package is not provided by the declared base plug-in org.eclipse.objectteams.otequinox but by plug-in Trac18b (OT/Equinox).",
            aspectPlugin.getPath().append(new Path("src/WrongBaseImportTeam2.java")), 12, 34,
            CategorizedProblem.CAT_TYPE, IMarker.SEVERITY_ERROR) });
}