diff --git a/src/nh3/ammonia/BugFixChangesUpdater.java b/src/nh3/ammonia/BugFixChangesUpdater.java deleted file mode 100644 index 87290b3..0000000 --- a/src/nh3/ammonia/BugFixChangesUpdater.java +++ /dev/null @@ -1,269 +0,0 @@ -package nh3.ammonia; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.io.StringReader; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeSet; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.io.SVNRepositoryFactory; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNDiffClient; -import org.tmatesoft.svn.core.wc.SVNRevision; - -public class BugFixChangesUpdater { - - public static void main(final String[] args) { - FBParserConfig.initialize(args); - BugFixChangesUpdater main = new BugFixChangesUpdater(); - main.update(); - } - - private void update() { - - try { - Class.forName("org.sqlite.JDBC"); - final String database = FBParserConfig.getInstance() - .getDATABASE(); - final Connection connector = DriverManager.getConnection("jdbc:sqlite:" + database); - - final long startrev = FBParserConfig.getInstance() - .getSTARTREV(); - final long endrev = FBParserConfig.getInstance() - .getENDREV(); - final SortedSet revisions = new TreeSet<>(); - final Statement statement1 = connector.createStatement(); - final ResultSet results1 = statement1 - .executeQuery("select id from revisions where " + startrev + " < id and id < " + endrev); - while (results1.next()) { - final int revision = results1.getInt(1); - revisions.add(revision); - } - statement1.close(); - - final String fbResult = FBParserConfig.getInstance() - .getFBRESULTS() - .get(0); - final FBParser parser = new FBParser(fbResult); - parser.perform(); - final List bugInstances = parser.getBugInstances(); - final Map transitions = new HashMap<>(); - for (final BugInstance instance : bugInstances) { - final SourceLine sourceline = instance.getSourceLines() - .get(0); - final String path = sourceline.sourcepath; - final int startLine = sourceline.start; - final int endLine = sourceline.end; - final LocationTransition transition = new LocationTransition(); - transition.add((int) startrev, new Location(path, startLine, endLine, false)); - transitions.put(instance, transition); - } - - final PreparedStatement statement2 = connector.prepareStatement("select " + "B.id, " - + "B.filepath, " + "(select C1.start from codes C1 where C1.id = B.beforeID), " - + "(select C2.end from codes C2 where C2.id = B.beforeID) " - + "from bugfixchanges B where B.revision = ?"); - final PreparedStatement statement3 = - connector.prepareStatement("update bugfixchanges set warningfix = ? where id = ?"); - for (final Integer revision : revisions) { - statement2.setInt(1, revision); - final ResultSet results2 = statement2.executeQuery(); - while (results2.next()) { - final int id = results2.getInt(1); - final String filepath = results2.getString(2); - final int startline = results2.getInt(3); - final int endline = results2.getInt(4); - - for (final LocationTransition wlt : transitions.values()) { - - if (!wlt.hasChanged()) { - - final Location warningLocation = wlt.getLatestLocation(); - if (!warningLocation.path.equals(filepath)) { - continue; - } - - if (endline < warningLocation.startLine) { - continue; - } - - if (warningLocation.endLine < startline) { - continue; - } - - statement3.setInt(1, 1); - statement3.setInt(2, id); - statement3.addBatch(); - } - } - } - - statement3.executeBatch(); - - this.updateWarningLocations(transitions, revision); - } - statement2.close(); - statement3.close(); - - } catch (SQLException | ClassNotFoundException e) { - e.printStackTrace(); - } - } - - private void updateWarningLocations(final Map transitions, - final int revision) { - - try { - - final String repository = FBParserConfig.getInstance() - .getSVNREPOSITORY(); - final SVNDiffClient diffClient = SVNClientManager.newInstance() - .getDiffClient(); - final Map diffCache = new HashMap<>(); - - for (final Entry entry : transitions.entrySet()) { - - final BugInstance warning = entry.getKey(); - final LocationTransition transition = entry.getValue(); - if (null == transition || transition.hasChanged()) { - continue; - } - - final String path = warning.getSourceLines() - .get(0).sourcepath; - String diffText = diffCache.get(path); - if (null == diffText) { - final SVNURL fileURL = SVNURL.fromFile(new File(repository + File.separator + path)); - final SVNNodeKind node = SVNRepositoryFactory.create(fileURL) - .checkPath("", revision - 1); - if (SVNNodeKind.NONE == node) { - continue; - } - - final StringBuilder text = new StringBuilder(); - diffClient.doDiff(fileURL, SVNRevision.create(revision - 1), fileURL, - SVNRevision.create(revision), SVNDepth.FILES, true, new OutputStream() { - - @Override - public void write(int b) throws IOException { - text.append((char) b); - } - }); - diffText = text.toString(); - diffCache.put(path, diffText); - } - - final List changedLocations = getChangedLocations(path, diffText); - final Location latestWarningLocation = transition.getLatestLocation(); - final Location movedWarningLocation = - moveWarningLocation(latestWarningLocation, changedLocations); - if (!latestWarningLocation.equals(movedWarningLocation)) { - transition.add(revision, movedWarningLocation); - } - } - } - - catch (final SVNException e) { - e.printStackTrace(); - } - } - - private List getChangedLocations(final String path, final String text) { - - final List changedLocations = new ArrayList<>(); - - try (final BufferedReader reader = new BufferedReader(new StringReader(text))) { - while (true) { - - final String line = reader.readLine(); - - if (null == line) { - break; - } - - else if (line.startsWith("@@") && line.endsWith("@@")) { - final StringTokenizer tokenizer = new StringTokenizer(line); - final String prefix = tokenizer.nextToken(); - final String beforeLocation = tokenizer.nextToken(); - final String afterLocation = tokenizer.nextToken(); - final String suffix = tokenizer.nextToken(); - - final int beforeStartLine = - Integer.parseInt(beforeLocation.substring(1, beforeLocation.indexOf(','))) + 3; - final int beforeEndLine = beforeStartLine - + Integer.parseInt(beforeLocation.substring(beforeLocation.indexOf(',') + 1)) - 3; - final int afterStartLine = - Integer.parseInt(afterLocation.substring(1, afterLocation.indexOf(','))) + 3; - final int afterEndLine = afterStartLine - + Integer.parseInt(afterLocation.substring(afterLocation.indexOf(',') + 1)) - 3; - final Location before = new Location(path, beforeStartLine, beforeEndLine, false); - final Location after = new Location(path, afterStartLine, afterEndLine, false); - final ChangedLocation changedLocation = new ChangedLocation(before, after, false); - changedLocations.add(changedLocation); - } - } - } - - catch (final IOException e) { - e.printStackTrace(); - } - - return changedLocations; - } - - private Location moveWarningLocation(final Location warningLocation, - final List changedLocations) { - - int moved = 0; - for (final ChangedLocation cl : changedLocations) { - - if (cl.before.endLine < warningLocation.startLine) { - moved += - (cl.after.endLine - cl.after.startLine) - (cl.before.endLine - cl.before.startLine); - } - - else if (warningLocation.endLine < cl.before.startLine) { - // do nothing - } - - else { - final String movedPath = warningLocation.path; - final int movedStartLine = warningLocation.startLine + moved; - final int movedEndLine = warningLocation.endLine + moved; - - final int sizeOfBeforeChange = cl.before.endLine - cl.before.startLine; - final int sizeOfAfterChange = cl.after.endLine - cl.after.startLine; - if (0 < sizeOfBeforeChange && 0 < sizeOfAfterChange) { - return new Location_REPLACEMENT(movedPath, movedStartLine, movedEndLine, false); - } else if (0 < sizeOfBeforeChange) { - return new Location_DELETION(movedPath, movedStartLine, movedEndLine, false); - } else if (0 < sizeOfAfterChange) { - return new Location_ADDITION(movedPath, movedStartLine, movedEndLine, false); - } else { - return new Location_UNKNOWN(movedPath, movedStartLine, movedEndLine, false); - } - } - } - - final Location movedWarningLocation = new Location(warningLocation.path, - warningLocation.startLine + moved, warningLocation.endLine + moved, false); - return movedWarningLocation; - } -} diff --git a/src/nh3/ammonia/BugFixDBMaker.java b/src/nh3/ammonia/BugFixDBMaker.java index b1d01bd..415c10c 100644 --- a/src/nh3/ammonia/BugFixDBMaker.java +++ b/src/nh3/ammonia/BugFixDBMaker.java @@ -5,7 +5,6 @@ public class BugFixDBMaker { public static void main(final String[] args) { BugFixRevisionsMaker.main(args); BugFixChangesMaker.main(args); - // BugFixChangesUpdater.main(args); BugFixPatternsMaker.main(args); } } diff --git a/src/nh3/ammonia/BugFixDBMakerWithoutFB.java b/src/nh3/ammonia/BugFixDBMakerWithoutFB.java deleted file mode 100644 index c4e0c11..0000000 --- a/src/nh3/ammonia/BugFixDBMakerWithoutFB.java +++ /dev/null @@ -1,10 +0,0 @@ -package nh3.ammonia; - -public class BugFixDBMakerWithoutFB { - - public static void main(final String[] args) { - BugFixRevisionsMaker.main(args); - BugFixChangesMaker.main(args); - BugFixPatternsMaker.main(args); - } -} diff --git a/src/nh3/ammonia/BugInstance.java b/src/nh3/ammonia/BugInstance.java deleted file mode 100644 index 179d9dd..0000000 --- a/src/nh3/ammonia/BugInstance.java +++ /dev/null @@ -1,111 +0,0 @@ -package nh3.ammonia; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class BugInstance { - - static public Set getBugInstances(final Collection instances, - final BugPattern pattern) { - - final Set subset = new HashSet<>(); - for (final BugInstance instance : instances) { - if (instance.pattern.equals(pattern)) { - subset.add(instance); - } - } - - return subset; - } - - final public BugPattern pattern; - final public int rank; - final public int priority; - final public String hash; - - final private List sourcelines; - - public BugInstance(final BugPattern pattern, final int rank, final int priority, - final String hash) { - this.pattern = pattern; - this.rank = rank; - this.priority = priority; - this.hash = hash; - this.sourcelines = new ArrayList<>(); - } - - public void addSourceLine(final SourceLine sourceline) { - this.sourcelines.add(sourceline); - } - - public List getSourceLines() { - return new ArrayList(this.sourcelines); - } - - @Override - public int hashCode() { - return this.hash.hashCode(); - } - - @Override - public boolean equals(final Object o) { - - if (!(o instanceof BugInstance)) { - return false; - } - - final BugInstance target = (BugInstance) o; - return this.hash.equals(target.hash); - } - - static public class RankLocationTypeComparator implements Comparator { - - @Override - public int compare(final BugInstance o1, final BugInstance o2) { - - final int rankComparison = Integer.valueOf(o1.rank) - .compareTo(o2.rank); - if (0 != rankComparison) { - return rankComparison; - } - - final int classComparison = o1.getSourceLines() - .get(0) - .compareTo(o2.getSourceLines() - .get(0)); - if (0 != classComparison) { - return classComparison; - } - - final int typeComparison = o1.pattern.type.compareTo(o2.pattern.type); - if (0 != typeComparison) { - return typeComparison; - } - - return 0; - } - } - - @Override - public String toString() { - final StringBuilder text = new StringBuilder(); - text.append("[BugInstance] type: "); - text.append(this.pattern.type); - text.append(", rank: "); - text.append(Integer.toString(this.rank)); - text.append(", priority: "); - text.append(Integer.toString(this.priority)); - text.append(", category: "); - text.append(this.pattern.category); - text.append(System.lineSeparator()); - for (final SourceLine sourceline : this.sourcelines) { - text.append(sourceline.toString()); - text.append(System.lineSeparator()); - } - return text.toString(); - } -} diff --git a/src/nh3/ammonia/BugPattern.java b/src/nh3/ammonia/BugPattern.java deleted file mode 100644 index 4c37f42..0000000 --- a/src/nh3/ammonia/BugPattern.java +++ /dev/null @@ -1,288 +0,0 @@ -package nh3.ammonia; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; - -public class BugPattern implements Comparable { - - final static public String[] NAMES = new String[] {"SQL_BAD_RESULTSET_ACCESS", - "SQL_BAD_PREPARED_STATEMENT_ACCESS", "RE_BAD_SYNTAX_FOR_REGULAR_EXPRESSION", - "RE_POSSIBLE_UNINTENDED_PATTERN", "RE_CANT_USE_FILE_SEPARATOR_AS_REGULAR_EXPRESSION", - "RV_CHECK_FOR_POSITIVE_INDEXOF", "RV_DONT_JUST_NULL_CHECK_READLINE", "NP_BOOLEAN_RETURN_NULL", - "CN_IDIOM", "CN_IDIOM_NO_SUPER_CALL", "CN_IMPLEMENTS_CLONE_BUT_NOT_CLONEABLE", - "CI_CONFUSED_INHERITANCE", "IA_AMBIGUOUS_INVOCATION_OF_INHERITED_OR_OUTER_METHOD", - "HRS_REQUEST_PARAMETER_TO_HTTP_HEADER", "HRS_REQUEST_PARAMETER_TO_COOKIE", - "XSS_REQUEST_PARAMETER_TO_JSP_WRITER", "XSS_REQUEST_PARAMETER_TO_SERVLET_WRITER", - "XSS_REQUEST_PARAMETER_TO_SEND_ERROR", "IMSE_DONT_CATCH_IMSE", "DE_MIGHT_DROP", - "DE_MIGHT_IGNORE", "DMI_EMPTY_DB_PASSWORD", "DMI_CONSTANT_DB_PASSWORD", - "DMI_USELESS_SUBSTRING", "DMI_HARDCODED_ABSOLUTE_FILENAME", - "NP_IMMEDIATE_DEREFERENCE_OF_READLINE", "RV_01_TO_INT", "DM_DEFAULT_ENCODING", - "DM_RUN_FINALIZERS_ON_EXIT", "DM_STRING_CTOR", "DM_STRING_VOID_CTOR", "DM_STRING_TOSTRING", - "DM_GC", "DM_BOOLEAN_CTOR", "DM_EXIT", "DM_BOXED_PRIMITIVE_TOSTRING", "DM_NEW_FOR_GETCLASS", - "DM_NEXTINT_VIA_NEXTDOUBLE", "DM_USELESS_THREAD", "DM_MONITOR_WAIT_ON_CONDITION", - "DMI_CALLING_NEXT_FROM_HASNEXT", "BIT_IOR_OF_SIGNED_BYTE", - "INT_BAD_COMPARISON_WITH_NONNEGATIVE_VALUE", "INT_BAD_COMPARISON_WITH_SIGNED_BYTE", - "INT_BAD_REM_BY_1", "DMI_ANNOTATION_IS_NOT_VISIBLE_TO_REFLECTION", "INT_VACUOUS_COMPARISON", - "BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS", "DMI_RANDOM_USED_ONLY_ONCE", - "DMI_LONG_BITS_TO_DOUBLE_INVOKED_ON_INT", "DMI_THREAD_PASSED_WHERE_RUNNABLE_EXPECTED", - "DB_DUPLICATE_BRANCHES", "DB_DUPLICATE_SWITCH_CLAUSES", "AM_CREATES_EMPTY_ZIP_FILE_ENTRY", - "AM_CREATES_EMPTY_JAR_FILE_ENTRY", "FI_FINALIZER_NULLS_FIELDS", - "FI_FINALIZER_ONLY_NULLS_FIELDS", "BC_BAD_CAST_TO_CONCRETE_COLLECTION", - "BC_BAD_CAST_TO_ABSTRACT_COLLECTION", "BC_UNCONFIRMED_CAST", "BC_IMPOSSIBLE_CAST", - "BC_IMPOSSIBLE_INSTANCEOF", "BC_VACUOUS_INSTANCEOF", "NP_NULL_INSTANCEOFY", - "QF_QUESTIONABLE_FOR_LOOP", "DLS_DEAD_LOCAL_STORE", "IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN", - "DLS_DEAD_LOCAL_STORE_OF_NULL", "DLS_DEAD_STORE_OF_CLASS_LITERAL", "DC_DOUBLECHECK", - "ESync_EMPTY_SYNC", "FI_PUBLIC_SHOULD_BE_PROTECTED", "FI_EMPTY", "FI_NULLIFY_SUPER", - "FI_USELESS", "FI_MISSING_SUPER_CALL", "FI_EXPLICIT_INVOCATION", "FE_FLOATING_POINT_EQUALITY", - "FE_TEST_IF_EQUAL_TO_NOT_A_NUMBER", "EQ_DONT_DEFINE_EQUALS_FOR_ENUM", "EQ_SELF_USE_OBJECT", - "EQ_SELF_NO_OBJECT", "CO_SELF_NO_OBJECT", "HE_HASHCODE_USE_OBJECT_EQUALS", - "HE_HASHCODE_NO_EQUALS", "HE_EQUALS_USE_HASHCODE", "HE_EQUALS_NO_HASHCODE", - "HE_INHERITS_EQUALS_USE_HASHCODE", "CO_ABSTRACT_SELF", "EQ_ABSTRACT_SELF", - "HE_USE_OF_UNHASHABLE_CLASS", "EQ_COMPARETO_USE_OBJECT_EQUALS", "EQ_DOESNT_OVERRIDE_EQUALS", - "EQ_OTHER_USE_OBJECT", "EQ_OTHER_NO_OBJECT", "IS2_INCONSISTENT_SYNC", "IS_FIELD_NOT_GUARDED", - "MSF_MUTABLE_SERVLET_FIELD", "JLM_JSR166_LOCK_MONITORENTER", "MF_METHOD_MASKS_FIELD", - "MF_CLASS_MASKS_FIELD", "MWN_MISMATCHED_WAIT", "MWN_MISMATCHED_NOTIFY", "NN_NAKED_NOTIFY", - "J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION", "NS_NON_SHORT_CIRCUIT", - "NS_DANGEROUS_NON_SHORT_CIRCUIT", "NP_NULL_ON_SOME_PATH_MIGHT_BE_INFEASIBLE", - "NP_TOSTRING_COULD_RETURN_NULL", "NP_CLONE_COULD_RETURN_NULL", "NP_ALWAYS_NULL_EXCEPTION", - "NP_ALWAYS_NULL", "NP_STORE_INTO_NONNULL_FIELD", "NP_NULL_ON_SOME_PATH_EXCEPTION", - "NP_NULL_ON_SOME_PATH", "NP_NULL_PARAM_DEREF_NONVIRTUAL", - "NP_NULL_PARAM_DEREF_ALL_TARGETS_DANGEROUS", "NP_NULL_PARAM_DEREF", - "RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE", "RCN_REDUNDANT_NULLCHECK_OF_NULL_VALUE", - "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE", "RCN_REDUNDANT_COMPARISON_TWO_NULL_VALUES", - "RCN_REDUNDANT_COMPARISON_OF_NULL_AND_NONNULL_VALUE", - "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", "NP_GUARANTEED_DEREF", - "NP_GUARANTEED_DEREF_ON_EXCEPTION_PATH", "NP_EQUALS_SHOULD_HANDLE_NULL_ARGUMENT", - "NP_ARGUMENT_MIGHT_BE_NULL", "OS_OPEN_STREAM", "OS_OPEN_STREAM_EXCEPTION_PATH", - "ODR_OPEN_DATABASE_RESOURCE", "ODR_OPEN_DATABASE_RESOURCE_EXCEPTION_PATH", - "DLS_DEAD_LOCAL_STORE_IN_RETURN", "EC_BAD_ARRAY_COMPARE", "DLS_OVERWRITTEN_INCREMENT", - "ICAST_BAD_SHIFT_AMOUNT", "ICAST_QUESTIONABLE_UNSIGNED_RIGHT_SHIFT", "DMI_BAD_MONTH", - "IM_MULTIPLYING_RESULT_OF_IREM", "IM_BAD_CHECK_FOR_ODD", "DMI_INVOKING_TOSTRING_ON_ARRAY", - "DMI_INVOKING_TOSTRING_ON_ANONYMOUS_ARRAY", "IM_AVERAGE_COMPUTATION_COULD_OVERFLOW", - "IC_SUPERCLASS_USES_SUBCLASS_DURING_INITIALIZATION", "ICAST_INTEGER_MULTIPLY_CAST_TO_LONG", - "BX_UNBOXED_AND_COERCED_FOR_TERNARY_OPERATOR", "BX_BOXING_IMMEDIATELY_UNBOXED", - "BX_BOXING_IMMEDIATELY_UNBOXED_TO_PERFORM_COERCION", "VA_FORMAT_STRING_ARG_MISMATCH", - "ES_COMPARING_STRINGS_WITH_EQ", "ES_COMPARING_PARAMETER_STRING_WITH_EQ", "RC_REF_COMPARISON", - "EC_UNRELATED_TYPES", "EC_NULL_ARG", "EC_UNRELATED_CLASS_AND_INTERFACE", - "EC_UNRELATED_INTERFACES", "EC_ARRAY_AND_NONARRAY", "EC_BAD_ARRAY_COMPARE", - "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", "MS_EXPOSE_REP", "MS_SHOULD_BE_FINAL", - "RU_INVOKE_RUN", "SA_FIELD_SELF_COMPARISON", "SA_LOCAL_SELF_COMPARISON", - "SA_FIELD_SELF_COMPUTATION", "SA_LOCAL_SELF_COMPUTATION", "SA_FIELD_DOUBLE_ASSIGNMENT", - "SA_FIELD_SELF_COMPARISON", "SA_LOCAL_SELF_COMPARISON", "SA_FIELD_SELF_COMPUTATION", - "SA_LOCAL_SELF_COMPUTATION", "SWL_SLEEP_WITH_LOCK_HELD", "SP_SPIN_ON_FIELD", - "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE", - "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING", "TLW_TWO_LOCK_WAIT", - "UW_UNCOND_WAIT", "UR_UNINIT_READ", "GC_UNRELATED_TYPES", "UL_UNRELEASED_LOCK", - "UL_UNRELEASED_LOCK_EXCEPTION_PATH", "UG_SYNC_SET_UNSYNC_GET", "UCF_USELESS_CONTROL_FLOW", - "UCF_USELESS_CONTROL_FLOW_NEXT_LINE", "ICAST_IDIV_CAST_TO_DOUBLE", - "ICAST_INT_CAST_TO_DOUBLE_PASSED_TO_CEIL", "ICAST_INT_CAST_TO_FLOAT_PASSED_TO_ROUND", - "BIT_AND", "BIT_AND_ZZ", "BIT_IOR", "BIT_SIGNED_CHECK", "BIT_SIGNED_CHECK_HIGH_BIT", - "ITA_INEFFICIENT_TO_ARRAY", "IL_INFINITE_LOOP", "IL_INFINITE_RECURSIVE_LOOP", - "IL_CONTAINER_ADDED_TO_ITSELF", "IL_INFINITE_RECURSIVE_LOOP", "IL_CONTAINER_ADDED_TO_ITSELF", - "UI_INHERITANCE_UNSAFE_GETRESOURCE", "SI_INSTANCE_BEFORE_FINALS_ASSIGNED", - "IC_INIT_CIRCULARITY", "ISC_INSTANTIATE_STATIC_CLASS", "LI_LAZY_INIT_STATIC", - "LI_LAZY_INIT_UPDATE_STATIC", "NP_LOAD_OF_KNOWN_NULL_VALUE", "RV_RETURN_VALUE_IGNORED", - "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", "RV_EXCEPTION_NOT_THROWN", - "MTIA_SUSPECT_STRUTS_INSTANCE_FIELD", "MTIA_SUSPECT_SERVLET_INSTANCE_FIELD", - "ML_SYNC_ON_UPDATED_FIELD", "NM_WRONG_PACKAGE", "NM_WRONG_PACKAGE_INTENTIONAL", - "NM_VERY_CONFUSING", "NM_VERY_CONFUSING_INTENTIONAL", "NM_CONFUSING", - "NM_METHOD_CONSTRUCTOR_CONFUSION", "NM_LCASE_HASHCODE", "NM_LCASE_TOSTRING", "NM_BAD_EQUAL", - "NM_CLASS_NAMING_CONVENTION", "NM_FIELD_NAMING_CONVENTION", "NM_METHOD_NAMING_CONVENTION", - "NM_CLASS_NOT_EXCEPTION", "NM_SAME_SIMPLE_NAME_AS_SUPERCLASS", - "NM_SAME_SIMPLE_NAME_AS_INTERFACE", "NM_FUTURE_KEYWORD_USED_AS_IDENTIFIER", "DM_NUMBER_CTOR", - "DM_FP_NUMBER_CTOR", "EQ_OVERRIDING_EQUALS_NOT_SYMMETRIC", "EQ_ALWAYS_TRUE", - "EQ_ALWAYS_FALSE", "EQ_COMPARING_CLASS_NAMES", "EQ_UNUSUAL", "EQ_GETCLASS_AND_CLASS_CONSTANT", - "PZLA_PREFER_ZERO_LENGTH_ARRAYS", "PS_PUBLIC_SEMAPHORES", - "QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT", "RR_NOT_CHECKED", "SR_NOT_CHECKED", - "REC_CATCH_EXCEPTION", "SC_START_IN_CTOR", "STCAL_STATIC_CALENDAR_INSTANCE", - "STCAL_STATIC_SIMPLE_DATE_FORMAT_INSTANCE", "STCAL_INVOKE_ON_STATIC_CALENDAR_INSTANCE", - "STCAL_INVOKE_ON_STATIC_DATE_FORMAT_INSTANCE", "SBSC_USE_STRINGBUFFER_CONCATENATION", - "SIO_SUPERFLUOUS_INSTANCEOF", "STI_INTERRUPTED_ON_CURRENTTHREAD", - "NP_SYNC_AND_NULL_CHECK_FIELD", "WL_USING_GETCLASS_RATHER_THAN_CLASS_LITERAL", - "ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD", "DMI_BLOCKING_METHODS_ON_URL", - "UM_UNNECESSARY_MATH", "NP_UNWRITTEN_FIELD", "UWF_NULL_FIELD", "SS_SHOULD_BE_STATIC", - "SIC_INNER_SHOULD_BE_STATIC", "SIC_INNER_SHOULD_BE_STATIC_ANON", - "SIC_INNER_SHOULD_BE_STATIC_NEEDS_THIS", "USM_USELESS_SUBCLASS_METHOD", - "USM_USELESS_ABSTRACT_METHOD", "VA_PRIMITIVE_ARRAY_PASSED_TO_OBJECT_VARARG", - "VO_VOLATILE_REFERENCE_TO_ARRAY", "WA_NOT_IN_LOOP", "WA_AWAIT_NOT_IN_LOOP", - "NO_NOTIFY_NOT_NOTIFYALL", "WMI_WRONG_MAP_ITERATOR", "XFB_XML_FACTORY_BYPASS", - "EI_EXPOSE_REP", "OBL_UNSATISFIED_OBLIGATION", "OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE", - "SE_BAD_FIELD", "UC_USELESS_CONDITION", "URF_UNREAD_FIELD", - "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD", "UUF_UNUSED_FIELD", - "DP_CREATE_CLASSLOADER_INSIDE_DO_PRIVILEGED", "EI_EXPOSE_REP2", "MS_PKGPROTECT", - "SA_FIELD_SELF_ASSIGNMENT", "SF_SWITCH_NO_DEFAULT", "UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD", - "DMI_INVOKING_HASHCODE_ON_ARRAY", "INT_VACUOUS_BIT_OPERATION", - "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", "EI_EXPOSE_STATIC_REP2", "SE_BAD_FIELD_STORE", - "SE_COMPARATOR_SHOULD_BE_SERIALIZABLE", "RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN", - "SE_NO_SERIALVERSIONID", "RV_NEGATING_RESULT_OF_COMPARETO", "DMI_COLLECTION_OF_URLS", - "INT_BAD_COMPARISON_WITH_INT_VALUE", "RpC_REPEATED_CONDITIONAL_TEST", - "DM_BOXED_PRIMITIVE_FOR_PARSING", "MS_OOI_PKGPROTECT"}; - - final static private Map PATTERNS = new HashMap<>(); - - // static { - // for (final String name : NAMES) { - // PATTERNS.put(name, new BugPattern(name)); - // } - // } - - public static BugPattern getBugPattern(final String name) { - return PATTERNS.get(name); - } - - static public SortedSet getBugPatterns() { - final SortedSet patterns = new TreeSet<>(); - patterns.addAll(PATTERNS.values()); - return patterns; - } - - static public void addBugPattern(final BugPattern pattern) { - PATTERNS.put(pattern.type, pattern); - } - - final public String type; - final public String category; - final private Map> instances; - - public BugPattern(final String type, final String category) { - this.type = type; - this.category = category; - this.instances = new HashMap>(); - } - - public void addBugInstance(final Object version, final BugInstance instance) { - List bugs = this.instances.get(version); - if (null == bugs) { - bugs = new ArrayList(); - this.instances.put(version, bugs); - } - bugs.add(instance); - } - - public SortedSet getBugInstances(final Object version) { - final SortedSet instances = new TreeSet<>(); - if (this.instances.containsKey(version)) { - instances.addAll(this.instances.get(version)); - } - return instances; - } - - public Float getAverageRank() { - int sum = 0; - final List ranks = this.getRanks(); - for (final Integer value : ranks) { - sum += value.intValue(); - } - return Float.valueOf((float) sum / (float) ranks.size()); - } - - public Float getAveragePriority() { - int sum = 0; - final List priorities = this.getPriorities(); - for (final Integer value : priorities) { - sum += value.intValue(); - } - return Float.valueOf((float) sum / (float) priorities.size()); - } - - public String getRankText() { - final List ranks = this.getRanks(); - Collections.sort(ranks); - final int firstValue = ranks.get(0); - final int lastValue = ranks.get(ranks.size() - 1); - if (firstValue == lastValue) { - return Integer.toString(firstValue); - } else { - final StringBuilder text = new StringBuilder(); - text.append(this.getAverageRank() - .toString()); - text.append(" ( from "); - text.append(Integer.toString(firstValue)); - text.append(" to "); - text.append(Integer.toString(lastValue)); - text.append(")"); - - return text.toString(); - } - } - - public String getPriorityText() { - final List priorities = this.getPriorities(); - Collections.sort(priorities); - final int firstValue = priorities.get(0); - final int lastValue = priorities.get(priorities.size() - 1); - if (firstValue == lastValue) { - return Integer.toString(firstValue); - } else { - final StringBuilder text = new StringBuilder(); - text.append(this.getAveragePriority() - .toString()); - text.append(" ( from "); - text.append(Integer.toString(firstValue)); - text.append(" to "); - text.append(Integer.toString(lastValue)); - text.append(" )"); - - return text.toString(); - } - } - - public List getRanks() { - final List ranks = new ArrayList(); - for (final List instances : this.instances.values()) { - for (final BugInstance instance : instances) { - ranks.add(instance.rank); - } - } - return ranks; - } - - public List getPriorities() { - final List priorities = new ArrayList(); - for (final List instances : this.instances.values()) { - for (final BugInstance instance : instances) { - priorities.add(instance.priority); - } - } - return priorities; - } - - @Override - public int compareTo(final BugPattern target) { - - final int rankComparison = this.getAverageRank() - .compareTo(target.getAverageRank()); - if (0 != rankComparison) { - return rankComparison; - } - - final int priorityComparison = this.getAveragePriority() - .compareTo(target.getAveragePriority()); - if (0 != priorityComparison) { - return priorityComparison; - } - - final int categoryComparison = this.category.compareTo(target.category); - if (0 != categoryComparison) { - return categoryComparison; - } - - final int typeComparison = this.type.compareTo(target.type); - return typeComparison; - } - - @Override - public String toString() { - final StringBuilder text = new StringBuilder(); - text.append("[BugPattern] type: "); - text.append(this.type); - text.append(", category: "); - text.append(this.category); - return text.toString(); - } -} diff --git a/src/nh3/ammonia/ChangedLocation.java b/src/nh3/ammonia/ChangedLocation.java deleted file mode 100644 index 3025b83..0000000 --- a/src/nh3/ammonia/ChangedLocation.java +++ /dev/null @@ -1,14 +0,0 @@ -package nh3.ammonia; - -public class ChangedLocation { - - final public Location before; - final public Location after; - final public boolean bugfix; - - public ChangedLocation(final Location before, final Location after, final boolean bugfix) { - this.before = before; - this.after = after; - this.bugfix = bugfix; - } -} diff --git a/src/nh3/ammonia/ClassStats.java b/src/nh3/ammonia/ClassStats.java deleted file mode 100644 index 30cec93..0000000 --- a/src/nh3/ammonia/ClassStats.java +++ /dev/null @@ -1,53 +0,0 @@ -package nh3.ammonia; - -import java.util.SortedSet; -import java.util.TreeSet; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -public class ClassStats implements Comparable { - - static public SortedSet getClassNames(final SortedSet classes) { - final SortedSet names = new TreeSet<>(); - for (final ClassStats c : classes) { - names.add(c.classname); - } - return names; - } - - static public ClassStats makeClassStats(final Node node) { - if (node.getNodeName() - .equals("ClassStats")) { - final NamedNodeMap nnMap = node.getAttributes(); - final String classname = nnMap.getNamedItem("class") - .getNodeValue(); - final int bugs = Integer.parseInt(nnMap.getNamedItem("bugs") - .getNodeValue()); - return new ClassStats(classname, bugs); - } - return null; - } - - final public String classname; - final public int bugs; - - private ClassStats(final String classname, final int bugs) { - this.classname = classname; - this.bugs = bugs; - } - - @Override - public int compareTo(final ClassStats target) { - return this.classname.compareTo(target.classname); - } - - @Override - public String toString() { - final StringBuilder text = new StringBuilder(); - text.append("class name: "); - text.append(this.classname); - text.append(", bugs: "); - text.append(Integer.toString(this.bugs)); - return text.toString(); - } -} diff --git a/src/nh3/ammonia/db/DAO.java b/src/nh3/ammonia/DAO.java similarity index 99% rename from src/nh3/ammonia/db/DAO.java rename to src/nh3/ammonia/DAO.java index 15752ce..b190a18 100644 --- a/src/nh3/ammonia/db/DAO.java +++ b/src/nh3/ammonia/DAO.java @@ -1,4 +1,4 @@ -package nh3.ammonia.db; +package nh3.ammonia; import java.io.BufferedReader; import java.io.FileInputStream; @@ -19,7 +19,6 @@ import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; -import nh3.ammonia.FBParserConfig; public class DAO { diff --git a/src/nh3/ammonia/FBChangePatternFinder.java b/src/nh3/ammonia/FBChangePatternFinder.java deleted file mode 100644 index 951837f..0000000 --- a/src/nh3/ammonia/FBChangePatternFinder.java +++ /dev/null @@ -1,835 +0,0 @@ -package nh3.ammonia; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import nh3.ammonia.db.DAO; -import nh3.ammonia.db.DAO.CHANGE_SQL; -import nh3.ammonia.db.DAO.PATTERN_SQL; -import nh3.ammonia.db.DAO.REVISION_SQL; -import org.apache.poi.hssf.util.CellRangeAddress; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.Comment; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNDirEntry; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNLogClient; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNWCClient; -import yoshikihigo.cpanalyzer.CPAConfig; -import yoshikihigo.cpanalyzer.LANGUAGE; -import yoshikihigo.cpanalyzer.StringUtility; -import yoshikihigo.cpanalyzer.data.Statement; - -public class FBChangePatternFinder { - - public static void main(final String[] args) { - - FBParserConfig.initialize(args); - final String trFile = FBParserConfig.getInstance() - .getTRANSITIONRESULT(); - final String cpFile = FBParserConfig.getInstance() - .getCHANGEPATTERN(); - final String fcpFile = FBParserConfig.getInstance() - .getFIXCHANGEPATTERN(); - final DAO dao = DAO.getInstance(); - - final Map foundPatternIDs = new HashMap<>(); - try (final PrintWriter writer = new PrintWriter( - new BufferedWriter(new OutputStreamWriter(new FileOutputStream(cpFile), "UTF-8")))) { - - final List lines = Files.readAllLines(Paths.get(trFile), Charset.forName("UTF-8")); - final String trTitle = lines.get(0); - writer.print(trTitle); - writer.println(", CHANGEPATTERN-ID, CHANGEPATTERN-SUPPORT"); - - lines.remove(0); - lines.stream() - .forEach(line -> { - final Line l = new Line(line); - if (!l.status.startsWith("removed")) { - return; - } - if ((l.startstartline <= 0) || (l.startendline <= 0)) { - return; - } - - final List changes = - dao.getChanges(Integer.toString(Integer.parseInt(l.endrev) + 1)); - for (final CHANGE_SQL change : changes) { - - if (!change.filepath.endsWith(l.path)) { - continue; - } - - if (change.beforeEndLine < l.startstartline) { - continue; - } - - if (l.startendline < change.beforeStartLine) { - continue; - } - - final List cps = - dao.getChangePatterns(change.beforeHash, change.afterHash); - - for (final PATTERN_SQL cp : cps) { - writer.print(line); - writer.print(", "); - writer.print(cp.id); - writer.print(", "); - writer.println(getChanges(cp).size()); - AtomicInteger number = foundPatternIDs.get(cp.id); - if (null == number) { - number = new AtomicInteger(0); - foundPatternIDs.put(cp.id, number); - } - number.addAndGet(1); - } - } - }); - - } catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - - try (final Workbook book = new XSSFWorkbook(); - final OutputStream stream = new FileOutputStream(fcpFile)) { - - Cell firstCell = null; - Cell lastCell = null; - - final Sheet sheet = book.createSheet(); - book.setSheetName(0, "change patterns"); - final Row titleRow = sheet.createRow(0); - titleRow.createCell(0) - .setCellValue("PATTERN-ID"); - titleRow.createCell(1) - .setCellValue("FINDBUGS-SUPPORT"); - titleRow.createCell(2) - .setCellValue("AUTHORS"); - titleRow.createCell(3) - .setCellValue("BUG-FIX-AUTHORS"); - titleRow.createCell(4) - .setCellValue("FILES"); - titleRow.createCell(5) - .setCellValue("BUG-FIX-FILES"); - titleRow.createCell(6) - .setCellValue("SUPPORT"); - titleRow.createCell(7) - .setCellValue("BUG-FIX-SUPPORT"); - titleRow.createCell(8) - .setCellValue("BEFORE-TEXT-SUPPORT"); - titleRow.createCell(9) - .setCellValue("CONFIDENCE1"); - titleRow.createCell(10) - .setCellValue("CONFIDENCE2"); - titleRow.createCell(11) - .setCellValue("CONFIDENCE3"); - titleRow.createCell(12) - .setCellValue("COMMITS"); - titleRow.createCell(13) - .setCellValue("BUG-FIX-COMMIT"); - titleRow.createCell(14) - .setCellValue("FIRST-DATE"); - titleRow.createCell(15) - .setCellValue("LAST-DATE"); - titleRow.createCell(16) - .setCellValue("DATE-DIFFERENCE"); - titleRow.createCell(17) - .setCellValue("OCCUPANCY"); - titleRow.createCell(18) - .setCellValue("Delta-PFCF"); - titleRow.createCell(19) - .setCellValue("TEXT-BEFORE-CHANGE"); - titleRow.createCell(20) - .setCellValue("TEXT-AFTER-CHANGE"); - titleRow.createCell(21) - .setCellValue("AUTHOR-LIST"); - titleRow.createCell(22) - .setCellValue("BUG-FIX-AUTHOR-LIST"); - titleRow.createCell(23) - .setCellValue("FILE-LIST"); - titleRow.createCell(24) - .setCellValue("BUG-FIX-FILE-LIST"); - - final int bugfixCommits = (int) DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> revision.bugfix) - .count(); - titleRow.createCell(25) - .setCellValue(bugfixCommits); - final int nonbugfixCommits = (int) DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> !revision.bugfix) - .count(); - titleRow.createCell(26) - .setCellValue(nonbugfixCommits); - - firstCell = titleRow.getCell(0); - lastCell = titleRow.getCell(24); - - setCellComment(titleRow.getCell(2), "Higo", - "the number of authors that committed the change pattern in all commits", 5, 2); - setCellComment(titleRow.getCell(3), "Higo", - "the number of authors commited the change pattern in bug-fix commits", 5, 2); - setCellComment(titleRow.getCell(4), "Higo", - "the number of files where the change pattern appeared in all commits", 5, 2); - setCellComment(titleRow.getCell(5), "Higo", - "the number of files where the change pattern appeared in bug-fix commits", 5, 2); - setCellComment(titleRow.getCell(6), "Higo", "the number of occurences of a given pattern", 4, - 1); - setCellComment(titleRow.getCell(7), "Higo", - "the number of occurences of a given pattern in bug-fix commits", 4, 2); - setCellComment(titleRow.getCell(8), "Higo", - "the number of code fragments whose texts are " - + "identical to before-text of a given pattern " - + "in the commit where the pattern appears initially", - 4, 3); - setCellComment(titleRow.getCell(9), "Higo", "BUG-FIX-SUPPORT / SUPPORT", 4, 2); - setCellComment(titleRow.getCell(10), "Higo", "SUPPORT / BEFORE-TEXT-SUPPORT", 4, 2); - setCellComment(titleRow.getCell(11), "Higo", "BUG-FIX-SUPPORT / BEFORE-TEXT-SUPPORT", 4, 2); - setCellComment(titleRow.getCell(12), "Higo", - "the number of commits where the pattern appears", 4, 2); - setCellComment(titleRow.getCell(13), "Higo", - "the number of bug-fix commits where the pattern appears", 4, 2); - setCellComment(titleRow.getCell(17), "Higo", - "average of (LOC of a given pattern changed in revision R) / " - + "(total LOC changed in revision R) " - + "for all the revisions where the pattern appears", - 4, 3); - setCellComment(titleRow.getCell(18), "Higo", - "delta-CFPF was calculated with the following formula" + System.lineSeparator() - + "pf*(cf1 - cf2)" + System.lineSeparator() - + "pf: pattern frequency, which is calculated as support / before-text-support" - + System.lineSeparator() - + "cf1: bug-fix commit frequensy, which is calculated as bug-fix commits / all bug-fix commits" - + System.lineSeparator() - + "cf2: non-bug-fix commit frequency, which is calculated as non-bug-fix commits / all non-bug-fix commits", - 5, 5); - - int currentRow = 1; - final List cps = dao.getFixChangePatterns(); - // Collections.sort(cps, (o1, o2) -> Integer.compare(o1.id, o2.id)); - Collections.sort(cps, (o1, o2) -> o1.firstdate.compareTo(o2.firstdate)); - for (final PATTERN_SQL cp : cps) { - - if (cp.beforeNText.isEmpty()) { - continue; - } - - final int findBugsSupport = foundPatternIDs.containsKey(cp.id) ? foundPatternIDs.get(cp.id) - .get() : 0; - - final Row dataRow = sheet.createRow(currentRow++); - dataRow.createCell(0) - .setCellValue(cp.id); - dataRow.createCell(1) - .setCellValue(findBugsSupport); - dataRow.createCell(2) - .setCellValue(getAuthors(cp).size()); - dataRow.createCell(3) - .setCellValue(getAuthors(cp, true).size()); - dataRow.createCell(4) - .setCellValue(getFiles(cp).size()); - dataRow.createCell(5) - .setCellValue(getFiles(cp, true).size()); - final int support = getChanges(cp).size(); - final int bugfixSupport = getChanges(cp, true).size(); - final int beforeTextSupport = support;// countTextAppearances(cp); - dataRow.createCell(6) - .setCellValue(support); - dataRow.createCell(7) - .setCellValue(bugfixSupport); - dataRow.createCell(8) - .setCellValue(beforeTextSupport); - dataRow.createCell(9) - .setCellValue((float) bugfixSupport / (float) support); - dataRow.createCell(10) - .setCellValue((float) support / (float) beforeTextSupport); - dataRow.createCell(11) - .setCellValue((float) bugfixSupport / (float) beforeTextSupport); - dataRow.createCell(12) - .setCellValue(getCommits(cp)); - dataRow.createCell(13) - .setCellValue(getCommits(cp, true)); - dataRow.createCell(14) - .setCellValue(cp.firstdate); - dataRow.createCell(15) - .setCellValue(cp.lastdate); - dataRow.createCell(16) - .setCellValue(getDayDifference(cp.firstdate, cp.lastdate)); - dataRow.createCell(17) - .setCellValue(getOccupancy(cp)); - dataRow.createCell(18) - .setCellValue(getDeltaCFPF(cp, beforeTextSupport)); - dataRow.createCell(19) - .setCellValue(cp.beforeNText); - dataRow.createCell(20) - .setCellValue(cp.afterNText); - dataRow.createCell(21) - .setCellValue(nh3.ammonia.StringUtility.concatinate(getAuthors(cp))); - dataRow.createCell(22) - .setCellValue(nh3.ammonia.StringUtility.concatinate(getAuthors(cp, true))); - dataRow.createCell(23) - .setCellValue(nh3.ammonia.StringUtility - .shrink(nh3.ammonia.StringUtility.concatinate(getFiles(cp)), 10000)); - dataRow.createCell(24) - .setCellValue(nh3.ammonia.StringUtility - .shrink(nh3.ammonia.StringUtility.concatinate(getFiles(cp, true)), 10000)); - lastCell = dataRow.getCell(24); - - final CellStyle style = book.createCellStyle(); - style.setWrapText(true); - style.setFillPattern(CellStyle.SOLID_FOREGROUND); - style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); - style.setBorderBottom(XSSFCellStyle.BORDER_THIN); - style.setBorderLeft(XSSFCellStyle.BORDER_THIN); - style.setBorderRight(XSSFCellStyle.BORDER_THIN); - style.setBorderTop(XSSFCellStyle.BORDER_THIN); - style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); - for (int column = 0; column <= 24; column++) { - dataRow.getCell(column) - .setCellStyle(style); - } - - int loc = Math.max(getLOC(cp.beforeNText), getLOC(cp.afterNText)); - dataRow.setHeight((short) (loc * dataRow.getHeight())); - } - - sheet.autoSizeColumn(0, true); - sheet.autoSizeColumn(1, true); - sheet.autoSizeColumn(2, true); - sheet.autoSizeColumn(3, true); - sheet.autoSizeColumn(4, true); - sheet.autoSizeColumn(5, true); - sheet.autoSizeColumn(6, true); - sheet.autoSizeColumn(7, true); - sheet.autoSizeColumn(8, true); - sheet.autoSizeColumn(9, true); - sheet.autoSizeColumn(10, true); - sheet.autoSizeColumn(11, true); - sheet.autoSizeColumn(12, true); - sheet.autoSizeColumn(13, true); - sheet.autoSizeColumn(14, true); - sheet.autoSizeColumn(15, true); - sheet.autoSizeColumn(16, true); - sheet.autoSizeColumn(17, true); - sheet.autoSizeColumn(18, true); - sheet.setColumnWidth(19, 20480); - sheet.setColumnWidth(20, 20480); - sheet.setColumnWidth(21, 5120); - sheet.setColumnWidth(22, 5120); - sheet.setColumnWidth(23, 20480); - sheet.setColumnWidth(24, 20480); - - sheet.setAutoFilter(new CellRangeAddress(firstCell.getRowIndex(), lastCell.getRowIndex(), - firstCell.getColumnIndex(), lastCell.getColumnIndex())); - sheet.createFreezePane(0, 1, 0, 1); - - book.write(stream); - - } catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - } - - private static void setCellComment(final Cell cell, final String author, final String text, - final int width, final int height) { - - final Sheet sheet = cell.getSheet(); - final Workbook workbook = sheet.getWorkbook(); - final CreationHelper helper = workbook.getCreationHelper(); - - final Drawing drawing = sheet.createDrawingPatriarch(); - final ClientAnchor anchor = - drawing.createAnchor(0, 0, 0, 0, (short) 4, 2, (short) (4 + width), (2 + height)); - final Comment comment = drawing.createCellComment(anchor); - comment.setAuthor(author); - comment.setString(helper.createRichTextString(text)); - cell.setCellComment(comment); - } - - private static int getLOC(final String text) { - - int count = 0; - final String newline = System.lineSeparator(); - final Matcher matcher = Pattern.compile(newline) - .matcher(text); - while (matcher.find()) { - count++; - } - return count + 1; - } - - private static int getDayDifference(final String firstdate, final String lastdate) { - - final Calendar calendar1 = Calendar.getInstance(); - { - final StringTokenizer tokenizer1 = new StringTokenizer(firstdate, " :/"); - final String year = tokenizer1.nextToken(); - final String month = tokenizer1.nextToken(); - final String date = tokenizer1.nextToken(); - final String hour = tokenizer1.nextToken(); - final String minute = tokenizer1.nextToken(); - final String second = tokenizer1.nextToken(); - calendar1.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(date), - Integer.parseInt(hour), Integer.parseInt(minute), Integer.parseInt(second)); - } - - final Calendar calendar2 = Calendar.getInstance(); - { - final StringTokenizer tokenizer1 = new StringTokenizer(lastdate, " :/"); - final String year = tokenizer1.nextToken(); - final String month = tokenizer1.nextToken(); - final String date = tokenizer1.nextToken(); - final String hour = tokenizer1.nextToken(); - final String minute = tokenizer1.nextToken(); - final String second = tokenizer1.nextToken(); - calendar2.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(date), - Integer.parseInt(hour), Integer.parseInt(minute), Integer.parseInt(second)); - } - - final long difference = calendar2.getTime() - .getTime() - - calendar1.getTime() - .getTime(); - return (int) (difference / 1000l / 60l / 60l / 24l); - } - - private static int getCommits(final PATTERN_SQL cp) { - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - return (int) DAO.getInstance() - .getChanges(beforeHash, afterHash) - .stream() - .map(change -> change.revision) - .distinct() - .count(); - } - - private static int getCommits(final PATTERN_SQL cp, final boolean bugfix) { - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changesInPattern = DAO.getInstance() - .getChanges(beforeHash, afterHash); - return (int) changesInPattern.stream() - .filter(change -> bugfix == change.bugfix) - .count(); - } - - private static float getOccupancy(final PATTERN_SQL cp) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changesInPattern = DAO.getInstance() - .getChanges(beforeHash, afterHash); - final Map map1 = new HashMap<>(); - final Map map2 = new HashMap<>(); - - final SortedSet revisions = DAO.getInstance() - .getRevisions(beforeHash, afterHash); - for (final REVISION_SQL revision : revisions) { - map1.put(revision, new AtomicInteger(0)); - map2.put(revision, new AtomicInteger(0)); - List changesInRevision = DAO.getInstance() - .getChanges(revision.id); - changesInRevision.stream() - .forEach(change -> { - if (changesInPattern.contains(change)) { - final AtomicInteger size = map1.get(revision); - size.addAndGet(change.beforeEndLine - change.beforeStartLine + 1); - } - final AtomicInteger size = map2.get(revision); - size.addAndGet(change.beforeEndLine - change.beforeStartLine + 1); - }); - } - - float sum = 0; - for (final REVISION_SQL revision : revisions) { - final AtomicInteger numerator = map1.get(revision); - final AtomicInteger denominator = map2.get(revision); - final float occupancy = (float) numerator.get() / (float) denominator.get(); - sum += occupancy; - } - - return sum / revisions.size(); - } - - private static double getDeltaCFPF(final PATTERN_SQL cp, final int beforeTextSupport) { - final double pf = (double) getChanges(cp).size() / (double) beforeTextSupport; - final long count1 = DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> revision.bugfix) - .count(); - final double cf1 = (double) getCommits(cp, true) / (double) (0 < count1 ? count1 : 1); - final long count2 = DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> !revision.bugfix) - .count(); - final double cf2 = (double) getCommits(cp, false) / (double) (0 < count2 ? count2 : 1); - final double pfcf = pf * (cf1 - cf2); - return pfcf; - } - - private static List getChanges(final PATTERN_SQL cp) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - return DAO.getInstance() - .getChanges(beforeHash, afterHash); - } - - private static List getChanges(final PATTERN_SQL cp, final boolean bugfix) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - final Iterator iterator = changes.iterator(); - while (iterator.hasNext()) { - final CHANGE_SQL change = iterator.next(); - if (bugfix && !change.bugfix || !bugfix && change.bugfix) { - iterator.remove(); - } - } - - return changes; - } - - private static SortedSet getAuthors(final PATTERN_SQL cp) { - - final SortedSet authors = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - authors.add(change.author); - } - - return authors; - } - - private static SortedSet getAuthors(final PATTERN_SQL cp, final boolean bugfix) { - - final SortedSet authors = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { - authors.add(change.author); - } - } - - return authors; - } - - private static SortedSet getFiles(final PATTERN_SQL cp) { - - final SortedSet files = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - files.add(change.filepath); - } - - return files; - } - - private static SortedSet getFiles(final PATTERN_SQL cp, final boolean bugfix) { - - final SortedSet files = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { - files.add(change.filepath); - } - } - - return files; - } - - private static int countTextAppearances(final PATTERN_SQL cp) { - - CPAConfig.initialize(new String[] {}); - final List pattern = StringUtility.splitToStatements(cp.beforeNText, 1, 1); - int count = 0; - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final SortedSet revisions = DAO.getInstance() - .getRevisions(beforeHash, afterHash); - List> contents = Collections.emptyList(); - if (FBParserConfig.getInstance() - .hasSVNREPOSITORY()) { - final int firstRevision = Integer.parseInt(revisions.first().id) - 1; - contents = getSVNFileContents(firstRevision); - } else if (FBParserConfig.getInstance() - .hasGITREPOSITORY()) { - - } - - for (final List content : contents) { - count += getCount(content, pattern); - } - - return count; - } - - static final private Map> REVISION_FILEPATH_MAP = new HashMap<>(); - static final private Map FILEPATH_CACHE_MAP = new HashMap<>(); - static final private Map> FILEPATH_REVISIONS_MAP = new HashMap<>(); - - static private int PREVIOUS_CHANGEPATTERN_REVISION = 0; - static private List> PREVIOUS_REVISION_CONTENTS = null; - - private static List> getSVNFileContents(final int revision) { - if (revision == PREVIOUS_CHANGEPATTERN_REVISION) { - return PREVIOUS_REVISION_CONTENTS; - } - - final String repository = FBParserConfig.getInstance() - .getSVNREPOSITORY(); - final List paths = new ArrayList<>(); - try { - - final SVNLogClient logClient = SVNClientManager.newInstance() - .getLogClient(); - final SVNURL url = SVNURL.fromFile(new File(repository)); - FSRepositoryFactory.setup(); - logClient.doList(url, SVNRevision.create(revision), SVNRevision.create(revision), true, - SVNDepth.INFINITY, SVNDirEntry.DIRENT_ALL, entry -> { - if (entry.getKind() != SVNNodeKind.FILE) { - return; - } - final String path = entry.getRelativePath(); - if (!path.endsWith(".java")) { - return; - } - paths.add(path); - }); - } catch (final SVNException | NullPointerException e) { - } - - final SVNWCClient wcClient = SVNClientManager.newInstance() - .getWCClient(); - final List> contents = new ArrayList<>(); - for (final String path : paths) { - try { - final SVNURL fileurl = - SVNURL.fromFile(new File(repository + System.getProperty("file.separator") + path)); - final StringBuilder text = new StringBuilder(); - wcClient.doGetFileContents(fileurl, SVNRevision.create(revision), - SVNRevision.create(revision), false, new OutputStream() { - - @Override - public void write(int b) throws IOException { - text.append((char) b); - } - }); - final List statements = - StringUtility.splitToStatements(text.toString(), LANGUAGE.JAVA); - contents.add(statements); - } catch (final SVNException | NullPointerException e) { - } - } - - PREVIOUS_CHANGEPATTERN_REVISION = revision; - PREVIOUS_REVISION_CONTENTS = contents; - - return contents; - } - - private static int getCount(final List statements, final List pattern) { - - int count = 0; - for (int index = 0; index < statements.size(); index++) { - - int pIndex = 0; - while (Arrays.equals(statements.get(index + pIndex).hash, pattern.get(pIndex).hash)) { - pIndex++; - if (pattern.size() == pIndex) { - count++; - break; - } - if (statements.size() == index + pIndex) { - break; - } - } - } - - return count; - } - - private static int[] getCacheRange(final SortedSet revisions, final int revision) { - - if (revisions.isEmpty()) { - return new int[] {revision, revision}; - } - - int cacheStartRevision = revisions.first() - .intValue(); - int cacheEndRevision = revisions.last() - .intValue() - 1; - for (final int r : revisions) { - if ((r <= revision) && (cacheStartRevision < r)) { - cacheStartRevision = r; - } - if ((revision <= r) && (r < cacheEndRevision)) { - cacheEndRevision = r - 1; - } - } - if (revision < cacheStartRevision) { - cacheStartRevision = revision; - } - if (cacheEndRevision < revision) { - cacheEndRevision = revision; - } - - return new int[] {cacheStartRevision, cacheEndRevision}; - } -} - - -class Line { - - final String hash; - final String type; - final int rank; - final int priority; - final String status; - final String startrev; - final String endrev; - final String path; - final int startstartline; - final int startendline; - final int endstartline; - final int endendline; - - Line(final String lineText) { - final StringTokenizer tokenizer = new StringTokenizer(lineText, ", "); - this.hash = tokenizer.nextToken(); - this.type = tokenizer.nextToken(); - this.rank = Integer.parseInt(tokenizer.nextToken()); - this.priority = Integer.parseInt(tokenizer.nextToken()); - this.status = tokenizer.nextToken(); - this.startrev = tokenizer.nextToken(); - this.endrev = tokenizer.nextToken(); - this.path = tokenizer.nextToken(); - final String startpos = tokenizer.nextToken(); - final String endpos = tokenizer.nextToken(); - if (startpos.equals("no-line-information")) { - this.startstartline = 0; - this.startendline = 0; - } else { - this.startstartline = Integer.parseInt(startpos.substring(0, startpos.indexOf('-'))); - this.startendline = Integer.parseInt(startpos.substring(startpos.lastIndexOf('-') + 1)); - } - if (endpos.equals("no-line-information")) { - this.endstartline = 0; - this.endendline = 0; - } else { - this.endstartline = Integer.parseInt(endpos.substring(0, endpos.indexOf('-'))); - this.endendline = Integer.parseInt(endpos.substring(endpos.lastIndexOf('-') + 1)); - } - } -} - - -class Cache { - - final public String path; - final private Map> data; - - Cache(final String path) { - this.path = path; - data = new HashMap<>(); - } - - public List getCache(final int revision) { - for (final Entry> entry : this.data.entrySet()) { - final int[] range = entry.getKey(); - if ((range[0] <= revision) && (revision <= range[1])) { - System.out.println("cashe hit! :" + revision + " " + this.path); - return entry.getValue(); - } - } - return null; - } - - public boolean addCache(final List statements, final int[] range) { - - final Iterator>> iterator = this.data.entrySet() - .iterator(); - while (iterator.hasNext()) { - final Entry> entry = iterator.next(); - final int[] r = entry.getKey(); - final List s = entry.getValue(); - if (range[1] < r[0] || r[1] < range[0]) { - continue; - } - if (s.equals(statements)) { - iterator.remove(); - continue; - } - System.err.println("warning: statements are different its cached one, " + range[0] + "--" - + range[1] + ", " + this.path); - // assert false : "adding cache condition was illegal."; - return false; - } - - System.out.println("adding cache: " + range[0] + "--" + range[1] + ", " + this.path); - this.data.put(range, statements); - return true; - } -} diff --git a/src/nh3/ammonia/FBChangePatternFinderWithoutFB.java b/src/nh3/ammonia/FBChangePatternFinderWithoutFB.java deleted file mode 100644 index a6d9507..0000000 --- a/src/nh3/ammonia/FBChangePatternFinderWithoutFB.java +++ /dev/null @@ -1,776 +0,0 @@ -package nh3.ammonia; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Calendar; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.TreeSet; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import nh3.ammonia.db.DAO; -import nh3.ammonia.db.DAO.CHANGE_SQL; -import nh3.ammonia.db.DAO.PATTERN_SQL; -import nh3.ammonia.db.DAO.REVISION_SQL; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.Comment; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.eclipse.jgit.internal.storage.file.FileRepository; -import org.eclipse.jgit.lib.ObjectId; -import org.eclipse.jgit.lib.ObjectReader; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevTree; -import org.eclipse.jgit.revwalk.RevWalk; -import org.eclipse.jgit.treewalk.TreeWalk; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNDirEntry; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNLogClient; -import org.tmatesoft.svn.core.wc.SVNRevision; -import org.tmatesoft.svn.core.wc.SVNWCClient; -import yoshikihigo.cpanalyzer.CPAConfig; -import yoshikihigo.cpanalyzer.LANGUAGE; -import yoshikihigo.cpanalyzer.StringUtility; -import yoshikihigo.cpanalyzer.data.Statement; - -public class FBChangePatternFinderWithoutFB { - - public static void main(final String[] args) { - - FBParserConfig.initialize(args); - final String fcpFile = FBParserConfig.getInstance() - .getFIXCHANGEPATTERN(); - final DAO dao = DAO.getInstance(); - - try (final Workbook book = new XSSFWorkbook(); - final OutputStream stream = new FileOutputStream(fcpFile)) { - - Cell firstCell = null; - Cell lastCell = null; - - final Sheet sheet = book.createSheet(); - book.setSheetName(0, "change patterns"); - final Row titleRow = sheet.createRow(0); - titleRow.createCell(0) - .setCellValue("MERGED-PATTERN-ID"); - titleRow.createCell(1) - .setCellValue("PATTERN-ID"); - titleRow.createCell(2) - .setCellValue("FINDBUGS-SUPPORT"); - titleRow.createCell(3) - .setCellValue("AUTHORS"); - titleRow.createCell(4) - .setCellValue("BUG-FIX-AUTHORS"); - titleRow.createCell(5) - .setCellValue("FILES"); - titleRow.createCell(6) - .setCellValue("BUG-FIX-FILES"); - titleRow.createCell(7) - .setCellValue("SUPPORT"); - titleRow.createCell(8) - .setCellValue("BUG-FIX-SUPPORT"); - titleRow.createCell(9) - .setCellValue("BEFORE-TEXT-SUPPORT"); - titleRow.createCell(10) - .setCellValue("CONFIDENCE1"); - titleRow.createCell(11) - .setCellValue("CONFIDENCE2"); - titleRow.createCell(12) - .setCellValue("CONFIDENCE3"); - titleRow.createCell(13) - .setCellValue("COMMITS"); - titleRow.createCell(14) - .setCellValue("BUG-FIX-COMMIT"); - titleRow.createCell(15) - .setCellValue("FIRST-DATE"); - titleRow.createCell(16) - .setCellValue("LAST-DATE"); - titleRow.createCell(17) - .setCellValue("DATE-DIFFERENCE"); - titleRow.createCell(18) - .setCellValue("OCCUPANCY"); - titleRow.createCell(19) - .setCellValue("Delta-PFCF"); - titleRow.createCell(20) - .setCellValue("RANK-of-\"G\""); - titleRow.createCell(21) - .setCellValue("RANK-of-\"F-G\""); - titleRow.createCell(22) - .setCellValue("RANK-of-\"R\""); - titleRow.createCell(23) - .setCellValue("TEXT-BEFORE-CHANGE"); - titleRow.createCell(24) - .setCellValue("TEXT-AFTER-CHANGE"); - titleRow.createCell(25) - .setCellValue("AUTHOR-LIST"); - titleRow.createCell(26) - .setCellValue("BUG-FIX-AUTHOR-LIST"); - titleRow.createCell(27) - .setCellValue("FILE-LIST"); - titleRow.createCell(28) - .setCellValue("BUG-FIX-FILE-LIST"); - - final int bugfixCommits = (int) DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> revision.bugfix) - .count(); - titleRow.createCell(29) - .setCellValue(bugfixCommits); - final int nonbugfixCommits = (int) DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> !revision.bugfix) - .count(); - titleRow.createCell(30) - .setCellValue(nonbugfixCommits); - - firstCell = titleRow.getCell(0); - lastCell = titleRow.getCell(28); - - setCellComment(titleRow.getCell(3), "Higo", - "the number of authors that committed the change pattern in all commits", 5, 2); - setCellComment(titleRow.getCell(4), "Higo", - "the number of authors commited the change pattern in bug-fix commits", 5, 2); - setCellComment(titleRow.getCell(5), "Higo", - "the number of files where the change pattern appeared in all commits", 5, 2); - setCellComment(titleRow.getCell(6), "Higo", - "the number of files where the change pattern appeared in bug-fix commits", 5, 2); - setCellComment(titleRow.getCell(7), "Higo", "the number of occurences of a given pattern", 4, - 1); - setCellComment(titleRow.getCell(8), "Higo", - "the number of occurences of a given pattern in bug-fix commits", 4, 2); - setCellComment(titleRow.getCell(9), "Higo", - "the number of code fragments whose texts are " - + "identical to before-text of a given pattern " - + "in the commit where the pattern appears initially", - 4, 3); - setCellComment(titleRow.getCell(10), "Higo", "BUG-FIX-SUPPORT / SUPPORT", 4, 2); - setCellComment(titleRow.getCell(11), "Higo", "SUPPORT / BEFORE-TEXT-SUPPORT", 4, 2); - setCellComment(titleRow.getCell(12), "Higo", "BUG-FIX-SUPPORT / BEFORE-TEXT-SUPPORT", 4, 2); - setCellComment(titleRow.getCell(13), "Higo", - "the number of commits where the pattern appears", 4, 2); - setCellComment(titleRow.getCell(14), "Higo", - "the number of bug-fix commits where the pattern appears", 4, 2); - setCellComment(titleRow.getCell(18), "Higo", - "average of (LOC of a given pattern changed in revision R) / " - + "(total LOC changed in revision R) " - + "for all the revisions where the pattern appears", - 4, 3); - setCellComment(titleRow.getCell(19), "Higo", - "delta-CFPF was calculated with the following formula" + System.lineSeparator() - + "pf*(cf1 - cf2)" + System.lineSeparator() - + "pf: pattern frequency, which is calculated as support / before-text-support" - + System.lineSeparator() - + "cf1: bug-fix commit frequensy, which is calculated as bug-fix commits / all bug-fix commits" - + System.lineSeparator() - + "cf2: non-bug-fix commit frequency, which is calculated as non-bug-fix commits / all non-bug-fix commits", - 5, 5); - - int currentRow = 1; - final List cps = dao.getFixChangePatterns(); - // Collections.sort(cps, (o1, o2) -> Integer.compare(o1.id, o2.id)); - Collections.sort(cps, (o1, o2) -> o1.firstdate.compareTo(o2.firstdate)); - for (final PATTERN_SQL cp : cps) { - - if (cp.beforeNText.isEmpty()) { - continue; - } - - if (cp.afterNText.isEmpty()) { - continue; - } - - if (cp.confidence < 1.0f) { - continue; - } - - if (cp.support < 2) { - continue; - } - - final int findBugsSupport = 0; - - final Row dataRow = sheet.createRow(currentRow++); - dataRow.createCell(0) - .setCellValue(cp.id); - dataRow.createCell(1) - .setCellValue(cp.id); - dataRow.createCell(2) - .setCellValue(findBugsSupport); - dataRow.createCell(3) - .setCellValue(getAuthors(cp).size()); - dataRow.createCell(4) - .setCellValue(getAuthors(cp, true).size()); - dataRow.createCell(5) - .setCellValue(getFiles(cp).size()); - dataRow.createCell(6) - .setCellValue(getFiles(cp, true).size()); - final int support = getChanges(cp).size(); - final int bugfixSupport = getChanges(cp, true).size(); - final int beforeTextSupport = 1;// countTextAppearances(cp); - dataRow.createCell(7) - .setCellValue(support); - dataRow.createCell(8) - .setCellValue(bugfixSupport); - dataRow.createCell(9) - .setCellValue(beforeTextSupport); - dataRow.createCell(10) - .setCellValue((float) bugfixSupport / (float) support); - dataRow.createCell(11) - .setCellValue((float) support / (float) beforeTextSupport); - dataRow.createCell(12) - .setCellValue((float) bugfixSupport / (float) beforeTextSupport); - dataRow.createCell(13) - .setCellValue(getCommits(cp)); - dataRow.createCell(14) - .setCellValue(getCommits(cp, true)); - dataRow.createCell(15) - .setCellValue(cp.firstdate); - dataRow.createCell(16) - .setCellValue(cp.lastdate); - dataRow.createCell(17) - .setCellValue(getDayDifference(cp.firstdate, cp.lastdate)); - dataRow.createCell(18) - .setCellValue(getOccupancy(cp)); - dataRow.createCell(19) - .setCellValue(getDeltaCFPF(cp, beforeTextSupport)); - dataRow.createCell(20) - .setCellValue("no data"); - dataRow.createCell(21) - .setCellValue("no date"); - dataRow.createCell(22) - .setCellValue("no date"); - dataRow.createCell(23) - .setCellValue(cp.beforeNText.length() > 32767 ? cp.beforeNText.substring(0, 32767) - : cp.beforeNText); - dataRow.createCell(24) - .setCellValue( - cp.afterNText.length() > 32767 ? cp.afterNText.substring(0, 32767) : cp.afterNText); - dataRow.createCell(25) - .setCellValue(nh3.ammonia.StringUtility.concatinate(getAuthors(cp))); - dataRow.createCell(26) - .setCellValue(nh3.ammonia.StringUtility.concatinate(getAuthors(cp, true))); - dataRow.createCell(27) - .setCellValue(nh3.ammonia.StringUtility - .shrink(nh3.ammonia.StringUtility.concatinate(getFiles(cp)), 10000)); - dataRow.createCell(28) - .setCellValue(nh3.ammonia.StringUtility - .shrink(nh3.ammonia.StringUtility.concatinate(getFiles(cp, true)), 10000)); - lastCell = dataRow.getCell(28); - - final CellStyle style = book.createCellStyle(); - style.setWrapText(true); - style.setFillPattern(CellStyle.SOLID_FOREGROUND); - style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); - style.setBorderBottom(XSSFCellStyle.BORDER_THIN); - style.setBorderLeft(XSSFCellStyle.BORDER_THIN); - style.setBorderRight(XSSFCellStyle.BORDER_THIN); - style.setBorderTop(XSSFCellStyle.BORDER_THIN); - style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); - for (int column = 0; column <= 28; column++) { - dataRow.getCell(column) - .setCellStyle(style); - } - - int loc = Math.max(getLOC(cp.beforeNText), getLOC(cp.afterNText)); - dataRow.setHeight((short) (loc * dataRow.getHeight())); - } - - sheet.autoSizeColumn(0, true); - sheet.autoSizeColumn(1, true); - sheet.autoSizeColumn(2, true); - sheet.autoSizeColumn(3, true); - sheet.autoSizeColumn(4, true); - sheet.autoSizeColumn(5, true); - sheet.autoSizeColumn(6, true); - sheet.autoSizeColumn(7, true); - sheet.autoSizeColumn(8, true); - sheet.autoSizeColumn(9, true); - sheet.autoSizeColumn(10, true); - sheet.autoSizeColumn(11, true); - sheet.autoSizeColumn(12, true); - sheet.autoSizeColumn(13, true); - sheet.autoSizeColumn(14, true); - sheet.autoSizeColumn(15, true); - sheet.autoSizeColumn(16, true); - sheet.autoSizeColumn(17, true); - sheet.autoSizeColumn(18, true); - sheet.autoSizeColumn(19, true); - sheet.autoSizeColumn(20, true); - sheet.autoSizeColumn(21, true); - sheet.autoSizeColumn(22, true); - sheet.setColumnWidth(23, 20480); - sheet.setColumnWidth(24, 20480); - sheet.setColumnWidth(25, 5120); - sheet.setColumnWidth(26, 5120); - sheet.setColumnWidth(27, 20480); - sheet.setColumnWidth(28, 20480); - - sheet.setAutoFilter(new CellRangeAddress(firstCell.getRowIndex(), lastCell.getRowIndex(), - firstCell.getColumnIndex(), lastCell.getColumnIndex())); - sheet.createFreezePane(0, 1, 0, 1); - - book.write(stream); - - } catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - } - - private static void setCellComment(final Cell cell, final String author, final String text, - final int width, final int height) { - - final Sheet sheet = cell.getSheet(); - final Workbook workbook = sheet.getWorkbook(); - final CreationHelper helper = workbook.getCreationHelper(); - - final Drawing drawing = sheet.createDrawingPatriarch(); - final ClientAnchor anchor = - drawing.createAnchor(0, 0, 0, 0, (short) 4, 2, (short) (4 + width), (2 + height)); - final Comment comment = drawing.createCellComment(anchor); - comment.setAuthor(author); - comment.setString(helper.createRichTextString(text)); - cell.setCellComment(comment); - } - - private static int getLOC(final String text) { - - int count = 0; - final String newline = System.lineSeparator(); - final Matcher matcher = Pattern.compile(newline) - .matcher(text); - while (matcher.find()) { - count++; - } - return count + 1; - } - - private static int getDayDifference(final String firstdate, final String lastdate) { - - final Calendar calendar1 = Calendar.getInstance(); - { - final StringTokenizer tokenizer1 = new StringTokenizer(firstdate, " :/"); - final String year = tokenizer1.nextToken(); - final String month = tokenizer1.nextToken(); - final String date = tokenizer1.nextToken(); - final String hour = tokenizer1.nextToken(); - final String minute = tokenizer1.nextToken(); - final String second = tokenizer1.nextToken(); - calendar1.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(date), - Integer.parseInt(hour), Integer.parseInt(minute), Integer.parseInt(second)); - } - - final Calendar calendar2 = Calendar.getInstance(); - { - final StringTokenizer tokenizer1 = new StringTokenizer(lastdate, " :/"); - final String year = tokenizer1.nextToken(); - final String month = tokenizer1.nextToken(); - final String date = tokenizer1.nextToken(); - final String hour = tokenizer1.nextToken(); - final String minute = tokenizer1.nextToken(); - final String second = tokenizer1.nextToken(); - calendar2.set(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(date), - Integer.parseInt(hour), Integer.parseInt(minute), Integer.parseInt(second)); - } - - final long difference = calendar2.getTime() - .getTime() - - calendar1.getTime() - .getTime(); - return (int) (difference / 1000l / 60l / 60l / 24l); - } - - public static int getCommits(final PATTERN_SQL cp) { - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - return (int) DAO.getInstance() - .getChanges(beforeHash, afterHash) - .stream() - .map(change -> change.revision) - .distinct() - .count(); - } - - public static int getCommits(final PATTERN_SQL cp, final boolean bugfix) { - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changesInPattern = DAO.getInstance() - .getChanges(beforeHash, afterHash); - return (int) changesInPattern.stream() - .filter(change -> bugfix == change.bugfix) - .count(); - } - - private static float getOccupancy(final PATTERN_SQL cp) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changesInPattern = DAO.getInstance() - .getChanges(beforeHash, afterHash); - final Map map1 = new HashMap<>(); - final Map map2 = new HashMap<>(); - - final SortedSet revisions = DAO.getInstance() - .getRevisions(beforeHash, afterHash); - for (final REVISION_SQL revision : revisions) { - map1.put(revision, new AtomicInteger(0)); - map2.put(revision, new AtomicInteger(0)); - List changesInRevision = DAO.getInstance() - .getChanges(revision.id); - changesInRevision.stream() - .forEach(change -> { - if (changesInPattern.contains(change)) { - final AtomicInteger size = map1.get(revision); - size.addAndGet(change.beforeEndLine - change.beforeStartLine + 1); - } - final AtomicInteger size = map2.get(revision); - size.addAndGet(change.beforeEndLine - change.beforeStartLine + 1); - }); - } - - float sum = 0; - for (final REVISION_SQL revision : revisions) { - final AtomicInteger numerator = map1.get(revision); - final AtomicInteger denominator = map2.get(revision); - final float occupancy = (float) numerator.get() / (float) denominator.get(); - sum += occupancy; - } - - return sum / revisions.size(); - } - - private static double getDeltaCFPF(final PATTERN_SQL cp, final int beforeTextSupport) { - final double pf = (double) getChanges(cp).size() / (double) beforeTextSupport; - final long count1 = DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> revision.bugfix) - .count(); - final double cf1 = (double) getCommits(cp, true) / (double) (0 < count1 ? count1 : 1); - final long count2 = DAO.getInstance() - .getRevisions() - .stream() - .filter(revision -> !revision.bugfix) - .count(); - final double cf2 = (double) getCommits(cp, false) / (double) (0 < count2 ? count2 : 1); - final double pfcf = pf * (cf1 - cf2); - return pfcf; - } - - private static List getChanges(final PATTERN_SQL cp) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - return DAO.getInstance() - .getChanges(beforeHash, afterHash); - } - - private static List getChanges(final PATTERN_SQL cp, final boolean bugfix) { - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - final Iterator iterator = changes.iterator(); - while (iterator.hasNext()) { - final CHANGE_SQL change = iterator.next(); - if (bugfix && !change.bugfix || !bugfix && change.bugfix) { - iterator.remove(); - } - } - - return changes; - } - - private static SortedSet getAuthors(final PATTERN_SQL cp) { - - final SortedSet authors = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - authors.add(change.author); - } - - return authors; - } - - public static SortedSet getAuthors(final PATTERN_SQL cp, final boolean bugfix) { - - final SortedSet authors = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { - authors.add(change.author); - } - } - - return authors; - } - - public static SortedSet getFiles(final PATTERN_SQL cp) { - - final SortedSet files = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - files.add(change.filepath); - } - - return files; - } - - public static SortedSet getFiles(final PATTERN_SQL cp, final boolean bugfix) { - - final SortedSet files = new TreeSet<>(); - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final List changes = DAO.getInstance() - .getChanges(beforeHash, afterHash); - for (final CHANGE_SQL change : changes) { - if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { - files.add(change.filepath); - } - } - - return files; - } - - private static int countTextAppearances(final PATTERN_SQL cp) { - - CPAConfig.initialize(new String[] {}); - final List pattern = StringUtility.splitToStatements(cp.beforeNText, 1, 1); - int count = 0; - - final byte[] beforeHash = cp.beforeHash; - final byte[] afterHash = cp.afterHash; - final SortedSet revisions = DAO.getInstance() - .getRevisions(beforeHash, afterHash); - List> contents = Collections.emptyList(); - if (FBParserConfig.getInstance() - .hasSVNREPOSITORY()) { - final int firstRevision = Integer.valueOf(revisions.first().id) - 1; - contents = getSVNFileContents(firstRevision); - } else if (FBParserConfig.getInstance() - .hasGITREPOSITORY()) { - final String firstRevision = revisions.first().id; - contents = getGITFileContents(firstRevision); - } - for (final List content : contents) { - count += getCount(content, pattern); - } - - return count; - } - - static final private Map> REVISION_FILEPATH_MAP = new HashMap<>(); - static final private Map FILEPATH_CACHE_MAP = new HashMap<>(); - static final private Map> FILEPATH_REVISIONS_MAP = new HashMap<>(); - - static private String PREVIOUS_CHANGEPATTERN_REVISION = ""; - static private List> PREVIOUS_REVISION_CONTENTS = null; - - private static List> getSVNFileContents(final int revision) { - - if (Integer.toString(revision) - .equals(PREVIOUS_CHANGEPATTERN_REVISION)) { - return PREVIOUS_REVISION_CONTENTS; - } - - final Set languages = FBParserConfig.getInstance() - .getLANGUAGE(); - final String repository = FBParserConfig.getInstance() - .getSVNREPOSITORY(); - final Map files = new HashMap<>(); - try { - - final SVNLogClient logClient = SVNClientManager.newInstance() - .getLogClient(); - final SVNURL url = SVNURL.fromFile(new File(repository)); - FSRepositoryFactory.setup(); - final long revNumber = Long.valueOf(revision); - logClient.doList(url, SVNRevision.create(revNumber), SVNRevision.create(revNumber), true, - SVNDepth.INFINITY, SVNDirEntry.DIRENT_ALL, entry -> { - if (entry.getKind() != SVNNodeKind.FILE) { - return; - } - final String path = entry.getRelativePath(); - for (final LANGUAGE language : languages) { - if (language.isTarget(path)) { - files.put(path, language); - } - break; - } - }); - } catch (final SVNException | NullPointerException e) { - } - - final SVNWCClient wcClient = SVNClientManager.newInstance() - .getWCClient(); - final List> contents = new ArrayList<>(); - for (final Entry file : files.entrySet()) { - final String path = file.getKey(); - final LANGUAGE lang = file.getValue(); - try { - final SVNURL fileurl = - SVNURL.fromFile(new File(repository + System.getProperty("file.separator") + path)); - final StringBuilder text = new StringBuilder(); - final long revNumber = Long.valueOf(revision); - wcClient.doGetFileContents(fileurl, SVNRevision.create(revNumber), - SVNRevision.create(revNumber), false, new OutputStream() { - - @Override - public void write(int b) throws IOException { - text.append((char) b); - } - }); - final List statements = StringUtility.splitToStatements(text.toString(), lang); - contents.add(statements); - } catch (final SVNException | NullPointerException e) { - } - } - - PREVIOUS_CHANGEPATTERN_REVISION = Integer.toString(revision); - PREVIOUS_REVISION_CONTENTS = contents; - - return contents; - } - - private static List> getGITFileContents(final String revision) { - - if (revision.equals(PREVIOUS_CHANGEPATTERN_REVISION)) { - return PREVIOUS_REVISION_CONTENTS; - } - - final String gitrepo = FBParserConfig.getInstance() - .getGITREPOSITORY(); - final Set languages = FBParserConfig.getInstance() - .getLANGUAGE(); - - final List> contents = new ArrayList<>(); - try (final FileRepository repo = new FileRepository(new File(gitrepo + "/.git")); - final ObjectReader reader = repo.newObjectReader(); - final TreeWalk treeWalk = new TreeWalk(reader); - final RevWalk revWalk = new RevWalk(reader)) { - - final ObjectId rootId = repo.resolve(revision); - revWalk.markStart(revWalk.parseCommit(rootId)); - final RevCommit commit = revWalk.next(); - final RevTree tree = commit.getTree(); - treeWalk.addTree(tree); - treeWalk.setRecursive(true); - final Map files = new HashMap<>(); - while (treeWalk.next()) { - final String path = treeWalk.getPathString(); - for (final LANGUAGE language : languages) { - if (language.isTarget(path)) { - files.put(path, language); - } - break; - } - } - - for (final Entry file : files.entrySet()) { - final String path = file.getKey(); - final LANGUAGE lang = file.getValue(); - final TreeWalk nodeWalk = TreeWalk.forPath(reader, path, tree); - final byte[] data = reader.open(nodeWalk.getObjectId(0)) - .getBytes(); - final String text = new String(data, "utf-8"); - final List statements = StringUtility.splitToStatements(text.toString(), lang); - contents.add(statements); - } - - } catch (final IOException e) { - e.printStackTrace(); - } - - PREVIOUS_CHANGEPATTERN_REVISION = revision; - PREVIOUS_REVISION_CONTENTS = contents; - - return contents; - } - - private static int getCount(final List statements, final List pattern) { - - int count = 0; - for (int index = 0; index < statements.size(); index++) { - - int pIndex = 0; - while (Arrays.equals(statements.get(index + pIndex).hash, pattern.get(pIndex).hash)) { - pIndex++; - if (pattern.size() == pIndex) { - count++; - break; - } - if (statements.size() == index + pIndex) { - break; - } - } - } - - return count; - } - - private static int[] getCacheRange(final SortedSet revisions, final int revision) { - - if (revisions.isEmpty()) { - return new int[] {revision, revision}; - } - - int cacheStartRevision = revisions.first() - .intValue(); - int cacheEndRevision = revisions.last() - .intValue() - 1; - for (final int r : revisions) { - if ((r <= revision) && (cacheStartRevision < r)) { - cacheStartRevision = r; - } - if ((revision <= r) && (r < cacheEndRevision)) { - cacheEndRevision = r - 1; - } - } - if (revision < cacheStartRevision) { - cacheStartRevision = revision; - } - if (cacheEndRevision < revision) { - cacheEndRevision = revision; - } - - return new int[] {cacheStartRevision, cacheEndRevision}; - } -} diff --git a/src/nh3/ammonia/FBChangeRetriever.java b/src/nh3/ammonia/FBChangeRetriever.java deleted file mode 100644 index 6f9e186..0000000 --- a/src/nh3/ammonia/FBChangeRetriever.java +++ /dev/null @@ -1,350 +0,0 @@ -package nh3.ammonia; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.SortedSet; -import java.util.StringTokenizer; -import java.util.stream.Collectors; -import nh3.ammonia.db.DAO; -import nh3.ammonia.db.DAO.REVISION_SQL; -import org.tmatesoft.svn.core.ISVNLogEntryHandler; -import org.tmatesoft.svn.core.SVNDepth; -import org.tmatesoft.svn.core.SVNException; -import org.tmatesoft.svn.core.SVNLogEntry; -import org.tmatesoft.svn.core.SVNNodeKind; -import org.tmatesoft.svn.core.SVNURL; -import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory; -import org.tmatesoft.svn.core.io.SVNRepository; -import org.tmatesoft.svn.core.wc.SVNClientManager; -import org.tmatesoft.svn.core.wc.SVNDiffClient; -import org.tmatesoft.svn.core.wc.SVNRevision; - -public class FBChangeRetriever { - - public static void main(final String[] args) { - - FBParserConfig.initialize(args); - - final List fbResults = FBParserConfig.getInstance() - .getFBRESULTS(); - final String startrevFBResult = fbResults.get(0); - final String endrevFBResult = fbResults.get(1); - final int startrev = FBParserConfig.getInstance() - .getSTARTREV(); - final int endrev = FBParserConfig.getInstance() - .getENDREV(); - final String repository = FBParserConfig.getInstance() - .getSVNREPOSITORY(); - - final FBParser startrevParser = new FBParser(startrevFBResult); - startrevParser.perform(); - final List startrevBugInstances = startrevParser.getBugInstances(); - - final Map transitions = new HashMap<>(); - for (final BugInstance instance : startrevBugInstances) { - final SourceLine sourceline = instance.getSourceLines() - .get(0); - final String path = sourceline.sourcepath; - final int startLine = sourceline.start; - final int endLine = sourceline.end; - - assert null != path : "variable \"path\" must not be null."; - assert 0 < startLine : "variable \"startLine\" must no be 0."; - assert 0 < endLine : "variable \"endLine\" must no be 0."; - - final LocationTransition transition = new LocationTransition(); - transition.add(startrev, new Location(path, startLine, endLine, false)); - transitions.put(instance, transition); - } - - final DAO dao = DAO.getInstance(); - final SortedSet revisions = dao.getRevisions(); - final Set bugfixRevisionIDs = revisions.stream() - .filter(r -> r.bugfix) - .map(r -> r.id) - .collect(Collectors.toSet()); - - try { - - final SVNURL url = SVNURL.fromFile(new File(repository)); - FSRepositoryFactory.setup(); - final SVNRepository svnRepository = FSRepositoryFactory.create(url); - final SVNDiffClient diffClient = SVNClientManager.newInstance() - .getDiffClient(); - - svnRepository.log(null, startrev + 1, endrev, true, true, new ISVNLogEntryHandler() { - - @Override - public void handleLogEntry(final SVNLogEntry logEntry) throws SVNException { - - final int number = (int) logEntry.getRevision(); - final boolean bugfix = bugfixRevisionIDs.contains(Integer.toString(number)); - for (final Object key : logEntry.getChangedPaths() - .keySet()) { - final String path = (String) key; - - for (final BugInstance instance : startrevBugInstances) { - - final LocationTransition transition = transitions.get(instance); - if ((null == transition) || transition.hasChanged()) { - continue; - } - - final SourceLine sourceline = instance.getSourceLines() - .get(0); - if (path.endsWith(sourceline.sourcepath)) { - - final StringBuilder text = new StringBuilder(); - final String filepath = svnRepository.getRepositoryRoot(false) - .getPath() + path; - final SVNURL fileURL = SVNURL.fromFile(new File(filepath)); - - final SVNRepository repo = FSRepositoryFactory.create(fileURL); - final SVNNodeKind node1 = repo.checkPath("", number - 1); - final SVNNodeKind node2 = repo.checkPath("", number); - if (SVNNodeKind.NONE == node1 || SVNNodeKind.NONE == node2) { - continue; - } - - try { - diffClient.doDiff(fileURL, SVNRevision.create(number - 1), fileURL, - SVNRevision.create(number), SVNDepth.INFINITY, true, new OutputStream() { - - @Override - public void write(int b) throws IOException { - text.append((char) b); - } - }); - - final List locations = - getChangedLocations(sourceline.sourcepath, text.toString(), bugfix); - final Location changedWarningLocation = - moveWarningLocation(transition.getLatestLocation(), locations); - transition.add(number, changedWarningLocation); - } catch (final SVNException e) { - e.printStackTrace(); - } - } - } - } - } - }); - - } catch (final SVNException e) { - e.printStackTrace(); - } - - final FBParser endrevParser = new FBParser(endrevFBResult); - endrevParser.perform(); - final List endrevBugInstances = endrevParser.getBugInstances(); - - final String trFile = FBParserConfig.getInstance() - .getTRANSITIONRESULT(); - try (final PrintWriter writer = new PrintWriter( - new BufferedWriter(new OutputStreamWriter(new FileOutputStream(trFile), "UTF-8")))) { - - writer.print("HASH, "); - writer.print("BUGTYPE, "); - writer.print("RANK, "); - writer.print("PRIORITY, "); - writer.print("STATUS, "); - writer.print("START-REV, "); - writer.print("END-REV, "); - writer.print("FILE, "); - writer.print("START-POSITION, "); - writer.print("END-POSITION"); - writer.println(); - - for (final Entry entry : transitions.entrySet()) { - final BugInstance instance = entry.getKey(); - final LocationTransition transition = entry.getValue(); - final Location initialLocation = transition.getInitialLocation(); - final Location latestLocation = transition.getLatestLocation(); - - writer.print(instance.hash); - writer.print(","); - writer.print(instance.pattern.type); - writer.print(","); - writer.print(Integer.toString(instance.rank)); - writer.print(","); - writer.print(Integer.toString(instance.priority)); - writer.print(","); - - boolean surviving = false; - for (final BugInstance endrevBugInstance : endrevBugInstances) { - if (instance.hash.equals(endrevBugInstance.hash)) { - writer.write("surviving(hash), "); - surviving = true; - break; - } - } - - if (!surviving) { - if (latestLocation.bugfix) { - if (!latestLocation.hasLineInformaltion()) { - writer.print("fixed(unknown), "); - } else if (latestLocation instanceof Location_ADDITION) { - writer.print("fixed(addition), "); - } else if (latestLocation instanceof Location_DELETION) { - writer.print("fixed(deletion), "); - } else if (latestLocation instanceof Location_REPLACEMENT) { - writer.print("fixed(replacement), "); - } else if (latestLocation instanceof Location_UNKNOWN) { - writer.print("fixed(unknown), "); - } else { - writer.print("surviving(tracking), "); - surviving = true; - } - } else { - if (!latestLocation.hasLineInformaltion()) { - writer.print("changed(unknown), "); - } else if (latestLocation instanceof Location_ADDITION) { - writer.print("changed(addition), "); - } else if (latestLocation instanceof Location_DELETION) { - writer.print("changed(deletion), "); - } else if (latestLocation instanceof Location_REPLACEMENT) { - writer.print("changed(replacement), "); - } else if (latestLocation instanceof Location_UNKNOWN) { - writer.print("changed(unknown), "); - } else { - writer.print("surviving(tracking), "); - surviving = true; - } - } - } - - Integer[] changedRevisions = transition.getChangedRevisions(); - writer.print(Integer.toString(startrev)); - writer.print(", "); - if (surviving) { - writer.print(Integer.toString(endrev)); - } else { - writer.print(Integer.toString(changedRevisions[changedRevisions.length - 1] - 1)); - } - writer.print(", "); - - writer.print(instance.getSourceLines() - .get(0).sourcepath); - writer.print(", "); - - writer.print(initialLocation.getLineRangeText()); - writer.print(", "); - - if (surviving) { - writer.print(latestLocation.getLineRangeText()); - } else { - final Integer revision = changedRevisions[changedRevisions.length - 1] - 1; - final Location location = transition.getLocation(revision); - writer.print(location.getLineRangeText()); - } - writer.println(); - } - } catch (final IOException e) { - - } - } - - static private List getChangedLocations(final String path, final String text, - final boolean bugfix) { - - final List changedLocations = new ArrayList<>(); - - try (final BufferedReader reader = new BufferedReader(new StringReader(text))) { - while (true) { - - final String line = reader.readLine(); - - if (null == line) { - break; - } - - else if (line.startsWith("@@") && line.endsWith("@@")) { - final StringTokenizer tokenizer = new StringTokenizer(line); - final String prefix = tokenizer.nextToken(); - final String beforeLocationText = tokenizer.nextToken(); - final String afterLocationText = tokenizer.nextToken(); - final String suffix = tokenizer.nextToken(); - - final int beforeStartLine = - Integer.parseInt(beforeLocationText.substring(1, beforeLocationText.indexOf(','))) - + 3; - final int beforeEndLine = beforeStartLine - + Integer.parseInt(beforeLocationText.substring(beforeLocationText.indexOf(',') + 1)) - - 3; - final int afterStartLine = - Integer.parseInt(afterLocationText.substring(1, afterLocationText.indexOf(','))) + 3; - final int afterEndLine = afterStartLine - + Integer.parseInt(afterLocationText.substring(afterLocationText.indexOf(',') + 1)) - - 3; - final Location beforeLocation = new Location(path, beforeStartLine, beforeEndLine, false); - final Location afterLocation = new Location(path, afterStartLine, afterEndLine, false); - final ChangedLocation changedLocation = - new ChangedLocation(beforeLocation, afterLocation, bugfix); - changedLocations.add(changedLocation); - } - } - } - - catch (final IOException e) { - e.printStackTrace(); - } - - return changedLocations; - } - - static private Location moveWarningLocation(final Location warningLocation, - final List changedLocations) { - - int movedLOC = 0; - for (final ChangedLocation changedLocation : changedLocations) { - - if (changedLocation.before.endLine < warningLocation.startLine) { - movedLOC += (changedLocation.after.endLine - changedLocation.after.startLine) - - (changedLocation.before.endLine - changedLocation.before.startLine); - } - - else if (warningLocation.endLine < changedLocation.before.startLine) { - // do nothing - } - - else { - final String path = warningLocation.path; - final int movedStartLine = warningLocation.startLine + movedLOC; - final int movedEndLine = warningLocation.endLine + movedLOC; - - final int changedBeforeLength = - changedLocation.before.endLine - changedLocation.before.startLine; - final int changedAfterLength = - changedLocation.after.endLine - changedLocation.after.startLine; - final boolean bugfix = changedLocation.bugfix; - if ((0 < changedBeforeLength) && (0 < changedAfterLength)) { - return new Location_REPLACEMENT(path, movedStartLine, movedEndLine, bugfix); - } else if (0 < changedBeforeLength) { - return new Location_DELETION(path, movedStartLine, movedEndLine, bugfix); - } else if (0 < changedAfterLength) { - return new Location_ADDITION(path, movedStartLine, movedEndLine, bugfix); - } else { - return new Location_UNKNOWN(path, movedStartLine, movedEndLine, bugfix); - } - } - } - - final Location changedWarningLocation = new Location(warningLocation.path, - warningLocation.startLine + movedLOC, warningLocation.endLine + movedLOC, false); - - return changedWarningLocation; - } -} diff --git a/src/nh3/ammonia/FBMeter.java b/src/nh3/ammonia/FBMeter.java deleted file mode 100644 index b4ad6ef..0000000 --- a/src/nh3/ammonia/FBMeter.java +++ /dev/null @@ -1,409 +0,0 @@ -package nh3.ammonia; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.concurrent.atomic.AtomicInteger; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -public class FBMeter { - - public static void main(final String[] args) { - - FBParserConfig.initialize(args); - - final List xmls = FBParserConfig.getInstance() - .getFBRESULTS(); - final Map> bugInstances = new HashMap>(); - for (String xml : xmls) { - final FBParser parser = new FBParser(xml); - parser.perform(); - final List bugs = parser.getBugInstances(); - bugInstances.put(xml, bugs); - } - - final List transitions = new ArrayList(); - for (int i = 2; i < xmls.size(); i++) { - final String earlierXMLFile = xmls.get(i - 1); - final String latterXMLFile = xmls.get(i); - - final Set earlierBugs = new HashSet<>(bugInstances.get(earlierXMLFile)); - final Set latterBugs = new HashSet<>(bugInstances.get(latterXMLFile)); - - final Set survivingBugs = new HashSet<>(); - final Set removedBugs = new HashSet<>(); - for (final BugInstance bug : earlierBugs) { - - if (latterBugs.contains(bug)) { - survivingBugs.add(bug); - } else { - removedBugs.add(bug); - } - } - - final Set addedBugs = new HashSet<>(); - for (final BugInstance bug : latterBugs) { - if (!earlierBugs.contains(bug)) { - addedBugs.add(bug); - } - } - - final Transition pair = - new Transition(earlierXMLFile, latterXMLFile, survivingBugs, addedBugs, removedBugs); - transitions.add(pair); - } - - if (FBParserConfig.getInstance() - .hasSURVIVINGBUGSCSV()) { - final String csvFile = FBParserConfig.getInstance() - .getSURVIVINGBUGSCSV(); - printInCSV(csvFile, transitions, "surviving"); - } - - if (FBParserConfig.getInstance() - .hasREMOVEDBUGSCSV()) { - final String csvFile = FBParserConfig.getInstance() - .getREMOVEDBUGSCSV(); - printInCSV(csvFile, transitions, "removed"); - } - - if (FBParserConfig.getInstance() - .hasADDEDBUGSCSV()) { - final String csvFile = FBParserConfig.getInstance() - .getADDEDBUGSCSV(); - printInCSV(csvFile, transitions, "added"); - } - - if (FBParserConfig.getInstance() - .hasMETRICSRESULTXLSX()) { - final String xlsxFile = FBParserConfig.getInstance() - .getMETRICSRESULTXLSX(); - printInXLSX(xlsxFile, transitions); - } - } - - static private int countBugInstances(final Set instances, final String type) { - int count = 0; - for (final BugInstance instance : instances) { - if (instance.pattern.type.equals(type)) { - count++; - } - } - return count; - } - - static private void printInCSV(final String path, final List transitions, - final String bugText) { - - final SortedMap patternsMap = new TreeMap<>(); - for (final BugPattern pattern : BugPattern.getBugPatterns()) { - final StringBuilder text = new StringBuilder(); - text.append(pattern.type) - .append(", ") - .append(pattern.getAverageRank()) - .append(", ") - .append(pattern.getAveragePriority()) - .append(", ") - .append(pattern.category); - patternsMap.put(pattern, text); - } - - for (final Transition transition : transitions) { - for (final Entry entry : patternsMap.entrySet()) { - final BugPattern pattern = entry.getKey(); - final StringBuilder text = entry.getValue(); - - final Set bugs; - switch (bugText) { - case "surviving": { - bugs = transition.survivingBugs; - break; - } - case "removed": { - bugs = transition.removedBugs; - break; - } - case "added": { - bugs = transition.addedBugs; - break; - } - default: { - bugs = new HashSet<>(); - } - } - final Set instances = BugInstance.getBugInstances(bugs, pattern); - text.append(", ") - .append(Integer.toString(instances.size())); - } - } - - try (final PrintWriter writer = - new PrintWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8"))) { - - final StringBuilder title = new StringBuilder(); - title.append("TYPE, RANK, PRIORITY, CATEGORY"); - for (final Transition transition : transitions) { - title.append(",") - .append(StringUtility.getName(transition.latterXMLFile)); - } - writer.println(title.toString()); - - for (final Entry entry : patternsMap.entrySet()) { - - final StringBuilder text = entry.getValue(); - writer.println(text.toString()); - } - } - - catch (final IOException e) { - e.printStackTrace(); - } - } - - static private void printInXLSX(final String path, final List transitions) { - - try (final Workbook book = new XSSFWorkbook(); - final OutputStream stream = new FileOutputStream(path)) { - - final Sheet sheet = book.createSheet(); - book.setSheetName(0, "metrics"); - - final CellStyle survivingStyle = book.createCellStyle(); - survivingStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); - survivingStyle.setFillForegroundColor(IndexedColors.ROSE.getIndex()); - - final CellStyle removingStyle = book.createCellStyle(); - removingStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); - removingStyle.setFillForegroundColor(IndexedColors.AQUA.getIndex()); - - final CellStyle nocareStyle = book.createCellStyle(); - nocareStyle.setFillPattern(CellStyle.SOLID_FOREGROUND); - nocareStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex()); - - final Row typeRow = sheet.createRow(0); - final Row rankRow = sheet.createRow(1); - final Row priorityRow = sheet.createRow(2); - final Row categoryRow = sheet.createRow(3); - final Row metricRow = sheet.createRow(4); - - typeRow.createCell(0) - .setCellValue("TYPE"); - rankRow.createCell(0) - .setCellValue("RANK"); - priorityRow.createCell(0) - .setCellValue("PRIORITY"); - categoryRow.createCell(0) - .setCellValue("CATETORY"); - metricRow.createCell(0) - .setCellValue("METRIC"); - - int titleColumn = 1; - - for (final BugPattern pattern : BugPattern.getBugPatterns()) { - - typeRow.createCell(titleColumn) - .setCellValue(pattern.type); - sheet.addMergedRegion(new CellRangeAddress(0, 0, titleColumn, titleColumn + 5)); - rankRow.createCell(titleColumn) - .setCellValue(pattern.getRankText()); - sheet.addMergedRegion(new CellRangeAddress(1, 1, titleColumn, titleColumn + 5)); - priorityRow.createCell(titleColumn) - .setCellValue(pattern.getPriorityText()); - sheet.addMergedRegion(new CellRangeAddress(2, 2, titleColumn, titleColumn + 5)); - categoryRow.createCell(titleColumn) - .setCellValue(pattern.category); - sheet.addMergedRegion(new CellRangeAddress(3, 3, titleColumn, titleColumn + 5)); - metricRow.createCell(titleColumn) - .setCellValue("#-surviving-bugs"); - metricRow.createCell(titleColumn + 1) - .setCellValue("#-removed-bugs"); - metricRow.createCell(titleColumn + 2) - .setCellValue("#-added-bugs"); - metricRow.createCell(titleColumn + 3) - .setCellValue("%-surviving-bugs"); - metricRow.createCell(titleColumn + 4) - .setCellValue("%-solved-old"); - metricRow.createCell(titleColumn + 5) - .setCellValue("%-solved-new"); - - titleColumn += 6; - } - - int dataRow = 5; - final Map survivingBugs = new HashMap<>(); - final Map removedBugs = new HashMap<>(); - final Map addedBugs = new HashMap<>(); - for (final Transition pair : transitions) { - - final Row row = sheet.createRow(dataRow); - row.createCell(0) - .setCellValue(StringUtility.getName(pair.latterXMLFile)); - - int dataColumn = 1; - for (final BugPattern pattern : BugPattern.getBugPatterns()) { - - final int numberOfSurvivingBugs = countBugInstances(pair.survivingBugs, pattern.type); - final int numberOfAddedBugs = countBugInstances(pair.addedBugs, pattern.type); - final int numberOfRemovedBugs = countBugInstances(pair.removedBugs, pattern.type); - - float ratioOfSurviving = - (float) numberOfSurvivingBugs / (float) (numberOfSurvivingBugs + numberOfRemovedBugs); - float ratioOfSolvedOld = - (float) numberOfRemovedBugs / (float) (numberOfSurvivingBugs + numberOfRemovedBugs); - float ratioOfSolvednew = - (float) numberOfRemovedBugs / (float) (numberOfSurvivingBugs + numberOfAddedBugs); - - row.createCell(dataColumn) - .setCellValue(numberOfSurvivingBugs); - row.createCell(dataColumn + 1) - .setCellValue(numberOfRemovedBugs); - row.createCell(dataColumn + 2) - .setCellValue(numberOfAddedBugs); - row.createCell(dataColumn + 3) - .setCellValue(ratioOfSurviving); - row.createCell(dataColumn + 4) - .setCellValue(ratioOfSolvedOld); - row.createCell(dataColumn + 5) - .setCellValue(ratioOfSolvednew); - - { - final AtomicInteger number = new AtomicInteger(numberOfSurvivingBugs); - survivingBugs.put(pattern.type, number); - } - - { - AtomicInteger number = removedBugs.get(pattern.type); - if (null == number) { - number = new AtomicInteger(0); - removedBugs.put(pattern.type, number); - } - number.addAndGet(numberOfRemovedBugs); - } - - { - AtomicInteger number = addedBugs.get(pattern.type); - if (null == number) { - number = new AtomicInteger(0); - addedBugs.put(pattern.type, number); - } - number.addAndGet(numberOfAddedBugs); - } - - dataColumn += 6; - } - - dataRow += 1; - } - - { - final Row row = sheet.createRow(dataRow); - row.createCell(0) - .setCellValue("summary"); - - int dataColumn = 1; - for (final BugPattern pattern : BugPattern.getBugPatterns()) { - - final int numberOfSurvivingBugs = survivingBugs.get(pattern.type) - .get(); - final int numberOfRemovedBugs = removedBugs.get(pattern.type) - .get(); - final int numberOfAddedBugs = addedBugs.get(pattern.type) - .get(); - - float ratioOfSurviving = - (float) numberOfSurvivingBugs / (float) (numberOfSurvivingBugs + numberOfRemovedBugs); - float ratioOfSolvedOld = - (float) numberOfRemovedBugs / (float) (numberOfSurvivingBugs + numberOfRemovedBugs); - float ratioOfSolvednew = - (float) numberOfRemovedBugs / (float) (numberOfSurvivingBugs + numberOfAddedBugs); - - row.createCell(dataColumn) - .setCellValue(numberOfSurvivingBugs); - row.createCell(dataColumn + 1) - .setCellValue(numberOfRemovedBugs); - row.createCell(dataColumn + 2) - .setCellValue(numberOfAddedBugs); - row.createCell(dataColumn + 3) - .setCellValue(ratioOfSurviving); - row.createCell(dataColumn + 4) - .setCellValue(ratioOfSolvedOld); - row.createCell(dataColumn + 5) - .setCellValue("No value"); - - CellStyle style = null; - if ((numberOfSurvivingBugs + numberOfRemovedBugs) < 4) { - style = nocareStyle; - } else if (ratioOfSurviving <= 0.2d) { - style = removingStyle; - } else { - style = survivingStyle; - } - - sheet.getRow(0) - .getCell(dataColumn) - .setCellStyle(style); - sheet.getRow(1) - .getCell(dataColumn) - .setCellStyle(style); - sheet.getRow(2) - .getCell(dataColumn) - .setCellStyle(style); - sheet.getRow(3) - .getCell(dataColumn) - .setCellStyle(style); - for (int rowIndex = 4; rowIndex <= dataRow; rowIndex++) { - for (int columnIndex = dataColumn; columnIndex < (dataColumn + 6); columnIndex++) { - sheet.getRow(rowIndex) - .getCell(columnIndex) - .setCellStyle(style); - } - } - - dataColumn += 6; - } - } - - book.write(stream); - } - - catch (final IOException e) { - e.printStackTrace(); - } - } - - static class Transition { - - final String earlierXMLFile; - final String latterXMLFile; - final Set survivingBugs; - final Set addedBugs; - final Set removedBugs; - - Transition(final String earlierXMLFile, final String latterXMLFile, - final Set survivingBugs, final Set addedBugs, - final Set removedBugs) { - this.earlierXMLFile = earlierXMLFile; - this.latterXMLFile = latterXMLFile; - this.survivingBugs = survivingBugs; - this.addedBugs = addedBugs; - this.removedBugs = removedBugs; - } - } -} diff --git a/src/nh3/ammonia/FBParser.java b/src/nh3/ammonia/FBParser.java deleted file mode 100644 index a04e894..0000000 --- a/src/nh3/ammonia/FBParser.java +++ /dev/null @@ -1,214 +0,0 @@ -package nh3.ammonia; - -import java.io.BufferedInputStream; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.zip.GZIPInputStream; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import org.w3c.dom.Document; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.xml.sax.SAXException; - -public class FBParser { - - public static void main(String[] args) { - - final FBParser parser = new FBParser(args[0]); - parser.perform(); - - try (final BufferedWriter writer = new BufferedWriter( - (2 <= args.length) ? new FileWriter(args[1]) : new PrintWriter(System.out))) { - for (final ClassStats cs : parser.getSummary()) { - if (0 < cs.bugs) { - writer.write(cs.toString()); - writer.newLine(); - } - } - } catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - } - - final public String path; - final private List buginstances; - final private SortedSet summary; - - public FBParser(final String path) { - this.path = path; - this.buginstances = new ArrayList<>(); - this.summary = new TreeSet<>(); - } - - public List getBugInstances() { - return new ArrayList(this.buginstances); - } - - public SortedSet getSummary() { - return new TreeSet(this.summary); - } - - public void perform() { - - if (0 < this.summary.size()) { - return; - } - - final File file = new File(this.path); - final Document document = read(file); - - if (document.hasChildNodes()) { - - final Node bugCollection = document.getFirstChild(); - assert bugCollection.getNodeName() - .equals("BugCollection") : "input file has illegal format."; - - if (bugCollection.hasChildNodes()) { - - for (Node cn1 = bugCollection.getFirstChild(); null != cn1; cn1 = cn1.getNextSibling()) { - - if (cn1.getNodeName() - .equals("Project")) { - } - - else if (cn1.getNodeName() - .equals("BugInstance")) { - - final NamedNodeMap nnMap1 = cn1.getAttributes(); - final Node typeNode = nnMap1.getNamedItem("type"); - final Node priorityNode = nnMap1.getNamedItem("priority"); - final Node rankNode = nnMap1.getNamedItem("rank"); - final Node abbrevNode = nnMap1.getNamedItem("abbrev"); - final Node categoryNode = nnMap1.getNamedItem("category"); - final Node instanceHashNode = nnMap1.getNamedItem("instanceHash"); - - final String type = typeNode.getNodeValue(); - BugPattern pattern = BugPattern.getBugPattern(type); - if (null == pattern) { - final String category = categoryNode.getNodeValue(); - pattern = new BugPattern(type, category); - BugPattern.addBugPattern(pattern); - } - - final int priority = Integer.parseInt(priorityNode.getNodeValue()); - final int rank = Integer.parseInt(rankNode.getNodeValue()); - final String instanceHash = instanceHashNode.getNodeValue(); - final BugInstance instance = new BugInstance(pattern, rank, priority, instanceHash); - pattern.addBugInstance(this.path, instance); - - for (Node cn2 = cn1.getFirstChild(); null != cn2; cn2 = cn2.getNextSibling()) { - - if (cn2.getNodeName() - .equals("SourceLine")) { - final SourceLine sourceline = getSourceLine(cn2, null); - if ((null != sourceline.sourcepath) && (0 < sourceline.start) - && (0 < sourceline.end)) { - instance.addSourceLine(sourceline); - } - } - } - - if (!instance.getSourceLines() - .isEmpty()) { - this.buginstances.add(instance); - } - } - - else if (cn1.getNodeName() - .equals("FindBugsSummary")) { - for (Node cn2 = cn1.getFirstChild(); null != cn2; cn2 = cn2.getNextSibling()) { - if (cn2.getNodeName() - .equals("PackageStats")) { - for (Node cn3 = cn2.getFirstChild(); null != cn3; cn3 = cn3.getNextSibling()) { - if (cn3.getNodeName() - .equals("ClassStats")) { - final ClassStats cs = ClassStats.makeClassStats(cn3); - this.summary.add(cs); - } - } - } - } - } - } - } - } - - // buginstances.sort(new BugInstance.LocationComparator()); - // for (final BugInstance buginstance : buginstances) { - // print(buginstance); - // } - } - - public static Document read(final File file) { - - DocumentBuilder documentBuilder = null; - try { - documentBuilder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - System.exit(0); - } - - Document document = null; - try { - if (file.getName() - .endsWith(".xml")) { - document = documentBuilder.parse(new BufferedInputStream(new FileInputStream(file))); - } else if (file.getName() - .endsWith(".gz")) { - document = documentBuilder - .parse(new GZIPInputStream(new BufferedInputStream(new FileInputStream(file)))); - } else { - System.err.println("option \"fbresults\" must be .xml or .gz file."); - System.exit(0); - } - } catch (final SAXException | IOException e) { - e.printStackTrace(); - System.exit(0); - } - - return document; - } - - private static SourceLine getSourceLine(final Node sourcelineNode, final String name) { - final NamedNodeMap nnMap = sourcelineNode.getAttributes(); - final Node classnameNode = nnMap.getNamedItem("classname"); - final Node startNode = nnMap.getNamedItem("start"); - final Node endNode = nnMap.getNamedItem("end"); - final Node sourcepathNode = nnMap.getNamedItem("sourcepath"); - final SourceLine sourceline = new SourceLine(classnameNode.getNodeValue(), - (null != startNode) ? Integer.parseInt(startNode.getNodeValue()) : 0, - (null != endNode) ? Integer.parseInt(endNode.getNodeValue()) : 0, - (null != sourcepathNode) ? sourcepathNode.getNodeValue() : null, name); - return sourceline; - } - - private static String makeText(final String element, final SourceLine sourceline) { - final StringBuilder text = new StringBuilder(); - text.append(" "); - text.append(element); - text.append(": "); - text.append(sourceline.name); - if (0 < sourceline.start) { - text.append(", "); - text.append(Integer.toString(sourceline.start)); - } - if (0 < sourceline.end) { - text.append("--"); - text.append(Integer.toString(sourceline.end)); - } - return text.toString(); - } -} diff --git a/src/nh3/ammonia/Location.java b/src/nh3/ammonia/Location.java deleted file mode 100644 index 8c3770f..0000000 --- a/src/nh3/ammonia/Location.java +++ /dev/null @@ -1,45 +0,0 @@ -package nh3.ammonia; - -public class Location { - - final public String path; - final public int startLine; - final public int endLine; - final public boolean bugfix; - - public Location(final String path, final int startLine, final int endLine, final boolean bugfix) { - this.path = path; - this.startLine = startLine; - this.endLine = endLine; - this.bugfix = bugfix; - } - - public boolean hasLineInformaltion() { - return (0 < this.startLine) && (0 < this.endLine); - } - - public String getLineRangeText() { - if (this.hasLineInformaltion()) { - return this.startLine + "--" + this.endLine; - } else { - return "no-line-information"; - } - } - - @Override - public boolean equals(final Object o) { - - if (!(o instanceof Location)) { - return false; - } - - final Location target = (Location) o; - return this.path.equals(target.path) && (this.startLine == target.startLine) - && (this.endLine == target.endLine); - } - - @Override - public int hashCode() { - return this.path.hashCode() + this.startLine + this.endLine; - } -} diff --git a/src/nh3/ammonia/LocationTransition.java b/src/nh3/ammonia/LocationTransition.java deleted file mode 100644 index 91242a6..0000000 --- a/src/nh3/ammonia/LocationTransition.java +++ /dev/null @@ -1,65 +0,0 @@ -package nh3.ammonia; - -import java.util.Map.Entry; -import java.util.SortedMap; -import java.util.TreeMap; - -public class LocationTransition { - - final private SortedMap locations; - - public LocationTransition() { - this.locations = new TreeMap<>(); - } - - public void add(final Integer revision, final Location location) { - this.locations.put(revision, location); - } - - public Location getLocation(final Integer revision) { - - Location location = null; - for (final Entry entry : this.locations.entrySet()) { - - final Integer currentRevision = entry.getKey(); - final Location currentLocation = entry.getValue(); - - if (revision < currentRevision) { - return location; - } - - else { - location = currentLocation; - } - } - - return location; - } - - public Location getInitialLocation() { - final Integer firstRevision = this.locations.firstKey(); - final Location location = this.locations.get(firstRevision); - return location; - } - - public Location getLatestLocation() { - final Integer lastRevision = this.locations.lastKey(); - final Location range = this.locations.get(lastRevision); - return range; - } - - public boolean hasChanged() { - final Location latestRange = this.getLatestLocation(); - if (latestRange instanceof Location_ADDITION || latestRange instanceof Location_DELETION - || latestRange instanceof Location_REPLACEMENT || latestRange instanceof Location_UNKNOWN) { - return true; - } else { - return false; - } - } - - public Integer[] getChangedRevisions() { - return this.locations.keySet() - .toArray(new Integer[0]); - } -} diff --git a/src/nh3/ammonia/Location_ADDITION.java b/src/nh3/ammonia/Location_ADDITION.java deleted file mode 100644 index d90bf73..0000000 --- a/src/nh3/ammonia/Location_ADDITION.java +++ /dev/null @@ -1,9 +0,0 @@ -package nh3.ammonia; - -public class Location_ADDITION extends Location { - - public Location_ADDITION(final String path, final int startLine, final int endLine, - final boolean bugfix) { - super(path, startLine, endLine, bugfix); - } -} diff --git a/src/nh3/ammonia/Location_DELETION.java b/src/nh3/ammonia/Location_DELETION.java deleted file mode 100644 index 14ffe13..0000000 --- a/src/nh3/ammonia/Location_DELETION.java +++ /dev/null @@ -1,9 +0,0 @@ -package nh3.ammonia; - -public class Location_DELETION extends Location { - - public Location_DELETION(final String path, final int startLine, final int endLine, - final boolean bugfix) { - super(path, startLine, endLine, bugfix); - } -} diff --git a/src/nh3/ammonia/Location_REPLACEMENT.java b/src/nh3/ammonia/Location_REPLACEMENT.java deleted file mode 100644 index 3bb5e98..0000000 --- a/src/nh3/ammonia/Location_REPLACEMENT.java +++ /dev/null @@ -1,9 +0,0 @@ -package nh3.ammonia; - -public class Location_REPLACEMENT extends Location { - - public Location_REPLACEMENT(final String path, final int startLine, final int endLine, - final boolean bugfix) { - super(path, startLine, endLine, bugfix); - } -} diff --git a/src/nh3/ammonia/Location_UNKNOWN.java b/src/nh3/ammonia/Location_UNKNOWN.java deleted file mode 100644 index 28ffce7..0000000 --- a/src/nh3/ammonia/Location_UNKNOWN.java +++ /dev/null @@ -1,9 +0,0 @@ -package nh3.ammonia; - -public class Location_UNKNOWN extends Location { - - public Location_UNKNOWN(final String path, final int startLine, final int endLine, - final boolean bugfix) { - super(path, startLine, endLine, bugfix); - } -} diff --git a/src/nh3/ammonia/Pattern.java b/src/nh3/ammonia/Pattern.java new file mode 100644 index 0000000..0795409 --- /dev/null +++ b/src/nh3/ammonia/Pattern.java @@ -0,0 +1,201 @@ +package nh3.ammonia; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.stream.Collectors; +import yoshikihigo.cpanalyzer.data.Statement; + +public class Pattern extends SimplePattern implements Comparable { + + + final public List beforeTextHashs; + final public List afterTextHashs; + final public List periods; + final public List ids; + final public List dates; + public int mergedID; + public int findbugsSupport; + public int support; + public int bugfixSupport; + public int beforeTextSupport; + public String beforeTextSupportPeriod; + public int commits; + public int bugfixCommits; + final public Map occupancies; + final public Map deltaCFPFs; + final private SortedSet files; + final private SortedSet bugfixFiles; + final private SortedSet authors; + final private SortedSet bugfixAuthors; + + public Pattern(final String beforeText, final String afterText) { + super(beforeText, afterText); + this.beforeTextHashs = StringUtility.split(beforeText) + .stream() + .map(text -> Statement.getMD5(text)) + .collect(Collectors.toList()); + this.afterTextHashs = StringUtility.split(afterText) + .stream() + .map(text -> Statement.getMD5(text)) + .collect(Collectors.toList()); + this.periods = new ArrayList<>(); + this.ids = new ArrayList<>(); + this.dates = new ArrayList<>(); + this.mergedID = 0; + this.findbugsSupport = 0; + this.support = 0; + this.bugfixSupport = 0; + this.beforeTextSupport = 0; + this.beforeTextSupportPeriod = null; + this.commits = 0; + this.bugfixCommits = 0; + this.occupancies = new HashMap<>(); + this.deltaCFPFs = new HashMap<>(); + this.files = new TreeSet<>(); + this.bugfixFiles = new TreeSet<>(); + this.authors = new TreeSet<>(); + this.bugfixAuthors = new TreeSet<>(); + } + + public void addPeriod(final String period) { + this.periods.add(period); + } + + public List getPeriods() { + return new ArrayList(this.periods); + } + + public void addID(final String id) { + this.ids.add(id); + } + + public String getIDsText() { + return nh3.ammonia.StringUtility.concatinate(this.ids); + } + + public List getIDs() { + return new ArrayList(this.ids); + } + + public void addFiles(final String fileText) { + this.files.addAll(StringUtility.split(fileText)); + } + + public void addFiles(final Collection files) { + this.files.addAll(files); + } + + public SortedSet getFiles() { + return new TreeSet(this.files); + } + + public void addBugfixFiles(final String fileText) { + this.bugfixFiles.addAll(StringUtility.split(fileText)); + } + + public void addBugfixFiles(final Collection files) { + this.bugfixFiles.addAll(files); + } + + public SortedSet getBugfixFiles() { + return new TreeSet(this.bugfixFiles); + } + + public void addAuthors(final String authorText) { + this.authors.addAll(StringUtility.split(authorText)); + } + + public void addAuthors(final Collection authors) { + this.authors.addAll(authors); + } + + public SortedSet getAuthors() { + return new TreeSet<>(this.authors); + } + + public void addBugfixAuthors(final String authorText) { + this.bugfixAuthors.addAll(StringUtility.split(authorText)); + } + + public void addBugfixAuthors(final Collection authors) { + this.bugfixAuthors.addAll(authors); + } + + public SortedSet getBugfixAuthors() { + return new TreeSet<>(this.bugfixAuthors); + } + + public void addDate(final String date) { + this.dates.add(date); + } + + public String getFirstDate() { + Collections.sort(this.dates); + return this.dates.get(0); + } + + public String getLastDate() { + Collections.sort(this.dates); + return this.dates.get(this.dates.size() - 1); + } + + public void addOccupancy(final String period, final Double occupancy) { + this.occupancies.put(period, occupancy); + } + + public Double getMaxOccuapncy() { + double max = 0d; + for (final Double occupancy : this.occupancies.values()) { + if (max < occupancy) { + max = occupancy; + } + } + return max; + } + + public String getOccupanciesText() { + final StringBuilder text = new StringBuilder(); + for (final Entry entry : this.occupancies.entrySet()) { + text.append(entry.getKey()); + text.append(": "); + text.append(entry.getValue()); + text.append(System.lineSeparator()); + } + return text.toString(); + } + + public void addDeltaCFPF(final String period, final Double deltaCFPF) { + this.deltaCFPFs.put(period, deltaCFPF); + } + + public Double getDeltaCFPF(final int allBugfixCommits, final int allNonbugfixCommits) { + final double pf = (double) this.support / (double) this.beforeTextSupport; + final double cf1 = (double) this.bugfixCommits / (double) allBugfixCommits; + final double cf2 = (double) (this.commits - this.bugfixCommits) / (double) allNonbugfixCommits; + final double pfcf = pf * (cf1 - cf2); + return pfcf; + } + + public String getDeltaCFPFsText() { + final StringBuilder text = new StringBuilder(); + for (final Entry entry : this.deltaCFPFs.entrySet()) { + text.append(entry.getKey()); + text.append(": "); + text.append(entry.getValue()); + text.append(System.lineSeparator()); + } + return text.toString(); + } + + @Override + public int compareTo(final Pattern target) { + return Integer.compare(this.mergedID, target.mergedID); + } +} diff --git a/src/nh3/ammonia/SimplePattern.java b/src/nh3/ammonia/SimplePattern.java new file mode 100644 index 0000000..f3b0eef --- /dev/null +++ b/src/nh3/ammonia/SimplePattern.java @@ -0,0 +1,35 @@ +package nh3.ammonia; + +import java.util.List; + +public class SimplePattern { + + + final public String beforeText; + final public String afterText; + final public List beforeTextPattern; + final public List afterTextPattern; + + public SimplePattern(final String beforeText, final String afterText) { + this.beforeText = beforeText; + this.afterText = afterText; + this.beforeTextPattern = StringUtility.split(beforeText); + this.afterTextPattern = StringUtility.split(afterText); + } + + @Override + final public boolean equals(final Object o) { + + if (!(o instanceof SimplePattern)) { + return false; + } + + final SimplePattern target = (SimplePattern) o; + return this.beforeText.equals(target.beforeText) && this.afterText.equals(target.afterText); + } + + @Override + final public int hashCode() { + return this.beforeText.hashCode() + this.afterText.hashCode(); + } +} diff --git a/src/nh3/ammonia/SourceLine.java b/src/nh3/ammonia/SourceLine.java deleted file mode 100644 index f2b5db0..0000000 --- a/src/nh3/ammonia/SourceLine.java +++ /dev/null @@ -1,62 +0,0 @@ -package nh3.ammonia; - -public class SourceLine implements Comparable { - - final public String classname; - final public int start; - final public int end; - final public String sourcepath; - final public String name; - - public SourceLine(final String classname, final int start, final int end, final String sourcepath, - final String name) { - this.classname = classname; - this.start = start; - this.end = end; - this.sourcepath = sourcepath; - this.name = name; - } - - @Override - public int compareTo(final SourceLine target) { - - final int classnameComparison = this.classname.compareTo(target.classname); - if (0 != classnameComparison) { - return classnameComparison; - } - - else if (this.start < target.start) { - return -1; - } else if (this.start > target.start) { - return 1; - } - - else if (this.end < target.end) { - return -1; - } else if (this.end > target.end) { - return 1; - } - - else { - return 0; - } - } - - static public String makeText(final String element, final SourceLine sourceline) { - final StringBuilder text = new StringBuilder(); - text.append(" "); - text.append(element); - text.append(": "); - text.append(sourceline.name); - if (0 < sourceline.start) { - text.append(", "); - text.append(Integer.toString(sourceline.start)); - } - if (0 < sourceline.end) { - text.append("--"); - text.append(Integer.toString(sourceline.end)); - } - return text.toString(); - } - -} diff --git a/src/nh3/ammonia/XLSXMerger.java b/src/nh3/ammonia/XLSXMerger.java deleted file mode 100644 index 7b2cfb1..0000000 --- a/src/nh3/ammonia/XLSXMerger.java +++ /dev/null @@ -1,739 +0,0 @@ -package nh3.ammonia; - -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.SortedSet; -import java.util.TreeSet; -import java.util.stream.Collectors; -import org.apache.poi.ss.usermodel.Cell; -import org.apache.poi.ss.usermodel.CellStyle; -import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.Comment; -import org.apache.poi.ss.usermodel.CreationHelper; -import org.apache.poi.ss.usermodel.Drawing; -import org.apache.poi.ss.usermodel.IndexedColors; -import org.apache.poi.ss.usermodel.Row; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.xssf.usermodel.XSSFCellStyle; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import yoshikihigo.cpanalyzer.data.Statement; - -public class XLSXMerger { - - public static void main(final String[] args) { - - for (String arg : args) { - System.out.println(arg); - } - - if (args.length < 2) { - System.err.println("two or more arguments are required."); - System.exit(0); - } - - final String mergedXLSXPath = args[0]; - - final Map patterns = new HashMap<>(); - final List allBugfixCommits = new ArrayList<>(); - final List allNonbugfixCommits = new ArrayList<>(); - for (int index = 1; index < args.length; index++) { - readXLSX(patterns, allBugfixCommits, allNonbugfixCommits, args[index]); - } - - final int allBugfixCommitNumber = allBugfixCommits.stream() - .mapToInt(value -> value.intValue()) - .sum(); - final int allNonbugfixCommitNumber = allNonbugfixCommits.stream() - .mapToInt(value -> value.intValue()) - .sum(); - - final List bugfixFileData = new ArrayList<>(); - final List fileDiffData = new ArrayList<>(); - final List dayDiffData = new ArrayList<>(); - for (final PATTERN pattern : patterns.values()) { - final int bugfixFiles = pattern.bugfixFiles.size(); - if (1 < bugfixFiles) { - bugfixFileData.add(bugfixFiles); - } - final int fileDiff = pattern.files.size() - pattern.bugfixFiles.size(); - if (0 < fileDiff) { - fileDiffData.add(fileDiff); - } - final int dayDifference = getDayDifference(pattern.getFirstDate(), pattern.getLastDate()); - if (0 < dayDifference) { - dayDiffData.add(dayDifference); - } - } - Collections.sort(bugfixFileData); - Collections.sort(fileDiffData); - Collections.sort(dayDiffData); - - writeXLSX(patterns, allBugfixCommitNumber, allNonbugfixCommitNumber, bugfixFileData, - fileDiffData, dayDiffData, mergedXLSXPath); - } - - private static void readXLSX(final Map patterns, - final List allBugfixCommits, final List allNonbugfixCommits, - final String xlsxPath) { - - final String period = StringUtility.removeExtension(StringUtility.getName(xlsxPath)); - - try (final Workbook book = new XSSFWorkbook(new FileInputStream(xlsxPath))) { - final Sheet sheet = book.getSheetAt(0); - - { - final Row titleRow = sheet.getRow(0); - final int bugfixCommit = (int) titleRow.getCell(25) - .getNumericCellValue(); - allBugfixCommits.add(bugfixCommit); - final int nonbugfixCommit = (int) titleRow.getCell(26) - .getNumericCellValue(); - allNonbugfixCommits.add(nonbugfixCommit); - } - - final int lastRowNumber = sheet.getLastRowNum(); - for (int rowNumber = 1; rowNumber < lastRowNumber; rowNumber++) { - final Row row = sheet.getRow(rowNumber); - final String beforeText = row.getCell(19) - .getStringCellValue(); - final String afterText = row.getCell(20) - .getStringCellValue(); - final SIMPLE_PATTERN p = new SIMPLE_PATTERN(beforeText, afterText); - PATTERN pattern = patterns.get(p); - if (null == pattern) { - pattern = new PATTERN(beforeText, afterText); - patterns.put(p, pattern); - } - - pattern.addPeriod(period); - - final String id = period + ": " + Integer.toString((int) row.getCell(0) - .getNumericCellValue()); - pattern.addID(id); - - final int findbugsSupport = (int) row.getCell(1) - .getNumericCellValue(); - pattern.findbugsSupport += findbugsSupport; - - final int support = (int) row.getCell(6) - .getNumericCellValue(); - pattern.support += support; - final int bugfixSupport = (int) row.getCell(7) - .getNumericCellValue(); - pattern.bugfixSupport += bugfixSupport; - final int beforeTextSupport = (int) row.getCell(8) - .getNumericCellValue(); - if (null == pattern.beforeTextSupportPeriod) { - pattern.beforeTextSupport = beforeTextSupport; - pattern.beforeTextSupportPeriod = period; - } - - final int commits = (int) row.getCell(12) - .getNumericCellValue(); - pattern.commits += commits; - final int bugfixCommits = (int) row.getCell(13) - .getNumericCellValue(); - pattern.bugfixCommits += bugfixCommits; - - final String firstDate = row.getCell(14) - .getStringCellValue(); - pattern.addDate(firstDate); - final String lastDate = row.getCell(15) - .getStringCellValue(); - pattern.addDate(lastDate); - - final double occupancy = row.getCell(17) - .getNumericCellValue(); - pattern.addOccupancy(period, occupancy); - final double deltaCFPF = row.getCell(18) - .getNumericCellValue(); - pattern.addDeltaCFPF(period, deltaCFPF); - - final String authorText = row.getCell(21) - .getStringCellValue(); - pattern.addAuthors(authorText); - final String bugfixAuthorText = row.getCell(22) - .getStringCellValue(); - pattern.addBugfixAuthors(bugfixAuthorText); - - final String fileText = row.getCell(23) - .getStringCellValue(); - pattern.addFiles(fileText); - final String bugfixFileText = row.getCell(24) - .getStringCellValue(); - pattern.addBugfixFiles(bugfixFileText); - } - } - - catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - } - - private static void writeXLSX(final Map patterns, - final int allBugfixCommits, final int allNonbugfixCommits, final List bugfixFileData, - final List fileDiffData, final List dayDifferenceData, - final String xlsxPath) { - - try (final Workbook book = new XSSFWorkbook(); - final OutputStream stream = new FileOutputStream(xlsxPath)) { - - Cell firstCell = null; - Cell lastCell = null; - - final Sheet sheet = book.createSheet(); - book.setSheetName(0, "merged change patterns"); - final Row titleRow = sheet.createRow(0); - titleRow.createCell(0) - .setCellValue("MERGED-PATTERN-ID"); - titleRow.createCell(1) - .setCellValue("PATTERN-ID"); - titleRow.createCell(2) - .setCellValue("FINDBUGS-SUPPORT"); - titleRow.createCell(3) - .setCellValue("AUTHORS"); - titleRow.createCell(4) - .setCellValue("BUG-FIX-AUTHORS"); - titleRow.createCell(5) - .setCellValue("FILES"); - titleRow.createCell(6) - .setCellValue("BUG-FIX-FILES"); - titleRow.createCell(7) - .setCellValue("SUPPORT"); - titleRow.createCell(8) - .setCellValue("BUG-FIX-SUPPORT"); - titleRow.createCell(9) - .setCellValue("BEFORE-TEXT-SUPPORT"); - titleRow.createCell(10) - .setCellValue("CONFIDENCE1"); - titleRow.createCell(11) - .setCellValue("CONFIDENCE2"); - titleRow.createCell(12) - .setCellValue("CONFIDENCE3"); - titleRow.createCell(13) - .setCellValue("COMMITS"); - titleRow.createCell(14) - .setCellValue("BUG-FIX-COMMIT"); - titleRow.createCell(15) - .setCellValue("FIRST-DATE"); - titleRow.createCell(16) - .setCellValue("LAST-DATE"); - titleRow.createCell(17) - .setCellValue("DATE-DIFFERENCE"); - titleRow.createCell(18) - .setCellValue("OCCUPANCY"); - titleRow.createCell(19) - .setCellValue("Delta-PFCF"); - titleRow.createCell(20) - .setCellValue("RANK-of-\"G\""); - titleRow.createCell(21) - .setCellValue("RANK-of-\"F-G\""); - titleRow.createCell(22) - .setCellValue("RANK-of-\"R\""); - titleRow.createCell(23) - .setCellValue("TEXT-BEFORE-CHANGE"); - titleRow.createCell(24) - .setCellValue("TEXT-AFTER-CHANGE"); - titleRow.createCell(25) - .setCellValue("AUTHOR-LIST"); - titleRow.createCell(26) - .setCellValue("BUG-FIX-AUTHOR-LIST"); - titleRow.createCell(27) - .setCellValue("FILE-LIST"); - titleRow.createCell(28) - .setCellValue("BUG-FIX-FILE-LIST"); - - firstCell = titleRow.getCell(0); - lastCell = titleRow.getCell(28); - - setCellComment(titleRow.getCell(2), "Higo", - "number of periods detected or not detected by FindBugs", 4, 1); - setCellComment(titleRow.getCell(3), "Higo", - "the number of authors that committed the change pattern in all commits", 5, 1); - setCellComment(titleRow.getCell(4), "Higo", - "the number of authors commited the change pattern in bug-fix commits", 5, 1); - setCellComment(titleRow.getCell(5), "Higo", - "the number of files where the change pattern appeared in all commits", 5, 1); - setCellComment(titleRow.getCell(6), "Higo", - "the number of files where the change pattern appeared in bug-fix commits", 5, 1); - setCellComment(titleRow.getCell(7), "Higo", "the number of occurences of a given pattern", 4, - 1); - setCellComment(titleRow.getCell(8), "Higo", - "the number of occurences of a given pattern in bug-fix commits", 4, 1); - setCellComment(titleRow.getCell(9), "Higo", - "the number of code fragments whose texts are " - + "identical to before-text of a given pattern " - + "in the commit where the pattern appears initially", - 4, 2); - setCellComment(titleRow.getCell(10), "Higo", "BUG-FIX-SUPPORT / SUPPORT", 4, 1); - setCellComment(titleRow.getCell(11), "Higo", "SUPPORT / BEFORE-TEXT-SUPPORT", 4, 1); - setCellComment(titleRow.getCell(12), "Higo", "BUG-FIX-SUPPORT / BEFORE-TEXT-SUPPORT", 4, 1); - setCellComment(titleRow.getCell(13), "Higo", - "the number of commits where the pattern appears", 4, 1); - setCellComment(titleRow.getCell(14), "Higo", - "the number of bug-fix commits where the pattern appears", 4, 1); - setCellComment(titleRow.getCell(18), "Higo", - "average of (LOC of a given pattern changed in revision R) / " - + "(total LOC changed in revision R) " - + "for all the revisions where the pattern appears", - 4, 2); - setCellComment(titleRow.getCell(19), "Higo", - "delta-CFPF was calculated with the following formula" + System.lineSeparator() - + "pf*(cf1 - cf2)" + System.lineSeparator() - + "pf: pattern frequency, which is calculated as support / before-text-support" - + System.lineSeparator() - + "cf1: bug-fix commit frequensy, which is calculated as bug-fix commits / all bug-fix commits" - + System.lineSeparator() - + "cf2: non-bug-fix commit frequency, which is calculated as non-bug-fix commits / all non-bug-fix commits", - 4, 5); - setCellComment(titleRow.getCell(20), "Higo", "Ranking of the number of bug-fix files", 3, 1); - setCellComment(titleRow.getCell(21), "Higo", - "Ranking of difference between files and bug-fix files", 4, 1); - setCellComment(titleRow.getCell(22), "Higo", "Ranking of date difference", 3, 1); - - int currentRow = 1; - final List patternlist = new ArrayList<>(patterns.values()); - Collections.sort(patternlist, - (o1, o2) -> Integer.compare(o1.bugfixCommits, o2.bugfixCommits)); - for (final PATTERN cp : patternlist) { - - if (cp.beforeText.isEmpty() || cp.afterText.isEmpty()) { - continue; - } - - final Row dataRow = sheet.createRow(currentRow++); - dataRow.createCell(0) - .setCellValue(dataRow.getRowNum()); - dataRow.createCell(1) - .setCellValue(cp.getIDsText()); - dataRow.createCell(2) - .setCellValue(cp.findbugsSupport); - dataRow.createCell(3) - .setCellValue(cp.getAuthors() - .size()); - dataRow.createCell(4) - .setCellValue(cp.getBugfixAuthors() - .size()); - dataRow.createCell(5) - .setCellValue(cp.getFiles() - .size()); - dataRow.createCell(6) - .setCellValue(cp.getBugfixFiles() - .size()); - dataRow.createCell(7) - .setCellValue(cp.support); - dataRow.createCell(8) - .setCellValue(cp.bugfixSupport); - dataRow.createCell(9) - .setCellValue(cp.beforeTextSupport); - dataRow.createCell(10) - .setCellValue((float) cp.bugfixSupport / (float) cp.support); - dataRow.createCell(11) - .setCellValue((float) cp.support / (float) cp.beforeTextSupport); - dataRow.createCell(12) - .setCellValue((float) cp.bugfixSupport / (float) cp.beforeTextSupport); - dataRow.createCell(13) - .setCellValue(cp.commits); - dataRow.createCell(14) - .setCellValue(cp.bugfixCommits); - dataRow.createCell(15) - .setCellValue(cp.getFirstDate()); - dataRow.createCell(16) - .setCellValue(cp.getLastDate()); - dataRow.createCell(17) - .setCellValue(getDayDifference(cp.getFirstDate(), cp.getLastDate())); - dataRow.createCell(18) - .setCellValue(cp.getMaxOccuapncy()); - dataRow.createCell(19) - .setCellValue(cp.getDeltaCFPF(allBugfixCommits, allNonbugfixCommits)); - - dataRow.createCell(20) - .setCellValue(getRank(bugfixFileData, cp.bugfixFiles.size(), 1)); - dataRow.createCell(21) - .setCellValue(getRank(fileDiffData, (cp.files.size() - cp.bugfixFiles.size()), 0)); - dataRow.createCell(22) - .setCellValue(getRank(dayDifferenceData, - getDayDifference(cp.getFirstDate(), cp.getLastDate()), 0)); - - dataRow.createCell(23) - .setCellValue( - cp.beforeText.length() > 32767 ? cp.beforeText.substring(0, 32767) : cp.beforeText); - dataRow.createCell(24) - .setCellValue( - cp.afterText.length() > 32767 ? cp.afterText.substring(0, 32767) : cp.afterText); - dataRow.createCell(25) - .setCellValue(StringUtility.concatinate(cp.getAuthors())); - dataRow.createCell(26) - .setCellValue(StringUtility.concatinate(cp.getBugfixAuthors())); - dataRow.createCell(27) - .setCellValue(StringUtility.concatinate(cp.getFiles())); - dataRow.createCell(28) - .setCellValue(StringUtility.concatinate(cp.getBugfixFiles())); - lastCell = dataRow.getCell(28); - - setCellComment(dataRow.getCell(9), "Higo", cp.beforeTextSupportPeriod, 1, 1); - setCellComment(dataRow.getCell(18), "Higo", cp.getOccupanciesText(), 3, cp.getPeriods() - .size()); - setCellComment(dataRow.getCell(19), "Higo", cp.getDeltaCFPFsText(), 3, cp.getPeriods() - .size()); - - final CellStyle style = book.createCellStyle(); - style.setWrapText(true); - style.setFillPattern(CellStyle.SOLID_FOREGROUND); - style.setFillForegroundColor(IndexedColors.WHITE.getIndex()); - style.setBorderBottom(XSSFCellStyle.BORDER_THIN); - style.setBorderLeft(XSSFCellStyle.BORDER_THIN); - style.setBorderRight(XSSFCellStyle.BORDER_THIN); - style.setBorderTop(XSSFCellStyle.BORDER_THIN); - style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); - for (int column = 0; column <= 25; column++) { - dataRow.getCell(column) - .setCellStyle(style); - } - - final int[] locs = new int[] {cp.getIDs() - .size(), - cp.getAuthors() - .size(), - cp.getFiles() - .size(), - StringUtility.getLOC(cp.beforeText), StringUtility.getLOC(cp.afterText)}; - Arrays.sort(locs); - dataRow.setHeight((short) (locs[locs.length - 1] * dataRow.getHeight())); - } - - sheet.autoSizeColumn(0, true); - sheet.setColumnWidth(1, 5120); - sheet.autoSizeColumn(2, true); - sheet.autoSizeColumn(3, true); - sheet.autoSizeColumn(4, true); - sheet.autoSizeColumn(5, true); - sheet.autoSizeColumn(6, true); - sheet.autoSizeColumn(7, true); - sheet.autoSizeColumn(8, true); - sheet.autoSizeColumn(9, true); - sheet.autoSizeColumn(10, true); - sheet.autoSizeColumn(11, true); - sheet.autoSizeColumn(12, true); - sheet.autoSizeColumn(13, true); - sheet.autoSizeColumn(14, true); - sheet.autoSizeColumn(15, true); - sheet.autoSizeColumn(16, true); - sheet.autoSizeColumn(17, true); - sheet.autoSizeColumn(18, true); - sheet.autoSizeColumn(19, true); - sheet.autoSizeColumn(20, true); - sheet.autoSizeColumn(21, true); - sheet.autoSizeColumn(22, true); - sheet.setColumnWidth(23, 20480); - sheet.setColumnWidth(24, 5120); - sheet.setColumnWidth(25, 5120); - sheet.setColumnWidth(26, 20480); - sheet.setColumnWidth(27, 20480); - sheet.setColumnWidth(28, 20480); - - sheet.setAutoFilter(new CellRangeAddress(firstCell.getRowIndex(), lastCell.getRowIndex(), - firstCell.getColumnIndex(), lastCell.getColumnIndex())); - sheet.createFreezePane(0, 1, 0, 1); - - book.write(stream); - - } catch (final IOException e) { - e.printStackTrace(); - System.exit(0); - } - } - - private static String getRank(final List data, final int value, final int lowestValue) { - - if (value == lowestValue) { - return "NONE"; - } - - int matchedIndex = 0; - for (int index = 0; index < data.size(); index++) { - if (data.get(index) == value) { - matchedIndex = index; - break; - } - } - - // System.out.println(matchedIndex + " : " + data.size()); - - final float position = (float) matchedIndex / (float) data.size(); - if (position < 0.334) { - return "LOW"; - } else if (position < 0.667) { - return "MIDDLE"; - } else { - return "HIGH"; - } - } - - private static void setCellComment(final Cell cell, final String author, final String text, - final int width, final int height) { - - final Sheet sheet = cell.getSheet(); - final Workbook workbook = sheet.getWorkbook(); - final CreationHelper helper = workbook.getCreationHelper(); - - final Drawing drawing = sheet.createDrawingPatriarch(); - final ClientAnchor anchor = - drawing.createAnchor(0, 0, 0, 0, (short) 4, 2, (short) (4 + width), (2 + height)); - final Comment comment = drawing.createCellComment(anchor); - comment.setAuthor(author); - comment.setString(helper.createRichTextString(text)); - cell.setCellComment(comment); - } - - private static int getDayDifference(final String firstdate, final String lastdate) { - - try { - final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - final Date date1 = dateFormat.parse(firstdate); - final Date date2 = dateFormat.parse(lastdate); - final long difference = date2.getTime() - date1.getTime(); - return (int) (difference / 1000l / 60l / 60l / 24l); - } - - catch (java.text.ParseException e) { - e.printStackTrace(); - } - - return 0; - } - - static public class SIMPLE_PATTERN { - - final public String beforeText; - final public String afterText; - final public List beforeTextPattern; - final public List afterTextPattern; - - public SIMPLE_PATTERN(final String beforeText, final String afterText) { - this.beforeText = beforeText; - this.afterText = afterText; - this.beforeTextPattern = StringUtility.split(beforeText); - this.afterTextPattern = StringUtility.split(afterText); - } - - @Override - final public boolean equals(final Object o) { - - if (!(o instanceof SIMPLE_PATTERN)) { - return false; - } - - final SIMPLE_PATTERN target = (SIMPLE_PATTERN) o; - return this.beforeText.equals(target.beforeText) && this.afterText.equals(target.afterText); - } - - @Override - final public int hashCode() { - return this.beforeText.hashCode() + this.afterText.hashCode(); - } - } - - static public class PATTERN extends SIMPLE_PATTERN implements Comparable { - - final public List beforeTextHashs; - final public List afterTextHashs; - final public List periods; - final public List ids; - final public List dates; - public int mergedID; - public int findbugsSupport; - public int support; - public int bugfixSupport; - public int beforeTextSupport; - public String beforeTextSupportPeriod; - public int commits; - public int bugfixCommits; - final public Map occupancies; - final public Map deltaCFPFs; - final private SortedSet files; - final private SortedSet bugfixFiles; - final private SortedSet authors; - final private SortedSet bugfixAuthors; - - public PATTERN(final String beforeText, final String afterText) { - super(beforeText, afterText); - this.beforeTextHashs = StringUtility.split(beforeText) - .stream() - .map(text -> Statement.getMD5(text)) - .collect(Collectors.toList()); - this.afterTextHashs = StringUtility.split(afterText) - .stream() - .map(text -> Statement.getMD5(text)) - .collect(Collectors.toList()); - this.periods = new ArrayList<>(); - this.ids = new ArrayList<>(); - this.dates = new ArrayList<>(); - this.mergedID = 0; - this.findbugsSupport = 0; - this.support = 0; - this.bugfixSupport = 0; - this.beforeTextSupport = 0; - this.beforeTextSupportPeriod = null; - this.commits = 0; - this.bugfixCommits = 0; - this.occupancies = new HashMap<>(); - this.deltaCFPFs = new HashMap<>(); - this.files = new TreeSet<>(); - this.bugfixFiles = new TreeSet<>(); - this.authors = new TreeSet<>(); - this.bugfixAuthors = new TreeSet<>(); - } - - public void addPeriod(final String period) { - this.periods.add(period); - } - - public List getPeriods() { - return new ArrayList(this.periods); - } - - public void addID(final String id) { - this.ids.add(id); - } - - public String getIDsText() { - return nh3.ammonia.StringUtility.concatinate(this.ids); - } - - public List getIDs() { - return new ArrayList(this.ids); - } - - public void addFiles(final String fileText) { - this.files.addAll(StringUtility.split(fileText)); - } - - public void addFiles(final Collection files) { - this.files.addAll(files); - } - - public SortedSet getFiles() { - return new TreeSet(this.files); - } - - public void addBugfixFiles(final String fileText) { - this.bugfixFiles.addAll(StringUtility.split(fileText)); - } - - public void addBugfixFiles(final Collection files) { - this.bugfixFiles.addAll(files); - } - - public SortedSet getBugfixFiles() { - return new TreeSet(this.bugfixFiles); - } - - public void addAuthors(final String authorText) { - this.authors.addAll(StringUtility.split(authorText)); - } - - public void addAuthors(final Collection authors) { - this.authors.addAll(authors); - } - - public SortedSet getAuthors() { - return new TreeSet<>(this.authors); - } - - public void addBugfixAuthors(final String authorText) { - this.bugfixAuthors.addAll(StringUtility.split(authorText)); - } - - public void addBugfixAuthors(final Collection authors) { - this.bugfixAuthors.addAll(authors); - } - - public SortedSet getBugfixAuthors() { - return new TreeSet<>(this.bugfixAuthors); - } - - public void addDate(final String date) { - this.dates.add(date); - } - - public String getFirstDate() { - Collections.sort(this.dates); - return this.dates.get(0); - } - - public String getLastDate() { - Collections.sort(this.dates); - return this.dates.get(this.dates.size() - 1); - } - - public void addOccupancy(final String period, final Double occupancy) { - this.occupancies.put(period, occupancy); - } - - public Double getMaxOccuapncy() { - double max = 0d; - for (final Double occupancy : this.occupancies.values()) { - if (max < occupancy) { - max = occupancy; - } - } - return max; - } - - public String getOccupanciesText() { - final StringBuilder text = new StringBuilder(); - for (final Entry entry : this.occupancies.entrySet()) { - text.append(entry.getKey()); - text.append(": "); - text.append(entry.getValue()); - text.append(System.lineSeparator()); - } - return text.toString(); - } - - public void addDeltaCFPF(final String period, final Double deltaCFPF) { - this.deltaCFPFs.put(period, deltaCFPF); - } - - public Double getDeltaCFPF(final int allBugfixCommits, final int allNonbugfixCommits) { - final double pf = (double) this.support / (double) this.beforeTextSupport; - final double cf1 = (double) this.bugfixCommits / (double) allBugfixCommits; - final double cf2 = - (double) (this.commits - this.bugfixCommits) / (double) allNonbugfixCommits; - final double pfcf = pf * (cf1 - cf2); - return pfcf; - } - - public String getDeltaCFPFsText() { - final StringBuilder text = new StringBuilder(); - for (final Entry entry : this.deltaCFPFs.entrySet()) { - text.append(entry.getKey()); - text.append(": "); - text.append(entry.getValue()); - text.append(System.lineSeparator()); - } - return text.toString(); - } - - @Override - public int compareTo(final PATTERN target) { - return Integer.compare(this.mergedID, target.mergedID); - } - } -} diff --git a/src/nh3/ammonia/gui/Ammonia.java b/src/nh3/ammonia/gui/Ammonia.java index ffae413..4df9dda 100644 --- a/src/nh3/ammonia/gui/Ammonia.java +++ b/src/nh3/ammonia/gui/Ammonia.java @@ -60,12 +60,12 @@ import org.tmatesoft.svn.core.wc.SVNClientManager; import org.tmatesoft.svn.core.wc.SVNRevision; import org.tmatesoft.svn.core.wc.SVNUpdateClient; -import nh3.ammonia.FBChangePatternFinderWithoutFB; +import nh3.ammonia.DAO; import nh3.ammonia.FBParserConfig; +import nh3.ammonia.Pattern; import nh3.ammonia.StringUtility; -import nh3.ammonia.XLSXMerger.PATTERN; -import nh3.ammonia.db.DAO; -import nh3.ammonia.db.DAO.PATTERN_SQL; +import nh3.ammonia.DAO.CHANGE_SQL; +import nh3.ammonia.DAO.PATTERN_SQL; import yoshikihigo.cpanalyzer.CPAConfig; import yoshikihigo.cpanalyzer.LANGUAGE; import yoshikihigo.cpanalyzer.data.Statement; @@ -146,7 +146,7 @@ else if (FBParserConfig.getInstance() } } - List patterns = null; + List patterns = null; if (FBParserConfig.getInstance() .hasFIXCHANGEPATTERN()) { final String xlsx = FBParserConfig.getInstance() @@ -157,8 +157,8 @@ else if (FBParserConfig.getInstance() } final SortedMap> fWarnings = new TreeMap<>(); - final SortedMap> pWarnings = new TreeMap<>(); - PATTERN: for (final PATTERN pattern : patterns) { + final SortedMap> pWarnings = new TreeMap<>(); + PATTERN: for (final Pattern pattern : patterns) { if (pattern.beforeTextHashs.isEmpty()) { continue PATTERN; @@ -283,9 +283,9 @@ static private List findMatchedCode(final List statements, return places; } - static List readXLSX(final String xlsx) { + static List readXLSX(final String xlsx) { - final List patterns = new ArrayList<>(); + final List patterns = new ArrayList<>(); try (final Workbook book = new XSSFWorkbook(new FileInputStream(xlsx))) { final Sheet sheet = book.getSheetAt(0); @@ -296,7 +296,7 @@ static List readXLSX(final String xlsx) { .getStringCellValue(); final String afterText = row.getCell(24) .getStringCellValue(); - final PATTERN pattern = new PATTERN(beforeText, afterText); + final Pattern pattern = new Pattern(beforeText, afterText); pattern.mergedID = (int) row.getCell(0) .getNumericCellValue(); pattern.support = (int) row.getCell(7) @@ -327,7 +327,7 @@ static List readXLSX(final String xlsx) { return patterns; } - static List getPatternsFromDB() { + static List getPatternsFromDB() { final int bugfixThreshold = FBParserConfig.getInstance() .getBUGFIXTHRESHOLD(); @@ -336,7 +336,7 @@ static List getPatternsFromDB() { final float confidenceThreshold = FBParserConfig.getInstance() .getCONFIDENCETHRESHOLD(); - final List patterns = new ArrayList<>(); + final List patterns = new ArrayList<>(); final List patternsSQL = DAO.getInstance() .getChangePatterns(bugfixThreshold, supportThreshold, confidenceThreshold); @@ -349,16 +349,16 @@ static List getPatternsFromDB() { continue; } - final PATTERN pattern = new PATTERN(beforeText, afterText); + final Pattern pattern = new Pattern(beforeText, afterText); pattern.mergedID = patternSQL.id; pattern.support = patternSQL.support; pattern.bugfixSupport = patternSQL.support; pattern.beforeTextSupport = 0; pattern.addDate(patternSQL.firstdate); pattern.addDate(patternSQL.lastdate); - pattern.bugfixCommits = FBChangePatternFinderWithoutFB.getCommits(patternSQL, true); - pattern.addBugfixAuthors(FBChangePatternFinderWithoutFB.getAuthors(patternSQL, true)); - pattern.addBugfixFiles(FBChangePatternFinderWithoutFB.getFiles(patternSQL, true)); + pattern.bugfixCommits = getCommits(patternSQL, true); + pattern.addBugfixAuthors(getAuthors(patternSQL, true)); + pattern.addBugfixFiles(getFiles(patternSQL, true)); patterns.add(pattern); } @@ -489,7 +489,7 @@ static SortedMap retrieveGITFiles(final String repository, } static void writeWarnings(final SortedMap> fWarnings, - final Map> pWarnings) { + final Map> pWarnings) { final String warningListFile = FBParserConfig.getInstance() .getWARNINGLIST(); @@ -553,7 +553,7 @@ static void writeWarnings(final SortedMap> fWarnings, } static void writeWarningsToDB(final SortedMap> fWarnings, - final Map> pWarnings) { + final Map> pWarnings) { Connection connector = null; try { @@ -667,7 +667,7 @@ private static void setCellComment(final Cell cell, final String author, final S } public Ammonia(final Map files, final Map> fWarnings, - final Map> pWarnings) { + final Map> pWarnings) { super("Ammonia"); @@ -829,4 +829,48 @@ public boolean equals(final Object o) { return Arrays.equals(this.hash, ((MD5) o).hash); } } + + public static int getCommits(final PATTERN_SQL cp, final boolean bugfix) { + final byte[] beforeHash = cp.beforeHash; + final byte[] afterHash = cp.afterHash; + final List changesInPattern = DAO.getInstance() + .getChanges(beforeHash, afterHash); + return (int) changesInPattern.stream() + .filter(change -> bugfix == change.bugfix) + .count(); + } + + + public static SortedSet getAuthors(final PATTERN_SQL cp, final boolean bugfix) { + + final SortedSet authors = new TreeSet<>(); + final byte[] beforeHash = cp.beforeHash; + final byte[] afterHash = cp.afterHash; + final List changes = DAO.getInstance() + .getChanges(beforeHash, afterHash); + for (final CHANGE_SQL change : changes) { + if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { + authors.add(change.author); + } + } + + return authors; + } + + + public static SortedSet getFiles(final PATTERN_SQL cp, final boolean bugfix) { + + final SortedSet files = new TreeSet<>(); + final byte[] beforeHash = cp.beforeHash; + final byte[] afterHash = cp.afterHash; + final List changes = DAO.getInstance() + .getChanges(beforeHash, afterHash); + for (final CHANGE_SQL change : changes) { + if ((bugfix && change.bugfix) || (!bugfix && !change.bugfix)) { + files.add(change.filepath); + } + } + + return files; + } } diff --git a/src/nh3/ammonia/gui/PastChangesView.java b/src/nh3/ammonia/gui/PastChangesView.java index fc0b460..7708841 100644 --- a/src/nh3/ammonia/gui/PastChangesView.java +++ b/src/nh3/ammonia/gui/PastChangesView.java @@ -23,10 +23,10 @@ import javax.swing.border.TitledBorder; import javax.swing.text.BadLocationException; import javax.swing.text.DefaultHighlighter.DefaultHighlightPainter; +import nh3.ammonia.DAO; import nh3.ammonia.FBParserConfig; import nh3.ammonia.StringUtility; -import nh3.ammonia.db.DAO; -import nh3.ammonia.db.DAO.CHANGE_SQL; +import nh3.ammonia.DAO.CHANGE_SQL; import org.eclipse.jgit.internal.storage.file.FileRepository; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectReader; diff --git a/src/nh3/ammonia/gui/PatternFilteringPanel.java b/src/nh3/ammonia/gui/PatternFilteringPanel.java index 49d0075..f5f0f02 100644 --- a/src/nh3/ammonia/gui/PatternFilteringPanel.java +++ b/src/nh3/ammonia/gui/PatternFilteringPanel.java @@ -22,8 +22,8 @@ import javax.swing.JTextField; import javax.swing.border.EtchedBorder; import javax.swing.border.LineBorder; -import nh3.ammonia.XLSXMerger.PATTERN; -import nh3.ammonia.db.DAO; +import nh3.ammonia.DAO; +import nh3.ammonia.Pattern; public class PatternFilteringPanel extends JPanel implements Observer { @@ -35,10 +35,10 @@ public class PatternFilteringPanel extends JPanel implements Observer { final private JRadioButton orButton; final private Map> fWarnings; - final private Map> pWarnings; + final private Map> pWarnings; public PatternFilteringPanel(final Map> fWarnings, - final Map> pWarnings) { + final Map> pWarnings) { super(new BorderLayout()); diff --git a/src/nh3/ammonia/gui/Warning.java b/src/nh3/ammonia/gui/Warning.java index 09eeca7..236458d 100644 --- a/src/nh3/ammonia/gui/Warning.java +++ b/src/nh3/ammonia/gui/Warning.java @@ -1,14 +1,14 @@ package nh3.ammonia.gui; -import nh3.ammonia.XLSXMerger.PATTERN; +import nh3.ammonia.Pattern; public class Warning implements Comparable { final public int fromLine; final public int toLine; - final public PATTERN pattern; + final public Pattern pattern; - public Warning(final int fromLine, final int toLine, final PATTERN pattern) { + public Warning(final int fromLine, final int toLine, final Pattern pattern) { this.fromLine = fromLine; this.toLine = toLine; this.pattern = pattern; diff --git a/src/nh3/ammonia/gui/WarningListView.java b/src/nh3/ammonia/gui/WarningListView.java index a652df8..03d154b 100644 --- a/src/nh3/ammonia/gui/WarningListView.java +++ b/src/nh3/ammonia/gui/WarningListView.java @@ -26,7 +26,7 @@ import javax.swing.table.TableColumnModel; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; -import nh3.ammonia.XLSXMerger.PATTERN; +import nh3.ammonia.Pattern; public class WarningListView extends JTable implements Observer { @@ -63,11 +63,11 @@ public void valueChanged(final ListSelectionEvent e) { final private SelectionHandler selectionHandler; final private Map> fWarnings; - final private Map> pWarnings; + final private Map> pWarnings; final public JScrollPane scrollPane; public WarningListView(final Map> fWarnings, - final Map> pWarnings) { + final Map> pWarnings) { super(); diff --git a/src/nh3/ammonia/gui/WarningListViewModel.java b/src/nh3/ammonia/gui/WarningListViewModel.java index a43746c..1f7474a 100644 --- a/src/nh3/ammonia/gui/WarningListViewModel.java +++ b/src/nh3/ammonia/gui/WarningListViewModel.java @@ -4,7 +4,7 @@ import java.util.List; import java.util.Map; import javax.swing.table.AbstractTableModel; -import nh3.ammonia.XLSXMerger.PATTERN; +import nh3.ammonia.Pattern; public class WarningListViewModel extends AbstractTableModel { @@ -23,10 +23,10 @@ public class WarningListViewModel extends AbstractTableModel { "AUTHORS", "LASTDATE", "Pattern ID", "MATCHED"}; final List warnings; - final private Map> pWarnings; + final private Map> pWarnings; public WarningListViewModel(final List warnings, - final Map> pWarnings) { + final Map> pWarnings) { this.warnings = new ArrayList<>(); this.warnings.addAll(warnings); this.pWarnings = pWarnings;