Skip to content

Commit 5a9e251

Browse files
authored
Merge pull request #44 from hacki11/ft-append
Append feature for p2AsMaven
2 parents a2dbf4c + 1e0c31a commit 5a9e251

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

src/main/java/com/diffplug/gradle/p2/AsMavenGroupImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public void run() throws Exception {
6868
project.getLogger().lifecycle("p2AsMaven " + def.group + " is dirty.");
6969
}
7070
// else, we'll need to run our own little thing
71-
FileMisc.cleanDir(dirP2());
7271
FileMisc.cleanDir(dirP2Runnable());
7372
FileMisc.cleanDir(dirMavenGroup());
7473

src/main/java/com/diffplug/gradle/p2/AsMavenPlugin.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@
133133
*
134134
* You can see all the available slicing options [here](https://wiki.eclipse.org/Equinox/p2/Ant_Tasks#SlicingOptions).
135135
*
136+
* ## Append option
137+
*
138+
* You can control whether iu's should be appended to destination repository
139+
* true: already downloaded iu's are preserved, new iu's are downloaded into the existing repo
140+
* false: Default value for goomph, repository will be completely cleared before download new iu's
141+
*
142+
* * ```groovy
143+
* p2AsMaven {
144+
* group 'eclipse-deps', {
145+
* ...
146+
* append true
147+
* }
148+
* }
149+
* ```
150+
*
151+
* More info [here]{https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_repositorytasks.htm}.
152+
*
136153
* ## Acknowledgements and comparisons to other options
137154
*
138155
* Inspired by Andrey Hihlovskiy's [unpuzzle](https://github.com/akhikhl/unpuzzle).

src/main/java/com/diffplug/gradle/p2/P2Declarative.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ default void slicingOption(String option, String value) {
7878
getP2().addSlicingOption(option, value);
7979
}
8080

81+
default void append(boolean append) {
82+
getP2().setAppend(append);
83+
}
84+
8185
public static void populate(P2Model model, Action<P2Declarative> action) {
8286
action.execute(new P2Declarative() {
8387
@Override

src/main/java/com/diffplug/gradle/p2/P2Model.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public void copyFrom(P2Model other) {
6363
metadataRepos.addAll(other.metadataRepos);
6464
artifactRepos.addAll(other.artifactRepos);
6565
slicingOptions.putAll(other.slicingOptions);
66+
append = other.append;
6667
}
6768

69+
private boolean append = false;
6870
private Set<String> ius = new LinkedHashSet<>();
6971
private Set<String> repos = new LinkedHashSet<>();
7072
private Set<String> metadataRepos = new LinkedHashSet<>();
@@ -105,6 +107,7 @@ public String toString() {
105107
add.accept("metadataRepo", metadataRepos);
106108
add.accept("artifactRepo", artifactRepos);
107109
add.accept("ius", ius);
110+
printer.print("append: " + append);
108111
});
109112
}
110113

@@ -167,6 +170,11 @@ public void addSlicingOption(String option, String value) {
167170
slicingOptions.put(option, value);
168171
}
169172

173+
/** https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fp2_repositorytasks.htm **/
174+
public void setAppend(boolean append) {
175+
this.append = append;
176+
}
177+
170178
/**
171179
* There are places where we add the local bundle pool
172180
* to act as an artifact cache. But sometimes, that cache
@@ -247,6 +255,7 @@ public P2AntRunner mirrorApp(File dstFolder) {
247255
sourceNode(taskNode);
248256
Node destination = new Node(taskNode, "destination");
249257
destination.attributes().put("location", FileMisc.asUrl(dstFolder));
258+
destination.attributes().put("append", append);
250259

251260
for (String iu : ius) {
252261
Node iuNode = new Node(taskNode, "iu");

src/test/java/com/diffplug/gradle/p2/P2ModelTest.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testMirrorAntFile() {
6767
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
6868
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
6969
" </source>",
70-
" <destination location=\"" + FileMisc.asUrl(dest) + "\"/>",
70+
" <destination location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
7171
" <iu id=\"com.diffplug.iu\"/>",
7272
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
7373
" </p2.mirror>",
@@ -95,12 +95,63 @@ public void testMirrorAntFileWithSlicingOptions() {
9595
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
9696
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
9797
" </source>",
98-
" <destination location=\"" + FileMisc.asUrl(dest) + "\"/>",
98+
" <destination location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
9999
" <iu id=\"com.diffplug.iu\"/>",
100100
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
101101
" <slicingOptions filter=\"key=value\" latestVersionOnly=\"true\" platformfilter=\"win32,win32,x86\"/>",
102102
" </p2.mirror>",
103103
"</project>");
104104
Assert.assertEquals(expected, actual);
105105
}
106+
107+
@Test
108+
public void testMirrorAntFileWithAppend() {
109+
File dest = new File("dest");
110+
P2Model p2 = testData();
111+
p2.setAppend(true);
112+
String actual = p2.mirrorApp(dest).completeState();
113+
String expected = StringPrinter.buildStringFromLines(
114+
"### ARGS ###",
115+
"-application org.eclipse.ant.core.antRunner",
116+
"",
117+
"### BUILD.XML ###",
118+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>",
119+
" <p2.mirror>",
120+
" <source>",
121+
" <repository location=\"http://p2repo\"/>",
122+
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
123+
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
124+
" </source>",
125+
" <destination location=\"" + FileMisc.asUrl(dest) + "\" append=\"true\"/>",
126+
" <iu id=\"com.diffplug.iu\"/>",
127+
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
128+
" </p2.mirror>",
129+
"</project>");
130+
Assert.assertEquals(expected, actual);
131+
}
132+
133+
@Test
134+
public void testMirrorAntFileWithAppendDefault() {
135+
File dest = new File("dest");
136+
P2Model p2 = testData();
137+
String actual = p2.mirrorApp(dest).completeState();
138+
String expected = StringPrinter.buildStringFromLines(
139+
"### ARGS ###",
140+
"-application org.eclipse.ant.core.antRunner",
141+
"",
142+
"### BUILD.XML ###",
143+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>",
144+
" <p2.mirror>",
145+
" <source>",
146+
" <repository location=\"http://p2repo\"/>",
147+
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
148+
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
149+
" </source>",
150+
" <destination location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
151+
" <iu id=\"com.diffplug.iu\"/>",
152+
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
153+
" </p2.mirror>",
154+
"</project>");
155+
Assert.assertEquals(expected, actual);
156+
}
106157
}

0 commit comments

Comments
 (0)