use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.
the class Log4jLogQuery method loadCoords.
protected String loadCoords(String coords, String filePath, String classifier) throws IOException {
String[] split = coords.split("/");
if (split != null && split.length > 2) {
String groupId = split[0];
String artifactId = split[1];
String version = split[2];
if (resolver == null) {
Properties defaultProperties = getDefaultProperties();
Properties systemProperties = System.getProperties();
if (config == null) {
Properties combined = new Properties();
combined.putAll(defaultProperties);
combined.putAll(systemProperties);
if (properties != null) {
combined.putAll(properties);
}
config = new MavenConfigurationImpl(new PropertiesPropertyResolver(combined), ServiceConstants.PID);
}
resolver = new AetherBasedResolver(config);
}
File file = resolver.resolveFile(groupId, artifactId, classifier, "jar", version);
if (file.exists() && file.isFile()) {
if (isRoot(filePath)) {
return jarIndex(file);
}
String fileUri = file.toURI().toString();
URL url = new URL("jar:" + fileUri + "!" + filePath);
return loadString(url);
}
}
return null;
}
use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.
the class ProfileDisplayAction method displayProfile.
private void displayProfile(Profile profile) {
PrintStream output = System.out;
output.println("Profile id: " + profile.getId());
output.println("Version : " + profile.getVersion());
output.println("Attributes: ");
Map<String, String> props = profile.getAttributes();
for (String key : props.keySet()) {
output.println("\t" + key + ": " + props.get(key));
}
String versionId = profile.getVersion();
String profileId = profile.getId();
output.printf("Containers: %s\n", toString(fabricService.getAssociatedContainers(versionId, profileId)));
ProfileService profileService = fabricService.adapt(ProfileService.class);
if (overlay) {
profile = profileService.getOverlayProfile(profile);
}
Map<String, Map<String, String>> configuration = new HashMap<>(profile.getConfigurations());
Map<String, byte[]> resources = profile.getFileConfigurations();
Map<String, String> agentConfiguration = profile.getConfiguration(Constants.AGENT_PID);
List<String> agentProperties = new ArrayList<String>();
List<String> systemProperties = new ArrayList<String>();
List<String> configProperties = new ArrayList<String>();
List<String> otherResources = new ArrayList<String>();
for (Map.Entry<String, String> entry : agentConfiguration.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value.contains(",")) {
value = "\t" + value.replace(",", ",\n\t\t");
}
if (key.startsWith("system.")) {
systemProperties.add(" " + key.substring("system.".length()) + " = " + value);
} else if (key.startsWith("config.")) {
configProperties.add(" " + key.substring("config.".length()) + " = " + value);
} else if (!key.startsWith("feature.") && !key.startsWith("repository") && !key.startsWith("bundle.") && !key.startsWith("fab.") && !key.startsWith("override.") && !key.startsWith("attribute.")) {
agentProperties.add(" " + key + " = " + value);
}
}
if (configuration.containsKey(Constants.AGENT_PID)) {
output.println("\nContainer settings");
output.println("----------------------------");
if (profile.getLibraries().size() > 0) {
printConfigList("Libraries : ", output, profile.getLibraries());
}
if (profile.getRepositories().size() > 0) {
printConfigList("Repositories : ", output, profile.getRepositories());
}
if (profile.getFeatures().size() > 0) {
printConfigList("Features : ", output, profile.getFeatures());
}
if (profile.getBundles().size() > 0) {
printConfigList("Bundles : ", output, profile.getBundles());
}
if (profile.getFabs().size() > 0) {
printConfigList("Fabs : ", output, profile.getFabs());
}
if (profile.getOverrides().size() > 0) {
printConfigList("Overrides : ", output, profile.getOverrides());
}
if (agentProperties.size() > 0) {
printConfigList("Agent Properties : ", output, agentProperties);
}
if (systemProperties.size() > 0) {
printConfigList("System Properties : ", output, systemProperties);
}
if (configProperties.size() > 0) {
printConfigList("Config Properties : ", output, configProperties);
}
configuration.remove(Constants.AGENT_PID);
}
output.println("\nConfiguration details");
output.println("----------------------------");
for (Map.Entry<String, Map<String, String>> cfg : configuration.entrySet()) {
output.println("PID: " + cfg.getKey());
for (Map.Entry<String, String> values : cfg.getValue().entrySet()) {
output.println(" " + values.getKey() + " " + values.getValue());
}
output.println("\n");
}
output.println("\nOther resources");
output.println("----------------------------");
for (Map.Entry<String, byte[]> resource : resources.entrySet()) {
String name = resource.getKey();
if (!name.endsWith(".properties")) {
output.println("Resource: " + resource.getKey());
if (displayResources) {
output.println(new String(resource.getValue(), Charsets.UTF_8));
output.println("\n");
}
}
}
}
use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.
the class ProfileEditAction method editProfile.
private void editProfile(Profile profile) throws Exception {
boolean editInLine = false;
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
if (delete || remove) {
editInLine = true;
}
if (features != null && features.length > 0) {
editInLine = true;
handleFeatures(builder, features, profile);
}
if (repositories != null && repositories.length > 0) {
editInLine = true;
handleFeatureRepositories(builder, repositories, profile);
}
if (libs != null && libs.length > 0) {
editInLine = true;
handleLibraries(builder, libs, profile, "lib", LIB_PREFIX);
}
if (endorsed != null && endorsed.length > 0) {
editInLine = true;
handleLibraries(builder, endorsed, profile, "endorsed lib", ENDORSED_PREFIX);
}
if (extension != null && extension.length > 0) {
editInLine = true;
handleLibraries(builder, extension, profile, "extension lib", EXT_PREFIX);
}
if (bundles != null && bundles.length > 0) {
editInLine = true;
handleBundles(builder, bundles, profile);
}
if (fabs != null && fabs.length > 0) {
editInLine = true;
handleFabs(builder, fabs, profile);
}
if (overrides != null && overrides.length > 0) {
editInLine = true;
handleOverrides(builder, overrides, profile);
}
if (pidProperties != null && pidProperties.length > 0) {
editInLine = handlePid(builder, pidProperties, profile);
}
if (systemProperties != null && systemProperties.length > 0) {
editInLine = true;
handleSystemProperties(builder, systemProperties, profile);
}
if (configProperties != null && configProperties.length > 0) {
editInLine = true;
handleConfigProperties(builder, configProperties, profile);
}
if (resource != null && delete) {
editInLine = true;
builder.deleteFileConfiguration(resource);
}
profileService.updateProfile(builder.getProfile());
if (!editInLine) {
resource = resource != null ? resource : "io.fabric8.agent.properties";
// then open the resource in the editor.
if (pidProperties != null && pidProperties.length == 1) {
resource = pidProperties[0] + ".properties";
}
openInEditor(profile, resource);
}
}
use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getEnvironment.
@Override
public String getEnvironment() {
assertValid();
String answer = runtimeProperties.get().getProperty(SystemProperties.FABRIC_ENVIRONMENT);
if (answer == null) {
// in case we've not updated the system properties in the JVM based on the profile
// e.g. when adding/removing profiles
Container currentContainer = getCurrentContainer();
if (currentContainer != null) {
Map<String, String> systemProperties = currentContainer.getOverlayProfile().getConfiguration(Constants.SYSTEM_PROPERTIES_PID);
answer = systemProperties.get(SystemProperties.FABRIC_ENVIRONMENT);
}
// lets store the effective profile for later on
if (answer != null) {
System.setProperty(SystemProperties.FABRIC_PROFILE_ENVIRONMENT, answer);
}
}
return answer;
}
use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.
the class FabricManager method setProfileSystemProperties.
@Override
public void setProfileSystemProperties(String versionId, String profileId, Map<String, String> systemProperties) {
Version version = profileService.getVersion(versionId);
Profile profile = version.getRequiredProfile(profileId);
ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
Map<String, String> profileProperties = builder.getConfiguration(Constants.AGENT_PID);
// remove those that are not present in passed systemProperties
for (Iterator<Map.Entry<String, String>> iterator = profileProperties.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry<String, String> entry = iterator.next();
if (entry.getKey().startsWith("system.")) {
String propertyName = entry.getKey().substring("system.".length());
if (!systemProperties.containsKey(propertyName)) {
iterator.remove();
}
}
}
// add changed
for (String k : systemProperties.keySet()) {
profileProperties.put("system." + k, systemProperties.get(k));
}
builder.addConfiguration(Constants.AGENT_PID, profileProperties);
profileService.updateProfile(builder.getProfile());
}
Aggregations