Try to procect builddep MOJO against patological cases

This commit is contained in:
Mikolaj Izdebski 2015-11-26 14:28:54 +01:00
parent 240d153b6f
commit b666fb6f1e
3 changed files with 62 additions and 3 deletions

View File

@ -1,7 +1,7 @@
From a2f918fe86c91e1a76d198e824118d5ba474808c Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Wed, 28 Oct 2015 22:26:44 +0100
Subject: [PATCH] Copy core dependencies to lib/core in assembly
Subject: [PATCH 1/2] Copy core dependencies to lib/core in assembly
---
xmvn-core/pom.xml | 15 +++++++++++++++
@ -34,5 +34,5 @@ index e792f6a..b0ef6b5 100644
</build>
</project>
--
2.4.3
2.5.0

View File

@ -0,0 +1,54 @@
From 3b214255464d5baca5ee26a897cd9afca53e52c3 Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Thu, 26 Nov 2015 14:18:48 +0100
Subject: [PATCH 2/2] Try to procect builddep MOJO against patological cases
- Clone model before processing it to avoid
UnsupportedOperationException (rhbz#1276729).
- Guard against NullPointerException.
- Inject a deep copy of resolutions to avoid
ConcurrentModificationException.
---
.../xmvn/connector/aether/XMvnMojoExecutionListener.java | 2 +-
.../src/main/java/org/fedoraproject/xmvn/mojo/BuilddepMojo.java | 5 ++++-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMojoExecutionListener.java b/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMojoExecutionListener.java
index 16f30db..7adfe44 100644
--- a/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMojoExecutionListener.java
+++ b/xmvn-connector-aether/src/main/java/org/fedoraproject/xmvn/connector/aether/XMvnMojoExecutionListener.java
@@ -222,7 +222,7 @@ public class XMvnMojoExecutionListener
for ( BeanProperty<Object> property : new BeanProperties( mojo.getClass() ) )
{
if ( property.getName().equals( "resolutions" ) )
- property.set( mojo, Collections.unmodifiableList( resolutions ) );
+ property.set( mojo, Collections.unmodifiableList( new ArrayList<>( resolutions ) ) );
}
}
}
diff --git a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/BuilddepMojo.java b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/BuilddepMojo.java
index 8bbdf5f..dd6a8f5 100644
--- a/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/BuilddepMojo.java
+++ b/xmvn-mojo/src/main/java/org/fedoraproject/xmvn/mojo/BuilddepMojo.java
@@ -139,7 +139,7 @@ public class BuilddepMojo
Set<Artifact> artifacts = new LinkedHashSet<>();
for ( MavenProject project : reactorProjects )
{
- Model model = project.getModel();
+ Model model = project.getModel().clone();
String modelId = model.getLocation( "" ).getSource().getModelId();
BuildDependencyVisitor visitor = new BuildDependencyVisitor( modelId );
modelProcessor.processModel( model, visitor );
@@ -149,6 +149,9 @@ public class BuilddepMojo
Set<NamespacedArtifact> deps = new LinkedHashSet<>();
for ( String[] resolution : resolutions )
{
+ if ( resolution == null )
+ continue;
+
Artifact artifact = new DefaultArtifact( resolution[0] );
String compatVersion = resolution[1];
String namespace = resolution[2];
--
2.5.0

View File

@ -8,7 +8,7 @@
Name: xmvn
Version: 2.5.0
Release: 4%{?dist}
Release: 5%{?dist}
Summary: Local Extensions for Apache Maven
License: ASL 2.0
URL: http://mizdebsk.fedorapeople.org/xmvn
@ -17,6 +17,7 @@ BuildArch: noarch
Source0: https://fedorahosted.org/released/%{name}/%{name}-%{version}.tar.xz
Patch0: 0001-Copy-core-dependencies-to-lib-core-in-assembly.patch
Patch1: 0002-Try-to-procect-builddep-MOJO-against-patological-cas.patch
BuildRequires: maven >= 3.3.9-2
BuildRequires: maven-local
@ -157,6 +158,7 @@ This package provides %{summary}.
%prep
%setup -q
%patch0 -p1
%patch1 -p1
%mvn_package ":xmvn{,-it}" __noinstall
@ -297,6 +299,9 @@ cp -P %{_datadir}/maven/bin/m2.conf %{buildroot}%{_datadir}/%{name}/bin/
%doc LICENSE NOTICE
%changelog
* Thu Nov 26 2015 Mikolaj Izdebski <mizdebsk@redhat.com> - 2.5.0-5
- Try to procect builddep MOJO against patological cases
* Mon Nov 23 2015 Mikolaj Izdebski <mizdebsk@redhat.com> - 2.5.0-4
- Remove temporary Maven 3.3.9 workaround