private PackageItem compilePackageIfNeeded(String packageName) throws SerializationException {
PackageItem p = repository.loadPackage(packageName);
if (p.isBinaryUpToDate()) {
return p;
} else {
BuilderResult builderResult = packageService.buildPackage(p.getUUID(), true);
if (builderResult != null && !builderResult.getLines().isEmpty()) {
StringBuilder errs = new StringBuilder();
errs.append("Unable to build package name [").append(packageName).append("]\n");
for (BuilderResultLine resultLine : builderResult.getLines()) {
errs.append(resultLine.toString()).append("\n");
}
throw new WebApplicationException(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(errs.toString()).build());
}