Skip to content

Commit c8325a8

Browse files
lipplingAlexander Lippling
authored andcommitted
Update README and UsageExamples
Change-Id: Ic93dae077e933f5ca567bdc49ac053a60660f98a
1 parent c565546 commit c8325a8

2 files changed

Lines changed: 18 additions & 89 deletions

File tree

README.md

Lines changed: 4 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,96 +2,15 @@
22

33
##Description
44

5-
These classes implement a basic API for the Xcode project file (works also with Xcode 4.3).
5+
These classes implement a basic API for the Xcode project file (works also with Xcode 4.3.x).
66

77
Note: *The low level classes in the ```com.sap.prd.mobile.ios.mios.xcodeprojreader.jaxb``` package can be used to load and save arbitrary property lists.*
88

99
##Usage
10-
11-
###Create a property list parser
12-
13-
``` java
14-
JAXBPlistParser parser = new JAXBPlistParser();
15-
// Xcode project file has to be converted to XML
16-
parser.convert("path/to/project.pbxproj", "path/to/project.pbxproj/or/other/destination");
17-
Plist plist = parser.load(JAXBPlistParserTest.fileName);
18-
```
19-
20-
###Get/Set values
21-
22-
```java
23-
ProjectFile projectFile = new ProjectFile(plist);
24-
assertEquals("46", projectFile.getObjectVersion());
25-
26-
Project project = projectFile.getProject();
27-
28-
Target target = project.getTargets().get(0);
29-
assertEquals("MyTest", target.getName());
30-
31-
target = project.getTargets().getByName("MyTest");
32-
assertEquals("MyTest", target.getName());
33-
34-
BuildConfiguration config =
35-
project.getBuildConfigurationList().getBuildConfigurations().get(0);
36-
assertEquals("Debug",
37-
config.getName());
38-
39-
config = project.getBuildConfigurationList().getBuildConfigurations().getByName("Release");
40-
assertEquals("Release", config.getName());
41-
42-
BuildSettings buildSettings = config.getBuildSettings();
43-
assertEquals("5.1",
44-
buildSettings.getString("IPHONEOS_DEPLOYMENT_TARGET"));
45-
buildSettings.setString("IPHONEOS_DEPLOYMENT_TARGET", "4.0");
46-
assertEquals("4.0",
47-
buildSettings.getString("IPHONEOS_DEPLOYMENT_TARGET"));
48-
49-
assertEquals("YES",
50-
buildSettings.getString("VALIDATE_PRODUCT"));
51-
```
52-
53-
### Example: Add custom build phase
54-
####Low Level (not recommended)
55-
56-
```java
57-
Array buildPhaseRefs = project.getTargets().get(0).getArray("buildPhases");
58-
String ref = projectFile.generateReference();
59-
Dict phase = projectFile.createDict();
60-
phase.put("isa", "PBXShellScriptBuildPhase");
61-
phase.put("files", projectFile.createArray());
62-
phase.put("inputPaths", projectFile.createArray());
63-
phase.put("outputPaths", projectFile.createArray());
64-
phase.put("runOnlyForDeploymentPostprocessing", "0");
65-
phase.put("shellPath", "/bin/sh");
66-
phase.put("shellScript", "env > test.txt");
67-
projectFile.setObjectByReference(ref, phase);
68-
buildPhaseRefs.add(ref);
69-
parser.save(plist, "path/to/project.pbxproj");
70-
```
71-
72-
####High Level
73-
74-
```java
75-
ReferenceArray<BuildPhase> buildPhases = project.getTargets().get(0).getBuildPhases();
76-
ShellScriptBuildPhase phase2 = new ShellScriptBuildPhase(projectFile);
77-
phase2.setDefaultValues();
78-
phase2.setShellScript("env > test.txt");
79-
buildPhases.add(phase2);
80-
parser.save(plist, "path/to/project.pbxproj");
81-
```
82-
83-
Note: *Collections are created on the fly.*
84-
85-
``` java
86-
project.getTargets().get(0).getBuildPhases().size()
87-
```
88-
*would create a collection of targets and a collection of build phases if they don't exist. This is important to know, if you intend to save the property list later. If you don't want this behavior, you have to use the low level APIs.*
10+
See [UsageExamples.java](https://github.com/sap-production/XcodeProjectJavaAPI/blob/master/src/test/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/UsageExamples.java).
8911

9012
##Known limitations
9113

92-
The following elements are not parsed, yet:
14+
In order to use this library, you have to convert the Xcode project file to XML (see ```convert``` method in [JAXBPlistParser.java](https://github.com/sap-production/XcodeProjectJavaAPI/blob/master/src/main/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/jaxb/JAXBPlistParser.java). This step can only be done on MAC OS X. The project file cannot be converted back!
9315

94-
- Date
95-
- Data
96-
- Integer
97-
- Real
16+
The remainder of the API uses standard Java features.

src/test/java/com/sap/prd/mobile/ios/mios/xcodeprojreader/UsageExamples.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void usage() throws Exception
3535
{
3636
JAXBPlistParser parser = new JAXBPlistParser();
3737

38-
// optional step, if project file is not already in XML format
38+
// Optional step, if project file is not already in XML format.
3939
// parser.convert(JAXBPlistParserTest.fileName, JAXBPlistParserTest.fileName)
4040
Plist plist = parser.load(JAXBPlistParserTest.fileName);
4141

@@ -64,7 +64,7 @@ public void usage() throws Exception
6464
assertEquals("YES",
6565
buildSettings.getDict().getString("VALIDATE_PRODUCT"));
6666

67-
// LOW LEVEL (not recommended)
67+
// LOW LEVEL (not recommended)
6868
Array buildPhaseRefs = project.getTargets().get(0).getDict().getArray("buildPhases");
6969
String ref = projectFile.generateReference();
7070
buildPhaseRefs.add(ref);
@@ -78,13 +78,23 @@ public void usage() throws Exception
7878
phase.put("shellScript", "env > test.txt");
7979
projectFile.setObjectByReference(ref, phase);
8080

81-
// HIGH LEVEL
81+
// HIGH LEVEL
8282
ReferenceArray<BuildPhase> buildPhases = project.getTargets().get(0).getBuildPhases();
8383
PBXShellScriptBuildPhase phase2 = new PBXShellScriptBuildPhase(projectFile);
8484
phase2.setDefaultValues();
8585
phase2.setShellScript("env > test.txt");
8686
buildPhases.add(phase2);
8787

88-
//parser.save(plist, JAXBPlistParserTest.fileName);
88+
/*
89+
* Note: Collections are created on the fly.
90+
*
91+
* project.getTargets().get(0).getBuildPhases().size() would create a collection of targets and
92+
* a collection of build phases if they don't exist. This is important to know, if you intend to
93+
* save the property list later. If you don't want this behavior, you have to use the low level
94+
* APIs.
95+
*/
96+
97+
// Save back to disk
98+
// parser.save(plist, JAXBPlistParserTest.fileName);
8999
}
90100
}

0 commit comments

Comments
 (0)