PR: MNG-613

refactoring to a more consistent interface for metadata

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280186 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-11 22:01:47 +00:00
parent f6cc2c6b9b
commit 27ad44e116
7 changed files with 69 additions and 23 deletions

View File

@ -240,6 +240,9 @@
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -258,6 +261,9 @@
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.manager.WagonManager;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
import org.apache.maven.wagon.TransferFailedException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
@ -38,6 +39,8 @@ public class DefaultArtifactDeployer
private ArtifactTransformationManager transformationManager;
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
*/
@ -71,12 +74,7 @@ public class DefaultArtifactDeployer
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository, deploymentRepository );
// TODO: shouldn't need to calculate this
File f = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
wagonManager.putArtifactMetadata( f, metadata, deploymentRepository );
repositoryMetadataManager.deploy( metadata, localRepository, deploymentRepository );
}
}
catch ( TransferFailedException e )

View File

@ -20,6 +20,7 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.metadata.ArtifactMetadata;
import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
import org.apache.maven.artifact.transform.ArtifactTransformationManager;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.FileUtils;
@ -34,6 +35,8 @@ public class DefaultArtifactInstaller
{
private ArtifactTransformationManager transformationManager;
private RepositoryMetadataManager repositoryMetadataManager;
/**
* @deprecated we want to use the artifact method only, and ensure artifact.file is set correctly.
*/
@ -70,9 +73,7 @@ public class DefaultArtifactInstaller
for ( Iterator i = artifact.getMetadataList().iterator(); i.hasNext(); )
{
ArtifactMetadata metadata = (ArtifactMetadata) i.next();
// TODO: method should be on repository?
metadata.storeInLocalRepository( localRepository, localRepository );
repositoryMetadataManager.install( metadata, localRepository );
}
}
catch ( IOException e )

View File

@ -26,7 +26,6 @@ import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
@ -70,10 +69,14 @@ public abstract class AbstractRepositoryMetadata
{
throw new ArtifactMetadataRetrievalException( "Error updating group repository metadata", e );
}
catch ( XmlPullParserException e )
{
throw new ArtifactMetadataRetrievalException( "Error updating group repository metadata", e );
}
}
protected void updateRepositoryMetadata( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws IOException
throws IOException, XmlPullParserException
{
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
@ -92,18 +95,6 @@ public abstract class AbstractRepositoryMetadata
metadata = mappingReader.read( reader );
}
catch ( FileNotFoundException e )
{
// TODO: Log a warning
}
catch ( IOException e )
{
// TODO: Log a warning
}
catch ( XmlPullParserException e )
{
// TODO: Log a warning
}
finally
{
IOUtil.close( reader );

View File

@ -130,4 +130,28 @@ public class DefaultRepositoryMetadataManager
return cachedMetadata.contains( metadata.getKey() );
}
public void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository deploymentRepository )
throws ArtifactMetadataRetrievalException
{
metadata.storeInLocalRepository( localRepository, deploymentRepository );
// TODO: shouldn't need to calculate this
File f = new File( localRepository.getBasedir(),
localRepository.pathOfLocalRepositoryMetadata( metadata, deploymentRepository ) );
try
{
wagonManager.putArtifactMetadata( f, metadata, deploymentRepository );
}
catch ( TransferFailedException e )
{
// TODO: wrong exception
throw new ArtifactMetadataRetrievalException( "Unable to retrieve metadata", e );
}
}
public void install( ArtifactMetadata metadata, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException
{
metadata.storeInLocalRepository( localRepository, localRepository );
}
}

View File

@ -109,6 +109,9 @@
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>
@ -127,6 +130,9 @@
<requirement>
<role>org.apache.maven.artifact.transform.ArtifactTransformationManager</role>
</requirement>
<requirement>
<role>org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager</role>
</requirement>
</requirements>
</component>

View File

@ -30,4 +30,24 @@ public interface RepositoryMetadataManager
void resolveAlways( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository remoteRepository )
throws ArtifactMetadataRetrievalException;
/**
* Deploy metadata to the remote repository.
*
* @param metadata the metadata to deploy
* @param localRepository the local repository to install to first
* @param deploymentRepository the remote repository to deploy to
*/
void deploy( ArtifactMetadata metadata, ArtifactRepository localRepository,
ArtifactRepository deploymentRepository )
throws ArtifactMetadataRetrievalException;
/**
* Install the metadata in the local repository.
*
* @param metadata the metadata
* @param localRepository the local repository
*/
void install( ArtifactMetadata metadata, ArtifactRepository localRepository )
throws ArtifactMetadataRetrievalException;
}