Project

General

Profile

Feature #9442

implement limited support for RCODE-INFORMATION

Added by Greg Shah over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Delia Mitric
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

History

#1 Updated by Greg Shah over 1 year ago

There are 2 patterns used that should be supported.

Both start with an assignment of RCODE-INFORMATION:FILENAME to some program name or class name.

Then they use:

  • RCODE-INFORMATION:DB-REFERENCES which we could easily add as an annotation during conversion. It appears to be a list of databases in use for that program. The code that uses this checks that the database is connected (at runtime).
  • RCODE-INFORMATION:MD5-VALUE which is used as described in #9439 (see that task for implementation ideas)

#2 Updated by Constantin Asofiei over 1 year ago

Greg Shah wrote:

Both start with an assignment of RCODE-INFORMATION:FILENAME to some program name or class name.

This is already supported.

  • RCODE-INFORMATION:DB-REFERENCES which we could easily add as an annotation during conversion. It appears to be a list of databases in use for that program. The code that uses this checks that the database is connected (at runtime).

This is already supported.

  • RCODE-INFORMATION:MD5-VALUE which is used as described in #9439 (see that task for implementation ideas)

This needs to be added.

#3 Updated by Alexandru Lungu over 1 year ago

  • Assignee set to Delia Mitric

#4 Updated by Delia Mitric over 1 year ago

  • Status changed from New to WIP

#5 Updated by Delia Mitric over 1 year ago

  • % Done changed from 0 to 20

In 4GL RCODE-INFO:MD5-VALUE returns ? if the GENERATE-MD5 option isn't used for COMPILE statement. Because in FWD the COMPILE statement is unimplemented and we don't have access to the original .r files, there is the question of how to know that MD5 value was stored for the file we're working on?
For the start, I've considered that for every procedure the option GENERATE-MD5 was used.

I'm working on RcodeInfoOps.java class.
Because the MD5 value has to be calculated by using the compiled file, I have to find the absolute path to the specific compiled file .class that was put in build directory.
I've tried to build the relative path from RcodeInfoPath.java class where I have some information about the package structure, but I am struggling with some problems. It doesn't work to read the file content using the relative path.
Is there any easy way to find the absolute path of a compiled class using the relative path or how should I proceed?

#6 Updated by Constantin Asofiei over 1 year ago

The class needs to be read from the .jar. Look into ThinClient.loadWindowIcon, how that works, I assume something similar can be used to get a stream for the .class file.

See RcodeInfoOps.initFileInfo, this resolves the qualified Java class name, and the Class file.

Keep in mind that we don't want this attribute to be calculated always - only first time the MD5-VALUE is read.

#7 Updated by Delia Mitric over 1 year ago

Constantin Asofiei wrote:

The class needs to be read from the .jar. Look into ThinClient.loadWindowIcon, how that works, I assume something similar can be used to get a stream for the .class file.

I don't understand how this method loadWindowIcon from ThinClient applies to my problem. Is there a specific method I should use? I only need the absolute path to the root of the project. From there, I'm able to build the absolute path to the .class file which is in the build/lib or deploy/lib. And I also need the name of the .jar file.

#8 Updated by Constantin Asofiei over 1 year ago

Please try this example:

      String file = "com/goldencode/p2j/testcases/Test1.class";
      URL url = MultiClassLoader.getClassLoader().getResource(file);
      InputStream s = url.openStream();

#9 Updated by Delia Mitric over 1 year ago

I got it and it works. Thank you!

Committed my solution to 9442a revision 15653 and 15654.

#10 Updated by Delia Mitric over 1 year ago

  • % Done changed from 20 to 50
  • Status changed from WIP to Review

#11 Updated by Constantin Asofiei over 1 year ago

Review of 9442a rev 15654:
  • please update the copyright year in the changed files, i.e. 2017-2025
  • do not set the history number if is not set, that was from a branch which was promoted to trunk at some time. Otherwise, we do fix history numbers if they are out-of-order
  • why is getMD5Val returning BaseDataType? This is The return value is a 32 character hexadecimal number., to quote from the docs. If you want to return an unknown value, use new character().
  • the @return needs to have the first javadoc text on the same line
  • hexazecimal needs to be hexadecimal
  • intermediate comments need to use // and not the /**/
  • when reading from jar files, you need to use UNIX-style '/' separator - using File.separator it may not work on Windows
  • there is a TODO in the catch (Exception e) of resolveMd5Value - at the least, please add WARNING logging of the exception
  • getMD5Val() needs to compute md5Value on the first read:
    • initialize it to null in initFileInfo
    • if is null, call resolveMd5Value
  • look for kw_md5_val in gaps/expressions.rules and change rw.rt_lvl_stub to rw.rt_lvl_full_restr - add a comment that the MD5 value is computed from the .class file, and not the .r file
  • I don't recall exactly the cases where FWD emits (anon) inner classes in the converted code, but these need to be included in the MD5 value, too:
    • find the folder where the main .class file is located
    • look in the folder for files which have the main class package + simple name + dollar sign as prefix, like com/goldencode/testcases/Test1$1.class - i.e. the <simpleName>$ is a prefix of that file name.

#12 Updated by Constantin Asofiei over 1 year ago

Addendum: kw_md5_val needs to be registered in SignatureHelper, too.

#13 Updated by Delia Mitric over 1 year ago

  • Status changed from Review to WIP

#14 Updated by Delia Mitric over 1 year ago

Constantin Asofiei wrote:

Addendum: kw_md5_val needs to be registered in SignatureHelper, too.

It is necessary to add it if it represents an attribute?

#15 Updated by Constantin Asofiei over 1 year ago

Delia Mitric wrote:

Constantin Asofiei wrote:

Addendum: kw_md5_val needs to be registered in SignatureHelper, too.

It is necessary to add it if it represents an attribute?

You are right, that's an attribute, not a method. So is not needed to be added.

#16 Updated by Delia Mitric over 1 year ago

  • % Done changed from 50 to 100

Committed to 9442a revision 15655

#17 Updated by Delia Mitric over 1 year ago

  • Status changed from WIP to Review

#18 Updated by Greg Shah over 1 year ago

  • reviewer Constantin Asofiei added

#19 Updated by Constantin Asofiei over 1 year ago

Review of 9442a/15655:
  • expressions.rules needs a history entry and the copyright year change
  • instead of LOG.warning(e.getMessage());, log both a message, the file and a full stacktrace, like this (untested):
    if (LOG.isLoggable(Level.WARNING)
    {
       LOG.warning("Error while trying to calculate the MD5-VALUE for file " + url, e);
    }
    
  • in wa.info.fileName != null && wa.info.md5Value == null test, instead of wa.info.fileName != null you need to have wa.info != null && wa.info.initialized.

Otherwise, did you test resolveMd5Value with a .class having an inner class?

#20 Updated by Greg Shah over 1 year ago

  • Status changed from Review to Internal Test

Code Review 9442a Revisions 15653 through 15655

This is good work. Some minor requests:

1. Please add a history entry to gaps/expressions.rules.

2. Please add javadoc to the RcodeInfoOps.getMD5Val() that explains that "By design, the calculated MD5 hash is not compatible with that calculated by OpenEdge because in OE the hash is calculated from r-code and in FWD the hash is calculated from the converted .class file.".

#21 Updated by Delia Mitric over 1 year ago

Constantin Asofiei wrote:

Otherwise, did you test resolveMd5Value with a .class having an inner class?

About this, I found at https://docs.progress.com/bundle/openedge-oo-abl-develop-applications-117/page/Class-definition-files-and-object-type-names.html that in 4GL we cannot have a class defined into another class. The problem is I didn't find any specific example for it, but I've tested it with a bit of an unorthodox method:
I added a procedure with a specific name (say test.p).
I manually added another procedure with the name prefixed by the name of the main procedure. I've done this to "mimic" an inner class and to see if the program takes it into account for calculating the md5 value.

#22 Updated by Constantin Asofiei over 1 year ago

Delia Mitric wrote:

Constantin Asofiei wrote:

Otherwise, did you test resolveMd5Value with a .class having an inner class?

About this, I found at https://docs.progress.com/bundle/openedge-oo-abl-develop-applications-117/page/Class-definition-files-and-object-type-names.html that in 4GL we cannot have a class defined into another class.

Yes, but FWD emits I think only a kind of triggers as inner classes, at this time.

The problem is I didn't find any specific example for it, but I've tested it with a bit of an unorthodox method:
I added a procedure with a specific name (say test.p).
I manually added another procedure with the name prefixed by the name of the main procedure. I've done this to "mimic" an inner class and to see if the program takes it into account for calculating the md5 value.

You meant you changed the Test.java file to have an inner class? That is a good way to check the code if it picks up the inner class or not.

#23 Updated by Delia Mitric over 1 year ago

Constantin Asofiei wrote:

You meant you changed the Test.java file to have an inner class? That is a good way to check the code if it picks up the inner class or not.

Using this test I found that compiled inner classes don't have a different path from that of main .class file. The "inner" compiled classes contents are just included in the main compiled file. This seems to be a pattern in FWD.
I don't think that it makes sense to treat them separately unless you found an example where inner classes are compiled in a separate file.

#24 Updated by Constantin Asofiei over 1 year ago

For this example:

package testing;

public class InnerTest
{
   public static void main(String[] args)
   {
      Runnable anon = new Runnable()
      {
         @Override
         public void run()
         {
         }
      };

      anon.run();
   }

   public static class OtherClass
   {

   }
}

Java 8 compiles these files:
-rw-rw---- 1 ca ca 543 Jan 30 09:35 'InnerTest$1.class'
-rw-rw---- 1 ca ca 357 Jan 30 09:35 'InnerTest$OtherClass.class'
-rw-rw---- 1 ca ca 667 Jan 30 09:35  InnerTest.class

#25 Updated by Delia Mitric over 1 year ago

Constantin Asofiei wrote:

For this example:
[...]
Java 8 compiles these files:
[...]

Yes, I know this is possible in Java, but in FWD it seems inner classes are not compiled this way.

#26 Updated by Constantin Asofiei over 1 year ago

Delia Mitric wrote:

Constantin Asofiei wrote:

For this example:
[...]
Java 8 compiles these files:
[...]

Yes, I know this is possible in Java, but in FWD it seems inner classes are not compiled this way.

I'm talking about what is possible in Java, to cover any case where FWD will emit in the converted Java file an inner Java class. See this example:

def var p1 as char.

on write of book do:
  message p1.
end.

#27 Updated by Delia Mitric over 1 year ago

Committed to 9442a revision 15656.

Tested with inner classes.

#28 Updated by Constantin Asofiei over 1 year ago

Delia Mitric wrote:

Committed to 9442a revision 15656.

The changes are OK, thank you.

#29 Updated by Constantin Asofiei over 1 year ago

  • Status changed from Internal Test to Merge Pending

9442a can be merged after 9355a.

#30 Updated by Alexandru Lungu over 1 year ago

Preparing to merge now.

#31 Updated by Alexandru Lungu over 1 year ago

  • Status changed from Merge Pending to Test

Branch 9442a was merged to trunk rev 15681 and archived.

#32 Updated by Greg Shah about 1 year ago

  • Status changed from Test to Closed

Also available in: Atom PDF