File derive4j.spec of Package derive4j

#
# spec file for package derive4j
#
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global base_name derive4j
%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "bootstrap"
%bcond_without bootstrap
%else
%bcond_with bootstrap
%endif
%if %{with bootstrap}
%global name %{base_name}-%{flavor}
%else
%global name %{base_name}
%endif
Name:           %{name}
Version:        1.1.1
Release:        0
Summary:        Java 8 annotation processor and framework
License:        GPL-3.0-only AND LGPL-3.0-only AND BSD-3-Clause
Group:          Development/Libraries/Java
URL:            https://github.com/%{base_name}/%{base_name}
Source0:        %{url}/archive/refs/tags/v%{version}.tar.gz#/%{base_name}-%{version}.tar.gz
Source1:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}/%{version}/%{base_name}-%{version}.jar
Source2:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}/%{version}/%{base_name}-%{version}.pom
Source3:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}-annotation/%{version}/%{base_name}-annotation-%{version}.jar
Source4:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}-annotation/%{version}/%{base_name}-annotation-%{version}.pom
Source5:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}-processor-api/%{version}/%{base_name}-processor-api-%{version}.jar
Source6:        https://repo1.maven.org/maven2/org/%{base_name}/%{base_name}-processor-api/%{version}/%{base_name}-processor-api-%{version}.pom
BuildRequires:  maven-local
BuildArch:      noarch
%if %{without bootstrap}
BuildRequires:  mvn(com.google.auto.service:auto-service)
BuildRequires:  mvn(com.squareup:javapoet)
BuildRequires:  mvn(org.derive4j:derive4j-bootstrap) = %{version}
%endif

%description
Java 8 annotation processor and framework for deriving algebraic data types
constructors, pattern-matching, folds, optics and typeclasses.

%if %{without bootstrap}
%package javadoc
Summary:        API documentation for %{name}
Group:          Documentation/HTML

%description javadoc
API documentation for %{name}.

%endif

%prep
%if %{with bootstrap}
cp %{SOURCE2} %{SOURCE4} %{SOURCE6} .

%pom_xpath_set 'pom:project/pom:artifactId' '%{base_name}-bootstrap' \
	%{base_name}-%{version}.pom
%pom_xpath_set 'pom:project/pom:artifactId' '%{base_name}-annotation-bootstrap' \
	%{base_name}-annotation-%{version}.pom
%pom_xpath_set 'pom:project/pom:artifactId' '%{base_name}-processor-api-bootstrap' \
	%{base_name}-processor-api-%{version}.pom
%pom_remove_dep 'org.derive4j' %{base_name}{,-processor-api}-%{version}.pom

%{mvn_file} ':%{name}{*}' %{name}/@1
%else
%setup -q
cp %{SOURCE2} processor/pom.xml
cp %{SOURCE4} annotation/pom.xml
cp %{SOURCE6} processor-api/pom.xml
cat <<__POM__ >pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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"
	>
	<modelVersion>4.0.0</modelVersion>
	<groupId>org.derive4j</groupId>
	<artifactId>derive4j-parent</artifactId>
	<packaging>pom</packaging>
	<version>%{version}</version>
	<name>Derive4J - Parent POM</name>
	<modules>
		<module>annotation</module>
		<module>processor-api</module>
		<module>processor</module>
	</modules>
</project>
__POM__

cp processor/LICENSE.txt GPL-3.0-only.txt
cp annotation/LICENSE.txt LGPL-3.0-only.txt
cp examples/LICENSE.txt BSD-3-Clause.txt

%pom_add_plugin org.apache.maven.plugins:maven-compiler-plugin annotation processor-api \
'<configuration>
	<annotationProcessorPaths>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-annotation-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-processor-api-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
	</annotationProcessorPaths>
	<annotationProcessors>
		<annotationProcessor>org.derive4j.processor.DerivingProcessor</annotationProcessor>
	</annotationProcessors>
</configuration>'

%pom_add_plugin org.apache.maven.plugins:maven-compiler-plugin processor \
'<configuration>
	<annotationProcessorPaths>
		<path>
			<groupId>com.google.auto.service</groupId>
			<artifactId>auto-service</artifactId>
			<version>1.0-rc5</version>
		</path>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-annotation-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
		<path>
			<groupId>org.derive4j</groupId>
			<artifactId>derive4j-processor-api-bootstrap</artifactId>
			<version>%{version}</version>
		</path>
	</annotationProcessorPaths>
	<annotationProcessors>
		<annotationProcessor>org.derive4j.processor.DerivingProcessor</annotationProcessor>
		<annotationProcessor>com.google.auto.service.processor.AutoServiceProcessor</annotationProcessor>
	</annotationProcessors>
</configuration>'

%pom_add_dep com.google.auto.service:auto-service processor

%endif

%build
%if %{without bootstrap}
%{mvn_build} -f -- \
    -Dmaven.compiler.{source,target}=8 \
    -DlegacyMode=true \
    -Dmaven.compiler.useIncrementalCompilation=false
%endif

%install
%if %{with bootstrap}
%{mvn_artifact} --skip-dependencies %{base_name}-%{version}.pom %{SOURCE1}
%{mvn_artifact} --skip-dependencies %{base_name}-annotation-%{version}.pom %{SOURCE3}
%{mvn_artifact} --skip-dependencies %{base_name}-processor-api-%{version}.pom %{SOURCE5}
%else
%{mvn_package} org.derive4j:%{name}-parent __noinstall
%endif
%mvn_install

%files -f .mfiles
%if %{without bootstrap}
%license LICENSES {GPL-3.0-only,LGPL-3.0-only,BSD-3-Clause}.txt
%doc README.md
%endif

%if %{without bootstrap}
%files javadoc -f .mfiles-javadoc
%license LICENSES {GPL-3.0-only,LGPL-3.0-only,BSD-3-Clause}.txt
%endif

%changelog
openSUSE Build Service is sponsored by