Package edu.umd.cs.findbugs

Examples of edu.umd.cs.findbugs.BugCollection


            BalloonTipFactory.showToolWindowInfoNotifier(_project, text);
          }
        });
        break;
      case ANALYSIS_FINISHED:
        final BugCollection bugCollection = event.getBugCollection();
        final AtomicReference<ProjectStats> projectStats = new AtomicReference<ProjectStats>();
        if (bugCollection != null) {
          _bugTreePanel.setBugCollection(bugCollection);
          projectStats.set(bugCollection.getProjectStats());
          _bugTreePanel.updateRootNode(projectStats.get());
        }

        EventDispatchThreadHelper.invokeLater(new Runnable() {
          public void run() {
View Full Code Here


      return;
    }


    final FindBugsPlugin findBugsPlugin = getPluginInterface(project);
    final BugCollection bugCollection = findBugsPlugin.getToolWindowPanel().getBugCollection();
    if (bugCollection != null && !bugCollection.getCollection().isEmpty()) {
      //noinspection DialogTitleCapitalization
      final int result = Messages.showYesNoDialog(project, "Current result in the 'Found bugs view' will be deleted. Continue ?", "Delete found bugs?", Messages.getQuestionIcon());
      if (result == 1) {
        return;
      }
View Full Code Here

  private Project getCurrentFbProject() {
    final ToolWindowPanel panel = _parent.getFindBugsPlugin().getToolWindowPanel();
    if (panel == null) {
      return null;
    }
    final BugCollection bugCollection = panel.getBugCollection();
    if (bugCollection == null) {
      return null;
    }
    return bugCollection.getProject();
  }
View Full Code Here

        if (args.length < 1 || args.length > 2) {
            System.out.println(USAGE);
            return;
        }

        BugCollection origCollection;
        origCollection = new SortedBugCollection();
        origCollection.readXML(args[0]);
        SourceFinder sourceFinder = new SourceFinder(origCollection.getProject());

        for (BugInstance b : origCollection) {
            SourceLineAnnotation s = b.getPrimarySourceLineAnnotation();
            if (!s.isSourceFileKnown()) {
                continue;
            }
            if (!sourceFinder.hasSourceFile(s)) {
                continue;
            }
            SourceFile sourceFile = sourceFinder.findSourceFile(s);
            long when = sourceFile.getLastModified();
            if (when > 0) {
                Date firstSeen = new Date(when);
                b.getXmlProps().setFirstSeen(firstSeen);
                System.out.println("Set first seen to " + firstSeen);
            }
        }
        Cloud cloud = origCollection.getCloud();
        cloud.bugsPopulated();
        if (cloud.getSigninState() != Cloud.SigninState.SIGNED_IN
                && cloud.getSigninState() != Cloud.SigninState.NO_SIGNIN_REQUIRED) {
            cloud.signIn();
            if (cloud.getSigninState() != Cloud.SigninState.SIGNED_IN
                    && cloud.getSigninState() != Cloud.SigninState.NO_SIGNIN_REQUIRED) {
                throw new IllegalStateException("Unable to sign in; state : " + cloud.getSigninState());
            }
        }

        cloud.waitUntilIssueDataDownloaded();

        if (args.length > 1) {
            origCollection.writeXML(args[1]);
        }
        cloud.waitUntilNewIssuesUploaded();
        cloud.shutdown();

    }
View Full Code Here

                    @Override
                    public void run() {
                        try {
                            updateDesignationDisplay();
                            Project project = getProject();
                            BugCollection bc = BugLoader.redoAnalysisKeepComments(project);
                            updateProjectAndBugCollection(bc);
                            setProjectAndBugCollectionInSwingThread(project, bc);
                        } finally {
                            releaseDisplayWait();
                        }
View Full Code Here

            System.out.println(USAGE);
            return;
        }

        int prefixLength = Integer.parseInt(args[0]);
        BugCollection origCollection = new SortedBugCollection();
        if (args.length == 1) {
            origCollection.readXML(System.in);
        } else {
            origCollection.readXML(args[1]);
        }
        Map<String, Integer> map = new TreeMap<String, Integer>();
        Map<String, Integer> ncss = new TreeMap<String, Integer>();

        for (BugInstance b : origCollection.getCollection()) {
            String prefix = ClassName.extractPackagePrefix(b.getPrimaryClass().getPackageName(), prefixLength);
            Integer v = map.get(prefix);
            if (v == null) {
                map.put(prefix, 1);
            } else {
                map.put(prefix, v + 1);
            }
        }
        for (PackageStats ps : origCollection.getProjectStats().getPackageStats()) {
            String prefix = ClassName.extractPackagePrefix(ps.getPackageName(), prefixLength);

            Integer v = ncss.get(prefix);
            if (v == null) {
                ncss.put(prefix, ps.size());
View Full Code Here

        }

        mapFromNewToOldBug.clear();

        matchedOldBugs.clear();
        BugCollection resultCollection = newCollection.createEmptyCollectionWithMetadata();
        // Previous sequence number
        long lastSequence = origCollection.getSequenceNumber();
        // The AppVersion history is retained from the orig collection,
        // adding an entry for the sequence/timestamp of the current state
        // of the orig collection.
        resultCollection.clearAppVersions();
        for (Iterator<AppVersion> i = origCollection.appVersionIterator(); i.hasNext();) {
            AppVersion appVersion = i.next();
            resultCollection.addAppVersion((AppVersion) appVersion.clone());
        }
        AppVersion origCollectionVersion = origCollection.getCurrentAppVersion();
        AppVersion origCollectionVersionClone = new AppVersion(lastSequence);
        origCollectionVersionClone.setTimestamp(origCollectionVersion.getTimestamp());
        origCollectionVersionClone.setReleaseName(origCollectionVersion.getReleaseName());
        origCollectionVersionClone.setNumClasses(origCollection.getProjectStats().getNumClasses());
        origCollectionVersionClone.setCodeSize(origCollection.getProjectStats().getCodeSize());

        resultCollection.addAppVersion(origCollectionVersionClone);

        // We assign a sequence number to the new collection as one greater than
        // the original collection.
        long currentSequence = origCollection.getSequenceNumber() + 1;
        resultCollection.setSequenceNumber(currentSequence);

        //        int oldBugs = 0;
        matchBugs(origCollection, newCollection);

        if (sloppyMatch) {
            matchBugs(new SloppyBugComparator(), origCollection, newCollection);
        }

        //        int newlyDeadBugs = 0;
        //        int persistantBugs = 0;
        //        int addedBugs = 0;
        //        int addedInNewCode = 0;
        //        int deadBugInDeadCode = 0;

        HashSet<String> analyzedSourceFiles = sourceFilesInCollection(newCollection);
        // Copy unmatched bugs
        if (copyDeadBugs || incrementalAnalysis) {
            for (BugInstance bug : origCollection.getCollection()) {
                if (!matchedOldBugs.containsKey(bug)) {
                    if (bug.isDead()) {
                        //                        oldBugs++;
                        BugInstance newBug = (BugInstance) bug.clone();
                        resultCollection.add(newBug, false);
                    } else {
                        //                        newlyDeadBugs++;

                        BugInstance newBug = (BugInstance) bug.clone();

                        ClassAnnotation classBugFoundIn = bug.getPrimaryClass();
                        String className = classBugFoundIn.getClassName();
                        String sourceFile = classBugFoundIn.getSourceFileName();
                        boolean fixed = sourceFile != null && analyzedSourceFiles.contains(sourceFile)
                                || newCollection.getProjectStats().getClassStats(className) != null;
                        if (fixed) {
                            if (!copyDeadBugs) {
                                continue;
                            }
                            newBug.setRemovedByChangeOfPersistingClass(true);
                            newBug.setLastVersion(lastSequence);
                        } else {
                            //                            deadBugInDeadCode++;
                            if (!incrementalAnalysis) {
                                newBug.setLastVersion(lastSequence);
                            }
                        }

                        if (newBug.isDead() && newBug.getFirstVersion() > newBug.getLastVersion()) {
                            throw new IllegalStateException("Illegal Version range: " + newBug.getFirstVersion() + ".."
                                    + newBug.getLastVersion());
                        }
                        resultCollection.add(newBug, false);
                    }
                }
            }
        }
        // Copy matched bugs
        for (BugInstance bug : newCollection.getCollection()) {
            BugInstance newBug = (BugInstance) bug.clone();
            if (mapFromNewToOldBug.containsKey(bug)) {
                BugInstance origWarning = mapFromNewToOldBug.get(bug);

                mergeBugHistory(origWarning, newBug);
                // handle getAnnotationText()/setAnnotationText() and
                // designation key
                BugDesignation designation = newBug.getUserDesignation();
                if (designation != null) {
                    designation.merge(origWarning.getUserDesignation());
                }
                else {
                    newBug.setUserDesignation(origWarning.getUserDesignation()); // clone??
                }

                //                persistantBugs++;
            } else {
                newBug.setFirstVersion(lastSequence + 1);
                //                addedBugs++;

                ClassAnnotation classBugFoundIn = bug.getPrimaryClass();

                String className = classBugFoundIn.getClassName();
                if (origCollection.getProjectStats().getClassStats(className) != null) {
                    newBug.setIntroducedByChangeOfExistingClass(true);
                    // System.out.println("added bug to existing code " +
                    // newBug.getUniqueId() + " : " + newBug.getAbbrev() + " in
                    // " + classBugFoundIn);
                } else {
                    //                    addedInNewCode++;
                }
            }
            if (newBug.isDead()) {
                throw new IllegalStateException("Illegal Version range: " + newBug.getFirstVersion() + ".."
                        + newBug.getLastVersion());
            }
            int oldSize = resultCollection.getCollection().size();
            resultCollection.add(newBug, false);
            int newSize = resultCollection.getCollection().size();
            if (newSize != oldSize + 1) {
                System.out.println("Failed to add bug" + newBug.getMessage());
            }
        }
        /*
 
View Full Code Here

            commonPrefix = Math.min(commonPrefix, lengthCommonPrefix(firstPathParts, getFilePathParts(args[i])));
        }

        String origFilename = args[argCount++];
        BugCollection origCollection;
        origCollection = new SortedBugCollection();
        if (verbose) {
            System.out.println("Starting with " + origFilename);
        }

        while (true) {
            try {
                while (true) {
                    File f = new File(origFilename);
                    if (f.length() > 0) {
                        break;
                    }
                    if (verbose) {
                        System.out.println("Empty input file: " + f);
                    }
                    origFilename = args[argCount++];
                }
                origCollection.readXML(origFilename);
                break;
            } catch (Exception e) {
                if (verbose) {
                    System.out.println("Error reading " + origFilename);
                    e.printStackTrace(System.out);
                }
                origFilename = args[argCount++];
            }
        }

        if (commandLine.overrideRevisionNames || origCollection.getReleaseName() == null
                || origCollection.getReleaseName().length() == 0) {

            if (commonPrefix >= firstPathParts.length) {
                // This should only happen if either
                //
                // (1) there is only one input file, or
                // (2) all of the input files have the same name
                //
                // In either case, make the release name the same
                // as the file part of the input file(s).
                commonPrefix = firstPathParts.length - 1;
            }

            origCollection.setReleaseName(firstPathParts[commonPrefix]);
            if (useAnalysisTimes) {
                origCollection.setTimestamp(origCollection.getAnalysisTimestamp());
            }
        }

        for (BugInstance bug : origCollection.getCollection()) {
            if (bug.getLastVersion() >= 0 && bug.getFirstVersion() > bug.getLastVersion()) {
                throw new IllegalStateException("Illegal Version range: " + bug.getFirstVersion() + ".." + bug.getLastVersion());
            }
        }

        discardUnwantedBugs(origCollection);

        while (argCount <= (args.length - 1)) {

            BugCollection newCollection = new SortedBugCollection();

            String newFilename = args[argCount++];
            if (verbose) {
                System.out.println("Merging " + newFilename);
            }
            try {
                File f = new File(newFilename);
                if (f.length() == 0) {
                    if (verbose) {
                        System.out.println("Empty input file: " + f);
                    }
                    continue;
                }
                newCollection.readXML(newFilename);

                if (commandLine.overrideRevisionNames || newCollection.getReleaseName() == null
                        || newCollection.getReleaseName().length() == 0) {
                    newCollection.setReleaseName(getFilePathParts(newFilename)[commonPrefix]);
                }
                if (useAnalysisTimes) {
                    newCollection.setTimestamp(newCollection.getAnalysisTimestamp());
                }
                discardUnwantedBugs(newCollection);

                origCollection = mergeCollections(origCollection, newCollection, true, false);
            } catch (IOException e) {
View Full Code Here

        if (args.length > 1 || (args.length > 0 && "-help".equals(args[0]))) {
            System.err.println("Usage: " + DefectDensity.class.getName() + " [<infile>]");
            System.exit(1);
        }
        FindBugs.setNoAnalysis();
        BugCollection origCollection = new SortedBugCollection();
        int argCount = 0;
        if (argCount == args.length) {
            origCollection.readXML(System.in);
        } else {
            origCollection.readXML(args[argCount]);
        }
        ProjectStats stats = origCollection.getProjectStats();
        printRow("kind", "name", "density/KNCSS", "bugs", "NCSS");
        double projectDensity = density(stats.getTotalBugs(), stats.getCodeSize());
        printRow("project", origCollection.getCurrentAppVersion().getReleaseName(), projectDensity, stats.getTotalBugs(),
                stats.getCodeSize());
        for (PackageStats p : stats.getPackageStats()) {
            if (p.getTotalBugs() > 4) {

                double packageDensity = density(p.getTotalBugs(), p.size());
View Full Code Here

        if (args.length > 1) {
            System.out.println(USAGE);
            return;
        }

        BugCollection bugs = new SortedBugCollection();
        if (args.length == 0) {
            bugs.readXML(System.in);
        } else {
            bugs.readXML(args[0]);
        }
        bugs.getCloud().waitUntilIssueDataDownloaded();
        PrintWriter out = UTF8.printWriter(System.out);
        bugs.getCloud().printCloudSummary(out, bugs, new String[0]);
        out.close();

    }
View Full Code Here

TOP

Related Classes of edu.umd.cs.findbugs.BugCollection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.