use of org.apache.maven.model.Dependency in project grails-maven by grails.
the class AbstractGrailsMojo method resolveArtifacts.
protected List<File> resolveArtifacts(MavenProject mavenProject, Collection<String> scopes, DependencyFilter filter) throws MojoExecutionException {
try {
DefaultDependencyResolutionRequest request = new DefaultDependencyResolutionRequest(mavenProject, repoSession);
if (filter != null) {
request.setResolutionFilter(new AndDependencyFilter(new ScopeDependencyFilter(scopes, Collections.<String>emptyList()), filter));
} else {
request.setResolutionFilter(new ScopeDependencyFilter(scopes, Collections.<String>emptyList()));
}
DependencyResolutionResult result = projectDependenciesResolver.resolve(request);
List<org.eclipse.aether.graph.Dependency> dependencies = result.getDependencies();
final List<File> files = new ArrayList<File>();
for (org.eclipse.aether.graph.Dependency d : dependencies) {
org.eclipse.aether.artifact.Artifact artifact = d.getArtifact();
File file = artifact.getFile();
if (file != null) {
String name = file.getName();
if (!name.contains("xml-apis") && !name.contains("commons-logging"))
files.add(file);
}
}
return files;
} catch (DependencyResolutionException e) {
throw new MojoExecutionException("Dependency resolution failure: " + e.getMessage(), e);
}
}
use of org.apache.maven.model.Dependency in project gradle by gradle.
the class DefaultPomDependenciesConverter method addMavenDependencies.
private void addMavenDependencies(Map<Dependency, Integer> dependenciesWithPriorities, ModuleDependency dependency, String name, String type, String scope, String classifier, Integer priority, Set<Configuration> configurations) {
List<Dependency> mavenDependencies = new ArrayList<Dependency>();
if (dependency instanceof ProjectDependency) {
ProjectDependency projectDependency = (ProjectDependency) dependency;
final String artifactId = determineProjectDependencyArtifactId((ProjectDependency) dependency);
Configuration dependencyConfig = getTargetConfiguration(projectDependency);
for (PublishArtifact artifactToPublish : dependencyConfig.getAllArtifacts()) {
Dependency mavenDependency = new Dependency();
mavenDependency.setArtifactId(artifactId);
if (artifactToPublish.getClassifier() != null && !artifactToPublish.getClassifier().equals("")) {
mavenDependency.setClassifier(artifactToPublish.getClassifier());
}
mavenDependencies.add(mavenDependency);
}
} else {
Dependency mavenDependency = new Dependency();
mavenDependency.setArtifactId(name);
mavenDependency.setClassifier(classifier);
mavenDependencies.add(mavenDependency);
}
for (Dependency mavenDependency : mavenDependencies) {
mavenDependency.setGroupId(dependency.getGroup());
mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
mavenDependency.setType(type);
mavenDependency.setScope(scope);
mavenDependency.setExclusions(getExclusions(dependency, configurations));
// Dependencies de-duplication
Optional<Dependency> duplicateDependency = findEqualIgnoreScopeVersionAndExclusions(dependenciesWithPriorities.keySet(), mavenDependency);
if (!duplicateDependency.isPresent()) {
// Add if absent
dependenciesWithPriorities.put(mavenDependency, priority);
} else {
// Use highest version on highest scope, keep highest scope exclusions only
int duplicatePriority = dependenciesWithPriorities.get(duplicateDependency.get());
boolean samePriority = priority == duplicatePriority;
boolean higherPriority = priority > duplicatePriority;
boolean higherVersion = compareMavenVersionStrings(mavenDependency.getVersion(), duplicateDependency.get().getVersion()) > 0;
if (higherPriority || higherVersion) {
// Replace if higher priority or version with highest priority and version
dependenciesWithPriorities.remove(duplicateDependency.get());
if (!higherPriority) {
// Lower or equal priority but higher version, keep higher scope and exclusions
mavenDependency.setScope(duplicateDependency.get().getScope());
if (!samePriority) {
mavenDependency.setExclusions(duplicateDependency.get().getExclusions());
}
}
int highestPriority = higherPriority ? priority : duplicatePriority;
dependenciesWithPriorities.put(mavenDependency, highestPriority);
}
}
}
}
use of org.apache.maven.model.Dependency in project spring-boot by spring-projects.
the class ArtifactsLibrariesTests method callbackWithUnpack.
@Test
public void callbackWithUnpack() throws Exception {
given(this.artifact.getGroupId()).willReturn("gid");
given(this.artifact.getArtifactId()).willReturn("aid");
given(this.artifact.getType()).willReturn("jar");
given(this.artifact.getScope()).willReturn("compile");
Dependency unpack = new Dependency();
unpack.setGroupId("gid");
unpack.setArtifactId("aid");
this.libs = new ArtifactsLibraries(this.artifacts, Collections.singleton(unpack), mock(Log.class));
this.libs.doWithLibraries(this.callback);
verify(this.callback).library(this.libraryCaptor.capture());
assertThat(this.libraryCaptor.getValue().isUnpackRequired()).isTrue();
}
use of org.apache.maven.model.Dependency in project intellij-plugins by JetBrains.
the class GeneratorServer method generate.
private String generate(final MavenProject project, final List<String> generators, final URL generatorJarPath) throws Exception {
session.setCurrentProject(project);
MojoExecution flexmojosMojoExecution = null;
try {
boolean flexmojosGeneratorFound = false;
boolean buildHelperFound = false;
boolean buildNumberFound = false;
for (Plugin plugin : project.getBuildPlugins()) {
final String pluginGroupId = plugin.getGroupId();
if (pluginGroupId.equals("org.sonatype.flexmojos") || pluginGroupId.equals("net.flexmojos.oss")) {
if (flexmojosMojoExecution == null && plugin.getArtifactId().equals("flexmojos-maven-plugin")) {
flexmojosMojoExecution = maven.createMojoExecution(plugin, getCompileGoalName(project), project);
for (Dependency dependency : plugin.getDependencies()) {
if (dependency.getArtifactId().equals("flexmojos-threadlocaltoolkit-wrapper")) {
AdditionalSourceRootUtil.addResourcesAsCompileSourceRoots(project);
break;
}
}
} else if (!flexmojosGeneratorFound && plugin.getArtifactId().equals("flexmojos-generator-mojo")) {
AdditionalSourceRootUtil.addByGeneratorMojo(maven.createMojoExecution(plugin, "generate", project), session, project, getLogger());
flexmojosGeneratorFound = true;
}
} else if (!buildHelperFound && plugin.getArtifactId().equals("build-helper-maven-plugin") && pluginGroupId.equals("org.codehaus.mojo")) {
AdditionalSourceRootUtil.addByBuildHelper(maven.createMojoExecution(plugin, "add-source", project), session, project, getLogger());
buildHelperFound = true;
} else if (!buildNumberFound && plugin.getArtifactId().equals("buildnumber-maven-plugin") && pluginGroupId.equals("org.codehaus.mojo")) {
populateBuildNumberPluginFields(project, plugin);
buildNumberFound = true;
}
if (flexmojosMojoExecution != null && flexmojosGeneratorFound && buildHelperFound && buildNumberFound) {
break;
}
}
AdditionalSourceRootUtil.addByUnknownGeneratorMojo(project);
assert flexmojosMojoExecution != null;
final ClassRealm flexmojosPluginRealm = maven.getPluginRealm(flexmojosMojoExecution);
flexmojosPluginRealm.addURL(generatorJarPath);
final Mojo mojo = mavenPluginManager.getConfiguredMojo(Mojo.class, session, flexmojosMojoExecution);
try {
Class<?> configuratorClass = flexmojosPluginRealm.loadClass(generators.get(0));
FlexConfigGenerator configurator = (FlexConfigGenerator) configuratorClass.getConstructor(MavenSession.class, File.class).newInstance(session, generatorOutputDirectory);
configurator.preGenerate(project, Flexmojos.getClassifier(mojo));
if ("swc".equals(project.getPackaging())) {
configurator.generate(mojo);
} else {
configurator.generate(mojo, Flexmojos.getSourceFileForSwf(mojo));
}
return configurator.postGenerate(project);
} finally {
plexusContainer.release(mojo);
}
} finally {
session.setCurrentProject(null);
if (flexmojosMojoExecution != null) {
maven.releaseMojoExecution(flexmojosMojoExecution);
}
}
}
use of org.apache.maven.model.Dependency in project robolectric by robolectric.
the class MavenDependencyResolver method getLocalArtifactUrls.
/**
* Get an array of local artifact URLs for the given dependencies. The order of the URLs is guaranteed to be the
* same as the input order of dependencies, i.e., urls[i] is the local artifact URL for dependencies[i].
*/
public URL[] getLocalArtifactUrls(DependencyJar... dependencies) {
DependenciesTask dependenciesTask = createDependenciesTask();
configureMaven(dependenciesTask);
RemoteRepository remoteRepository = new RemoteRepository();
remoteRepository.setUrl(repositoryUrl);
remoteRepository.setId(repositoryId);
dependenciesTask.addConfiguredRemoteRepository(remoteRepository);
dependenciesTask.setProject(project);
for (DependencyJar dependencyJar : dependencies) {
Dependency dependency = new Dependency();
dependency.setArtifactId(dependencyJar.getArtifactId());
dependency.setGroupId(dependencyJar.getGroupId());
dependency.setType(dependencyJar.getType());
dependency.setVersion(dependencyJar.getVersion());
if (dependencyJar.getClassifier() != null) {
dependency.setClassifier(dependencyJar.getClassifier());
}
dependenciesTask.addDependency(dependency);
}
dependenciesTask.execute();
@SuppressWarnings("unchecked") Hashtable<String, String> artifacts = project.getProperties();
URL[] urls = new URL[dependencies.length];
for (int i = 0; i < urls.length; i++) {
try {
urls[i] = Util.url(artifacts.get(key(dependencies[i])));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
return urls;
}
Aggregations