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

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

Introduction

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

Prototype

Map<String, String> getOptions(boolean inheritJavaCoreOptions);

Source Link

Document

Returns the table of the current custom options for this project.

Usage

From source file:com.sympedia.genfw.jdt.impl.JavaFormatterImpl.java

License:Open Source License

/**
 * <!-- begin-user-doc -->/*w  w  w .  j a  va 2 s.com*/
 * <!-- end-user-doc -->
 * @generated NOT
 */
public byte[] doGenerate(Object inputObject, String targetPath, IProgressMonitor monitor) throws Exception {
    Generator delegate = getDelegate();
    if (delegate == null)
        return null;

    byte[] result = delegate.generate(inputObject, targetPath, monitor);
    if (result == null)
        return null;

    Map options = null;
    String profileFile = getProfileFile();
    if (profileFile == null || profileFile.length() == 0 || profileFile.equals("default")) {
        if (targetPath != null) {
            String projectName = new Path(targetPath).segment(0);
            if (projectName != null) {
                IProject project = ResourcesHelper.ROOT.getProject(projectName);
                if (project != null) {
                    IJavaProject javaProject = JavaCore.create(project);
                    if (javaProject != null) {
                        options = javaProject.getOptions(true);
                    }
                }
            }
        }
    } else {
        options = CodeFormatterProfileParser.parse(profileFile);
        if (options == null) {
            throw new CoreException(
                    new Status(IStatus.ERROR, JdtActivator.getPlugin().getBundle().getSymbolicName(), 0,
                            "Unable to read profile file: '" + profileFile + "'", null));
        }
    }

    CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options);
    result = formatCode(result, codeFormatter);
    return result;
}

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

License:Open Source License

/********************************************************************************/

void handlePreferences(String proj, IvyXmlWriter xw) {
    xw.begin("PREFERENCES");

    Map<?, ?> opts;/*from  w w  w.  j av a2s . c  om*/
    if (proj == null) {
        opts = JavaCore.getOptions();
    } else {
        try {
            IProject ip = findProject(proj);
            IJavaProject ijp = JavaCore.create(ip);
            opts = ijp.getOptions(true);
        } catch (BedrockException e) {
            opts = JavaCore.getOptions();
        }
    }

    for (Map.Entry<?, ?> ent : opts.entrySet()) {
        String key = (String) ent.getKey();
        String val = (String) ent.getValue();
        xw.begin("PREF");
        xw.field("NAME", key);
        xw.field("VALUE", val);
        xw.field("OPTS", true);
        xw.end("PREF");
    }

    // handle special preferences
    try {
        Bundle b = Platform.getBundle("com.android.ide.eclipse.adt");
        if (b != null) {
            xw.begin("PREF");
            xw.field("NAME", "bedrock.useAndroid");
            xw.field("VALUE", true);
            xw.field("OPTS", true);
            xw.end("PREF");
            use_android = true;
        }
    } catch (Throwable t) {
    }

    xw.end("PREFERENCES");
}

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  ww w .j  a va  2s  .  com*/
        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;
}

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

License:Open Source License

/********************************************************************************/

private void outputProject(IProject p, boolean fil, boolean pat, boolean cls, boolean opt, boolean imps,
        IvyXmlWriter xw) {/*  w  w  w  .  j av  a2s.c o  m*/
    if (p.getLocation() == null)
        return;

    xw.begin("PROJECT");
    xw.field("NAME", p.getName());
    xw.field("PATH", p.getLocation().toOSString());
    xw.field("WORKSPACE", p.getWorkspace().getRoot().getLocation().toOSString());
    xw.field("BEDROCKDIR", p.getWorkingLocation(BEDROCK_PLUGIN).toOSString());
    try {
        if (p.hasNature("org.eclipse.jdt.core.javanature"))
            xw.field("ISJAVA", true);
        if (p.hasNature("com.android.ide.eclipse.adt.AndroidNature"))
            xw.field("ISANDROID", true);
    } catch (CoreException e) {
    }

    IJavaProject jp = JavaCore.create(p);
    if (jp != null && pat) {
        xw.begin("CLASSPATH");
        addClassPaths(jp, xw, null, false);
        xw.end("CLASSPATH");
        xw.begin("RAWPATH");
        try {
            IClasspathEntry[] ents = jp.getRawClasspath();
            for (IClasspathEntry ent : ents) {
                addPath(xw, jp, ent, false);
            }
        } catch (JavaModelException e) {
        }
        xw.end("RAWPATH");
    }

    if (fil) {
        xw.begin("FILES");
        addSourceFiles(p, xw, null);
        xw.end("FILES");
    }

    if (jp != null && cls) {
        xw.begin("CLASSES");
        addClasses(jp, xw);
        xw.end("CLASSES");
    }

    try {
        IProject[] rp = p.getReferencedProjects();
        IProject[] up = p.getReferencingProjects();
        for (int j = 0; j < rp.length; ++j) {
            xw.textElement("REFERENCES", rp[j].getName());
        }
        for (int j = 0; j < up.length; ++j) {
            xw.textElement("USEDBY", up[j].getName());
        }
    } catch (Exception e) {
    }

    if (opt && jp != null) {
        Map<?, ?> opts = jp.getOptions(false);
        for (Map.Entry<?, ?> ent : opts.entrySet()) {
            xw.begin("OPTION");
            xw.field("NAME", ent.getKey().toString());
            xw.field("VALUE", ent.getValue().toString());
            xw.end("OPTION");
        }
        Map<?, ?> allopts = jp.getOptions(true);
        for (Map.Entry<?, ?> ent : allopts.entrySet()) {
            String knm = (String) ent.getKey();
            if (opts.containsKey(knm))
                continue;
            if (knm.startsWith("org.eclipse.jdt.core.formatter"))
                continue;
            xw.begin("OPTION");
            xw.field("DEFAULT", true);
            xw.field("NAME", ent.getKey().toString());
            xw.field("VALUE", ent.getValue().toString());
            xw.end("OPTION");
        }
        try {
            Map<?, ?> pm = p.getPersistentProperties();
            for (Map.Entry<?, ?> ent : pm.entrySet()) {
                QualifiedName qn = (QualifiedName) ent.getKey();
                xw.begin("PROPERTY");
                xw.field("QUAL", qn.getQualifier());
                xw.field("NAME", qn.getLocalName());
                xw.field("VALUE", ent.getValue().toString());
                xw.end("PROPERTY");
            }
        } catch (CoreException e) {
        }
    }

    if (imps && jp != null) {
        try {
            for (IPackageFragment ipf : jp.getPackageFragments()) {
                outputImports(xw, ipf);
            }
        } catch (JavaModelException e) {
        }
    }

    xw.end("PROJECT");
}

From source file:edu.illinois.keshmesh.detector.tests.TestSetupHelper.java

License:Open Source License

/**
 * Creates a new project in Eclipse and sets up its dependencies on JRE.
 * /*  w  w  w  . j  av  a 2s  .  co  m*/
 * @param projectName
 * @param baseProjectName
 * @return
 * @throws CoreException
 */
@SuppressWarnings("rawtypes")
static IJavaProject createAndInitializeProject(String projectName, String baseProjectName)
        throws CoreException {
    IJavaProject project;
    project = JavaProjectHelper.createJavaProject(projectName, "bin");
    addJREContainer(project);
    // set compiler options on projectOriginal
    Map options = project.getOptions(false);
    JavaProjectHelper.set15CompilerOptions(options);
    project.setOptions(options);
    JavaProjectHelper.addLibrary(project, new Path(Activator.getDefault()
            .getFileInPlugin(new Path(join("lib", "annotations.jar"))).getAbsolutePath()));
    return project;
}

From source file:fede.workspace.eclipse.java.JMergeUtil.java

License:Apache License

public static CodeFormatter createCodeFormatter(IJavaProject javaProject) {
    return ToolFactory.createCodeFormatter(javaProject.getOptions(true));
}

From source file:io.sarl.tests.api.WorkbenchTestHelper.java

License:Apache License

/** Make the given project compliant for the given version.
 *
 * @param javaProject the project.//from   w ww  .  j a  v a2  s.c o  m
 * @param javaVersion the Java version.
 */
public static void makeCompliantFor(IJavaProject javaProject, JavaVersion javaVersion) {
    Map<String, String> options = javaProject.getOptions(false);
    String jreLevel;
    switch (javaVersion) {
    case JAVA8:
        jreLevel = JavaCore.VERSION_1_8;
        break;
    case JAVA6:
        jreLevel = JavaCore.VERSION_1_6;
        break;
    case JAVA5:
        jreLevel = JavaCore.VERSION_1_5;
        break;
    case JAVA7:
    default:
        jreLevel = JavaCore.VERSION_1_7;
    }
    options.put(JavaCore.COMPILER_COMPLIANCE, jreLevel);
    options.put(JavaCore.COMPILER_SOURCE, jreLevel);
    options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, jreLevel);
    options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR);
    options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE, JavaCore.ENABLED);
    options.put(JavaCore.COMPILER_LOCAL_VARIABLE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_LINE_NUMBER_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_SOURCE_FILE_ATTR, JavaCore.GENERATE);
    options.put(JavaCore.COMPILER_CODEGEN_UNUSED_LOCAL, JavaCore.PRESERVE);
    javaProject.setOptions(options);
}

From source file:it.wallgren.android.platform.project.AndroidPlatformProject.java

License:Apache License

private void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException {
    if (project == null) {
        throw new IllegalStateException("Project must be created before giving it a Java nature");
    }//  w  w  w.  ja  v a 2  s.co m
    final IFolder repoLink = createRepoLink(monitor, project, repoPath);
    IFile classpath = repoLink.getFile("development/ide/eclipse/.classpath");
    IFile classpathDestination = project.getFile(".classpath");
    if (classpathDestination.exists()) {
        classpathDestination.delete(true, monitor);
    }
    classpath.copy(classpathDestination.getFullPath(), true, monitor);
    final IProjectDescription description = project.getDescription();
    final String[] natures = description.getNatureIds();
    final String[] newNatures = Arrays.copyOf(natures, natures.length + 1);
    newNatures[natures.length] = JavaCore.NATURE_ID;
    description.setNatureIds(newNatures);
    project.setDescription(description, null);
    final IJavaProject javaProject = JavaCore.create(project);
    @SuppressWarnings("rawtypes")
    final Map options = javaProject.getOptions(true);
    // Compliance level need to be 1.6
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
    javaProject.setOptions(options);

    IClasspathEntry[] classPath = mangleClasspath(javaProject.getRawClasspath(), project, repoLink);
    javaProject.setRawClasspath(classPath, monitor);
    javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor);
}

From source file:it.wallgren.android.platform.project.PackagesProject.java

License:Apache License

private void addJavaNature(IClasspathEntry[] classPath, IProject project, IProgressMonitor monitor)
        throws CoreException {
    if (project == null) {
        throw new IllegalStateException("Project must be created before giving it a Java nature");
    }/*from ww w . j  av a 2s .c  o  m*/

    final IProjectDescription description = project.getDescription();
    final String[] natures = description.getNatureIds();
    final String[] newNatures = Arrays.copyOf(natures, natures.length + 1);
    newNatures[natures.length] = JavaCore.NATURE_ID;
    description.setNatureIds(newNatures);
    project.setDescription(description, null);
    final IJavaProject javaProject = JavaCore.create(project);
    @SuppressWarnings("rawtypes")
    final Map options = javaProject.getOptions(true);
    // Compliance level need to be 1.6
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_6, options);
    javaProject.setOptions(options);
    javaProject.setRawClasspath(classPath, monitor);
    javaProject.setOutputLocation(javaProject.getPath().append("out"), monitor);
}

From source file:mt.com.southedge.jclockwork.plugin.codegenerator.formatter.JClockWorkCodeFormatter.java

License:Open Source License

/**
 * creates a code formatter based on the options defined in the java project.
 * //from www.ja  v  a2s.  c o  m
 * @param javaProject the java project
 * @return the codeFormatter object
 */
public static Object createCodeFormatter(IJavaProject javaProject) {
    Map<?, ?> options = javaProject.getOptions(true);
    return ToolFactory.createCodeFormatter(options);
}