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

Add support for anttask p2.mirror slicingOptions #41

Merged
merged 3 commits into from
Dec 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -74,6 +74,10 @@ default void feature(String feature, String version) {
getP2().addFeature(feature, version);
}

default void slicingOption(String option, String value) {
getP2().addSlicingOption(option, value);
}

public static void populate(P2Model model, Action<P2Declarative> action) {
action.execute(new P2Declarative() {
@Override
Expand Down
26 changes: 20 additions & 6 deletions src/main/java/com/diffplug/gradle/p2/P2Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
import java.io.File;
import java.io.Serializable;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -67,12 +62,14 @@ public void copyFrom(P2Model other) {
repos.addAll(other.repos);
metadataRepos.addAll(other.metadataRepos);
artifactRepos.addAll(other.artifactRepos);
slicingOptions.putAll(other.slicingOptions);
}

private Set<String> ius = new LinkedHashSet<>();
private Set<String> repos = new LinkedHashSet<>();
private Set<String> metadataRepos = new LinkedHashSet<>();
private Set<String> artifactRepos = new LinkedHashSet<>();
private Map<String, String> slicingOptions = new HashMap<>();

/** Combines all fields for easy implementation of equals and hashCode. */
private final List<Object> content = Arrays.asList(ius, repos, metadataRepos, artifactRepos);
Expand Down Expand Up @@ -165,6 +162,10 @@ public void addArtifactRepoBundlePool() {
addArtifactRepo(GoomphCacheLocations.bundlePool());
}

public void addSlicingOption(String option, String value) {
slicingOptions.put(option, value);
}

/**
* There are places where we add the local bundle pool
* to act as an artifact cache. But sometimes, that cache
Expand Down Expand Up @@ -257,6 +258,10 @@ public P2AntRunner mirrorApp(File dstFolder) {
iuNode.attributes().put("version", iu.substring(slash + 1));
}
}

if (slicingOptions.size() > 0) {
slicingOptionsNode(taskNode);
}
});
});
}
Expand All @@ -278,6 +283,15 @@ private Node sourceNode(Node parent) {
return source;
}

/** Creates an XML node for slicingOptions. */
private Node slicingOptionsNode(Node parent) {
Node slicingOptionsNode = new Node(parent, "slicingOptions");
for (Map.Entry<String, String> option : slicingOptions.entrySet()) {
slicingOptionsNode.attributes().put(option.getKey(), option.getValue());
}
return slicingOptionsNode;
}

////////////////
// P2DIRECTOR //
////////////////
Expand Down
29 changes: 29 additions & 0 deletions src/test/java/com/diffplug/gradle/p2/P2ModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,33 @@ public void testMirrorAntFile() {
"</project>");
Assert.assertEquals(expected, actual);
}

@Test
public void testMirrorAntFileWithSlicingOptions() {
File dest = new File("dest");
P2Model p2 = testData();
p2.addSlicingOption("latestVersionOnly", "true");
p2.addSlicingOption("platformfilter", "win32,win32,x86");
p2.addSlicingOption("filter", "key=value");
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>",
" <destination location=\"" + FileMisc.asUrl(dest) + "\"/>",
" <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);
}
}