-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-6393] Add bytecode verification check using ASM in the gradl…
…e build
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ pluginManagement { | |
} | ||
} | ||
|
||
include("asmchecker") | ||
include("javacc") | ||
include("fmpp") | ||
include("buildext") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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. | ||
*/ | ||
|
||
dependencies { | ||
val asmVersion = "9.6" | ||
implementation("org.ow2.asm:asm:$asmVersion") | ||
implementation("org.ow2.asm:asm-analysis:$asmVersion") | ||
implementation("org.ow2.asm:asm-commons:$asmVersion") | ||
implementation("org.ow2.asm:asm-tree:$asmVersion") | ||
implementation("org.ow2.asm:asm-util:$asmVersion") | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
register("asmchecker") { | ||
id = "calcite.asmchecker" | ||
implementationClass = "org.apache.calcite.buildtools.asmchecker.AsmCheckerPlugin" | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...s/asmchecker/src/main/kotlin/org/apache/calcite/buildtools/asmchecker/AsmCheckerPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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. | ||
*/ | ||
|
||
package org.apache.calcite.buildtools.asmchecker | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
open class AsmCheckerPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...cts/asmchecker/src/main/kotlin/org/apache/calcite/buildtools/asmchecker/AsmCheckerTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to you 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. | ||
*/ | ||
|
||
package org.apache.calcite.buildtools.asmchecker | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.tasks.CacheableTask | ||
import org.gradle.api.tasks.TaskAction | ||
import org.objectweb.asm.ClassReader | ||
import org.objectweb.asm.ClassWriter | ||
import org.objectweb.asm.commons.ClassRemapper | ||
import org.objectweb.asm.commons.Remapper | ||
import org.objectweb.asm.util.CheckClassAdapter | ||
|
||
@CacheableTask | ||
open class AsmCheckerTask : DefaultTask() { | ||
|
||
@TaskAction | ||
fun run() { | ||
project.buildDir.walk().filter { file -> file.getName().toLowerCase().endsWith(".class") } | ||
.forEach { | ||
val classReader = ClassReader(Files.readAllBytes(Paths.get(it.getPath()))) | ||
val classVisitor = CheckClassAdapter(ClassWriter(ClassWriter.COMPUTE_MAXS)) | ||
val classRemapper = ClassRemapper(classVisitor, object : Remapper() {}) | ||
try { | ||
classReader.accept(classRemapper, ClassReader.EXPAND_FRAMES) | ||
} catch (e: java.lang.RuntimeException) { | ||
throw java.lang.RuntimeException("Invalid bytecode file:" + it, e) | ||
} | ||
} | ||
} | ||
} |