Skip to content
Permalink
Browse files

Allow build-from-source on GNU/Linux without maven repositories (#546)

* sspi: provide ISSPIClient interface

This is needed for GNU/Linux systems at the moment where
waffle-jna.jar is not usually available in a native package
(built-from-source on GNU/Linux).

* pgjdbc: allow limiting build requirements

This commit is aimed to ease the building of pgjdbc from source on
GNU/Linux hosts "offline";  without having  some of the
dependencies installed (otherwise strictly required) and without
some features built-in.

There are two new properties, waffleEnabled and osgiEnabled, both
are set to 'true' by default and are used to turn on/off
corresponding maven profiles.

By specifying '-DwaffleEnabled=false' during maven build we can
build pgjdbc.jar without Windows SSPI authentication support.
By specifying '-DosgiEnabled=false' respectively, you can build
pgjdbc.jar without OSGi Enterprise support.

* pgjdbc: fix indentation to pass syntax check

* ISSPIClient is interface now, SSPIClient implements it Made few changes to respect conventions

* Changed ReflectiveOperationException to Exception since there no support for until Java 7

* travis: add job with disabled osgi and waffle

* pgjdbc: require 1.0.6 parent poms

The v1.0.6 has Waffle/OSGi dependencies optional.

* javadoc: don't generate javadoc for not-compiled packages

This is unfortunate because users who want to build without OSGIi
and without Waffle need to specify yet another compilation flag.

But there is no way to do this automatically when user specifies
'-DwaffleEnabled', the reason is that excludePackageNames accepts
one string (colon or comma separated list of package names), and
we can not edit the excludePackageNames tag twice (firstly for
waffleEnabled and then for osgiEnabled properties) -- the last
excludePackageNames wins.
  • Loading branch information
praiskup authored and davecramer committed May 10, 2016
1 parent fc59851 commit 87489a9974fefbcf0aad9c2869e4dc0e6199b38a
@@ -115,6 +115,14 @@ matrix:
postgresql: "9.1"
env: PG_VERSION=9.1

- jdk: oraclejdk8
addons:
postgresql: "9.4"
env:
- PG_VERSION=9.4
- MVN_CUSTOM_ARGS='-DwaffleEnabled=false -DosgiEnabled=false -DexcludePackageNames=org.postgresql.osgi:org.postgresql.sspi'


# Deploy snapshots to Maven Central
after_success:
- "test $TRAVIS_PULL_REQUEST == 'false' && test $TRAVIS_BRANCH == 'master' && test $PG_VERSION == '9.4' && ./travis_deploy.sh"
@@ -3,7 +3,7 @@
<parent>
<groupId>org.postgresql</groupId>
<artifactId>pgjdbc-core-parent</artifactId>
<version>1.0.5</version>
<version>1.0.6</version>
<relativePath />
</parent>

@@ -113,6 +113,71 @@
</plugins>
</build>
</profile>

<profile>
<id>excludeWaffleFiles</id>
<activation>
<property>
<name>waffleEnabled</name>
<value>false</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes combine.children="append">
<exclude>org/postgresql/sspi/NTDSAPI.java</exclude>
<exclude>org/postgresql/sspi/NTDSAPIWrapper.java</exclude>
<exclude>org/postgresql/sspi/SSPIClient.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>excludeOsgiFiles</id>
<activation>
<property>
<name>osgiEnabled</name>
<value>false</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<excludes combine.children="append">
<exclude>org/postgresql/osgi/PGBundleActivator.java</exclude>
<exclude>org/postgresql/osgi/PGDataSourceFactory.java</exclude>
</excludes>
<testExcludes combine.children="append">
<exclude>**/PGDataSourceFactoryTest.java</exclude>
<exclude>**/OsgiTestSuite.java</exclude>
</testExcludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/OsgiTestSuite.java</exclude>
<exclude>**/PGDataSourceFactoryTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>


</profiles>

<build>
@@ -24,7 +24,7 @@
import org.postgresql.hostchooser.HostChooserFactory;
import org.postgresql.hostchooser.HostRequirement;
import org.postgresql.hostchooser.HostStatus;
import org.postgresql.sspi.SSPIClient;
import org.postgresql.sspi.ISSPIClient;
import org.postgresql.util.GT;
import org.postgresql.util.HostSpec;
import org.postgresql.util.MD5Digest;
@@ -68,6 +68,22 @@
private static class UnsupportedProtocolException extends IOException {
}


private ISSPIClient createSSPI(PGStream pgStream,
String spnServiceClass,
boolean enableNegotiate,
Logger logger) {
Class[] cArg = new Class[]{PGStream.class, String.class, boolean.class, Logger.class};
Class c = null;
try {
c = Class.forName("org.postgresql.sspi.SSPIClient");
return (ISSPIClient) c.getDeclaredConstructor(cArg).newInstance(pgStream, spnServiceClass, enableNegotiate, logger);
} catch (Exception e) {
// This catched quite a lot exceptions, but until Java 7 there is no ReflectiveOperationException
throw new UnsupportedOperationException("You are using jar from Linux distribution or class SPPIClient cannot be loaded");
}
}

public ProtocolConnection openConnectionImpl(HostSpec[] hostSpecs, String user, String database,
Properties info, Logger logger) throws SQLException {
// Extract interesting values from the info properties:
@@ -403,7 +419,7 @@ private void doAuthentication(PGStream pgStream, String host, String user, Prope
String password = PGProperty.PASSWORD.get(info);

/* SSPI negotiation state, if used */
SSPIClient sspiClient = null;
ISSPIClient sspiClient = null;

try {
authloop: while (true) {
@@ -562,7 +578,7 @@ private void doAuthentication(PGStream pgStream, String host, String user, Prope
"Using JSSE GSSAPI, gssapi requested by server and gsslib=sspi not forced");
} else {
/* Determine if SSPI is supported by the client */
sspiClient = new SSPIClient(pgStream, PGProperty.SSPI_SERVICE_CLASS.get(info),
sspiClient = createSSPI(pgStream, PGProperty.SSPI_SERVICE_CLASS.get(info),
/* Use negotiation for SSPI, or if explicitly requested for GSS */
areq == AUTH_REQ_SSPI || (areq == AUTH_REQ_GSS && usespnego), logger);

@@ -0,0 +1,24 @@
package org.postgresql.sspi;

import java.io.IOException;
import java.sql.SQLException;

/**
* Use Waffle-JNI to support SSPI authentication when PgJDBC is running on a Windows
* client and talking to a Windows server.
*
* SSPI is not supported on a non-Windows client.
*
*
* @author pkajaba
*
*/
public interface ISSPIClient {
public boolean isSSPISupported();

public void startSSPI() throws SQLException, IOException;

public void continueSSPI(int msgLength) throws SQLException, IOException;

public void dispose();
}
@@ -26,7 +26,7 @@
*
* @author craig
*/
public class SSPIClient {
public class SSPIClient implements ISSPIClient {

public static String SSPI_DEFAULT_SPN_SERVICE_CLASS = "POSTGRES";

@@ -2,7 +2,7 @@
set -x -e

# Build project
MVN_ARGS="clean package -B -V"
MVN_ARGS="clean package -B -V $MVN_CUSTOM_ARGS"
MVN_PROFILES="release"

if [[ "${COVERAGE}" == *"Y"* ]];
@@ -3,6 +3,7 @@ set -x -e

# Skip tests and checkstype to speed up snapshot deployment
MVN_ARGS="clean deploy -B -V -DskipTests -Dcheckstyle.skip=true -Dskip.assembly=true --settings settings.xml"
MVN_ARGS="$MVN_ARGS $MVN_CUSTOM_ARGS"

if [[ "${TRAVIS_JDK_VERSION}" == *"jdk6"* ]];
then

0 comments on commit 87489a9

Please sign in to comment.
You can’t perform that action at this time.