CentralRepositoryService implements RepositoryService { public Project retrieveProject( String groupId, String artifactId, String version ) throws RepositoryException { Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, version ); MavenProject mavenProject; try { mavenProject = projectBuilder.buildFromRepository( artifact, Collections.singletonList( repository ), localRepository ); } catch ( ProjectBuildingException e ) { throw new RepositoryException( e.getMessage(), e ); } Project project = new Project(); project.setId( MavenCoordinates.constructProjectId( groupId, artifactId ) ); project.setVersion( version ); MavenCoordinates coordinates = new MavenCoordinates(); coordinates.setGroupId( groupId ); coordinates.setArtifactId( artifactId ); project.addExtensionModel( coordinates ); project.setDescription( mavenProject.getDescription() ); project.setName( mavenProject.getName() ); if ( mavenProject.getCiManagement() != null ) { project.setCiManagementUrl( mavenProject.getCiManagement().getUrl() ); } if ( mavenProject.getIssueManagement() != null ) { project.setIssueTrackerUrl( mavenProject.getIssueManagement().getUrl() ); } if ( mavenProject.getScm() != null ) { project.setScmUrl( mavenProject.getScm().getUrl() ); } project.setUrl( mavenProject.getUrl() ); DistributionManagement distMgmt = mavenProject.getDistributionManagement(); if ( distMgmt != null ) { project.setRepositoryUrl( distMgmt.getRepository().getUrl() ); project.setSnapshotRepositoryUrl( distMgmt.getSnapshotRepository().getUrl() ); } return project; } @Inject private  CentralRepositoryService( RepositoryParams params ); @SuppressWarnings( "unchecked" ) List<String> getAvailableVersions( String groupId, String artifactId ); Project retrieveProject( String groupId, String artifactId, String version );  }
@Test public void getProjectFromRepository() throws RepositoryException { Project project = repositoryService.retrieveProject( "com.effectivemaven.test", "artifact", "1.2" ); assert "com.effectivemaven.test:artifact".equals( project.getId() ); assert "Unnamed - com.effectivemaven.test:artifact:jar:1.2".equals( project.getName() ); assert "Description from parent".equals( project.getDescription() ); assert "http: assert "1.2".equals( project.getVersion() ); assert "http: assert "http: assert "http: assert "http: assert "http: MavenCoordinates coordinates = (MavenCoordinates) project.getExtensionModel( "maven" ); assert "com.effectivemaven.test".equals( coordinates.getGroupId() ); assert "artifact".equals( coordinates.getArtifactId() ); }
@Test public void getMinimalProjectFromRepository() throws RepositoryException { Project project = repositoryService.retrieveProject( "com.effectivemaven.test", "parent", "1.2" ); assert "com.effectivemaven.test:parent".equals( project.getId() ); assert "Unnamed - com.effectivemaven.test:parent:pom:1.2".equals( project.getName() ); assert "Description from parent".equals( project.getDescription() ); assert "http: assert "1.2".equals( project.getVersion() ); assert project.getCiManagementUrl() == null; assert project.getIssueTrackerUrl() == null; assert project.getRepositoryUrl() == null; assert project.getScmUrl() == null; assert project.getSnapshotRepositoryUrl() == null; MavenCoordinates coordinates = (MavenCoordinates) project.getExtensionModel( "maven" ); assert "com.effectivemaven.test".equals( coordinates.getGroupId() ); assert "parent".equals( coordinates.getArtifactId() ); }