Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AD-317] Janino work-around - embed Janino patch #89

Merged
merged 16 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*.iml
*.iws
*.ipr
*.jar

# Mac
.DS_Store
Expand Down
35 changes: 32 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,42 @@ plugins {
id 'com.github.hierynomus.license' version '0.15.0'
id 'com.github.johnrengelman.shadow' version '6.1.0'
id 'org.kordamp.gradle.markdown' version '2.2.0'
id "de.undercouch.download" version "4.1.2"
id "com.github.dkorotych.gradle-maven-exec" version "2.2.1"
}

group 'software.amazon.documentdb.jdbc'
version "${project.MAJOR_VERSION}.${project.MINOR_VERSION}.${project.PATCH_VERSION}-beta.${project.BETA_VERSION}"
description 'documentdb-jdbc-driver'

tasks.register('patchJanino') {
download {
println "Dowloading Janino Library"
src 'https://github.com/janino-compiler/janino/archive/4b98b5b44ee329685503e264751067fab259f7b7.zip'
dest buildDir
}
copy {
def zipFile = file("${buildDir}/4b98b5b44ee329685503e264751067fab259f7b7.zip")
def outputDir = file("${buildDir}/dependencies")
from zipTree(zipFile)
into outputDir
}
copy {
from "src/main/dependency/org/codehaus/commons/compiler/CompilerFactoryFactory.java"
into "${buildDir}/dependencies/janino-4b98b5b44ee329685503e264751067fab259f7b7/commons-compiler/src/main/java/org/codehaus/commons/compiler"
}
mavenexec {
workingDir "${buildDir}/dependencies/janino-4b98b5b44ee329685503e264751067fab259f7b7/commons-compiler"
goals 'package'
threads '2C'
quiet false
}
copy {
from "${buildDir}/dependencies/janino-4b98b5b44ee329685503e264751067fab259f7b7/commons-compiler/target/commons-compiler-3.0.11.jar"
into "src/main/resources"
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -39,6 +69,8 @@ jar {
}

shadowJar {
dependsOn('patchJanino')

// Exclude driver unnecessary classes.
exclude 'org/apache/calcite/jdbc/Driver*'
exclude 'org/apache/calcite/avatica/remote/Driver*'
Expand Down Expand Up @@ -246,9 +278,6 @@ processResources {
}

repositories {
maven {
url 'https://raw.githubusercontent.com/birschick-bq/janino/brucei/ad-189/maven'
}
mavenCentral()
}

Expand Down
4 changes: 0 additions & 4 deletions calcite-adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ license {
}

repositories {
maven {
url 'https://raw.githubusercontent.com/birschick-bq/janino/brucei/ad-189/maven'
}
mavenCentral()
}

Expand All @@ -204,7 +201,6 @@ dependencies {
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.3'
implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.32'
implementation group: 'org.apache.calcite', name: 'calcite-core', version: '1.26.0'
implementation group: 'org.codehaus.janino', name: 'commons-compiler', version: '3.0.17'
implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.1.1'

compileOnly 'org.projectlombok:lombok:1.18.16'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@

/*
* Janino - An embedded Java[TM] compiler
*
* Copyright (c) 2001-2010 Arno Unkrig. All rights reserved.
* Copyright (c) 2015-2016 TIBCO Software Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
* following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package org.codehaus.commons.compiler;

import org.codehaus.commons.nullanalysis.Nullable;

import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;

/**
* Utility class that finds implementations of {@link ICompilerFactory}s.
*/
public final
class CompilerFactoryFactory {

private CompilerFactoryFactory() {}

@Nullable
private static ICompilerFactory defaultCompilerFactory;

/**
* Finds the first implementation of {@code org.codehaus.commons.compiler} on the class path, then loads and
* instantiates its {@link ICompilerFactory}.
*
* @return The {@link ICompilerFactory} of the first implementation on the class path
* @throws Exception Many things can go wrong while finding and initializing the default compiler factory
*/
public static ICompilerFactory
getDefaultCompilerFactory() throws Exception {
if (CompilerFactoryFactory.defaultCompilerFactory != null) {
return CompilerFactoryFactory.defaultCompilerFactory;
}
Properties properties = new Properties();
InputStream is = CompilerFactoryFactory.class.getClassLoader().getResourceAsStream(
"org.codehaus.commons.compiler.properties"
);
if (is == null) {
throw new ClassNotFoundException(
"No implementation of org.codehaus.commons.compiler is on the class path. Typically, you'd have "
+ "'janino.jar', or 'commons-compiler-jdk.jar', or both on the classpath."
);
}
try {
properties.load(is);
} finally {
is.close();
}
String compilerFactoryClassName = properties.getProperty("compilerFactory");

return (
CompilerFactoryFactory.defaultCompilerFactory
= CompilerFactoryFactory.getCompilerFactory(compilerFactoryClassName)
);
}

/**
* Finds all implementation of {@code org.codehaus.commons.compiler} on the class path, then loads and
* instantiates their {@link ICompilerFactory}s.
*
* @return The {@link ICompilerFactory}s of all implementations on the class path
* @throws Exception Many things can go wrong while finding and initializing compiler factories
*/
public static ICompilerFactory[]
getAllCompilerFactories() throws Exception {
ClassLoader cl = CompilerFactoryFactory.class.getClassLoader();
List<ICompilerFactory> factories = new ArrayList<ICompilerFactory>();
for (Enumeration<URL> en = cl.getResources("org.codehaus.commons.compiler.properties"); en.hasMoreElements();) {
URL url = (URL) en.nextElement();

Properties properties;
{
properties = new Properties();
InputStream is = url.openStream();
try {
properties.load(is);
} finally {
is.close();
}
}

String compilerFactoryClassName = properties.getProperty("compilerFactory");
if (compilerFactoryClassName == null) {
throw new IllegalStateException(url.toString() + " does not specify the 'compilerFactory' property");
}

factories.add(CompilerFactoryFactory.getCompilerFactory(compilerFactoryClassName));
}
return (ICompilerFactory[]) factories.toArray(new ICompilerFactory[factories.size()]);
}

/**
* Loads an {@link ICompilerFactory} by class name.
*
* @param compilerFactoryClassName Name of a class that implements {@link ICompilerFactory}
* @throws Exception Many things can go wrong while loading and initializing the default compiler
* factory
*/
public static ICompilerFactory
getCompilerFactory(String compilerFactoryClassName) throws Exception {
return (ICompilerFactory) CompilerFactoryFactory.class.getClassLoader().loadClass(
compilerFactoryClassName
).newInstance();
}

/**
* @return The version of the commons-compiler specification, or {@code null}
*/
public static String
getSpecificationVersion() {
return CompilerFactoryFactory.class.getPackage().getSpecificationVersion();
}
}