use of org.apache.maven.project.MavenProject in project asterixdb by apache.
the class LicenseMojo method resolveDependency.
protected MavenProject resolveDependency(Artifact depObj) throws ProjectBuildingException {
String key = depObj.getGroupId() + ":" + depObj.getArtifactId() + ":" + depObj.getVersion();
MavenProject depProj = projectCache.get(key);
if (depProj == null) {
try {
depProj = projectBuilder.buildFromRepository(depObj, remoteRepositories, localRepository, false);
} catch (ProjectBuildingException e) {
throw new ProjectBuildingException(key, "Error creating dependent artifacts", e);
}
Model supplement = supplementModels.get(SupplementalModelHelper.generateSupplementMapKey(depObj.getGroupId(), depObj.getArtifactId()));
if (supplement != null) {
Model merged = SupplementalModelHelper.mergeModels(assembler, depProj.getModel(), supplement);
Set<String> origLicenses = depProj.getModel().getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
Set<String> newLicenses = merged.getLicenses().stream().map(License::getUrl).collect(Collectors.toSet());
if (!origLicenses.equals(newLicenses)) {
getLog().warn("license list for " + toGav(depProj) + " changed with supplemental model; was: " + origLicenses + ", now: " + newLicenses);
}
depProj = new MavenProject(merged);
depProj.setArtifact(depObj);
depProj.setVersion(depObj.getVersion());
}
depProj.getArtifact().setScope(depObj.getScope());
projectCache.put(key, depProj);
}
return depProj;
}
use of org.apache.maven.project.MavenProject in project asterixdb by apache.
the class LicenseMojo method gatherProjectDependencies.
private void gatherProjectDependencies(MavenProject project, Map<MavenProject, List<Pair<String, String>>> dependencyLicenseMap, Map<String, MavenProject> dependencyGavMap) throws ProjectBuildingException {
final Set dependencyArtifacts = project.getArtifacts();
if (dependencyArtifacts != null) {
for (Object depArtifactObj : dependencyArtifacts) {
final Artifact depArtifact = (Artifact) depArtifactObj;
if (!excludedScopes.contains(depArtifact.getScope())) {
MavenProject dep = resolveDependency(depArtifact);
dep.setArtifact(depArtifact);
dependencyGavMap.put(toGav(dep), dep);
List<Pair<String, String>> licenseUrls = new ArrayList<>();
for (Object license : dep.getLicenses()) {
final License license1 = (License) license;
String url = license1.getUrl() != null ? license1.getUrl() : (license1.getName() != null ? license1.getName() : "LICENSE_EMPTY_NAME_URL");
licenseUrls.add(new ImmutablePair<>(url, license1.getName()));
}
dependencyLicenseMap.put(dep, licenseUrls);
}
}
}
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DefaultAssemblyReader method readAssembly.
public Assembly readAssembly(Reader reader, final String locationDescription, final File assemblyDir, final AssemblerConfigurationSource configSource) throws AssemblyReadException, InvalidAssemblerConfigurationException {
Assembly assembly;
final MavenProject project = configSource.getProject();
try {
InterpolationState is = new InterpolationState();
final RecursionInterceptor interceptor = new PrefixAwareRecursionInterceptor(InterpolationConstants.PROJECT_PREFIXES, true);
is.setRecursionInterceptor(interceptor);
FixedStringSearchInterpolator interpolator = AssemblyInterpolator.fullInterpolator(project, createProjectInterpolator(project), configSource);
AssemblyXpp3Reader.ContentTransformer transformer = AssemblyInterpolator.assemblyInterpolator(interpolator, is, getLogger());
final AssemblyXpp3Reader r = new AssemblyXpp3Reader(transformer);
assembly = r.read(reader);
ComponentXpp3Reader.ContentTransformer ctrans = AssemblyInterpolator.componentInterpolator(interpolator, is, getLogger());
mergeComponentsWithMainAssembly(assembly, assemblyDir, configSource, ctrans);
debugPrintAssembly("After assembly is interpolated:", assembly);
AssemblyInterpolator.checkErrors(AssemblyId.createAssemblyId(assembly), is, getLogger());
reader.close();
reader = null;
} catch (final IOException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} catch (final XmlPullParserException e) {
throw new AssemblyReadException("Error reading descriptor: " + locationDescription + ": " + e.getMessage(), e);
} finally {
IOUtil.close(reader);
}
if (assembly.isIncludeSiteDirectory()) {
includeSiteInAssembly(assembly, configSource);
}
return assembly;
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DependencySetAssemblyPhaseTest method testExecute_ShouldAddOneDependencyFromProject.
public void testExecute_ShouldAddOneDependencyFromProject() throws AssemblyFormattingException, ArchiveCreationException, IOException, InvalidAssemblerConfigurationException, DependencyResolutionException {
final String outputLocation = "/out";
final MavenProject project = newMavenProject("group", "project", "0");
final ArtifactMock projectArtifactMock = new ArtifactMock(mm, "group", "project", "0", "jar", false);
project.setArtifact(projectArtifactMock.getArtifact());
final DependencySet ds = new DependencySet();
ds.setUseProjectArtifact(false);
ds.setOutputDirectory(outputLocation);
ds.setOutputFileNameMapping("${artifact.artifactId}");
ds.setUnpack(false);
ds.setScope(Artifact.SCOPE_COMPILE);
ds.setFileMode(Integer.toString(10, 8));
final Assembly assembly = new Assembly();
assembly.setId("test");
assembly.setIncludeBaseDirectory(false);
assembly.addDependencySet(ds);
final MockAndControlForAddDependencySetsTask macTask = new MockAndControlForAddDependencySetsTask(mm, project);
final ArtifactMock artifactMock = new ArtifactMock(mm, "group", "dep", "1", "jar", false);
System.out.println("On test setup, hashcode for dependency artifact: " + artifactMock.getArtifact().hashCode());
macTask.expectCSGetRepositories(null, null);
macTask.expectGetDestFile(new File("junk"));
// macTask.expectAddFile( artifactFile, "out/dep", 10 );
project.setArtifacts(Collections.singleton(artifactMock.getArtifact()));
macTask.expectCSGetFinalName("final-name");
final Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test");
final MavenProject depProject = newMavenProject("group", "dep", "1");
macTask.expectBuildFromRepository(depProject);
macTask.expectResolveDependencySets();
mm.replayAll();
createPhase(macTask, logger, macTask.dependencyResolver).execute(assembly, macTask.archiver, macTask.configSource);
mm.verifyAll();
}
use of org.apache.maven.project.MavenProject in project maven-plugins by apache.
the class DependencySetAssemblyPhaseTest method newMavenProject.
private MavenProject newMavenProject(final String groupId, final String artifactId, final String version) {
final Model model = new Model();
model.setGroupId(groupId);
model.setArtifactId(artifactId);
model.setVersion(version);
return new MavenProject(model);
}
Aggregations