Java Code Examples for org.apache.maven.model.Model#getProperties()

The following examples show how to use org.apache.maven.model.Model#getProperties() . 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: PomUtils.java    From helidon-build-tools with Apache License 2.0 5 votes vote down vote up
private static boolean ensurePluginVersion(Model model, String helidonPluginVersion) {
    Properties properties = model.getProperties();
    String existing = properties.getProperty(HELIDON_PLUGIN_VERSION_PROPERTY);
    if (existing == null || !existing.equals(helidonPluginVersion)) {
        model.addProperty(HELIDON_PLUGIN_VERSION_PROPERTY, helidonPluginVersion);
        return true;
    } else {
        return false;
    }
}
 
Example 2
Source File: VerifyMojo.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private Map<String,String> scanRenames() throws IOException, XmlPullParserException {
  final BufferedReader in = new BufferedReader(new FileReader(project.getParent().getFile()));
  final MavenXpp3Reader reader = new MavenXpp3Reader();
  final Model model = reader.read(in);
  final Properties properties = model.getProperties();
  final Map<String,String> renames = new HashMap<>();
  for (final Dependency dependency : model.getDependencies()) {
    final String rename = properties.getProperty(dependency.getArtifactId());
    if (rename != null)
      renames.put(dependency.getArtifactId() + "-" + dependency.getVersion() + ".jar", rename + ".jar");
  }

  return renames;
}
 
Example 3
Source File: MojoUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static void write(Model model, OutputStream fileOutputStream) throws IOException {
    final Properties props = model.getProperties();
    // until we can preserve the user ordering, it's better to stick to the alphabetical one
    if (!props.isEmpty() && !(props instanceof SortedProperties)) {
        final Properties sorted = new SortedProperties();
        sorted.putAll(props);
        model.setProperties(sorted);
    }
    try (OutputStream stream = fileOutputStream) {
        new MavenXpp3Writer().write(stream, model);
    }
}
 
Example 4
Source File: ModelUtils.java    From quarkus with Apache License 2.0 5 votes vote down vote up
/**
 * If the model contains properties, this method overrides those that appear to be
 * defined as system properties.
 */
public static Model applySystemProperties(Model model) {
    final Properties props = model.getProperties();
    for (Map.Entry<Object, Object> prop : model.getProperties().entrySet()) {
        final String systemValue = PropertyUtils.getProperty(prop.getKey().toString());
        if (systemValue != null) {
            props.put(prop.getKey(), systemValue);
        }
    }
    return model;
}
 
Example 5
Source File: PomAddProperty.java    From butterfly with MIT License 5 votes vote down vote up
@Override
protected TOExecutionResult pomExecution(String relativePomFile, Model model) {
    Exception warning = null;

    if (model.getProperties() == null ) {
        model.setProperties(new Properties());
    }

    Properties properties = model.getProperties();

    if (properties.getProperty(propertyName) != null) {
        String notAddMessage = "Property " + propertyName + " was not added to POM file " + getRelativePath() + " because it is already present";
        switch (ifPresent) {
            case WarnNotAdd:
                return TOExecutionResult.warning(this, new TransformationOperationException(notAddMessage));
            case WarnButAdd:
                warning = new TransformationOperationException("Property " + propertyName + " was already present in POM file " + getRelativePath() + ", but it was overwritten to " + propertyValue);
                break;
            case NoOp:
                return TOExecutionResult.noOp(this, notAddMessage);
            case Overwrite:
                // Nothing to be done here
                break;
            case Fail:
                // Fail is the default
            default:
                return TOExecutionResult.error(this, new TransformationOperationException(notAddMessage));
        }
    }

    properties.put(propertyName, propertyValue);
    String details = String.format("Property %s=%s has been added to POM file %s", propertyName, propertyValue, relativePomFile);
    TOExecutionResult result = TOExecutionResult.success(this, details);

    if (warning != null) {
        result.addWarning(warning);
    }

    return result;
}
 
Example 6
Source File: ThorntailFacet.java    From thorntail-addon with Eclipse Public License 1.0 5 votes vote down vote up
private void addSwarmVersionProperty()
{
   MavenFacet maven = getFaceted().getFacet(MavenFacet.class);
   Model pom = maven.getModel();
   Properties properties = pom.getProperties();
   properties.setProperty(THORNTAIL_VERSION_PROPERTY, getWildflySwarmVersion());
   maven.setModel(pom);
}
 
Example 7
Source File: GenerateReleaseTrainDocs.java    From spring-cloud-release with Apache License 2.0 5 votes vote down vote up
List<Project> mavenPropertiesToDocsProjects(File file) {
	Model model = PomReader.readPom(file);
	Properties properties = model.getProperties();
	return properties.entrySet().stream()
			.filter(e -> e.getKey().toString().endsWith(".version"))
			.map(e -> new Project(e.getKey().toString().replace(".version", ""),
					e.getValue().toString()))
			.collect(Collectors.toCollection(LinkedList::new));
}
 
Example 8
Source File: ModelIO.java    From pom-manipulation-ext with Apache License 2.0 5 votes vote down vote up
public Properties getRemotePropertyMappingOverrides( final ProjectVersionRef ref )
                throws ManipulationException
{
    logger.debug( "Resolving remote property mapping POM: " + ref );

    final Model m = resolveRawModel( ref );

    logger.debug( "Returning override of " + m.getProperties() );

    return m.getProperties();
}
 
Example 9
Source File: CamelQuarkusExtension.java    From camel-quarkus with Apache License 2.0 4 votes vote down vote up
public static CamelQuarkusExtension read(Path runtimePomXmlPath) {
    try (Reader runtimeReader = Files.newBufferedReader(runtimePomXmlPath, StandardCharsets.UTF_8)) {
        final MavenXpp3Reader rxppReader = new MavenXpp3Reader();
        final Model runtimePom = rxppReader.read(runtimeReader);
        final List<Dependency> deps = runtimePom.getDependencies();

        final String aid = runtimePom.getArtifactId();
        String camelComponentArtifactId = null;
        if (deps != null && !deps.isEmpty()) {
            Optional<Dependency> artifact = deps.stream()
                    .filter(dep ->

                    "org.apache.camel".equals(dep.getGroupId()) &&
                            ("compile".equals(dep.getScope()) || dep.getScope() == null))
                    .findFirst();
            if (artifact.isPresent()) {
                camelComponentArtifactId = CqCatalog.toCamelComponentArtifactIdBase(artifact.get().getArtifactId());
            }
        }
        final Properties props = runtimePom.getProperties() != null ? runtimePom.getProperties() : new Properties();

        String name = props.getProperty("title");
        if (name == null) {
            name = CqUtils.getNameBase(runtimePom.getName());
        }

        final String version = CqUtils.getVersion(runtimePom);

        return new CamelQuarkusExtension(
                runtimePomXmlPath,
                camelComponentArtifactId,
                (String) props.get("firstVersion"),
                aid,
                name,
                runtimePom.getDescription(),
                props.getProperty("label"),
                version,
                !runtimePomXmlPath.getParent().getParent().getParent().getFileName().toString().endsWith("-jvm"),
                deps == null ? Collections.emptyList() : Collections.unmodifiableList(deps));
    } catch (IOException | XmlPullParserException e) {
        throw new RuntimeException("Could not read " + runtimePomXmlPath, e);
    }
}
 
Example 10
Source File: Verify.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
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 11
Source File: SetupVerifier.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public static void verifySetup(File pomFile) throws Exception {
    assertNotNull(pomFile, "Unable to find pom.xml");
    MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
    Model model = xpp3Reader.read(new FileInputStream(pomFile));

    MavenProject project = new MavenProject(model);

    Optional<Plugin> maybe = hasPlugin(project, ToolsConstants.IO_QUARKUS + ":" + ToolsConstants.QUARKUS_MAVEN_PLUGIN);
    assertThat(maybe).isNotEmpty();

    //Check if the properties have been set correctly
    Properties properties = model.getProperties();
    assertThat(properties.containsKey(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLATFORM_GROUP_ID_NAME)).isTrue();
    assertThat(properties.containsKey(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLATFORM_ARTIFACT_ID_NAME)).isTrue();
    assertThat(properties.containsKey(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLATFORM_VERSION_NAME)).isTrue();
    assertThat(properties.containsKey(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLUGIN_VERSION_NAME)).isTrue();

    // Check plugin is set
    Plugin plugin = maybe.orElseThrow(() -> new AssertionError("Plugin expected"));
    assertThat(plugin).isNotNull().satisfies(p -> {
        assertThat(p.getArtifactId()).isEqualTo(ToolsConstants.QUARKUS_MAVEN_PLUGIN);
        assertThat(p.getGroupId()).isEqualTo(ToolsConstants.IO_QUARKUS);
        assertThat(p.getVersion()).isEqualTo(MojoUtils.TEMPLATE_PROPERTY_QUARKUS_PLUGIN_VERSION_VALUE);
    });

    // Check build execution Configuration
    assertThat(plugin.getExecutions()).hasSize(1).allSatisfy(execution -> {
        assertThat(execution.getGoals()).containsExactly("build");
        assertThat(execution.getConfiguration()).isNull();
    });

    // Check profile
    assertThat(model.getProfiles()).hasSize(1);
    Profile profile = model.getProfiles().get(0);
    assertThat(profile.getId()).isEqualTo("native");
    Plugin actual = profile.getBuild().getPluginsAsMap()
            .get(ToolsConstants.IO_QUARKUS + ":" + ToolsConstants.QUARKUS_MAVEN_PLUGIN);
    assertThat(actual).isNotNull();
    assertThat(actual.getExecutions()).hasSize(1).allSatisfy(exec -> {
        assertThat(exec.getGoals()).containsExactly("native-image");
        assertThat(exec.getConfiguration()).isInstanceOf(Xpp3Dom.class)
                .satisfies(o -> assertThat(o.toString()).contains("enableHttpUrlHandler"));
    });
}
 
Example 12
Source File: Verify.java    From vertx-maven-plugin with Apache License 2.0 4 votes vote down vote up
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 13
Source File: PomProperty.java    From flatten-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Properties get( Model model )
{
    return model.getProperties();
}