Lines 42-60
Link Here
|
42 |
|
42 |
|
43 |
package org.netbeans.modules.maven.queries; |
43 |
package org.netbeans.modules.maven.queries; |
44 |
|
44 |
|
|
|
45 |
import java.beans.PropertyChangeEvent; |
46 |
import java.beans.PropertyChangeListener; |
45 |
import java.io.File; |
47 |
import java.io.File; |
46 |
import java.io.IOException; |
48 |
import java.io.IOException; |
|
|
49 |
import java.lang.ref.WeakReference; |
50 |
import java.net.MalformedURLException; |
51 |
import java.net.URI; |
47 |
import java.net.URL; |
52 |
import java.net.URL; |
|
|
53 |
import java.util.Arrays; |
54 |
import java.util.Collections; |
48 |
import java.util.Date; |
55 |
import java.util.Date; |
|
|
56 |
import java.util.HashMap; |
57 |
import java.util.Map; |
58 |
import java.util.logging.Level; |
59 |
import java.util.logging.Logger; |
60 |
import java.util.prefs.PreferenceChangeEvent; |
61 |
import java.util.prefs.PreferenceChangeListener; |
49 |
import javax.swing.event.ChangeListener; |
62 |
import javax.swing.event.ChangeListener; |
50 |
import org.netbeans.api.java.queries.SourceForBinaryQuery; |
63 |
import org.netbeans.api.java.queries.JavadocForBinaryQuery; |
|
|
64 |
import org.netbeans.api.project.Project; |
65 |
import org.netbeans.modules.maven.api.NbMavenProject; |
66 |
import org.netbeans.modules.maven.embedder.EmbedderFactory; |
67 |
import org.netbeans.modules.maven.spi.queries.ForeignClassBundler; |
51 |
import org.netbeans.spi.java.project.support.JavadocAndSourceRootDetection; |
68 |
import org.netbeans.spi.java.project.support.JavadocAndSourceRootDetection; |
|
|
69 |
import org.netbeans.spi.java.queries.JavadocForBinaryQueryImplementation; |
52 |
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; |
70 |
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation; |
|
|
71 |
import org.netbeans.spi.java.queries.SourceForBinaryQueryImplementation2; |
72 |
import org.openide.ErrorManager; |
73 |
import org.openide.filesystems.FileChangeAdapter; |
74 |
import org.openide.filesystems.FileChangeListener; |
75 |
import org.openide.filesystems.FileEvent; |
53 |
import org.openide.filesystems.FileObject; |
76 |
import org.openide.filesystems.FileObject; |
54 |
import org.openide.filesystems.FileUtil; |
77 |
import org.openide.filesystems.FileUtil; |
55 |
import org.openide.filesystems.URLMapper; |
78 |
import org.openide.modules.InstalledFileLocator; |
|
|
79 |
import org.openide.util.ChangeSupport; |
56 |
import org.openide.util.Exceptions; |
80 |
import org.openide.util.Exceptions; |
|
|
81 |
import org.openide.util.RequestProcessor; |
82 |
import org.openide.util.WeakListeners; |
57 |
import org.openide.util.lookup.ServiceProvider; |
83 |
import org.openide.util.lookup.ServiceProvider; |
|
|
84 |
import org.openide.util.lookup.ServiceProviders; |
58 |
|
85 |
|
59 |
/** |
86 |
/** |
60 |
* |
87 |
* |
Lines 64-87
Link Here
|
64 |
* |
91 |
* |
65 |
* @author Milos Kleint |
92 |
* @author Milos Kleint |
66 |
*/ |
93 |
*/ |
67 |
@ServiceProvider(service=SourceForBinaryQueryImplementation.class, position=999) |
94 |
@ServiceProviders({ |
68 |
public class RepositorySourceForBinaryQueryImpl implements SourceForBinaryQueryImplementation { |
95 |
@ServiceProvider(service=SourceForBinaryQueryImplementation.class, position=68), |
|
|
96 |
@ServiceProvider(service=SourceForBinaryQueryImplementation2.class, position=68), |
97 |
@ServiceProvider(service=JavadocForBinaryQueryImplementation.class, position=68) |
98 |
}) |
99 |
public class RepositorySourceForBinaryQueryImpl extends AbstractMavenForBinaryQueryImpl { |
69 |
|
100 |
|
70 |
@Override public SourceForBinaryQuery.Result findSourceRoots(URL url) { |
101 |
|
71 |
File stored = SourceJavadocByHash.find(url, false); |
102 |
private final Map<URL, WeakReference<SrcResult>> srcCache = Collections.synchronizedMap(new HashMap<URL, WeakReference<SrcResult>>()); |
72 |
if (stored != null) { |
103 |
private final Map<URL, WeakReference<JavadocResult>> javadocCache = Collections.synchronizedMap(new HashMap<URL, WeakReference<JavadocResult>>()); |
73 |
return new SrcResult(stored); |
104 |
|
|
|
105 |
|
106 |
private static final RequestProcessor RP = new RequestProcessor("Maven Repository SFBQ result change"); |
107 |
|
108 |
@Override |
109 |
public synchronized Result findSourceRoots2(URL url) { |
110 |
if (!"jar".equals(url.getProtocol())) { //NOI18N |
111 |
// null for directories. |
112 |
return null; |
74 |
} |
113 |
} |
75 |
URL binRoot = url; |
114 |
|
|
|
115 |
WeakReference<SrcResult> cached = srcCache.get(url); |
116 |
if (cached != null) { |
117 |
SrcResult result = cached.get(); |
118 |
if (result != null) { |
119 |
return result; |
120 |
} |
121 |
} |
122 |
|
123 |
File jarFile = FileUtil.archiveOrDirForURL(url); |
124 |
if (jarFile != null) { |
125 |
// String name = jarFile.getName(); |
126 |
File parent = jarFile.getParentFile(); |
127 |
if (parent != null) { |
128 |
File parentParent = parent.getParentFile(); |
129 |
if (parentParent != null) { |
130 |
// each repository artifact should have this structure |
131 |
String artifact = parentParent.getName(); |
132 |
String version = parent.getName(); |
133 |
// File pom = new File(parent, artifact + "-" + version + ".pom"); |
134 |
// // maybe this condition is already overkill.. |
135 |
// if (pom.exists()) { |
136 |
File srcs = new File(parent, artifact + "-" + version + "-sources.jar"); //NOI18N |
137 |
if (jarFile.getName().startsWith(artifact + "-" + version)) { //one last perf check before calling the embedder |
138 |
URI localRepo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile().toURI(); |
139 |
URI rel = localRepo.relativize(parentParent.getParentFile().toURI()); |
140 |
if (!rel.isAbsolute()) { |
141 |
String groupId = rel.getPath(); |
142 |
if (groupId != null && !groupId.equals("")) { |
143 |
groupId = groupId.replace("/", "."); |
144 |
if (groupId.endsWith(".")) { |
145 |
groupId = groupId.substring(0, groupId.length() - 1); |
146 |
} |
147 |
SrcResult result = new SrcResult(groupId, artifact, version, FileUtil.getArchiveFile(url), srcs); |
148 |
srcCache.put(url, new WeakReference<SrcResult>(result)); |
149 |
return result; |
150 |
} |
151 |
} |
152 |
|
153 |
} |
154 |
// } |
155 |
} |
156 |
} |
157 |
} |
158 |
return null; |
159 |
|
160 |
} |
161 |
|
162 |
@Override |
163 |
public JavadocForBinaryQuery.Result findJavadoc(URL url) { |
164 |
URL binRoot; |
76 |
if ("jar".equals(url.getProtocol())) { //NOI18N |
165 |
if ("jar".equals(url.getProtocol())) { //NOI18N |
77 |
binRoot = FileUtil.getArchiveFile(url); |
166 |
binRoot = FileUtil.getArchiveFile(url); |
78 |
} else { |
167 |
} else { |
79 |
// null for directories. |
168 |
// null for directories. |
80 |
return null; |
169 |
return null; |
81 |
} |
170 |
} |
82 |
FileObject jarFO = URLMapper.findFileObject(binRoot); |
171 |
|
83 |
if (jarFO != null) { |
172 |
//hack for javaee6 jar docs which we ship with netbeans and which are not in any maven repository |
84 |
File jarFile = FileUtil.toFile(jarFO); |
173 |
if (binRoot.getPath().endsWith("/javax/javaee-api/6.0/javaee-api-6.0.jar") |
|
|
174 |
|| binRoot.getPath().endsWith("/javax/javaee-web-api/6.0/javaee-web-api-6.0.jar")) { //NOI18N |
175 |
return new Javaee6Result(); |
176 |
} |
177 |
|
178 |
WeakReference<JavadocResult> cached = javadocCache.get(url); |
179 |
if (cached != null) { |
180 |
JavadocResult result = cached.get(); |
181 |
if (result != null) { |
182 |
return result; |
183 |
} |
184 |
} |
185 |
|
186 |
|
187 |
File jarFile = FileUtil.archiveOrDirForURL(url); |
85 |
if (jarFile != null) { |
188 |
if (jarFile != null) { |
86 |
// String name = jarFile.getName(); |
189 |
// String name = jarFile.getName(); |
87 |
File parent = jarFile.getParentFile(); |
190 |
File parent = jarFile.getParentFile(); |
Lines 94-128
Link Here
|
94 |
// File pom = new File(parent, artifact + "-" + version + ".pom"); |
197 |
// File pom = new File(parent, artifact + "-" + version + ".pom"); |
95 |
// // maybe this condition is already overkill.. |
198 |
// // maybe this condition is already overkill.. |
96 |
// if (pom.exists()) { |
199 |
// if (pom.exists()) { |
97 |
File srcs = new File(parent, artifact + "-" + version + "-sources.jar"); //NOI18N |
200 |
File javadoc = new File(parent, artifact + "-" + version + "-javadoc.jar"); //NOI18N |
98 |
if (srcs.exists()) { |
201 |
if (jarFile.getName().startsWith(artifact + "-" + version)) { //one last perf check before calling the embedder |
99 |
return new SrcResult(srcs); |
202 |
URI localRepo = EmbedderFactory.getProjectEmbedder().getLocalRepositoryFile().toURI(); |
|
|
203 |
URI rel = localRepo.relativize(parentParent.getParentFile().toURI()); |
204 |
if (!rel.isAbsolute()) { |
205 |
String groupId = rel.getPath(); |
206 |
if (groupId != null && !groupId.equals("")) { |
207 |
groupId = groupId.replace("/", "."); |
208 |
if (groupId.endsWith(".")) { |
209 |
groupId = groupId.substring(0, groupId.length() - 1); |
100 |
} |
210 |
} |
101 |
// } |
211 |
JavadocResult result = new JavadocResult(groupId, artifact, version, binRoot, javadoc); |
|
|
212 |
javadocCache.put(url, new WeakReference<JavadocResult>(result)); |
213 |
return result; |
102 |
} |
214 |
} |
103 |
} |
215 |
} |
|
|
216 |
|
104 |
} |
217 |
} |
|
|
218 |
// } |
105 |
} |
219 |
} |
|
|
220 |
} |
221 |
} |
106 |
return null; |
222 |
return null; |
107 |
|
|
|
108 |
} |
223 |
} |
109 |
|
224 |
|
110 |
private static class SrcResult implements SourceForBinaryQuery.Result { |
225 |
private static class SrcResult implements SourceForBinaryQueryImplementation2.Result { |
111 |
private static final String ATTR_PATH = "lastRootCheckPath"; //NOI18N |
226 |
private static final String ATTR_PATH = "lastRootCheckPath"; //NOI18N |
112 |
private static final String ATTR_STAMP = "lastRootCheckStamp"; //NOI18N |
227 |
private static final String ATTR_STAMP = "lastRootCheckStamp"; //NOI18N |
113 |
private File file; |
228 |
private final File sourceJarFile; |
|
|
229 |
private final ChangeSupport support; |
230 |
private final PreferenceChangeListener prefListener; |
231 |
private final PropertyChangeListener projectListener; |
232 |
private final FileChangeListener sourceJarChangeListener; |
233 |
private final String groupId; |
234 |
private final String artifactId; |
235 |
private final String version; |
236 |
private final String gav; |
237 |
private final URL binary; |
114 |
|
238 |
|
115 |
SrcResult(File src) { |
239 |
private Project currentProject; |
116 |
file = src; |
240 |
private FileObject[] cached; |
|
|
241 |
|
242 |
|
243 |
SrcResult(String groupId, String artifactId, String version, URL binary, File sourceJar) { |
244 |
sourceJarFile = sourceJar; |
245 |
this.groupId = groupId; |
246 |
this.artifactId = artifactId; |
247 |
this.version = version; |
248 |
this.binary = binary; |
249 |
this.gav = MavenFileOwnerQueryImpl.cacheKey(groupId, artifactId, version); |
250 |
|
251 |
support = new ChangeSupport(this); |
252 |
prefListener = new PreferenceChangeListener() { |
253 |
@Override |
254 |
public void preferenceChange(PreferenceChangeEvent evt) { |
255 |
if (gav.equals(evt.getKey())) { |
256 |
//external root in local repository changed.. |
257 |
checkChanges(); |
117 |
} |
258 |
} |
|
|
259 |
} |
260 |
}; |
261 |
projectListener = new PropertyChangeListener() { |
262 |
public @Override |
263 |
void propertyChange(PropertyChangeEvent event) { |
264 |
if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) { |
265 |
//project could have changed source roots.. |
266 |
checkChanges(); |
267 |
} |
268 |
} |
269 |
}; |
270 |
sourceJarChangeListener = new FileChangeAdapter(){ |
271 |
@Override |
272 |
public void fileDataCreated(FileEvent fe) { |
273 |
//source jar was created.. |
274 |
checkChanges(); |
275 |
} |
118 |
|
276 |
|
119 |
@Override public void addChangeListener(ChangeListener changeListener) {} |
277 |
}; |
|
|
278 |
MavenFileOwnerQueryImpl.prefs().addPreferenceChangeListener( |
279 |
WeakListeners.create(PreferenceChangeListener.class, prefListener, MavenFileOwnerQueryImpl.prefs())); |
120 |
|
280 |
|
121 |
@Override public void removeChangeListener(ChangeListener changeListener) {} |
281 |
FileUtil.addFileChangeListener(FileUtil.weakFileChangeListener(sourceJarChangeListener, sourceJar)); |
|
|
282 |
} |
122 |
|
283 |
|
123 |
@Override public FileObject[] getRoots() { |
284 |
private void checkChanges() { |
124 |
if (file.exists()) { |
285 |
if (!Arrays.equals(getCached(), getRoots())) { |
125 |
FileObject fo = FileUtil.toFileObject(file); |
286 |
support.fireChange(); |
|
|
287 |
} |
288 |
} |
289 |
/** |
290 |
* use MFOQI to determine what is the current project owning our coordinates in local repository. |
291 |
*/ |
292 |
private void checkCurrentProject() { |
293 |
Project owner = MavenFileOwnerQueryImpl.getInstance().getOwner(groupId, artifactId, version); |
294 |
if (owner != null && owner.getLookup().lookup(NbMavenProject.class) == null) { |
295 |
owner = null; |
296 |
} |
297 |
//XXX TODO should we be attaching a weak listener here? |
298 |
if (currentProject != null && !currentProject.equals(owner)) { |
299 |
currentProject.getLookup().lookup(NbMavenProject.class).removePropertyChangeListener(projectListener); |
300 |
} |
301 |
if (owner != null && !owner.equals(currentProject)) { |
302 |
owner.getLookup().lookup(NbMavenProject.class).addPropertyChangeListener(projectListener); |
303 |
} |
304 |
currentProject = owner; |
305 |
} |
306 |
|
307 |
@Override |
308 |
public void addChangeListener(ChangeListener changeListener) { |
309 |
support.addChangeListener(changeListener); |
310 |
} |
311 |
|
312 |
@Override |
313 |
public void removeChangeListener(ChangeListener changeListener) { |
314 |
support.removeChangeListener(changeListener); |
315 |
} |
316 |
|
317 |
@Override |
318 |
public FileObject[] getRoots() { |
319 |
FileObject[] toRet; |
320 |
checkCurrentProject(); |
321 |
Project prj = currentProject; |
322 |
if (prj != null) { |
323 |
toRet = getProjectSrcRoots(prj); |
324 |
} else { |
325 |
File f = SourceJavadocByHash.find(binary, false); |
326 |
if (f != null && f.exists()) { |
327 |
toRet = getSourceJarRoot(f); |
328 |
} |
329 |
else if (sourceJarFile.exists()) { |
330 |
toRet = getSourceJarRoot(sourceJarFile); |
331 |
} else { |
332 |
toRet = new FileObject[0]; |
333 |
} |
334 |
} |
335 |
if (!Arrays.equals(cached, toRet)) { |
336 |
//how to figure otherwise that something changed, possibly multiple people hold the result instance |
337 |
// and one asks the roots, later we get event from outside, but then the cached value already updated.. |
338 |
RP.post(new Runnable() { |
339 |
@Override |
340 |
public void run() { |
341 |
support.fireChange(); |
342 |
} |
343 |
}); |
344 |
} |
345 |
cached = toRet; |
346 |
return toRet; |
347 |
} |
348 |
|
349 |
public FileObject[] getCached() { |
350 |
return cached; |
351 |
} |
352 |
|
353 |
private String checkPath(FileObject jarRoot, FileObject fo) { |
354 |
String toRet = null; |
355 |
FileObject root = JavadocAndSourceRootDetection.findSourceRoot(jarRoot); |
356 |
try { |
357 |
if (root != null && !root.equals(jarRoot)) { |
358 |
toRet = FileUtil.getRelativePath(jarRoot, root); |
359 |
fo.setAttribute(ATTR_PATH, toRet); |
360 |
} |
361 |
fo.setAttribute(ATTR_STAMP, new Date()); |
362 |
} catch (IOException ex) { |
363 |
Exceptions.printStackTrace(ex); |
364 |
} |
365 |
return toRet; |
366 |
} |
367 |
|
368 |
private FileObject[] getSourceJarRoot(File sourceJar) { |
369 |
FileObject fo = FileUtil.toFileObject(sourceJar); |
126 |
FileObject jarRoot = FileUtil.getArchiveRoot(fo); |
370 |
FileObject jarRoot = FileUtil.getArchiveRoot(fo); |
127 |
if (jarRoot != null) { //#139894 it seems that sometimes it can return null. |
371 |
if (jarRoot != null) { //#139894 it seems that sometimes it can return null. |
128 |
// I suppose it's in the case when the jar/zip file in repository exists |
372 |
// I suppose it's in the case when the jar/zip file in repository exists |
Lines 145-157
Link Here
|
145 |
} |
389 |
} |
146 |
return fos; |
390 |
return fos; |
147 |
} |
391 |
} |
148 |
} |
|
|
149 |
return new FileObject[0]; |
392 |
return new FileObject[0]; |
150 |
} |
393 |
} |
151 |
|
394 |
|
|
|
395 |
@Override |
396 |
public boolean preferSources() { |
397 |
Project prj = currentProject; |
398 |
if (prj != null) { |
399 |
//TODO is project broken or not, handle accordingly.. |
400 |
return prj.getLookup().lookup(ForeignClassBundler.class).preferSources(); |
401 |
} |
402 |
return false; |
403 |
} |
404 |
|
405 |
} |
406 |
|
407 |
private static class JavadocResult implements JavadocForBinaryQuery.Result { |
408 |
private final File sourceJarFile; |
409 |
private final String groupId; |
410 |
private final String artifactId; |
411 |
private final String version; |
412 |
private final URL binary; |
413 |
private final String gav; |
414 |
private final ChangeSupport support; |
415 |
private final PreferenceChangeListener prefListener; |
416 |
private final PropertyChangeListener projectListener; |
417 |
private final FileChangeAdapter javadocJarChangeListener; |
418 |
private Project currentProject; |
419 |
private URL[] cached; |
420 |
private static final String ATTR_PATH = "lastRootCheckPath"; //NOI18N |
421 |
private static final String ATTR_STAMP = "lastRootCheckStamp"; //NOI18N |
422 |
|
423 |
|
424 |
|
425 |
JavadocResult(String groupId, String artifactId, String version, URL binary, File javadocJar) { |
426 |
sourceJarFile = javadocJar; |
427 |
this.groupId = groupId; |
428 |
this.artifactId = artifactId; |
429 |
this.version = version; |
430 |
this.binary = binary; |
431 |
this.gav = MavenFileOwnerQueryImpl.cacheKey(groupId, artifactId, version); |
432 |
|
433 |
support = new ChangeSupport(this); |
434 |
prefListener = new PreferenceChangeListener() { |
435 |
@Override |
436 |
public void preferenceChange(PreferenceChangeEvent evt) { |
437 |
if (gav.equals(evt.getKey())) { |
438 |
//external root in local repository changed.. |
439 |
checkCurrentProject(); |
440 |
checkChanges(); |
441 |
} |
442 |
} |
443 |
}; |
444 |
projectListener = new PropertyChangeListener() { |
445 |
public @Override |
446 |
void propertyChange(PropertyChangeEvent event) { |
447 |
if (NbMavenProject.PROP_PROJECT.equals(event.getPropertyName())) { |
448 |
//project could have changed coordinates.. |
449 |
checkCurrentProject(); |
450 |
checkChanges(); |
451 |
} |
452 |
} |
453 |
}; |
454 |
javadocJarChangeListener = new FileChangeAdapter(){ |
455 |
@Override |
456 |
public void fileDataCreated(FileEvent fe) { |
457 |
//source jar was created.. |
458 |
checkChanges(); |
459 |
} |
460 |
|
461 |
}; |
462 |
MavenFileOwnerQueryImpl.prefs().addPreferenceChangeListener( |
463 |
WeakListeners.create(PreferenceChangeListener.class, prefListener, MavenFileOwnerQueryImpl.prefs())); |
464 |
|
465 |
FileUtil.addFileChangeListener(javadocJarChangeListener, javadocJar); |
466 |
} |
467 |
@Override |
468 |
public URL[] getRoots() { |
469 |
URL[] toRet; |
470 |
Project prj = currentProject; |
471 |
if (prj != null) { |
472 |
toRet = new URL[0]; |
473 |
} else { |
474 |
File f = SourceJavadocByHash.find(binary, true); |
475 |
if (f != null && f.exists()) { |
476 |
toRet = getJavadocJarRoot(f); |
477 |
} |
478 |
else if (sourceJarFile.exists()) { |
479 |
toRet = getJavadocJarRoot(sourceJarFile); |
480 |
} else { |
481 |
toRet = new URL[0]; |
482 |
} |
483 |
} |
484 |
cached = toRet; |
485 |
return toRet; |
486 |
} |
487 |
|
488 |
public URL[] getCached() { |
489 |
return cached; |
490 |
} |
491 |
|
492 |
@Override |
493 |
public void addChangeListener(ChangeListener l) { |
494 |
support.addChangeListener(l); |
495 |
} |
496 |
|
497 |
@Override |
498 |
public void removeChangeListener(ChangeListener l) { |
499 |
support.removeChangeListener(l); |
500 |
} |
501 |
|
502 |
private void checkChanges() { |
503 |
if (!Arrays.equals(getCached(), getRoots())) { |
504 |
support.fireChange(); |
505 |
} |
506 |
} |
507 |
/** |
508 |
* use MFOQI to determine what is the current project owning our coordinates in local repository. |
509 |
*/ |
510 |
private void checkCurrentProject() { |
511 |
Project owner = MavenFileOwnerQueryImpl.getInstance().getOwner(groupId, artifactId, version); |
512 |
if (owner != null && owner.getLookup().lookup(NbMavenProject.class) == null) { |
513 |
owner = null; |
514 |
} |
515 |
if (currentProject != null && !currentProject.equals(owner)) { |
516 |
currentProject.getLookup().lookup(NbMavenProject.class).removePropertyChangeListener(projectListener); |
517 |
} |
518 |
if (owner != null && !owner.equals(currentProject)) { |
519 |
owner.getLookup().lookup(NbMavenProject.class).addPropertyChangeListener(projectListener); |
520 |
} |
521 |
currentProject = owner; |
522 |
} |
523 |
|
524 |
private URL[] getJavadocJarRoot(File file) { |
525 |
try { |
526 |
if (file.exists()) { |
527 |
FileObject fo = FileUtil.toFileObject(file); |
528 |
if (!FileUtil.isArchiveFile(fo)) { |
529 |
//#124175 ignore any jar files that are not jar files (like when downloaded file is actually an error html page). |
530 |
Logger.getLogger(RepositorySourceForBinaryQueryImpl.class.getName()).log(Level.INFO, "javadoc in repository is not really a JAR: {0}", file); |
531 |
return new URL[0]; |
532 |
} |
533 |
//try detecting the source path root, in case the source jar has the sources not in root. |
534 |
Date date = (Date) fo.getAttribute(ATTR_STAMP); |
535 |
String path = (String) fo.getAttribute(ATTR_PATH); |
536 |
if (date == null || fo.lastModified().after(date)) { |
537 |
path = checkPath(FileUtil.getArchiveRoot(fo), fo); |
538 |
} |
539 |
|
540 |
URL[] url; |
541 |
if (path != null) { |
542 |
url = new URL[1]; |
543 |
URL root = FileUtil.getArchiveRoot(file.toURI().toURL()); |
544 |
if (!path.endsWith("/")) { //NOI18N |
545 |
path = path + "/"; //NOI18N |
546 |
} |
547 |
url[0] = new URL(root, path); |
548 |
} else { |
549 |
url = new URL[1]; |
550 |
url[0] = FileUtil.getArchiveRoot(file.toURI().toURL()); |
551 |
} |
552 |
return url; |
553 |
} |
554 |
} catch (MalformedURLException exc) { |
555 |
ErrorManager.getDefault().notify(exc); |
556 |
} |
557 |
return new URL[0]; |
558 |
} |
559 |
|
152 |
private String checkPath(FileObject jarRoot, FileObject fo) { |
560 |
private String checkPath(FileObject jarRoot, FileObject fo) { |
153 |
String toRet = null; |
561 |
String toRet = null; |
154 |
FileObject root = JavadocAndSourceRootDetection.findSourceRoot(jarRoot); |
562 |
FileObject root = JavadocAndSourceRootDetection.findJavadocRoot(jarRoot); |
155 |
try { |
563 |
try { |
156 |
if (root != null && !root.equals(jarRoot)) { |
564 |
if (root != null && !root.equals(jarRoot)) { |
157 |
toRet = FileUtil.getRelativePath(jarRoot, root); |
565 |
toRet = FileUtil.getRelativePath(jarRoot, root); |
Lines 166-169
Link Here
|
166 |
|
574 |
|
167 |
} |
575 |
} |
168 |
|
576 |
|
|
|
577 |
private static class Javaee6Result implements JavadocForBinaryQuery.Result { |
578 |
|
579 |
Javaee6Result() {} |
580 |
|
581 |
@Override public void addChangeListener(ChangeListener changeListener) {} |
582 |
|
583 |
@Override public void removeChangeListener(ChangeListener changeListener) {} |
584 |
|
585 |
@Override public URL[] getRoots() { |
586 |
try { |
587 |
File j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee6-doc-api.zip", "org.netbeans.modules.j2ee.platform", false); // NOI18N |
588 |
if (j2eeDoc != null) { |
589 |
URL url = FileUtil.getArchiveRoot(j2eeDoc.toURI().toURL()); |
590 |
url = new URL(url + "docs/api/"); //NOI18N |
591 |
return new URL[]{url}; |
169 |
} |
592 |
} |
|
|
593 |
} catch (MalformedURLException ex) { |
594 |
Exceptions.printStackTrace(ex); |
595 |
} |
596 |
return new URL[0]; |
597 |
} |
598 |
|
599 |
} |
600 |
|
601 |
} |