private static Collection<String> collectActivatedProfiles(MavenProject mavenProject) { // for some reason project's active profiles do not contain parent's profiles - only local and // settings'. // parent's profiles do not contain settings' profiles. List<Profile> profiles = new ArrayList<Profile>(); while (mavenProject != null) { profiles.addAll(mavenProject.getActiveProfiles()); mavenProject = mavenProject.getParent(); } return collectProfilesIds(profiles); }
@NotNull private MavenServerExecutionResult createExecutionResult( File file, MavenExecutionResult result, DependencyNode rootNode) throws RemoteException { Collection<MavenProjectProblem> problems = MavenProjectProblem.createProblemsList(); THashSet<MavenId> unresolvedArtifacts = new THashSet<MavenId>(); validate(file, result.getExceptions(), problems, unresolvedArtifacts); MavenProject mavenProject = result.getMavenProject(); if (mavenProject == null) return new MavenServerExecutionResult(null, problems, unresolvedArtifacts); MavenModel model = MavenModelConverter.convertModel( mavenProject.getModel(), mavenProject.getCompileSourceRoots(), mavenProject.getTestCompileSourceRoots(), mavenProject.getArtifacts(), (rootNode == null ? Collections.emptyList() : rootNode.getChildren()), mavenProject.getExtensionArtifacts(), getLocalRepositoryFile()); RemoteNativeMavenProjectHolder holder = new RemoteNativeMavenProjectHolder(mavenProject); try { UnicastRemoteObject.exportObject(holder, 0); } catch (RemoteException e) { throw new RuntimeException(e); } Collection<String> activatedProfiles = collectActivatedProfiles(mavenProject); MavenServerExecutionResult.ProjectData data = new MavenServerExecutionResult.ProjectData( model, MavenModelConverter.convertToMap(mavenProject.getModel()), holder, activatedProfiles); return new MavenServerExecutionResult(data, problems, unresolvedArtifacts); }
@Override public Collection<MavenArtifact> resolvePlugin( @NotNull MavenPlugin plugin, @NotNull List<MavenRemoteRepository> repositories, int nativeMavenProjectId, boolean transitive) throws RemoteException, MavenServerProcessCanceledException { try { Plugin mavenPlugin = new Plugin(); mavenPlugin.setGroupId(plugin.getGroupId()); mavenPlugin.setArtifactId(plugin.getArtifactId()); mavenPlugin.setVersion(plugin.getVersion()); MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId); MavenExecutionRequest request = createRequest( null, Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String>emptyList()); DefaultMaven maven = (DefaultMaven) getComponent(Maven.class); RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request); if (plugin.getVersion() == null) { PluginVersionRequest versionRequest = new DefaultPluginVersionRequest( mavenPlugin, repositorySystemSession, project.getRemotePluginRepositories()); mavenPlugin.setVersion( getComponent(PluginVersionResolver.class).resolve(versionRequest).getVersion()); } PluginDescriptor result = getComponent(MavenPluginManager.class) .getPluginDescriptor( mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession); Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts = new THashMap<MavenArtifactInfo, MavenArtifact>(); Artifact pluginArtifact = result.getPluginArtifact(); MavenArtifactInfo artifactInfo = new MavenArtifactInfo( pluginArtifact.getGroupId(), pluginArtifact.getArtifactId(), pluginArtifact.getVersion(), pluginArtifact.getType(), null); resolveIfNecessary(artifactInfo, repositories, resolvedArtifacts); if (transitive) { // todo try to use parallel downloading for (Artifact each : result.getIntroducedDependencyArtifacts()) { resolveIfNecessary( new MavenArtifactInfo( each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null), repositories, resolvedArtifacts); } for (ComponentDependency each : result.getDependencies()) { resolveIfNecessary( new MavenArtifactInfo( each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null), repositories, resolvedArtifacts); } } return new THashSet<MavenArtifact>(resolvedArtifacts.values()); } catch (Exception e) { Maven3ServerGlobals.getLogger().info(e); return Collections.emptyList(); } }