From 06a2320619cd37d1b7daf4fb43f63b1578f6fe7e Mon Sep 17 00:00:00 2001 From: Vincent Cantin Date: Sun, 28 Jul 2013 02:21:43 +0800 Subject: [PATCH] Clean up the source code here and there. --- README.md | 2 +- build.gradle | 10 ++-- .../auth/maven/AuthenticationManager.java | 2 +- .../maven/LegacyAuthenticationHandler.java | 10 ++-- .../PublishingAuthenticationHandler.java | 7 +-- .../RepositoryAuthenticationHandler.java | 48 ++++++++++++++----- 6 files changed, 56 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index cb7e6f9..3d6da50 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Support for the new Gradle Publication DSL ------------------------------------------ One of the new (and still ongoing and incubating) developments in Gradle is the new Publication DSL as the means for -declaring how your project artifacts are pulished. See the Gradle UserGuide for more information. +declaring how your project artifacts are published. See the Gradle UserGuide for more information. The "bridge" between Maven authentication credentials and Gradle is the repository id. For an example, lets assume you have a Maven settings.xml that defines the following credentials: diff --git a/build.gradle b/build.gradle index 163f4b5..7fd04ac 100644 --- a/build.gradle +++ b/build.gradle @@ -28,8 +28,6 @@ dependencies { compile 'dom4j:dom4j:1.6.1@jar' compile 'org.sonatype.plexus:plexus-sec-dispatcher:1.3' runtime 'org.codehaus.plexus:plexus-container-default:1.0.0' - - groovy localGroovy() } idea { @@ -62,10 +60,10 @@ task sourceJar(type: Jar, dependsOn: compileJava) { // This is the kind of malarkey this plugin tries to address ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ( ! hasProperty( "JBOSS_REPO_USER" ) ) { - JBOSS_REPO_USER = ""; + ext.JBOSS_REPO_USER = ""; } if ( ! hasProperty( "JBOSS_REPO_PASS" ) ) { - JBOSS_REPO_PASS = ""; + ext.JBOSS_REPO_PASS = ""; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -130,3 +128,7 @@ publishing { task wrapper(type: Wrapper) { gradleVersion = '1.5' } + +tasks.withType(Compile) { + options.compilerArgs << "-Xlint:unchecked" +} diff --git a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager.java b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager.java index 75cf901..ad0feea 100644 --- a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager.java +++ b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager.java @@ -43,6 +43,6 @@ public void apply(final Project project) { legacyHandler.applyTo( project ); final RepositoryAuthenticationHandler repositoryHandler = new RepositoryAuthenticationHandler( registry ); - repositoryHandler.applyTo(project); + repositoryHandler.applyTo( project ); } } diff --git a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/LegacyAuthenticationHandler.java b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/LegacyAuthenticationHandler.java index 7b3a4fb..8d9568f 100644 --- a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/LegacyAuthenticationHandler.java +++ b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/LegacyAuthenticationHandler.java @@ -54,7 +54,7 @@ public void applyTo(Project project) { project.getTasks().withType( Upload.class ).all( new Action() { @Override - @SuppressWarnings( {"unchecked"}) + @SuppressWarnings( {"unchecked"} ) public void execute(final Upload uploadTask) { if ( ! uploadTask.getRepositories().withType( MavenDeployer.class ).isEmpty() ) { uploadTask.doFirst( authAction ); @@ -68,6 +68,7 @@ public void execute(final Upload uploadTask) { public void execute(Upload upload) { upload.getRepositories().withType( MavenDeployer.class ).all( new Action() { + @Override public void execute(MavenDeployer deployer) { final Object repositoryDelegate = deployer.getRepository(); if ( repositoryDelegate != null ) { @@ -206,6 +207,7 @@ public Method idGetterMethod() { return idGetterMethod; } + @SuppressWarnings( {"unchecked"} ) private Method locateIdGetterMethod() { try { return getRemoteRepositoryClass().getMethod( "getId" ); @@ -224,6 +226,7 @@ public Method urlGetterMethod() { return urlGetterMethod; } + @SuppressWarnings( {"unchecked"} ) private Method locateUrlGetterMethod() { try { return getRemoteRepositoryClass().getMethod( "getUrl" ); @@ -242,6 +245,7 @@ private Method authenticationAdderMethod() { return addAuthenticationMethod; } + @SuppressWarnings( {"unchecked"} ) private Method locateAuthenticationAdderMethod() { try { return getRemoteRepositoryClass().getMethod( "addAuthentication", getAuthClass() ); @@ -345,14 +349,14 @@ private Method locatePassphraseSetter() { private static final String AUTH_CLASS_NAME = "org.apache.maven.artifact.ant.Authentication"; private Class authClass; - public Class getAuthClass() { + public Class getAuthClass() { if ( authClass == null ) { authClass = locateAuthClass(); } return authClass; } - private Class locateAuthClass() { + private Class locateAuthClass() { try { return classLoader.loadClass( AUTH_CLASS_NAME ); } diff --git a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/PublishingAuthenticationHandler.java b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/PublishingAuthenticationHandler.java index 106da80..1a6290a 100644 --- a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/PublishingAuthenticationHandler.java +++ b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/PublishingAuthenticationHandler.java @@ -26,7 +26,7 @@ import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; -import org.gradle.api.plugins.ExtraPropertiesExtension; +import org.gradle.api.artifacts.repositories.PasswordCredentials; import org.gradle.api.publish.maven.tasks.PublishToMavenRepository; /** @@ -64,8 +64,9 @@ public void execute(PublishToMavenRepository publishToMavenRepository) { return; } - publishToMavenRepository.getRepository().getCredentials().setUsername( credentials.getUserName() ); - publishToMavenRepository.getRepository().getCredentials().setPassword( credentials.getPassword() ); + PasswordCredentials passwordCredentials = publishToMavenRepository.getRepository().getCredentials(); + passwordCredentials.setUsername( credentials.getUserName() ); + passwordCredentials.setPassword( credentials.getPassword() ); } private Credentials locateAuthenticationCredentials(String repositoryId) { diff --git a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/RepositoryAuthenticationHandler.java b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/RepositoryAuthenticationHandler.java index 79c3825..41a57ae 100644 --- a/src/main/java/org/hibernate/build/gradle/publish/auth/maven/RepositoryAuthenticationHandler.java +++ b/src/main/java/org/hibernate/build/gradle/publish/auth/maven/RepositoryAuthenticationHandler.java @@ -1,9 +1,37 @@ +/* + * 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.publish.auth.maven; import org.gradle.api.Action; import org.gradle.api.Project; import org.gradle.api.artifacts.repositories.MavenArtifactRepository; +import org.gradle.api.artifacts.repositories.PasswordCredentials; +/** + * + * @author Artur Kotyrba + */ public class RepositoryAuthenticationHandler implements Action { private final CredentialsProviderRegistry credentialsProviderRegistry; @@ -12,31 +40,29 @@ public RepositoryAuthenticationHandler(CredentialsProviderRegistry credentialsPr } public void applyTo(Project project) { - project.getRepositories().withType(MavenArtifactRepository.class).all(this); + project.getRepositories().withType( MavenArtifactRepository.class ).all( this ); } @Override public void execute(MavenArtifactRepository mavenArtifactRepository) { final String id = mavenArtifactRepository.getName(); - final Credentials credentials = locateAuthenticationCredentials(id); - - if (credentials == null) { + final Credentials credentials = locateAuthenticationCredentials( id ); + if ( credentials == null ) { return; } - mavenArtifactRepository.getCredentials().setUsername(credentials.getUserName()); - mavenArtifactRepository.getCredentials().setPassword(credentials.getPassword()); + PasswordCredentials passwordCredentials = mavenArtifactRepository.getCredentials(); + passwordCredentials.setUsername( credentials.getUserName() ); + passwordCredentials.setPassword( credentials.getPassword() ); } private Credentials locateAuthenticationCredentials(String repositoryId) { - for (CredentialsProvider provider : credentialsProviderRegistry.providers()) { - Credentials authentication = provider.determineAuthentication(repositoryId); - - if (authentication != null) { + for ( CredentialsProvider provider : credentialsProviderRegistry.providers() ) { + Credentials authentication = provider.determineAuthentication( repositoryId ); + if ( authentication != null ) { return authentication; } } - return null; } }