Skip to content

Commit

Permalink
[GR-47568] Added noMavenSources to prevent sources upload to maven re…
Browse files Browse the repository at this point in the history
…pository.

PullRequest: mx/1656
  • Loading branch information
tzezula committed Aug 14, 2023
2 parents 6bb2d6e + a37ea90 commit 7cf3088
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
from argparse import ArgumentParser, PARSER, REMAINDER, Namespace, HelpFormatter, ArgumentTypeError, RawTextHelpFormatter, FileType
from os.path import join, basename, dirname, exists, lexists, isabs, expandvars as os_expandvars, isdir, islink, normpath, realpath, relpath, splitext
from tempfile import mkdtemp, mkstemp
from io import BytesIO, open as io_open
from io import BytesIO, StringIO, open as io_open
import fnmatch
import operator
import calendar
Expand Down Expand Up @@ -11808,7 +11808,20 @@ def _maven_deploy_dists(dists, versionGetter, repo, settingsXml,
jar_to_deploy = alt_jmd.jarpath

pushed_file = dist.prePush(jar_to_deploy)
pushed_src_file = dist.prePush(dist.sourcesPath)
if getattr(dist, "noMavenSources", False):
tmpSourcesJar = tempfile.NamedTemporaryFile('w', suffix='.jar', delete=False)
tmpSourcesJar.close()
pushed_src_file = tmpSourcesJar.name
with zipfile.ZipFile(pushed_src_file, 'w', compression=zipfile.ZIP_DEFLATED) as arc:
with StringIO() as license_file_content:
license_ids = dist.theLicense
if not license_ids:
license_ids = dist.suite.defaultLicense
for resolved_license in get_license(license_ids):
print(f'{resolved_license.name} {resolved_license.url}\n', file=license_file_content)
arc.writestr("LICENSE", license_file_content.getvalue())
else:
pushed_src_file = dist.prePush(dist.sourcesPath)
_deploy_binary_maven(dist.suite, dist.maven_artifact_id(), dist.maven_group_id(), pushed_file, versionGetter(dist.suite), repo,
srcPath=pushed_src_file,
settingsXml=settingsXml,
Expand Down Expand Up @@ -11879,10 +11892,16 @@ def _deploy_dists(uploader, dists, version_getter, snapshot_id, primary_revision

def _match_tags(dist, tags):
maven = getattr(dist, 'maven', False)
maven_tag = 'default'
maven_tag = {'default'}
if isinstance(maven, dict) and 'tag' in maven:
maven_tag = maven['tag']
return maven_tag in tags
if isinstance(maven_tag, str):
maven_tag = {maven_tag}
elif isinstance(maven_tag, list):
maven_tag = set(maven_tag)
else:
abort('Maven tag must be str or list[str]', context=dist)
return any(tag in maven_tag for tag in tags)

def _file_name_match(dist, names):
return any(fnmatch.fnmatch(dist.name, n) or fnmatch.fnmatch(dist.qualifiedName(), n) for n in names)
Expand Down Expand Up @@ -18595,7 +18614,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.40.2") # GR-47853 - remove URL verification from gate
version = VersionSpec("6.41.0") # Added noMavenSources, forbidding uploading source code to the maven repository.

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down

0 comments on commit 7cf3088

Please sign in to comment.