Skip to content

Commit

Permalink
[GR-47667] Added support for maven meta-POMs.
Browse files Browse the repository at this point in the history
PullRequest: mx/1646
  • Loading branch information
tzezula committed Aug 1, 2023
2 parents 03fdc47 + 1a6a0ef commit 76312a4
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
25 changes: 23 additions & 2 deletions mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,6 +1464,9 @@ def isDistribution(self):
def isJARDistribution(self):
return isinstance(self, JARDistribution)

def isPOMDistribution(self):
return isinstance(self, POMDistribution)

def isLayoutJARDistribution(self):
return isinstance(self, LayoutJARDistribution)

Expand Down Expand Up @@ -2406,6 +2409,10 @@ def create_layout(default_type):
d = NativeTARDistribution(self, name, deps, path, exclLibs, platformDependent, theLicense, relpath, output, testDistribution=testDistribution, **attrs)
elif layout is not None:
d = create_layout('jar')
elif attrs.pop('type', None) == 'pom':
distDeps = Suite._pop_list(attrs, 'distDependencies', context)
runtimeDeps = Suite._pop_list(attrs, 'runtimeDependencies', context)
d = POMDistribution(self, name, distDeps, runtimeDeps, theLicense, **attrs)
else:
subDir = attrs.pop('subDir', None)
sourcesPath = attrs.pop('sourcesPath', None)
Expand Down Expand Up @@ -5566,6 +5573,7 @@ def get_artifact_metadata(self):
return None

from mx_jardistribution import JARDistribution, _get_proguard_cp, _use_exploded_build, _stage_file_impl
from mx_pomdistribution import POMDistribution

class JMHArchiveParticipant(object):
""" Archive participant for building JMH benchmarking jars. """
Expand Down Expand Up @@ -11344,6 +11352,8 @@ def _addDevAttr(name, default=None):
pom.element('version', data=dep_version)
if dep.remoteExtension() != 'jar':
pom.element('type', data=dep.remoteExtension())
if dist.isPOMDistribution() and dist.is_runtime_dependency(dep):
pom.element('scope', data='runtime')
pom.close('dependency')
for l in directLibDeps:
if (l.isJdkLibrary() or l.isJreLibrary()) and l.is_provided_by(get_jdk()) and l.is_provided_by(get_jdk(dist.maxJavaCompliance())):
Expand Down Expand Up @@ -11822,6 +11832,17 @@ def _maven_deploy_dists(dists, versionGetter, repo, settingsXml,
pomFile=pomFile,
gpg=gpg, keyid=keyid,
extraFiles=extraFiles)
elif dist.isPOMDistribution():
extraFiles = []
if repo_metadata_name:
extraFiles.append((repo_metadata_name, 'suite-revisions', 'xml'))
_deploy_binary_maven(dist.suite, dist.maven_artifact_id(), dist.maven_group_id(), pomFile, versionGetter(dist.suite), repo,
settingsXml=settingsXml,
extension=dist.remoteExtension(),
dryRun=dryRun,
pomFile=pomFile,
gpg=gpg, keyid=keyid,
extraFiles=extraFiles)
else:
abort_or_warn('Unsupported distribution: ' + dist.name, dist.suite.getMxCompatibility().maven_deploy_unsupported_is_error())
os.unlink(pomFile)
Expand Down Expand Up @@ -11868,7 +11889,7 @@ def _dist_matcher(dist, tags, all_distributions, only, skip, all_distribution_ty
return False
if all_distributions:
return True
if not dist.isJARDistribution() and not all_distribution_types:
if not (dist.isJARDistribution() or dist.isPOMDistribution()) and not all_distribution_types:
return False
if only is not None:
return _file_name_match(dist, only)
Expand Down Expand Up @@ -18538,7 +18559,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.36.1") # JAVA_HOME/EXTRA_JAVA_HOMES should be absolute valid paths
version = VersionSpec("6.37.0") # Add meta-POM distribution for artefacts with pom packaging.

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
72 changes: 72 additions & 0 deletions mx_pomdistribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#
# ----------------------------------------------------------------------------------------------------
#
# Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# ----------------------------------------------------------------------------------------------------
#

import mx


class POMDistribution(mx.Distribution):
"""
Represents a Maven artifact with POM packaging used to group Maven dependencies. It does not contain any actual
code or resources like traditional JARDistribution but acts as a metadata container that defines the project's
dependencies and other essential project information.
:param Suite suite: the suite in which the distribution is defined
:param str name: the name of the distribution which must be unique across all suites
:param list distDependencies: the `JARDistribution` dependencies that must be on the class path when this distribution
is on the class path (at compile or run time)
:param list runtimeDependencies: the `JARDistribution` dependencies that must be on the class path when this distribution
is on the class path (at run time)
:param str | None theLicense: license applicable when redistributing the built artifact of the distribution
"""
def __init__(self, suite, name, distDependencies, runtimeDependencies, theLicense, **kwArgs):
mx.Distribution.__init__(self, suite, name, distDependencies + runtimeDependencies, [], False, theLicense, **kwArgs)
self.runtimeDependencies = runtimeDependencies

def getBuildTask(self, args):
return mx.NoOpTask(self, args)

def make_archive(self):
pass

def exists(self):
return True

def remoteExtension(self):
return 'pom'

def localExtension(self):
return 'xml'

def resolveDeps(self):
super(POMDistribution, self).resolveDeps()
new_runtime_deps = []
for runtime_dep in self.runtimeDependencies:
new_runtime_deps.append(mx.dependency(runtime_dep, fatalIfMissing=True, context=self))
self.runtimeDependencies = new_runtime_deps

def is_runtime_dependency(self, dependency):
return dependency in self.runtimeDependencies

0 comments on commit 76312a4

Please sign in to comment.