protected DependencyArtifacts doResolvePlatform( final MavenSession session, final MavenProject project, List<ReactorProject> reactorProjects, DependencyResolverConfiguration resolverConfiguration, TargetPlatform resolutionContext, P2Resolver resolver, TargetPlatformConfiguration configuration) { Map<File, ReactorProject> projects = new HashMap<File, ReactorProject>(); resolver.setEnvironments(getEnvironments(configuration)); for (ReactorProject otherProject : reactorProjects) { projects.put(otherProject.getBasedir(), otherProject); } if (resolverConfiguration != null) { for (Dependency dependency : resolverConfiguration.getExtraRequirements()) { resolver.addDependency( dependency.getType(), dependency.getArtifactId(), dependency.getVersion()); } } if (!isAllowConflictingDependencies(project, configuration)) { List<P2ResolutionResult> results = resolver.resolveProject(resolutionContext, project.getBasedir()); MultiEnvironmentTargetPlatform multiPlatform = new MultiEnvironmentTargetPlatform(DefaultReactorProject.adapt(project)); // FIXME this is just wrong for (int i = 0; i < configuration.getEnvironments().size(); i++) { TargetEnvironment environment = configuration.getEnvironments().get(i); P2ResolutionResult result = results.get(i); DefaultTargetPlatform platform = newDefaultTargetPlatform( session, DefaultReactorProject.adapt(project), projects, result); // addProjects( session, platform ); multiPlatform.addPlatform(environment, platform); } return multiPlatform; } else { P2ResolutionResult result = resolver.collectProjectDependencies(resolutionContext, project.getBasedir()); return newDefaultTargetPlatform( session, DefaultReactorProject.adapt(project), projects, result); } }
protected DependencyArtifacts getTargetPlatform(File location) throws Exception, IOException { LocalDependencyResolver resolver = (LocalDependencyResolver) lookup(DependencyResolver.class, LocalDependencyResolver.ROLE_HINT); MavenExecutionRequest request = new DefaultMavenExecutionRequest(); request.setLocalRepository(new StubArtifactRepository(location.getAbsolutePath())); MavenExecutionResult result = new DefaultMavenExecutionResult(); DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession(); MavenSession session = new MavenSession(getContainer(), repositorySession, request, result); session.setProjects(new ArrayList<MavenProject>()); lookup(LegacySupport.class).setSession(session); MavenProject project = new MavenProject(); resolver.setLocation(location); DependencyArtifacts platform = resolver.resolveDependencies( session, project, null, DefaultReactorProject.adapt(session), null); return platform; }
protected void attachP2Metadata() throws MojoExecutionException { if (!attachP2Metadata || !supportedProjectTypes.contains(project.getPackaging())) { return; } File file = project.getArtifact().getFile(); if (file == null || !file.canRead()) { throw new IllegalStateException(); } File targetDir = new File(project.getBuild().getDirectory()); Map<String, IArtifactFacade> artifactsToBeAttached = new HashMap<String, IArtifactFacade>(); ArtifactFacade projectDefaultArtifact = new ArtifactFacade(project.getArtifact()); Artifact p2contentArtifact = createP2Artifact( projectDefaultArtifact, EXTENSION_P2_METADATA, CLASSIFIER_P2_METADATA, FILE_NAME_P2_METADATA, targetDir); artifactsToBeAttached.put(CLASSIFIER_P2_METADATA, new ArtifactFacade(p2contentArtifact)); Artifact p2artifactsArtifact = createP2Artifact( projectDefaultArtifact, EXTENSION_P2_ARTIFACTS, CLASSIFIER_P2_ARTIFACTS, FILE_NAME_P2_ARTIFACTS, targetDir); artifactsToBeAttached.put(CLASSIFIER_P2_ARTIFACTS, new ArtifactFacade(p2artifactsArtifact)); try { List<IArtifactFacade> artifacts = new ArrayList<IArtifactFacade>(); artifacts.add(projectDefaultArtifact); for (Artifact attachedArtifact : project.getAttachedArtifacts()) { if (attachedArtifact.getFile() != null && attachedArtifact.getFile().getName().endsWith(".jar")) { artifacts.add(new ArtifactFacade(attachedArtifact)); } } Map<String, Set<Object>> generateMetadata = getP2Generator().generateMetadata(artifacts, artifactsToBeAttached, targetDir); ReactorProject reactorProject = DefaultReactorProject.adapt(project); for (Map.Entry<String, Set<Object>> entry : generateMetadata.entrySet()) { reactorProject.setDependencyMetadata(entry.getKey(), true, entry.getValue()); reactorProject.setDependencyMetadata(entry.getKey(), false, Collections.emptySet()); } } catch (IOException e) { throw new MojoExecutionException("Could not generate P2 metadata", e); } for (Entry<String, IArtifactFacade> entry : artifactsToBeAttached.entrySet()) { IArtifactFacade artifactFacade = entry.getValue(); projectHelper.attachArtifact( project, artifactFacade.getPackagingType(), artifactFacade.getClassifier(), artifactFacade.getLocation()); } File localArtifactsFile = new File(project.getBuild().getDirectory(), FILE_NAME_LOCAL_ARTIFACTS); writeArtifactLocations(localArtifactsFile, getAllProjectArtifacts(project)); }