Example #1
0
  static void validateAgainstAUDTDs(InputSource input, final Path updaterJar, final Task task)
      throws IOException, SAXException {
    XMLUtil.parse(
        input,
        true,
        false,
        XMLUtil.rethrowHandler(),
        new EntityResolver() {
          ClassLoader loader = new AntClassLoader(task.getProject(), updaterJar);

          public InputSource resolveEntity(String publicId, String systemId)
              throws SAXException, IOException {
            String remote = "http://www.netbeans.org/dtds/";
            if (systemId.startsWith(remote)) {
              String rsrc = "org/netbeans/updater/resources/" + systemId.substring(remote.length());
              URL u = loader.getResource(rsrc);
              if (u != null) {
                return new InputSource(u.toString());
              } else {
                task.log(rsrc + " not found in " + updaterJar, Project.MSG_WARN);
              }
            }
            return null;
          }
        });
  }
  public @Override void execute() throws BuildException {
    String p = getProject().getProperty("javahelpbin.exclude.modules");
    excludedModulesSet = parseExcludeModulesProperty(p);
    for (FileSet fs : filesets) {
      FileScanner scanner = fs.getDirectoryScanner(getProject());
      File dir = scanner.getBasedir();
      String[] files = scanner.getIncludedFiles();

      URLClassLoader globalClassLoader;
      Map<String, URLClassLoader> classLoaderMap;
      try {
        globalClassLoader = createGlobalClassLoader(dir, files);
        classLoaderMap = createClassLoaderMap(dir, files);
        NbDocsStreamHandler.NbDocsURLConnection.globalClassLoader.set(globalClassLoader);
        NbDocsStreamHandler.NbDocsURLConnection.classLoaderMap.set(classLoaderMap);
        CheckLinks.handlerFactory.set(new NbDocsStreamHandler.Factory());
        for (Map.Entry<String, URLClassLoader> entry : classLoaderMap.entrySet()) {
          String cnb = entry.getKey();
          if (excludedModulesSet.contains(cnb)) {
            log("skipping module: " + cnb, Project.MSG_INFO);
            continue;
          }
          URLClassLoader l = entry.getValue();
          Manifest m;
          InputStream is = l.getResourceAsStream("META-INF/MANIFEST.MF");
          if (is != null) {
            try {
              m = new Manifest(is);
            } finally {
              is.close();
            }
          } else {
            log("No manifest in " + Arrays.toString(l.getURLs()), Project.MSG_WARN);
            continue;
          }
          for (String resource :
              new String[] {
                m.getMainAttributes().getValue("OpenIDE-Module-Layer"),
                "META-INF/generated-layer.xml"
              }) {
            if (resource == null) {
              continue;
            }
            URL layer = l.getResource(resource);
            if (layer == null) {
              log("No layer " + resource, Project.MSG_VERBOSE);
              continue;
            }
            Document doc;
            try {
              doc = XMLUtil.parse(new InputSource(layer.toString()), false, false, null, NO_DTDS);
            } catch (SAXException x) {
              log("Could not parse " + layer, x, Project.MSG_WARN);
              continue;
            }
            for (Element services : XMLUtil.findSubElements(doc.getDocumentElement())) {
              if (!services.getTagName().equals("folder")
                  || !services.getAttribute("name").equals("Services")) {
                continue;
              }
              for (Element javahelp : XMLUtil.findSubElements(services)) {
                if (!javahelp.getTagName().equals("folder")
                    || !javahelp.getAttribute("name").equals("JavaHelp")) {
                  continue;
                }
                JAVAHELP:
                for (Element registration : XMLUtil.findSubElements(javahelp)) {
                  if (!registration.getTagName().equals("file")) {
                    continue;
                  }
                  InputSource input = null;
                  String url = registration.getAttribute("url");
                  if (!url.isEmpty()) {
                    input = new InputSource(new URL(layer, url).toString());
                  } else {
                    NodeList nl = registration.getChildNodes();
                    for (int i = 0; i < nl.getLength(); i++) {
                      if (nl.item(i).getNodeType() == Node.CDATA_SECTION_NODE) {
                        if (input == null) {
                          input = new InputSource(new StringReader(nl.item(i).getNodeValue()));
                        } else {
                          log(
                              "Multiple content for "
                                  + registration.getAttribute("name")
                                  + " in "
                                  + layer,
                              Project.MSG_WARN);
                          continue JAVAHELP;
                        }
                      }
                    }
                    if (input == null) {
                      log(
                          "No content for " + registration.getAttribute("name") + " in " + layer,
                          Project.MSG_WARN);
                    }
                  }
                  Document doc2;
                  try {
                    doc2 = XMLUtil.parse(input, false, false, null, NO_DTDS);
                  } catch (SAXException x) {
                    log(
                        "Could not parse " + registration.getAttribute("name") + " in " + layer,
                        x,
                        Project.MSG_WARN);
                    continue;
                  }
                  URI helpsetref = URI.create(doc2.getDocumentElement().getAttribute("url"));
                  if ("nbdocs".equals(helpsetref.getScheme())
                      && helpsetref.getAuthority() == null) {
                    try {
                      helpsetref =
                          new URI(
                              helpsetref.getScheme(),
                              cnb,
                              helpsetref.getPath(),
                              helpsetref.getQuery(),
                              helpsetref.getFragment());
                    } catch (URISyntaxException x) {
                      throw new BuildException(x);
                    }
                  }
                  log("checking: " + helpsetref, Project.MSG_INFO);
                  checkHelpSetURL(
                      CheckLinks.toURL(helpsetref), globalClassLoader, l, classLoaderMap, cnb);
                }
              }
            }
          }
        }
      } catch (IOException x) {
        throw new BuildException(x);
      } finally {
        NbDocsStreamHandler.NbDocsURLConnection.globalClassLoader.set(null);
        NbDocsStreamHandler.NbDocsURLConnection.classLoaderMap.set(null);
        CheckLinks.handlerFactory.set(null);
      }
    }
  }
 public Document getDocument() throws IOException, SAXException {
   return XMLUtil.parse(
       AVMNodeConverter.ToAVMVersionPath(nodeRef).getFirst(),
       AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond(),
       this.getServiceRegistry().getAVMService());
 }
Example #4
0
  public void testOutputPathPatternForFormInstanceData() throws Exception {
    class OutputPathPatternTest {
      public final String expected;
      public final String pattern;
      public final Document xml;
      public final String name;
      public final String parentAVMPath;
      public final String webapp;

      public OutputPathPatternTest(
          final String expected,
          final String pattern,
          final Document xml,
          final String name,
          final String parentAVMPath,
          final String webapp) {
        this.expected = expected;
        this.pattern = pattern;
        this.xml = xml;
        this.name = name;
        this.parentAVMPath = parentAVMPath;
        this.webapp = webapp;
      }
    }

    final OutputPathPatternTest[] opps =
        new OutputPathPatternTest[] {
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/foo.xml",
              "${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/foo.xml",
              "/${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/foo.xml",
              "/${webapp}/${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/foo.xml",
              "/${webapp}/${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/another_webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir1/dir2/foo.xml",
              "/${webapp}/${cwd}/${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/another_webapp/dir1/dir2",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/"
                  + Calendar.getInstance().get(Calendar.YEAR)
                  + "_foo.xml",
              "${date?string('yyyy')}_${name}.xml",
              XMLUtil.parse("<foo/>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/foo.xml",
              "${xml.root_tag.name}.xml",
              XMLUtil.parse("<root_tag><name>foo</name></root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/07.xml",
              "${xml.root_tag.date?date('yyyy-MM-dd')?string('MM')}.xml",
              XMLUtil.parse("<root_tag><date>1776-07-04</date></root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/foo.xml",
              "${xml['foons:root_tag/foons:name']}.xml",
              XMLUtil.parse(
                  "<foons:root_tag xmlns:foons='bar'><foons:name>foo</foons:name></foons:root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/foo.xml",
              "${xml[\"/*[name()='foons:root_tag']/*[name()='foons:name']\"]}.xml",
              XMLUtil.parse(
                  "<foons:root_tag xmlns:foons='bar'><foons:name>foo</foons:name></foons:root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              "avmstore:/www/avm_webapps/webapp/dir/foo.xml",
              "${xml['/foons:root_tag/foons:name']}.xml",
              XMLUtil.parse(
                  "<foons:root_tag xmlns:foons='bar'><foons:name>foo</foons:name></foons:root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp"),
          new OutputPathPatternTest(
              null,
              "${xml.root_tag.name}",
              XMLUtil.parse(
                  "<foons:root_tag xmlns:foons='bar'><foons:name>foo</foons:name></foons:root_tag>"),
              "foo",
              "avmstore:/www/avm_webapps/webapp/dir",
              "webapp")
        };
    for (final OutputPathPatternTest oppt : opps) {
      this.mockForm.setOutputPathPattern(oppt.pattern);
      if (oppt.expected == null) {
        try {
          this.mockForm.getOutputPathForFormInstanceData(
              oppt.xml, oppt.name, oppt.parentAVMPath, oppt.webapp);
          fail("expected pattern " + oppt.pattern + " to fail");
        } catch (Exception e) {
          // expected failure
        }
      } else {
        assertEquals(
            oppt.pattern + " failed",
            oppt.expected,
            this.mockForm.getOutputPathForFormInstanceData(
                oppt.xml, oppt.name, oppt.parentAVMPath, oppt.webapp));
      }
    }
  }