Changeset 3560 for devel-tools/trunk


Ignore:
Timestamp:
Mar 21, 2008, 4:18:15 PM (13 years ago)
Author:
yura
Message:
  • No exception throws to Eclipse runtime.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/launching/RfpContainerInitializerAndResolver.java

    r3558 r3560  
    22
    33import java.io.IOException;
     4import java.net.URL;
    45
    56import org.eclipse.core.runtime.CoreException;
     
    2829        private final IClasspathEntry[] entries;
    2930
    30         private RfpContainer (IPath containerPath) {
     31        private RfpContainer (IPath containerPath, IClasspathEntry entry) {
    3132            this.containerPath = containerPath;
    32             IPath path = RfpContainerInitializerAndResolver.getPath();
    33             IPath srcPath = RfpContainerInitializerAndResolver.getSrcPath();
    34             this.entries = path == null ? new IClasspathEntry[0] : new IClasspathEntry[] { JavaCore.newLibraryEntry(
    35                     path, srcPath, null) };
     33            this.entries = new IClasspathEntry[] { entry };
    3634        }
    3735
     
    5351    }
    5452
    55     private static IPath getPath () {
    56         Bundle b = Platform.getBundle("org.refal.rfpdt.runtime");
    57         if (b != null)
    58             try {
    59                 return new Path(FileLocator.resolve(b.getEntry("/rfprt.jar")).getPath());
    60             } catch (IOException e) {
    61                 RfpCore.log(e);
    62             }
    63         return null;
     53    /** May return <code>null</code>. */
     54    private static IPath getEntryPath (String bundleName, String entry) {
     55        Bundle bundle = Platform.getBundle(bundleName);
     56        if (bundle == null)
     57            return null;
     58        URL entryUrl = bundle.getEntry(entry);
     59        if (entryUrl == null)
     60            return null;
     61        try {
     62            return new Path(FileLocator.resolve(entryUrl).getPath());
     63        } catch (IOException e) {
     64            return null;
     65        }
    6466    }
    6567
     68    /** May return <code>null</code>. */
     69    private static IPath getBinPath () {
     70        return getEntryPath("org.refal.rfpdt.runtime", "rfprt.jar");
     71    }
     72
     73    /** May return <code>null</code>. */
    6674    private static IPath getSrcPath () {
    67         Bundle b = Platform.getBundle("org.refal.rfpdt.runtime");
    68         if (b != null)
    69             try {
    70                 return new Path(FileLocator.resolve(b.getEntry("/rfprt-src.jar")).getPath());
    71             } catch (IOException e) {
    72                 RfpCore.log(e);
    73             }
    74         return null;
     75        return getEntryPath("org.refal.rfpdt.runtime", "rfprt-src.jar");
     76    }
     77
     78    private static IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry () {
     79        IPath path = getBinPath();
     80        if (path == null)
     81            return new IRuntimeClasspathEntry[] {};
     82        else
     83            return new IRuntimeClasspathEntry[] { JavaRuntime.newArchiveRuntimeClasspathEntry(path) };
    7584    }
    7685
    7786    @Override
    7887    public void initialize (IPath containerPath, IJavaProject project) throws CoreException {
    79         if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(RfpCore.RFP_CONTAINER)) {
     88        IPath path = getBinPath();
     89        if (path == null)
     90            RfpCore.log("Refal Plus Library can not be found", IStatus.ERROR);
     91        else
    8092            JavaCore.setClasspathContainer(containerPath, new IJavaProject[] { project },
    81                     new IClasspathContainer[] { new RfpContainer(containerPath) }, null);
    82         } else
    83             RfpCore.log("Invalid RfpContainer path", IStatus.ERROR);
     93                    new IClasspathContainer[] { new RfpContainer(containerPath, JavaCore.newLibraryEntry(path,
     94                            getSrcPath(), null)) }, null);
    8495    }
    8596
    8697    public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry (IRuntimeClasspathEntry entry,
    8798            ILaunchConfiguration configuration) {
    88         return new IRuntimeClasspathEntry[] { JavaRuntime.newArchiveRuntimeClasspathEntry(getPath()) };
     99        return resolveRuntimeClasspathEntry();
    89100    }
    90101
    91102    public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry (IRuntimeClasspathEntry entry, IJavaProject project) {
    92         return new IRuntimeClasspathEntry[] { JavaRuntime.newArchiveRuntimeClasspathEntry(getPath()) };
     103        return resolveRuntimeClasspathEntry();
    93104    }
    94105
Note: See TracChangeset for help on using the changeset viewer.