[forge-issues] [JBoss JIRA] (ROASTER-12) Shade the JDT dependencies into Roaster-JDT

Walter Medvedeo (JIRA) issues at jboss.org
Tue May 6 12:33:57 EDT 2014


    [ https://issues.jboss.org/browse/ROASTER-12?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12965897#comment-12965897 ] 

Walter Medvedeo commented on ROASTER-12:
----------------------------------------

The following scenario can give more information to the issue:

When the Roaster library is used form an external project we have this first situation:

1) The shade is shading the following line of code at the class "org.jboss.forge.roaster.model.util.Formatter"

    Properties options = readConfig("org.jboss.forge.roaster._shade.org.eclipse.jdt.core.prefs");   <-- Preferencies file invocation was renamed.

    so when the Formatter is running we have a NPE because the preferencies file "org.eclipes.jdt.core.prefs" was not renamed by the shade.

    Ok, this is not a problem. I've managed the shade configuration in order the keep the line untouched
  
    Properties options = readConfig("org.eclipse.jdt.core.prefs");

    and as expected the NPE disappeared. But when I modify a class using the api, etc., the format is not applied.

2) So then I decompiled the following eclipse shaded class that has the formatting constants defintions:

    "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants"

    And we have somethinig like this:

        public static final String FORMATTER_ALIGN_TYPE_MEMBERS_ON_COLUMNS = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.align_type_members_on_columns";
  public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression";
  public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ENUM_CONSTANT = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant";
  public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ANNOTATION = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation";
  public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call";
  public static final String FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION = "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation";

    
     The shade is basically changing also the value for the defined constants in the Eclipse class. So in runtime, the formatter
     is looking for properties in the form "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation".

     So I believe that we need to:

     2.1) try to configure the shade to not change the constants definitions in Eclipse's DefaultCodeFormatterConstants class.
       (but I guess it's not possible)

     2.2) try to configure the shade in order to rename the properties in "org.eclipse.jdt.core.prefs" automatically and set the shade prefix.
        For this second option I've done several tests but it seems like property names in the file "org.eclipse.jdt.core.prefs" are not renamed by the
        shade plugin.

     2.3) Rename the properties in "org.eclipse.jdt.core.prefs" manually and set the shade prefix.

     2.4) whatever other better option ¿?


So to continue my tests I've basically used option 3) and made a small change in the shade configuration in order to fix 1), and then I've had the following results.

1) External projects that uses Roaster as a third party library works well.

2) But Roaster tests that uses the Formatter don't works. It seems like when a test (e.g. FormatterTest.java ) is being runned with maven the classes that runs are the eclipse original classes, and not the shaded classes. And the original Eclipse classes still have the original property names e.g.
    "org.eclipse.jdt.core.formatter.align_type_members_on_columns".
 
But when a client project uses the Formatter, the Eclipse classes that runs are the shaded ones, and in this cases the formatting constants are in the form
    
    "org.jboss.forge.roaster._shade.org.eclipse.jdt.core.formatter.align_type_members_on_columns";

It seems like we need "two versions" of the property file, one for maven tests, and another version that should be used when Roaster is being used in "client" mode. Or configure the pom.xml/shade in order that the two different invocation scenarios works.

> Shade the JDT dependencies into Roaster-JDT
> -------------------------------------------
>
>                 Key: ROASTER-12
>                 URL: https://issues.jboss.org/browse/ROASTER-12
>             Project: Roaster
>          Issue Type: Feature Request
>          Components: JDT
>    Affects Versions: 2.3.0.Final
>            Reporter: George Gastaldi
>            Assignee: Lincoln Baxter III
>             Fix For: 2.3.1.Final
>
>
> The current JDT version used conflicts with ECJ in Drools. We should shade the JDT classes since we don't expect people to use them directly with Roaster.



--
This message was sent by Atlassian JIRA
(v6.2.3#6260)



More information about the forge-issues mailing list