importClasses imports the named classes from the classpaths of the Importer.
(names []string, allowMissingClasses bool)
| 595 | |
| 596 | // importClasses imports the named classes from the classpaths of the Importer. |
| 597 | func (j *Importer) importClasses(names []string, allowMissingClasses bool) ([]*Class, error) { |
| 598 | if len(names) == 0 { |
| 599 | return nil, nil |
| 600 | } |
| 601 | args := []string{"-J-Duser.language=en", "-s", "-protected", "-constants"} |
| 602 | args = append(args, "-classpath", j.Classpath) |
| 603 | if j.Bootclasspath != "" { |
| 604 | args = append(args, "-bootclasspath", j.Bootclasspath) |
| 605 | } |
| 606 | args = append(args, names...) |
| 607 | javapPath, err := javapPath() |
| 608 | if err != nil { |
| 609 | return nil, err |
| 610 | } |
| 611 | javap := exec.Command(javapPath, args...) |
| 612 | out, err := javap.CombinedOutput() |
| 613 | if err != nil { |
| 614 | if _, ok := err.(*exec.ExitError); !ok { |
| 615 | return nil, fmt.Errorf("javap failed: %v", err) |
| 616 | } |
| 617 | // Not every name is a Java class so an exit error from javap is not |
| 618 | // fatal. |
| 619 | } |
| 620 | s := bufio.NewScanner(bytes.NewBuffer(out)) |
| 621 | var classes []*Class |
| 622 | for _, name := range names { |
| 623 | cls, err := j.scanClass(s, name) |
| 624 | if err != nil { |
| 625 | _, notfound := err.(*errClsNotFound) |
| 626 | if notfound && allowMissingClasses { |
| 627 | continue |
| 628 | } |
| 629 | if notfound && name != "android.databinding.DataBindingComponent" { |
| 630 | return nil, err |
| 631 | } |
| 632 | // The Android Databinding library generates android.databinding.DataBindingComponent |
| 633 | // too late in the build process for the gobind plugin to import it. Synthesize a class |
| 634 | // for it instead. |
| 635 | cls = &Class{ |
| 636 | Name: name, |
| 637 | FindName: name, |
| 638 | Interface: true, |
| 639 | PkgName: "databinding", |
| 640 | JNIName: JNIMangle(name), |
| 641 | } |
| 642 | } |
| 643 | classes = append(classes, cls) |
| 644 | j.clsMap[name] = cls |
| 645 | } |
| 646 | return classes, nil |
| 647 | } |
| 648 | |
| 649 | // importReferencedClasses imports all implicit classes (super types, parameter and |
| 650 | // return types) for the given classes not already imported. |
no test coverage detected