org.apache.maven.model.Dependency Java Examples
The following examples show how to use
org.apache.maven.model.Dependency.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BomGeneratorMojo.java From camel-spring-boot with Apache License 2.0 | 6 votes |
private void checkConflictsWithExternalBoms(Collection<Dependency> dependencies, Set<String> external) throws MojoFailureException { Set<String> errors = new TreeSet<>(); for (Dependency d : dependencies) { String key = comparisonKey(d); if (external.contains(key)) { errors.add(key); } } if (errors.size() > 0) { StringBuilder msg = new StringBuilder(); msg.append("Found ").append(errors.size()).append(" conflicts between the current managed dependencies and the external BOMS:\n"); for (String error : errors) { msg.append(" - ").append(error).append("\n"); } throw new MojoFailureException(msg.toString()); } }
Example #2
Source File: PomAddDependencyTest.java From butterfly with MIT License | 6 votes |
/** * Get dependency list from a maven model. Note: This is needed because * {@link AbstractArtifactPomOperation#getDependencyInList(List, String, String)} * does not accept a version as argument. */ private Dependency getDependencyInList(Model model, String groupId, String artifactId, String version) { List<Dependency> dependencyList = model.getDependencies(); if (dependencyList == null || dependencyList.size() == 0) { return null; } Dependency dependency = null; for (Dependency d : dependencyList) { if (d.getArtifactId().equals(artifactId) && d.getGroupId().equals(groupId) && d.getVersion().equals(version)) { dependency = d; break; } } return dependency; }
Example #3
Source File: CheckPluginDependencyVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 6 votes |
private Multimap<ArtifactCoordinates, ArtifactCoordinates> getSnapshots(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking direct plugin references"); Multimap<ArtifactCoordinates, ArtifactCoordinates> result = HashMultimap.create(); Build build = project.getBuild(); if (build != null) { for (Plugin plugin : build.getPlugins()) { Collection<Dependency> snapshots = Collections2.filter(plugin.getDependencies(), new IsSnapshotDependency(propertyResolver)); if (!snapshots.isEmpty()) { result.putAll(PluginToCoordinates.INSTANCE.apply(plugin), Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } } } return result; }
Example #4
Source File: YamlFileDependencyLoader.java From yaks with Apache License 2.0 | 6 votes |
@Override protected List<Dependency> load(Path filePath, Properties properties, Logger logger) throws LifecycleExecutionException { try { List<Dependency> dependencyList = new ArrayList<>(); Yaml yaml = new Yaml(); HashMap<String, List<Map<String, Object>>> root = yaml.load(new StringReader(new String(Files.readAllBytes(filePath), StandardCharsets.UTF_8))); if (root.containsKey("dependencies")) { for (Map<String, Object> coordinates : root.get("dependencies")) { Dependency dependency = new Dependency(); dependency.setGroupId(Objects.toString(coordinates.get("groupId"))); dependency.setArtifactId(Objects.toString(coordinates.get("artifactId"))); dependency.setVersion(resolveVersionProperty(Objects.toString(coordinates.get("version")), properties)); logger.info(String.format("Add %s", dependency)); dependencyList.add(dependency); } } return dependencyList; } catch (IOException e) { throw new LifecycleExecutionException("Failed to read dependency configuration file", e); } }
Example #5
Source File: LockSnapshotsMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
/** * Determine the timestamp version of the snapshot dependency used in the build. * * @param dep * @return The timestamp version if exists, otherwise the original snapshot dependency version is returned. */ private String resolveSnapshotVersion( Dependency dep ) { getLog().debug( "Resolving snapshot version for dependency: " + dep ); String lockedVersion = dep.getVersion(); try { Artifact depArtifact = artifactFactory.createDependencyArtifact( dep.getGroupId(), dep.getArtifactId(), VersionRange.createFromVersionSpec( dep.getVersion() ), dep.getType(), dep.getClassifier(), dep.getScope() ); resolver.resolve( depArtifact, getProject().getRemoteArtifactRepositories(), localRepository ); lockedVersion = depArtifact.getVersion(); } catch ( Exception e ) { getLog().error( e ); } return lockedVersion; }
Example #6
Source File: GradleBuildFileFromConnector.java From quarkus with Apache License 2.0 | 6 votes |
@Override public List<Dependency> getDependencies() throws IOException { if (dependencies == null) { EclipseProject eclipseProject = null; if (getBuildContent() != null) { try { ProjectConnection connection = GradleConnector.newConnector() .forProjectDirectory(getProjectDirPath().toFile()) .connect(); eclipseProject = connection.getModel(EclipseProject.class); } catch (BuildException e) { // ignore this error. e.printStackTrace(); } } if (eclipseProject != null) { dependencies = eclipseProject.getClasspath().stream().map(this::gradleModuleVersionToDependency) .filter(Objects::nonNull) .collect(Collectors.toList()); } else { dependencies = Collections.emptyList(); } dependencies = Collections.unmodifiableList(dependencies); } return dependencies; }
Example #7
Source File: ConfluenceDeployMojo.java From maven-confluence-plugin with Apache License 2.0 | 6 votes |
/** * * @param projectId * @param dependencyManagement * @return * @throws ProjectBuildingException */ private Map<String,Artifact> createManagedVersionMap(String projectId, DependencyManagement dependencyManagement) throws ProjectBuildingException { Map<String,Artifact> map; if (dependencyManagement != null && dependencyManagement.getDependencies() != null) { map = new HashMap<>(); for (Dependency d : dependencyManagement.getDependencies()) { try { VersionRange versionRange = VersionRange.createFromVersionSpec(d.getVersion()); Artifact artifact = factory.createDependencyArtifact(d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope()); map.put(d.getManagementKey(), artifact); } catch (InvalidVersionSpecificationException e) { throw new ProjectBuildingException(projectId, "Unable to parse version '" + d.getVersion() + "' for dependency '" + d.getManagementKey() + "': " + e.getMessage(), e); } } } else { map = Collections.emptyMap(); } return map; }
Example #8
Source File: Project.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
/** * This method will scan the dependencies in the potentially active Profiles in this project and * return a fully resolved list. Note that this will only return full dependencies not managed * i.e. those with a group, artifact and version. * * Note that while updating the {@link Dependency} reference returned will be reflected in the * Model as it is the same object, if you wish to remove or add items to the Model then you * must use {@link #getModel()} * * @param session MavenSessionHandler, used by {@link PropertyResolver} * @return a list of fully resolved {@link ArtifactRef} to the original {@link Dependency} * @throws ManipulationException if an error occurs */ public Map<Profile, Map<ArtifactRef, Dependency>> getResolvedProfileDependencies( MavenSessionHandler session) throws ManipulationException { Map<Profile, Map<ArtifactRef, Dependency>> resolvedProfileDependencies = new HashMap<>(); for ( final Profile profile : ProfileUtils.getProfiles( session, model ) ) { Map<ArtifactRef, Dependency> profileDeps = new HashMap<>(); resolveDeps( session, profile.getDependencies(), false, profileDeps ); resolvedProfileDependencies.put( profile, profileDeps ); } return resolvedProfileDependencies; }
Example #9
Source File: UseReleasesMojo.java From versions-maven-plugin with Apache License 2.0 | 6 votes |
private void noRangeMatching( ModifiedPomXMLEventReader pom, Dependency dep, String version, String releaseVersion, ArtifactVersions versions ) throws XMLStreamException { if ( versions.containsVersion( releaseVersion ) ) { if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), version, releaseVersion, getProject().getModel() ) ) { getLog().info( "Updated " + toString( dep ) + " to version " + releaseVersion ); } } else if ( failIfNotReplaced ) { throw new NoSuchElementException( "No matching release of " + toString( dep ) + " found for update." ); } }
Example #10
Source File: PomAddDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void warnButAddIfPresentTest() throws IOException, XmlPullParserException { PomAddDependency uut = new PomAddDependency("xmlunit", "xmlunit", "1.7").relative("pom.xml").warnButAddIfPresent(); TOExecutionResult executionResult = uut.execution(transformedAppFolder, transformationContext); Assert.assertEquals(executionResult.getType(), TOExecutionResult.Type.WARNING); Assert.assertNull(executionResult.getException()); Dependency dependencyAfterChange = getDependencyInList(getTransformedPomModel("pom.xml"), "xmlunit", "xmlunit", "1.7"); Assert.assertNotNull(dependencyAfterChange); }
Example #11
Source File: BOMBuilderManipulator.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
private List<Dependency> getArtifacts( List<Project> projects ) { List<Dependency> results = new ArrayList<>( ); for ( Project p : projects ) { Dependency d = new Dependency(); d.setGroupId( p.getGroupId() ); d.setArtifactId( p.getArtifactId() ); d.setVersion( p.getVersion() ); d.setType( p.getModel().getPackaging() ); results.add( d ); } return results; }
Example #12
Source File: AddExtensionIT.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAddExtensionWithASingleExtensionWithPluralForm() throws MavenInvocationException, IOException { testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithASingleExtensionWithPluralForm"); invoker = initInvoker(testDir); addExtension(true, VERTX_ARTIFACT_ID); Model model = loadPom(testDir); Dependency expected = new Dependency(); expected.setGroupId(QUARKUS_GROUPID); expected.setArtifactId(VERTX_ARTIFACT_ID); assertThat(contains(model.getDependencies(), expected)).isTrue(); }
Example #13
Source File: PomRemoveDependency.java From butterfly with MIT License | 5 votes |
@Override protected TOExecutionResult pomExecution(String relativePomFile, Model model) { TOExecutionResult result = null; String details; Dependency dependency = getDependency(model, groupId, artifactId); if (dependency != null) { model.removeDependency(dependency); details = String.format("Dependency %s:%s has been removed from POM file %s", groupId, artifactId, relativePomFile); result = TOExecutionResult.success(this, details); } else { details = String.format("Dependency %s:%s has NOT been removed from POM file %s because it is not present", groupId, artifactId, relativePomFile); switch (ifNotPresent) { case Warn: result = TOExecutionResult.warning(this, new TransformationOperationException(details)); break; case NoOp: result = TOExecutionResult.noOp(this, details); break; case Fail: // Fail is the default default: result = TOExecutionResult.error(this, new TransformationOperationException(details)); break; } } return result; }
Example #14
Source File: DependencyUpdatesRenderer.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private void renderDependencyDetail( Dependency dependency, ArtifactVersions details ) { sink.section2(); sink.sectionTitle2(); sink.text( ArtifactUtils.versionlessKey( dependency.getGroupId(), dependency.getArtifactId() ) ); sink.sectionTitle2_(); renderDependencyDetailTable( dependency, details ); sink.section2_(); }
Example #15
Source File: ProjectVersionEnforcingManipulator.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
private void enforceDependencyProjectVersion( final Project project, final List<Dependency> dependencies, final Set<Project> changed ) { String newVersion = project.getVersion(); dependencies.stream().filter( d-> Version.PROJECT_VERSION.equals( d.getVersion() ) ).forEach( d -> { logger.debug( "Replacing project.version within {} for project {} with {}", d, project, newVersion ); d.setVersion( newVersion ); changed.add( project ); } ); }
Example #16
Source File: DependencyAddedInProfileTest.java From quarkus with Apache License 2.0 | 5 votes |
@Override protected TsArtifact modelApp() { final TsQuarkusExt extA_100 = new TsQuarkusExt("ext-a", "1.0.0"); addToExpectedLib(extA_100.getRuntime()); final TsQuarkusExt extB_100 = new TsQuarkusExt("ext-b", "1.0.0"); install(extB_100); final TsArtifact extB_100_rt = extB_100.getRuntime(); addToExpectedLib(extB_100_rt); final TsArtifact appJar = TsArtifact.jar("app") .addDependency(extA_100); final Profile profile = new Profile(); profile.setId("extra"); Activation activation = new Activation(); ActivationProperty ap = new ActivationProperty(); ap.setName("extra"); activation.setProperty(ap); profile.setActivation(activation); final Dependency dep = new Dependency(); dep.setGroupId(extB_100_rt.getGroupId()); dep.setArtifactId(extB_100_rt.getArtifactId()); dep.setVersion(extB_100_rt.getVersion()); profile.addDependency(dep); appJar.addProfile(profile); createWorkspace(); setSystemProperty("extra", "extra"); return appJar; }
Example #17
Source File: MavenDependency.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Dependency[] toDependencies(final Collection<? extends MavenDependency> dependencies) { final Dependency[] result = new Dependency[dependencies.size()]; final Iterator<? extends MavenDependency> iterator = dependencies.iterator(); for (int i = 0; iterator.hasNext(); ++i) result[i] = iterator.next().toDependency(); return result; }
Example #18
Source File: VertxDependency.java From vertx-maven-plugin with Apache License 2.0 | 5 votes |
public Dependency toDependency() { Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); if (scope != null && !scope.isEmpty()) { dependency.setScope(scope); } if (classifier != null && !classifier.isEmpty()) { dependency.setClassifier(classifier); } return dependency; }
Example #19
Source File: MavenUtil.java From java-specialagent with Apache License 2.0 | 5 votes |
public static Dependency newDependency(final String groupId, final String artifactId, final String version, final String classifier, final String type) { final Dependency dependency = new Dependency(); dependency.setGroupId(groupId); dependency.setArtifactId(artifactId); dependency.setVersion(version); dependency.setClassifier(classifier); if (type != null) dependency.setType(type); return dependency; }
Example #20
Source File: DisplayDependencyUpdatesMojo.java From versions-maven-plugin with Apache License 2.0 | 5 votes |
private static Set<Dependency> extractDependenciesFromPlugins( List<Plugin> plugins ) { Set<Dependency> result = new TreeSet<>( new DependencyComparator() ); for ( Plugin plugin : plugins ) { if ( plugin.getDependencies() != null && !plugin.getDependencies().isEmpty() ) { for ( Dependency pluginDependency : plugin.getDependencies() ) { result.add( pluginDependency ); } } } return result; }
Example #21
Source File: DependencyResolver.java From smart-testing with Apache License 2.0 | 5 votes |
private Dependency smartTestingProviderDependency() { final Dependency smartTestingSurefireProvider = new Dependency(); smartTestingSurefireProvider.setGroupId("org.arquillian.smart.testing"); smartTestingSurefireProvider.setArtifactId("surefire-provider"); smartTestingSurefireProvider.setVersion(ExtensionVersion.version().toString()); smartTestingSurefireProvider.setScope("runtime"); smartTestingSurefireProvider.setClassifier("shaded"); return smartTestingSurefireProvider; }
Example #22
Source File: MvnProjectBuilder.java From quarkus with Apache License 2.0 | 5 votes |
public MvnProjectBuilder addDependency(String artifactId) { final Dependency dep = new Dependency(); dep.setGroupId(DEFAULT_GROUP_ID); dep.setArtifactId(artifactId); dep.setVersion(DEFAULT_VERSION); return addDependency(dep); }
Example #23
Source File: CheckDependencyVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private Set<ArtifactCoordinates> getSnapshotsFromManagement(Profile profile, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed dependencies of profile '" + profile.getId() + "'"); DependencyManagement dependencyManagement = profile.getDependencyManagement(); if (dependencyManagement != null) { Collection<Dependency> snapshots = Collections2.filter(dependencyManagement.getDependencies(), new IsSnapshotDependency(propertyResolver)); return Sets.newHashSet(Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); } return Collections.emptySet(); }
Example #24
Source File: AbstractVersionsStep.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private void setProfilesReactorDependenciesVersion(MavenProject project, Document document) { List<Profile> profiles = this.rawModels.getUnchecked(project).getProfiles(); for (Profile profile : profiles) { final String dependenciesPath = "/profiles/profile[id[text()='" + profile.getId() + "']]"; List<Dependency> dependencies = profile.getDependencies(); for (Dependency dependency : dependencies) { trySetDependencyVersionFromReactorProjects(project, document, dependenciesPath, dependency); } } }
Example #25
Source File: MavenHelper.java From sarl with Apache License 2.0 | 5 votes |
/** Convert an artifact to a dependency. * * @param artifact the artifact to convert. * @return the result of the conversion. */ @SuppressWarnings("static-method") public Dependency toDependency(Artifact artifact) { final Dependency result = new Dependency(); result.setArtifactId(artifact.getArtifactId()); result.setClassifier(artifact.getClassifier()); result.setGroupId(artifact.getGroupId()); result.setOptional(artifact.isOptional()); result.setScope(artifact.getScope()); result.setType(artifact.getType()); result.setVersion(artifact.getVersion()); return result; }
Example #26
Source File: PomAddDependencyTest.java From butterfly with MIT License | 5 votes |
@Test public void addDependencyWithoutVersionTest() throws IOException, XmlPullParserException { PomAddDependency uut = new PomAddDependency("org.springframework.batch", "spring-batch-core").relative("pom.xml"); Assert.assertNull(getDependencyBeforeChange(uut)); executeAndAssertSuccess(uut); Dependency dependencyAfterChange = getDependencyAfterChange(uut); Assert.assertNotNull(dependencyAfterChange); Assert.assertEquals(dependencyAfterChange.getGroupId(), "org.springframework.batch"); Assert.assertEquals(dependencyAfterChange.getArtifactId(), "spring-batch-core"); Assert.assertEquals(dependencyAfterChange.getVersion(), null); Assert.assertEquals(dependencyAfterChange.getScope(), null); }
Example #27
Source File: AddExtensionMojoTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAddSingleDependency() throws MojoExecutionException, IOException, XmlPullParserException { mojo.extension = DEP_GAV; mojo.extensions = new HashSet<>(); mojo.execute(); Model reloaded = reload(); List<Dependency> dependencies = reloaded.getDependencies(); assertThat(dependencies).hasSize(1); assertThat(dependencies.get(0).getArtifactId()).isEqualTo("commons-lang3"); }
Example #28
Source File: Mojo.java From capsule-maven-plugin with MIT License | 5 votes |
private Dependency toDependency(final Artifact artifact) { if (artifact == null) return null; final Dependency dependency = new Dependency(); dependency.setGroupId(artifact.getGroupId()); dependency.setArtifactId(artifact.getArtifactId()); dependency.setVersion(artifact.getVersion()); dependency.setScope(artifact.getScope()); dependency.setClassifier(artifact.getClassifier()); dependency.setOptional(artifact.isOptional()); if (dependency.getScope() == null || dependency.getScope().isEmpty()) dependency.setScope("compile"); return dependency; }
Example #29
Source File: GenerateBomMojo.java From sundrio with Apache License 2.0 | 5 votes |
/** * Returns all dependency artifacts in all modules, excluding all reactor artifacts (including attached). * * @return */ private Set<Artifact> getProjectDependencies() { Set<Artifact> result = new LinkedHashSet<Artifact>(); for (MavenProject p : getSession().getProjectDependencyGraph().getSortedProjects()) { for (Dependency dependency : p.getDependencies()) { result.add(toArtifact(dependency)); } } return result; }
Example #30
Source File: AddExtensionMojoTest.java From quarkus with Apache License 2.0 | 5 votes |
@Test void testAddMultipleDependency() throws MojoExecutionException, IOException, XmlPullParserException { Set<String> deps = new HashSet<>(); deps.add(DEP_GAV); deps.add("commons-io:commons-io:2.6"); mojo.extensions = deps; mojo.execute(); Model reloaded = reload(); List<Dependency> dependencies = reloaded.getDependencies(); assertThat(dependencies).hasSize(2); }