Skip to content

Commit

Permalink
Fix for Bug#93340 (28970166), C/J BUILD SCRIPT IS TOO VERBOSE
Browse files Browse the repository at this point in the history
  • Loading branch information
soklakov committed Nov 26, 2018
1 parent e568a61 commit d4aa2dc
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.14

- Fix for Bug#93340 (28970166), C/J BUILD SCRIPT IS TOO VERBOSE

- WL#12462, DevAPI: Be prepared for initial notice on connection.

- Fix for Bug#28924137, WL#12463:IF COLLECTION DOESN'T EXIST, COLL.COUNT() IS GIVING A WRONG ERROR MESSAGE.
Expand Down
4 changes: 4 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ com.mysql.cj.build.jdk - path to JDK used for building driver: [${com.mysql.cj.b
com.mysql.cj.build.addDebugInfo - should the driver be compiled with debugging info: [${com.mysql.cj.build.addDebugInfo}]
com.mysql.cj.build.noCleanBetweenCompiles - don't clean artifacts from previous build: [_unset_]
com.mysql.cj.build.failOnWarnings - fail the build when any warning is found: [_unset_]
com.mysql.cj.build.verbose - log the extended build info: [_unset_]

com.mysql.cj.build.commercial - build commercial variant of the driver: [_unset_]
com.mysql.cj.build.filterLicense - build ISV variant of the driver: [_unset_]
Expand Down Expand Up @@ -978,20 +979,23 @@ See also com.mysql.cj.conf.PropertyDefinitions.SYSP_* variables for other test o
fork="yes"
failonerror="true">
<arg value="${com.mysql.cj.build.compiler.output}" />
<arg value="${com.mysql.cj.build.verbose}" />
</java>
<java jvm="${com.mysql.cj.build.jdk.java}"
classname="instrumentation.TranslateExceptions"
classpathref="instrumentation.classpath"
fork="yes"
failonerror="true">
<arg value="${com.mysql.cj.build.compiler.output}" />
<arg value="${com.mysql.cj.build.verbose}" />
</java>
<java jvm="${com.mysql.cj.build.jdk.java}"
classname="instrumentation.AddMethods"
classpathref="instrumentation.classpath"
fork="yes"
failonerror="true">
<arg value="${com.mysql.cj.build.compiler.output}" />
<arg value="${com.mysql.cj.build.verbose}" />
</java>
</target>

Expand Down
25 changes: 19 additions & 6 deletions src/build/java/instrumentation/AddMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,31 @@
import javassist.bytecode.DuplicateMemberException;

public class AddMethods {
private static boolean verbose = false;

public static void main(String[] args) throws Exception {

System.out.println("Applying AddMethods.");

verbose = "true".equalsIgnoreCase(args[1]);

ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(args[0]);

System.out.println("---");
sysOut("---");
CtClass clazz = pool.get(MysqlDataSource.class.getName());
System.out.println("Add properties setters/getters to " + clazz.getName());
sysOut("Add properties setters/getters to " + clazz.getName());
addPropertiesGettersSetters(clazz, PropertyDefinitions.PROPERTY_KEY_TO_PROPERTY_DEFINITION.values());
clazz.writeFile(args[0]);

}

private static void sysOut(String s) {
if (verbose) {
System.out.println(s);
}
}

private static void addPropertiesGettersSetters(CtClass clazz, Collection<PropertyDefinition<?>> propertyDefinitions) throws Exception {
for (PropertyDefinition<?> def : propertyDefinitions) {
String pname = def.hasCcAlias() ? def.getCcAlias() : def.getName();
Expand Down Expand Up @@ -97,11 +110,11 @@ private static void addPropertiesGettersSetters(CtClass clazz, Collection<Proper
private static void addGetter(CtClass clazz, String pname, String paramType, String getPropertyMethod) throws Exception {
String mname = "get" + pname.substring(0, 1).toUpperCase() + pname.substring(1);
String mbody = "public " + paramType + " " + mname + "() throws java.sql.SQLException { return " + getPropertyMethod + "(\"" + pname + "\");}";
System.out.println(mbody);
sysOut(mbody);
try {
CtMethod m = CtNewMethod.make(mbody, clazz);
clazz.addMethod(m);
System.out.println(m);
sysOut(m.toString());
} catch (DuplicateMemberException ex) {
// ignore
}
Expand All @@ -111,11 +124,11 @@ private static void addSetter(CtClass clazz, String pname, String paramType, Str
String mname = "set" + pname.substring(0, 1).toUpperCase() + pname.substring(1);
String mbody = "public void " + mname + "(" + paramType + " value) throws java.sql.SQLException { " + setPropertyMethod + "(\"" + pname
+ "\", value);}";
System.out.println(mbody);
sysOut(mbody);
try {
CtMethod m = CtNewMethod.make(mbody, clazz);
clazz.addMethod(m);
System.out.println(m);
sysOut(m.toString());
} catch (DuplicateMemberException ex) {
// ignore
}
Expand Down
15 changes: 14 additions & 1 deletion src/build/java/instrumentation/CommonChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
import javassist.CtMethod;

public class CommonChecks {
private static boolean verbose = false;

public static void main(String[] args) throws Exception {

System.out.println("Applying CommonChecks.");

verbose = "true".equalsIgnoreCase(args[1]);

ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(args[0]);

Expand Down Expand Up @@ -172,8 +179,14 @@ public static void main(String[] args) throws Exception {
}

private static void addClosedCheck(CtMethod m) throws Exception {
System.out.println(m);
sysOut(m.toString());
m.insertBefore("checkClosed();");
}

private static void sysOut(String s) {
if (verbose) {
System.out.println(s);
}
}

}
36 changes: 27 additions & 9 deletions src/build/java/instrumentation/TranslateExceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,14 @@ public class TranslateExceptions {

private static String EXCEPTION_INTERCEPTOR_GETTER = "getExceptionInterceptor()";
private static String EXCEPTION_INTERCEPTOR_MEMBER = "this.exceptionInterceptor";
private static boolean verbose = false;

public static void main(String[] args) throws Exception {

System.out.println("Applying TranslateExceptions.");

verbose = "true".equalsIgnoreCase(args[1]);

pool.insertClassPath(args[0]);
processed.clear();

Expand Down Expand Up @@ -634,8 +640,8 @@ private static void instrumentJdbcMethods(CtClass cjClazz, Class<?> jdbcClass) t
*/
private static void instrumentJdbcMethods(CtClass cjClazz, Class<?> jdbcClass, boolean declaredMethodsOnly, String exceptionInterceptorStr)
throws Exception {
System.out.println("---");
System.out.println(cjClazz.getName());
sysOutPrintln("---");
sysOutPrintln(cjClazz.getName());

Method[] methods;
if (declaredMethodsOnly) {
Expand Down Expand Up @@ -666,16 +672,16 @@ private static void instrumentJdbcMethods(CtClass cjClazz, Class<?> jdbcClass, b
break;
}
}
System.out.print(prefix);
System.out.print(method.toGenericString());
sysOutPrint(prefix);
sysOutPrint(method.toGenericString());
if (ctm != null) {
if (catchRuntimeException(cjClazz, ctm, exceptionInterceptorStr, false)) {
System.out.print(" ... DONE.");
sysOutPrint(" ... DONE.");
} else {
System.out.print(" ... ALREADY PROCESSED!!!");
sysOutPrint(" ... ALREADY PROCESSED!!!");
}
}
System.out.println();
sysOutPrintln("");
}

}
Expand All @@ -687,12 +693,12 @@ private static void catchRuntimeException(CtClass clazz, CtMethod m, String exce
private static boolean catchRuntimeException(CtClass clazz, CtMethod m, String exceptionInterceptorStr, boolean log) throws Exception {
if (isProcessed(clazz.getClassFile().getName(), m)) {
if (log) {
System.out.println("ALREADY PROCESSED!!! " + m);
sysOutPrintln("ALREADY PROCESSED!!! " + m);
}
return false;
}
if (log) {
System.out.println(m + ", " + exceptionInterceptorStr);
sysOutPrintln(m + ", " + exceptionInterceptorStr);
}
if (exceptionInterceptorStr == null) {
m.addCatch("{throw " + SQLExceptionsMapping.class.getName() + ".translateException(ex);}", runTimeException, "ex");
Expand All @@ -715,4 +721,16 @@ private static boolean isProcessed(String fileName, CtMethod m) throws Exception
return false;
}

private static void sysOutPrint(String s) {
if (verbose) {
System.out.print(s);
}
}

private static void sysOutPrintln(String s) {
if (verbose) {
System.out.println(s);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public class PropertyDefinitions {
public static final String SYSP_testsuite_runLongTests /* */ = "com.mysql.cj.testsuite.runLongTests";
public static final String SYSP_testsuite_serverController_basedir /* */ = "com.mysql.cj.testsuite.serverController.basedir";

public static final String SYSP_com_mysql_cj_build_verbose /* */ = "com.mysql.cj.build.verbose";

/*
* Categories of connection properties
*/
Expand Down

0 comments on commit d4aa2dc

Please sign in to comment.