Java Code Examples for org.apache.maven.model.Model#getDependencyManagement()
The following examples show how to use
org.apache.maven.model.Model#getDependencyManagement() .
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: 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 2
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 3
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 4
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.version")).isTrue(); assertThat(properties.getProperty("vertx.version")) .isEqualTo(MojoUtils.getVersion("vertx-core-version")); assertThat(properties.containsKey("vertx-maven-plugin.version")).isTrue(); assertThat(properties.getProperty("vertx-maven-plugin.version")) .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-stack-depchain") && d.getGroupId().equals("io.vertx")) .findFirst(); assertThat(vertxDeps.isPresent()).isTrue(); assertThat(vertxDeps.get().getVersion()).isEqualTo("${vertx.version}"); //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"); assertNotNull(vmp); Xpp3Dom pluginConfig = (Xpp3Dom) vmp.getConfiguration(); assertNotNull(pluginConfig); String redeploy = pluginConfig.getChild("redeploy").getValue(); assertNotNull(redeploy); assertTrue(Boolean.valueOf(redeploy)); }
Example 5
Source File: ScalaCreateMavenProjectIT.java From quarkus with Apache License 2.0 | 4 votes |
@Test public void testProjectGenerationFromScratchForScala() throws MavenInvocationException, IOException { testDir = initEmptyProject("projects/project-generation-scala"); 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", "scala,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/scala")).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().equals("import") && d.getType().equals("pom"))).isTrue(); assertThat( model.getDependencies().stream().anyMatch(d -> d.getArtifactId().equals("quarkus-resteasy") && d.getVersion() == null)).isTrue(); assertThat( model.getDependencies().stream().anyMatch(d -> d.getArtifactId().equals("quarkus-scala") && d.getVersion() == null)).isTrue(); assertThat(model.getProfiles()).hasSize(1); assertThat(model.getProfiles().get(0).getId()).isEqualTo("native"); }
Example 6
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"); }
Example 7
Source File: AbstractArtifactPomOperation.java From butterfly with MIT License | 4 votes |
protected Dependency getManagedDependency(Model model, String groupId, String artifactId) { if (model.getDependencyManagement() == null) { return null; } return getDependencyInList(model.getDependencyManagement().getDependencies(), groupId, artifactId); }
Example 8
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 9
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 10
Source File: ProjectVersionEnforcingManipulator.java From pom-manipulation-ext with Apache License 2.0 | 4 votes |
/** * For each project in the current build set, reset the version if using project.version */ @Override public Set<Project> applyChanges( final List<Project> projects ) { final ProjectVersionEnforcingState state = session.getState( ProjectVersionEnforcingState.class ); if ( !session.isEnabled() || !session.anyStateEnabled( State.activeByDefault ) || state == null || !state.isEnabled() ) { logger.debug( "Project version enforcement is disabled." ); return Collections.emptySet(); } final Set<Project> changed = new HashSet<>(); for ( final Project project : projects ) { final Model model = project.getModel(); model.getProperties().stringPropertyNames().stream().filter( k -> model.getProperties().getProperty( k ).equals( Version.PROJECT_VERSION ) ). forEach( k -> { logger.debug( "Replacing project.version within properties for project {} with key {}", project, k ); model.getProperties().setProperty( k, project.getVersion() ); changed.add( project ); } ); // TODO: We _could_ change it everywhere but it only really breaks in POM files. if ( model.getPackaging().equals( "pom" ) ) { enforceDependencyProjectVersion( project, model.getDependencies(), changed ); if ( model.getDependencyManagement() != null ) { enforceDependencyProjectVersion( project, model.getDependencyManagement().getDependencies(), changed ); } if ( model.getBuild() != null ) { enforcePluginProjectVersion( project, model.getBuild().getPlugins(), changed ); if ( model.getBuild().getPluginManagement() != null ) { enforcePluginProjectVersion( project, model.getBuild().getPluginManagement().getPlugins(), changed ); } } final List<Profile> profiles = ProfileUtils.getProfiles( session, model); for ( final Profile profile : profiles ) { enforceDependencyProjectVersion( project, profile.getDependencies(), changed ); if ( profile.getDependencyManagement() != null ) { enforceDependencyProjectVersion( project, profile.getDependencyManagement().getDependencies(), changed ); } if ( profile.getBuild() != null ) { enforcePluginProjectVersion( project, profile.getBuild().getPlugins(), changed ); if ( profile.getBuild().getPluginManagement() != null ) { enforcePluginProjectVersion( project, profile.getBuild().getPluginManagement().getPlugins(), changed ); } } } } } if (!changed.isEmpty()) { logger.warn( "Using ${project.version} in pom files may lead to unexpected errors with inheritance." ); } return changed; }