Skip to content

Commit

Permalink
Add Java to assets report (#5967)
Browse files Browse the repository at this point in the history
* add processing of `java` to the assets report
  • Loading branch information
scbedd authored Apr 17, 2023
1 parent dc7ce88 commit e4c5572
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
3 changes: 2 additions & 1 deletion eng/scripts/python/assets-automation/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ js.md
net.md
go.md
cpp.md
.net.md
.net.md
java.md
72 changes: 71 additions & 1 deletion eng/scripts/python/assets-automation/generate_assets_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from packaging import version # from packaging
from ci_tools.functions import (
discover_targeted_packages,
) # azure-sdk-tools from azure-sdk-for-python
) # azure-sdk-tools from Azure/azure-sdk-for-python

from ci_tools.parsing import ParsedSetup

Expand Down Expand Up @@ -325,6 +325,72 @@ def generate_cpp_report() -> ScanResult:
return result


def resolve_java_test_directory(package_path: str) -> str:
singular = os.path.join(os.path.dirname(package_path), "src", "test")
plural = os.path.join(os.path.dirname(package_path), "src", "tests")

if os.path.exists(singular):
return singular
elif os.path.exists(plural):
return plural
else:
return ""


def evaluate_java_package(package_path: str) -> int:
possible_test_directory = resolve_java_test_directory(package_path)
possible_assets_location = os.path.join(os.path.dirname(package_path),'assets.json')

if not possible_test_directory:
return 0

test_files = glob.glob(os.path.join(possible_test_directory, "**", "*.java"), recursive=True)

if os.path.exists(possible_assets_location):
return 2

for testfile in test_files:
try:
with open(testfile, "r", encoding="utf-8") as f:
content = f.read()

if "extends TestProxyTestBase" in content:
return 1
except:
pass

return 0


def generate_java_report() -> ScanResult:
language = "Java"
result = ScanResult(language)
repo_root = get_repo(language)

print(f"Evaluating repo for {language} @ {repo_root}", end="...")

# enforce looking under individual package dir, and not service dir
packages = glob.glob(os.path.join(repo_root, "sdk", "*", "*", "pom.xml"), recursive=True)

# we don't care about packages that start with 'microsoft-' as they are track 1 and will never migrate
packages = [package for package in packages if not "microsoft-" in os.path.dirname(package)]

result.packages = sorted([os.path.basename(os.path.dirname(pkg)) for pkg in packages])

for pkg in packages:
evaluation = evaluate_java_package(pkg)

if evaluation == 1:
result.packages_using_proxy.append(os.path.basename(os.path.dirname(pkg)))
elif evaluation == 2:
result.packages_using_proxy.append(os.path.basename(os.path.dirname(pkg)))
result.packages_using_external.append(os.path.basename(os.path.dirname(pkg)))


print("done.")
return result


def evaluate_js_package(package_path: str) -> int:
with open(package_path, "r", encoding="utf-8") as f:
package_json = json.load(f)
Expand Down Expand Up @@ -532,12 +598,16 @@ def write_summary(results: List[ScanResult]) -> None:
cpp = generate_cpp_report()
write_output(cpp)

java = generate_java_report()
write_output(java)

write_summary(
[
python,
js,
go,
net,
cpp,
java
]
)

0 comments on commit e4c5572

Please sign in to comment.