[javapackages/new-metadata-experiment] [artifact] Handle incomplete metadata properly
by Stanislav Ochotnicky
commit 6b0ad7df2e87c2a498439718cd631d18dcf7c456
Author: Stanislav Ochotnicky <sochotnicky(a)redhat.com>
Date: Fri Apr 11 17:18:34 2014 +0200
[artifact] Handle incomplete metadata properly
python/javapackages/artifact.py | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/python/javapackages/artifact.py b/python/javapackages/artifact.py
index 01d63eb..e6d61bb 100644
--- a/python/javapackages/artifact.py
+++ b/python/javapackages/artifact.py
@@ -257,17 +257,17 @@ class Artifact(object):
groupId = metadata.groupId.strip()
artifactId = metadata.artifactId.strip()
version = extension = classifier = namespace = ""
- if metadata.version:
+ if hasattr(metadata, 'version') and metadata.version:
version = metadata.version.strip()
- if metadata.extension:
+ if hasattr(metadata, 'extension') and metadata.extension:
extension = metadata.extension.strip()
- if metadata.classifier:
+ if hasattr(metadata, 'classifier') and metadata.classifier:
classifier = metadata.classifier.strip()
- if metadata.namespace:
+ if hasattr(metadata, 'namespace') and metadata.namespace:
namespace = metadata.namespace.strip()
compatVersions = []
- if metadata.compatVersions:
+ if hasattr(metadata, 'compatVersions') and metadata.compatVersions:
for cv in metadata.compatVersions.version:
compatVersions.append(cv)
10 years, 1 month
[javapackages/new-metadata-experiment] [artifact] Properly initialize values when creating from metadata
by Stanislav Ochotnicky
commit a54093ab8bea4f11f8f632280d3d45c0628aaa85
Author: Stanislav Ochotnicky <sochotnicky(a)redhat.com>
Date: Fri Apr 11 16:12:01 2014 +0200
[artifact] Properly initialize values when creating from metadata
python/javapackages/artifact.py | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
---
diff --git a/python/javapackages/artifact.py b/python/javapackages/artifact.py
index 6c9a57a..01d63eb 100644
--- a/python/javapackages/artifact.py
+++ b/python/javapackages/artifact.py
@@ -256,6 +256,7 @@ class Artifact(object):
def from_metadata(cls, metadata):
groupId = metadata.groupId.strip()
artifactId = metadata.artifactId.strip()
+ version = extension = classifier = namespace = ""
if metadata.version:
version = metadata.version.strip()
if metadata.extension:
10 years, 1 month
[javapackages: 16/16] Merge branch 'pom_editor.py'
by Michael Šimáček
commit 6778c6869f033c216cf35708efab51aaf309343f
Merge: 31f380c 4cf222b
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Fri Apr 11 16:47:15 2014 +0200
Merge branch 'pom_editor.py'
build | 1 +
java-utils/pom_editor.py | 538 ++++++++++++++------
macros.d/macros.fjava | 13 +-
man/pom_add_dep.txt | 32 +-
man/pom_add_parent.txt | 6 +-
man/pom_add_plugin.txt | 5 +-
man/pom_change_dep.txt | 79 +++
man/pom_disable_module.txt | 6 +-
man/pom_remove_dep.txt | 34 ++-
man/pom_remove_parent.txt | 6 +-
man/pom_remove_plugin.txt | 19 +-
man/pom_set_parent.txt | 8 +-
man/pom_xpath_inject.txt | 38 +-
man/pom_xpath_remove.txt | 51 ++-
man/pom_xpath_replace.txt | 43 ++-
man/pom_xpath_set.txt | 34 +-
test/data/pom_editor/build.xml | 26 +
test/data/pom_editor/build_ns.xml | 10 +
test/data/pom_editor/example_common.xml | 37 ++
test/data/pom_editor/example_intermediate.xml | 26 +
test/data/pom_editor/example_parent.xml | 26 +
.../example_parent_plugin_with_module.xml | 28 +
test/data/pom_editor/example_parent_profile.xml | 29 +
test/data/pom_editor/example_schemas.xml | 67 +++
test/data/pom_editor/intermediate_pom.xml | 26 +
test/data/pom_editor/minimal_pom.xml | 13 +
test/data/pom_editor/minimal_pom_nons.xml | 13 +
test/data/pom_editor/simple_ivy.xml | 11 +
test/data/pom_editor/simple_pom.xml | 37 ++
test/data/pom_editor/want/build_attr.xml | 26 +
test/data/pom_editor/want/build_attr_removed.xml | 26 +
test/data/pom_editor/want/build_ns_set.xml | 10 +
test/data/pom_editor/want/build_set.xml | 25 +
test/data/pom_editor/want/build_with_lib.xml | 27 +
test/data/pom_editor/want/build_without_dist.xml | 19 +
.../data/pom_editor/want/example_common_apache.xml | 37 ++
.../pom_editor/want/example_common_commons.xml | 37 ++
.../data/pom_editor/want/example_common_junit3.xml | 37 ++
.../want/example_common_removed_all_deps.xml | 16 +
.../want/example_common_removed_commons_io.xml | 22 +
.../want/example_common_removed_commons_iox.xml | 32 ++
.../want/example_common_removed_junit.xml | 31 ++
.../example_intermediate_removed_commons_io.xml | 20 +
.../want/example_schemas_removed_junit.xml | 60 +++
.../pom_editor/want/minimal_add_dep_mgmt_scope.xml | 22 +
.../data/pom_editor/want/minimal_add_dep_scope.xml | 20 +
.../want/minimal_add_plugin_resource.xml | 25 +
test/data/pom_editor/want/minimal_pom_add_ant.xml | 22 +
.../data/pom_editor/want/minimal_pom_add_uimaj.xml | 21 +
.../pom_editor/want/minimal_removed_parent.xml | 9 +
.../pom_editor/want/simple_ivy_added_foo_bar.xml | 12 +
.../pom_editor/want/simple_ivy_added_orbit.xml | 16 +
.../data/pom_editor/want/simple_ivy_remove_rev.xml | 11 +
.../pom_editor/want/simple_ivy_removed_xerces.xml | 10 +
.../data/pom_editor/want/simple_ivy_xerces_aid.xml | 11 +
.../pom_editor/want/simple_removed_commons_io.xml | 22 +
.../data/pom_editor/want/simple_removed_parent.xml | 32 ++
test/data/pom_editor/want/simple_removed_scope.xml | 36 ++
test/data/pom_macros/pom_xpath_set.xml-want | 6 +-
test/data/pom_macros/pom_xpath_set2.xml-want | 6 +-
.../pom_macros/pom_xpath_set_multiple.xml-want | 24 +-
test/data/pom_macros/pom_xpath_set_nons.xml-want | 6 +-
test/pom_editor_artifact_test.py | 81 +++
test/pom_editor_paths_test.py | 247 +++++++++
test/pom_editor_xml_test.py | 98 ++++
test/pom_macros_test.py | 4 +-
test/test_common.py | 110 ++++-
test/test_rpmbuild.py | 33 +-
68 files changed, 2248 insertions(+), 323 deletions(-)
---
diff --cc test/test_rpmbuild.py
index 51251d3,4eefc4d..122f50b
--- a/test/test_rpmbuild.py
+++ b/test/test_rpmbuild.py
@@@ -169,11 -170,12 +171,12 @@@ class Package(object)
def __prepare_sources(self):
destpath = os.path.join('rpmbuild', 'SOURCES')
- for sourcepath, targetname in self.__sources.iteritems():
- shutil.copy(sourcepath, os.path.join(destpath, targetname))
+ for index, (sourcepath, targetname) in enumerate(self.__sources):
+ target = os.path.join(destpath, os.path.basename(targetname))
+ shutil.copy(sourcepath, '{0}{1}'.format(target, index))
def _prepare_macros():
- etcpath = os.path.join(DIRPATH, '..', 'etc')
+ macropath = os.path.join(DIRPATH, '..', 'macros.d')
java_utils = os.path.abspath(os.path.join(DIRPATH, '..', 'java-utils'))
with open('.rpmmacros', 'w') as rpmmacros:
10 years, 1 month
[javapackages] (16 commits) ...Merge branch 'pom_editor.py'
by Michael Šimáček
Summary of changes:
25690e1... [test] Add tests for pom paths specification (*)
9b12d18... [macros] pass -r (recursive) and -f (force) options to pom_ (*)
dc2286a... [test] add tests for recursive mode and force option (*)
c6d1b8e... [pom_editor] implement recursive mode and force option (*)
ba6355f... [test] refactor tests (*)
13e94e6... [test] tests for pom_change_dep and other artifact macros (*)
2118198... [pom_editor] implement pom_change_dep (*)
e2195a5... [pom_editor] don't follow module nodes where arbitrary cont (*)
803b549... [pom_editor] replacement coments identify what has been rem (*)
970e3d9... [pom_editor] pom_xpath_* can manipulate arbitrary XML files (*)
b257c9b... [pom_editor] Implement dependency handling macros for Ivy (*)
4b01f41... [pom_editor] allow removing pars with pom_change_dep (*)
6ab2f26... [pom_editor] tests for generic xml files and ivy files (*)
b8dd278... [pom_editor] Use namespace prefixes from input file (*)
4cf222b... [man] Document new features in pom_editor (*)
6778c68... Merge branch 'pom_editor.py'
(*) This commit already existed in another branch; no separate mail sent
10 years, 1 month
[javapackages/pom_editor.py] [man] Document new features in pom_editor
by Michael Šimáček
commit 4cf222baf4f9911e5d1fffdd01b02b60f78a7703
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Fri Apr 11 16:42:39 2014 +0200
[man] Document new features in pom_editor
build | 1 +
man/pom_add_dep.txt | 32 +++++++++++++-----
man/pom_add_parent.txt | 6 ++-
man/pom_add_plugin.txt | 5 ++-
man/pom_change_dep.txt | 79 ++++++++++++++++++++++++++++++++++++++++++++
man/pom_disable_module.txt | 6 ++-
man/pom_remove_dep.txt | 34 ++++++++++++++++--
man/pom_remove_parent.txt | 6 ++-
man/pom_remove_plugin.txt | 19 +++++++++-
man/pom_set_parent.txt | 8 ++++-
man/pom_xpath_inject.txt | 38 ++++++++++++++-------
man/pom_xpath_remove.txt | 51 +++++++++++++++++++++-------
man/pom_xpath_replace.txt | 43 ++++++++++++++++++------
man/pom_xpath_set.txt | 34 ++++++++++++-------
14 files changed, 289 insertions(+), 73 deletions(-)
---
diff --git a/build b/build
index 8a23526..9849cd1 100755
--- a/build
+++ b/build
@@ -103,6 +103,7 @@ manpage pom_disable_module
manpage pom_remove_dep
manpage pom_remove_parent
manpage pom_remove_plugin
+manpage pom_change_dep
manpage pom_set_parent
manpage pom_xpath_inject
manpage pom_xpath_remove
diff --git a/man/pom_add_dep.txt b/man/pom_add_dep.txt
index 3d2d863..f1643aa 100644
--- a/man/pom_add_dep.txt
+++ b/man/pom_add_dep.txt
@@ -6,21 +6,24 @@ pom_add_dep(7)
NAME
----
-pom_add_dep - add dependency to POM file
+pom_add_dep - add dependency to Maven POM file or Ivy module
SYNOPSIS
--------
*%pom_add_dep* groupId**:**artifactId[**:**version[**:**scope]]
- [POM-location] [extra-XML]
+ [POM-location]... [extra-XML]
+
+*%pom_add_dep* org**:**name[**:**rev[**:**conf[**:**transitive]]]
+ [Ivy-module-location]... [extra-XML]
*%pom_add_dep_mgmt* groupId**:**articId[**:**version[**:**scope]]
- [POM-location] [extra-XML]
+ [POM-location]... [extra-XML]
DESCRIPTION
-----------
-These macros patch specified POM file adding a dependency on given
-version of artifactId from groupId, with given scope (if
-any). *pom_add_dep* adds the dependency to *<dependencies>* XML node,
+These macros patch specified POM or Ivy file adding a dependency on given
+Maven artifact specified by artifact coordinates.
+*pom_add_dep* adds the dependency to *<dependencies>* XML node,
while *pom_add_dep_mgmt* adds it to *<dependencyManagement>*.
groupId and artifactId are identifiers of Maven artifact on which
@@ -29,9 +32,19 @@ specified then default value of *"any"* is used. If scope is not
specified then no scope is defined (Maven defaults to "compile" in
this case).
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+When modifying Ivy modules, the org, name and rev correspond to the
+Maven groupId and artifactId and version. Org and name must be
+specified, other attributes use defaults. The conf attribute specifies
+the configuration in which the dependency should apply. The transitive
+attribute specifies whether the dependency should also pull in it's
+dependencies. It accepts boolean values - true or false. When
+unspecified Ivy defaults to true.
+
+POM location can be either a full path to the POM or Ivy file, or a path
+to the directory containing *pom.xml* or *ivy.xml*. If POM location is
+not given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations which will be processed.
Extra XML is additional XML code to be added into the *<dependency>*
node. This parameter can be ommited, in which case no extra XML is
@@ -59,6 +72,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_add_parent.txt b/man/pom_add_parent.txt
index c7fc043..966f323 100644
--- a/man/pom_add_parent.txt
+++ b/man/pom_add_parent.txt
@@ -10,7 +10,7 @@ pom_add_parent - add parent POM reference to POM file
SYNOPSIS
--------
-*%pom_add_parent* groupId**:**artifactId[**:**version] [POM-location]
+*%pom_add_parent* groupId**:**artifactId[**:**version] [POM-location]...
DESCRIPTION
-----------
@@ -23,7 +23,8 @@ version is not specified then default value of "any" is used.
POM location can be either a full path to the POM file, or a path to
the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed.
EXAMPLES
--------
@@ -47,6 +48,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_add_plugin.txt b/man/pom_add_plugin.txt
index b7a1dc0..1b32f96 100644
--- a/man/pom_add_plugin.txt
+++ b/man/pom_add_plugin.txt
@@ -10,7 +10,7 @@ pom_add_plugin - add plugin invocation to POM file
SYNOPSIS
--------
-*%pom_add_plugin* groupId**:**artifactId[**:**version] [POM-location]
+*%pom_add_plugin* groupId**:**artifactId[**:**version] [POM-location]...
[extra-XML]
DESCRIPTION
@@ -26,7 +26,8 @@ default value of "any" is used.
POM location can be either a full path to the POM file, or a path to
the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed.
Extra XML is additional XML code to be added into the *<plugin>* node.
This parameter can be ommited, in which case no extra XML is appended.
diff --git a/man/pom_change_dep.txt b/man/pom_change_dep.txt
new file mode 100644
index 0000000..234853f
--- /dev/null
+++ b/man/pom_change_dep.txt
@@ -0,0 +1,79 @@
+pom_add_dep(7)
+==============
+:doctype: manpage
+:man source: JAVAPACKAGES
+:man manual: Java Packages Tools
+
+NAME
+----
+pom_change_dep - change dependency in Maven POM file or Ivy module
+
+SYNOPSIS
+--------
+*%pom_change_dep* [OPTIONS] SOURCE_ARTIFACT CHANGED_ARTIFACT [POM-location]...
+ [extra-XML]
+
+*%pom_change_dep* [OPTIONS] SOURCE_ARTIFACT CHANGED_ARTIFACT
+ [Ivy-module-location]... [extra-XML]
+
+OPTIONS
+-------
+
+*-r*::
+Work in recursive mode. That means that given dependency is also changed
+in all enabled submodules of given POM file(s). Has no effect if the
+file is not Maven POM.
+
+*-f*::
+Do not throw an error when one of the specified files doesn't contain
+given dependency.
+
+DESCRIPTION
+-----------
+These macros patch specified POM or Ivy file changing a dependency on
+given Maven artifact specified by artifact coordinates to artifact
+specified by second set of Maven coordinates. The artifact specification
+has same format as *%pom_add_dep*. The omitted or empty parts in second
+artifact specification cause the original value to be left unmodified.
+Supplying a special value of *-* for given part causes that part of
+artifact specification to be deleted.
+
+POM location can be either a full path to the POM or Ivy file, or a path
+to the directory containing *pom.xml* or *ivy.xml*. If POM location is
+not given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations which will be processed.
+
+Extra XML is additional XML code to be added into the *<dependency>*
+node. This parameter can be ommited, in which case no extra XML is
+appended.
+
+EXAMPLES
+--------
+*pom_change_dep foo: com.example.foo:* - this call changes groupId of
+all dependencies which have groupId foo to com.example.foo. Their
+artifactId, versions and other possible parts are left unmodified.
+
+AUTHOR
+------
+Written by Michael Simacek.
+
+REPORTING BUGS
+--------------
+Bugs should be reported through Red Hat Bugzilla at
+http://bugzilla.redhat.com/.
+
+SEE ALSO
+--------
+*pom_add_dep*(7),
+*pom_add_parent*(7),
+*pom_add_plugin*(7),
+*pom_disable_module*(7),
+*pom_remove_dep*(7),
+*pom_remove_parent*(7),
+*pom_remove_plugin*(7),
+*pom_set_parent*(7),
+*pom_xpath_inject*(7),
+*pom_xpath_remove*(7),
+*pom_xpath_replace*(7),
+*pom_xpath_set*(7).
diff --git a/man/pom_disable_module.txt b/man/pom_disable_module.txt
index 85f5342..dbbad1b 100644
--- a/man/pom_disable_module.txt
+++ b/man/pom_disable_module.txt
@@ -10,7 +10,7 @@ pom_disable_module - disable given project module in POM file
SYNOPSIS
--------
-*%pom_disable_module* module-name [POM-location]
+*%pom_disable_module* module-name [POM-location]...
DESCRIPTION
-----------
@@ -22,7 +22,8 @@ not be ommited.
POM location can be either a full path to the POM file, or a path to
the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed.
EXAMPLES
--------
@@ -46,6 +47,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_remove_dep.txt b/man/pom_remove_dep.txt
index 113aeb2..142d8cf 100644
--- a/man/pom_remove_dep.txt
+++ b/man/pom_remove_dep.txt
@@ -10,7 +10,24 @@ pom_remove_dep - remove dependency on Maven artifact from POM file
SYNOPSIS
--------
-*%pom_remove_dep* \[groupId]**:**[artifactId] [POM-location]
+*%pom_remove_dep* [OPTIONS]
+\[groupId]**:**[artifactId][**:**version[**:**scope]] [POM-location]...
+
+*%pom_remove_dep* [OPTIONS]
+\[org]**:**[name][**:**rev[**:**conf[**:**transitive]]]
+[Ivy-module-location]...
+
+OPTIONS
+-------
+
+*-r*::
+Work in recursive mode. That means that dependency is also removed from
+all enabled submodules of given POM file(s).
+
+*-f*::
+Do not throw an error when one of the specified files doesn't contain
+given dependency.
+
DESCRIPTION
-----------
@@ -21,9 +38,17 @@ groupId and artifactId are identifiers of Maven group and artifact of
the module on which dependency is to be removed. If they are ommited
then all identifiers are matched.
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+When modifying Ivy modules, the org and name correspond to the Maven
+groupId and artifactId.
+
+POM location can be either a full path to the POM or Ivy file, or a path
+to the directory containing *pom.xml* or *ivy.xml*. If POM location is
+not given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations. If the dependency is not
+found in all of given files, the command raises an error. This can be
+overriden with the `-f` option.
+
EXAMPLES
--------
@@ -52,6 +77,7 @@ SEE ALSO
*pom_disable_module*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_remove_parent.txt b/man/pom_remove_parent.txt
index 9b00646..bfbcc96 100644
--- a/man/pom_remove_parent.txt
+++ b/man/pom_remove_parent.txt
@@ -10,7 +10,7 @@ pom_remove_parent - remove parent POM reference from POM file
SYNOPSIS
--------
-*%pom_remove_parent* [POM-location]
+*%pom_remove_parent* [POM-location]...
DESCRIPTION
-----------
@@ -19,7 +19,8 @@ POM.
POM location can be either a full path to the POM file, or a path to
the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed.
EXAMPLES
--------
@@ -43,6 +44,7 @@ SEE ALSO
*pom_disable_module*(7),
*pom_remove_dep*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_remove_plugin.txt b/man/pom_remove_plugin.txt
index 4a38423..246e50d 100644
--- a/man/pom_remove_plugin.txt
+++ b/man/pom_remove_plugin.txt
@@ -10,7 +10,19 @@ pom_remove_plugin - remove Maven plugin invocation from POM file
SYNOPSIS
--------
-*%pom_remove_plugin* \[groupId]**:**[artifactId] [POM-location]
+*%pom_remove_plugin* [OPTIONS]
+\[groupId]**:**[artifactId][**:**version[**:**scope]] [POM-location]...
+
+OPTIONS
+-------
+
+*-r*::
+Work in recursive mode. That means that plugin is also removed from
+all enabled submodules of given POM file(s).
+
+*-f*::
+Do not throw an error when one of the specified files doesn't contain
+given dependency.
DESCRIPTION
-----------
@@ -23,7 +35,9 @@ then all identifiers are matched.
POM location can be either a full path to the POM file, or a path to
the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed. You can specify more file
+locations.
EXAMPLES
--------
@@ -47,6 +61,7 @@ SEE ALSO
*pom_disable_module*(7),
*pom_remove_dep*(7),
*pom_remove_parent*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_set_parent.txt b/man/pom_set_parent.txt
index c8ab874..9d74724 100644
--- a/man/pom_set_parent.txt
+++ b/man/pom_set_parent.txt
@@ -10,7 +10,7 @@ pom_set_parent - set parent POM reference in POM file
SYNOPSIS
--------
-*%pom_set_parent* groupId**:**artifactId[**:**version] [POM-location]
+*%pom_set_parent* groupId**:**artifactId[**:**version] [POM-location]...
DESCRIPTION
-----------
@@ -23,6 +23,11 @@ followed by invocation of *%pom_add_parent*. See
*pom_remove_parent*(7) and *pom_add_parent*(7) for more information
about parameters.
+POM location can be either a full path to the POM file, or a path to
+the directory containing *pom.xml*. If POM location is not given then
+*pom.xml* from current working directory is used. You can specify more
+file locations which will be processed.
+
EXAMPLES
--------
*%pom_set_parent com.example:example-parent module* - this call sets
@@ -46,6 +51,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
*pom_xpath_replace*(7),
diff --git a/man/pom_xpath_inject.txt b/man/pom_xpath_inject.txt
index 8528cc5..914f79a 100644
--- a/man/pom_xpath_inject.txt
+++ b/man/pom_xpath_inject.txt
@@ -6,36 +6,47 @@ pom_xpath_inject(7)
NAME
----
-pom_xpath_inject - inject XML code into POM file
+pom_xpath_inject - inject code into XML file
SYNOPSIS
--------
-*%pom_xpath_inject* XPath [XML-code] [POM-location]
+*%pom_xpath_inject* XPath [XML-code] [XML-file-location]...
DESCRIPTION
-----------
-This macro patches specified POM file appending some code as childreen
+This macro patches specified XML file appending given code as children
of all XML nodes described by the XPath expression.
-XPath is an expression describing a set of XML nodes in the POM file
+XPath is an expression describing a set of XML nodes in the XML file
to which child code is to be appended. It must be a properly formated
XPath 1.0 expression, as described in http://www.w3.org/TR/xpath/.
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+Maven POM files use specific XML namespace
+`http://maven.apache.org/POM/4.0.0` as default. This namespace needs to
+be explicitly specified in XPath expressions by prefixing all node names
+with `pom:` (i.e. `pom:modelVersion`).
+
+Many other XML formats also use namespaces which you have to explicitly
+specify. This script will use the namespace prefix names from the
+*xmlns* declarations in the document's root element. So if the document
+begins with `<root xmlns:my="myurl.com">` you would select the root node
+with XPath expression `/my:root`. If the document specifies a default
+namespace (e.g. `xmlns="myurl.com"`) use the prefix named *default* to
+acces elements in that namespace.
+
+XML location can be either a full path to the XML, or a path to the
+directory containing *pom.xml* or *ivy.xml*. If XML location is not
+given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations.
EXAMPLES
--------
*%pom_xpath_inject pom:project "<packaging>war</packaging>"* - this
call sets packaging of POM in current working directory to *war*.
-BUGS
-----
-POM files use a specific namespace -
-http://maven.apache.org/POM/4.0.0. Currently this namespace needs to
-be explicitly specified in all XPath POM macros by prefixing all node
-names with *pom:*.
+*%pom_xpath inject configurations \'<conf name="test"/>'* - this adds
+a new configuration to the Ivy file in current working directory.
AUTHOR
------
@@ -55,6 +66,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_remove*(7),
*pom_xpath_replace*(7),
diff --git a/man/pom_xpath_remove.txt b/man/pom_xpath_remove.txt
index 57c3201..9b73e3f 100644
--- a/man/pom_xpath_remove.txt
+++ b/man/pom_xpath_remove.txt
@@ -6,36 +6,62 @@ pom_xpath_remove(7)
NAME
----
-pom_xpath_remove - remove an XML node from POM file
+pom_xpath_remove - remove a node from XML file
SYNOPSIS
--------
-*%pom_xpath_remove* XPath [POM-location]
+*%pom_xpath_remove* [OPTIONS] XPath [XML-file-location]...
+
+OPTIONS
+-------
+
+*-r*::
+Work in recursive mode. That means that given node is also removed from
+all enabled submodules of given POM file(s). Has no effect if the file is
+not Maven POM.
+
+*-f*::
+Do not throw an error when one of the specified files doesn't contain
+given node.
DESCRIPTION
-----------
This macro patches specified POM file removing all XML nodes described
-by the XPath expression.
+by the XPath expression. This also works on attributes and text nodes.
XPath is an expression describing a set of XML nodes to be removed
from the POM file. It must be a properly formated XPath 1.0
expression, as described in http://www.w3.org/TR/xpath/.
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+Maven POM files use specific XML namespace
+`http://maven.apache.org/POM/4.0.0` as default. This namespace needs to
+be explicitly specified in XPath expressions by prefixing all node names
+with *pom* (i.e. *pom:modelVersion*).
+
+Many other XML formats also use namespaces which you have to explicitly
+specify. This script will use the namespace prefix names from the
+*xmlns* declarations in the document's root element. So if the document
+begins with `<root xmlns:my="myurl.com">` you would select the root node
+with XPath expression */my:root*. If the document specifies a default
+namespace (eg `xmlns="myurl.com"`) use the prefix named *default* to
+acces elements in that namespace.
+
+XML location can be either a full path to the XML, or a path to the
+directory containing *pom.xml* or *ivy.xml*. If XML location is not
+given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations.
EXAMPLES
--------
*%pom_xpath_remove pom:project/pom:reporting* - this call removes
reporting section from POM in current working directory.
-BUGS
-----
-POM files use a specific namespace -
-http://maven.apache.org/POM/4.0.0. Currently this namespace needs to
-be explicitly specified in all XPath POM macros by prefixing all node
-names with *pom:*.
+*%pom_xpath_remove \'ivy:configure' build.xml* - this call disables
+loading of ivy configuration in build.xml file. Note the use of `ivy`
+namespace which was declared in the document as
+`xmlns:ivy="antlib:org.apache.ivy.ant"`.
+
AUTHOR
------
@@ -55,6 +81,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_replace*(7),
diff --git a/man/pom_xpath_replace.txt b/man/pom_xpath_replace.txt
index acefa2a..f872db1 100644
--- a/man/pom_xpath_replace.txt
+++ b/man/pom_xpath_replace.txt
@@ -6,11 +6,23 @@ pom_xpath_replace(7)
NAME
----
-pom_xpath_replace - replace XML node from POM file with given XML code
+pom_xpath_replace - replace XML node from XML file with given code
SYNOPSIS
--------
-*%pom_xpath_replace* XPath XML-code [POM-location]
+*%pom_xpath_replace* XPath XML-code [XML-file-location]...
+
+OPTIONS
+-------
+
+*-r*::
+Work in recursive mode. That means that given node is also replaced in
+all enabled submodules of given POM file(s). Has no effect if the file is
+not Maven POM.
+
+*-f*::
+Do not throw an error when one of the specified files doesn't contain
+given node.
DESCRIPTION
-----------
@@ -21,16 +33,24 @@ XPath is an expression describing a set of XML nodes to be removed
from the POM file. It must be a properly formated XPath 1.0
expression, as described in http://www.w3.org/TR/xpath/.
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+Maven POM files use specific XML namespace
+`http://maven.apache.org/POM/4.0.0` as default. This namespace needs to
+be explicitly specified in XPath expressions by prefixing all node names
+with *pom* (i.e. *pom:modelVersion*).
-BUGS
-----
-POM files use a specific namespace -
-http://maven.apache.org/POM/4.0.0. Currently this namespace needs to
-be explicitly specified in all XPath POM macros by prefixing all node
-names with *pom:*.
+Many other XML formats also use namespaces which you have to explicitly
+specify. This script will use the namespace prefix names from the
+*xmlns* declarations in the document's root element. So if the document
+begins with `<root xmlns:my="myurl.com">` you would select the root node
+with XPath expression */my:root*. If the document specifies a default
+namespace (eg `xmlns="myurl.com"`) use the prefix named *default* to
+acces elements in that namespace.
+
+XML location can be either a full path to the XML, or a path to the
+directory containing *pom.xml* or *ivy.xml*. If XML location is not
+given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations.
AUTHOR
------
@@ -50,6 +70,7 @@ SEE ALSO
*pom_remove_dep*(7),
*pom_remove_parent*(7),
*pom_remove_plugin*(7),
+*pom_change_dep*(7),
*pom_set_parent*(7),
*pom_xpath_inject*(7),
*pom_xpath_remove*(7),
diff --git a/man/pom_xpath_set.txt b/man/pom_xpath_set.txt
index ec4d3fb..e3722c8 100644
--- a/man/pom_xpath_set.txt
+++ b/man/pom_xpath_set.txt
@@ -6,32 +6,40 @@ pom_xpath_set(7)
NAME
----
-pom_xpath_set - set text contents of XML node from POM file
+pom_xpath_set - set contents of XML node from XML file
SYNOPSIS
--------
-*%pom_xpath_set* XPath new-contents [POM-location]
+*%pom_xpath_set* XPath new-contents [XML-file-location]
DESCRIPTION
-----------
-This macro patches specified POM file replacing text contents of all
+This macro patches specified POM file replacing contents of all
XML nodes described by the XPath expression with given new text
-content.
+content. This works on both elements and attributes.
XPath is an expression describing a set of XML nodes to be removed
from the POM file. It must be a properly formated XPath 1.0
expression, as described in http://www.w3.org/TR/xpath/.
-POM location can be either a full path to the POM file, or a path to
-the directory containing *pom.xml*. If POM location is not given then
-*pom.xml* from current working directory is used.
+Maven POM files use specific XML namespace
+`http://maven.apache.org/POM/4.0.0` as default. This namespace needs to
+be explicitly specified in XPath expressions by prefixing all node names
+with *pom* (i.e. *pom:modelVersion*).
-BUGS
-----
-POM files use a specific namespace -
-http://maven.apache.org/POM/4.0.0. Currently this namespace needs to
-be explicitly specified in all XPath POM macros by prefixing all node
-names with *pom:*.
+Many other XML formats also use namespaces which you have to explicitly
+specify. This script will use the namespace prefix names from the
+*xmlns* declarations in the document's root element. So if the document
+begins with `<root xmlns:my="myurl.com">` you would select the root node
+with XPath expression */my:root*. If the document specifies a default
+namespace (eg `xmlns="myurl.com"`) use the prefix named *default* to
+acces elements in that namespace.
+
+XML location can be either a full path to the XML, or a path to the
+directory containing *pom.xml* or *ivy.xml*. If XML location is not
+given then *pom.xml* or *ivy.xml* from current working directory is
+used. When both *pom.xml* and *ivy.xml* are present, *pom.xml* is
+processed. You can specify more file locations.
AUTHOR
------
10 years, 1 month
[javapackages/pom_editor.py] [pom_editor] Use namespace prefixes from input file
by Michael Šimáček
commit b8dd278859ee6761967c2aa5fd9c61b2974406de
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Tue Apr 8 13:20:20 2014 +0200
[pom_editor] Use namespace prefixes from input file
java-utils/pom_editor.py | 12 ++++++++-
test/data/pom_editor/build_ns.xml | 10 ++++++++
test/data/pom_editor/want/build_attr_removed.xml | 26 ++++++++++++++++++++++
test/data/pom_editor/want/build_ns_set.xml | 10 ++++++++
test/pom_editor_xml_test.py | 9 +++++++
5 files changed, 65 insertions(+), 2 deletions(-)
---
diff --git a/java-utils/pom_editor.py b/java-utils/pom_editor.py
index e393873..8d9482c 100644
--- a/java-utils/pom_editor.py
+++ b/java-utils/pom_editor.py
@@ -276,7 +276,12 @@ class XmlFile(object):
if not query.startswith('/'):
query = '//' + query
try:
- query_result = self.root.xpath(query, namespaces=self.NSMAP)
+ nsmap = dict(self.NSMAP)
+ nsmap.update(self.root.nsmap)
+ if None in nsmap:
+ nsmap['default'] = nsmap[None]
+ del nsmap[None]
+ query_result = self.root.xpath(query, namespaces=nsmap)
except etree.XPathEvalError as error:
raise PomQueryInvalid("XPath query '{0}': {1}.".format(query,
error.message))
@@ -435,7 +440,10 @@ def pom_xpath_replace(where, xml_string, pom=None):
def pom_xpath_remove(where, pom=None):
"""<XPath> [POM location]"""
for element in pom.xpath_query(where):
- pom.replace_xml(element, etree.Comment(" element removed by maintainer: {0} ".format(where)))
+ if hasattr(element, 'is_attribute') and element.is_attribute:
+ del element.getparent().attrib[element.attrname]
+ else:
+ pom.replace_xml(element, etree.Comment(" element removed by maintainer: {0} ".format(where)))
@macro()
def pom_xpath_set(where, content, pom=None):
diff --git a/test/data/pom_editor/build_ns.xml b/test/data/pom_editor/build_ns.xml
new file mode 100644
index 0000000..f8993a0
--- /dev/null
+++ b/test/data/pom_editor/build_ns.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<project name="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant"
+ xmlns:ivy="antlib:org.apache.ivy.ant"
+ xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
+
+ <target name="ivy-cache">
+ <ivy:cachepath organisation="org.apache.maven" module="maven-ant-tasks" revision="2.1.3"
+ inline="true" conf="master" type="jar" pathid="maven-ant-tasks.classpath"/>
+ </target>
+</project>
diff --git a/test/data/pom_editor/want/build_attr_removed.xml b/test/data/pom_editor/want/build_attr_removed.xml
new file mode 100644
index 0000000..9f928f6
--- /dev/null
+++ b/test/data/pom_editor/want/build_attr_removed.xml
@@ -0,0 +1,26 @@
+<project name="MyProject" default="dist" basedir=".">
+ <property name="src" location="src"/>
+ <property name="build" location="build"/>
+ <property name="dist" location="dist"/>
+
+ <target name="init" description="Create build directory">
+ <mkdir dir="${build}"/>
+ </target>
+
+ <target name="compile" depends="init"
+ description="Compile the source">
+ <javac srcdir="${src}" destdir="${build}"/>
+ </target>
+
+ <target name="dist" depends="compile"
+ description="Generate jar">
+ <mkdir dir="${dist}/lib"/>
+
+ <jar jarfile="${dist}/myproject.jar"/>
+ </target>
+
+ <target name="clean" description="Clean build files">
+ <delete dir="${build}"/>
+ <delete dir="${dist}"/>
+ </target>
+</project>
diff --git a/test/data/pom_editor/want/build_ns_set.xml b/test/data/pom_editor/want/build_ns_set.xml
new file mode 100644
index 0000000..9bb5c26
--- /dev/null
+++ b/test/data/pom_editor/want/build_ns_set.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<project name="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant"
+ xmlns:ivy="antlib:org.apache.ivy.ant"
+ xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">
+
+ <target name="ivy-cache">
+ <ivy:cachepath organisation="org.apache.maven" module="maven-ant-tasks" revision="2.1.3"
+ inline="true" conf="master" type="war" pathid="maven-ant-tasks.classpath"/>
+ </target>
+</project>
diff --git a/test/pom_editor_xml_test.py b/test/pom_editor_xml_test.py
index f1a9be1..bb21967 100644
--- a/test/pom_editor_xml_test.py
+++ b/test/pom_editor_xml_test.py
@@ -38,6 +38,15 @@ class TestGeneric(WorkdirTestCase):
self.assertEqual(0, return_value, stderr)
self.assertEqual('', report, report)
+ def test_namespace(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_set "target/ivy:cachepath/@type" 'war' build.xml""",
+ 'build_ns.xml', 'build_ns_set.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+
+
class TestIvy(WorkdirTestCase):
def test_inject(self):
return_value, stderr, report = exec_pom_macro_simple(\
10 years, 1 month
[javapackages/pom_editor.py] [pom_editor] tests for generic xml files and ivy files
by Michael Šimáček
commit 6ab2f267cd573c656afa311648319a8ca3afb79e
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Fri Apr 4 18:59:35 2014 +0200
[pom_editor] tests for generic xml files and ivy files
.../data/pom_editor/want/simple_ivy_remove_rev.xml | 11 +++
test/pom_editor_xml_test.py | 89 ++++++++++++++++++++
2 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/test/data/pom_editor/want/simple_ivy_remove_rev.xml b/test/data/pom_editor/want/simple_ivy_remove_rev.xml
new file mode 100644
index 0000000..82a651d
--- /dev/null
+++ b/test/data/pom_editor/want/simple_ivy_remove_rev.xml
@@ -0,0 +1,11 @@
+<ivy-module version="2.0">
+ <info organisation="org.apache.lucene" module="benchmark"/>
+ <dependencies>
+ <dependency org="org.apache.commons" name="commons-compress" rev="${/org.apache.commons/commons-compress}" transitive="false"/>
+ <dependency org="xerces" name="xercesImpl" rev="${/xerces/xercesImpl}" transitive="false"/>
+ <dependency org="net.sourceforge.nekohtml" name="nekohtml" transitive="false"/>
+ <dependency org="com.ibm.icu" name="icu4j" rev="${/com.ibm.icu/icu4j}" transitive="false"/>
+ <dependency org="com.spatial4j" name="spatial4j" rev="${/com.spatial4j/spatial4j}" transitive="false"/>
+ <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
+ </dependencies>
+</ivy-module>
diff --git a/test/pom_editor_xml_test.py b/test/pom_editor_xml_test.py
new file mode 100644
index 0000000..f1a9be1
--- /dev/null
+++ b/test/pom_editor_xml_test.py
@@ -0,0 +1,89 @@
+from test_common import exec_pom_macro_simple, WorkdirTestCase
+
+class TestGeneric(WorkdirTestCase):
+ def test_inject(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_inject "/project/target[@name='init']" '
+ <mkdir dir="lib"/>
+ ' build.xml""",
+ 'build.xml', 'build_with_lib.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_remove(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_remove "/project/target[@name='dist']" build.xml""",
+ 'build.xml', 'build_without_dist.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_set(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_set "target[@name='clean']" '<echo/>' build.xml""",
+ 'build.xml', 'build_set.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_set_attribute(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_set "jar/@jarfile" '${dist}/other.jar' build.xml""",
+ 'build.xml', 'build_attr.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_remove_attribute(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_remove "jar/@basedir" build.xml""",
+ 'build.xml', 'build_attr_removed.xml', filename='build.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+class TestIvy(WorkdirTestCase):
+ def test_inject(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_xpath_inject dependencies '
+ <dependency org="foo" name="bar" transitive="false"/>
+ '""",
+ 'simple_ivy.xml', 'simple_ivy_added_foo_bar.xml', filename='ivy.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_unsupported(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ "%pom_remove_parent",
+ "simple_ivy.xml", filename='ivy.xml')
+ self.assertIn('Operation not supported', stderr)
+ self.assertNotEqual(0, return_value)
+ self.assertEqual('', report)
+
+ def test_add_dep(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ """%pom_add_dep 'org.eclipse.jetty.orbit:javax.servlet:3.1:servlet->default:false' '
+ <artifact name="javax.servlet" type="orbit" ext="jar"/>
+ '""",
+ 'simple_ivy.xml', 'simple_ivy_added_orbit.xml', filename='ivy.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_remove_dep(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ "%pom_remove_dep 'xerces:'",
+ 'simple_ivy.xml', 'simple_ivy_removed_xerces.xml', filename='ivy.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_change_dep(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ "%pom_change_dep ':xercesImpl' ':xerces'",
+ 'simple_ivy.xml', 'simple_ivy_xerces_aid.xml', filename='ivy.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+ def test_remove_rev(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ "%pom_change_dep ':nekohtml' '::-'",
+ 'simple_ivy.xml', 'simple_ivy_remove_rev.xml', filename='ivy.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
+
10 years, 1 month
[javapackages/pom_editor.py] [pom_editor] allow removing pars with pom_change_dep
by Michael Šimáček
commit 4b01f41fd7301e31ea9a8e29ee39b373a78a0ffb
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Fri Apr 4 18:58:12 2014 +0200
[pom_editor] allow removing pars with pom_change_dep
java-utils/pom_editor.py | 7 +++-
test/data/pom_editor/want/simple_removed_scope.xml | 36 ++++++++++++++++++++
test/pom_editor_artifact_test.py | 7 ++++
3 files changed, 49 insertions(+), 1 deletions(-)
---
diff --git a/java-utils/pom_editor.py b/java-utils/pom_editor.py
index 92c11ec..e393873 100644
--- a/java-utils/pom_editor.py
+++ b/java-utils/pom_editor.py
@@ -53,6 +53,11 @@ def MetaArtifact(specification, attributes=False, **defaults):
if value:
self[key] = value
+ def remove_items(self, fn):
+ for prop, val in dict(self.values).iteritems():
+ if fn(val):
+ del self.values[prop]
+
def __getitem__(self, key):
return self.values.get(key, '')
@@ -532,8 +537,8 @@ def pom_change_dep(old, new, pom=None, xml_string=''):
for element in elements:
new_artifact = pom.create_artifact().from_xml(element)
new_artifact.update(pom.create_artifact().from_mvn_str(new))
+ new_artifact.remove_items(lambda x: x == '-')
new_xml = new_artifact.get_xml(extra=xml_string)
- print etree.tostring(new_xml)
pom.replace_xml_content(element, new_xml, replace_attrib=True)
except PomQueryNoMatch:
raise PomQueryNoMatch("Dependency '{0}' not found.".format(old))
diff --git a/test/data/pom_editor/want/simple_removed_scope.xml b/test/data/pom_editor/want/simple_removed_scope.xml
new file mode 100644
index 0000000..89d826f
--- /dev/null
+++ b/test/data/pom_editor/want/simple_removed_scope.xml
@@ -0,0 +1,36 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-parent</artifactId>
+ <version>17</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ <name>Commons Lang</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-ioX</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>1.2</version>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/test/pom_editor_artifact_test.py b/test/pom_editor_artifact_test.py
index c5069d3..5973878 100644
--- a/test/pom_editor_artifact_test.py
+++ b/test/pom_editor_artifact_test.py
@@ -72,3 +72,10 @@ class TestPomChange(WorkdirTestCase):
self.assertEqual(0, return_value, stderr)
self.assertEqual('', report, report)
+ def test_remove_scope(self):
+ return_value, stderr, report = exec_pom_macro_simple(\
+ "%pom_change_dep :::test :::-",
+ 'simple_pom.xml', 'simple_removed_scope.xml')
+ self.assertEqual(0, return_value, stderr)
+ self.assertEqual('', report, report)
+
10 years, 1 month
[javapackages/pom_editor.py] [pom_editor] Implement dependency handling macros for Ivy
by Michael Šimáček
commit b257c9bfa4a42457baec136ee2d92175e00e3ab2
Author: Michael Simacek <msimacek(a)redhat.com>
Date: Fri Apr 4 17:46:51 2014 +0200
[pom_editor] Implement dependency handling macros for Ivy
java-utils/pom_editor.py | 242 ++++++++++++--------
.../pom_editor/want/simple_ivy_added_orbit.xml | 16 ++
.../pom_editor/want/simple_ivy_removed_xerces.xml | 10 +
.../data/pom_editor/want/simple_ivy_xerces_aid.xml | 11 +
test/data/pom_macros/pom_xpath_set.xml-want | 6 +-
test/data/pom_macros/pom_xpath_set2.xml-want | 6 +-
.../pom_macros/pom_xpath_set_multiple.xml-want | 24 +--
test/data/pom_macros/pom_xpath_set_nons.xml-want | 6 +-
8 files changed, 189 insertions(+), 132 deletions(-)
---
diff --git a/java-utils/pom_editor.py b/java-utils/pom_editor.py
index c79a3e4..92c11ec 100644
--- a/java-utils/pom_editor.py
+++ b/java-utils/pom_editor.py
@@ -13,10 +13,15 @@ from textwrap import dedent
macros = {}
-BEGIN_COMMENT = "<!-- begin of code added by maintainer -->"
-END_COMMENT = "<!-- end of code added by maintainer -->"
-COMMENT = (BEGIN_COMMENT, END_COMMENT)
+BEGIN_COMMENT = etree.Comment(' begin of code added by maintainer ')
+END_COMMENT = etree.Comment(' end of code added by maintainer ')
+def annotate(elements):
+ if isinstance(elements, etree._Element):
+ elements[:0] = [BEGIN_COMMENT]
+ elements.append(END_COMMENT)
+ return elements
+ return [BEGIN_COMMENT] + elements + [END_COMMENT]
class PomException(Exception):
pass
@@ -27,13 +32,11 @@ class PomQueryAmbigous(PomException):
class PomQueryInvalid(PomException):
pass
-def MetaArtifact(specification, **defaults):
+def MetaArtifact(specification, attributes=False, **defaults):
parts = specification.split(':')
class Artifact(object):
def __init__(self, **values):
- self.values = dict.fromkeys(parts, '')
- self.values.update(defaults)
- self.values.update(values)
+ self.values = values
@classmethod
def from_mvn_str(cls, string):
@@ -43,6 +46,22 @@ def MetaArtifact(specification, **defaults):
values[key] = value
return cls(**values)
+ def update(self, artifact):
+ for key, value in artifact.values.iteritems():
+ if key not in parts:
+ raise KeyError(key + ' not defined')
+ if value:
+ self[key] = value
+
+ def __getitem__(self, key):
+ return self.values.get(key, '')
+
+ def __setitem__(self, key, value):
+ if key not in parts:
+ raise KeyError(key + ' not defined')
+ self.values[key] = value
+
+ class NodeArtifact(Artifact):
@classmethod
def from_xml(cls, element):
values = {}
@@ -52,39 +71,51 @@ def MetaArtifact(specification, **defaults):
values[part] = subelement.text.strip()
return cls(**values)
- def get_xml(self):
- xml = ''
+ def get_xml(self, node='artifact', extra=''):
+ xml = ['<{0}>'.format(node)]
for key in parts:
- value = self.values[key]
+ value = self.values.get(key, defaults.get(key, ''))
if value:
- xml += "<{0}>{1}</{0}>".format(key, value)
- return xml
+ xml.append("<{0}>{1}</{0}>".format(key, value))
+ xml.append(extra)
+ xml.append('</{0}>'.format(node))
+ return etree.fromstring('\n'.join(xml))
def get_xpath_condition(self):
expr = "normalize-space(pom:{0})='{1}'"
conditions = []
for key in parts:
- value = self.values[key]
+ value = self.values.get(key, '')
if value and value != '*':
conditions.append(expr.format(key, value))
return ' and '.join(conditions) if conditions else 'true()'
- def update(self, artifact):
- for key, value in artifact.values.iteritems():
- if key not in parts:
- raise KeyError(key + ' not defined')
- if value:
- self[key] = value
+ class AttributeArtifact(Artifact):
+ @classmethod
+ def from_xml(cls, element):
+ values = dict([(key, val) for key, val
+ in element.attrib.iteritems() if key in parts])
+ return cls(**values)
- def __getitem__(self, key):
- return self.values[key]
+ def get_xml(self, node='artifact', extra=''):
+ xml = []
+ for key in parts:
+ value = self.values.get(key, defaults.get(key, ''))
+ if value:
+ xml.append('{0}="{1}"'.format(key, value))
+ return etree.fromstring('<{0} {1}>{2}</{0}>'.format(node,
+ ' '.join(xml), extra))
- def __setitem__(self, key, value):
- if key not in parts:
- raise KeyError(key + ' not defined')
- self.values[key] = value
+ def get_xpath_condition(self):
+ expr = "@{0}='{1}'"
+ conditions = []
+ for key in parts:
+ value = self.values.get(key, '')
+ if value and value != '*':
+ conditions.append(expr.format(key, value))
+ return ' and '.join(conditions) if conditions else 'true()'
- return Artifact
+ return AttributeArtifact if attributes else NodeArtifact
def find_xml(xmlpath):
if path.isfile(xmlpath):
@@ -134,6 +165,8 @@ def parse_args(function, args):
option_parser.add_option('-f', '--force', action="store_true")
options, arguments = option_parser.parse_args(list(args))
min_arg_count = len(arglist) - len(defaults)
+ if len(arguments) < min_arg_count:
+ raise PomException('Too few arguments given to {0}'.format(function.__name__))
fnargs = dict(zip(arglist, arguments[:min_arg_count]))
poms = arguments[min_arg_count:]
if len(defaults or [] > 1) and poms:
@@ -175,33 +208,34 @@ class XmlFile(object):
shutil.move(self.xmlpath, origfile)
self.write(self.xmlpath)
- def inject_xml(self, parent, content, comment=''):
- content = self.subtree_from_string(content, comment)
+ def inject_xml(self, parent, content):
items = len(content)
parent[:0] = content
self.reformat(parent, parent[:items])
- def replace_xml(self, replaced, content='', comment=''):
- content = self.subtree_from_string(content, comment)
+ def replace_xml(self, replaced, content):
parent = replaced.getparent()
- parent.text = content.text
if not isinstance(replaced, etree._Element):
parent.extend(content)
- else:
- idx = parent.index(replaced)
- items = len(content)
- del parent[idx]
- for i, element in enumerate(content):
- parent.insert(idx + i, element)
- self.reformat(parent, parent[idx: idx + items])
-
- def replace_xml_content(self, parent, content, comment=''):
+ if content.tag is not etree.Comment:
+ parent.text = content.text
+ return
+ idx = parent.index(replaced)
+ items = len(content)
+ del parent[idx]
+ for i, element in enumerate(content):
+ parent.insert(idx + i, element)
+ self.reformat(parent, parent[idx: idx + items])
+
+ def replace_xml_content(self, parent, content, replace_attrib=False):
if hasattr(parent, 'is_attribute'):
if parent.is_attribute:
- parent.getparent().attrib[parent.attrname] = content
+ parent.getparent().attrib[parent.attrname] = content.text
return
- content = self.subtree_from_string(content, comment)
parent[:] = content
+ if replace_attrib and hasattr(content, 'attrib'):
+ parent.attrib.clear()
+ parent.attrib.update(content.attrib)
parent.text = content.text
self.reformat(parent, parent)
@@ -247,13 +281,8 @@ class XmlFile(object):
(Did you forget to specify 'pom:' namespace?)""").format(query))
return query_result
- def subtree_from_string(self, xml_string, comment=('', ''), root='root'):
- if type(comment) == tuple:
- begin, end = comment
- else:
- begin, end = comment, ''
- document = "<{root} {ns}>{begin}{0}{end}</{root}>".format(xml_string,
- root=root, ns=self.XMLNS, begin=begin, end=end)
+ def subtree_from_string(self, xml_string):
+ document = "<root {ns}>{0}</root>".format(xml_string, ns=self.XMLNS)
try:
tree = etree.fromstring(document)
except etree.XMLSyntaxError as error:
@@ -276,6 +305,13 @@ class XmlFile(object):
return self.make_path(child, elements[1:])
return node
+ def inject_artifact(self, where, node_name, artifact, aux_content=''):
+ path_parts = [part for part in where.split('/') if part]
+ parent = self.make_path(self.root, path_parts)
+ content = annotate([artifact.get_xml(node_name, aux_content)])
+ self.inject_xml(parent, content)
+
+
class Pom(XmlFile):
default_name = 'pom.xml'
NSMAP = {'pom': 'http://maven.apache.org/POM/4.0.0',
@@ -285,6 +321,8 @@ class Pom(XmlFile):
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'
'xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 '
'http://maven.apache.org/xsd/maven-4.0.0.xsd"')
+ DEPENDENCY_NODE = 'pom:dependency'
+ DEPENDENCIES_NODE = 'pom:dependencies'
def __init__(self, pompath):
super(Pom, self).__init__(pompath)
@@ -295,22 +333,36 @@ class Pom(XmlFile):
('<project {ns}>').format(ns=self.XMLNS), pomfile.read())
self.root = etree.fromstring(pom)
+ @classmethod
+ def create_artifact(cls, *args, **kwargs):
+ plugin = kwargs.get('plugin', False)
+ if 'plugin' in kwargs:
+ del kwargs['plugin']
+ if plugin:
+ pom_plugin_spec = 'groupId:artifactId:version'
+ ArtifactClass = MetaArtifact(pom_plugin_spec, version='any',
+ groupId='org.apache.maven.plugins')
+ else:
+ pom_dependency_spec = 'groupId:artifactId:version:scope'
+ ArtifactClass = MetaArtifact(pom_dependency_spec, version='any')
+ return ArtifactClass(*args, **kwargs)
+
+
+class Ivy(XmlFile):
+ DEPENDENCY_NODE = 'dependency'
+ DEPENDENCIES_NODE = 'dependencies'
+
+ def __init__(self, pompath):
+ super(Ivy, self).__init__(pompath)
+
+ @classmethod
+ def create_artifact(cls, *args, **kwargs):
+ if 'plugin' in kwargs:
+ del kwargs['plugin']
+ ivy_dependency_spec = 'org:name:rev:conf:transitive'
+ IvyDependency = MetaArtifact(ivy_dependency_spec, attributes=True)
+ return IvyDependency(*args, **kwargs)
- def inject_artifact(self, where, node_name, artifact, aux_content=''):
- path_parts = [part for part in where.split('/') if part]
- parent = self.make_path(self.root, path_parts)
- self.inject_xml(parent, "<{name}>{content} {aux}</{name}>"\
- .format(name=node_name,
- content=artifact.get_xml(),
- aux=aux_content),
- comment=COMMENT)
-
-artifact_spec = 'groupId:artifactId:version'
-artifact_spec_scoped = artifact_spec + ':scope'
-VersionedArtifact = MetaArtifact(artifact_spec)
-DefaultVersionedArtifact = MetaArtifact(artifact_spec, version='any')
-ScopedArtifact = MetaArtifact(artifact_spec_scoped)
-DefaultScopedArtifact = MetaArtifact(artifact_spec_scoped, version='any')
def create_xml_object(filepath):
tree = etree.parse(filepath)
@@ -319,7 +371,7 @@ def create_xml_object(filepath):
if root.xpath(pom_detect, namespaces=Pom.NSMAP):
return Pom(filepath)
if root.tag == 'ivy-module':
- pass
+ return Ivy(filepath)
return XmlFile(filepath)
def macro(types=(XmlFile,)):
@@ -339,7 +391,7 @@ def macro(types=(XmlFile,)):
for xmlpath in xmlpaths:
try:
xml = create_xml_object(xmlpath)
- if not any(isinstance(xml, allowed) for allowed in types):
+ if not any([isinstance(xml, allowed) for allowed in types]):
raise PomException('Operation not supported on '
'given file type.')
fnargs['pom'] = xml
@@ -350,7 +402,7 @@ def macro(types=(XmlFile,)):
if matches == 0 and not options.force:
raise exception
- except (PomException, etree.XMLSyntaxError, IOError, TypeError) as exception:
+ except (PomException, etree.XMLSyntaxError, IOError) as exception:
if xmlpath:
print >> sys.stderr, "Error in processing {0}".format(xmlpath)
print >> sys.stderr, exception.message
@@ -366,37 +418,35 @@ def macro(types=(XmlFile,)):
def pom_xpath_inject(where, xml_string, pom=None):
"""<XPath> [XML code] [POM location]"""
for element in pom.xpath_query(where):
- pom.inject_xml(element, xml_string, comment=COMMENT)
+ pom.inject_xml(element, annotate(pom.subtree_from_string(xml_string)))
@macro()
def pom_xpath_replace(where, xml_string, pom=None):
"""<XPath> <XML code> [POM location]"""
for element in pom.xpath_query(where):
- pom.replace_xml(element, xml_string, comment=COMMENT)
+ pom.replace_xml(element, annotate(pom.subtree_from_string(xml_string)))
@macro()
def pom_xpath_remove(where, pom=None):
"""<XPath> [POM location]"""
for element in pom.xpath_query(where):
- pom.replace_xml(element,
- comment="<!-- element removed by maintainer: {0} -->".format(where))
+ pom.replace_xml(element, etree.Comment(" element removed by maintainer: {0} ".format(where)))
@macro()
def pom_xpath_set(where, content, pom=None):
"""<XPath> <new contents> [POM location]"""
for element in pom.xpath_query(where):
- pom.replace_xml_content(element, content, comment=COMMENT)
+ pom.replace_xml_content(element, pom.subtree_from_string(content))
-@macro()
+@macro(types=(Pom, Ivy))
def pom_remove_dep(dep, pom=None):
"""[groupId]:[artifactId] [POM location]"""
try:
- artifact = VersionedArtifact.from_mvn_str(dep)
- xpath = "//pom:dependency[{0}]".format(artifact.get_xpath_condition())
+ artifact = pom.create_artifact().from_mvn_str(dep)
+ xpath = "//{0}[{1}]".format(pom.DEPENDENCY_NODE, artifact.get_xpath_condition())
elements = pom.xpath_query(xpath)
for element in elements:
- pom.replace_xml(element,
- comment="<!-- dependency removed by maintainer: {0} -->".format(dep))
+ pom.replace_xml(element, etree.Comment(" dependency removed by maintainer: {0} ".format(dep)))
except PomQueryNoMatch:
raise PomQueryNoMatch("Dependency '{0}' not found.".format(dep))
@@ -404,12 +454,11 @@ def pom_remove_dep(dep, pom=None):
def pom_remove_plugin(plugin, pom=None):
"""[groupId]:[artifactId] [POM location]"""
try:
- artifact = VersionedArtifact.from_mvn_str(plugin)
+ artifact = pom.create_artifact(plugin=True).from_mvn_str(plugin)
xpath = "//pom:plugin[{0}]".format(artifact.get_xpath_condition())
elements = pom.xpath_query(xpath)
for element in elements:
- pom.replace_xml(element,
- comment="<!-- plugin removed by maintainer: {0} -->".format(plugin))
+ pom.replace_xml(element, etree.Comment(" plugin removed by maintainer: {0} ".format(plugin)))
except PomQueryNoMatch:
raise PomQueryNoMatch("Plugin '{0}' not found.".format(plugin))
@@ -420,8 +469,7 @@ def pom_disable_module(module, pom=None):
xpath = "//pom:module[normalize-space(text())='{0}']".format(module)
elements = pom.xpath_query(xpath)
for element in elements:
- pom.replace_xml(element,
- comment="<!-- module removed by maintainer: {0} -->".format(module))
+ pom.replace_xml(element, etree.Comment(" module removed by maintainer: {0} ".format(module)))
except PomQueryNoMatch:
raise PomQueryNoMatch("Module '{0}' not found.".format(module))
@@ -430,7 +478,7 @@ def pom_add_parent(parent, pom=None):
"""groupId:artifactId[:version] [POM location]"""
if pom.root.find('pom:parent', namespaces=Pom.NSMAP) is not None:
raise PomException("POM already has a parent.")
- artifact = DefaultVersionedArtifact.from_mvn_str(parent)
+ artifact = pom.create_artifact().from_mvn_str(parent)
pom.inject_artifact('', 'parent', artifact)
@macro(types=(Pom,))
@@ -438,7 +486,7 @@ def pom_remove_parent(pom=None):
"""[POM location]"""
try:
pom.replace_xml(pom.xpath_query_element("/pom:project/pom:parent"),
- comment="<!-- parent POM reference removed by maintainer -->")
+ etree.Comment(" parent POM reference removed by maintainer --> "))
except PomQueryNoMatch:
raise PomQueryNoMatch("POM doesn't specify parent.")
@@ -446,31 +494,30 @@ def pom_remove_parent(pom=None):
def pom_set_parent(parent, pom=None):
"""groupId:artifactId[:version] [POM location]"""
try:
- artifact = DefaultVersionedArtifact.from_mvn_str(parent)
+ artifact = pom.create_artifact().from_mvn_str(parent)
element = pom.xpath_query_element("/pom:project/pom:parent")
pom.replace_xml_content(element, artifact.get_xml())
except PomQueryNoMatch:
raise PomQueryNoMatch("POM doesn't specify parent.")
-@macro()
+@macro(types=(Pom, Ivy))
def pom_add_dep(dep, pom=None, xml_string=''):
"""groupId:artifactId[:version[:scope]] [POM location] [extra XML]"""
- artifact = DefaultScopedArtifact.from_mvn_str(dep)
- pom.inject_artifact('pom:dependencies', 'dependency', artifact,
+ artifact = pom.create_artifact().from_mvn_str(dep)
+ pom.inject_artifact(pom.DEPENDENCIES_NODE, 'dependency', artifact,
xml_string)
@macro(types=(Pom,))
def pom_add_dep_mgmt(dep, pom=None, xml_string=''):
"""groupId:artifactId[:version[:scope]] [POM location] [extra XML]"""
- artifact = DefaultScopedArtifact.from_mvn_str(dep)
+ artifact = pom.create_artifact().from_mvn_str(dep)
pom.inject_artifact('pom:dependencyManagement/pom:dependencies',
'dependency', artifact, xml_string)
@macro(types=(Pom,))
def pom_add_plugin(plugin, pom=None, xml_string=''):
"""groupId:artifactId[:version] [POM location] [extra XML]"""
- artifact = MetaArtifact(artifact_spec, version='any',
- groupId='org.apache.maven.plugins').from_mvn_str(plugin)
+ artifact = pom.create_artifact(plugin=True).from_mvn_str(plugin)
pom.inject_artifact('pom:build/pom:plugins', 'plugin', artifact,
xml_string)
@@ -479,14 +526,15 @@ def pom_change_dep(old, new, pom=None, xml_string=''):
"""groupId:artifactId[:version] groupId:artifactId[:version[:scope]]
[POM location] [extra XML]"""
try:
- old_artifact = VersionedArtifact.from_mvn_str(old)
- xpath = "//pom:dependency[{0}]".format(old_artifact.get_xpath_condition())
+ old_artifact = pom.create_artifact().from_mvn_str(old)
+ xpath = "//{0}[{1}]".format(pom.DEPENDENCY_NODE, old_artifact.get_xpath_condition())
elements = pom.xpath_query(xpath)
for element in elements:
- new_artifact = DefaultScopedArtifact.from_xml(element)
- new_artifact.update(ScopedArtifact.from_mvn_str(new))
- new_xml = new_artifact.get_xml() + xml_string
- pom.replace_xml_content(element, new_xml)
+ new_artifact = pom.create_artifact().from_xml(element)
+ new_artifact.update(pom.create_artifact().from_mvn_str(new))
+ new_xml = new_artifact.get_xml(extra=xml_string)
+ print etree.tostring(new_xml)
+ pom.replace_xml_content(element, new_xml, replace_attrib=True)
except PomQueryNoMatch:
raise PomQueryNoMatch("Dependency '{0}' not found.".format(old))
diff --git a/test/data/pom_editor/want/simple_ivy_added_orbit.xml b/test/data/pom_editor/want/simple_ivy_added_orbit.xml
new file mode 100644
index 0000000..9ebe328
--- /dev/null
+++ b/test/data/pom_editor/want/simple_ivy_added_orbit.xml
@@ -0,0 +1,16 @@
+<ivy-module version="2.0">
+ <info organisation="org.apache.lucene" module="benchmark"/>
+ <dependencies>
+ <dependency org="org.eclipse.jetty.orbit" name="javax.servlet"
+ rev="3.1" transitive="false" conf="servlet->default">
+ <artifact name="javax.servlet" type="orbit" ext="jar"/>
+ </dependency>
+ <dependency org="org.apache.commons" name="commons-compress" rev="${/org.apache.commons/commons-compress}" transitive="false"/>
+ <dependency org="xerces" name="xercesImpl" rev="${/xerces/xercesImpl}" transitive="false"/>
+ <dependency org="net.sourceforge.nekohtml" name="nekohtml" rev="${/net.sourceforge.nekohtml/nekohtml}" transitive="false"/>
+ <dependency org="com.ibm.icu" name="icu4j" rev="${/com.ibm.icu/icu4j}" transitive="false"/>
+ <dependency org="com.spatial4j" name="spatial4j" rev="${/com.spatial4j/spatial4j}" transitive="false"/>
+ <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
+
+ </dependencies>
+</ivy-module>
diff --git a/test/data/pom_editor/want/simple_ivy_removed_xerces.xml b/test/data/pom_editor/want/simple_ivy_removed_xerces.xml
new file mode 100644
index 0000000..5783cc4
--- /dev/null
+++ b/test/data/pom_editor/want/simple_ivy_removed_xerces.xml
@@ -0,0 +1,10 @@
+<ivy-module version="2.0">
+ <info organisation="org.apache.lucene" module="benchmark"/>
+ <dependencies>
+ <dependency org="org.apache.commons" name="commons-compress" rev="${/org.apache.commons/commons-compress}" transitive="false"/>
+ <dependency org="net.sourceforge.nekohtml" name="nekohtml" rev="${/net.sourceforge.nekohtml/nekohtml}" transitive="false"/>
+ <dependency org="com.ibm.icu" name="icu4j" rev="${/com.ibm.icu/icu4j}" transitive="false"/>
+ <dependency org="com.spatial4j" name="spatial4j" rev="${/com.spatial4j/spatial4j}" transitive="false"/>
+ <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
+ </dependencies>
+</ivy-module>
diff --git a/test/data/pom_editor/want/simple_ivy_xerces_aid.xml b/test/data/pom_editor/want/simple_ivy_xerces_aid.xml
new file mode 100644
index 0000000..31252df
--- /dev/null
+++ b/test/data/pom_editor/want/simple_ivy_xerces_aid.xml
@@ -0,0 +1,11 @@
+<ivy-module version="2.0">
+ <info organisation="org.apache.lucene" module="benchmark"/>
+ <dependencies>
+ <dependency org="org.apache.commons" name="commons-compress" rev="${/org.apache.commons/commons-compress}" transitive="false"/>
+ <dependency org="xerces" name="xerces" rev="${/xerces/xercesImpl}" transitive="false"/>
+ <dependency org="net.sourceforge.nekohtml" name="nekohtml" rev="${/net.sourceforge.nekohtml/nekohtml}" transitive="false"/>
+ <dependency org="com.ibm.icu" name="icu4j" rev="${/com.ibm.icu/icu4j}" transitive="false"/>
+ <dependency org="com.spatial4j" name="spatial4j" rev="${/com.spatial4j/spatial4j}" transitive="false"/>
+ <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
+ </dependencies>
+</ivy-module>
diff --git a/test/data/pom_macros/pom_xpath_set.xml-want b/test/data/pom_macros/pom_xpath_set.xml-want
index 36047f2..c9981d1 100644
--- a/test/data/pom_macros/pom_xpath_set.xml-want
+++ b/test/data/pom_macros/pom_xpath_set.xml-want
@@ -5,11 +5,7 @@
<version>2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>
- <!-- begin of code added by maintainer -->
- commons
-
- <!-- end of code added by maintainer --></groupId>
+ <groupId>commons</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<name>Commons Lang</name>
diff --git a/test/data/pom_macros/pom_xpath_set2.xml-want b/test/data/pom_macros/pom_xpath_set2.xml-want
index 958dd01..93cd354 100644
--- a/test/data/pom_macros/pom_xpath_set2.xml-want
+++ b/test/data/pom_macros/pom_xpath_set2.xml-want
@@ -29,11 +29,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
- <version>
- <!-- begin of code added by maintainer -->
- 2
-
- <!-- end of code added by maintainer --></version>
+ <version>2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
diff --git a/test/data/pom_macros/pom_xpath_set_multiple.xml-want b/test/data/pom_macros/pom_xpath_set_multiple.xml-want
index aa2c5bd..10d28d1 100644
--- a/test/data/pom_macros/pom_xpath_set_multiple.xml-want
+++ b/test/data/pom_macros/pom_xpath_set_multiple.xml-want
@@ -1,40 +1,24 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
- <groupId>
- <!-- begin of code added by maintainer -->
- commons
- <!-- end of code added by maintainer -->
- </groupId>
+ <groupId>commons</groupId>
<artifactId>commons-parent</artifactId>
<version>2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
- <groupId>
- <!-- begin of code added by maintainer -->
- commons
- <!-- end of code added by maintainer -->
- </groupId>
+ <groupId>commons</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
<name>Commons Lang</name>
<dependencies>
<dependency>
- <groupId>
- <!-- begin of code added by maintainer -->
- commons
- <!-- end of code added by maintainer -->
- </groupId>
+ <groupId>commons</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
- <groupId>
- <!-- begin of code added by maintainer -->
- commons
- <!-- end of code added by maintainer -->
- </groupId>
+ <groupId>commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.2</version>
</dependency>
diff --git a/test/data/pom_macros/pom_xpath_set_nons.xml-want b/test/data/pom_macros/pom_xpath_set_nons.xml-want
index e75cc01..00295fd 100644
--- a/test/data/pom_macros/pom_xpath_set_nons.xml-want
+++ b/test/data/pom_macros/pom_xpath_set_nons.xml-want
@@ -1,11 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.commons</groupId>
- <artifactId>
- <!-- begin of code added by maintainer -->
- a-Id
- <!-- end of code added by maintainer -->
- </artifactId>
+ <artifactId>a-Id</artifactId>
<version>2.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
10 years, 1 month
[javapackages/new-metadata-experiment] [artifact] Add partial support for compatVersions
by Stanislav Ochotnicky
commit adc83139613a8ccdd98775a92a68e94238e63f2f
Author: Stanislav Ochotnicky <sochotnicky(a)redhat.com>
Date: Fri Apr 11 16:06:27 2014 +0200
[artifact] Add partial support for compatVersions
Not all methods support this. In some cases it's probably not needed/wanted
anyway
python/javapackages/artifact.py | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/python/javapackages/artifact.py b/python/javapackages/artifact.py
index 0fa4bfb..6c9a57a 100644
--- a/python/javapackages/artifact.py
+++ b/python/javapackages/artifact.py
@@ -53,13 +53,15 @@ class Artifact(object):
"""
def __init__(self, groupId, artifactId, extension="",
- classifier="", version="", namespace=""):
+ classifier="", version="", namespace="",
+ compatVersions=[]):
self.groupId = groupId.strip()
self.artifactId = artifactId.strip()
self.extension = extension.strip()
self.classifier = classifier.strip()
self.version = version.strip()
self.namespace = namespace.strip()
+ self.compatVersions = compatVersions
def __unicode__(self):
return u"{gid}:{aid}:{ext}:{cls}:{ver}".format(gid=self.groupId,
@@ -263,8 +265,14 @@ class Artifact(object):
if metadata.namespace:
namespace = metadata.namespace.strip()
+ compatVersions = []
+ if metadata.compatVersions:
+ for cv in metadata.compatVersions.version:
+ compatVersions.append(cv)
+
return cls(groupId, artifactId, extension,
- classifier, version, namespace)
+ classifier, version, namespace,
+ compatVersions)
10 years, 1 month