7 Replies Latest reply on Dec 15, 2009 11:51 AM by alrubinger

    SHRINKWRAP-106: Inner Classes

    alrubinger

      @see https://jira.jboss.org/jira/browse/SHRINKWRAP-106

      What should be the expected behaviour? Add a class and its inner classes get thrown in too? Some user option?

      The issue is one of visibility; clients of ShrinkWrap may not be able to see all inner classes that must be added to the archive, though they'll be required at runtime. Though this problem is not unique to inner classes, it's any class. So the fallback is to addResource or similar.

      S,
      ALR

        • 1. Re: SHRINKWRAP-106: Inner Classes
          alrubinger

          Another workaround to the visibility problem is to "addPackage".

          • 2. Re: SHRINKWRAP-106: Inner Classes
            dan.j.allen

            Just to throw some suggestions out there:

            1. Is it possible to do addClasses(TopLevelClass.class, TopLevelClass.InnerClass.class) ?

            2. How about a type that could represent a star import for class and it's decendants: addClasses(new ClassAndDependentsLiteral() {});

            • 3. Re: SHRINKWRAP-106: Inner Classes
              dan.j.allen

              My generics code cut off:

              addClasses(new ClassAndDependentsLiteral<TopLevelClass>() {});


              • 4. Re: SHRINKWRAP-106: Inner Classes
                alrubinger

                 

                "dan.j.allen" wrote:
                1. Is it possible to do addClasses(TopLevelClass.class, TopLevelClass.InnerClass.class) ?


                Yup, but if InnerClass is private or otherwise isn't visible to the calling code...then... :)

                "dan.j.allen" wrote:
                2. How about a type that could represent a star import for class and it's decendants:
                addClasses(new ClassAndDependentsLiteral<TopLevelClass>() {});


                We could to a star import for class and all *parents*. Feel free to open a JIRA enhancement request for that one. But of course the generics wouldn't matter to the runtime as they'd be lost after compilation.

                Maybe like:

                addClassAndParents(Class<?> clazz)


                ?

                S,
                ALR

                • 5. Re: SHRINKWRAP-106: Inner Classes
                  alrubinger

                   

                  "@maxandersen" wrote:
                  @ALRubinger inner classes should Per definition be included when its owning class is added


                  S,
                  ALR

                  • 6. Re: SHRINKWRAP-106: Inner Classes
                    aslak

                    addPackage with filters should work for the Inner class problem.

                     

                    {code}

                         addClass(Class<?> clazz)

                         {

                              Asset resource = new ClassAsset(clazz);
                              Path location = new BasicPath(getClassesPath(), AssetUtil.getFullPathForClassResource(clazz));
                              add(resource, location);
                              addPackage(clazz.getPackage(), Filters.include(clazz.getSimpleName() + "$.*"));
                    

                         }

                    {code}

                     

                     

                    • 7. Re: SHRINKWRAP-106: Inner Classes
                      alrubinger

                      We'll ignore hierarchy, as this goes outside the expected domain.  Probably a user won't be anticipating adding any classes (inner) of parents when they add a child.  So the logic is now:

                       

                      // Get all inner classes and add them
                      final Class<?>[] innerClasses = clazz.getDeclaredClasses();
                      for (final Class<?> innerClass : innerClasses)
                      {
                        this.addClass(innerClass);
                      }
                      

                       

                      S,

                      ALR