Lines 45-58
Link Here
|
45 |
|
45 |
|
46 |
|
46 |
|
47 |
import java.io.IOException; |
47 |
import java.io.IOException; |
|
|
48 |
import java.net.URI; |
48 |
import java.net.URL; |
49 |
import java.net.URL; |
49 |
import java.util.List; |
50 |
import java.util.List; |
50 |
import java.util.ArrayList; |
51 |
import java.util.ArrayList; |
|
|
52 |
import java.util.HashSet; |
51 |
import java.util.Iterator; |
53 |
import java.util.Iterator; |
52 |
|
54 |
|
53 |
import java.util.Map; |
55 |
import java.util.Set; |
54 |
import java.util.concurrent.atomic.AtomicBoolean; |
56 |
import java.util.concurrent.atomic.AtomicBoolean; |
|
|
57 |
import java.util.regex.Pattern; |
55 |
import javax.swing.Action; |
58 |
import javax.swing.Action; |
|
|
59 |
import org.apache.tools.ant.module.api.support.ActionUtils; |
60 |
import org.netbeans.api.annotations.common.CheckForNull; |
56 |
import org.netbeans.api.annotations.common.NonNull; |
61 |
import org.netbeans.api.annotations.common.NonNull; |
57 |
import org.netbeans.api.annotations.common.NullAllowed; |
62 |
import org.netbeans.api.annotations.common.NullAllowed; |
58 |
import org.netbeans.api.project.libraries.Library; |
63 |
import org.netbeans.api.project.libraries.Library; |
Lines 70-75
Link Here
|
70 |
import org.netbeans.api.project.FileOwnerQuery; |
75 |
import org.netbeans.api.project.FileOwnerQuery; |
71 |
import org.netbeans.api.project.Project; |
76 |
import org.netbeans.api.project.Project; |
72 |
import org.netbeans.api.java.queries.JavadocForBinaryQuery; |
77 |
import org.netbeans.api.java.queries.JavadocForBinaryQuery; |
|
|
78 |
import org.netbeans.api.java.queries.SourceForBinaryQuery; |
73 |
import org.netbeans.api.project.ProjectManager; |
79 |
import org.netbeans.api.project.ProjectManager; |
74 |
import org.netbeans.api.project.libraries.LibrariesCustomizer; |
80 |
import org.netbeans.api.project.libraries.LibrariesCustomizer; |
75 |
import org.netbeans.modules.java.api.common.ant.UpdateHelper; |
81 |
import org.netbeans.modules.java.api.common.ant.UpdateHelper; |
Lines 85-90
Link Here
|
85 |
import org.openide.actions.EditAction; |
91 |
import org.openide.actions.EditAction; |
86 |
import org.openide.actions.FindAction; |
92 |
import org.openide.actions.FindAction; |
87 |
import org.openide.actions.OpenAction; |
93 |
import org.openide.actions.OpenAction; |
|
|
94 |
import org.openide.filesystems.URLMapper; |
95 |
import org.openide.loaders.DataFolder; |
88 |
import org.openide.util.Exceptions; |
96 |
import org.openide.util.Exceptions; |
89 |
import org.openide.util.Parameters; |
97 |
import org.openide.util.Parameters; |
90 |
import org.openide.util.RequestProcessor; |
98 |
import org.openide.util.RequestProcessor; |
Lines 250-258
Link Here
|
250 |
} |
258 |
} |
251 |
|
259 |
|
252 |
private static Lookup createLookup(final Node original, Object... toAdd) { |
260 |
private static Lookup createLookup(final Node original, Object... toAdd) { |
|
|
261 |
final Lookup lookup = original.getLookup(); |
262 |
final org.netbeans.spi.project.ui.PathFinder pathFinder = |
263 |
lookup.lookup(org.netbeans.spi.project.ui.PathFinder.class); |
253 |
final Lookup lkp = new ProxyLookup( |
264 |
final Lookup lkp = new ProxyLookup( |
254 |
original.getLookup(), |
265 |
Lookups.exclude(lookup, org.netbeans.spi.project.ui.PathFinder.class), |
255 |
Lookups.fixed (toAdd)); |
266 |
Lookups.fixed (toAdd), |
|
|
267 |
Lookups.singleton(new PathFinder(pathFinder))); |
256 |
return lkp; |
268 |
return lkp; |
257 |
} |
269 |
} |
258 |
|
270 |
|
Lines 633-636
Link Here
|
633 |
} |
645 |
} |
634 |
} |
646 |
} |
635 |
} |
647 |
} |
|
|
648 |
|
649 |
private static final class PathFinder implements org.netbeans.spi.project.ui.PathFinder { |
650 |
|
651 |
private static final Pattern SRCDIRJAVA = Pattern.compile("\\.java$"); // NOI18N |
652 |
private static final String SUBST = ".class"; // NOI18N |
653 |
|
654 |
//@GuardBy("PathFinder.class") |
655 |
private static URI currentKey; |
656 |
//@GuardBy("PathFinder.class") |
657 |
private static Set<URI> currentValues; |
658 |
|
659 |
private final org.netbeans.spi.project.ui.PathFinder delegate; |
660 |
|
661 |
public PathFinder(@NullAllowed final org.netbeans.spi.project.ui.PathFinder delegate) { |
662 |
this.delegate = delegate; |
663 |
} |
664 |
|
665 |
@Override |
666 |
public Node findPath(Node root, Object target) { |
667 |
Node result = null; |
668 |
if (delegate != null && target instanceof FileObject) { |
669 |
FileObject binRoot = root.getLookup().lookup(FileObject.class); |
670 |
if (binRoot == null) { |
671 |
final DataFolder dobj = root.getLookup().lookup(DataFolder.class); |
672 |
binRoot = dobj == null ? null : dobj.getPrimaryFile(); |
673 |
} |
674 |
if (binRoot != null) { |
675 |
FileObject newTarget = rebase(binRoot, (FileObject) target); |
676 |
if (newTarget != null) { |
677 |
result = delegate.findPath(root, newTarget); |
678 |
} |
679 |
} |
680 |
} |
681 |
return result; |
682 |
} |
683 |
|
684 |
@CheckForNull |
685 |
static FileObject rebase( |
686 |
@NonNull final FileObject binRoot, |
687 |
@NonNull final FileObject sourceTarget) { |
688 |
|
689 |
if (shouldIgnore(sourceTarget.toURI(), binRoot.toURI())) { |
690 |
return null; |
691 |
} |
692 |
final URL providedBinRootURL = (URL) sourceTarget.getAttribute("classfile-root"); //NOI18N |
693 |
final String providedBinaryName = (String) sourceTarget.getAttribute("classfile-binaryName"); //NOI18N |
694 |
if (providedBinRootURL != null && providedBinaryName != null) { |
695 |
final FileObject providedBinRoot = URLMapper.findFileObject(providedBinRootURL); |
696 |
if (binRoot.equals(providedBinRoot)) { |
697 |
return binRoot.getFileObject(providedBinaryName + SUBST); |
698 |
} |
699 |
} else { |
700 |
for (FileObject srcRoot : SourceForBinaryQuery.findSourceRoots(binRoot.toURL()).getRoots()) { |
701 |
if (FileUtil.isParentOf(srcRoot, sourceTarget)) { |
702 |
final FileObject[] newTarget = ActionUtils.regexpMapFiles( |
703 |
new FileObject[]{sourceTarget}, |
704 |
srcRoot, |
705 |
SRCDIRJAVA, |
706 |
binRoot, |
707 |
SUBST, |
708 |
true); |
709 |
if (newTarget != null) { |
710 |
return newTarget[0]; |
711 |
} |
712 |
} |
713 |
} |
714 |
} |
715 |
ignore(sourceTarget.toURI(), binRoot.toURI()); |
716 |
return null; |
717 |
} |
718 |
|
719 |
private static synchronized boolean shouldIgnore ( |
720 |
@NonNull final URI key, |
721 |
@NonNull final URI value) { |
722 |
if (!key.equals(currentKey)) { |
723 |
return false; |
724 |
} |
725 |
return currentValues.contains(value); |
726 |
} |
727 |
|
728 |
private static synchronized void ignore( |
729 |
@NonNull final URI key, |
730 |
@NonNull final URI value) { |
731 |
if (!key.equals(currentKey)) { |
732 |
currentKey = key; |
733 |
currentValues = new HashSet<URI>(); |
734 |
} |
735 |
currentValues.add(value); |
736 |
} |
737 |
|
738 |
} |
636 |
} |
739 |
} |