Example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind

List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind.

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:com.ifedorenko.m2e.sourcelookup.internal.JavaProjectSources.java

License:Open Source License

static ISourceContainer getProjectSourceContainer(IJavaProject javaProject) {
    List<ISourceContainer> containers = new ArrayList<ISourceContainer>();

    boolean hasSources = false;

    try {//w ww.  j  a va 2  s. c  om
        for (IClasspathEntry cpe : javaProject.getRawClasspath()) {
            switch (cpe.getEntryKind()) {
            case IClasspathEntry.CPE_SOURCE:
                hasSources = true;
                break;
            case IClasspathEntry.CPE_LIBRARY:
                IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
                IResource lib = workspaceRoot.findMember(cpe.getPath());
                IPackageFragmentRoot fragmentRoot;
                if (lib != null) {
                    fragmentRoot = javaProject.getPackageFragmentRoot(lib);
                } else {
                    fragmentRoot = javaProject.getPackageFragmentRoot(cpe.getPath().toOSString());
                }
                containers.add(new PackageFragmentRootSourceContainer(fragmentRoot));
                break;
            }
        }
    } catch (JavaModelException e) {
        // ignore... maybe log
    }

    if (hasSources) {
        containers.add(0, new JavaProjectSourceContainer(javaProject));
    }

    if (containers.isEmpty()) {
        return null;
    }

    if (containers.size() == 1) {
        return containers.get(0);
    }

    return new CompositeSourceContainer(containers);
}

From source file:com.iw.plugins.spindle.core.builder.TapestryBuilder.java

License:Mozilla Public License

public static IProject[] getBuildInterestingProjects(IJavaProject jproject, IWorkspaceRoot root) {
    if (jproject == null || root == null)
        return new IProject[0];

    ArrayList projects = new ArrayList();
    try {//from  www  . ja va2  s  .c  o  m
        IClasspathEntry[] entries = ((JavaProject) jproject).getExpandedClasspath();
        for (int i = 0, length = entries.length; i < length; i++) {
            IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(entries[i]);
            if (entry != null) {
                IPath path = entry.getPath();
                IProject p = null;
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    IProject workspaceProject = root.getProject(path.lastSegment());
                    if (workspaceProject.hasNature(JavaCore.NATURE_ID))
                        p = workspaceProject;

                }
                if (p != null && !projects.contains(p))
                    projects.add(p);

            }
        }
    } catch (CoreException e) {
        return new IProject[0];
    }
    IProject[] result = new IProject[projects.size()];
    projects.toArray(result);
    return result;
}

From source file:com.iw.plugins.spindle.ui.wizards.project.BaseNewTapestryProjectJavaPage.java

License:Mozilla Public License

/**
 * @param entries//from  w  w  w  .  j  a va2 s.  c  o m
 * @return
 */
private IClasspathEntry[] checkEntries(IClasspathEntry[] entries) throws CoreException {

    if (entries == null) {
        createSrcFolder();
        return new IClasspathEntry[] { createSrcClasspathEntry(), TapestryProjectInstallData.TAPESTRY_FRAMEWORK,
                JavaRuntime.getDefaultJREContainerEntry() };

    }

    boolean hasSrcEntry = false;
    boolean hasTapestryEntry = false;
    boolean hasDefaultJREEntry = false;
    List allEntries = Arrays.asList(entries);
    for (Iterator iter = allEntries.iterator(); iter.hasNext();) {
        IClasspathEntry element = (IClasspathEntry) iter.next();
        if (!hasSrcEntry && element.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            hasSrcEntry = true;
        } else if (element.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            if (!hasTapestryEntry)
                hasTapestryEntry = element.getPath().segment(0).equals(TapestryCore.CORE_CONTAINER);
            if (!hasDefaultJREEntry)
                hasDefaultJREEntry = element.getPath().segment(0).equals(JavaRuntime.JRE_CONTAINER);
        }
    }

    if (!hasSrcEntry) {
        createSrcFolder();
        allEntries.add(createSrcClasspathEntry());

    }

    if (!hasTapestryEntry)
        allEntries.add(TapestryProjectInstallData.TAPESTRY_FRAMEWORK);

    if (!hasDefaultJREEntry)
        allEntries.add(JavaRuntime.getDefaultJREContainerEntry());

    return (IClasspathEntry[]) allEntries.toArray(new IClasspathEntry[allEntries.size()]);
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Get all the resolved classpath entries for a specific project. The entries 
 * with ID JRClasspathContainer.ID and JavaRuntime.JRE_CONTAINER are not resolved
 * or included in the result. At also add the source and output folder provided with the 
 * project/*from w  ww  .  j  a  v  a 2 s.c o m*/
 * 
 * @param project the project where the file to compile is contained, must be not null
 * @return a not null list of string that contains the classpath to include in the compilation project
 */
private List<String> getClasspaths(IProject project) {
    IJavaProject jprj = JavaCore.create(project);
    List<String> classpath = new ArrayList<String>();
    IWorkspaceRoot wsRoot = project.getWorkspace().getRoot();
    if (jprj != null) {
        try {
            IClasspathEntry[] entries = jprj.getRawClasspath();

            //Add the default output folder if any
            IPath defaultLocationPath = jprj.getOutputLocation();
            if (defaultLocationPath != null) {
                IFolder entryOutputFolder = wsRoot.getFolder(defaultLocationPath);
                classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
            }

            for (IClasspathEntry en : entries) {
                if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                    String containerPath = en.getPath().toString();
                    //Don't add the eclipse runtime and the classpath extension defined in the exclusion list
                    if (!containerPath.startsWith(JavaRuntime.JRE_CONTAINER)
                            && !classpathExclusionSet.contains(containerPath)) {
                        addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(),
                                classpath, jprj);
                    }
                } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
                    classpath.add(wsRoot.findMember(en.getPath()).getLocation().toOSString() + File.separator);
                } else if (en.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && en.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    //check if is a source folder and if it has a custom output folder to add them also to the classpath
                    IPath entryOutputLocation = en.getOutputLocation();
                    if (entryOutputLocation != null) {
                        IFolder entryOutputFolder = wsRoot.getFolder(entryOutputLocation);
                        classpath.add(entryOutputFolder.getLocation().toOSString() + File.separator);
                    }
                } else {
                    //It is a jar check if it is internal to the workspace of external
                    IPath location = wsRoot.getFile(en.getPath()).getLocation();
                    if (location == null) {
                        //The location could not be resolved from the root of the workspace, it is external
                        classpath.add(en.getPath().toOSString());
                    } else {
                        //The location has been resolved from the root of the workspace, it is internal
                        classpath.add(location.toOSString());
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return classpath;
}

From source file:com.jaspersoft.studio.backward.ConsoleExecuter.java

License:Open Source License

/**
 * Add an array of classpath entry to the result set. If an entry is a classpath container 
 * then it is resolved and the resulting entries are added recursively
 * /*from  w  w  w.j a  v a 2  s  .  c  o m*/
 * @param entries the entries to add
 * @param classpath the current result
 * @param jprj the current java project
 */
private void addEntries(IClasspathEntry[] entries, List<String> classpath, IJavaProject jprj) {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    for (IClasspathEntry en : entries) {
        if (en.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
            try {
                addEntries(JavaCore.getClasspathContainer(en.getPath(), jprj).getClasspathEntries(), classpath,
                        jprj);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else if (en.getEntryKind() == IClasspathEntry.CPE_PROJECT
                || en.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            classpath.add(workspace.getRoot().findMember(en.getPath()).getLocation().toOSString()
                    + File.separator + "*"); //$NON-NLS-1$
        } else {
            classpath.add(en.getPath().toOSString());
        }
    }
}

From source file:com.javadude.antxr.eclipse.core.AntxrNature.java

License:Open Source License

public void configure() throws CoreException {
    if (AntxrNature.DEBUG) {
        System.out.println("configuring ANTXR nature");
    }//from  w w  w.  j av a 2s .c  o  m
    IProject project = getProject();
    IProjectDescription projectDescription = project.getDescription();
    List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(projectDescription.getBuildSpec()));

    ICommand antxrBuilderCommand = projectDescription.newCommand();
    antxrBuilderCommand.setBuilderName(AntxrBuilder.BUILDER_ID);
    ICommand warningCleanerBuilderCommand = projectDescription.newCommand();
    warningCleanerBuilderCommand.setBuilderName(WarningCleanerBuilder.BUILDER_ID);
    ICommand smapBuilderCommand = projectDescription.newCommand();
    smapBuilderCommand.setBuilderName(SMapInstallerBuilder.BUILDER_ID);

    if (!commands.contains(antxrBuilderCommand)) {
        commands.add(0, antxrBuilderCommand); // add at start
    }
    if (!commands.contains(warningCleanerBuilderCommand)) {
        commands.add(warningCleanerBuilderCommand); // add at end
    }
    if (!commands.contains(smapBuilderCommand)) {
        commands.add(smapBuilderCommand); // add at end
    }

    // Commit the spec change into the project
    projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
    getProject().setDescription(projectDescription, null);

    //        // add the antxr.jar file to a lib dir
    //        IFolder folder = getProject().getFolder("lib");
    //        if (!folder.exists()) {
    //            folder.create(true, true, null);
    //        }
    //        IPath rawLocation = folder.getRawLocation();
    //        URL antxrJarUrl = AntxrCorePlugin.getDefault().getBundle().getEntry("lib/antxr.jar");
    //
    //        BufferedOutputStream bout = null;
    //        BufferedInputStream bin = null;
    //        int b;
    //        try {
    //            try {
    //                bout = new BufferedOutputStream(new FileOutputStream(new File(rawLocation.toFile(), "antxr.jar")));
    //                bin = new BufferedInputStream(antxrJarUrl.openStream());
    //                while ((b = bin.read()) != -1) {
    //                    bout.write(b);
    //                }
    //            } finally {
    //                if (bout != null) {
    //                    bout.close();
    //                }
    //                if (bin != null) {
    //                    bin.close();
    //                }
    //            }
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }
    //
    //        folder.refreshLocal(IResource.DEPTH_ONE, null);
    //
    //        // add the jar to the classpath if not present
    //        String jarPath = "/" + getProject().getName() + "/lib/antxr.jar";

    IFolder antxr3GeneratedFolder = getProject().getFolder("antxr-generated");
    if (!antxr3GeneratedFolder.exists()) {
        antxr3GeneratedFolder.create(true, true, null);
    }
    String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated";

    final IJavaProject javaProject = JavaCore.create(getProject());
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    boolean generatedSourceDirFound = false;
    for (IClasspathEntry classpathEntry : rawClasspath) {
        //            if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        //                if (classpathEntry.getPath().toString().equals(jarPath)) {
        //                    found = true;
        //                }
        //            }
        if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            if (classpathEntry.getPath().toString().equals(generatedSourcePath)) {
                generatedSourceDirFound = true;
            }
        }
    }

    int toAdd = 0;
    if (!generatedSourceDirFound) {
        toAdd++;
    }
    if (!generatedSourceDirFound) {
        final IClasspathEntry newEntries[] = new IClasspathEntry[rawClasspath.length + toAdd];
        System.arraycopy(rawClasspath, 0, newEntries, 0, rawClasspath.length);
        //            newEntries[rawClasspath.length] = JavaCore.newLibraryEntry(new Path(jarPath), Path.EMPTY, Path.ROOT);
        if (!generatedSourceDirFound) {
            newEntries[newEntries.length - 1] = JavaCore.newSourceEntry(new Path(generatedSourcePath));
        }
        JavaCore.run(new IWorkspaceRunnable() {
            public void run(IProgressMonitor monitor) throws CoreException {
                javaProject.setRawClasspath(newEntries, null);
            }
        }, null);
    }
}

From source file:com.javadude.antxr.eclipse.core.AntxrNature.java

License:Open Source License

public void deconfigure() throws CoreException {
    if (AntxrNature.DEBUG) {
        System.out.println("deconfiguring ANTXR nature");
    }/*from  w  w  w.  j av  a 2s .com*/
    IProject project = getProject();
    IProjectDescription desc = project.getDescription();
    List<ICommand> commands = new ArrayList<ICommand>(Arrays.asList(desc.getBuildSpec()));
    for (Iterator i = commands.iterator(); i.hasNext();) {
        ICommand command = (ICommand) i.next();
        if (command.getBuilderName().equals(AntxrBuilder.BUILDER_ID)
                || command.getBuilderName().equals(SMapInstallerBuilder.BUILDER_ID)
                || command.getBuilderName().equals(WarningCleanerBuilder.BUILDER_ID)) {
            i.remove();
        }
    }

    // Commit the spec change into the project
    desc.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
    project.setDescription(desc, null);

    // remove the jar from the classpath if present
    // delete the jar from the lib dir
    // if the lib dir is empty, delete it
    //        String jarPath = "/" + getProject().getName() + "/lib/antxr.jar";
    String generatedSourcePath = "/" + getProject().getName() + "/antxr-generated";
    final IJavaProject javaProject = JavaCore.create(getProject());
    IClasspathEntry[] rawClasspath = javaProject.getRawClasspath();
    final List<IClasspathEntry> newEntries = new ArrayList<IClasspathEntry>();
    for (IClasspathEntry entry : rawClasspath) {
        //            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        //                if (entry.getPath().toString().equals(jarPath)) {
        //                    found = i;
        //                    break;
        //                }
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
            if (entry.getPath().toString().equals(generatedSourcePath)) {
                continue; // skip the antxr-generated source folder
            }
        }
        newEntries.add(entry);
    }

    JavaCore.run(new IWorkspaceRunnable() {
        public void run(IProgressMonitor monitor) throws CoreException {
            IClasspathEntry entries[] = newEntries.toArray(new IClasspathEntry[newEntries.size()]);
            javaProject.setRawClasspath(entries, null);
            IFolder folder = getProject().getFolder("antxr-generated");
            if (folder.exists() && !hasNonAntxrGeneratedFile(folder)) {
                folder.delete(true, null);
            } else {
                AntxrCorePlugin.getUtil().warning(4211,
                        "Did not delete antxr-generated source directory; it contains non-generated source. You should move that source to another source dir; it really doesn't belong there...");
            }
        }
    }, null);
}

From source file:com.javadude.antxr.eclipse.core.builder.AntxrBuilder.java

License:Open Source License

/**
 * Compile a grammar//from   ww  w . ja  va 2s.c  o  m
 *
 * @param aFile
 *            The grammar file to compile
 * @param aMonitor
 *            A progress monitor
 */
public void compileFile(IFile aFile, IProgressMonitor aMonitor) {
    String grammarFileName = aFile.getProjectRelativePath().toString();
    try {
        // delete the old generated files for this grammar
        aFile.getProject().accept(new CleaningVisitor(aMonitor, grammarFileName));

        // if it's in a java project, only build it if it's in a source dir
        if (AntxrCorePlugin.getUtil().hasNature(aFile.getProject(), AntxrNature.NATURE_ID)) {
            IProject project = aFile.getProject();
            IJavaProject javaProject = JavaCore.create(project);
            IPath path = aFile.getFullPath();
            boolean ok = false;
            IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
            for (int i = 0; i < resolvedClasspath.length; i++) {
                IClasspathEntry entry = resolvedClasspath[i];

                if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                    continue;
                }

                IPath entryPath = entry.getPath();
                if (entryPath.isPrefixOf(path)) {
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                return;
            }
        }
    } catch (CoreException e1) {
        e1.printStackTrace();
    }

    fFile = aFile;

    aMonitor.beginTask(
            AntxrCorePlugin.getFormattedMessage("AntxrBuilder.compiling", aFile.getFullPath().toString()), 4);

    // Remove all markers from this file
    try {
        aFile.deleteMarkers(null, true, IResource.DEPTH_INFINITE);
    } catch (CoreException e) {
        AntxrCorePlugin.log(e);
    }

    // Prepare arguments for ANTXR compiler
    // read the settings for this grammar
    Map<String, Map<String, String>> map = SettingsPersister.readSettings(aFile.getProject());

    List<String> args = createArguments(map, aFile);
    if (AntxrBuilder.DEBUG) {
        System.out.println("Compiling ANTXR grammar '" + aFile.getName() + "': arguments=" + args);
    }

    // Monitor system out and err
    fOriginalOut = System.out;
    fOriginalErr = System.err;
    System.setOut(new PrintStream(new MonitoredOutputStream(this)));
    System.setErr(new PrintStream(new MonitoredOutputStream(this)));

    try {
        // Compile ANTXR grammar file
        AntxrTool tool = new AntxrTool();
        if (!tool.preprocess(args.toArray(new String[args.size()]))) {
            try {
                aMonitor.worked(1);
                if (!tool.parse()) {
                    aMonitor.worked(1);
                    if (!tool.generate()) {
                        aMonitor.worked(1);
                        refreshFolder(map, tool, args, aFile, grammarFileName,
                                ResourcesPlugin.getWorkspace().getRoot().findMember(fOutput), aMonitor,
                                tool.getSourceMaps());
                    } else {

                        // If errors during generate then delete all
                        // generated files
                        deleteFiles(tool, aFile.getParent(), aMonitor);
                    }
                    aMonitor.worked(1);
                }
            } catch (CoreException e) {
                AntxrCorePlugin.log(e);
            }
        }

    } catch (Throwable e) {
        if (!(e instanceof SecurityException)) {
            AntxrCorePlugin.log(e);
        }
    } finally {
        System.setOut(fOriginalOut);
        System.setErr(fOriginalErr);
        aMonitor.done();
    }
}

From source file:com.javadude.antxr.eclipse.core.builder.AntxrBuilder.java

License:Open Source License

/**
 * Returns list of commandline arguments for ANTXR compiler.
 *
 * @param map/* ww w  . jav a  2  s . c  o m*/
 *            the saved antxr-eclipse settings for this project
 * @param file
 *            The grammar file to parse
 * @return a list of command-line arguments
 */
private List<String> createArguments(Map<String, Map<String, String>> map, IFile file) {
    List<String> args = new ArrayList<String>();

    AntxrCorePlugin.getDefault().upgradeOldSettings(file, map);

    fOutput = SettingsPersister.get(map, file, SettingsPersister.OUTPUT_PROPERTY);
    // Prepare absolute output path (-o)
    String outputPath = null;
    if (fOutput != null && fOutput.trim().length() > 0) {
        outputPath = convertRootRelatedPath(fOutput);
    }
    if (outputPath == null) {
        try {
            IJavaProject javaProject = JavaCore.create(file.getProject());
            IClasspathEntry rawClasspath[] = javaProject.getRawClasspath();
            String longestSourceDirPrefix = "";
            String grammarFilePath = file.getFullPath().toString();
            for (IClasspathEntry entry : rawClasspath) {
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                    String sourceDirString = entry.getPath().toString();
                    if (grammarFilePath.startsWith(sourceDirString)
                            && sourceDirString.length() > longestSourceDirPrefix.length()) {
                        longestSourceDirPrefix = sourceDirString;
                    }
                }
            }

            if ("".equals(longestSourceDirPrefix)) {
                return null;
            }
            String basePath = file.getFullPath().removeLastSegments(1).toString();
            String packageName = basePath.substring(longestSourceDirPrefix.length());
            IFolder targetDirFolder = file.getProject().getFolder("antxr-generated/" + packageName);
            if (!targetDirFolder.exists()) {
                targetDirFolder.getRawLocation().toFile().mkdirs();
                file.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
            }
            fOutput = targetDirFolder.getFullPath().toString();
            outputPath = targetDirFolder.getLocation().toString();
        } catch (Exception e) {
            throw new RuntimeException("Could not set up antxr-generated as output dir", e);
        }
    }

    args.add("-o");
    args.add(outputPath);

    // Get boolean options from grammar properties
    addBooleanGrammarProperty(map, file, SettingsPersister.DEBUG_PROPERTY, "-debug", null, args, false);
    addBooleanGrammarProperty(map, file, SettingsPersister.HTML_PROPERTY, "-html", null, args, false);
    addBooleanGrammarProperty(map, file, SettingsPersister.DOCBOOK_PROPERTY, "-docbook", null, args, false);
    addBooleanGrammarProperty(map, file, SettingsPersister.DIAGNOSTIC_PROPERTY, "-diagnostic", null, args,
            false);
    addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_PROPERTY, "-trace", null, args, false);
    addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_PARSER_PROPERTY, "-traceParser", null, args,
            false);
    addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_LEXER_PROPERTY, "-traceLexer", null, args,
            false);
    addBooleanGrammarProperty(map, file, SettingsPersister.TRACE_TREE_PARSER_PROPERTY, "-traceTreeParser", null,
            args, false);
    addBooleanGrammarProperty(map, file, SettingsPersister.SMAP_PROPERTY, "-smap", null, args, true);

    // Get super grammars from grammar properties
    String superGrammars = SettingsPersister.get(map, file, SettingsPersister.SUPER_GRAMMARS_PROPERTY);

    // Prepare optional super grammar(s) (-glib)
    // Can be defined in two ways : in a property dialog OR
    // inside the grammar using a comment "// -glib <file in same folder>"
    if (superGrammars != null && superGrammars.trim().length() > 0) {
        superGrammars = convertRootRelatedPathList(superGrammars);
        if (superGrammars != null) {
            args.add("-glib");
            args.add(superGrammars);
        }
    } else {
        // Try to get // -glib parameter from comment in .g file. This
        // enables sharing in a team project without local reconfiguration
        String localSuperGrammar = extractGlibComment(fFile);
        if (localSuperGrammar != null) {
            localSuperGrammar = convertFolderRelatedPath(localSuperGrammar);
            if (localSuperGrammar != null) {
                args.add("-glib");
                args.add(localSuperGrammar);
            }
        }
    }

    // Prepare ANTXR grammar file which needs to be compiled
    args.add(fFile.getLocation().toOSString());
    return args;
}

From source file:com.javadude.antxr.eclipse.smapinstaller.SMapInstallerBuilder.java

License:Open Source License

/**
 * Installs the modified smap into a generated classfile
 * @param resource/*from www.  j a va 2  s.  c  om*/
 * @throws JavaModelException
 */
protected void installSmap(IResource resource) throws JavaModelException {
    // We only work on smap files -- skip everything else
    if (!(resource instanceof IFile)) {
        return;
    }
    IFile smapIFile = (IFile) resource;
    if (!"smap".equalsIgnoreCase(smapIFile.getFileExtension())) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(smapIFile.getProject());

    // get the name of the corresponding java source file
    IPath smapPath = smapIFile.getFullPath();

    IClasspathEntry[] classpathEntries = javaProject.getResolvedClasspath(true);
    for (IClasspathEntry entry : classpathEntries) {
        if (entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
            continue;
        }
        if (!entry.getPath().isPrefixOf(smapPath)) {
            continue;
        }

        // found the right source container
        IPath outputLocation = entry.getOutputLocation();
        if (outputLocation == null) {
            outputLocation = javaProject.getOutputLocation();
        }
        // strip the source dir and .smap suffix
        String sourceDir = entry.getPath().toString();
        String smapName = smapPath.toString();
        String javaSourceName = smapName.substring(0, smapName.length() - 5) + ".java";
        String className = smapName.substring(sourceDir.length(), smapName.length() - 5) + ".class";
        IPath path = outputLocation.append(className);
        IPath workspaceLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation();
        IPath classFileLocation = workspaceLoc.append(path);
        IResource classResource = ResourcesPlugin.getWorkspace().getRoot().findMember(javaSourceName);

        File classFile = classFileLocation.toFile();
        File smapFile = smapIFile.getLocation().toFile();
        try {
            String installSmap = classResource.getPersistentProperty(AntxrBuilder.INSTALL_SMAP);
            if ("true".equals(installSmap)) {
                SDEInstaller.install(classFile, smapFile);
            }
        } catch (CoreException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}