changeset 15:cc7cda3d6842

module filter in RepGen, module information, filters for ProductInstr CODETOOLS-7901552, CODETOOLS-7901559, CODETOOLS-7901558,CODETOOLS-7901554, CODETOOLS-7901551, CODETOOLS-7901544
author afedorch
date Wed, 02 Dec 2015 20:24:32 +0300
parents 4027bcf80b8d
children 1fca3f09b1ce
files src/classes/com/sun/tdk/jcov/JREInstr.java src/classes/com/sun/tdk/jcov/Merger.java src/classes/com/sun/tdk/jcov/ProductInstr.java src/classes/com/sun/tdk/jcov/RepGen.java src/classes/com/sun/tdk/jcov/report/html/CoverageReport.java src/classes/com/sun/tdk/jcov/runtime/FileSaver.java src/classes/com/sun/tdk/jcov/runtime/JCovXMLFileSaver.java src/classes/com/sun/tdk/jcov/util/Utils.java
diffstat 8 files changed, 142 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/src/classes/com/sun/tdk/jcov/JREInstr.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/JREInstr.java	Wed Dec 02 20:24:32 2015 +0300
@@ -196,7 +196,11 @@
                         }
                     }
                 } else {
-                    instr.instrumentFile(dirtoInstrument.getAbsolutePath(), null, null);
+                    for (File mod : dirtoInstrument.listFiles()) {
+                        if (mod != null && mod.isDirectory()) {
+                            instr.instrumentFile(mod.getAbsolutePath(), null, null, mod.getName());
+                        }
+                    }
                 }
                 createJimage(dirtoInstrument, jimageInstr.getAbsolutePath() + "i");
 
--- a/src/classes/com/sun/tdk/jcov/Merger.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/Merger.java	Wed Dec 02 20:24:32 2015 +0300
@@ -84,6 +84,8 @@
     private int loose_lvl = 0;
     private String[] include = new String[]{".*"};
     private String[] exclude = new String[]{""};
+    private String[] m_include = new String[]{".*"};
+    private String[] m_exclude = new String[]{""};
     private String[] fm = null;
     private boolean compress;
     private boolean sigmerge = false;
@@ -418,7 +420,7 @@
      */
     public void merge(Merge merge, String outTestList, boolean ignoreOriginalScales) {
 
-        readFilter = new ClassSignatureFilter(include, exclude, fm);
+        readFilter = new ClassSignatureFilter(include, exclude, m_include, m_exclude, fm);
         DataRoot merged = null;
         DataRoot rNext = null;
         logger.log(Level.INFO, "- Merging started");
@@ -790,10 +792,16 @@
      * @param fm
      */
     public void setDefaultReadingFilter(String[] include, String[] exclude, String[] fm) {
+        setDefaultReadingFilter(include, exclude, m_include, m_exclude, fm);
+    }
+
+    public void setDefaultReadingFilter(String[] include, String[] exclude, String[] m_include, String[] m_exclude, String[] fm) {
         this.include = include;
         this.exclude = exclude;
+        this.m_include = m_include;
+        this.m_exclude = m_exclude;
         this.fm = fm;
-        this.readFilter = new ClassSignatureFilter(include, exclude, fm);
+        this.readFilter = new ClassSignatureFilter(include, exclude, m_include, m_exclude, fm);
     }
 
     /**
@@ -963,6 +971,8 @@
 
         include = InstrumentationOptions.handleInclude(opts);
         exclude = InstrumentationOptions.handleExclude(opts);
+        m_include = InstrumentationOptions.handleMInclude(opts);
+        m_exclude = InstrumentationOptions.handleMExclude(opts);
         fm = InstrumentationOptions.handleFM(opts);
 
         read_scales = opts.isSet(DSC_SCALE);
--- a/src/classes/com/sun/tdk/jcov/ProductInstr.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/ProductInstr.java	Wed Dec 02 20:24:32 2015 +0300
@@ -60,6 +60,13 @@
     private String tempPath;
     private File rtLibFile;
     private String[] rtClassDirTargets;
+    private InstrumentationOptions.InstrumentationMode mode = InstrumentationOptions.InstrumentationMode.BRANCH;
+    private String[] include = new String[]{".*"};
+    private String[] exclude = new String[]{""};
+    private String[] m_include = new String[]{".*"};
+    private String[] m_exclude = new String[]{""};
+    private String[] callerInclude;
+    private String[] callerExclude;
 
     public void instrumentProduct() throws IOException {
         logger.log(Level.INFO, " - Instrumenting product");
@@ -78,7 +85,7 @@
     }
 
     private AbstractUniversalInstrumenter setupInstrumenter() {
-        InstrumentationParams params = new InstrumentationParams(false, false, true, null, null, InstrumentationOptions.InstrumentationMode.BRANCH)
+        InstrumentationParams params = new InstrumentationParams(true, false, false, false, false, false, InstrumentationOptions.ABSTRACTMODE.NONE, include, exclude, callerInclude, callerExclude, m_include, m_exclude, mode, null, null)
                 .setInstrumentAnonymous(true)
                 .setInstrumentSynthetic(false);
 
@@ -120,6 +127,17 @@
     @Override
     protected EnvHandler defineHandler() {
         return new EnvHandler(new OptionDescr[]{
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_TYPE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_INCLUDE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_EXCLUDE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_MINCLUDE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_MEXCLUDE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_INCLUDE_LIST,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_EXCLUDE_LIST,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_MINCLUDE_LIST,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_MEXCLUDE_LIST,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_CALLER_INCLUDE,
+                    com.sun.tdk.jcov.instrument.InstrumentationOptions.DSC_CALLER_EXCLUDE,
                     DSC_INSTRUMENT,
                     DSC_INSTRUMENT_TO,
                     Instr.DSC_INCLUDE_RT,
@@ -138,6 +156,19 @@
             throw new EnvHandlingException("Please specify saver location with '-rt' option");
         }
         rtClassDirTargets = envHandler.getValues(ProductInstr.DSC_RT_TO);
+        if (envHandler.getValue(InstrumentationOptions.DSC_TYPE) != null) {
+            mode = InstrumentationOptions.InstrumentationMode.fromString(envHandler.getValue(InstrumentationOptions.DSC_TYPE));
+        }
+
+        include = InstrumentationOptions.handleInclude(envHandler);
+        exclude = InstrumentationOptions.handleExclude(envHandler);
+
+        m_include = InstrumentationOptions.handleMInclude(envHandler);
+        m_exclude = InstrumentationOptions.handleMExclude(envHandler);
+
+        callerInclude = envHandler.getValues(InstrumentationOptions.DSC_CALLER_INCLUDE);
+        callerExclude = envHandler.getValues(InstrumentationOptions.DSC_CALLER_EXCLUDE);
+
         return SUCCESS_EXIT_CODE;
     }
 
--- a/src/classes/com/sun/tdk/jcov/RepGen.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/RepGen.java	Wed Dec 02 20:24:32 2015 +0300
@@ -552,6 +552,7 @@
                 Merger.Merge merge = new Merger.Merge(results, null);
                 merger.setAddMissing(true);
                 merger.setRead_scales(true);
+                merger.setDefaultReadingFilter(include, exclude, m_include, m_exclude, fms);
                 merger.merge(merge, outputDir, true);
 
                 ReportGenerator rg;
--- a/src/classes/com/sun/tdk/jcov/report/html/CoverageReport.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/report/html/CoverageReport.java	Wed Dec 02 20:24:32 2015 +0300
@@ -126,7 +126,7 @@
         generateFrameset(directory);
         generatePackageList(directory);
         generateClassList(directory);
-        HashMap<String, CoverageData[]> modules = getModulesCoverage();
+        HashMap<String, ArrayList<ModuleCoverageData>> modules = getModulesCoverage();
         if (modules == null || (modules.size() == 1 && XmlNames.NO_MODULE.equals(modules.keySet().iterator().next()))){
             modules = null;
         }
@@ -137,18 +137,18 @@
 
     }
 
-    private void generateModulesList(File directory, HashMap<String, CoverageData[]> modules) throws IOException{
+    private void generateModulesList(File directory, HashMap<String, ArrayList<ModuleCoverageData>> modules) throws IOException{
         List<PackageCoverage> list = coverage.getPackages();
 
         for (String moduleName: modules.keySet()) {
-            HashMap<String, CoverageData[]> module = new HashMap<String, CoverageData[]>();
+            HashMap<String, ArrayList<ModuleCoverageData>> module = new HashMap<String, ArrayList<ModuleCoverageData>>();
             module.put(moduleName, modules.get(moduleName));
             generateModuleOverview(directory, list, module);
         }
     }
 
-    private HashMap<String, CoverageData[]> getModulesCoverage(){
-        HashMap<String, CoverageData[]> modules = null;
+    private HashMap<String, ArrayList<ModuleCoverageData>> getModulesCoverage(){
+        HashMap<String, ArrayList<ModuleCoverageData>> modules = null;
         List<PackageCoverage> list = coverage.getPackages();
 
         if (list == null || list.size() == 0 || list.get(0) == null
@@ -156,16 +156,26 @@
             return modules;
         }
 
-        modules = new HashMap<String, CoverageData[]>();
+        modules = new HashMap<String, ArrayList<ModuleCoverageData>>();
         for (PackageCoverage pkg : list) {
             String moduleName = pkg.getClasses().get(0).getModuleName();
             if (modules.get(moduleName) == null) {
-                modules.put(moduleName, new CoverageData[]{pkg.getData(DataType.CLASS), pkg.getData(DataType.METHOD),
-                        pkg.getData(DataType.BLOCK), pkg.getData(DataType.BRANCH), pkg.getData(DataType.LINE)});
+                ArrayList<ModuleCoverageData> coverageDataList = new ArrayList<ModuleCoverageData>();
+                if (testService != null && (isAddTestsInfo || isMergeRepGenMode)) {
+                    for (int test = 0; test < testService.getTestCount(); test++) {
+                        coverageDataList.add(new ModuleCoverageData(pkg, test));
+                    }
+                }
+                coverageDataList.add(new ModuleCoverageData(pkg));
+                modules.put(moduleName, coverageDataList);
             } else {
-                CoverageData[] oldCD = modules.get(moduleName);
-                modules.put(moduleName, new CoverageData[]{oldCD[0].add(pkg.getData(DataType.CLASS)), oldCD[1].add(pkg.getData(DataType.METHOD)),
-                        oldCD[2].add(pkg.getData(DataType.BLOCK)), oldCD[3].add(pkg.getData(DataType.BRANCH)), oldCD[4].add(pkg.getData(DataType.LINE))});
+                ArrayList<ModuleCoverageData> modulesCD = modules.get(moduleName);
+                if (testService != null && (isAddTestsInfo || isMergeRepGenMode)) {
+                    for (int test = 0; test < testService.getTestCount(); test++) {
+                        modulesCD.get(test).addPackage(pkg);
+                    }
+                }
+                modulesCD.get(modulesCD.size()-1).addPackage(pkg);
             }
         }
 
@@ -370,11 +380,11 @@
         pw.close();
     }
 
-    private void generateOverview(File dir, HashMap<String, CoverageData[]> modules) throws IOException {
+    private void generateOverview(File dir, HashMap<String, ArrayList<ModuleCoverageData>> modules) throws IOException {
         generateOverview(dir, null, modules);
     }
 
-    private void generateModuleOverview(File dir, List<PackageCoverage> allPkgList, HashMap<String, CoverageData[]> module) throws IOException {
+    private void generateModuleOverview(File dir, List<PackageCoverage> allPkgList, HashMap<String, ArrayList<ModuleCoverageData>> module) throws IOException {
         String filename = "overview-summary.html";
         String rootRef = "../";
         String moduleName = module.keySet().iterator().next();
@@ -497,7 +507,7 @@
         pw.close();
     }
 
-    private void generateOverview(File dir, PackageCoverage thePackage, HashMap<String, CoverageData[]> modules)
+    private void generateOverview(File dir, PackageCoverage thePackage, HashMap<String, ArrayList<ModuleCoverageData>> modules)
             throws IOException {
         String filename = "overview-summary.html";
         String rootRef;
@@ -680,7 +690,7 @@
         pw.close();
     }
 
-    private void generateModulesInfo(PrintWriter pw, HashMap<String, CoverageData[]> modules, boolean decorate){
+    private void generateModulesInfo(PrintWriter pw, HashMap<String, ArrayList<ModuleCoverageData>> modules, boolean decorate){
 
         if (modules.keySet().size() > 1) {
             pw.println("<span class=\"title2\">Modules</span><br>");
@@ -708,11 +718,23 @@
                         + " </b> </a></td>");
             }
 
+            int moduleDataColumnsSize = modules.get(module).size();
+            ModuleCoverageData totalModuleCD = modules.get(module).get(moduleDataColumnsSize-1);
             pw.println("<td class=\"reportValue_number\">"
-                    + modules.get(module)[0].getTotal() + "</td>");
-            for (int i = 1; i< modules.get(module).length; i++) {
+                    + totalModuleCD.getData()[columns.classes.number].getTotal() + "</td>");
+            for (int i = 1; i< totalModuleCD.getData().length; i++) {
                 if (show(columns.valueOf(i))) {
-                    CoverageData cd = modules.get(module)[i];
+                    if (testService != null && (isAddTestsInfo || isMergeRepGenMode)) {
+                        for (int test = 0; test < testService.getTestCount(); test++) {
+                            if (show(columns.valueOf(i)) && i != columns.line.number) {
+                                CoverageData cd = modules.get(module).get(test).getData()[i];
+                                    pw.println("<td class=\"reportValue\">"
+                                            + decorate(cd.getFormattedCoverage(coverage.isAncFiltersSet())) + "</td>");
+                            }
+                        }
+                    }
+
+                    CoverageData cd = totalModuleCD.getData()[i];
                     if (!decorate) {
                         pw.println("<td class=\"reportValue\">"
                                 + decorate(cd.getFormattedCoverage(coverage.isAncFiltersSet())) + "</td>");
@@ -729,8 +751,51 @@
     }
 
 
+    private class ModuleCoverageData {
+
+        private CoverageData[] collectedData;
+
+        public ModuleCoverageData() {
+            collectedData = new CoverageData[6];
+        }
+
+        public ModuleCoverageData(PackageCoverage pkg) {
+            collectedData = new CoverageData[]{
+                    pkg.getData(DataType.FIELD),
+                    pkg.getData(DataType.METHOD),
+                    pkg.getData(DataType.BLOCK),
+                    pkg.getData(DataType.BRANCH),
+                    pkg.getData(DataType.LINE),
+                    pkg.getData(DataType.CLASS)};
+        }
+
+        public ModuleCoverageData(PackageCoverage pkg, int testNumber) {
+            collectedData = new CoverageData[]{
+                    pkg.getData(DataType.FIELD, testNumber),
+                    pkg.getData(DataType.METHOD, testNumber),
+                    pkg.getData(DataType.BLOCK, testNumber),
+                    pkg.getData(DataType.BRANCH, testNumber),
+                    pkg.getData(DataType.LINE, testNumber),
+                    pkg.getData(DataType.CLASS, testNumber)};
+        }
+
+        public void addPackage(PackageCoverage pkg) {
+            collectedData[columns.field.number].add(pkg.getData(DataType.FIELD));
+            collectedData[columns.method.number].add(pkg.getData(DataType.METHOD));
+            collectedData[columns.block.number].add(pkg.getData(DataType.BLOCK));
+            collectedData[columns.branch.number].add(pkg.getData(DataType.BRANCH));
+            collectedData[columns.line.number].add(pkg.getData(DataType.LINE));
+            collectedData[columns.classes.number].add(pkg.getData(DataType.CLASS));
+        }
+
+        public CoverageData[] getData(){
+            return collectedData;
+        }
+
+    }
+
     public enum columns {
-        method(1), field(0), block(2), branch(3), line(4);
+        method(1), field(0), block(2), branch(3), line(4), classes(5);
 
         private int number;
 
--- a/src/classes/com/sun/tdk/jcov/runtime/FileSaver.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/runtime/FileSaver.java	Wed Dec 02 20:24:32 2015 +0300
@@ -47,40 +47,6 @@
     protected boolean scales;
     private static boolean isWindows = System.getProperty("os.name").toLowerCase().startsWith("windows");
 
-    protected static File createLockFile(String filename) {
-
-        if (isWindows) {
-            return null;
-        }
-
-        for (int i = LOCK_REPEAT; i != 0; i--) {
-            String lockName = filename + ".lock";
-            File fl = new File(lockName);
-            try {
-                if (fl.createNewFile()) {
-                    return fl;
-                }
-                Thread.sleep(LOCK_SLEEP);
-            } catch (InterruptedException e) {
-                // should be exit??
-                return null;
-            } catch (IOException ioe) {
-                return null;
-            }
-        }
-        return null;
-    }
-
-    protected static void deleteLock(File lock) {
-        if (isWindows) {
-            return;
-        }
-
-        if (lock != null) {
-            lock.delete();
-        }
-    }
-
     protected static String genUniqFileName(String filename) {
         for (int i = 1; i < Integer.MAX_VALUE; i++) {
             if (!new File(filename + "." + i).exists()) {
@@ -135,20 +101,10 @@
 
             if (new File(filename).exists()
                     && !mergeMode.equals(MERGE.OVERWRITE)) {
-                File lock = createLockFile(filename);
-                try {
-                    try2MergeAndSave(filename, filename, scales || mergeMode == MERGE.SCALE);
-                } finally {
-                    deleteLock(lock);
-                }
+                try2MergeAndSave(filename, filename, scales || mergeMode == MERGE.SCALE);
                 return;
             } else {
-                File lock = createLockFile(filename);
-                try {
-                    try2MergeAndSave(filename, template, scales || mergeMode == MERGE.SCALE);
-                } finally {
-                    deleteLock(lock);
-                }
+                try2MergeAndSave(filename, template, scales || mergeMode == MERGE.SCALE);
             }
         } catch (Exception e) {
             e.printStackTrace();
--- a/src/classes/com/sun/tdk/jcov/runtime/JCovXMLFileSaver.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/runtime/JCovXMLFileSaver.java	Wed Dec 02 20:24:32 2015 +0300
@@ -60,7 +60,7 @@
     }
 
     public void saveResults(String filename) throws Exception {
-        if (isWindows) {
+        //if (isWindows) {
             File file = new File(filename);
             FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
 
@@ -82,12 +82,12 @@
                     Thread.sleep(LOCK_SLEEP);
                 }
             }
-        } else {
+        /*} else {
             XmlContext ctx = new XmlContext(filename, root.getParams());
             ctx.setSkipNotCoveredClasses(agentdata);
             root.xmlGen(ctx);
             ctx.close();
-        }
+        }*/
     }
 
     void mergeResults(String dest, String src, boolean scale) throws Exception {
--- a/src/classes/com/sun/tdk/jcov/util/Utils.java	Mon Oct 26 14:31:30 2015 +0300
+++ b/src/classes/com/sun/tdk/jcov/util/Utils.java	Wed Dec 02 20:24:32 2015 +0300
@@ -1337,6 +1337,7 @@
 
         if ((!classname.equals("java/lang/System"))
                 && (!classname.equals("java/lang/String"))
+                && (!classname.equals("java/lang/StringLatin1"))
                 && (!classname.equals("java/lang/String$CaseInsensitiveComparator"))
                 && (!classname.equals("java/lang/Thread"))
                 && (!classname.equals("java/lang/ThreadGroup"))
@@ -1352,6 +1353,8 @@
                 && !methodname.equals("<init>")
                 && !methodname.equals("init")
                 && !methodname.equals("length")
+                && !methodname.equals("coder")
+                && !methodname.equals("isLatin1")
                 && !methodname.equals("charAt")
                 && !methodname.equals("equals")
                 && !methodname.equals("add")