Fix upgrade path scriptlet

- Add patch to fix NPE when debugging is disabled
This commit is contained in:
Stanislav Ochotnicky 2013-05-24 17:24:19 +02:00
parent 0fcec66506
commit 4619d32763
2 changed files with 131 additions and 2 deletions

View File

@ -0,0 +1,120 @@
From ccc197d9503267243cc4427d60dd360e1953d4c1 Mon Sep 17 00:00:00 2001
From: Mikolaj Izdebski <mizdebsk@redhat.com>
Date: Fri, 24 May 2013 17:15:36 +0200
Subject: [PATCH] Be careful when unboxing Boolean that can be null
Add explicit check for null value when unboxing Booleans that can be
null. Also extract duplicated code to a utility class.
---
.../maven/resolver/DefaultArtifactBlacklist.java | 4 +--
.../maven/resolver/DefaultResolver.java | 4 +--
.../fedoraproject/maven/utils/LoggingUtils.java | 30 ++++++++++++++++++++++
.../maven/rpminstall/plugin/InstallMojo.java | 4 +--
4 files changed, 36 insertions(+), 6 deletions(-)
create mode 100644 xmvn-core/src/main/java/org/fedoraproject/maven/utils/LoggingUtils.java
diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultArtifactBlacklist.java b/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultArtifactBlacklist.java
index 451f71e..a6502be 100644
--- a/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultArtifactBlacklist.java
+++ b/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultArtifactBlacklist.java
@@ -26,6 +26,7 @@ import org.codehaus.plexus.logging.Logger;
import org.fedoraproject.maven.config.Configurator;
import org.fedoraproject.maven.config.ResolverSettings;
import org.fedoraproject.maven.model.Artifact;
+import org.fedoraproject.maven.utils.LoggingUtils;
/**
* @author Mikolaj Izdebski
@@ -113,8 +114,7 @@ public class DefaultArtifactBlacklist
{
Set<Artifact> aliasBlacklist = new TreeSet<>();
ResolverSettings settings = configurator.getConfiguration().getResolverSettings();
- int loggerThreshold = settings.isDebug() ? Logger.LEVEL_DEBUG : Logger.LEVEL_WARN;
- logger.setThreshold( Math.min( logger.getThreshold(), loggerThreshold ) );
+ LoggingUtils.setLoggerThreshold( logger, settings.isDebug() );
for ( String prefix : settings.getPrefixes() )
{
diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultResolver.java b/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultResolver.java
index 7fb51c5..c6a82ad 100644
--- a/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultResolver.java
+++ b/xmvn-core/src/main/java/org/fedoraproject/maven/resolver/DefaultResolver.java
@@ -31,6 +31,7 @@ import org.fedoraproject.maven.repository.Layout;
import org.fedoraproject.maven.repository.Repository;
import org.fedoraproject.maven.repository.SingletonRepository;
import org.fedoraproject.maven.utils.AtomicFileCounter;
+import org.fedoraproject.maven.utils.LoggingUtils;
/**
* @author Mikolaj Izdebski
@@ -90,8 +91,7 @@ public class DefaultResolver
initializeBisect();
ResolverSettings settings = configurator.getConfiguration().getResolverSettings();
- int loggerThreshold = settings.isDebug() ? Logger.LEVEL_DEBUG : Logger.LEVEL_WARN;
- logger.setThreshold( Math.min( logger.getThreshold(), loggerThreshold ) );
+ LoggingUtils.setLoggerThreshold( logger, settings.isDebug() );
resolvers.add( new LocalResolver( settings ) );
diff --git a/xmvn-core/src/main/java/org/fedoraproject/maven/utils/LoggingUtils.java b/xmvn-core/src/main/java/org/fedoraproject/maven/utils/LoggingUtils.java
new file mode 100644
index 0000000..7dcd265
--- /dev/null
+++ b/xmvn-core/src/main/java/org/fedoraproject/maven/utils/LoggingUtils.java
@@ -0,0 +1,30 @@
+/*-
+ * Copyright (c) 2012-2013 Red Hat, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.fedoraproject.maven.utils;
+
+import org.codehaus.plexus.logging.Logger;
+
+/**
+ * @author Mikolaj Izdebski
+ */
+public class LoggingUtils
+{
+ public static void setLoggerThreshold( Logger logger, Boolean debugSetting )
+ {
+ int threshold = debugSetting != null && debugSetting ? Logger.LEVEL_DEBUG : Logger.LEVEL_WARN;
+ logger.setThreshold( Math.min( logger.getThreshold(), threshold ) );
+ }
+}
diff --git a/xmvn-mojo/src/main/java/org/fedoraproject/maven/rpminstall/plugin/InstallMojo.java b/xmvn-mojo/src/main/java/org/fedoraproject/maven/rpminstall/plugin/InstallMojo.java
index a8bf55d..1f53a49 100644
--- a/xmvn-mojo/src/main/java/org/fedoraproject/maven/rpminstall/plugin/InstallMojo.java
+++ b/xmvn-mojo/src/main/java/org/fedoraproject/maven/rpminstall/plugin/InstallMojo.java
@@ -44,6 +44,7 @@ import org.fedoraproject.maven.installer.DefaultPackage;
import org.fedoraproject.maven.installer.Installer;
import org.fedoraproject.maven.installer.ProjectInstallationException;
import org.fedoraproject.maven.installer.ProjectInstaller;
+import org.fedoraproject.maven.utils.LoggingUtils;
/**
* @author Mikolaj Izdebski
@@ -124,8 +125,7 @@ public class InstallMojo
{
Configuration configuration = configurator.getConfiguration();
settings = configuration.getInstallerSettings();
- int loggerThreshold = settings.isDebug() ? Logger.LEVEL_DEBUG : Logger.LEVEL_WARN;
- logger.setThreshold( Math.min( logger.getThreshold(), loggerThreshold ) );
+ LoggingUtils.setLoggerThreshold( logger, settings.isDebug() );
Map<String, DefaultPackage> packages = new TreeMap<>();
--
1.8.1.4

View File

@ -1,12 +1,15 @@
Name: xmvn
Version: 0.5.0
Release: 1%{?dist}
Release: 2%{?dist}
Summary: Local Extensions for Apache Maven
License: ASL 2.0
URL: http://mizdebsk.fedorapeople.org/xmvn
BuildArch: noarch
Source0: https://fedorahosted.org/released/%{name}/%{name}-%{version}.tar.xz
# from upstream commit ccc197d to fix NPE
Patch0: 0001-Be-careful-when-unboxing-Boolean-that-can-be-null.patch
BuildRequires: maven-local
BuildRequires: beust-jcommander
BuildRequires: cglib
@ -41,6 +44,8 @@ This package provides %{summary}.
%prep
%setup -q
%patch0 -p1
# Add cglib test dependency as a workaround for rhbz#911365
%pom_add_dep cglib:cglib::test %{name}-core
@ -112,7 +117,7 @@ cp -P %{_datadir}/maven/conf/settings.xml %{buildroot}%{_datadir}/%{name}/conf/
%pre
# we are changing symlink to dir, workaround RPM issues
for dir in conf boot;do
[ $1 -eq 1 ] && [ -L %{_datadir}/%{name}/$dir ] && \
[ $1 -ge 1 ] && [ -L %{_datadir}/%{name}/$dir ] && \
rm -f %{_datadir}/%{name}/$dir || :
done
@ -126,6 +131,10 @@ done
%doc LICENSE NOTICE
%changelog
* Fri May 24 2013 Stanislav Ochotnicky <sochotnicky@redhat.com> - 0.5.0-2
- Fix upgrade path scriptlet
- Add patch to fix NPE when debugging is disabled
* Fri May 24 2013 Stanislav Ochotnicky <sochotnicky@redhat.com> - 0.5.0-1
- Update to upstream version 0.5.0