use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class AddDependencySetsTaskTest method testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed.
// TODO: Find a better way of testing the project-stubbing behavior when a ProjectBuildingException takes place.
public void testAddDependencySet_ShouldNotAddDependenciesWhenProjectIsStubbed() throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, IOException {
final MavenProject project = new MavenProject(new Model());
final ProjectBuildingException pbe = new ProjectBuildingException("test", "Test error.", new Throwable());
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mockManager, new MavenProject(new Model()));
final String gid = "org.test";
final String aid = "test-dep";
final String version = "2.0-SNAPSHOT";
final String type = "jar";
final File file = new File("dep-artifact.jar");
final ArtifactMock depMock = new ArtifactMock(mockManager, gid, aid, version, type, true);
depMock.setBaseVersion(version);
depMock.setFile(file);
final File destFile = new File("assembly-dep-set.zip");
macTask.expectGetDestFile(destFile);
macTask.expectBuildFromRepository(pbe);
macTask.expectCSGetRepositories(null, null);
macTask.expectCSGetFinalName("final-name");
macTask.expectAddFile(file, "out/" + aid + "-" + version + "." + type);
macTask.expectGetMode(0222, 0222);
final DependencySet ds = new DependencySet();
ds.setOutputDirectory("/out");
DefaultAssemblyArchiverTest.setupInterpolators(macTask.configSource);
mockManager.replayAll();
final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
final AddDependencySetsTask task = new AddDependencySetsTask(Collections.singletonList(ds), Collections.singleton(depMock.getArtifact()), project, macTask.projectBuilder, logger);
task.addDependencySet(ds, macTask.archiver, macTask.configSource);
mockManager.verifyAll();
}
use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class DependencyManagementRenderer method getDependencyRow.
@SuppressWarnings("unchecked")
private String[] getDependencyRow(Dependency dependency, boolean hasClassifier) {
Artifact artifact = artifactFactory.createProjectArtifact(dependency.getGroupId(), dependency.getArtifactId(), dependency.getVersion());
StringBuilder licensesBuffer = new StringBuilder();
String url = null;
try {
VersionRange range = VersionRange.createFromVersionSpec(dependency.getVersion());
if (range.getRecommendedVersion() == null) {
// MPIR-216: no direct version but version range: need to choose one precise version
log.debug("Resolving range for DependencyManagement on " + artifact.getId());
List<ArtifactVersion> versions = artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories);
// only use versions from range
for (Iterator<ArtifactVersion> iter = versions.iterator(); iter.hasNext(); ) {
if (!range.containsVersion(iter.next())) {
iter.remove();
}
}
// select latest, assuming pom information will be the most accurate
if (versions.size() > 0) {
ArtifactVersion maxArtifactVersion = Collections.max(versions);
artifact.setVersion(maxArtifactVersion.toString());
log.debug("DependencyManagement resolved: " + artifact.getId());
}
}
url = ProjectInfoReportUtils.getArtifactUrl(artifactFactory, artifact, mavenProjectBuilder, remoteRepositories, localRepository);
MavenProject artifactProject = repoUtils.getMavenProjectFromRepository(artifact);
List<License> licenses = artifactProject.getLicenses();
for (License license : licenses) {
String licenseCell = ProjectInfoReportUtils.getArtifactIdCell(license.getName(), license.getUrl());
if (licensesBuffer.length() > 0) {
licensesBuffer.append(", ");
}
licensesBuffer.append(licenseCell);
}
} catch (InvalidVersionSpecificationException e) {
log.warn("Unable to parse version for " + artifact.getId(), e);
} catch (ArtifactMetadataRetrievalException e) {
log.warn("Unable to retrieve versions for " + artifact.getId() + " from repository.", e);
} catch (ProjectBuildingException e) {
log.warn("Unable to create Maven project for " + artifact.getId() + " from repository.", e);
}
String artifactIdCell = ProjectInfoReportUtils.getArtifactIdCell(artifact.getArtifactId(), url);
if (hasClassifier) {
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getClassifier(), dependency.getType(), licensesBuffer.toString() };
}
return new String[] { dependency.getGroupId(), artifactIdCell, dependency.getVersion(), dependency.getType(), licensesBuffer.toString() };
}
use of org.apache.maven.project.ProjectBuildingException in project maven-plugins by apache.
the class AddDependencySetsTask method addDependencySet.
void addDependencySet(final DependencySet dependencySet, final Archiver archiver, final AssemblerConfigurationSource configSource) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException {
logger.debug("Processing DependencySet (output=" + dependencySet.getOutputDirectory() + ")");
if (!dependencySet.isUseTransitiveDependencies() && dependencySet.isUseTransitiveFiltering()) {
logger.warn("DependencySet has nonsensical configuration: useTransitiveDependencies == false " + "AND useTransitiveFiltering == true. Transitive filtering flag will be ignored.");
}
final Set<Artifact> dependencyArtifacts = resolveDependencyArtifacts(dependencySet);
if (!unpackTransformsContent(dependencySet) && dependencyArtifacts.size() > 1) {
checkMultiArtifactOutputConfig(dependencySet);
}
logger.debug("Adding " + dependencyArtifacts.size() + " dependency artifacts.");
InputStreamTransformer fileSetTransformers = isUnpackWithOptions(dependencySet) ? ReaderFormatter.getFileSetTransformers(configSource, dependencySet.getUnpackOptions().isFiltered(), dependencySet.getUnpackOptions().getLineEnding()) : null;
for (final Artifact depArtifact : dependencyArtifacts) {
ProjectBuildingRequest pbr = getProjectBuildingRequest(configSource);
MavenProject depProject;
try {
ProjectBuildingResult build = projectBuilder1.build(depArtifact, pbr);
depProject = build.getProject();
} catch (final ProjectBuildingException e) {
logger.debug("Error retrieving POM of module-dependency: " + depArtifact.getId() + "; Reason: " + e.getMessage() + "\n\nBuilding stub project instance.");
depProject = buildProjectStub(depArtifact);
}
if (NON_ARCHIVE_DEPENDENCY_TYPES.contains(depArtifact.getType())) {
addNonArchiveDependency(depArtifact, depProject, dependencySet, archiver, configSource);
} else {
addNormalArtifact(dependencySet, depArtifact, depProject, archiver, configSource, fileSetTransformers);
}
}
}
Aggregations