forked from apache/geode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GEODE-8087: Fix Java binary compatibility errors reported by japicmp
* Fix 'exludeAnnotations' to use FQN of the annotation. * Allow changes if a class or superclass is marked @experimental
- Loading branch information
Showing
6 changed files
with
192 additions
and
82 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
35 changes: 35 additions & 0 deletions
35
buildSrc/src/main/groovy/org/apache/geode/gradle/japicmp/AllowMajorBreakingChanges.groovy
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,35 @@ | ||
/* | ||
* 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.geode.gradle.japicmp | ||
|
||
import japicmp.model.JApiCompatibility | ||
import me.champeau.gradle.japicmp.report.Violation | ||
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers | ||
import me.champeau.gradle.japicmp.report.Severity | ||
|
||
class AllowMajorBreakingChanges extends AbstractRecordingSeenMembers { | ||
@Override | ||
Violation maybeAddViolation(final JApiCompatibility member) { | ||
if (!member.isBinaryCompatible()) { | ||
return Violation.notBinaryCompatible(member, Severity.warning) | ||
} else { | ||
return null | ||
} | ||
} | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
buildSrc/src/main/groovy/org/apache/geode/gradle/japicmp/ParentIsExperimental.groovy
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,63 @@ | ||
/* | ||
* 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.geode.gradle.japicmp; | ||
|
||
import me.champeau.gradle.japicmp.report.Violation | ||
import me.champeau.gradle.japicmp.report.stdrules.AbstractRecordingSeenMembers | ||
import japicmp.model.JApiMethod | ||
import japicmp.model.JApiClass | ||
import japicmp.model.JApiSuperclass | ||
import japicmp.model.JApiConstructor | ||
import japicmp.model.JApiCompatibility | ||
|
||
|
||
class ParentIsExperimental extends AbstractRecordingSeenMembers { | ||
@Override | ||
public Violation maybeAddViolation(final JApiCompatibility member) { | ||
boolean isExperimental = true | ||
if (!member.isBinaryCompatible()) { | ||
if (member instanceof JApiMethod || member instanceof JApiConstructor) { | ||
isExperimental = isClassExperimental(member.jApiClass) | ||
} else if (member instanceof JApiClass) { | ||
isExperimental = isClassExperimental(member) | ||
} | ||
|
||
if (isExperimental) { | ||
println("return accept [${member}]") | ||
return Violation.accept(member, "Parent class is @Experimental") | ||
} | ||
} | ||
} | ||
|
||
boolean isClassExperimental(final JApiClass member) { | ||
println(" member annotations: [${member.annotations}]") | ||
boolean isExperimental = false | ||
if (!member.annotations.find { | ||
it.fullyQualifiedName == 'org.apache.geode.annotations.Experimental' | ||
}) { | ||
JApiSuperclass sup = member.superclass | ||
if (sup.getJApiClass().present) { | ||
isExperimental = isClassExperimental(sup.getJApiClass().get()) | ||
} else { | ||
} | ||
} else { | ||
isExperimental = true | ||
} | ||
return isExperimental | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import japicmp.model.JApiChangeStatus | ||
import org.apache.maven.artifact.versioning.ComparableVersion | ||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion | ||
|
||
import org.apache.geode.gradle.japicmp.AllowMajorBreakingChanges | ||
import org.apache.geode.gradle.japicmp.ParentIsExperimental | ||
|
||
|
||
def mostRecentReleaseProj = project(':geode-old-versions').subprojects.max(){ v -> new ComparableVersion(v.name)} | ||
def newest = mostRecentReleaseProj.name | ||
|
||
tasks.register('japicmp', me.champeau.gradle.japicmp.JapicmpTask) { | ||
inputs.files { configurations.geodeArchives } | ||
def ourUnpackTaskProvider = project(":geode-old-versions:${newest}").tasks.named('downloadAndUnzipFile') | ||
inputs.files { ourUnpackTaskProvider } | ||
|
||
def d = java.nio.file.Paths.get(project(":geode-old-versions:${newest}").buildDir.path.toString(), "apache-geode-${newest}", 'lib') | ||
// Dirty hack, to set the value as requied in configuration, | ||
// but then reset to the acutal unpacked jars on runtime. | ||
oldClasspath = files() | ||
oldArchives = files() | ||
doFirst { | ||
oldClasspath = files(file(d).listFiles()) | ||
oldArchives = files(file(d).listFiles(new FilenameFilter() { | ||
public boolean accept(File dir, String name) { | ||
return name.toLowerCase().startsWith("geode-") && name.toLowerCase().endsWith(".jar"); | ||
}; | ||
})) | ||
} | ||
|
||
newClasspath = configurations.geodeArchives | ||
newArchives = configurations.geodeArchives.filter { File f -> | ||
f.toString().contains("geode-") && f.toString().endsWith(".jar") | ||
} | ||
|
||
ignoreMissingClasses = true | ||
onlyModified = true | ||
accessModifier = "protected" | ||
|
||
def allowMajorBreaking = false | ||
if (new DefaultArtifactVersion(version).majorVersion > new DefaultArtifactVersion(newest).majorVersion) { | ||
logger.error("japicmp will always pass when comparing across major versions.") | ||
allowMajorBreaking = true | ||
} | ||
// failOnModification = !allowMajorBreaking | ||
// failOnSourceIncompatibility = !allowMajorBreaking | ||
|
||
// onlyBinaryIncompatibleModified = true | ||
// includeSynthetic = true | ||
|
||
def reportFileName = "japi-v${newest}-${version}" | ||
txtOutputFile = file("$buildDir/reports/${reportFileName}.txt") | ||
htmlOutputFile = file("$buildDir/reports/${reportFileName}.html") | ||
packageExcludes = ['*internal*'] | ||
packageIncludes = ['org.apache.geode.*'] | ||
annotationExcludes = ['@org.apache.geode.annotations.Experimental'] | ||
|
||
richReport { | ||
title = "Geode API Compatibility Report" | ||
description = "Comparing current ${version} against downloaded v${newest}." | ||
reportName = "rich-report-${reportFileName}.html" | ||
|
||
if (allowMajorBreaking) { | ||
addRule(AllowMajorBreakingChanges) | ||
} else { | ||
addRule(JApiChangeStatus.REMOVED, ParentIsExperimental) | ||
addRule(JApiChangeStatus.MODIFIED, ParentIsExperimental) | ||
} | ||
addDefaultRules = true | ||
} | ||
} |