Sophie

Sophie

distrib > Fedora > 17 > i386 > by-pkgid > 85cdd9d53a2590bf7aae917bca02caaa > files > 11

jpackage-utils-1.7.5-18.2.fc17.i686.rpm

# Copyright (c) 2012, Red Hat, Inc
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of Red Hat nor the names of its
#    contributors may be used to endorse or promote products derived
#    from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Stanislav Ochotnicky <sochotnicky@redhat.com>
#          Mikolaj Izdebski <mizdebsk@redhat.com>


# directory that can contain a proper maven repository usable by upstream
# maven one day
%_maven_repository %{_datadir}/maven-repository

#==============================================================================
#
# add_maven_depmap is simplified version of jpackage-style add_to_maven_depmap
# -f addition to fragment name
# -a is "g1:a1,g2:a2" formatted string with additional depmaps (groupId:artifactId,...)
# -v is "v1,v2" formatted string with additional compatibility versions
#    supposed to be provided (jar,pom will be renamed to -%{version} variants
#    and additional symlinks optionally created)
# -m If included a Maven repository layout will be generated in %_maven_repository
#    and files will be symlinked there as well
# %1 is the pom filename relative to mavenpomdir
# %2 is the path to jar file (when omitted we deal with parent pom file without jar)
#
# add_maven_depmap automatically parses pom file and it will fail with incorrect pom
# or jar filename
#
# in the end add_maven_depmap optionally moves jar and pom file to
# -%{version} variant and can create additional versioned symlinks

%add_maven_depmap(f:a:v:m) \
set -e \
# default values \
%if %# == 0 \
   _pompart="JPP-%{name}.pom" \
   _jarpart="%{name}.jar" \
%else \
   _pompart="%1" \
   _jarpart="%2" \
%endif \
_filelist=".mfiles%{-f*:-%{-f*}}" \
install -dm 755 $RPM_BUILD_ROOT/%{_mavendepmapfragdir}\
for _dir in %{_jnidir} %{_javajnidir} %{_javadir}; do \
    if [ -f %{buildroot}/$_dir/$_jarpart ]; then \
	_jpath="%{buildroot}/$_dir/$_jarpart" \
    fi \
done \
python -m /usr/share/java-utils/maven_depmap %{-a} %{-v*:-r %{-v*}} \\\
          %{-m:-m %{buildroot}%{_maven_repository}} \\\
          %{buildroot}%{_mavendepmapfragdir}/%{name}%{-f*:-%{-f*}} \\\
          %{buildroot}%{_mavenpomdir}/$_pompart \\\
%if %# == 2 \
          "${_jpath}" \\\
%endif \
%if %# == 0 \
          "${_jpath}" \\\
%endif \
        >> ${_filelist} \
# this part only works for jars for now (now war/other compat support) \
if [[ "%{-v}" != "" ]];then \
mv %{buildroot}%{_mavenpomdir}/$_pompart \\\
   %{buildroot}%{_mavenpomdir}/${_pompart/.pom/-%{version}.pom} \
if [ -f "${_jpath}" ]; then \
    mv ${_jpath} ${_jpath/.jar/-%{version}.jar} \
fi \
for ver in $(echo %{-v*} | tr ',' '\\n');do \
 ln -s ${_pompart/.pom/-%{version}.pom} \\\
       %{buildroot}/%{_mavenpomdir}/${_pompart/.pom/-$ver.pom} \
 echo %{_mavenpomdir}/${_pompart/.pom/-$ver.pom} >>${_filelist} \
 # we can have pom-only artifacts \
 if [ -f "${_jpath/.jar/-%{version}.jar}" ];then \
       ln -s `basename ${_jpath/.jar/-%{version}.jar}` \\\
             ${_jpath/.jar/-$ver.jar} \
       echo ${_jpath/.jar/-$ver.jar} >>${_filelist} \
 fi \
done \
fi \
sed -i 's:%{buildroot}::' ${_filelist} \
sort -u -o ${_filelist} ${_filelist} \
\
%{nil}

#==============================================================================

# %create_javadoc_subpackage can be used to completely create
# javadoc subpackage for java projects.
# !!! Needs to be used at the end of %install section
# There are these variables that change its behaviour:
#
# %__javadoc_license - set if the license is in non-standard place
# %__apidocs_dir - set custom path to directory with javadocs
#                (defaults to target/site/apidocs)
# %__javadoc_no_license - if defined javadoc subpackage will not have
#                licensing information. Use only if if upstream
#                doesn't provide separate license file.
#


%create_javadoc_subpackage() %{expand:\
%{!?__apidocs_dir: %global __apidocs_dir target/site/apidocs} \
%{expand: %{__find_javadoc_license}} \
%global __spec_install_post %{expand:%{__java_install_post}} \
%if "%{__javadoc_license}" == "%{nil}" \
%{?!__javadoc_no_license:echo License not found. Either set __javadoc_license to point to license file or set __javadoc_no_license if sources do not contain license file;exit 1;} \
%endif \
%package javadoc \
Group:          Documentation \
Summary:        Javadoc for %{name} \
Requires:       jpackage-utils \
%description javadoc \
API documentation for %{name}. \
%files javadoc \
%{_javadocdir}/%{name} \
%doc %{__javadoc_license} \
}

%__java_install_post %{expand: \
%{?__spec_check_pre} \
pushd %{buildsubdir} \
%{__mkdir_p} %{buildroot}/%{_javadocdir}/%{name} \
cp -pr %{__apidocs_dir}/* %{buildroot}/%{_javadocdir}/%{name} \
popd \
}

%__find_javadoc_license() %{expand: \
%{!?__javadoc_license: \
%global __javadoc_license %(\
cd %{buildsubdir} \
licenses="" \
for lic in LICENSE* COPYING* doc/LICENSE* doc/COPYING* license*;do \
if [ -f $lic ];then \
   licenses="$licenses $lic"; \
fi \
done \
if [ "$licenses" == "" ]; then \
echo "%{nil}"; \
else \
echo $licenses; \
fi \
)\
}
}


#==============================================================================
#
# %pom_* -- macros for batch editing of POM files
#
# These macros can be used to edit Maven POM files directly from RPM spec
# file. Using these macros it is possible to alter Maven dependency management,
# change plugin invocation, or even inject or remove arbitrary XML code to/from
# nodes described by an XPath expression.
#
# See comments preceding individual macros for more detailed documentation.
#

# Private macro, shouldn't be used directly
%__pom_call           . /usr/share/java-utils/pom_editor.sh; pom_


# %pom_remove_dep - remove dependency on Maven artifact from POM file
#
# Usage: %pom_remove_dep [groupId]:[artifactId] [POM location]
#
# This macro patches specified POM file not to contain dependencies on given
# Maven artifact.
#
# 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.
#
%pom_remove_dep()     %{expand: %{__pom_call}remove_dep     %*
}


# %pom_remove_plugin - remove Maven plugin invocation from POM file
#
# Usage: %pom_remove_plugin [groupId]:[artifactId] [POM location]
#
# This macro patches specified POM file not to contain invocations of given
# Maven plugin.
#
# groupId and artifactId are identifiers of Maven group and artifact of the
# plugin which invocation 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.
#
%pom_remove_plugin()  %{expand: %{__pom_call}remove_plugin  %*
}


# %pom_disable_module - disable given project module in POM file
#
# Usage: %pom_disable_module <module name> [POM location]
#
# This macro patches specified POM file not to contain reference to given
# project module.
#
# Module name is the exact name of the module to be disabled. It must 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_disable_module() %{expand: %{__pom_call}disable_module %*
}


# %pom_xpath_remove - remove an XML node from POM file
#
# Usage: %pom_xpath_remove <XPath> [POM location]
#
# This macro patches specified POM file removing all XML nodes described by the
# XPath expression.
#
# 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.
#
# NOTE: POM files use a specific namespace - http://maven.apache.org/POM/4.0.0.
# The easiest way to respect this namespace in XPath expressions is prefixing
# all node names with "pom:". For example, "pom:environment/pom:os" will work
# because it selects nodes from pom namespace, but "environment/os" won't find
# anything because it looks for nodes that don't belong to any XML namespace.
#
%pom_xpath_remove()   %{expand: %{__pom_call}xpath_remove   %*
}


# %pom_xpath_inject - inject XML code into POM file
#
# Usage: %pom_xpath_inject <XPath> [XML code] [POM location]
#
# This macro patches specified POM file appending some code as childreen of all
# XML nodes described by the XPath expression.
#
# XPath is an expression describing a set of XML nodes in the POM 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.
#
%pom_xpath_inject()   %{expand: %{__pom_call}xpath_inject   %*
}


# %pom_add_parent - add parent POM reference to POM file
#
# Usage: %pom_add_parent groupId:artifactId[:version] [POM location]
#
# This macro patches specified POM file adding a reference to parent POM with
# specified groupId, artifactId and version.
#
# groupId and artifactId are identifiers of Maven group and artifact of the POM
# to be referenced as parent POM. They must be specified. If 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.
#
# Note: If specified POM has already a reference to parent POM this macro will
# not alter or remove it. Instead a second reference will be added. This is
# usually not the expected behavior, so if you want to replace existing parent
# POM reference, consider using %pom_set_parent macro instead.
#
%pom_add_parent()     %{expand: %{__pom_call}add_parent     %*
}


# %pom_remove_parent - remove parent POM reference from POM file
#
# Usage: %pom_remove_parent [POM location]
#
# This macro patches specified POM file removing reference to parent 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_remove_parent()  %{expand: %{__pom_call}remove_parent  %*
}


# %pom_set_parent - set parent POM reference in POM file
#
# Usage: %pom_set_parent groupId:artifactId[:version] [POM location]
#
# This macro patches specified POM file setting reference to parent POM to
# specified groupId, artifactId and version.
#
# This macros first removes parent POM reference and then adds a new one. It's
# (more or less) equivalent to call to %pom_remove_parent followed by
# invocation of %pom_add_parent. See documentation for these macros for more
# information about parameters.
#
%pom_set_parent()     %{expand: %{__pom_call}set_parent     %*
}


# %pom_add_dep[_mgmt] - add dependency to POM file
#
# Usage: %pom_add_dep groupId:artifactId[:version[:scope]] [POM location] \
#            [extra XML]
#        %pom_add_dep_mgmt groupId:articId[:version[:scope]] [POM location] \
#            [extra XML]
#
# 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, while %pom_add_dep_mgmt adds it to
# <dependencyManagement>.
#
# groupId and artifactId are identifiers of Maven artifact on which dependency
# is to be added.. They must be specified. If version is not 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.
#
# 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.
#
%pom_add_dep()        %{expand: %{__pom_call}add_dep        %*
}
%pom_add_dep_mgmt()   %{expand: %{__pom_call}add_dep_mgmt   %*
}


# %pom_add_plugin - add plugin invocation to POM file
#
# Usage: %pom_add_plugin groupId:artifactId[:version] [POM location] \
#            [extra XML]
#
# This macro patches specified POM file adding plugin invocation of given
# groupId and artifactId.
#
# groupId and artifactId are identifiers of Maven plugin artifact of which
# invocation is to be added. groupId may be ommited, in which case value of
# "org.apache.maven.plugins" is used as default. artifactId must be
# specified. If 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.
#
# 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.
#
%pom_add_plugin()     %{expand: %{__pom_call}add_plugin     %*
}