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

Add Java to assets report #5967

Merged
merged 4 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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
]
)