/**
  * Perform {@link com.android.manifmerger.ManifestMerger2.SystemProperty} injection.
  *
  * @param mergingReport to log actions and errors.
  * @param xmlDocument the xml document to inject into.
  */
 protected void performSystemPropertiesInjection(
     MergingReport.Builder mergingReport, XmlDocument xmlDocument) {
   for (SystemProperty systemProperty : SystemProperty.values()) {
     String propertyOverride = mSystemPropertyResolver.getValue(systemProperty);
     if (propertyOverride != null) {
       systemProperty.addTo(mergingReport.getActionRecorder(), xmlDocument, propertyOverride);
     }
   }
 }
    private LifeCycle.Listener getSystemPropertiesListener(SystemProperty[] systemProperties) {
      Properties props = new Properties();

      if (systemProperties != null) {
        for (SystemProperty prop : systemProperties) {
          props.setProperty(prop.getName(), prop.getValue());
        }
      }

      return new SystemPropertiesLifeCycleListener(props);
    }
    // utility method to add an attribute which name is derived from the enum name().
    private static void addToElement(
        SystemProperty systemProperty, ActionRecorder actionRecorder, String value, XmlElement to) {

      to.getXml().setAttribute(systemProperty.toCamelCase(), value);
      XmlAttribute xmlAttribute =
          new XmlAttribute(to, to.getXml().getAttributeNode(systemProperty.toCamelCase()), null);
      actionRecorder.recordAttributeAction(
          xmlAttribute,
          new Actions.AttributeRecord(
              Actions.ActionType.INJECTED,
              new Actions.ActionLocation(to.getSourceLocation(), PositionImpl.UNKNOWN),
              xmlAttribute.getId(),
              null, /* reason */
              null /* attributeOperationType */));
    }
    // utility method to add an attribute in android namespace which local name is derived from
    // the enum name().
    private static void addToElementInAndroidNS(
        SystemProperty systemProperty, ActionRecorder actionRecorder, String value, XmlElement to) {

      String toolsPrefix = getAndroidPrefix(to.getXml());
      to.getXml()
          .setAttributeNS(
              SdkConstants.ANDROID_URI,
              toolsPrefix + XmlUtils.NS_SEPARATOR + systemProperty.toCamelCase(),
              value);
      Attr attr =
          to.getXml().getAttributeNodeNS(SdkConstants.ANDROID_URI, systemProperty.toCamelCase());

      XmlAttribute xmlAttribute = new XmlAttribute(to, attr, null);
      actionRecorder.recordAttributeAction(
          xmlAttribute,
          new Actions.AttributeRecord(
              Actions.ActionType.INJECTED,
              new Actions.ActionLocation(to.getSourceLocation(), PositionImpl.UNKNOWN),
              xmlAttribute.getId(),
              null, /* reason */
              null /* attributeOperationType */));
    }
Example #5
0
  public Config copyConfig(Configs configs, Config config, String destConfigName, Logger logger)
      throws PropertyVetoException, TransactionFailure {
    final Config destCopy = (Config) config.deepCopy(configs);
    if (systemproperties != null) {
      final Properties properties =
          GenericCrudCommand.convertStringToProperties(systemproperties, ':');

      for (final Object key : properties.keySet()) {
        final String propName = (String) key;
        // cannot update a system property so remove it first
        List<SystemProperty> sysprops = destCopy.getSystemProperty();
        for (SystemProperty sysprop : sysprops) {
          if (propName.equals(sysprop.getName())) {
            sysprops.remove(sysprop);
            break;
          }
        }
        SystemProperty newSysProp = destCopy.createChild(SystemProperty.class);
        newSysProp.setName(propName);
        newSysProp.setValue(properties.getProperty(propName));
        destCopy.getSystemProperty().add(newSysProp);
      }
    }
    final String configName = destConfigName;
    destCopy.setName(configName);
    configs.getConfig().add(destCopy);
    copyOfConfig = destCopy;

    String srcConfig = "";
    srcConfig = config.getName();

    File configConfigDir = new File(env.getConfigDirPath(), configName);
    for (Config c : configs.getConfig()) {
      File existingConfigConfigDir = new File(env.getConfigDirPath(), c.getName());
      if (!c.getName().equals(configName) && configConfigDir.equals(existingConfigConfigDir)) {
        throw new TransactionFailure(
            localStrings.getLocalString(
                "config.duplicate.dir",
                "Config {0} is trying to use the same directory as config {1}",
                configName,
                c.getName()));
      }
    }
    try {
      if (!(new File(configConfigDir, "docroot").mkdirs()
          && new File(configConfigDir, "lib/ext").mkdirs())) {
        throw new IOException(
            localStrings.getLocalString(
                "config.mkdirs", "error creating config specific directories"));
      }

      String srcConfigLoggingFile =
          env.getInstanceRoot().getAbsolutePath()
              + File.separator
              + "config"
              + File.separator
              + srcConfig
              + File.separator
              + ServerEnvironmentImpl.kLoggingPropertiesFileName;
      File src = new File(srcConfigLoggingFile);

      if (!src.exists()) {
        src = new File(env.getConfigDirPath(), ServerEnvironmentImpl.kLoggingPropertiesFileName);
      }

      File dest = new File(configConfigDir, ServerEnvironmentImpl.kLoggingPropertiesFileName);
      FileUtils.copy(src, dest);
    } catch (Exception e) {
      logger.log(Level.WARNING, ConfigApiLoggerInfo.copyConfigError, e.getLocalizedMessage());
    }
    return destCopy;
  }