/**
   * Determine imports for the given bundle. Based on the user settings, this method will consider
   * only the the test hierarchy until the testing framework is found or all classes available
   * inside the test bundle.
   *
   * <p>Note that split packages are not supported.
   *
   * @return
   */
  private String[] determineImports() {

    boolean useTestClassOnly = false;

    // no jar entry present, bail out.
    if (jarEntries == null || jarEntries.isEmpty()) {
      logger.debug("No test jar content detected, generating bundle imports from the test class");
      useTestClassOnly = true;
    } else if (createManifestOnlyFromTestClass()) {
      logger.info("Using the test class for generating bundle imports");
      useTestClassOnly = true;
    } else logger.info("Using all classes in the jar for the generation of bundle imports");

    // className, class resource
    Map entries;

    if (useTestClassOnly) {

      entries = new LinkedHashMap(4);

      // get current class (test class that bootstraps the OSGi infrastructure)
      Class<?> clazz = getClass();
      String clazzPackage = null;
      String endPackage = AbstractOnTheFlyBundleCreatorTests.class.getPackage().getName();

      do {

        // consider inner classes as well
        List classes = new ArrayList(4);
        classes.add(clazz);
        CollectionUtils.mergeArrayIntoCollection(clazz.getDeclaredClasses(), classes);

        for (Iterator iterator = classes.iterator(); iterator.hasNext(); ) {
          Class<?> classToInspect = (Class) iterator.next();

          Package pkg = classToInspect.getPackage();
          if (pkg != null) {
            clazzPackage = pkg.getName();
            String classFile = ClassUtils.getClassFileName(classToInspect);
            entries.put(
                classToInspect.getName().replace('.', '/').concat(ClassUtils.CLASS_FILE_SUFFIX),
                new InputStreamResource(classToInspect.getResourceAsStream(classFile)));
          }
          // handle default package
          else {
            logger.warn("Could not find package for class " + classToInspect + "; ignoring...");
          }
        }

        clazz = clazz.getSuperclass();

      } while (!endPackage.equals(clazzPackage));
    } else entries = jarEntries;

    return determineImportsFor(entries);
  }
  @Test
  public void testMergeArrayIntoCollection() {
    Object[] arr = new Object[] {"value1", "value2"};
    List<Comparable<?>> list = new LinkedList<>();
    list.add("value3");

    CollectionUtils.mergeArrayIntoCollection(arr, list);
    assertEquals("value3", list.get(0));
    assertEquals("value1", list.get(1));
    assertEquals("value2", list.get(2));
  }
  @Test
  public void testMergePrimitiveArrayIntoCollection() {
    int[] arr = new int[] {1, 2};
    List<Comparable<?>> list = new LinkedList<>();
    list.add(new Integer(3));

    CollectionUtils.mergeArrayIntoCollection(arr, list);
    assertEquals(new Integer(3), list.get(0));
    assertEquals(new Integer(1), list.get(1));
    assertEquals(new Integer(2), list.get(2));
  }
  protected String[] getTestFrameworkBundlesNames() {
    String[] def = super.getTestFrameworkBundlesNames();
    List col = new ArrayList();
    CollectionUtils.mergeArrayIntoCollection(def, col);

    System.setProperty("DEBUG", "false");
    // set this property (to whatever value) to get logging in Jetty
    // System.setProperty("VERBOSE", "false");

    // Servlet/JSP artifacts
    col.add("javax.servlet, com.springsource.javax.servlet, 2.4.0");
    col.add("org.springframework.osgi, jsp-api.osgi, 2.0-SNAPSHOT");

    // JSP compiler
    col.add("org.springframework.osgi, jasper.osgi, 5.5.23-SNAPSHOT");
    col.add("org.springframework.osgi, commons-el.osgi, 1.0-SNAPSHOT");

    // standard tag library
    col.add("org.springframework.osgi, jstl.osgi, 1.1.2-SNAPSHOT");

    // add MX4J for 1.4
    // if < jdk 1.5, add an JMX implementation
    if (!JdkVersion.isAtLeastJava15())
      col.add("net.sourceforge.mx4j, com.springsource.mx4j, 3.0.2");

    col.add("org.springframework.osgi, catalina.osgi, 5.5.23-SNAPSHOT");
    col.add("org.springframework.osgi, catalina.start.osgi, 1.0.0");

    // jetty starter
    //		col.add("org.springframework.osgi, jetty.start.osgi, 1.0.0");
    //		col.add("org.springframework.osgi, jetty.web.extender.fragment.osgi, 1.0.0");
    //		col.add("org.mortbay.jetty, jetty-util, 6.1.9");
    //		col.add("org.mortbay.jetty, jetty, 6.1.9");

    // Spring DM web extender
    col.add("org.springframework.osgi, spring-osgi-web," + getSpringDMVersion());
    col.add("org.springframework.osgi, spring-osgi-web-extender," + getSpringDMVersion());
    col.add("net.sourceforge.cglib, com.springsource.net.sf.cglib, 2.1.3");

    return (String[]) col.toArray(new String[col.size()]);
  }
Exemple #5
0
  /**
   * Copies the given resources using the given parameters.
   *
   * @param preserveReplication preserveReplication
   * @param preserveBlockSize preserveBlockSize
   * @param preserveUser preserveUser
   * @param preserveGroup preserveGroup
   * @param preservePermission preservePermission
   * @param ignoreFailures ignoreFailures
   * @param skipCrc skipCrc
   * @param logDir logDir
   * @param mappers mappers
   * @param overwrite overwrite
   * @param update update
   * @param delete delete
   * @param fileLimit fileLimit
   * @param sizeLimit sizeLimit
   * @param fileList fileList
   * @param uris uris
   */
  public void copy(
      Boolean preserveReplication,
      Boolean preserveBlockSize,
      Boolean preserveUser,
      Boolean preserveGroup,
      Boolean preservePermission,
      Boolean ignoreFailures,
      Boolean skipCrc,
      String logDir,
      Integer mappers,
      Boolean overwrite,
      Boolean update,
      Boolean delete,
      Long fileLimit,
      Long sizeLimit,
      String fileList,
      String... uris) {

    List<String> args = new ArrayList<String>();

    args.add(
        Preserve.toString(
            preserveReplication,
            preserveBlockSize,
            preserveUser,
            preserveGroup,
            preservePermission));

    if (Boolean.TRUE.equals(ignoreFailures)) {
      args.add("-i");
    }
    if (Boolean.TRUE.equals(skipCrc)) {
      args.add("-skipcrccheck");
    }
    if (logDir != null) {
      args.add("-log " + logDir);
    }
    if (mappers != null) {
      args.add("-m " + mappers.intValue());
    }
    if (Boolean.TRUE.equals(overwrite)) {
      args.add("-overwrite");
    }
    if (Boolean.TRUE.equals(update)) {
      args.add("-update");
    }
    if (Boolean.TRUE.equals(delete)) {
      args.add("-delete");
    }
    if (fileLimit != null) {
      log.warn("Hadoop DistCp v2 will ignore fileLimit argument");
      args.add("-filelimit " + fileLimit);
    }
    if (sizeLimit != null) {
      log.warn("Hadoop DistCp v2 will ignore sizeLimit argument");
      args.add("-sizelimit " + sizeLimit);
    }
    if (StringUtils.hasText(fileList)) {
      args.add("-f " + fileList);
    }

    CollectionUtils.mergeArrayIntoCollection(uris, args);
    copy(args.toArray(new String[args.size()]));
  }