Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@
<scope>provided</scope>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-resolver-provider</artifactId>
<scope>provided</scope>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ public ClassLoaderEntriesCalculatorRequest setUseTestClassPath( boolean useTestC
return this;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
*/
package org.apache.tomcat.maven.common.run;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
Expand All @@ -30,16 +39,6 @@
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;


import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
* @author Olivier Lamy
* @since 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@
*/
package org.apache.tomcat.maven.plugin.tomcat;

import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.tomcat.maven.common.deployer.TomcatManager;
import org.apache.tomcat.maven.common.deployer.TomcatManagerException;


import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Map;
import java.util.StringTokenizer;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.crypto.SettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecryptionResult;
import org.apache.tomcat.maven.common.deployer.TomcatManager;
import org.apache.tomcat.maven.common.deployer.TomcatManagerException;

/**
* Abstract goal that provides common configuration for Catalina-based goals.
*
Expand Down Expand Up @@ -64,12 +67,6 @@ public abstract class AbstractCatalinaMojo
// Mojo Parameters
// ----------------------------------------------------------------------

/**
* The Maven Wagon manager to use when obtaining server authentication details.
*/
@Component
private WagonManager wagonManager;

/**
* The full URL of the Tomcat manager instance to use.
*/
Expand Down Expand Up @@ -108,6 +105,16 @@ public abstract class AbstractCatalinaMojo
@Parameter( defaultValue = "${plugin.version}", required = true, readonly = true )
private String version;

// ----------------------------------------------------------------------
// Mojo Components
// ----------------------------------------------------------------------

/**
* Component used to decrypt server passwords from Maven settings.
*/
@Component
protected SettingsDecrypter settingsDecrypter;

// ----------------------------------------------------------------------
// Fields
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -173,7 +180,7 @@ protected TomcatManager getManager()
// lazily instantiate when config values have been injected
if ( manager == null )
{
String userName;
String userName = null;
String password;

if ( server == null )
Expand All @@ -185,24 +192,51 @@ protected TomcatManager getManager()
}
else
{
// obtain authenication details for specified server from wagon
AuthenticationInfo info = wagonManager.getAuthenticationInfo( server );
if ( info == null )
// obtain authentication details for specified server from settings
Server settingsServer = settings.getServer( server );
if ( settingsServer == null )
{
throw new MojoExecutionException(
messagesProvider.getMessage( "AbstractCatalinaMojo.unknownServer", server ) );
}

// derive username
userName = info.getUserName();
if ( userName == null )
// decrypt the server password
String decryptedPassword = null;
Object configObj = settingsServer.getConfiguration();
if ( configObj instanceof Map )
{
@SuppressWarnings("unchecked")
Map<String, Object> config = (Map<String, Object>) configObj;
if ( config.get( "password" ) != null )
{
SettingsDecryptionRequest decryptionRequest =
new DefaultSettingsDecryptionRequest( settingsServer );
SettingsDecryptionResult decryptionResult = settingsDecrypter.decrypt( decryptionRequest );
Object decryptedConfigObj = decryptionResult.getServer().getConfiguration();
if ( decryptedConfigObj instanceof Map )
{
@SuppressWarnings("unchecked")
Map<String, Object> decryptedConfig = (Map<String, Object>) decryptedConfigObj;
if ( decryptedConfig.get( "password" ) != null )
{
decryptedPassword = (String) decryptedConfig.get( "password" );
}
}
}

// derive username
if ( config.get( "username" ) != null )
{
userName = (String) config.get( "username" );
}
}
if ( userName == null || userName.isEmpty() )
{
getLog().debug( messagesProvider.getMessage( "AbstractCatalinaMojo.defaultUserName" ) );
userName = DEFAULT_USERNAME;
}

// derive password
password = info.getPassword();
password = decryptedPassword;
if ( password == null )
{
getLog().debug( messagesProvider.getMessage( "AbstractCatalinaMojo.defaultPassword" ) );
Expand Down Expand Up @@ -275,4 +309,4 @@ protected void log( String string )
getLog().info( tokenizer.nextToken() );
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@
import org.apache.commons.compress.archivers.jar.JarArchiveEntry;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -59,6 +57,10 @@
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.util.DirectoryScanner;
import org.codehaus.plexus.util.SelectorUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.resolution.ArtifactRequest;
import org.eclipse.aether.resolution.ArtifactResolutionException;
import org.eclipse.aether.resolution.ArtifactResult;

/**
* @author Olivier Lamy
Expand Down Expand Up @@ -120,14 +122,13 @@ public abstract class AbstractExecWarMojo
@Parameter
protected List<WarRunDependency> warRunDependencies;

@Component
protected ArtifactResolver artifactResolver;

/**
* Maven Artifact Factory component.
* Used to resolve artifacts using Eclipse Aether.
*/
@Component
protected ArtifactFactory artifactFactory;
protected org.eclipse.aether.RepositorySystem artifactResolver;



/**
* Location of the local repository.
Expand All @@ -136,11 +137,76 @@ public abstract class AbstractExecWarMojo
protected ArtifactRepository local;

/**
* List of Remote Repositories used by the resolver
* List of Remote Repositories used by the resolver.
*/
@Parameter( defaultValue = "${project.remoteArtifactRepositories}", required = true, readonly = true )
protected List<ArtifactRepository> remoteRepos;

protected List<org.eclipse.aether.repository.RemoteRepository> convertToRemoteRepositories( List<ArtifactRepository> mavenRepos )
{
List<org.eclipse.aether.repository.RemoteRepository> remoteRepos = new ArrayList<>();
for ( ArtifactRepository repo : mavenRepos )
{
remoteRepos.add( new org.eclipse.aether.repository.RemoteRepository.Builder( repo.getId(), "default", repo.getUrl() ).build() );
}
return remoteRepos;
}

protected Artifact resolveArtifact( String groupId, String artifactId, String version, String type,
String classifier, String scope )
throws MojoExecutionException
{
try
{
org.eclipse.aether.artifact.DefaultArtifact aetherArtifact = new org.eclipse.aether.artifact.DefaultArtifact(
groupId,
artifactId,
classifier != null && !classifier.isEmpty() ? classifier : null,
type != null && !type.isEmpty() ? type : "jar",
version
);
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( aetherArtifact );
artifactRequest.setRepositories( convertToRemoteRepositories( remoteRepos ) );

org.eclipse.aether.RepositorySystemSession repoSession = new DefaultRepositorySystemSession( session.getRepositorySession() );
ArtifactResult result = artifactResolver.resolveArtifact( repoSession, artifactRequest );
org.eclipse.aether.artifact.Artifact resolved = result.getArtifact();

if ( resolved != null && resolved.getFile() != null )
{
// Use DefaultArtifact to create a Maven Artifact from the resolved info
return new DefaultArtifact(
resolved.getGroupId(),
resolved.getArtifactId(),
resolved.getVersion(),
scope != null && !scope.isEmpty() ? scope : Artifact.SCOPE_COMPILE,
resolved.getExtension(),
resolved.getExtension(),
new DefaultArtifactHandler()
);
}
}
catch ( ArtifactResolutionException e )
{
throw new MojoExecutionException( "Unable to resolve artifact: " + groupId + ":" + artifactId
+ ":" + version, e );
}

return new DefaultArtifact(
groupId,
artifactId,
version,
scope != null && !scope.isEmpty() ? scope : Artifact.SCOPE_COMPILE,
type != null && !type.isEmpty() ? type : "jar",
classifier,
new DefaultArtifactHandler()
);
}

@Parameter( defaultValue = "${session}", readonly = true, required = true )
protected MavenSession session;

@Component
protected MavenProjectHelper projectHelper;

Expand Down Expand Up @@ -324,13 +390,12 @@ else if ( warRunDependencies != null && !warRunDependencies.isEmpty() )
"Dependency '" + dependency.getGroupId() + "':'" + dependency.getArtifactId()
+ "' does not have version specified" );
}
Artifact artifact = artifactFactory.createArtifactWithClassifier( dependency.getGroupId(), //
dependency.getArtifactId(), //
version, //
dependency.getType(), //
dependency.getClassifier() );

artifactResolver.resolve( artifact, this.remoteRepos, this.local );
Artifact artifact = resolveArtifact( dependency.getGroupId(), //
dependency.getArtifactId(), //
version, //
dependency.getType(), //
dependency.getClassifier(), //
null );

File warFileToBundle = new File( resolvePluginWorkDir(), artifact.getFile().getName() );
FileUtils.copyFile( artifact.getFile(), warFileToBundle );
Expand Down Expand Up @@ -416,13 +481,12 @@ else if ( warRunDependencies != null && !warRunDependencies.isEmpty() )
}

// String groupId, String artifactId, String version, String scope, String type
Artifact artifact = artifactFactory.createArtifact( dependency.getGroupId(), //
dependency.getArtifactId(), //
version, //
dependency.getScope(), //
dependency.getType() );

artifactResolver.resolve( artifact, this.remoteRepos, this.local );
Artifact artifact = resolveArtifact( dependency.getGroupId(), //
dependency.getArtifactId(), //
version, //
dependency.getType(), //
null, //
dependency.getScope() );
JarFile jarFile = new JarFile( artifact.getFile() );
extractJarToArchive( jarFile, os, this.excludes );
}
Expand Down Expand Up @@ -480,7 +544,7 @@ else if ( warRunDependencies != null && !warRunDependencies.isEmpty() )
}

}
catch (ManifestException | IOException | ArtifactNotFoundException | ArtifactResolutionException e )
catch ( ManifestException | IOException e )
{
throw new MojoExecutionException( e.getMessage(), e );
}
Expand Down
Loading