private void validate( File file, Collection<Exception> exceptions, Collection<MavenProjectProblem> problems, Collection<MavenId> unresolvedArtifacts) throws RemoteException { for (Exception each : exceptions) { Maven3ServerGlobals.getLogger().info(each); if (each instanceof InvalidProjectModelException) { ModelValidationResult modelValidationResult = ((InvalidProjectModelException) each).getValidationResult(); if (modelValidationResult != null) { for (Object eachValidationProblem : modelValidationResult.getMessages()) { problems.add( MavenProjectProblem.createStructureProblem( file.getPath(), (String) eachValidationProblem)); } } else { problems.add( MavenProjectProblem.createStructureProblem( file.getPath(), each.getCause().getMessage())); } } else if (each instanceof ProjectBuildingException) { String causeMessage = each.getCause() != null ? each.getCause().getMessage() : each.getMessage(); problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), causeMessage)); } else { problems.add(MavenProjectProblem.createStructureProblem(file.getPath(), each.getMessage())); } } unresolvedArtifacts.addAll(retrieveUnresolvedArtifactIds()); }
private static Collection<String> collectProfilesIds(List<Profile> profiles) { Collection<String> result = new THashSet<String>(); for (Profile each : profiles) { if (each.getId() != null) { result.add(each.getId()); } } return result; }
/** * Converts a collection of Dependency objects to a list of corresponding Artifact objects. * * @param deps The collection of dependencies to convert. * @return A list of Artifact instances. */ private List<Artifact> dependenciesToArtifacts(final Collection<Dependency> deps) { final List<Artifact> artifacts = new ArrayList<Artifact>(deps.size()); for (Dependency dep : deps) { artifacts.add(dependencyToArtifact(dep)); } return artifacts; }
/** * Converts a collection of Maven artifacts to files. For this method to function properly, the * artifacts MUST be resolved first. * * @param artifacts A collection of artifacts. * @return The list of files pointed to by the artifacts. */ private List<File> artifactsToFiles(final Collection<Artifact> artifacts) { final List<File> files = new ArrayList<File>(artifacts.size()); StringBuilder sb = new StringBuilder(); for (Artifact artifact : artifacts) { sb.append("\natof " + artifact.getFile().getAbsolutePath()); files.add(artifact.getFile()); } if (logDependencies) getLog().info(sb.toString()); return files; }
public static ProfileApplicationResult applyProfiles( MavenModel model, File basedir, Collection<String> explicitProfiles, Collection<String> alwaysOnProfiles) throws RemoteException { Model nativeModel = MavenModelConverter.toNativeModel(model); List<Profile> activatedPom = new ArrayList<Profile>(); List<Profile> activatedExternal = new ArrayList<Profile>(); List<Profile> activeByDefault = new ArrayList<Profile>(); List<Profile> rawProfiles = nativeModel.getProfiles(); List<Profile> expandedProfilesCache = null; for (int i = 0; i < rawProfiles.size(); i++) { Profile eachRawProfile = rawProfiles.get(i); boolean shouldAdd = explicitProfiles.contains(eachRawProfile.getId()) || alwaysOnProfiles.contains(eachRawProfile.getId()); Activation activation = eachRawProfile.getActivation(); if (activation != null) { if (activation.isActiveByDefault()) { activeByDefault.add(eachRawProfile); } // expand only if necessary if (expandedProfilesCache == null) expandedProfilesCache = doInterpolate(nativeModel, basedir).getProfiles(); Profile eachExpandedProfile = expandedProfilesCache.get(i); for (ProfileActivator eachActivator : getProfileActivators(basedir)) { try { if (eachActivator.canDetermineActivation(eachExpandedProfile) && eachActivator.isActive(eachExpandedProfile)) { shouldAdd = true; break; } } catch (ProfileActivationException e) { Maven3ServerGlobals.getLogger().warn(e); } } } if (shouldAdd) { if (MavenConstants.PROFILE_FROM_POM.equals(eachRawProfile.getSource())) { activatedPom.add(eachRawProfile); } else { activatedExternal.add(eachRawProfile); } } } List<Profile> activatedProfiles = new ArrayList<Profile>(activatedPom.isEmpty() ? activeByDefault : activatedPom); activatedProfiles.addAll(activatedExternal); for (Profile each : activatedProfiles) { new DefaultProfileInjector().injectProfile(nativeModel, each, null, null); } return new ProfileApplicationResult( MavenModelConverter.convertModel(nativeModel, null), collectProfilesIds(activatedProfiles)); }