diff --git a/build.gradle b/build.gradle
index 113337409a..78846a521d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -10,6 +10,17 @@ allprojects {
}
}
+buildscript {
+ repositories {
+ mavenLocal()
+ mavenRepo name: 'jboss-nexus', urls: "https://repository.jboss.org/nexus/content/groups/public/"
+ mavenRepo name: "jboss-snapshots", urls: "http://snapshots.jboss.org/maven2/"
+ }
+ dependencies {
+ classpath 'org.hibernate.build.gradle:gradle-upload-auth-plugin:1.0.0'
+ }
+}
+
ideaProject {
javaVersion = "1.6"
withXml { provider ->
@@ -86,11 +97,11 @@ subprojects { subProject ->
// minimize changes, at least for now (gradle uses 'build' by default)..
buildDir = "target"
-
+
if ( ! subProject.name.startsWith( 'release' ) ) {
apply plugin: 'java'
apply plugin: 'maven' // for install task as well as deploy dependencies
- apply plugin: org.hibernate.build.gradle.upload.UploadAuthenticationManager
+ apply plugin: 'uploadAuth'
configurations {
provided {
diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java
deleted file mode 100644
index 4bd52c860f..0000000000
--- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationHandler.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-
-package org.hibernate.build.gradle.upload;
-
-import org.apache.maven.artifact.ant.Authentication;
-import org.apache.maven.artifact.ant.RemoteRepository;
-import org.gradle.api.Action;
-import org.gradle.api.DefaultTask;
-import org.gradle.api.artifacts.maven.MavenDeployer;
-import org.gradle.api.tasks.TaskAction;
-import org.gradle.api.tasks.Upload;
-
-/**
- * Acts as the main authentication coordinator for the upload. It will delegate to all {@link AuthenticationProvider}
- * instances registered with the {@link AuthenticationProviderRegistry} looking for any that provide
- * {@link Authentication} against the given {@link RemoteRepository} defined for each upload task.
- *
- * IMPL NOTE : This will need to change drastically whenever Gradle moves to its {@code Publication} scheme for uploads.
- *
- * @author Steve Ebersole
- */
-public class AuthenticationHandler extends DefaultTask {
- private AuthenticationProviderRegistry authenticationProviderRegistry;
- private Upload uploadTask;
-
- public void injectProviderRegistry(AuthenticationProviderRegistry authenticationProviderRegistry) {
- this.authenticationProviderRegistry = authenticationProviderRegistry;
- }
-
- public void injectUploadTask(Upload uploadTask) {
- this.uploadTask = uploadTask;
- }
-
- @TaskAction
- public void configureUploadAuthentication() {
- // todo : unfortunately I have no idea how to apply this to non MavenDeployer-type repos...
- uploadTask.getRepositories().withType( MavenDeployer.class ).all(
- new Action() {
- public void execute(MavenDeployer deployer) {
- final RemoteRepository repository = deployer.getRepository();
- if ( repository != null ) {
- final Authentication authentication = locateAuthenticationDetails( repository );
- if ( authentication != null ) {
- repository.addAuthentication( authentication );
- }
- }
- final RemoteRepository snapshotRepository = deployer.getSnapshotRepository();
- if ( snapshotRepository != null ) {
- final Authentication authentication = locateAuthenticationDetails( snapshotRepository );
- if ( authentication != null ) {
- snapshotRepository.addAuthentication( authentication );
- }
- }
- }
- }
- );
- }
-
- private Authentication locateAuthenticationDetails(RemoteRepository repository) {
- for ( AuthenticationProvider provider : authenticationProviderRegistry.providers() ) {
- Authentication authentication = provider.determineAuthentication( repository );
- if ( authentication != null ) {
- return authentication;
- }
- }
- return null;
- }
-}
diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java
deleted file mode 100644
index 26c592a4bb..0000000000
--- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProvider.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.build.gradle.upload;
-
-import org.apache.maven.artifact.ant.Authentication;
-import org.apache.maven.artifact.ant.RemoteRepository;
-
-/**
- * Contract for providers of {@link Authentication} details for authenticating against remote repositories.
- *
- * @author Steve Ebersole
- */
-public interface AuthenticationProvider {
- /**
- * The contract method. Given a repository, determine the {@link Authentication} according to this provider's
- * contract. Return {@literal null} to indicate no {@link Authentication} applied for this repository by this
- * provider.
- *
- * @param remoteRepository The repository to check for authentication details.
- *
- * @return The authentication details, or {@literal null} to indicate none.
- */
- public Authentication determineAuthentication(RemoteRepository remoteRepository);
-}
diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java
deleted file mode 100644
index 13590a5cf0..0000000000
--- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/AuthenticationProviderRegistry.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.build.gradle.upload;
-
-import java.util.LinkedList;
-
-/**
- * A registry of {@link AuthenticationProvider} instances.
- *
- * @author Steve Ebersole
- */
-public class AuthenticationProviderRegistry {
- private final LinkedList authenticationProviders = buildStandardAuthenticationProviders();
-
- private static LinkedList buildStandardAuthenticationProviders() {
- LinkedList providers = new LinkedList();
- providers.add( new StandardMavenAuthenticationProvider() );
- return providers;
- }
-
- public void appendAuthenticationProvider(AuthenticationProvider provider) {
- authenticationProviders.addLast( provider );
- }
-
- public void prependAuthenticationProvider(AuthenticationProvider provider) {
- authenticationProviders.addFirst( provider );
- }
-
- public Iterable providers() {
- return authenticationProviders;
- }
-}
diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java
deleted file mode 100644
index 6b68b72a92..0000000000
--- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/StandardMavenAuthenticationProvider.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.build.gradle.upload;
-
-import org.apache.maven.artifact.ant.Authentication;
-import org.apache.maven.artifact.ant.RemoteRepository;
-import org.dom4j.Document;
-import org.dom4j.DocumentException;
-import org.dom4j.Element;
-import org.dom4j.io.SAXReader;
-import org.xml.sax.InputSource;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.util.Iterator;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Provider of {@link org.apache.maven.artifact.ant.RemoteRepository} {@link Authentication} based on standard Maven
- * conventions using {@literal settings.xml}.
- *
- * @author Steve Ebersole
- */
-public class StandardMavenAuthenticationProvider implements AuthenticationProvider {
- private static final Logger log = LoggerFactory.getLogger( StandardMavenAuthenticationProvider.class );
-
- public static final String SETTINGS_LOCATION_OVERRIDE = "maven.settings";
-
- private ConcurrentHashMap repositoryAuthenticationMap;
-
- @Override
- public Authentication determineAuthentication(RemoteRepository remoteRepository) {
- if ( repositoryAuthenticationMap == null ) {
- loadRepositoryAuthenticationMap();
- }
-
- return repositoryAuthenticationMap.get( remoteRepository.getId() );
- }
-
- private void loadRepositoryAuthenticationMap() {
- repositoryAuthenticationMap = new ConcurrentHashMap();
-
- final File settingsFile = determineSettingsFileLocation();
- try {
- InputSource inputSource = new InputSource( new FileInputStream( settingsFile ) );
- try {
- final Document document = buildSAXReader().read( inputSource );
- final Element settingsElement = document.getRootElement();
- final Element serversElement = settingsElement.element( "servers" );
- final Iterator serversIterator = serversElement.elementIterator( "server" );
- while ( serversIterator.hasNext() ) {
- final Element serverElement = (Element) serversIterator.next();
- final String id = extractValue( serverElement.element( "id" ) );
- if ( id == null ) {
- continue;
- }
- final Authentication authentication = new Authentication();
- authentication.setUserName( extractValue( serverElement.element( "username" ) ) );
- authentication.setPassword( extractValue( serverElement.element( "password" ) ) );
- authentication.setPrivateKey( extractValue( serverElement.element( "privateKey" ) ) );
- authentication.setPassphrase( extractValue( serverElement.element( "passphrase" ) ) );
- repositoryAuthenticationMap.put( id, authentication );
- }
- }
- catch (DocumentException e) {
- log.error( "Error reading Maven settings.xml", e );
- }
- }
- catch ( FileNotFoundException e ) {
- log.info( "Unable to locate Maven settings.xml" );
- }
- }
-
- private String extractValue(Element element) {
- if ( element == null ) {
- return null;
- }
-
- final String value = element.getTextTrim();
- if ( value != null && value.length() == 0 ) {
- return null;
- }
-
- return value;
- }
-
- private SAXReader buildSAXReader() {
- SAXReader saxReader = new SAXReader();
- saxReader.setMergeAdjacentText( true );
- return saxReader;
- }
-
- private File determineSettingsFileLocation() {
- final String overrideLocation = System.getProperty( SETTINGS_LOCATION_OVERRIDE );
- return overrideLocation == null
- ? new File( new File( System.getProperty( "user.home" ), ".m2" ), "settings.xml" )
- : new File( overrideLocation );
- }
-}
diff --git a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java b/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java
deleted file mode 100644
index 2c8909fece..0000000000
--- a/buildSrc/src/main/java/org/hibernate/build/gradle/upload/UploadAuthenticationManager.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
- * indicated by the @author tags or express copyright attribution
- * statements applied by the authors. All third-party contributions are
- * distributed under license by Red Hat Inc.
- *
- * This copyrighted material is made available to anyone wishing to use, modify,
- * copy, or redistribute it subject to the terms and conditions of the GNU
- * Lesser General Public License, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
- * for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this distribution; if not, write to:
- * Free Software Foundation, Inc.
- * 51 Franklin Street, Fifth Floor
- * Boston, MA 02110-1301 USA
- */
-package org.hibernate.build.gradle.upload;
-
-import org.gradle.api.Action;
-import org.gradle.api.Plugin;
-import org.gradle.api.Project;
-import org.gradle.api.tasks.Upload;
-
-/**
- * Manages authentication aspects of artifact uploading by delegation to registered {@link AuthenticationProvider}
- * instances.
- *
- * @author Steve Ebersole
- */
-public class UploadAuthenticationManager implements Plugin {
-
- @Override
- public void apply(final Project project) {
- // todo : ideally the registry would be handled by a convention to allow configuration (aka, adding more providers)...
- // for our purposes here in Hibernate we only care about the Maven settings.xml based way so we
- // code for just that.
- final AuthenticationProviderRegistry registry = new AuthenticationProviderRegistry();
-
- project.getTasks().withType( Upload.class ).all(
- new Action() {
- @Override
- public void execute(final Upload uploadTask) {
- // create a auth task for each upload task...
- final AuthenticationHandler authenticationHandler = project.getTasks().add(
- "uploadAuthenticationHandler-" + uploadTask.getName(),
- AuthenticationHandler.class
- );
-
- // link the auth task with the upload task
- authenticationHandler.injectUploadTask( uploadTask );
-
- // todo: Also in conjunction, would be best to have the handler lookup the registry rather than pushing it
- authenticationHandler.injectProviderRegistry( registry );
-
- uploadTask.getDependsOn().add( authenticationHandler );
- }
- }
- );
- }
-
-}