Skip to content

Commit

Permalink
Refactor code to improve separation of Maven APIs and Aether code. Al…
Browse files Browse the repository at this point in the history
…l transfer internal Maven3x implementations should not use (close to) any Maven Core code, only a few classes are allowed.
  • Loading branch information
rfscholte committed Oct 27, 2019
1 parent cec0cf9 commit d23716a
Show file tree
Hide file tree
Showing 28 changed files with 778 additions and 484 deletions.
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
<url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url>
</site>
</distributionManagement>

<properties>
<javaVersion>7</javaVersion>
</properties>

<build>
<plugins>
Expand Down Expand Up @@ -83,7 +87,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.15</version>
<version>1.18</version>
<executions>
<execution>
<id>sniff</id>
Expand All @@ -94,10 +98,13 @@
</execution>
</executions>
<configuration>
<ignores>
<ignore>java.lang.invoke.MethodHandle</ignore>
</ignores>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java16</artifactId>
<version>1.1</version>
<artifactId>java17</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
Expand All @@ -110,7 +117,7 @@
<configuration>
<rules>
<enforceBytecodeVersion>
<maxJdkVersion>1.6</maxJdkVersion>
<maxJdkVersion>1.${javaVersion}</maxJdkVersion>
</enforceBytecodeVersion>
</rules>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public void deploy( ProjectBuildingRequest request, Collection<Artifact> mavenAr

try
{
String hint = isMaven31() ? "maven31" : "maven3";

ArtifactDeployer effectiveArtifactDeployer = container.lookup( ArtifactDeployer.class, hint );

effectiveArtifactDeployer.deploy( request, mavenArtifacts );
getMavenArtifactDeployer( request ).deploy( mavenArtifacts );
}
catch ( ComponentLookupException e )
{
Expand All @@ -72,11 +68,7 @@ public void deploy( ProjectBuildingRequest request, ArtifactRepository remoteRep
validateParameters( request, mavenArtifacts );
try
{
String hint = isMaven31() ? "maven31" : "maven3";

ArtifactDeployer effectiveArtifactDeployer = container.lookup( ArtifactDeployer.class, hint );

effectiveArtifactDeployer.deploy( request, remoteRepository, mavenArtifacts );
getMavenArtifactDeployer( request ).deploy( remoteRepository, mavenArtifacts );
}
catch ( ComponentLookupException e )
{
Expand Down Expand Up @@ -133,4 +125,29 @@ public void contextualize( Context context )
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}

private MavenArtifactDeployer getMavenArtifactDeployer( ProjectBuildingRequest buildingRequest )
throws ComponentLookupException, ArtifactDeployerException
{
if ( isMaven31() )
{
org.eclipse.aether.RepositorySystem repositorySystem =
container.lookup( org.eclipse.aether.RepositorySystem.class );

org.eclipse.aether.RepositorySystemSession session =
(org.eclipse.aether.RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

return new Maven31ArtifactDeployer( repositorySystem, session );
}
else
{
org.sonatype.aether.RepositorySystem repositorySystem =
container.lookup( org.sonatype.aether.RepositorySystem.class );

org.sonatype.aether.RepositorySystemSession session =
(org.sonatype.aether.RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

return new Maven30ArtifactDeployer( repositorySystem, session );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
import org.apache.maven.shared.transfer.metadata.internal.Maven30MetadataBridge;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.sonatype.aether.RepositorySystem;
import org.sonatype.aether.RepositorySystemSession;
import org.sonatype.aether.artifact.Artifact;
Expand All @@ -43,33 +39,35 @@
/**
*
*/
@Component( role = ArtifactDeployer.class, hint = "maven3" )
class Maven30ArtifactDeployer
implements ArtifactDeployer
implements MavenArtifactDeployer
{

@Requirement
private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

private final RepositorySystemSession session;

Maven30ArtifactDeployer( RepositorySystem repositorySystem, RepositorySystemSession session )
{
this.repositorySystem = repositorySystem;
this.session = session;
}

@Override
public void deploy( ProjectBuildingRequest buildingRequest,
Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
public void deploy( Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
throws ArtifactDeployerException
{
deploy( buildingRequest, null, mavenArtifacts );
deploy( null, mavenArtifacts );
}

@Override
public void deploy( ProjectBuildingRequest buildingRequest, ArtifactRepository remoteRepository,
public void deploy( ArtifactRepository remoteRepository,
Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
throws ArtifactDeployerException
{
// prepare request
DeployRequest request = new DeployRequest();

RepositorySystemSession session =
(RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

RemoteRepository defaultRepository = null;

if ( remoteRepository != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.ArtifactRepositoryMetadata;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.project.artifact.ProjectArtifactMetadata;
import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployer;
import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;
import org.apache.maven.shared.transfer.metadata.internal.Maven31MetadataBridge;
import org.codehaus.plexus.component.annotations.Component;
import org.codehaus.plexus.component.annotations.Requirement;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.artifact.Artifact;
Expand All @@ -43,33 +39,36 @@
/**
*
*/
@Component( role = ArtifactDeployer.class, hint = "maven31" )
class Maven31ArtifactDeployer
implements ArtifactDeployer
implements MavenArtifactDeployer
{

@Requirement
private RepositorySystem repositorySystem;
private final RepositorySystem repositorySystem;

private final RepositorySystemSession session;

Maven31ArtifactDeployer( RepositorySystem repositorySystem, RepositorySystemSession session )
{
super();
this.repositorySystem = repositorySystem;
this.session = session;
}

@Override
public void deploy( ProjectBuildingRequest buildingRequest,
Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
public void deploy( Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
throws ArtifactDeployerException
{
deploy( buildingRequest, null, mavenArtifacts );
deploy( null, mavenArtifacts );
}

/** {@inheritDoc} */
public void deploy( ProjectBuildingRequest buildingRequest, ArtifactRepository remoteRepository,
@Override
public void deploy( ArtifactRepository remoteRepository,
Collection<org.apache.maven.artifact.Artifact> mavenArtifacts )
throws ArtifactDeployerException
{
// prepare request
DeployRequest request = new DeployRequest();

RepositorySystemSession session =
(RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

RemoteRepository defaultRepository = null;

if ( remoteRepository != null )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.apache.maven.shared.transfer.artifact.deploy.internal;

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import java.util.Collection;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.shared.transfer.artifact.deploy.ArtifactDeployerException;

/**
*
* @author Robert Scholte
*
*/
public interface MavenArtifactDeployer
{

void deploy( Collection<Artifact> mavenArtifacts )
throws ArtifactDeployerException;

void deploy( ArtifactRepository remoteRepository, Collection<Artifact> mavenArtifacts )
throws ArtifactDeployerException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.transfer.artifact.install.ArtifactInstaller;
import org.apache.maven.shared.transfer.artifact.install.ArtifactInstallerException;
import org.apache.maven.shared.transfer.repository.RepositoryManager;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.annotations.Component;
Expand All @@ -41,8 +42,9 @@
class DefaultArtifactInstaller
implements ArtifactInstaller, Contextualizable
{

private PlexusContainer container;

private RepositoryManager repositoryManager;

@Override
public void install( ProjectBuildingRequest request, Collection<Artifact> mavenArtifacts )
Expand All @@ -51,11 +53,7 @@ public void install( ProjectBuildingRequest request, Collection<Artifact> mavenA
validateParameters( request, mavenArtifacts );
try
{
String hint = isMaven31() ? "maven31" : "maven3";

ArtifactInstaller effectiveArtifactInstaller = container.lookup( ArtifactInstaller.class, hint );

effectiveArtifactInstaller.install( request, mavenArtifacts );
getMavenArtifactInstaller( request ).install( mavenArtifacts );
}
catch ( ComponentLookupException e )
{
Expand All @@ -78,14 +76,13 @@ public void install( ProjectBuildingRequest request, File localRepositry, Collec
}

// TODO: Should we check for exists() ?

// update local repo in request
ProjectBuildingRequest newRequest = repositoryManager.setLocalRepositoryBasedir( request, localRepositry );

try
{
String hint = isMaven31() ? "maven31" : "maven3";

ArtifactInstaller effectiveArtifactInstaller = container.lookup( ArtifactInstaller.class, hint );

effectiveArtifactInstaller.install( request, localRepositry, mavenArtifacts );
getMavenArtifactInstaller( newRequest ).install( mavenArtifacts );
}
catch ( ComponentLookupException e )
{
Expand Down Expand Up @@ -142,4 +139,29 @@ public void contextualize( Context context )
{
container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}

private MavenArtifactInstaller getMavenArtifactInstaller( ProjectBuildingRequest buildingRequest )
throws ComponentLookupException, ArtifactInstallerException
{
if ( isMaven31() )
{
org.eclipse.aether.RepositorySystem repositorySystem =
container.lookup( org.eclipse.aether.RepositorySystem.class );

org.eclipse.aether.RepositorySystemSession session =
(org.eclipse.aether.RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

return new Maven31ArtifactInstaller( repositorySystem, session );
}
else
{
org.sonatype.aether.RepositorySystem repositorySystem =
container.lookup( org.sonatype.aether.RepositorySystem.class );

org.sonatype.aether.RepositorySystemSession session =
(org.sonatype.aether.RepositorySystemSession) Invoker.invoke( buildingRequest, "getRepositorySession" );

return new Maven30ArtifactInstaller( repositorySystem, session );
}
}
}
Loading

0 comments on commit d23716a

Please sign in to comment.