|
162 | 162 | import org.scijava.ui.swing.script.commands.KillScript;
|
163 | 163 | import org.scijava.util.FileUtils;
|
164 | 164 | import org.scijava.util.MiscUtils;
|
| 165 | +import org.scijava.util.POM; |
| 166 | +import org.scijava.util.Types; |
165 | 167 | import org.scijava.widget.FileWidget;
|
166 | 168 |
|
167 | 169 | /**
|
@@ -1402,22 +1404,14 @@ else if (source == openMacroFunctions) try {
|
1402 | 1404 | else if (source == extractSourceJar) extractSourceJar();
|
1403 | 1405 | else if (source == openSourceForClass) {
|
1404 | 1406 | final String className = getSelectedClassNameOrAsk();
|
1405 |
| - if (className != null) try { |
1406 |
| - final String path = new FileFunctions(this).getSourcePath(className); |
1407 |
| - if (path != null) open(new File(path)); |
1408 |
| - else { |
| 1407 | + if (className != null) { |
| 1408 | + try { |
1409 | 1409 | final String url = new FileFunctions(this).getSourceURL(className);
|
1410 |
| - try { |
1411 |
| - platformService.open(new URL(url)); |
1412 |
| - } |
1413 |
| - catch (final Throwable e) { |
1414 |
| - handleException(e); |
1415 |
| - } |
| 1410 | + platformService.open(new URL(url)); |
| 1411 | + } |
| 1412 | + catch (final Throwable e) { |
| 1413 | + handleException(e); |
1416 | 1414 | }
|
1417 |
| - } |
1418 |
| - catch (final ClassNotFoundException e) { |
1419 |
| - log.debug(e); |
1420 |
| - error("Could not open source for class " + className); |
1421 | 1415 | }
|
1422 | 1416 | }
|
1423 | 1417 | /* TODO
|
@@ -2606,10 +2600,63 @@ public void openHelp(final String className) {
|
2606 | 2600 | * @param className
|
2607 | 2601 | * @param withFrames
|
2608 | 2602 | */
|
2609 |
| - public void openHelp(final String className, final boolean withFrames) { |
2610 |
| - if (className == null) { |
2611 |
| - // FIXME: This cannot be right. |
2612 |
| - getSelectedClassNameOrAsk(); |
| 2603 | + public void openHelp(String className, final boolean withFrames) { |
| 2604 | + if (className == null) className = getSelectedClassNameOrAsk(); |
| 2605 | + if (className == null) return; |
| 2606 | + final Class<?> c = Types.load(className, false); |
| 2607 | + |
| 2608 | + final String path = (withFrames ? "index.html?" : "") + // |
| 2609 | + className.replace('.', '/') + ".html"; |
| 2610 | + |
| 2611 | + final String url; |
| 2612 | + |
| 2613 | + if (className.startsWith("java.") || className.startsWith("javax.")) { |
| 2614 | + // Core Java class -- use javadoc.scijava.org/Java<#> link. |
| 2615 | + final String javaVersion = System.getProperty("java.version"); |
| 2616 | + final String majorVersion; |
| 2617 | + if (javaVersion.startsWith("1.")) { |
| 2618 | + majorVersion = javaVersion.substring(2, javaVersion.indexOf('.', 2)); |
| 2619 | + } |
| 2620 | + else majorVersion = javaVersion.substring(0, javaVersion.indexOf('.')); |
| 2621 | + url = "https://javadoc.scijava.org/Java" + majorVersion + "/" + path; |
| 2622 | + } |
| 2623 | + else { |
| 2624 | + // Third party library -- look for a Maven POM identifying it. |
| 2625 | + final POM pom = POM.getPOM(c); |
| 2626 | + if (pom == null) { |
| 2627 | + throw new IllegalArgumentException(// |
| 2628 | + "Unknown origin for class " + className); |
| 2629 | + } |
| 2630 | + final String releaseProfiles = pom.cdata("//properties/releaseProfiles"); |
| 2631 | + final boolean scijavaRepo = "deploy-to-scijava".equals(releaseProfiles); |
| 2632 | + if (scijavaRepo) { |
| 2633 | + // Use javadoc.scijava.org -- try to figure out which project. |
| 2634 | + // Maybe some day, we can bake this information into the POM. |
| 2635 | + final String project; |
| 2636 | + final String g = pom.getGroupId(); |
| 2637 | + if ("net.imagej".equals(g)) { |
| 2638 | + project = "ij".equals(pom.getArtifactId()) ? "ImageJ1" : "ImageJ"; |
| 2639 | + } |
| 2640 | + else if ("io.scif".equals(g)) project = "SCIFIO"; |
| 2641 | + else if ("net.imglib2".equals(g)) project = "ImgLib2"; |
| 2642 | + else if ("org.bonej".equals(g)) project = "BoneJ"; |
| 2643 | + else if ("org.scijava".equals(g)) project = "SciJava"; |
| 2644 | + else if ("sc.fiji".equals(g)) project = "Fiji"; |
| 2645 | + else project = "Java"; |
| 2646 | + url = "https://javadoc.scijava.org/" + project + "/" + path; |
| 2647 | + } |
| 2648 | + else { |
| 2649 | + // Assume Maven Central -- use javadoc.io. |
| 2650 | + url = "https://javadoc.io/static/" + pom.getGroupId() + "/" + // |
| 2651 | + pom.getArtifactId() + "/" + pom.getVersion() + "/" + path; |
| 2652 | + } |
| 2653 | + } |
| 2654 | + |
| 2655 | + try { |
| 2656 | + platformService.open(new URL(url)); |
| 2657 | + } |
| 2658 | + catch (final Throwable e) { |
| 2659 | + handleException(e); |
2613 | 2660 | }
|
2614 | 2661 | }
|
2615 | 2662 |
|
|
0 commit comments