Project

General

Profile

autoconvert.trunk.15308.patch

Marian Edu, 06/26/2024 06:53 AM

Download (11.7 KB)

View differences:

new/src/com/goldencode/p2j/cfg/Configuration.java 2024-06-07 10:29:14 +0000
85 85
**     ECF 20230127          Added mutable schema configuration option.
86 86
** 024 VVT 20230318          Constant added: default legacy unit test framework type. See #6237.
87 87
** 025 GBB 20230512          Logging methods replaced by CentralLogger/ConversionStatus.
88
** 026 ME  20240604          Added support for automatic dependency conversion when file list is used. 
88 89
*/
89 90

  
90 91
/*
......
353 354
   /** The loaded schema configuration. */
354 355
   private SchemaConfig schemaConfig = null;
355 356
   
357
   /** The list of conversion dependencies listeners */
358
   private static Set<Consumer<String>> conversionDepsListeners;
359
   
356 360
   /**
357 361
    * Holds a set of configuration parameter names whose values are OS dependent. These are
358 362
    * related to the system we run now, and are invisible for original P4GL code.
......
1402 1406
      loadConfigProfiles(profiles);
1403 1407
      // schema will have the default profile set if profile switching occurs
1404 1408
   }
1409
   
1410
   /**
1411
    * Add a dependency listener used for conversion only, no-op for runtime configuration.
1412
    * 
1413
    * Automatic dependency resolution during conversion is enabled by setting the 
1414
    * 'convert-deps' general parameter to true.
1415
    * 
1416
    * @param listener the dependency listener
1417
    */
1418
   public static void addConversionDependencyListener(Consumer<String> listener) 
1419
   {
1420
      if (listener != null && !isRuntimeConfig() && getParameter("convert-deps", false))
1421
      {
1422
         if (conversionDepsListeners == null)
1423
         {
1424
            conversionDepsListeners = new HashSet<>();
1425
         }
1426
         
1427
         conversionDepsListeners.add(listener);
1428
      }
1429
   }
1430
   
1431
   /**
1432
    * Remove a dependency listener used for conversion only, no-op for runtime configuration.
1433
    * 
1434
    * @param listener the dependency listener
1435
    */
1436
   public static void removeConversionDependencyListener(Consumer<String> listener) 
1437
   {
1438
      if (listener != null && conversionDepsListeners != null)
1439
      {
1440
         conversionDepsListeners.remove(listener);
1441
      }
1442
   }
1443
   
1444
   /**
1445
    * Notify dependency listeners a new dependency has been found (class or procedure).
1446
    * 
1447
    * @param filename the dependency file name
1448
    */
1449
   public static void foundConversionDependency(String filename) {
1450
      if (conversionDepsListeners != null)
1451
      {
1452
         conversionDepsListeners.forEach(l -> l.accept(filename));
1453
      }
1454
   }
1405 1455

  
1406 1456
   /**
1407 1457
    * Create a Configuration instance.
......
1417 1467
         // always start with P2J_HOME parameter; this is reserved
1418 1468
         config.parmMap.put(PROP_HOME_DIR, home());
1419 1469
         
1420
         InputStream cfgStream;
1470
         InputStream cfgStream = null;
1421 1471
         
1422
         // attempt to load from jar first
1423
         ClassLoader cl = ClassLoader.getSystemClassLoader();
1424
         cfgStream = cl.getResourceAsStream(CFG_DIR + "/" + DEF_CFG_FILE);
1472
         // runtime configuration attempt to load from jar first
1473
         if (isRuntimeConfig())
1474
         {
1475
            ClassLoader cl = ClassLoader.getSystemClassLoader();
1476
            cfgStream = cl.getResourceAsStream(CFG_DIR + "/" + DEF_CFG_FILE);
1477
         }
1425 1478
         
1426 1479
         if (cfgStream == null)
1427 1480
         {
new/src/com/goldencode/p2j/convert/ConversionDriver.java 2024-06-07 10:29:14 +0000
142 142
**     CA  20220603          Allow the generation of proxy Java programs in the folder specified by 
143 143
**                           'proxy-output-root'.
144 144
** 047 OM  20240311          Do not generate the <schema>.meta.xml any more. The information is already
145
**                           present in DMO interface annotations. 
145
**                           present in DMO interface annotations.
146
** 048 ME  20240604          Add support for automatic dependencies conversion when using file list.
146 147
*/
147 148

  
148 149
/*
......
215 216
import com.goldencode.p2j.schema.*;
216 217
import com.goldencode.p2j.uast.*;
217 218
import com.goldencode.p2j.util.*;
219
import com.goldencode.util.StringHelper;
218 220
import java.io.*;
219 221
import java.util.*;
220 222

  
......
343 345
   /** The list of Progress source file specific P2O files. */
344 346
   private FileList sp2os = null;
345 347
   
348
   /** The list of Progress source files dependencies (used but not in convert list). */
349
   private Set<String> dependencies = null;
350
   
346 351
   /**
347 352
    * Creates an instance with a specific configuration.
348 353
    *
......
583 588
      brew(jasts, "Business Logic and Frames Classes");
584 589
   }
585 590
   
591
   
592
   @Override
593
   protected void executeJob(String title)
594
   {
595
      // add conversion dependency listener
596
      Configuration.addConversionDependencyListener(file -> {
597
         if (dependencies == null)
598
         {
599
            dependencies = new HashSet<>();
600
         }
601
         
602
         file = StringHelper.removeQuotes(file);
603
         
604
         if (dependencies.add(file))
605
         {
606
            // remove old java ast if we need to convert it
607
            zapFiles(new String[] { file }, new String[] { ".jast" });
608
         }
609
      });
610
      
611
      super.executeJob(title);
612
   }
613

  
586 614
   /**
587 615
    * Gather all SOAP operations from all files, regardless if they are included in the incremental conversion
588 616
    * or not, and generate the WSDLs.
......
1080 1108
      jasts = new ExplicitFileList(oldjasts.toArray(new String[0]));
1081 1109
   }
1082 1110
   
1111
   @Override
1112
   protected void runScanDriver(boolean preproc, boolean schema, boolean abortOnError,
1113
            int threads) throws Exception
1114
   {
1115
      // update source dependencies with database schema triggers before scan
1116
      updateSourceDependencies();
1117
      
1118
      super.runScanDriver(preproc, schema, abortOnError, threads);
1119
      
1120
      // update source dependencies with those found during scan
1121
      updateSourceDependencies();
1122
   }
1123
   
1124
   private void updateSourceDependencies ()
1125
   {
1126
      if (dependencies != null) {
1127
         for (String src : source.listFilenames())
1128
         {
1129
            dependencies.remove(src);
1130
         }
1131
         
1132
         if (!dependencies.isEmpty())
1133
         {
1134
            dependencies.addAll(Arrays.asList(source.listFilenames()));
1135
            source = new ExplicitFileList(dependencies.toArray(new String[0]));
1136
            job.files = source;
1137
         }
1138
         
1139
         dependencies = null;
1140
      }
1141
   }
1142

  
1083 1143
   /**
1084 1144
    * Container class that aggregates a set of options to control a run of the conversion
1085 1145
    * driver.
new/src/com/goldencode/p2j/schema/schema.g 2024-06-07 10:29:14 +0000
110 110
**     CA  20230321          A table's signature must include index information (this includes the index
111 111
**                           name, options, field position and type). 
112 112
** 041 GBB 20230512          Logging methods replaced by CentralLogger/ConversionStatus.
113
** 042 ME  20240604          Add database schema trigger procedures as conversion dependencies.
113 114
*/
114 115

  
115 116
/*
......
2064 2065
 */
2065 2066
proc_clause
2066 2067
   :
2067
      KW_PROC^ STRING
2068
      KW_PROC^ s:STRING
2069
      {
2070
         Configuration.foundConversionDependency(#s.getText());
2071
      }
2068 2072
   ;
2069 2073
   
2070 2074
/**
new/src/com/goldencode/p2j/uast/AstGenerator.java 2024-06-07 10:29:14 +0000
191 191
** 060 GBB 20230512          Logging methods replaced by CentralLogger/ConversionStatus.
192 192
** 061 OM  20230115          Replaced absolutePath(), relativePath(), upPath() and downPath() with faster
193 193
**                           versions, based on node types.
194
** 062 ME  20240604          Automatic add OO dependencies found during conversion using file list.
194 195
*/
195 196

  
196 197
/*
......
1638 1639
         String qname = ref.getText();
1639 1640
         ClassDefinition cdef = SymbolResolver.getClassDefinition(qname);
1640 1641
         cdef.parseFinished(false);
1642
         
1643
         if (!cdef.isBuiltIn()) 
1644
         {
1645
            // flag non built-in OO elements as conversion dependencies
1646
            Configuration.foundConversionDependency(filename);
1647
         }
1648
      }
1649
      else
1650
      {
1651
         // flag procedures as conversion dependencies
1652
         Configuration.foundConversionDependency(filename);
1641 1653
      }
1642 1654
      // save off output if requested, THIS MUST BE DONE AFTER FIXUPS!
1643 1655
      if (dumpParser)
new/src/com/goldencode/p2j/uast/SymbolResolver.java 2024-06-26 10:44:09 +0000
592 592
import com.goldencode.p2j.schema.*;
593 593
import com.goldencode.p2j.security.*;
594 594
import com.goldencode.p2j.util.*;
595
import com.goldencode.p2j.util.InternalEntry.Type;
595 596

  
596 597
/**
597 598
 * Contains a dictionary for each type of language namespace and provides
......
4073 4074
    */
4074 4075
   public int lookupProcedure(String name)
4075 4076
   {
4076
      return lookupWorkerExact(procDict, name);
4077
      int ret = lookupWorkerExact(procDict, name);
4078
      
4079
      if (ret == -1) 
4080
      {
4081
         // if not resolved already parse the procedure
4082
         try 
4083
         {
4084
            getAstGenerator().processFile(name, null, -1);
4085
         } catch (AstException e) {
4086
            // catch error for internal procedures call
4087
         }
4088
      }
4089
      
4090
      return ret;
4077 4091
   }
4078 4092
   
4079 4093
   /**
......
4594 4608
            // at this point found.filename must be valid
4595 4609
         }
4596 4610

  
4597
         if (generator == null)
4598
         {
4599
            generator = new AstGenerator();
4600
            generator.setSilent(silent);
4601
            generator.setPreprocess(true);
4602
            generator.setCache(true);
4603
            generator.setDumpLexer(true);
4604
            generator.setDumpParser(true);
4605
            generator.setAstPersist(true);
4606
         }
4607

  
4608 4611
         String relative = Configuration.normalizeFilename(found.filename);
4609 4612
         
4610 4613
         if (wa.preScanPass == 0)
......
4628 4631
            }
4629 4632

  
4630 4633
            // the PROPATH is inherited from the caller
4631
            generator.preScanClass(relative, found.builtin, found.dotnet, this.propath);
4634
            getAstGenerator().preScanClass(relative, found.builtin, found.dotnet, this.propath);
4632 4635
            
4633 4636
            // save all referenced classes/interfaces except for the genesis object
4634 4637
            if (wa.preScanPass > 1)
......
8752 8755
      
8753 8756
      if (!cdef.isBuiltIn() && new File(file).exists())
8754 8757
      {
8755
         generator.processFile(file, null, -1);
8758
         getAstGenerator().processFile(file, null, -1);
8756 8759
         
8757 8760
         // at this point we have been fully parsed and all parents have been fully parsed, so
8758 8761
         // it is safe to detect whether or not one of our ancestors is a .NET class 
......
9976 9979
   }
9977 9980
   
9978 9981
   /**
9982
    * Lazy load the AST Generator when new class/procedure needs to be processed.
9983
    * 
9984
    * @return the AST generator
9985
    */
9986
   private AstGenerator getAstGenerator () {
9987
      if (generator == null)
9988
      {
9989
         generator = new AstGenerator();
9990
         generator.setSilent(silent);
9991
         generator.setPreprocess(true);
9992
         generator.setCache(true);
9993
         generator.setDumpLexer(true);
9994
         generator.setDumpParser(true);
9995
         generator.setAstPersist(true);
9996
      }
9997
      
9998
      return generator;
9999
   }
10000
   
10001
   /**
9979 10002
    * Create a new {@link Variable}, with the specified details.
9980 10003
    * 
9981 10004
    * @param    name