/*
 * #%L
 * it-xcode-maven-plugin
 * %%
 * Copyright (C) 2012 SAP AG
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package com.sap.prd.mobile.ios.mios;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import junit.framework.Assert;

import org.apache.commons.io.IOUtils;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.Test;

public class DependencyToZipToBundleTest extends XCodeTest
{

  @Test
  public void testPrepare() throws Exception
  {

    final String testName = getTestName();

    final File testSourceDirApp = new File(getTestRootDirectory(), "straight-forward/MyApp");
    final File alternateTestSourceDirApp = new File(getTestRootDirectory(), "straight-forward-transitive-bundles");

    final File remoteRepositoryDirectory = getRemoteRepositoryDirectory(getClass().getName());

    prepareRemoteRepository(remoteRepositoryDirectory);

    final File zipRepository = new File(new File(".").getCanonicalFile(), "src/test/zipRepository");

    Properties pomReplacements = new Properties();
    pomReplacements.setProperty(PROP_NAME_DEPLOY_REPO_DIR, remoteRepositoryDirectory.getAbsolutePath());
    pomReplacements.setProperty(PROP_NAME_DYNAMIC_VERSION, "1.0." + String.valueOf(System.currentTimeMillis()));
    pomReplacements.setProperty(PROP_NAME_ZIP_REPO_DIR, zipRepository.getAbsolutePath());

    final ProjectModifier projectModifier = new ChainProjectModifier(new FileCopyProjectModifier(
          alternateTestSourceDirApp, "pom.xml"), new ProjectModifier() {

      @Override
      public void execute() throws Exception
      {
        final File pom = new File(testExecutionDirectory, "pom.xml");
        FileInputStream fis = null;
        FileOutputStream fos = null;

        try {
          fis = new FileInputStream(pom);
          final Model model = new MavenXpp3Reader().read(fis);
          fis.close();
          fos = new FileOutputStream(pom);
          Plugin plugin = model.getBuild().getPlugins().get(0);
          ((Xpp3Dom) plugin.getConfiguration()).getChild("additionalPackagingTypes").getChild("html5")
            .setValue("BUNDLE");
          new MavenXpp3Writer().write(fos, model);
        }
        finally {
          IOUtils.closeQuietly(fis);
          IOUtils.closeQuietly(fos);
        }
      }
    });

    test(testName, testSourceDirApp,
          "com.sap.prd.mobile.ios.mios:xcode-maven-plugin:" + getMavenXcodePluginVersion() + ":prepare-xcode-build",
          THE_EMPTY_LIST,
          null, pomReplacements, projectModifier);

    File tmp = new File(getTestExecutionDirectory(testName, "MyApp"), "target/xcode-deps/html5/"
          + Constants.GROUP_ID + "/MyZip/MyZip.bundle/dummy.txt");

    Assert.assertTrue("File '" + tmp + "' not found", tmp.exists());
  }
}

@@ -754,32 +754,89 @@
 leOutputStream;%0A
+import java.io.IOException;%0Aimport java.io.OutputStream;%0A
 import java.util
@@ -1149,16 +1149,81 @@
 pp3Dom;%0A
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;%0A
 import o
@@ -2379,16 +2379,24 @@
 %22), new 
+Abstract
 ProjectM
@@ -2551,260 +2551,47 @@
 %22);%0A
-        FileInputStream fis = null;%0A        FileOutputStream fos = null;%0A%0A        try %7B%0A          fis = new FileInputStream(pom);%0A          final Model model = new MavenXpp3Reader().read(fis);%0A          fis.close();%0A          fos = new FileOutputStream
+%0A          final Model model = getModel
 (pom
@@ -2807,160 +2807,33 @@
     
-new MavenXpp3Writer().write(fos, model);%0A        %7D%0A        finally %7B%0A          IOUtils.closeQuietly(fis);%0A          IOUtils.closeQuietly(fos);%0A        %7D
+persistModel(pom, model);
 %0A   

Use getModel/persistModel