# Guidance in creating a port using java & maven



## ddaley (Jan 13, 2012)

I am in the process of creating a port for a *java* based application that uses *maven* for the build.  This is my first port and am a complete noob to this, though  I have read through some of the porters guide.  I am just looking to be pointed in the right direction for resolving the issues below and for improving the port in general.

I have a port that works.  I can do make install, make clean, make deinstall and they all work as expected.  However, I think there may be better ways to do some of the things that I am doing.

First Issue: 
For those not familiar with maven, it is a build tool similar to make with the ports.  It downloads necessary dependencies when you build.  By default, it downloads all of the application dependencies to ~/.m2/repository.  However, the base directory can be overridden.  I have told it put the files into /usr/ports/distfiles/.m2/repository.  I thought about putting the files into the <port directory>/work/.m2/repository.  However, doing a make clean would wipe out the dependencies and other ports based on maven could potentially reuse the repository if it were in /usr/ports/distfiles

Is there a recommended approach in this case?

Second Issue: 
Maven is a build tool like make.  At first I thought I could just trick the port into using maven by setting a few variables like this:


```
MAKE=mvn
MAKE_ARGS=-Duser.home=${DISTDIR}
MAKEFILE=pom.xml
ALL_TARGET=install
```

This kinda worked, but it posed some issues.

Here is my current Makefile


```
# New ports collection Makefile for:    repose
# Date created:        			10 January 2012
# Whom:                			Dan Daley <dddaley@yahoo.com>
#
# $FreeBSD$

PORTNAME=	papi
PORTVERSION=	1.0.6
CATEGORIES=	devel java
MASTER_SITES=	http://nodeload.github.com/rackspace/repose/tarball/

MAINTAINER=	dddaley@yahoo.com
COMMENT=	RESTful Proxy Service

EXTRACT_SUFX=

BUILD_DEPENDS=	${LOCALBASE}/openjdk6/bin/java:${PORTSDIR}/java/openjdk6 \
		${LOCALBASE}/share/java/maven3/bin/mvn:${PORTSDIR}/devel/maven3

RUN_DEPENDS=	${BUILD_DEPENDS}

USE_JAVA=	yes
JAVA_VERSION=	1.6
JAVA_VENDOR=	openjdk

PORTHOME=	${PORTSDIR}/java/repose-${PORTVERSION}
NOCLEANDEPENDS=	yes
#MAKE=		mvn
#MAKE_ARGS=	-D user.home=${DISTDIR}
#MAKEFILE=	pom.xml
#ALL_TARGET=	install
MVN_OPTS=	MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
MVN=		mvn
MVN_ARGS=	-Duser.home=${DISTDIR}/
#MVN_ARGS=	-Duser.home=${PORTHOME}/
MVN_TARGET=	install
MVN_CLEAN_TARGET=clean

#Install related

PREFIXDIR=	${PREFIX}/repose-${PORTVERSION}
PLIST_SUB+=	PORTVERSION=${PORTVERSION}

post-extract:
	${ECHO_CMD} "mv ${WRKDIR}/rackspace* ${WRKDIR}/${PORTNAME}-${PORTVERSION}"
	${MV} ${WRKDIR}/rackspace* ${WRKDIR}/${PORTNAME}-${PORTVERSION}

clean-repo:
	${ECHO_CMD} "rm -rf ${DISTDIR}/.m2"
	${RM} -rf ${DISTDIR}/.m2

do-clean:
	${ECHO_CMD} "cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_CLEAN_TARGET}"
	@(cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_CLEAN_TARGET})
	${ECHO_CMD} "cd ${PORTHOME} && ${RM} -rf ${WRKDIR}"
	cd ${PORTHOME} && ${RM} -rf ${WRKDIR}

do-build:
	${ECHO_CMD} "cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_TARGET}"
	@(cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_TARGET})

do-install:
	@${MKDIR} ${PREFIXDIR}
	@${MKDIR} ${PREFIXDIR}/bin
	@${MKDIR} ${PREFIXDIR}/etc
	@${MKDIR} ${PREFIXDIR}/etc/powerapi
	@${MKDIR} ${PREFIXDIR}/lib
	@${MKDIR} ${PREFIXDIR}/lib/filters
	@${MKDIR} ${PREFIXDIR}/var
	@${MKDIR} ${PREFIXDIR}/var/powerapi
	@${MKDIR} ${PREFIXDIR}/logs
	@${MKDIR} ${PREFIXDIR}/docs
	@(cd ${PORTHOME}/files/etc && ${COPYTREE_SHARE} \* ${PREFIXDIR}/etc/powerapi/)
	@(cd ${PORTHOME}/files/bin && ${COPYTREE_SHARE} \* ${PREFIXDIR}/bin/)
	@(cd ${WRKSRC}/project-set/core/valve/target && ${COPYTREE_SHARE} \repose-valve.jar ${PREFIXDIR}/bin/)
	@(cd ${WRKSRC}/project-set/components/filter-bundle/target && ${COPYTREE_SHARE} \*.ear ${PREFIXDIR}/lib/filters/)
	@(cd ${WRKSRC}/documentation/docbook/target/docbkx/pdf/ && ${COPYTREE_SHARE} \*.pdf ${PREFIXDIR}/docs/)
	@(cd ${WRKSRC}/documentation/presentations/OpenStack_Essex_2011 && ${COPYTREE_SHARE} \*.pdf ${PREFIXDIR}/docs/)

.include <bsd.port.mk>
```

Here is my distinfo 

```
SHA256 (papi-1.0.6) = be962cf8d0705bf3845bc64fdf6ff7f4bdce4ea6035eb4718f996a90c95e875c
SIZE (papi-1.0.6) = 3465112
```


pkg-plist

```
repose-1.0.6/bin/start-valve.sh
repose-1.0.6/bin/repose-valve.jar
repose-1.0.6/etc/powerapi/container.cfg.xml
repose-1.0.6/etc/powerapi/content-normalization.cfg.xml
repose-1.0.6/etc/powerapi/http-logging.cfg.xml
repose-1.0.6/etc/powerapi/http-logging.cfg.xml~
repose-1.0.6/etc/powerapi/power-proxy.cfg.xml
repose-1.0.6/etc/powerapi/versioning.cfg.xml
repose-1.0.6/lib/filters/filter-bundle-1.0.6.ear
repose-1.0.6/docs/repose-authn-deploy.pdf
repose-1.0.6/docs/repose-glossary.pdf
repose-1.0.6/docs/repose-intro.pdf
repose-1.0.6/docs/repose-logging-deploy.pdf
repose-1.0.6/docs/repose-ratelimiting-deploy.pdf
repose-1.0.6/docs/repose-rootwar-deploy.pdf
repose-1.0.6/docs/repose-versioning-deploy.pdf
repose-1.0.6/docs/ReposePresentation.pdf
@dirrm repose-1.0.6/bin
@dirrm repose-1.0.6/etc/powerapi
@dirrm repose-1.0.6/etc
@dirrm repose-1.0.6/lib/filters
@dirrm repose-1.0.6/lib
@dirrm repose-1.0.6/var/powerapi
@dirrm repose-1.0.6/var
@dirrm repose-1.0.6/logs
@dirrm repose-1.0.6/docs
@dirrm repose-1.0.6
```

pkg-descr

```
REPOSE is an open-source RESTful HTTP proxy service that scales to the cloud. 
REPOSE provides the solution to common API processing tasks such as rate 
limiting, client authentication, versioning, and logging so that web service 
developers can focus on the unique features of their services. 

WWW: http://www.openrepose.org/
```

contents of the repose-1.0.6 directory

./distinfo
./files
./files/etc
./files/etc/versioning.cfg.xml
./files/etc/power-proxy.cfg.xml
./files/etc/http-logging.cfg.xml
./files/etc/container.cfg.xml
./files/etc/content-normalization.cfg.xml
./files/bin
./files/bin/start-valve.sh
./pkg-descr
./Makefile
./pkg-plist



Here is the resulting install (under /usr/local)
repose-1.0.6
repose-1.0.6/bin
repose-1.0.6/bin/start-valve.sh
repose-1.0.6/bin/repose-valve.jar
repose-1.0.6/etc
repose-1.0.6/etc/powerapi
repose-1.0.6/etc/powerapi/container.cfg.xml
repose-1.0.6/etc/powerapi/content-normalization.cfg.xml
repose-1.0.6/etc/powerapi/http-logging.cfg.xml
repose-1.0.6/etc/powerapi/power-proxy.cfg.xml
repose-1.0.6/etc/powerapi/versioning.cfg.xml
repose-1.0.6/lib
repose-1.0.6/lib/filters
repose-1.0.6/lib/filters/filter-bundle-1.0.6.ear
repose-1.0.6/var
repose-1.0.6/var/powerapi
repose-1.0.6/logs
repose-1.0.6/docs
repose-1.0.6/docs/repose-authn-deploy.pdf
repose-1.0.6/docs/repose-glossary.pdf
repose-1.0.6/docs/repose-intro.pdf
repose-1.0.6/docs/repose-logging-deploy.pdf
repose-1.0.6/docs/repose-ratelimiting-deploy.pdf
repose-1.0.6/docs/repose-rootwar-deploy.pdf
repose-1.0.6/docs/repose-versioning-deploy.pdf
repose-1.0.6/docs/ReposePresentation.pdf


----------



## ddaley (Jan 13, 2012)

I updated this a bit, so thought I would post the updates.

Changed the Makefile to set permissions on a few files/directories and changed to use INSTALL macros.

Makefile

```
# New ports collection Makefile for:    repose
# Date created:        			10 January 2012
# Whom:                			Dan Daley <dddaley@yahoo.com>
#
# $FreeBSD$

PORTNAME=	papi
PORTVERSION=	1.0.6
CATEGORIES=	devel java
MASTER_SITES=	http://nodeload.github.com/rackspace/repose/tarball/

MAINTAINER=	dddaley@yahoo.com
COMMENT=	RESTful Proxy Service

EXTRACT_SUFX=

BUILD_DEPENDS=	${LOCALBASE}/openjdk6/bin/java:${PORTSDIR}/java/openjdk6 \
		${LOCALBASE}/share/java/maven3/bin/mvn:${PORTSDIR}/devel/maven3

RUN_DEPENDS=	${BUILD_DEPENDS}

USE_JAVA=	yes
JAVA_VERSION=	1.6
JAVA_VENDOR=	openjdk

PORTHOME=	${PORTSDIR}/java/repose-${PORTVERSION}
NOCLEANDEPENDS=	yes
#MAKE=		mvn
#MAKE_ARGS=	-D user.home=${DISTDIR}
#MAKEFILE=	pom.xml
#ALL_TARGET=	install
MVN_OPTS=	MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=256m"
MVN=		mvn
MVN_ARGS=	-Duser.home=${DISTDIR}/
#MVN_ARGS=	-Duser.home=${PORTHOME}/
MVN_TARGET=	install
MVN_CLEAN_TARGET=clean

#Install related

PREFIXDIR=	${PREFIX}/repose-${PORTVERSION}
PLIST_SUB+=	PORTVERSION=${PORTVERSION}

echo:
	${ECHO_CMD} WRKDIR ${WRKDIR}
	${ECHO_CMD} WRKSRC ${WRKSRC}

post-extract:
	${ECHO_CMD} "mv ${WRKDIR}/rackspace* ${WRKDIR}/${PORTNAME}-${PORTVERSION}"
	${MV} ${WRKDIR}/rackspace* ${WRKDIR}/${PORTNAME}-${PORTVERSION}

clean-repo:
	${ECHO_CMD} "rm -rf ${DISTDIR}/.m2"
	${RM} -rf ${DISTDIR}/.m2

do-clean:
	${ECHO_CMD} "cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_CLEAN_TARGET}"
	@(cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_CLEAN_TARGET})
	${ECHO_CMD} "cd ${PORTHOME} && ${RM} -rf ${WRKDIR}"
	cd ${PORTHOME} && ${RM} -rf ${WRKDIR}

do-build:
	${ECHO_CMD} "cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_TARGET}"
	@(cd ${WRKSRC} && ${MVN_OPTS} ${MVN} ${MVN_ARGS} ${MVN_TARGET})

do-install:
	@${MKDIR} ${PREFIXDIR}
	@${MKDIR} ${PREFIXDIR}/bin
	@${MKDIR} ${PREFIXDIR}/etc
	@${MKDIR} ${PREFIXDIR}/etc/powerapi
	@${MKDIR} ${PREFIXDIR}/lib
	@${MKDIR} ${PREFIXDIR}/lib/filters
	@${MKDIR} ${PREFIXDIR}/var
	@${MKDIR} ${PREFIXDIR}/var/powerapi
	@${MKDIR} ${PREFIXDIR}/logs
	@${MKDIR} ${PREFIXDIR}/docs
	${CHMOD} 775 ${PREFIXDIR}/logs
	${CHMOD} 775 ${PREFIXDIR}/var/powerapi
	${INSTALL_DATA} ${PORTHOME}/files/etc/* ${PREFIXDIR}/etc/powerapi/
	${INSTALL_SCRIPT} ${PORTHOME}/files/bin/start-valve.sh  ${PREFIXDIR}/bin/start-valve.sh
	${INSTALL_DATA} ${WRKSRC}/project-set/core/valve/target/repose-valve.jar ${PREFIXDIR}/bin/repose-valve.jar
	${INSTALL_DATA} ${WRKSRC}/project-set/components/filter-bundle/target/filter-bundle-${PORTVERSION}.ear ${PREFIXDIR}/lib/filters/filter-bundle-${PORTVERSION}.ear
	${INSTALL_DATA} ${WRKSRC}/documentation/docbook/target/docbkx/pdf/*.pdf ${PREFIXDIR}/docs/
	${INSTALL_DATA} ${WRKSRC}/documentation/presentations/OpenStack_Essex_2011/*.pdf ${PREFIXDIR}/docs/

.include <bsd.port.mk>
```

Also, figured out how to use a variable in pkg-plist:

```
repose-%%PORTVERSION%%/bin/start-valve.sh
repose-%%PORTVERSION%%/bin/repose-valve.jar
repose-%%PORTVERSION%%/etc/powerapi/container.cfg.xml
repose-%%PORTVERSION%%/etc/powerapi/content-normalization.cfg.xml
repose-%%PORTVERSION%%/etc/powerapi/http-logging.cfg.xml
repose-%%PORTVERSION%%/etc/powerapi/power-proxy.cfg.xml
repose-%%PORTVERSION%%/etc/powerapi/versioning.cfg.xml
repose-%%PORTVERSION%%/lib/filters/filter-bundle-%%PORTVERSION%%.ear
repose-%%PORTVERSION%%/docs/repose-authn-deploy.pdf
repose-%%PORTVERSION%%/docs/repose-glossary.pdf
repose-%%PORTVERSION%%/docs/repose-intro.pdf
repose-%%PORTVERSION%%/docs/repose-logging-deploy.pdf
repose-%%PORTVERSION%%/docs/repose-ratelimiting-deploy.pdf
repose-%%PORTVERSION%%/docs/repose-rootwar-deploy.pdf
repose-%%PORTVERSION%%/docs/repose-versioning-deploy.pdf
repose-%%PORTVERSION%%/docs/ReposePresentation.pdf
@dirrm repose-%%PORTVERSION%%/bin
@dirrm repose-%%PORTVERSION%%/etc/powerapi
@dirrm repose-%%PORTVERSION%%/etc
@dirrm repose-%%PORTVERSION%%/lib/filters
@dirrm repose-%%PORTVERSION%%/lib
@dirrm repose-%%PORTVERSION%%/var/powerapi
@dirrm repose-%%PORTVERSION%%/var
@dirrm repose-%%PORTVERSION%%/logs
@dirrm repose-%%PORTVERSION%%/docs
@dirrm repose-%%PORTVERSION%%
```

When I run [CMD="portlint"][/CMD], I get a couple warnings which I haven't figured out how to get rid of:


```
[root@freebsdvm /usr/ports/java/repose-1.0.6]# portlint -A
WARN: Makefile: only one MASTER_SITE configured.  Consider adding additional mirrors.
WARN: Makefile: "EXTRACT_SUFX" has to appear earlier.
WARN: Makefile: "BUILD_DEPENDS" has to appear earlier.
WARN: Makefile: "RUN_DEPENDS" has to appear earlier.
0 fatal errors and 4 warnings found.
```


----------

