1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.sap.prd.mobile.ios.mios;
21
22 import java.io.File;
23 import java.io.FileFilter;
24 import java.io.IOException;
25 import java.util.Arrays;
26 import java.util.HashSet;
27 import java.util.Properties;
28 import java.util.Set;
29
30 import org.apache.commons.io.FileUtils;
31
32 public class XCodeTest
33 {
34 protected void ensureCleanProjectDirectoryAndFilterPom(final File projectDirectory) throws Exception
35 {
36 File source = new File(new File(".").getAbsoluteFile(), "src/test/projects");
37
38 MacFileUtil.deleteDirectory(projectDirectory);
39 FileUtils.copyDirectory(source, projectDirectory);
40 filterPoms(projectDirectory);
41 }
42
43 private static void filterPoms(File projectDirectory) throws IOException
44 {
45 Set<File> pomFiles = new HashSet<File>();
46 getPomFiles(projectDirectory, pomFiles);
47
48 for (File pomFile : pomFiles) {
49 String pom = FileUtils.readFileToString(pomFile);
50 pom = pom.replaceAll("\\$\\{xcode.maven.plugin.version\\}", getMavenXcodePluginVersion());
51 FileUtils.writeStringToFile(pomFile, pom, "UTF-8");
52 }
53 }
54
55 private static void getPomFiles(File root, final Set<File> pomFiles)
56 {
57 if (root.isFile())
58 return;
59
60 pomFiles.addAll(Arrays.asList(root.listFiles(new FileFilter() {
61
62 @Override
63 public boolean accept(File f)
64 {
65
66
67
68 return f.isFile() && f.getName().equals("pom.xml");
69 }
70
71 })));
72
73 for (File f : Arrays.asList(root.listFiles(new FileFilter() {
74
75 @Override
76 public boolean accept(File f)
77 {
78 return f.isDirectory();
79 }
80 })))
81 getPomFiles(f, pomFiles);
82 }
83
84 private static String getMavenXcodePluginVersion() throws IOException
85 {
86 Properties properties = new Properties();
87 properties.load(XCodeManagerTest.class.getResourceAsStream("/misc/project.properties"));
88 final String xcodePluginVersion = properties.getProperty("xcode-plugin-version");
89
90 if (xcodePluginVersion.equals("${project.version}"))
91 throw new IllegalStateException(
92 "Variable ${project.version} was not replaced. May be running \"mvn clean install\" beforehand might solve this issue.");
93 return xcodePluginVersion;
94 }
95
96 }