Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Append feature for p2AsMaven #44

Merged
merged 4 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/main/java/com/diffplug/gradle/p2/AsMavenGroupImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public void run() throws Exception {
project.getLogger().lifecycle("p2AsMaven " + def.group + " is dirty.");
}
// else, we'll need to run our own little thing
FileMisc.cleanDir(dirP2());
FileMisc.cleanDir(dirP2Runnable());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be guarded on append? Otherwise this looks great and ready to merge to me!

FileMisc.cleanDir(dirMavenGroup());

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/diffplug/gradle/p2/P2Declarative.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ default void slicingOption(String option, String value) {
getP2().addSlicingOption(option, value);
}

default void append(boolean append) {
getP2().setAppend(append);
}

public static void populate(P2Model model, Action<P2Declarative> action) {
action.execute(new P2Declarative() {
@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/diffplug/gradle/p2/P2Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public void copyFrom(P2Model other) {
metadataRepos.addAll(other.metadataRepos);
artifactRepos.addAll(other.artifactRepos);
slicingOptions.putAll(other.slicingOptions);
append = other.append;
}

private boolean append = false;
private Set<String> ius = new LinkedHashSet<>();
private Set<String> repos = new LinkedHashSet<>();
private Set<String> metadataRepos = new LinkedHashSet<>();
Expand Down Expand Up @@ -105,6 +107,7 @@ public String toString() {
add.accept("metadataRepo", metadataRepos);
add.accept("artifactRepo", artifactRepos);
add.accept("ius", ius);
printer.print("append: " + append);
});
}

Expand Down Expand Up @@ -166,6 +169,10 @@ public void addSlicingOption(String option, String value) {
slicingOptions.put(option, value);
}

public void setAppend(boolean append) {
this.append = append;
}

/**
* There are places where we add the local bundle pool
* to act as an artifact cache. But sometimes, that cache
Expand Down Expand Up @@ -246,6 +253,7 @@ public P2AntRunner mirrorApp(File dstFolder) {
sourceNode(taskNode);
Node destination = new Node(taskNode, "destination");
destination.attributes().put("location", FileMisc.asUrl(dstFolder));
destination.attributes().put("append", append);

for (String iu : ius) {
Node iuNode = new Node(taskNode, "iu");
Expand Down
55 changes: 53 additions & 2 deletions src/test/java/com/diffplug/gradle/p2/P2ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testMirrorAntFile() {
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
" </source>",
" <destination location=\"" + FileMisc.asUrl(dest) + "\"/>",
" <repository location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
" <iu id=\"com.diffplug.iu\"/>",
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
" </p2.mirror>",
Expand Down Expand Up @@ -95,12 +95,63 @@ public void testMirrorAntFileWithSlicingOptions() {
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
" </source>",
" <destination location=\"" + FileMisc.asUrl(dest) + "\"/>",
" <repository location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
" <iu id=\"com.diffplug.iu\"/>",
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
" <slicingOptions filter=\"key=value\" latestVersionOnly=\"true\" platformfilter=\"win32,win32,x86\"/>",
" </p2.mirror>",
"</project>");
Assert.assertEquals(expected, actual);
}

@Test
public void testMirrorAntFileWithAppend() {
File dest = new File("dest");
P2Model p2 = testData();
p2.setAppend(true);
String actual = p2.mirrorApp(dest).completeState();
String expected = StringPrinter.buildStringFromLines(
"### ARGS ###",
"-application org.eclipse.ant.core.antRunner",
"",
"### BUILD.XML ###",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>",
" <p2.mirror>",
" <source>",
" <repository location=\"http://p2repo\"/>",
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
" </source>",
" <repository location=\"" + FileMisc.asUrl(dest) + "\" append=\"true\"/>",
" <iu id=\"com.diffplug.iu\"/>",
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
" </p2.mirror>",
"</project>");
Assert.assertEquals(expected, actual);
}

@Test
public void testMirrorAntFileWithAppendDefault() {
File dest = new File("dest");
P2Model p2 = testData();
String actual = p2.mirrorApp(dest).completeState();
String expected = StringPrinter.buildStringFromLines(
"### ARGS ###",
"-application org.eclipse.ant.core.antRunner",
"",
"### BUILD.XML ###",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><project>",
" <p2.mirror>",
" <source>",
" <repository location=\"http://p2repo\"/>",
" <repository kind=\"metadata\" location=\"http://metadatarepo\"/>",
" <repository kind=\"artifact\" location=\"http://artifactrepo\"/>",
" </source>",
" <repository location=\"" + FileMisc.asUrl(dest) + "\" append=\"false\"/>",
" <iu id=\"com.diffplug.iu\"/>",
" <iu id=\"com.diffplug.otheriu\" version=\"1.0.0\"/>",
" </p2.mirror>",
"</project>");
Assert.assertEquals(expected, actual);
}
}