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

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

Introduction

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

Prototype

IPath getOutputLocation() throws JavaModelException;

Source Link

Document

Returns the default output location for this project as a workspace- relative absolute path.

Usage

From source file:com.siteview.mde.internal.core.project.BundleProjectDescription.java

License:Open Source License

/**
 * Initialize settings from the given project.
 * /*  www  .ja  va  2s  . c om*/
 * @param project project
 * @exception CoreException if unable to initialize
 */
private void initialize(IProject project) throws CoreException {
    IContainer root = PDEProject.getBundleRoot(project);
    if (root != project) {
        setBundleRoot(root.getProjectRelativePath());
    }
    IEclipsePreferences node = new ProjectScope(project).getNode(MDECore.PLUGIN_ID);
    if (node != null) {
        setExtensionRegistry(node.getBoolean(ICoreConstants.EXTENSIONS_PROPERTY, true));
        setEquinox(node.getBoolean(ICoreConstants.EQUINOX_PROPERTY, true));
    }
    // export wizard and launch shortcuts
    setExportWizardId(PDEProject.getExportWizard(project));
    setLaunchShortcuts(PDEProject.getLaunchShortcuts(project));
    // location and natures
    setLocationURI(project.getDescription().getLocationURI());
    setNatureIds(project.getDescription().getNatureIds());

    IFile manifest = PDEProject.getManifest(project);
    if (manifest.exists()) {
        Map headers;
        try {
            headers = ManifestElement.parseBundleManifest(manifest.getContents(), null);
            fReadHeaders = headers;
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, MDECore.PLUGIN_ID, e.getMessage(), e));
        } catch (BundleException e) {
            throw new CoreException(new Status(IStatus.ERROR, MDECore.PLUGIN_ID, e.getMessage(), e));
        }
        setActivator(getHeaderValue(headers, Constants.BUNDLE_ACTIVATOR));
        setBundleName(getHeaderValue(headers, Constants.BUNDLE_NAME));
        setBundleVendor(getHeaderValue(headers, Constants.BUNDLE_VENDOR));
        String version = getHeaderValue(headers, Constants.BUNDLE_VERSION);
        if (version != null) {
            setBundleVersion(new Version(version));
        }
        IJavaProject jp = JavaCore.create(project);
        if (jp.exists()) {
            setDefaultOutputFolder(jp.getOutputLocation().removeFirstSegments(1));
        }
        ManifestElement[] elements = parseHeader(headers, Constants.FRAGMENT_HOST);
        if (elements != null && elements.length > 0) {
            setHost(getBundleProjectService().newHost(elements[0].getValue(),
                    getRange(elements[0].getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE))));
        }
        String value = getHeaderValue(headers, Constants.BUNDLE_LOCALIZATION);
        if (value != null) {
            setLocalization(new Path(value));
        }
        elements = parseHeader(headers, Constants.BUNDLE_REQUIREDEXECUTIONENVIRONMENT);
        if (elements != null && elements.length > 0) {
            String[] keys = new String[elements.length];
            for (int i = 0; i < elements.length; i++) {
                keys[i] = elements[i].getValue();
            }
            setExecutionEnvironments(keys);
        }
        IBuild build = getBuildModel(project);
        elements = parseHeader(headers, Constants.BUNDLE_CLASSPATH);
        IBundleClasspathEntry[] classpath = null;
        if (elements != null && elements.length > 0) {
            List collect = new ArrayList();
            for (int i = 0; i < elements.length; i++) {
                String libName = elements[i].getValue();
                IBundleClasspathEntry[] entries = getClasspathEntries(project, build, libName);
                if (entries != null) {
                    for (int j = 0; j < entries.length; j++) {
                        collect.add(entries[j]);
                    }
                }
            }
            classpath = (IBundleClasspathEntry[]) collect.toArray(new IBundleClasspathEntry[collect.size()]);
        } else if (elements == null) {
            // default bundle classpath of '.'
            classpath = getClasspathEntries(project, build, "."); //$NON-NLS-1$
        }
        setBundleClasspath(classpath);
        elements = parseHeader(headers, Constants.BUNDLE_SYMBOLICNAME);
        if (elements != null && elements.length > 0) {
            setSymbolicName(elements[0].getValue());
            String directive = elements[0].getDirective(Constants.SINGLETON_DIRECTIVE);
            if (directive == null) {
                directive = elements[0].getAttribute(Constants.SINGLETON_DIRECTIVE);
            }
            setSingleton("true".equals(directive)); //$NON-NLS-1$
        }
        elements = parseHeader(headers, Constants.IMPORT_PACKAGE);
        if (elements != null) {
            if (elements.length > 0) {
                IPackageImportDescription[] imports = new IPackageImportDescription[elements.length];
                for (int i = 0; i < elements.length; i++) {
                    boolean optional = Constants.RESOLUTION_OPTIONAL
                            .equals(elements[i].getDirective(Constants.RESOLUTION_DIRECTIVE))
                            || "true".equals(elements[i].getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
                    String pv = elements[i].getAttribute(ICoreConstants.PACKAGE_SPECIFICATION_VERSION);
                    if (pv == null) {
                        pv = elements[i].getAttribute(Constants.VERSION_ATTRIBUTE);
                    }
                    imports[i] = getBundleProjectService().newPackageImport(elements[i].getValue(),
                            getRange(pv), optional);
                }
                setPackageImports(imports);
            } else {
                // empty header - should be maintained
                setHeader(Constants.IMPORT_PACKAGE, ""); //$NON-NLS-1$
            }
        }
        elements = parseHeader(headers, Constants.EXPORT_PACKAGE);
        if (elements != null && elements.length > 0) {
            IPackageExportDescription[] exports = new IPackageExportDescription[elements.length];
            for (int i = 0; i < elements.length; i++) {
                ManifestElement exp = elements[i];
                String pv = exp.getAttribute(ICoreConstants.PACKAGE_SPECIFICATION_VERSION);
                if (pv == null) {
                    pv = exp.getAttribute(Constants.VERSION_ATTRIBUTE);
                }
                String directive = exp.getDirective(ICoreConstants.FRIENDS_DIRECTIVE);
                boolean internal = "true".equals(exp.getDirective(ICoreConstants.INTERNAL_DIRECTIVE)) //$NON-NLS-1$
                        || directive != null;
                String[] friends = null;
                if (directive != null) {
                    friends = ManifestElement.getArrayFromList(directive);
                }
                exports[i] = getBundleProjectService().newPackageExport(exp.getValue(), getVersion(pv),
                        !internal, friends);
            }
            setPackageExports(exports);
        }
        elements = parseHeader(headers, Constants.REQUIRE_BUNDLE);
        if (elements != null && elements.length > 0) {
            IRequiredBundleDescription[] req = new IRequiredBundleDescription[elements.length];
            for (int i = 0; i < elements.length; i++) {
                ManifestElement rb = elements[i];
                boolean reexport = Constants.VISIBILITY_REEXPORT
                        .equals(rb.getDirective(Constants.VISIBILITY_DIRECTIVE))
                        || "true".equals(rb.getAttribute(ICoreConstants.REPROVIDE_ATTRIBUTE)); //$NON-NLS-1$
                boolean optional = Constants.RESOLUTION_OPTIONAL
                        .equals(rb.getDirective(Constants.RESOLUTION_DIRECTIVE))
                        || "true".equals(rb.getAttribute(ICoreConstants.OPTIONAL_ATTRIBUTE)); //$NON-NLS-1$
                req[i] = getBundleProjectService().newRequiredBundle(rb.getValue(),
                        getRange(rb.getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE)), optional, reexport);
            }
            setRequiredBundles(req);
        }
        String lazy = getHeaderValue(headers, ICoreConstants.ECLIPSE_AUTOSTART);
        if (lazy == null) {
            lazy = getHeaderValue(headers, ICoreConstants.ECLIPSE_LAZYSTART);
            if (lazy == null) {
                setActivationPolicy(getHeaderValue(headers, Constants.BUNDLE_ACTIVATIONPOLICY));
            }
        }
        if ("true".equals(lazy)) { //$NON-NLS-1$
            setActivationPolicy(Constants.ACTIVATION_LAZY);
        }
        String latest = TargetPlatformHelper.getTargetVersionString();
        IMonitorModelBase model = MonitorRegistry.findModel(project);
        if (model != null) {
            IMonitorBase base = model.getMonitorBase();
            String tv = TargetPlatformHelper.getTargetVersionForSchemaVersion(base.getSchemaVersion());
            if (!tv.equals(latest)) {
                setTargetVersion(tv);
            }
        }
        if (build != null) {
            IBuildEntry entry = build.getEntry(IBuildEntry.BIN_INCLUDES);
            if (entry != null) {
                String[] tokens = entry.getTokens();
                if (tokens != null && tokens.length > 0) {
                    List strings = new ArrayList();
                    for (int i = 0; i < tokens.length; i++) {
                        strings.add(tokens[i]);
                    }
                    // remove the default entries
                    strings.remove("META-INF/"); //$NON-NLS-1$
                    String[] names = ProjectModifyOperation.getLibraryNames(this);
                    if (names != null) {
                        for (int i = 0; i < names.length; i++) {
                            strings.remove(names[i]);
                            // if the library is a folder, account for trailing slash - see bug 306991
                            IPath path = new Path(names[i]);
                            if (path.getFileExtension() == null) {
                                strings.remove(names[i] + "/"); //$NON-NLS-1$
                            }
                        }
                    }
                    // set left overs
                    if (!strings.isEmpty()) {
                        IPath[] paths = new IPath[strings.size()];
                        for (int i = 0; i < strings.size(); i++) {
                            paths[i] = new Path((String) strings.get(i));
                        }
                        setBinIncludes(paths);
                    }
                }
            }
        }
    }
}

From source file:com.siteview.mde.internal.core.project.ProjectModifyOperation.java

License:Open Source License

private boolean createSourceOutputBuildEntries(WorkspaceBuildModel model, IBuildModelFactory factory,
        IBundleProjectDescription description, IBundleProjectDescription before) throws CoreException {
    boolean modified = false;
    IBundleClasspathEntry[] folders = description.getBundleClasspath();
    IBundleClasspathEntry[] prev = before.getBundleClasspath();
    if (!isEqual(folders, prev)) {
        modified = true;//from  ww w  .  j a  va2  s . co m
        // remove the old ones
        String[] oldNames = getLibraryNames(before);
        IBuild build = model.getBuild();
        if (oldNames != null) {
            for (int i = 0; i < oldNames.length; i++) {
                removeBuildEntry(build, IBuildEntry.JAR_PREFIX + oldNames[i]);
                removeBuildEntry(build, IBuildEntry.OUTPUT_PREFIX + oldNames[i]);
            }
        }
        // configure the new ones
        if (folders != null && folders.length > 0) {
            for (int i = 0; i < folders.length; i++) {
                String libraryName = null;
                IPath libPath = folders[i].getLibrary();
                if (libPath == null) {
                    libraryName = "."; //$NON-NLS-1$
                } else {
                    libraryName = folders[i].getLibrary().toString();
                }

                // SOURCE.<LIBRARY_NAME>
                IPath srcFolder = folders[i].getSourcePath();
                if (srcFolder != null) {
                    IBuildEntry entry = getBuildEntry(build, factory, IBuildEntry.JAR_PREFIX + libraryName);
                    if (!srcFolder.isEmpty())
                        entry.addToken(srcFolder.addTrailingSeparator().toString());
                    else
                        entry.addToken("."); //$NON-NLS-1$
                }

                // OUTPUT.<LIBRARY_NAME>
                IPath outFolder = folders[i].getBinaryPath();
                if (srcFolder != null && outFolder == null) {
                    // default output folder
                    IJavaProject project = JavaCore.create(description.getProject());
                    outFolder = project.getOutputLocation().removeFirstSegments(1);
                }
                if (outFolder != null) {
                    IBuildEntry entry = getBuildEntry(build, factory, IBuildEntry.OUTPUT_PREFIX + libraryName);
                    String token = null;
                    if (!outFolder.isEmpty())
                        token = outFolder.addTrailingSeparator().toString();
                    else
                        token = "."; //$NON-NLS-1$
                    if (!entry.contains(token)) {
                        entry.addToken(token);
                    }
                }

            }
        }
    }
    return modified;
}

From source file:com.siteview.mde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

private static String getEquinoxStartupPath(String packageName) throws CoreException {
    IMonitorModelBase model = MonitorRegistry.findModel(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (model != null) {
        IResource resource = model.getUnderlyingResource();
        // found in the target
        if (resource == null)
            return model.getInstallLocation();

        // find it in the workspace
        IProject project = resource.getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                int kind = entries[i].getEntryKind();
                if (kind == IClasspathEntry.CPE_SOURCE || kind == IClasspathEntry.CPE_LIBRARY) {
                    IPackageFragmentRoot[] roots = jProject.findPackageFragmentRoots(entries[i]);
                    for (int j = 0; j < roots.length; j++) {
                        if (roots[j].getPackageFragment(packageName).exists()) {
                            // if source folder, find the output folder
                            if (kind == IClasspathEntry.CPE_SOURCE) {
                                IPath path = entries[i].getOutputLocation();
                                if (path == null)
                                    path = jProject.getOutputLocation();
                                path = path.removeFirstSegments(1);
                                return project.getLocation().append(path).toOSString();
                            }/*w w w .  j  ava2 s . co m*/
                            // else if is a library jar, then get the location of the jar itself
                            IResource jar = roots[j].getResource();
                            if (jar != null) {
                                return jar.getLocation().toOSString();
                            }
                        }
                    }
                }
            }
        }
    }
    Bundle bundle = Platform.getBundle(IPDEBuildConstants.BUNDLE_EQUINOX_LAUNCHER);
    if (bundle != null) {
        try {
            URL url = FileLocator.resolve(bundle.getEntry("/")); //$NON-NLS-1$
            url = FileLocator.toFileURL(url);
            String path = url.getFile();
            if (path.startsWith("file:")) //$NON-NLS-1$
                path = path.substring(5);
            path = new File(path).getAbsolutePath();
            if (path.endsWith("!")) //$NON-NLS-1$
                path = path.substring(0, path.length() - 1);
            return path;
        } catch (IOException e) {
        }
    }
    return null;
}

From source file:com.siteview.mde.internal.launching.launcher.LaunchArgumentsHelper.java

License:Open Source License

private static String getStartupJarPath() throws CoreException {
    IMonitorModelBase model = MonitorRegistry.findModel("org.eclipse.platform"); //$NON-NLS-1$
    if (model != null && model.getUnderlyingResource() != null) {
        IProject project = model.getUnderlyingResource().getProject();
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots();
            for (int i = 0; i < roots.length; i++) {
                if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE
                        && roots[i].getPackageFragment("org.eclipse.core.launcher").exists()) { //$NON-NLS-1$
                    IPath path = jProject.getOutputLocation().removeFirstSegments(1);
                    return project.getLocation().append(path).toOSString();
                }//from  ww  w .j a v  a  2s.c o  m
            }
        }
        if (project.getFile("startup.jar").exists()) //$NON-NLS-1$
            return project.getFile("startup.jar").getLocation().toOSString(); //$NON-NLS-1$
    }
    File startupJar = new Path(TargetPlatform.getLocation()).append("startup.jar").toFile(); //$NON-NLS-1$

    // if something goes wrong with the preferences, fall back on the startup.jar 
    // in the running eclipse.  
    if (!startupJar.exists())
        startupJar = new Path(TargetPlatform.getDefaultLocation()).append("startup.jar").toFile(); //$NON-NLS-1$

    return startupJar.exists() ? startupJar.getAbsolutePath() : null;
}

From source file:com.siteview.mde.internal.launching.launcher.LauncherUtils.java

License:Open Source License

private static String getTimeStamp(IProject project) {
    IJavaProject jp = JavaCore.create(project);
    try {//ww w .  j  av  a  2  s .c om
        long timeStamp = 0;
        IClasspathEntry[] entries = jp.getResolvedClasspath(true);
        for (int i = 0; i < entries.length; i++) {
            if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                File file;
                IPath location = entries[i].getOutputLocation();
                if (location == null)
                    location = jp.getOutputLocation();
                IResource res = project.getWorkspace().getRoot().findMember(location);
                IPath path = res == null ? null : res.getLocation();
                if (path == null)
                    continue;
                file = path.toFile();
                Stack files = new Stack();
                files.push(file);
                while (!files.isEmpty()) {
                    file = (File) files.pop();
                    if (file.isDirectory()) {
                        File[] children = file.listFiles();
                        if (children != null) {
                            for (int j = 0; j < children.length; j++)
                                files.push(children[j]);
                        }
                    } else if (file.getName().endsWith(".class") && timeStamp < file.lastModified()) //$NON-NLS-1$
                        timeStamp = file.lastModified();
                }
            }
        }
        IFile[] otherFiles = new IFile[] { PDEProject.getManifest(project),
                PDEProject.getBuildProperties(project) };
        for (int i = 0; i < otherFiles.length; i++) {
            IFile file = otherFiles[i];
            if (file != null) {
                long fileTimeStamp = file.getRawLocation().toFile().lastModified();
                if (timeStamp < fileTimeStamp)
                    timeStamp = fileTimeStamp;
            }
        }
        return Long.toString(timeStamp);
    } catch (JavaModelException e) {
    }
    return "0"; //$NON-NLS-1$
}

From source file:com.siteview.mde.internal.ui.properties.SelfHostingPropertyPage.java

License:Open Source License

private String[] getOutputFolders() {
    IProject project = (IProject) getElement().getAdapter(IProject.class);
    ArrayList list = new ArrayList();
    try {// w w w  .j a  v a 2 s. c  o m
        if (project.hasNature(JavaCore.NATURE_ID)) {
            IJavaProject jProject = JavaCore.create(project);
            list.add(jProject.getOutputLocation().toString());
            IClasspathEntry[] entries = jProject.getRawClasspath();
            for (int i = 0; i < entries.length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
                        && entry.getContentKind() == IPackageFragmentRoot.K_SOURCE) {
                    IPath path = entry.getOutputLocation();
                    if (path != null)
                        list.add(path.toString());
                }
            }
        }
    } catch (JavaModelException e) {
    } catch (CoreException e) {
    }
    return (String[]) list.toArray(new String[list.size()]);
}

From source file:com.sympedia.genfw.util.ClasspathHelper.java

License:Open Source License

public static void collectClasspathURLs(IJavaProject javaProject, List<URL> urls) {
    try {/*ww w.  j  a  v a 2 s .c o m*/
        collectClasspathUrlOutput(javaProject.getOutputLocation(), urls);

        IClasspathEntry[] resolvedClasspath = javaProject.getResolvedClasspath(true);
        for (IClasspathEntry entry : resolvedClasspath) {
            try {
                switch (entry.getEntryKind()) {
                case IClasspathEntry.CPE_SOURCE:
                    collectClasspathUrlOutput(entry.getOutputLocation(), urls);
                    break;

                case IClasspathEntry.CPE_LIBRARY:
                    File libFile = new File(entry.getPath().toString());
                    URL url = libFile.toURL();
                    if (!urls.contains(url)) {
                        //              System.out.println("LIB: " + url);
                        urls.add(url);
                    }
                    break;

                case IClasspathEntry.CPE_PROJECT:
                    String projectName = entry.getPath().segment(0);
                    IJavaProject requiredProject = getJavaProject(projectName);
                    collectClasspathURLs(requiredProject, urls);
                    break;

                default:
                    throw new RuntimeException();
                }
            } catch (MalformedURLException ex) {
                ex.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.technophobia.substeps.syntax.ProjectToSyntaxTransformer.java

License:Open Source License

private Set<String> outputFoldersForProject(final IJavaProject project) {
    final Set<String> outputFolders = new HashSet<String>();
    final IPath projectLocation = projectLocationPath(project);

    try {//from  ww  w. j  a v a2s. com
        final IPath defaultOutputLocation = project.getOutputLocation();
        if (defaultOutputLocation != null) {
            final IPath fullPath = appendPathTo(projectLocation, defaultOutputLocation);
            if (fullPath.toFile().exists()) {
                outputFolders.add(fullPath.toOSString());
            }
        }
        for (final IClasspathEntry entry : project.getRawClasspath()) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                final IPath outputLocation = entry.getOutputLocation();
                if (outputLocation != null) {
                    final IPath fullPath = appendPathTo(projectLocation, outputLocation);
                    if (fullPath.toFile().exists()) {
                        outputFolders.add(fullPath.toOSString());
                    }
                }
            }
        }
    } catch (final JavaModelException ex) {
        FeatureEditorPlugin.instance()
                .warn("Could not get output folder location for project " + project.getElementName());
    }

    return outputFolders;
}

From source file:com.temenos.ds.op.xtext.ui.internal.se.JdtBasedProcessorProvider.java

License:Open Source License

private List<URL> getOutputFolders(final IJavaProject javaProject) {
    try {/*  w ww .j  a v  a2s  .  c  o m*/
        final List<URL> result = CollectionLiterals.<URL>newArrayList();
        IPath _outputLocation = javaProject.getOutputLocation();
        IPath path = _outputLocation.addTrailingSeparator();
        String _string = path.toString();
        org.eclipse.emf.common.util.URI _createPlatformResourceURI = org.eclipse.emf.common.util.URI
                .createPlatformResourceURI(_string, true);
        String _string_1 = _createPlatformResourceURI.toString();
        URL url = new URL(_string_1);
        result.add(url);
        IClasspathEntry[] _rawClasspath = javaProject.getRawClasspath();
        for (final IClasspathEntry entry : _rawClasspath) {
            int _entryKind = entry.getEntryKind();
            switch (_entryKind) {
            case IClasspathEntry.CPE_SOURCE:
                IPath _outputLocation_1 = entry.getOutputLocation();
                path = _outputLocation_1;
                boolean _notEquals = (!Objects.equal(path, null));
                if (_notEquals) {
                    IPath _addTrailingSeparator = path.addTrailingSeparator();
                    String _string_2 = _addTrailingSeparator.toString();
                    org.eclipse.emf.common.util.URI _createPlatformResourceURI_1 = org.eclipse.emf.common.util.URI
                            .createPlatformResourceURI(_string_2, true);
                    String _string_3 = _createPlatformResourceURI_1.toString();
                    URL _uRL = new URL(_string_3);
                    url = _uRL;
                    result.add(url);
                }
                break;
            }
        }
        return result;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}

From source file:com.versant.core.jdo.tools.eclipse.EnhancerBuilder.java

License:Open Source License

private static void enhanceImp(IProject project) throws Exception {
    if (ECLIPSE_DEBUG)
        System.out.println("EnhancerBuilder.enhanceImp");

    if (!project.exists() || !project.isOpen())
        return;/*from w ww  .java 2  s.c  om*/

    IJavaProject jProject = JavaCore.create(project);

    boolean copyProjectFile = Utils.getBooleanProp(VOAConfigStruct.PAGE_ID, PROP_COPY_PROJECT_FILE, project,
            DEFAULT_COPY_PROJECT_FILE);

    String absPropFilePath = Utils.getAbsProjectFileName(project);
    if (absPropFilePath == null) {
        //the propfile is not specified
        throw new Exception("Enhancement failed: No Versant OpenAccess project file specified."
                + "\nRefer to 'Project|Properties|Versant OpenAccess Properties'");
    }
    File configFile = new File(absPropFilePath);
    if (!configFile.exists()) {
        throw new Exception(
                "Enhancement failed: Versant OpenAccess project file does not exist." + "\nSpecified file '"
                        + configFile + "'" + "\nRefer to 'Project|Properties|Versant OpenAccess Properties'");
    }

    String tokenFileName = Utils.getAbsTokenFileName(project);
    File tokenFile = null;
    if (tokenFileName != null) {
        tokenFile = new File(tokenFileName);
        if (!tokenFile.exists()) {
            tokenFile = null;
        }
    }
    IPath output = jProject.getOutputLocation().removeFirstSegments(1);

    //This is where the enhanced classes wil end up.
    File outFile = new File(project.getLocation().toFile(), output.toFile().getPath());

    ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        EnhancerClassLoader enhancerClassLoader = new EnhancerClassLoader(
                EnhancerBuilder.class.getClassLoader(), jProject);
        Enhancer enhancer = new Enhancer();

        if (copyProjectFile) {
            copyConfigFile(configFile, outFile, tokenFile);
            configFile = new File(outFile, configFile.getName());
            if (!configFile.exists()) {
                throw new RuntimeException("The new config file does not exist");
            }
        }
        enhancer.setClassLoader(enhancerClassLoader);
        enhancer.setPropertiesFile(configFile);
        enhancer.setOutputDir(outFile);

        enhancer.enhance();
    } finally {
        Thread.currentThread().setContextClassLoader(ctxClassLoader);
    }
}