gpt4 book ai didi

java - 如何自动生成 API 版本之间的差异?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:29 25 4
gpt4 key购买 nike

Android Open Source 会定期发布 API 级别之间的 API 差异列表。以下是来自 developer.android.com 的一些示例:

Difference between API Level 18 and 19

Difference between API Level 14 and 15

这看起来像是自动生成的。

我想使用类似的工具,以便跟踪我自己的源代码的 API 版本之间的差异。

什么工具可以帮我做这件事?

最佳答案

他们使用 JDiff,spring还在他们的文档中使用它。

如果您使用的是 gradle,您可以使用此文件作为引用,了解如何使用 JDiff 自动生成 API 差异报告:
https://github.com/Netflix/governator/blob/master/jdiff.gradle

/*
* Copyright 2015 Netflix, Inc.
*
* 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.
*/
plugins {
id 'org.ajoberstar.github-pages' version '1.4.2'
}
/**
* Generate a JDiff report between a newer version and an older version.
*
* Usage:
* gradle -PjDiff.olderVersion=2.1312.0 [-PjDiff.newerVersion=2.1716.0] generateJDiffReport
*
* View generated report at:
* build/reports/jDiff/${olderVersion}-to-${newerVersion}/changes.html
*/
task generateJDiffReport(dependsOn: '_jDiff_cloneOldVersion') {
description = "Generates a JDiff report"
group = "Documentation"

final jDiffHome = "${rootProject.rootDir}/buildSrc/lib/jdiff-1.1.1/"

ant.taskdef(
name: 'jDiff',
classname: 'jdiff.JDiffAntTask',
classpath: "${jDiffHome}/antjdiff.jar")

doLast {
final olderVersion = project.getProperty('jDiff.olderVersion')
final olderVersionRoot = new File("${rootProject.buildDir}/jDiff/${rootProject.name}-${olderVersion}")

if (olderVersion == null)
throw new IllegalArgumentException(
'Set `jDiff.olderVersion` property to indicate older of the two versions being compared')

final newerVersion = project.hasProperty('jDiff.newerVersion') ? project.getProperty('jDiff.newerVersion') : rootProject.version
final newerVersionRoot = rootProject.rootDir

final outputDir = "${rootProject.buildDir}/reports/jDiff/${olderVersion}-to-${newerVersion}"
mkdir(outputDir)

ant.metaClass.jDiff_getSrcDirSets = { root ->
root.eachDirMatch({ dir ->
new File("${dir}/src/main/java").exists()
}) { dir ->
dirset(dir: "${dir}/src/main/java")
}
}

ant.property(name: "JDIFF_HOME", value: jDiffHome)
ant.jDiff(
destdir: outputDir,
verbose: 'off',
stats: 'on',
docchanges: 'off',
source: '1.8') {
old(name: "${rootProject.name}-${olderVersion}") {
jDiff_getSrcDirSets(olderVersionRoot)
}

'new'(name: "${rootProject.name}-${newerVersion}") {
jDiff_getSrcDirSets(newerVersionRoot)
}
}
}
}
import org.ajoberstar.grgit.Grgit
task _jDiff_cloneOldVersion << {
final olderVersion = project.getProperty('jDiff.olderVersion')
final olderVersionRoot = new File("${rootProject.buildDir}/jDiff/${rootProject.name}-${olderVersion}")

final newerVersionRoot = rootProject.rootDir

if (!olderVersionRoot.isDirectory()) {
Grgit.clone(
uri: "file://${newerVersionRoot.path}/.git",
dir: olderVersionRoot.path,
refToCheckout: "refs/tags/v${olderVersion}")
}
}

关于java - 如何自动生成 API 版本之间的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21615411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com