Skip to content

Commit 2bb19ca

Browse files
authored
Merge pull request #126 from m273d15/category_publisher
Add CategoryPublisher application
2 parents af7648f + 26e4ddd commit 2bb19ca

File tree

4 files changed

+234
-0
lines changed

4 files changed

+234
-0
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Goomph releases
22

33
## [Unreleased]
4+
### Added
5+
- Added `CategoryPublisher` ([#124](https://github.com/diffplug/goomph/issues/124))
46

57
## [3.23.0] - 2020-06-17
68
### Added

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ Below is an index of Goomph's capabilities, along with links to the javadoc wher
8989
* [`asmaven`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/AsMavenPlugin.html) downloads dependencies from a p2 repository and makes them available in a local maven repository.
9090
* [`P2Model`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/P2Model.html) models a set of p2 repositories and IUs, and provides convenience methods for running p2-director or the p2.mirror ant task against these.
9191
* [`P2AntRunner`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/P2AntRunner.html) runs eclipse ant tasks.
92+
* [`CategoryPublisher`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/CategoryPublisher.html) models the CategoryPublisher eclipse application.
9293
* [`FeaturesAndBundlesPublisher`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/FeaturesAndBundlesPublisher.html) models the FeaturesAndBundlesPublisher eclipse application.
9394
* [`Repo2Runnable`](https://javadoc.io/static/com.diffplug.gradle/goomph/3.23.0/com/diffplug/gradle/p2/Repo2Runnable.html) models the Repo2Runnable eclipse application.
9495

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright (C) 2020 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.p2;
17+
18+
19+
import com.diffplug.gradle.FileMisc;
20+
import com.diffplug.gradle.eclipserunner.EclipseApp;
21+
import com.diffplug.gradle.pde.EclipseRelease;
22+
import com.diffplug.gradle.pde.PdeInstallation;
23+
import java.io.File;
24+
25+
/**
26+
* Models the CategoryPublisher application ([eclipse docs](https://wiki.eclipse.org/Equinox/p2/Publisher#Category_Publisher).
27+
*/
28+
public class CategoryPublisher extends EclipseApp {
29+
30+
private final EclipseRelease eclipseRelease;
31+
32+
/**
33+
* Creates a CategoryPublisher
34+
*
35+
* @param eclipseRelease The eclipse release to be used to run the public application
36+
* */
37+
public CategoryPublisher(EclipseRelease eclipseRelease) {
38+
super("org.eclipse.equinox.p2.publisher.CategoryPublisher");
39+
consolelog();
40+
this.eclipseRelease = eclipseRelease;
41+
}
42+
43+
/** Compress the output index */
44+
public void compress() {
45+
addArg("compress");
46+
}
47+
48+
/** Sets the given location to be the target for metadata. */
49+
public void metadataRepository(File file) {
50+
addArg("metadataRepository", FileMisc.asUrl(file));
51+
}
52+
53+
/** Sets the given location of context metadata. */
54+
public void contextMetadata(File file) {
55+
addArg("contextMetadata", FileMisc.asUrl(file));
56+
}
57+
58+
/** Sets the given location of the category definition. */
59+
public void categoryDefinition(File file) {
60+
addArg("categoryDefinition", FileMisc.asUrl(file));
61+
}
62+
63+
/** Sets the given category qualifier */
64+
public void categoryQualifier(String categoryQualifier) {
65+
addArg("categoryQualifier", categoryQualifier);
66+
}
67+
68+
public void runUsingPdeInstallation() throws Exception {
69+
runUsing(PdeInstallation.from(eclipseRelease));
70+
}
71+
}
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
/*
2+
* Copyright (C) 2020 DiffPlug
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.diffplug.gradle.p2;
17+
18+
19+
import com.diffplug.gradle.GradleIntegrationTest;
20+
import java.io.File;
21+
import java.io.IOException;
22+
import java.util.regex.Matcher;
23+
import java.util.regex.Pattern;
24+
import org.junit.Assert;
25+
import org.junit.Test;
26+
27+
public class CategoryPublisherTest extends GradleIntegrationTest {
28+
29+
// Eclipse version used for application execution
30+
private static String ECLIPSE_PDE_VERSION = "4.8.0";
31+
32+
private static String FEATURE_ID = "goomph.test.feature";
33+
private static String FEATURE_VERSION = "1.1.1";
34+
private static String FEATURE_JAR_NAME = FEATURE_ID + "_" + FEATURE_VERSION + ".jar";
35+
36+
private static String PLUGIN_NAME = "goomph.test.plugin";
37+
private static String PLUGIN_VERSION = "0.2.0";
38+
private static String PLUGIN_JAR_NAME = PLUGIN_NAME + "_" + PLUGIN_VERSION + ".jar";
39+
40+
// Directory used as target of the applications
41+
private static String PROJECT_DIR_PATH = "project";
42+
private static String PLUGINS_DIR_PATH = PROJECT_DIR_PATH + "/plugins";
43+
private static String FEATURES_DIR_PATH = PROJECT_DIR_PATH + "/features";
44+
45+
private static String CATEGORY_FILE_PATH = "category/category.xml";
46+
private static String CATEGORY_NAME = "TestCategory";
47+
48+
private static String PUBLISH_CATEGORY_TASK_NAME = "publishCategory";
49+
private static String PUBLISH_FEATURES_AND_BUNDLES_TASK_NAME = "publishFeaturesAndBundles";
50+
51+
/**
52+
* Tests the update site creation using the {@see FeaturesAndBundlesPublisher}
53+
* and {@see CategoryPublisher}
54+
**/
55+
@Test
56+
public void testCreateUpdateSite() throws IOException {
57+
58+
write(
59+
"build.gradle",
60+
"plugins {",
61+
" id 'com.diffplug.p2.asmaven'",
62+
"}",
63+
"import com.diffplug.gradle.pde.EclipseRelease",
64+
"import com.diffplug.gradle.p2.CategoryPublisher",
65+
"import com.diffplug.gradle.p2.FeaturesAndBundlesPublisher",
66+
"tasks.register('testProjectJar', Jar) {",
67+
" archiveFileName = 'test.jar'",
68+
" destinationDirectory = file('" + PLUGINS_DIR_PATH + "')",
69+
" manifest{attributes('Bundle-SymbolicName': '" + PLUGIN_NAME + "', 'Bundle-Version': '" + PLUGIN_VERSION + "')}",
70+
"}",
71+
"tasks.register('" + PUBLISH_FEATURES_AND_BUNDLES_TASK_NAME + "') {",
72+
" dependsOn('testProjectJar')",
73+
" doLast {",
74+
" new FeaturesAndBundlesPublisher().with {",
75+
" source(file('" + PROJECT_DIR_PATH + "'))",
76+
" inplace()",
77+
" append()",
78+
" publishArtifacts()",
79+
" runUsingBootstrapper()",
80+
" }",
81+
" }",
82+
"}",
83+
"tasks.register('" + PUBLISH_CATEGORY_TASK_NAME + "') {",
84+
" doLast {",
85+
" new CategoryPublisher(EclipseRelease.official('" + ECLIPSE_PDE_VERSION + "')).with {",
86+
" metadataRepository(file('" + PROJECT_DIR_PATH + "'))",
87+
" categoryDefinition(file('" + CATEGORY_FILE_PATH + "'))",
88+
" runUsingPdeInstallation()",
89+
" }",
90+
" }",
91+
"}");
92+
93+
folder.newFolder(PLUGINS_DIR_PATH);
94+
folder.newFolder(FEATURES_DIR_PATH);
95+
96+
writeFeatureXml();
97+
writeCategoryDefinition();
98+
99+
/* Execute FeaturesAndBundlesPublisher using the file structure:
100+
* project
101+
* - features
102+
* - feature.xml
103+
* - plugins
104+
* - test.jar // created by task 'testProjectJar'
105+
*/
106+
gradleRunner().forwardOutput().withArguments(PUBLISH_FEATURES_AND_BUNDLES_TASK_NAME).build();
107+
108+
// Verify result of FeaturesAndBundlesPublisher application execution
109+
String artifactsXml = read(PROJECT_DIR_PATH + "/artifacts.xml");
110+
Assert.assertTrue("FeaturesAndBundles application does not found plugin specified in features.xml",
111+
artifactsXml.contains("id='goomph.test.plugin'"));
112+
Assert.assertTrue("FeaturesAndBundles application does not create a feature jar",
113+
new File(folder.getRoot(), FEATURES_DIR_PATH + '/' + FEATURE_JAR_NAME).exists());
114+
Assert.assertTrue("FeaturesAndBundles application does not create a plugin jar",
115+
new File(folder.getRoot(), PLUGINS_DIR_PATH + '/' + PLUGIN_JAR_NAME).exists());
116+
117+
Pattern categoryContextPattern = Pattern.compile("<property\\s+name='org.eclipse.equinox.p2.name'\\s+value='" + CATEGORY_NAME + "'\\s*/>\\s*" +
118+
"<property\\s+name='org.eclipse.equinox.p2.type.category'\\s+value='true'\\s*/>");
119+
120+
String contentXML = read(PROJECT_DIR_PATH + "/content.xml");
121+
Matcher m = categoryContextPattern.matcher(contentXML);
122+
Assert.assertFalse("content.xml already contains category metadata", m.find());
123+
124+
// Execute CategoryPublisher
125+
gradleRunner().forwardOutput().withArguments(PUBLISH_CATEGORY_TASK_NAME).build();
126+
127+
// Verify result of CategoryPublisher application execution
128+
contentXML = read(PROJECT_DIR_PATH + "/content.xml");
129+
m = categoryContextPattern.matcher(contentXML);
130+
Assert.assertTrue("CategoryPublisher application does not add the category metadata to content.xml", m.find());
131+
}
132+
133+
private void writeFeatureXml() throws IOException {
134+
write(FEATURES_DIR_PATH + "/feature.xml",
135+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
136+
"<feature id=\"" + FEATURE_ID + "\" label=\"test\" version=\"" + FEATURE_VERSION + "\">",
137+
" <description></description>",
138+
" <plugin id=\"" + PLUGIN_NAME + "\"",
139+
" download-size=\"0\"",
140+
" install-size=\"0\"",
141+
" version=\"" + PLUGIN_VERSION + "\"",
142+
" unpack=\"false\"/>",
143+
"</feature>");
144+
}
145+
146+
private void writeCategoryDefinition() throws IOException {
147+
write(CATEGORY_FILE_PATH,
148+
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
149+
"<site>",
150+
" <description url=\"empty url\"></description>",
151+
" <feature url=\"\"",
152+
" id=\"" + FEATURE_ID + "\"",
153+
" version=\"" + FEATURE_VERSION + "\">",
154+
" <category name=\"test\"/>",
155+
" </feature>",
156+
" <category-def name=\"test\"",
157+
" label=\"" + CATEGORY_NAME + "\"/>",
158+
"</site>");
159+
}
160+
}

0 commit comments

Comments
 (0)