//
  // Find all the java.sql interfaces implemented by a class and find
  // the methods in those interfaces which raise
  // SQLFeatureNotSupportedException when called on the passed-in candidate object.
  //
  private void vetInterfaces(
      Object candidate,
      Class myClass,
      HashSet<String> unsupportedList,
      HashSet<String> notUnderstoodList)
      throws Exception {
    Class superClass = myClass.getSuperclass();

    if (superClass != null) {
      vetInterfaces(candidate, superClass, unsupportedList, notUnderstoodList);
    }

    //
    // The contract for Class.getInterfaces() states that the interfaces
    // come back in a deterministic order, namely, in the order that
    // they were declared in the "extends" clause.
    //
    Class<?>[] interfaces = myClass.getInterfaces();
    int interfaceCount = interfaces.length;

    for (int i = 0; i < interfaceCount; i++) {
      Class<?> iface = interfaces[i];

      if (iface.getPackage().getName().equals(SQL_PACKAGE_NAME)) {
        vetInterfaceMethods(candidate, iface, unsupportedList, notUnderstoodList);
      }

      vetInterfaces(candidate, iface, unsupportedList, notUnderstoodList);
    }
  }
 Runtime(
     boolean hasFastStructs,
     boolean hasJNA,
     boolean hasBitFields,
     Class<?> callbackClass,
     Class<?> pointerClass,
     Class<?> memoryClass,
     Class<?> structClass,
     Class<?> unionClass,
     Class<?> structIOClass,
     Class<?> arrayClass,
     Class<?> libraryClass,
     Class<? extends Annotation> someAnnotationClass,
     String runtimeFilesListFileName) {
   this.hasFastStructs = hasFastStructs;
   this.hasBitFields = hasBitFields;
   this.hasJNA = hasJNA;
   this.callbackClass = callbackClass;
   this.pointerClass = pointerClass;
   this.memoryClass = memoryClass;
   this.structClass = structClass;
   this.libraryClass = libraryClass;
   this.unionClass = unionClass;
   this.structIOClass = structIOClass;
   this.arrayClass = arrayClass;
   this.runtimeFilesListFileName = runtimeFilesListFileName;
   annotationPackage =
       someAnnotationClass == null ? null : someAnnotationClass.getPackage().getName();
 }
  /**
   * Method updates existing Spring bean definitions in a XML application context file. Bean
   * definition is identified by its type defining class.
   *
   * @param project
   * @param type
   * @param jaxbElement
   */
  public void updateBeanDefinitions(
      File configFile, Project project, Class<?> type, Object jaxbElement) {
    Source xsltSource;
    Source xmlSource;
    try {
      xsltSource =
          new StreamSource(
              new ClassPathResource("transform/update-bean-type.xsl").getInputStream());
      xsltSource.setSystemId("update-bean");

      List<File> configFiles = new ArrayList<>();
      configFiles.add(configFile);
      configFiles.addAll(getConfigImports(configFile, project));

      LSParser parser = XMLUtils.createLSParser();
      GetSpringBeansFilter getBeanFilter = new GetSpringBeansFilter(type, null);
      parser.setFilter(getBeanFilter);

      for (File file : configFiles) {
        parser.parseURI(file.toURI().toString());
        if (!CollectionUtils.isEmpty(getBeanFilter.getBeanDefinitions())) {
          xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(file)));

          String beanElement = type.getAnnotation(XmlRootElement.class).name();
          String beanNamespace = type.getPackage().getAnnotation(XmlSchema.class).namespace();

          // create transformer
          Transformer transformer = transformerFactory.newTransformer(xsltSource);
          transformer.setParameter("bean_element", beanElement);
          transformer.setParameter("bean_namespace", beanNamespace);
          transformer.setParameter(
              "bean_content",
              getXmlContent(jaxbElement)
                  .replaceAll("(?m)^(\\s<)", getTabs(1, project.getSettings().getTabSize()) + "$1")
                  .replaceAll("(?m)^(</)", getTabs(1, project.getSettings().getTabSize()) + "$1"));

          // transform
          StringResult result = new StringResult();
          transformer.transform(xmlSource, result);
          FileUtils.writeToFile(
              format(result.toString(), project.getSettings().getTabSize()), file);
          return;
        }
      }
    } catch (IOException e) {
      throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e);
    } catch (TransformerException e) {
      throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e);
    }
  }
 public String getVersion(Class<?> api) {
   log.trace("getVersion for {}", api);
   Package pkg = api.getPackage();
   log.trace("    -> {}/{}", pkg.getImplementationVersion(), pkg.getSpecificationVersion());
   String version = pkg.getSpecificationVersion();
   if (version == null) version = pkg.getImplementationVersion();
   if (version == null) {
     try {
       version = readVersionFromManifest(api);
     } catch (IOException e) {
       log.error("Could not extract version for " + api, e);
       return null;
     }
   }
   return version;
 }
  protected static void convertUnsupportedToAsciidocTable(
      Properties props, List<Class<?>> clazzes, String title)
      throws ParserConfigurationException, TransformerException {
    List<String[]> rows = new ArrayList<>(clazzes.size() + 1);
    rows.add(new String[] {"Package", "Class"}); // add column titles first
    for (Class<?> clazz : clazzes)
      rows.add(new String[] {clazz.getPackage().getName(), clazz.getSimpleName()});

    String tmp =
        createAsciidocTable(rows, title, "[align=\"left\",width=\"50%\",options=\"header\"]");

    // do we have more than one property (superclass Protocol has only one property (stats))
    if (clazzes.size() > 1) {
      props.put(title, tmp);
    }
  }
Beispiel #6
0
  public void testString() throws Exception {
    Subclasser sub = new Subclasser();
    Class clazz = this.getClass();
    String packageName = clazz.getPackage().getName();
    String className = clazz.getName();

    // NB, this will all break if you change the package structure :)
    // pretty unlikely, but just in case it starts to fail, keep it in mind
    String expectedName = "P6TestSubclasser";
    assertEquals(expectedName, sub.baseName(className));

    // this one's a little trickier... since it could fail
    // depending on your architecture.  So put in this terrible
    // switchlike hack here
    String expectedPath = null;

    if (sub.DELIMITER.equals("/")) {
      expectedPath = "com/p6spy/engine/test";
    } else if (sub.DELIMITER.equals("\\")) {
      expectedPath = "com\\p6spy\\engine\\test";
    } else if (sub.DELIMITER.equals(":")) {
      expectedPath = "com:p6spy:engine:test";
    }

    if (expectedPath == null) {
      fail(
          "Unexpected file separator: "
              + sub.DELIMITER
              + ". Please expand the test class to test for this file separator.");
    }

    assertEquals(expectedPath, sub.packToDir(packageName));

    // now check the default file
    String newName = "ThisIsATestClass";

    sub.setOutputPackage(packageName);
    sub.setOutputName(newName);

    File actualFile = sub.getOutputFile();
    File expectedFile = new File("scratch" + sub.DELIMITER + expectedPath, newName + ".java");

    assertEquals(expectedFile, actualFile);
  }
  /**
   * Method removes all Spring bean definitions of given type from the XML application context file.
   *
   * @param project
   * @param type
   */
  public void removeBeanDefinitions(File configFile, Project project, Class<?> type) {
    Source xsltSource;
    Source xmlSource;
    try {
      xsltSource =
          new StreamSource(
              new ClassPathResource("transform/delete-bean-type.xsl").getInputStream());
      xsltSource.setSystemId("delete-bean");

      List<File> configFiles = new ArrayList<>();
      configFiles.add(configFile);
      configFiles.addAll(getConfigImports(configFile, project));

      for (File file : configFiles) {
        xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(configFile)));

        String beanElement = type.getAnnotation(XmlRootElement.class).name();
        String beanNamespace = type.getPackage().getAnnotation(XmlSchema.class).namespace();

        // create transformer
        Transformer transformer = transformerFactory.newTransformer(xsltSource);
        transformer.setParameter("bean_element", beanElement);
        transformer.setParameter("bean_namespace", beanNamespace);

        // transform
        StringResult result = new StringResult();
        transformer.transform(xmlSource, result);
        FileUtils.writeToFile(format(result.toString(), project.getSettings().getTabSize()), file);
        return;
      }
    } catch (IOException e) {
      throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e);
    } catch (TransformerException e) {
      throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e);
    }
  }