mirror of https://github.com/apache/maven.git
[MNG-3849] - created Mercury adaptor project
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@749540 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2aabec225e
commit
aece478e1e
|
@ -0,0 +1,82 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>maven</artifactId>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<version>3.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>maven-repository-mercury</artifactId>
|
||||||
|
<name>Mercury Repository </name>
|
||||||
|
<description>Mercury implementation for the Maven Repository System</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<mercury.version>1.0-alpha-6-SNAPSHOT</mercury.version>
|
||||||
|
<plexus.lang.version>1.1</plexus.lang.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-repository</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-container-default</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.mercury</groupId>
|
||||||
|
<artifactId>mercury-plexus</artifactId>
|
||||||
|
<version>${mercury.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.mercury</groupId>
|
||||||
|
<artifactId>mercury-repo-remote-m2</artifactId>
|
||||||
|
<version>${mercury.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-lang</artifactId>
|
||||||
|
<version>${plexus.lang.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-component-metadata</artifactId>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
|
@ -0,0 +1,124 @@
|
||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.maven.repository.mercury;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.DefaultArtifact;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.versioning.ArtifactVersion;
|
||||||
|
import org.apache.maven.artifact.versioning.VersionRange;
|
||||||
|
import org.apache.maven.mercury.artifact.ArtifactBasicMetadata;
|
||||||
|
import org.apache.maven.mercury.artifact.ArtifactMetadata;
|
||||||
|
import org.apache.maven.mercury.builder.api.DependencyProcessor;
|
||||||
|
import org.apache.maven.mercury.repository.api.Repository;
|
||||||
|
import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2;
|
||||||
|
import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2;
|
||||||
|
import org.apache.maven.mercury.transport.api.Server;
|
||||||
|
import org.apache.maven.mercury.util.Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleg Gusakov
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
public class MercuryAdaptor
|
||||||
|
{
|
||||||
|
public static List<Repository> toMercuryRepos( ArtifactRepository localRepository,
|
||||||
|
List<ArtifactRepository> remoteRepositories,
|
||||||
|
DependencyProcessor dependencyProcessor )
|
||||||
|
{
|
||||||
|
if ( localRepository == null && Util.isEmpty( remoteRepositories ) )
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int nRepos =
|
||||||
|
( localRepository == null ? 0 : 1 ) + ( Util.isEmpty( remoteRepositories ) ? 0 : remoteRepositories.size() );
|
||||||
|
|
||||||
|
List<Repository> res = new ArrayList<Repository>( nRepos );
|
||||||
|
|
||||||
|
if ( localRepository != null )
|
||||||
|
{
|
||||||
|
LocalRepositoryM2 lr =
|
||||||
|
new LocalRepositoryM2( localRepository.getId(), new File( localRepository.getBasedir() ),
|
||||||
|
dependencyProcessor );
|
||||||
|
res.add( lr );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !Util.isEmpty( remoteRepositories ) )
|
||||||
|
{
|
||||||
|
for ( ArtifactRepository ar : remoteRepositories )
|
||||||
|
{
|
||||||
|
Server server;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
server = new Server( ar.getId(), new URL( ar.getUrl() ) );
|
||||||
|
}
|
||||||
|
catch ( MalformedURLException e )
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException( e );
|
||||||
|
}
|
||||||
|
RemoteRepositoryM2 rr = new RemoteRepositoryM2( server, dependencyProcessor );
|
||||||
|
|
||||||
|
res.add( rr );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactBasicMetadata toBasicMetadata( Artifact a )
|
||||||
|
{
|
||||||
|
ArtifactBasicMetadata md = new ArtifactBasicMetadata();
|
||||||
|
md.setGroupId( a.getGroupId() );
|
||||||
|
md.setArtifactId( a.getArtifactId() );
|
||||||
|
md.setVersion( a.getVersion() );
|
||||||
|
md.setType( a.getType() );
|
||||||
|
md.setScope( a.getScope() );
|
||||||
|
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArtifactMetadata toMetadata( Artifact a )
|
||||||
|
{
|
||||||
|
ArtifactMetadata md = new ArtifactMetadata();
|
||||||
|
md.setGroupId( a.getGroupId() );
|
||||||
|
md.setArtifactId( a.getArtifactId() );
|
||||||
|
md.setVersion( a.getVersion() );
|
||||||
|
md.setType( a.getType() );
|
||||||
|
md.setScope( a.getScope() );
|
||||||
|
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Artifact toMavenArtifact( org.apache.maven.mercury.artifact.Artifact a )
|
||||||
|
{
|
||||||
|
VersionRange vr = VersionRange.createFromVersion( a.getVersion() );
|
||||||
|
Artifact ma =
|
||||||
|
new DefaultArtifact( a.getGroupId(), a.getArtifactId(), vr, a.getScope(), a.getType(), a.getClassifier(),
|
||||||
|
null );
|
||||||
|
|
||||||
|
return ma;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.maven.repository.mercury;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.maven.artifact.Artifact;
|
||||||
|
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
|
||||||
|
import org.apache.maven.artifact.metadata.ResolutionGroup;
|
||||||
|
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
|
||||||
|
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
|
||||||
|
import org.apache.maven.mercury.artifact.ArtifactMetadata;
|
||||||
|
import org.apache.maven.mercury.builder.api.DependencyProcessor;
|
||||||
|
import org.apache.maven.mercury.plexus.PlexusMercury;
|
||||||
|
import org.apache.maven.mercury.repository.api.Repository;
|
||||||
|
import org.apache.maven.mercury.repository.api.RepositoryException;
|
||||||
|
import org.apache.maven.mercury.repository.local.m2.LocalRepositoryM2;
|
||||||
|
import org.apache.maven.mercury.repository.remote.m2.RemoteRepositoryM2;
|
||||||
|
import org.apache.maven.mercury.transport.api.Server;
|
||||||
|
import org.apache.maven.mercury.util.Util;
|
||||||
|
import org.apache.maven.repository.LegacyMavenRepositorySystem;
|
||||||
|
import org.apache.maven.repository.MavenRepositorySystem;
|
||||||
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
import org.codehaus.plexus.component.annotations.Requirement;
|
||||||
|
import org.codehaus.plexus.lang.DefaultLanguage;
|
||||||
|
import org.codehaus.plexus.lang.Language;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Oleg Gusakov
|
||||||
|
* @version $Id$
|
||||||
|
*/
|
||||||
|
@Component( role = MavenRepositorySystem.class, hint = "mercury" )
|
||||||
|
public class MercuryRepositorySystem
|
||||||
|
extends LegacyMavenRepositorySystem
|
||||||
|
implements MavenRepositorySystem
|
||||||
|
{
|
||||||
|
private static final Language LANG = new DefaultLanguage( MercuryRepositorySystem.class );
|
||||||
|
|
||||||
|
@Requirement( hint = "maven" )
|
||||||
|
DependencyProcessor _dependencyProcessor;
|
||||||
|
|
||||||
|
@Requirement
|
||||||
|
PlexusMercury _mercury;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArtifactResolutionResult resolve( ArtifactResolutionRequest request )
|
||||||
|
{
|
||||||
|
if ( request == null )
|
||||||
|
throw new IllegalArgumentException( LANG.getMessage( "null.request" ) );
|
||||||
|
|
||||||
|
if ( request.getArtifact() == null )
|
||||||
|
throw new IllegalArgumentException( LANG.getMessage( "null.request.artifact" ) );
|
||||||
|
|
||||||
|
ArtifactResolutionResult result = new ArtifactResolutionResult();
|
||||||
|
|
||||||
|
List<Repository> repos =
|
||||||
|
MercuryAdaptor.toMercuryRepos( request.getLocalRepository(), request.getRemoteRepostories(),
|
||||||
|
_dependencyProcessor );
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
List<ArtifactMetadata> mercuryMetadataList =
|
||||||
|
_mercury.resolve( repos, null, MercuryAdaptor.toMetadata( request.getArtifact() ) );
|
||||||
|
|
||||||
|
List<org.apache.maven.mercury.artifact.Artifact> mercuryArtifactList =
|
||||||
|
_mercury.read( repos, mercuryMetadataList );
|
||||||
|
|
||||||
|
if ( !Util.isEmpty( mercuryArtifactList ) )
|
||||||
|
for ( org.apache.maven.mercury.artifact.Artifact a : mercuryArtifactList )
|
||||||
|
result.addArtifact( MercuryAdaptor.toMavenArtifact( a ) );
|
||||||
|
}
|
||||||
|
catch ( RepositoryException e )
|
||||||
|
{
|
||||||
|
result.addErrorArtifactException( new ArtifactResolutionException( e.getMessage(), request.getArtifact(),
|
||||||
|
request.getRemoteRepostories() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository,
|
||||||
|
List<ArtifactRepository> remoteRepositories )
|
||||||
|
throws ArtifactMetadataRetrievalException
|
||||||
|
{
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return super.retrieve( artifact, localRepository, remoteRepositories );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
null.request=null request - too bad
|
||||||
|
null.request.artifact=null artifact in the request - too bad
|
Loading…
Reference in New Issue