All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.bnd.ant.ExpandPropertiesTask Maven / Gradle / Ivy

Go to download

This command line utility is the Swiss army knife of OSGi. It provides you with a breadth of tools to understand and manage OSGi based systems. This project basically uses bndlib.

There is a newer version: 7.1.0
Show newest version
package aQute.bnd.ant;

import java.io.File;
import java.io.IOException;
import java.util.Properties;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;

import aQute.bnd.osgi.Processor;
import aQute.lib.utf8properties.UTF8Properties;

public class ExpandPropertiesTask extends BaseTask {
	File propertyFile;

	@Override
	@SuppressWarnings("unchecked")
	public void execute() throws BuildException {
		try {
			if (propertyFile.exists()) {
				Properties properties = new UTF8Properties();
				properties.putAll(getProject().getProperties());

				try (Processor processor = new Processor(properties)) {
					processor.setProperties(propertyFile);

					Project project = getProject();
					Properties flattened = processor.getFlattenedProperties();
					for (Object object : flattened.keySet()) {
						String key = (String) object;
						if (project.getProperty(key) == null) {
							project.setProperty(key, flattened.getProperty(key));
						}
					}
				}
			}
			report();
		} catch (IOException e) {
			e.printStackTrace();
			throw new BuildException(e);
		}
	}

	public void setPropertyFile(File file) {
		this.propertyFile = file;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy