public void convertRepositoryFormatFor( Artifact artifact, ApplicationConfig applicationConfig,
Repository repository, File mavenRepository )
throws IOException, NPandayRepositoryException
{
ProjectDao dao = (ProjectDao) daoRegistry.find( "dao:project" );
dao.init( artifactFactory, artifactResolver );
dao.setRdfRepository( repository );
dao.openConnection();
Project project;
try
{
project = dao.getProjectFor( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
artifact.getType(), artifact.getClassifier() );
}
catch( ProjectDaoException e )
{
throw new NPandayRepositoryException( "NPANDAY-190-005: An error occurred while retrieving projects.", e );
}
logger.finest( "NPANDAY-190-002: Converting Project: Artifact ID = " + project.getArtifactId() +
", Dependency Count =" + project.getProjectDependencies().size() );
Model model = ProjectFactory.createModelFrom( project );
ArtifactHandler handler = new DefaultArtifactHandler(
ArtifactType.getArtifactTypeForPackagingName( artifact.getType() ).getExtension() );
artifact.setArtifactHandler( handler );
ArtifactRepositoryLayout layout = new DefaultRepositoryLayout();
if ( !project.getArtifactType().equals( "pom" ) )
{
if ( artifact.getFile().exists() )
{
FileUtils.copyFile( artifact.getFile(), new File( mavenRepository, layout.pathOf( artifact ) ) );
}
else
{
logger.warning( "NPANDAY-190-003: Could not find file: " + artifact.getFile().getAbsolutePath() );
return;
}
}
if ( applicationConfig != null )
{
File destPath = applicationConfig.getConfigBuildPath();
if ( destPath.exists() )
{
FileUtils.copyFile( destPath, applicationConfig.getRepositoryPath( mavenRepository ) );
}
}
if ( !artifact.getType().equals( "exe.config" ) )//This is attached
{
ArtifactHandler pomhandler = new DefaultArtifactHandler( "pom" );
artifact.setArtifactHandler( pomhandler );
File pomFile = new File( mavenRepository, pathOfPom( artifact ) );
FileWriter fileWriter = new FileWriter( pomFile );
new MavenXpp3Writer().write( fileWriter, model );
IOUtil.close( fileWriter );
}
artifact.setArtifactHandler( handler );
dao.closeConnection();
}