org.apache.maven.model.DependencyManagement Java Examples
The following examples show how to use
org.apache.maven.model.DependencyManagement.
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: Project.java From pom-manipulation-ext with Apache License 2.0 | 6 votes |
/** * This method will scan the dependencies in the dependencyManagement section of the potentially active Profiles in * this project and return a fully resolved list. 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} (that were within DependencyManagement) * @throws ManipulationException if an error occurs */ public Map<Profile, Map<ArtifactRef, Dependency>> getResolvedProfileManagedDependencies( MavenSessionHandler session) throws ManipulationException { Map<Profile, Map<ArtifactRef, Dependency>> resolvedProfileManagedDependencies = new HashMap<>(); for ( final Profile profile : ProfileUtils.getProfiles( session, model ) ) { Map<ArtifactRef, Dependency> profileDeps = new HashMap<>(); final DependencyManagement dm = profile.getDependencyManagement(); if ( dm != null ) { resolveDeps( session, dm.getDependencies(), false, profileDeps ); } resolvedProfileManagedDependencies.put( profile, profileDeps ); } return resolvedProfileManagedDependencies; }
Example #2
Source File: LinkageCheckerRuleTest.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
private void setupMockDependencyManagementSection(String... coordinates) { org.apache.maven.artifact.DefaultArtifact bomArtifact = new org.apache.maven.artifact.DefaultArtifact( "com.google.dummy", "dummy-bom", "0.1", "compile", "pom", "", new DefaultArtifactHandler()); when(mockProject.getArtifact()).thenReturn(bomArtifact); DependencyManagement mockDependencyManagement = mock(DependencyManagement.class); when(mockProject.getDependencyManagement()).thenReturn(mockDependencyManagement); ImmutableList<org.apache.maven.model.Dependency> bomMembers = Arrays.stream(coordinates) .map(DefaultArtifact::new) .map(artifact -> new Dependency(artifact, "compile")) .map(LinkageCheckerRuleTest::toDependency) .collect(toImmutableList()); when(mockDependencyManagement.getDependencies()).thenReturn(bomMembers); when(mockMavenSession.getRepositorySession()).thenReturn(repositorySystemSession); }
Example #3
Source File: Bom.java From cloud-opensource-java with Apache License 2.0 | 6 votes |
public static Bom readBom(Path pomFile) throws MavenRepositoryException { RepositorySystem system = RepositoryUtility.newRepositorySystem(); RepositorySystemSession session = RepositoryUtility.newSession(system); MavenProject mavenProject = RepositoryUtility.createMavenProject(pomFile, session); String coordinates = mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + ":" + mavenProject.getVersion(); DependencyManagement dependencyManagement = mavenProject.getDependencyManagement(); List<org.apache.maven.model.Dependency> dependencies = dependencyManagement.getDependencies(); ArtifactTypeRegistry registry = session.getArtifactTypeRegistry(); ImmutableList<Artifact> artifacts = dependencies.stream() .map(dependency -> RepositoryUtils.toDependency(dependency, registry)) .map(Dependency::getArtifact) .filter(artifact -> !shouldSkipBomMember(artifact)) .collect(ImmutableList.toImmutableList()); Bom bom = new Bom(coordinates, artifacts); return bom; }
Example #4
Source File: RawXJC2Mojo.java From maven-jaxb2-plugin with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("unchecked") protected void injectDependencyDefaults(Dependency[] dependencies) { if (dependencies != null) { final Map<String, Dependency> dependencyMap = new TreeMap<String, Dependency>(); for (final Dependency dependency : dependencies) { if (dependency.getScope() == null) { dependency.setScope(Artifact.SCOPE_RUNTIME); } dependencyMap.put(dependency.getManagementKey(), dependency); } final DependencyManagement dependencyManagement = getProject().getDependencyManagement(); if (dependencyManagement != null) { merge(dependencyMap, dependencyManagement.getDependencies()); } merge(dependencyMap, getProjectDependencies()); } }
Example #5
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 #6
Source File: MavenArtifactResolvingHelper.java From thorntail with Apache License 2.0 | 6 votes |
public MavenArtifactResolvingHelper(ArtifactResolver resolver, RepositorySystem system, RepositorySystemSession session, DependencyManagement dependencyManagement) { this.resolver = resolver; this.system = system; this.session = session; this.dependencyManagement = dependencyManagement; this.remoteRepositories.add(buildRemoteRepository("jboss-public-repository-group", "https://repository.jboss.org/nexus/content/groups/public/", null, ENABLED_POLICY, DISABLED_POLICY)); this.remoteRepositories.add(buildRemoteRepository("redhat-ga", "https://maven.repository.redhat.com/ga/", null, ENABLED_POLICY, DISABLED_POLICY)); }
Example #7
Source File: GraphConstructor.java From netbeans with Apache License 2.0 | 5 votes |
private int obtainManagedState(MavenDependencyNode dependencyNode) { if (proj == null) { return GraphNode.UNMANAGED; } DependencyManagement dm = proj.getDependencyManagement(); if (dm == null) { return GraphNode.UNMANAGED; } @SuppressWarnings("unchecked") List<Dependency> deps = dm.getDependencies(); if (deps == null) { return GraphNode.UNMANAGED; } Artifact artifact = dependencyNode.getArtifact(); String id = artifact.getArtifactId(); String groupId = artifact.getGroupId(); String version = artifact.getVersion(); for (Dependency dep : deps) { if (id.equals(dep.getArtifactId()) && groupId.equals(dep.getGroupId())) { if (!version.equals(dep.getVersion())) { return GraphNode.OVERRIDES_MANAGED; } else { return GraphNode.MANAGED; } } } return GraphNode.UNMANAGED; }
Example #8
Source File: Project.java From pom-manipulation-ext with Apache License 2.0 | 5 votes |
/** * This method will scan the dependencies in the dependencyManagement section of this project and return a * fully resolved list. 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} (that were within DependencyManagement) * @throws ManipulationException if an error occurs */ public Map<ArtifactRef, Dependency> getResolvedManagedDependencies( MavenSessionHandler session ) throws ManipulationException { Map<ArtifactRef, Dependency> resolvedManagedDependencies = new HashMap<>(); final DependencyManagement dm = getModel().getDependencyManagement(); if ( !( dm == null || dm.getDependencies() == null ) ) { resolveDeps( session, dm.getDependencies(), false, resolvedManagedDependencies ); } return resolvedManagedDependencies; }
Example #9
Source File: GenerateBomMojo.java From sundrio with Apache License 2.0 | 5 votes |
/** * Returns all dependencies defined in dependency management of the root pom. * * @return */ private Set<Artifact> getProjectDependencyManagement() { Set<Artifact> result = new LinkedHashSet<Artifact>(); DependencyManagement dependencyManagement = getProject().getDependencyManagement(); if (dependencyManagement != null) { for (Dependency dependency : dependencyManagement.getDependencies()) { result.add(toArtifact(dependency)); } } return result; }
Example #10
Source File: MavenArtifactResolvingHelperTest.java From thorntail with Apache License 2.0 | 5 votes |
/** * @see #testArtifactExtensions() */ @Test public void testManagedDependenciesExtensions() throws Exception { // prepare mocks // always find an artifact in local repo Mockito.when(localRepositoryManager.find(Mockito.any(), Mockito.any(LocalArtifactRequest.class))) .thenReturn(new LocalArtifactResult(new LocalArtifactRequest()) .setAvailable(true).setFile(new File("test.jar"))); // return non-null when system.collectDependencies() is called CollectResult collectResult = new CollectResult(new CollectRequest()); collectResult.setRoot(new DefaultDependencyNode((Artifact) null)); Mockito.when(system.collectDependencies(Mockito.any(), Mockito.any(CollectRequest.class))) .thenReturn(collectResult); DependencyManagement dependencyManagement = new DependencyManagement(); dependencyManagement.addDependency(createDependency("ejb-client")); dependencyManagement.addDependency(createDependency("javadoc")); dependencyManagement.addDependency(createDependency("pom")); MavenArtifactResolvingHelper artifactResolverHelper = new MavenArtifactResolvingHelper(resolver, system, sessionMock, dependencyManagement); // try to resolve artifacts with various packagings List<ArtifactSpec> artifacts = Arrays.asList(createSpec("ejb"), createSpec("pom"), createSpec("javadoc")); artifactResolverHelper.resolveAll(artifacts, true, false); ArgumentCaptor<CollectRequest> captor = ArgumentCaptor.forClass(CollectRequest.class); Mockito.verify(system).collectDependencies(Mockito.any(), captor.capture()); // verify managed dependencies extensions Assert.assertEquals("jar", captor.getValue().getManagedDependencies().get(0).getArtifact().getExtension()); // type ejb-client Assert.assertEquals("jar", captor.getValue().getManagedDependencies().get(1).getArtifact().getExtension()); // type javadoc Assert.assertEquals("pom", captor.getValue().getManagedDependencies().get(2).getArtifact().getExtension()); // type pom // verify artifact extensions Assert.assertEquals("jar", captor.getValue().getDependencies().get(0).getArtifact().getExtension()); // packaging ejb Assert.assertEquals("pom", captor.getValue().getDependencies().get(1).getArtifact().getExtension()); // packaging pom Assert.assertEquals("jar", captor.getValue().getDependencies().get(2).getArtifact().getExtension()); // packaging javadoc }
Example #11
Source File: AbstractVersionsStep.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private void setProfilesReactorDependencyManagementVersion(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() + "']]/dependencyManagement"; DependencyManagement dependencyManagement = profile.getDependencyManagement(); if (dependencyManagement != null) { List<Dependency> dependencies = dependencyManagement.getDependencies(); for (Dependency dependency : dependencies) { trySetDependencyVersionFromReactorProjects(project, document, dependenciesPath, dependency); } } } }
Example #12
Source File: AbstractVersionsStep.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private void setProjectReactorDependencyManagementVersion(MavenProject project, Document document) { DependencyManagement dependencyManagement = this.rawModels.getUnchecked(project).getDependencyManagement(); if (dependencyManagement != null) { String dependenciesPath = "/dependencyManagement"; List<Dependency> dependencies = dependencyManagement.getDependencies(); for (Dependency dependency : dependencies) { trySetDependencyVersionFromReactorProjects(project, document, dependenciesPath, dependency); } } }
Example #13
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 #14
Source File: CheckDependencyVersions.java From unleash-maven-plugin with Eclipse Public License 1.0 | 5 votes |
private Set<ArtifactCoordinates> getSnapshotsFromManagement(MavenProject project, PomPropertyResolver propertyResolver) { this.log.debug("\t\tChecking managed dependencies"); DependencyManagement dependencyManagement = project.getDependencyManagement(); if (dependencyManagement != null) { Collection<Dependency> snapshots = Collections2.filter(dependencyManagement.getDependencies(), new IsSnapshotDependency(propertyResolver)); HashSet<ArtifactCoordinates> snapshotDependencies = Sets .newHashSet(Collections2.transform(snapshots, DependencyToCoordinates.INSTANCE)); filterMultiModuleDependencies(snapshotDependencies); return snapshotDependencies; } return Collections.emptySet(); }
Example #15
Source File: MavenHelpers.java From fabric8-forge with Apache License 2.0 | 5 votes |
/** * Returns true if the pom has the given managed dependency */ public static boolean hasManagedDependency(Model pom, String groupId, String artifactId) { if (pom != null) { DependencyManagement dependencyManagement = pom.getDependencyManagement(); if (dependencyManagement != null) { return hasDependency(dependencyManagement.getDependencies(), groupId, artifactId); } } return false; }
Example #16
Source File: PomCopyManagedDependencies.java From butterfly with MIT License | 5 votes |
@Override List<Dependency> getMavenDependencies(Model mavenModel) { DependencyManagement dependencyManagement = mavenModel.getDependencyManagement(); if (dependencyManagement == null) { return Collections.emptyList(); } return dependencyManagement.getDependencies(); }
Example #17
Source File: MavenUtil.java From java-specialagent with Apache License 2.0 | 5 votes |
public static String lookupVersion(final MavenProject project, final MavenDependency mavenDependency) throws MojoExecutionException { final DependencyManagement dependencyManagement = project.getModel().getDependencyManagement(); if (dependencyManagement != null) for (final Dependency dependency : dependencyManagement.getDependencies()) if (dependency.getGroupId().equals(mavenDependency.getGroupId()) && dependency.getArtifactId().equals(mavenDependency.getArtifactId())) return dependency.getVersion(); if (project.getParent() == null) throw new MojoExecutionException("Was not able to find the version of: " + mavenDependency.getGroupId() + ":" + mavenDependency.getArtifactId()); return lookupVersion(project.getParent(), mavenDependency); }
Example #18
Source File: VersionSubstitutingModelResolverTest.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
@Test public void testSubstitution() throws ArtifactResolutionException, ModelBuildingException { // Google-cloud-bom 0.121.0-alpha imports google-auth-library-bom 0.19.0. DefaultArtifact googleCloudBom = new DefaultArtifact("com.google.cloud:google-cloud-bom:pom:0.121.0-alpha"); ArtifactResult bomResult = repositorySystem.resolveArtifact( session, new ArtifactRequest(googleCloudBom, ImmutableList.of(CENTRAL), null)); ImmutableMap<String, String> substitution = ImmutableMap.of( "com.google.auth:google-auth-library-bom", "0.18.0" // This is intentionally different from 0.19.0 ); VersionSubstitutingModelResolver resolver = new VersionSubstitutingModelResolver( session, null, repositorySystem, remoteRepositoryManager, ImmutableList.of(CENTRAL), // Needed when parent pom is not locally available substitution); ModelBuildingRequest modelRequest = new DefaultModelBuildingRequest(); modelRequest.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL); modelRequest.setPomFile(bomResult.getArtifact().getFile()); modelRequest.setModelResolver(resolver); modelRequest.setSystemProperties(System.getProperties()); // for Java version property ModelBuildingResult result = modelBuilder.build(modelRequest); DependencyManagement dependencyManagement = result.getEffectiveModel().getDependencyManagement(); Truth.assertWithMessage( "Google-cloud-bom's google-auth-library part should be substituted for a different version.") .that(dependencyManagement.getDependencies()) .comparingElementsUsing(dependencyToCoordinates) .contains("com.google.auth:google-auth-library-credentials:0.18.0"); }
Example #19
Source File: LocationAwareMavenXpp3Writer.java From netbeans with Apache License 2.0 | 5 votes |
private void writeDependencyManagement(DependencyManagement dependencyManagement, String tagName, XmlSerializer serializer) throws java.io.IOException { serializer.startTag(NAMESPACE, tagName); if ((dependencyManagement.getDependencies() != null) && (dependencyManagement.getDependencies().size() > 0)) { serializer.startTag(NAMESPACE, "dependencies"); for (Iterator<Dependency> iter = dependencyManagement.getDependencies().iterator(); iter.hasNext();) { Dependency o = iter.next(); writeDependency(o, "dependency", serializer); } serializer.endTag(NAMESPACE, "dependencies"); } serializer.endTag(NAMESPACE, tagName); }
Example #20
Source File: PomCopyManagedDependencies.java From butterfly with MIT License | 5 votes |
@Override void addMavenDependencies(Model mavenModelTo, List<Dependency> dependencies) { if (mavenModelTo.getDependencyManagement() == null) { mavenModelTo.setDependencyManagement(new DependencyManagement()); } dependencies.forEach(d -> mavenModelTo.getDependencyManagement().addDependency(d)); }
Example #21
Source File: ResolverTest.java From migration-tooling with Apache License 2.0 | 5 votes |
private Model mockDepManagementModel(String dependencyManagementDep, String normalDep) { Dependency dmDep = getDependency(dependencyManagementDep); Dependency dep = getDependency(normalDep); Model mockModel = mock(Model.class); DependencyManagement dependencyManagement = new DependencyManagement(); dependencyManagement.addDependency(dmDep); when(mockModel.getDependencyManagement()).thenReturn(dependencyManagement); when(mockModel.getDependencies()).thenReturn(ImmutableList.of(dep)); return mockModel; }
Example #22
Source File: MavenNodeFactory.java From netbeans with Apache License 2.0 | 5 votes |
/** Creates a new instance of VersionNode */ public VersionNode(NBVersionInfo versionInfo, boolean fromDepMng) { super(Children.LEAF, fromDepMng ? Lookups.fixed(versionInfo, new DependencyManagement()) : Lookups.fixed(versionInfo)); this.nbvi = versionInfo; this.fromDepMng = fromDepMng; setName(versionInfo.getVersion()); StringBuilder sb = new StringBuilder(); if (fromDepMng) { sb.append(nbvi.getGroupId()); sb.append(DELIMITER); sb.append(nbvi.getArtifactId()); sb.append(DELIMITER); } else { sb.append(nbvi.getVersion()); } sb.append(" [ "); sb.append(nbvi.getType()); String classifier = nbvi.getClassifier(); if (classifier != null) { sb.append(","); sb.append(classifier); } sb.append(" ] "); String repo = nbvi.getRepoId(); if (repo != null) { sb.append(" - "); sb.append(repo); } setDisplayName(sb.toString()); setIconBaseWithExtension(IconResources.ICON_DEPENDENCY_JAR); }
Example #23
Source File: DependencyNode.java From netbeans with Apache License 2.0 | 5 votes |
public boolean isManaged() { DependencyManagement dm = project.getLookup().lookup(NbMavenProject.class).getMavenProject().getDependencyManagement(); if (dm != null) { List<Dependency> dmList = dm.getDependencies(); for (Dependency d : dmList) { if (art.getGroupId().equals(d.getGroupId()) && art.getArtifactId().equals(d.getArtifactId())) { return true; } } } return false; }
Example #24
Source File: AddDependencyPanel.java From netbeans with Apache License 2.0 | 5 votes |
private static List<Dependency> getDependenciesFromDM(MavenProject project, Project nbprj) { NbMavenProjectImpl p = nbprj.getLookup().lookup(NbMavenProjectImpl.class); MavenProject localProj = project; DependencyManagement curDM; List<Dependency> result = new ArrayList<Dependency>(); //mkleint: without the managementKey checks I got some entries multiple times. // do we actually need to traverse the parent poms, are they completely resolved anyway? //XXX Set<String> knownKeys = new HashSet<String>(); while (localProj != null) { curDM = localProj.getDependencyManagement(); if (curDM != null) { @SuppressWarnings("unchecked") List<Dependency> ds = curDM.getDependencies(); for (Dependency d : ds) { if (knownKeys.contains(d.getManagementKey())) { continue; } result.add(d); knownKeys.add(d.getManagementKey()); } } try { localProj = p.loadParentOf(EmbedderFactory.getProjectEmbedder(), localProj); } catch (ProjectBuildingException x) { break; } } Collections.sort(result, new Comparator<Dependency>() { @Override public int compare(Dependency o1, Dependency o2) { return o1.getManagementKey().compareTo(o2.getManagementKey()); } }); return result; }
Example #25
Source File: Verify.java From vertx-maven-plugin with Apache License 2.0 | 4 votes |
public static void verifySetup(File pomFile) throws Exception { assertNotNull("Unable to find pom.xml", pomFile); MavenXpp3Reader xpp3Reader = new MavenXpp3Reader(); Model model = xpp3Reader.read(new FileInputStream(pomFile)); MavenProject project = new MavenProject(model); Optional<Plugin> vmPlugin = MojoUtils.hasPlugin(project, "io.reactiverse:vertx-maven-plugin"); assertTrue(vmPlugin.isPresent()); //Check if the properties have been set correctly Properties properties = model.getProperties(); assertThat(properties.containsKey("vertx.projectVersion")).isTrue(); assertThat(properties.getProperty("vertx.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-core-version")); assertThat(properties.containsKey("reactiverse-vertx-maven-plugin.projectVersion")).isTrue(); assertThat(properties.getProperty("reactiverse-vertx-maven-plugin.projectVersion")) .isEqualTo(MojoUtils.getVersion("vertx-maven-plugin-version")); //Check if the dependencies has been set correctly DependencyManagement dependencyManagement = model.getDependencyManagement(); assertThat(dependencyManagement).isNotNull(); assertThat(dependencyManagement.getDependencies().isEmpty()).isFalse(); //Check Vert.x dependencies BOM Optional<Dependency> vertxDeps = dependencyManagement.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-dependencies") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxDeps.isPresent()).isTrue(); assertThat(vertxDeps.get().getVersion()).isEqualTo("${vertx.projectVersion}"); //Check Vert.x core dependency Optional<Dependency> vertxCoreDep = model.getDependencies().stream() .filter(d -> d.getArtifactId().equals("vertx-core") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxCoreDep.isPresent()).isTrue(); assertThat(vertxCoreDep.get().getVersion()).isNull(); //Check Redeploy Configuration Plugin vmp = project.getPlugin("io.reactiverse:vertx-maven-plugin"); Assert.assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); Assert.assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); Assert.assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
Example #26
Source File: GitVersioningExtensionIT.java From maven-git-versioning-extension with MIT License | 4 votes |
@Test void commitVersioning_multiModuleProject() throws Exception { // Given Git.init().setDirectory(projectDir.toFile()).call(); pomModel.setPackaging("pom"); pomModel.addModule("api"); pomModel.addModule("logic"); pomModel.setDependencyManagement(new DependencyManagement() {{ addDependency(new Dependency() {{ setGroupId("${project.groupId}"); setArtifactId("api"); setVersion("${project.version}"); }}); addDependency(new Dependency() {{ setGroupId("${project.groupId}"); setArtifactId("logic"); setVersion("${project.version}"); }}); }}); writeModel(projectDir.resolve("pom.xml").toFile(), pomModel); writeExtensionsFile(projectDir); writeExtensionConfigFile(projectDir, new Configuration()); Path apiProjectDir = Files.createDirectories(projectDir.resolve("api")); Model apiPomModel = writeModel(apiProjectDir.resolve("pom.xml").toFile(), new Model() {{ setModelVersion(pomModel.getModelVersion()); setParent(new Parent() {{ setGroupId(pomModel.getGroupId()); setArtifactId(pomModel.getArtifactId()); setVersion(pomModel.getVersion()); }}); setArtifactId("api"); setVersion(pomModel.getVersion()); }}); Path logicProjectDir = Files.createDirectories(projectDir.resolve("logic")); Model logicPomModel = writeModel(logicProjectDir.resolve("pom.xml").toFile(), new Model() {{ setModelVersion(pomModel.getModelVersion()); setParent(new Parent() {{ setGroupId(pomModel.getGroupId()); setArtifactId(pomModel.getArtifactId()); setVersion(pomModel.getVersion()); }}); setArtifactId("logic"); }}); // When Verifier verifier = new Verifier(projectDir.toFile().getAbsolutePath()); verifier.executeGoal("verify"); // Then String log = getLog(verifier); assertThat(log).doesNotContain("[ERROR]", "[FATAL]"); String expectedVersion = NO_COMMIT; assertThat(log).contains("Building " + pomModel.getArtifactId() + " " + expectedVersion); Model gitVersionedPomModel = readModel(projectDir.resolve("target/").resolve(GIT_VERSIONING_POM_NAME).toFile()); assertThat(gitVersionedPomModel).satisfies(it -> assertSoftly(softly -> { softly.assertThat(it.getModelVersion()).isEqualTo(pomModel.getModelVersion()); softly.assertThat(it.getGroupId()).isEqualTo(pomModel.getGroupId()); softly.assertThat(it.getArtifactId()).isEqualTo(pomModel.getArtifactId()); softly.assertThat(it.getVersion()).isEqualTo(expectedVersion); softly.assertThat(it.getProperties()).doesNotContainKeys( "git.commit", "git.ref" ); })); Model apiGitVersionedPomModel = readModel(apiProjectDir.resolve("target/").resolve(GIT_VERSIONING_POM_NAME).toFile()); assertThat(apiGitVersionedPomModel).satisfies(it -> assertSoftly(softly -> { softly.assertThat(it.getModelVersion()).isEqualTo(apiPomModel.getModelVersion()); softly.assertThat(it.getGroupId()).isEqualTo(apiPomModel.getGroupId()); softly.assertThat(it.getArtifactId()).isEqualTo(apiPomModel.getArtifactId()); softly.assertThat(it.getVersion()).isEqualTo(expectedVersion); softly.assertThat(it.getProperties()).doesNotContainKeys( "git.commit", "git.ref" ); })); Model logicGitVersionedPomModel = readModel(logicProjectDir.resolve("target/").resolve(GIT_VERSIONING_POM_NAME).toFile()); assertThat(logicGitVersionedPomModel).satisfies(it -> assertSoftly(softly -> { softly.assertThat(it.getModelVersion()).isEqualTo(logicPomModel.getModelVersion()); softly.assertThat(it.getGroupId()).isEqualTo(logicPomModel.getGroupId()); softly.assertThat(it.getArtifactId()).isEqualTo(logicPomModel.getArtifactId()); softly.assertThat(it.getVersion()).isEqualTo(null); softly.assertThat(it.getProperties()).doesNotContainKeys( "git.commit", "git.ref" ); })); }
Example #27
Source File: QuarkusProjectMojoBase.java From quarkus with Apache License 2.0 | 4 votes |
private List<Dependency> getManagedDependencies() throws IOException { final DependencyManagement managed = project.getModel().getDependencyManagement(); return managed != null ? managed.getDependencies() : Collections.emptyList(); }
Example #28
Source File: PomProperty.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
@Override public DependencyManagement get( Model model ) { return model.getDependencyManagement(); }
Example #29
Source File: PomProperty.java From flatten-maven-plugin with Apache License 2.0 | 4 votes |
@Override public void set( Model model, DependencyManagement value ) { model.setDependencyManagement( value ); }
Example #30
Source File: KotlinCreateMavenProjectIT.java From quarkus with Apache License 2.0 | 4 votes |
@Test public void testProjectGenerationFromScratchForKotlin() throws MavenInvocationException, IOException { testDir = initEmptyProject("projects/project-generation-kotlin"); assertThat(testDir).isDirectory(); invoker = initInvoker(testDir); Properties properties = new Properties(); properties.put("projectGroupId", "org.acme"); properties.put("projectArtifactId", "acme"); properties.put("projectVersion", "1.0-SNAPSHOT"); properties.put("extensions", "kotlin,resteasy-jsonb"); setup(properties); // As the directory is not empty (log) navigate to the artifactID directory testDir = new File(testDir, "acme"); assertThat(new File(testDir, "pom.xml")).isFile(); assertThat(new File(testDir, "src/main/kotlin")).isDirectory(); assertThat(new File(testDir, "src/main/resources/application.properties")).isFile(); String config = Files .asCharSource(new File(testDir, "src/main/resources/application.properties"), Charsets.UTF_8) .read(); assertThat(config).contains("key = value"); assertThat(new File(testDir, "src/main/docker/Dockerfile.native")).isFile(); assertThat(new File(testDir, "src/main/docker/Dockerfile.jvm")).isFile(); Model model = loadPom(testDir); final DependencyManagement dependencyManagement = model.getDependencyManagement(); final List<Dependency> dependencies = dependencyManagement.getDependencies(); assertThat(dependencies.stream() .anyMatch(d -> d.getArtifactId().equals(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLATFORM_ARTIFACT_ID_VALUE) && d.getVersion().equals(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLATFORM_VERSION_VALUE) && d.getScope().equalsIgnoreCase("import") && d.getType().equalsIgnoreCase("pom"))).isTrue(); assertThat( model.getDependencies().stream().anyMatch(d -> d.getArtifactId().equalsIgnoreCase("quarkus-resteasy") && d.getVersion() == null)).isTrue(); assertThat( model.getDependencies().stream().anyMatch(d -> d.getArtifactId().equalsIgnoreCase("quarkus-kotlin") && d.getVersion() == null)).isTrue(); assertThat(model.getProfiles()).hasSize(1); assertThat(model.getProfiles().get(0).getId()).isEqualTo("native"); }