[jOOQ/jOOQ#12488] Log warning in code generator when wrong runtime

version is used
This commit is contained in:
Lukas Eder 2021-10-07 15:03:44 +02:00
parent c094b7b798
commit 74005c452d
6 changed files with 366 additions and 2 deletions

View File

@ -53,5 +53,14 @@
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,157 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.codegen;
/**
* Some publicly available constants used in jOOQ
*
* @author Lukas Eder
*/
public final class Constants {
/**
* The latest jOOQ minor version.
*/
public static final String MINOR_VERSION = "3.15";
/**
* The latest jOOQ version.
* <p>
* This is the same as {@link #MINOR_VERSION}, but it may include patch
* version suffixes.
*/
public static final String VERSION = "3.16.0-SNAPSHOT";
/**
* The latest jOOQ full version.
* <p>
* This is the same as {@link #VERSION}, but it may include release
* candidate and other suffixes.
*/
public static final String FULL_VERSION = "3.16.0-SNAPSHOT";
/**
* The current jooq-runtime XSD file name.
*/
public static final String XSD_RUNTIME = "jooq-runtime-3.16.0.xsd";
/**
* The current jooq-runtime XML namespace.
*/
public static final String NS_RUNTIME = "http://www.jooq.org/xsd/" + XSD_RUNTIME;
/**
* The current jooq-runtime XSD classpath location.
*/
public static final String CP_RUNTIME = "/xsd/" + XSD_RUNTIME;
/**
* The current jooq-export XSD file name.
*/
public static final String XSD_EXPORT = "jooq-export-3.10.0.xsd";
/**
* The current jooq-export XML namespace.
*/
public static final String NS_EXPORT = "http://www.jooq.org/xsd/" + XSD_EXPORT;
/**
* The current jooq-export XSD classpath location.
*/
public static final String CP_EXPORT = "/xsd/" + XSD_EXPORT;
/**
* The current jooq-meta XSD file name.
*/
public static final String XSD_META = "jooq-meta-3.14.0.xsd";
/**
* The current jooq-meta XML namespace.
*/
public static final String NS_META = "http://www.jooq.org/xsd/" + XSD_META;
/**
* The current jooq-meta XSD classpath location.
*/
public static final String CP_META = "/xsd/" + XSD_META;
/**
* The current jooq-migrations XSD file name.
*/
public static final String XSD_MIGRATIONS = "jooq-migrations-3.15.0.xsd";
/**
* The current jooq-migrations XML namespace.
*/
public static final String NS_MIGRATIONS = "http://www.jooq.org/xsd/" + XSD_META;
/**
* The current jooq-migrations XSD classpath location.
*/
public static final String CP_MIGRATIONS = "/xsd/" + XSD_META;
/**
* The current jooq-codegen XSD file name.
*/
public static final String XSD_CODEGEN = "jooq-codegen-3.15.0.xsd";
/**
* The current jooq-codegen XML namespace.
*/
public static final String NS_CODEGEN = "http://www.jooq.org/xsd/" + XSD_CODEGEN;
/**
* The current jooq-codegen XSD classpath location.
*/
public static final String CP_CODEGEN = "/xsd/" + XSD_CODEGEN;
/**
* The maximum degree of {@link Row} and {@link Record} subtypes
*/
public static final int MAX_ROW_DEGREE = 22;
/**
* No further instances
*/
private Constants() {}
}

View File

@ -39,6 +39,7 @@ package org.jooq.codegen;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static java.util.Comparator.comparing;
import static org.jooq.SQLDialect.HSQLDB;
import static org.jooq.tools.StringUtils.defaultIfNull;
import static org.jooq.tools.StringUtils.defaultString;
@ -51,6 +52,7 @@ import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.SQLException;
@ -58,6 +60,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Properties;
import javax.sql.DataSource;
@ -871,6 +874,7 @@ public class GenerationTool {
strategy.setInstanceFields(generator.generateInstanceFields());
strategy.setJavaBeansGettersAndSetters(generator.generateJavaBeansGettersAndSetters());
verifyVersions();
generator.generate(database);
logUnused("forced type", "forced types", database.getUnusedForcedTypes());
@ -908,6 +912,43 @@ public class GenerationTool {
}
}
private void verifyVersions() {
// [#12488] Check if all of jOOQ, jOOQ-meta, jOOQ-codegen are using the same versions and editions
Field[] f1 = org.jooq.Constants.class.getFields();
Field[] f2 = org.jooq.meta.Constants.class.getFields();
Field[] f3 = org.jooq.codegen.Constants.class.getFields();
Arrays.sort(f1, comparing(Field::getName));
Arrays.sort(f2, comparing(Field::getName));
Arrays.sort(f3, comparing(Field::getName));
if (f1.length != f2.length)
log.warn("Version check", "org.jooq.Constants and org.jooq.meta.Constants contents mismatch. Check if you're using the same versions for org.jooq and org.jooq.meta");
if (f1.length != f3.length)
log.warn("Version check", "org.jooq.Constants and org.jooq.codegen.Constants contents mismatch. Check if you're using the same versions for org.jooq and org.jooq.meta");
String v1 = org.jooq.Constants.FULL_VERSION;
String v2 = org.jooq.meta.Constants.FULL_VERSION;
String v3 = org.jooq.codegen.Constants.FULL_VERSION;
for (int i = 0; i < f1.length && i < f2.length && i < f3.length; i++) {
try {
Object c1 = f1[i].get(org.jooq.Constants.class);
Object c2 = f2[i].get(org.jooq.meta.Constants.class);
Object c3 = f3[i].get(org.jooq.codegen.Constants.class);
if (!Objects.equals(c1, c2))
log.warn("Version check", "org.jooq.Constants." + f1[i].getName() + " contents mismatch: " + c1 + " vs " + c2 + ". Check if you're using the same versions for org.jooq (" + v1 + ") and org.jooq.meta (" + v2 + ")");
if (!Objects.equals(c1, c3))
log.warn("Version check", "org.jooq.Constants." + f1[i].getName() + " contents mismatch: " + c1 + " vs " + c3 + ". Check if you're using the same versions for org.jooq (" + v1 + ") and org.jooq.codegen (" + v3 + ")");
}
catch (Exception e) {
log.warn("Version check", e);
}
}
}
private void logUnused(String objectType, String objectTypes, List<?> list) {
if (!list.isEmpty() && Boolean.parseBoolean(System.getProperty("jooq.codegen.logunused", "true"))) {
unusedLogger.warn(

View File

@ -0,0 +1,157 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* ASL 2.0 and offer limited warranties, support, maintenance, and commercial
* database integrations.
*
* For more information, please visit: http://www.jooq.org/licenses
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.meta;
/**
* Some publicly available constants used in jOOQ
*
* @author Lukas Eder
*/
public final class Constants {
/**
* The latest jOOQ minor version.
*/
public static final String MINOR_VERSION = "3.15";
/**
* The latest jOOQ version.
* <p>
* This is the same as {@link #MINOR_VERSION}, but it may include patch
* version suffixes.
*/
public static final String VERSION = "3.16.0-SNAPSHOT";
/**
* The latest jOOQ full version.
* <p>
* This is the same as {@link #VERSION}, but it may include release
* candidate and other suffixes.
*/
public static final String FULL_VERSION = "3.16.0-SNAPSHOT";
/**
* The current jooq-runtime XSD file name.
*/
public static final String XSD_RUNTIME = "jooq-runtime-3.16.0.xsd";
/**
* The current jooq-runtime XML namespace.
*/
public static final String NS_RUNTIME = "http://www.jooq.org/xsd/" + XSD_RUNTIME;
/**
* The current jooq-runtime XSD classpath location.
*/
public static final String CP_RUNTIME = "/xsd/" + XSD_RUNTIME;
/**
* The current jooq-export XSD file name.
*/
public static final String XSD_EXPORT = "jooq-export-3.10.0.xsd";
/**
* The current jooq-export XML namespace.
*/
public static final String NS_EXPORT = "http://www.jooq.org/xsd/" + XSD_EXPORT;
/**
* The current jooq-export XSD classpath location.
*/
public static final String CP_EXPORT = "/xsd/" + XSD_EXPORT;
/**
* The current jooq-meta XSD file name.
*/
public static final String XSD_META = "jooq-meta-3.14.0.xsd";
/**
* The current jooq-meta XML namespace.
*/
public static final String NS_META = "http://www.jooq.org/xsd/" + XSD_META;
/**
* The current jooq-meta XSD classpath location.
*/
public static final String CP_META = "/xsd/" + XSD_META;
/**
* The current jooq-migrations XSD file name.
*/
public static final String XSD_MIGRATIONS = "jooq-migrations-3.15.0.xsd";
/**
* The current jooq-migrations XML namespace.
*/
public static final String NS_MIGRATIONS = "http://www.jooq.org/xsd/" + XSD_META;
/**
* The current jooq-migrations XSD classpath location.
*/
public static final String CP_MIGRATIONS = "/xsd/" + XSD_META;
/**
* The current jooq-codegen XSD file name.
*/
public static final String XSD_CODEGEN = "jooq-codegen-3.15.0.xsd";
/**
* The current jooq-codegen XML namespace.
*/
public static final String NS_CODEGEN = "http://www.jooq.org/xsd/" + XSD_CODEGEN;
/**
* The current jooq-codegen XSD classpath location.
*/
public static final String CP_CODEGEN = "/xsd/" + XSD_CODEGEN;
/**
* The maximum degree of {@link Row} and {@link Record} subtypes
*/
public static final int MAX_ROW_DEGREE = 22;
/**
* No further instances
*/
private Constants() {}
}

View File

@ -133,7 +133,7 @@ implements
}
public final Function1<? super MList<? extends Field<?>>, ? extends QOM.XMLForest> constructor() {
return (a1) -> new XMLForest(a1);
return (a1) -> new XMLForest((Collection<? extends Field<?>>) a1);
}
@Override

View File

@ -131,7 +131,7 @@ implements
}
public final Function1<? super MList<? extends Field<?>>, ? extends QOM.XMLConcat> constructor() {
return (a1) -> new XMLConcat(a1);
return (a1) -> new XMLConcat((Collection<? extends Field<?>>) a1);
}
@Override