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

The following examples show how to use org.apache.maven.model.Model#setProperties() . These examples are extracted from open source projects. 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 Project: quarkus   File: MojoUtils.java    License: 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 2
Source Project: butterfly   File: PomAddProperty.java    License: 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 3
private static MavenProject createProject(Path path) {
    MavenProject project = new MavenProject();
    Model model = new Model();
    model.setProperties(new Properties());
    project.setModel(model);
    project.setArtifactId(path.getFileName().toString());
    project.setGroupId(path.getFileName().toString());
    project.setVersion("1");
    project.setFile(path.resolve("pom.xml").toFile());
    return project;
}
 
Example 4
ModelWrapper modelWithSameValues() {
	Model model = new Model();
	model.setProperties(propertiesWithSameValues());
	return new ModelWrapper(model);
}
 
Example 5
ModelWrapper nonMatchingModel() {
	Model model = new Model();
	model.setProperties(nonMatchingProperties());
	return new ModelWrapper(model);
}
 
Example 6
@Override
public void set( Model model, Properties value )
{
    model.setProperties( value );
}