This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 241884
Collapse All | Expand All

(-)java.project/src/org/netbeans/modules/java/project/JavaAntLogger.java (-1 / +41 lines)
Lines 301-311 Link Here
301
            }
301
            }
302
            // Also check global sourcepath (sources of open projects, and sources
302
            // Also check global sourcepath (sources of open projects, and sources
303
            // corresponding to compile or boot classpaths of open projects).
303
            // corresponding to compile or boot classpaths of open projects).
304
            // Try to use the directory of the calling ant script to help
305
            // GlobalPathRegistry in finding the correct resource.
304
            // Fallback in case a JAR file is copied to an unknown location, etc.
306
            // Fallback in case a JAR file is copied to an unknown location, etc.
305
            // In this case we can't be sure that this source file really matches
307
            // In this case we can't be sure that this source file really matches
306
            // the .class used in the stack trace, but it is a good guess.
308
            // the .class used in the stack trace, but it is a good guess.
307
            if (!event.isConsumed()) {
309
            if (!event.isConsumed()) {
308
                FileObject source = GlobalPathRegistry.getDefault().findResource(parse.resource);
310
                FileObject projectDir = FileUtil.toFileObject(session.getOriginatingScript().getParentFile());
311
                FileObject source = projectDir == null ? GlobalPathRegistry.getDefault().findResource(parse.resource) : findResource(parse.resource, projectDir);
309
                if (source != null) {
312
                if (source != null) {
310
                    parse.hyperlink(session, event, source, messageLevel, sessionLevel, data);
313
                    parse.hyperlink(session, event, source, messageLevel, sessionLevel, data);
311
                } else if (messageLevel <= sessionLevel && "java".equals(event.getTaskName())) {
314
                } else if (messageLevel <= sessionLevel && "java".equals(event.getTaskName())) {
Lines 341-346 Link Here
341
        }
344
        }
342
    }
345
    }
343
    
346
    
347
    /**
348
     * Convenience method to find a particular source file by resource path.
349
     * This is copied from GlobalPathRegistry.getDefault().findResource.
350
     * In case more than one source root contains the resource, one is chosen
351
     * based on the projectDir instead of arbitrarily.
352
     * As with {@link ClassPath#findResource}, include/exclude lists can affect the result.
353
     * @param resource a resource path, e.g. <samp>somepkg/Foo.java</samp>
354
     * @param projectDir the directory containing the calling ant script
355
     * @return some file found with that path, or null
356
     */
357
    private FileObject findResource(String resource, FileObject projectDir) {
358
        for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
359
            FileObject f = cp.findResource(resource);
360
            if (f != null) {
361
                FileObject ownerRoot = cp.findOwnerRoot(f);
362
                if (ownerRoot != null) {
363
                    if(FileUtil.toFile(f).getPath().startsWith(projectDir.getPath())) {
364
                        return f;
365
                    }
366
                }
367
            }
368
        }
369
        for (FileObject root : GlobalPathRegistry.getDefault().getSourceRoots()) {
370
            FileObject f = root.getFileObject(resource);
371
            if (f != null) {
372
                // Make sure it is not from one of the above, since they control incl/excl.
373
                for (ClassPath cp : GlobalPathRegistry.getDefault().getPaths(ClassPath.SOURCE)) {
374
                    if (cp.findOwnerRoot(f) != null) {
375
                        return null;
376
                    }
377
                }
378
                return f;
379
            }
380
        }
381
        return null;
382
    }
383
    
344
    private ClassPath findPlatformSources(String javaExecutable) {
384
    private ClassPath findPlatformSources(String javaExecutable) {
345
        for (JavaPlatform p : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
385
        for (JavaPlatform p : JavaPlatformManager.getDefault().getInstalledPlatforms()) {
346
            FileObject fo = p.findTool("java"); // NOI18N
386
            FileObject fo = p.findTool("java"); // NOI18N

Return to bug 241884