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

Added metadata for testing jars #1011

Merged
merged 2 commits into from
Aug 8, 2024
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
37 changes: 31 additions & 6 deletions .github/download_jars.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import requests
import random
import os
import json

print('Job Starting')

BASE_URL = "https://search.maven.org/solrsearch/select"
DOWNLOAD_URL_TEMPLATE = "https://repo1.maven.org/maven2/{group}/{artifact}/{version}/{artifact}-{version}.jar"
metadata_path = os.getenv('METADATA_PATH', 'metadata.json')
OUTPUT_DIR = "downloaded_jars"
NUM_JARS = 100
MAX_SIZE_MB = 5 * 1024 * 1024 # 5MB in bytes
Expand Down Expand Up @@ -50,6 +52,23 @@ def get_random_artifact():


downloaded_count = 0


def get_metadata():
if os.path.isfile(metadata_path): # Check if it is a file
with open(metadata_path, 'r') as file:
return json.load(file)
elif os.path.isdir(metadata_path):
raise IsADirectoryError(f"{metadata_path} is a directory, not a file.")
return {"jars": []}


def save_metadata(data):
with open(metadata_path, 'w') as file:
json.dump(data, file, indent=4)


metadata = get_metadata()
# Download 100 random JARs
while downloaded_count < NUM_JARS:
artifact = get_random_artifact()
Expand All @@ -60,12 +79,18 @@ def get_random_artifact():
version = artifact['latestVersion']
download_url = construct_download_url(group, artifact_id, version)
output_path = os.path.join(OUTPUT_DIR, f"{artifact_id}-{version}.jar")
artifact_name = f"{artifact_id}--{version}.jar"
try:
if download_file(download_url, output_path):
print(f"Downloaded: {output_path}")
downloaded_count += 1
else:
print(f"Skipped (too large): {output_path}")
if not any(jar['name'] == artifact_name for jar in metadata['jars']):
if download_file(download_url, output_path):
metadata['jars'].append({
'name': artifact_name
})
save_metadata(metadata)
print(f"Downloaded: {output_path}")
downloaded_count += 1
else:
print(f"Skipped (too large): {output_path}")
except requests.RequestException as e:
print(f"Failed to download {download_url}: {e}")
print(f"Downloaded {downloaded_count} JAR files.")
print(f"Downloaded {downloaded_count} JAR files.")
31 changes: 29 additions & 2 deletions .github/workflows/test-jars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,38 @@ jobs:
run:
pip install requests

- name: Download Metadata
id: download-metadata
uses: actions/download-artifact@v3
with:
name: metadata
path: metadata
continue-on-error: true # Allows workflow to continue even if the artifact metadata is not found (obviously it will not be found for the first run)

- name: Create empty metadata file
if: failure() # This runs if the previous step failed
run: |
echo '{"jars":[]}' > metadata/metadata.json

- name: Download random JARs
id: download
run: |
python .github/download_jars.py
env:
METADATA_PATH: metadata/metadata.json

- name: Upload JARs
uses: actions/upload-artifact@v3
with:
name: jars
path: downloaded_jars/

- name: Upload Metadata
uses: actions/upload-artifact@v3
with:
name: metadata
path: metadata/metadata.json

- name: Setup Java
uses: actions/setup-java@v3
with:
Expand All @@ -48,11 +70,16 @@ jobs:
run: |
mvn clean install -DskipTests

- name: List directory contents
run: |
ls -l
ls -l ${{ github.workspace }}/downloaded_jars

- name: Run tests on downloaded JARs
run: |
for jar in ${{ github.workspace }}/downloaded_jars/*.jar; do
for jar in $(ls ${{ github.workspace }}/downloaded_jars/*.jar); do
echo "Testing $jar"
mvn clean test -Dtest=sootup.java.bytecode.inputlocation.RandomJarTest -DjarPath="$jar" -pl sootup.java.bytecode
mvn test -Dtest=sootup.java.bytecode.inputlocation.RandomJarTest -DjarPath="$jar" -pl sootup.java.bytecode
done

- name: Upload the Artifact
Expand Down
Loading