@@ -52,26 +52,62 @@ public void tearDown() {
52
52
53
53
@ Test
54
54
public void testZipPublish () throws IOException , XmlPullParserException {
55
- Project project = ProjectBuilder .builder ().build ();
56
55
String zipPublishTask = "publishPluginZipPublicationToZipStagingRepository" ;
57
- // Apply the opensearch.pluginzip plugin
58
- project .getPluginManager ().apply ("opensearch.pluginzip" );
59
- // Check if the plugin has been applied to the project
60
- assertTrue (project .getPluginManager ().hasPlugin ("opensearch.pluginzip" ));
61
- // Check if the project has the task from class PublishToMavenRepository after plugin apply
62
- assertNotNull (project .getTasks ().withType (PublishToMavenRepository .class ));
63
- // Create a mock bundlePlugin task
64
- Zip task = project .getTasks ().create ("bundlePlugin" , Zip .class );
65
- Publish .configMaven (project );
66
- // Check if the main task publishPluginZipPublicationToZipStagingRepository exists after plugin apply
67
- assertTrue (project .getTasks ().getNames ().contains (zipPublishTask ));
68
- assertNotNull ("Task to generate: " , project .getTasks ().getByName (zipPublishTask ));
69
- // Run Gradle functional tests, but calling a build.gradle file, that resembles the plugin publish behavior
56
+ prepareProjectForPublishTask (zipPublishTask );
57
+
58
+ // Generate the build.gradle file
59
+ String buildFileContent = "apply plugin: 'maven-publish' \n "
60
+ + "apply plugin: 'java' \n "
61
+ + "publishing {\n "
62
+ + " repositories {\n "
63
+ + " maven {\n "
64
+ + " url = 'local-staging-repo/'\n "
65
+ + " name = 'zipStaging'\n "
66
+ + " }\n "
67
+ + " }\n "
68
+ + " publications {\n "
69
+ + " pluginZip(MavenPublication) {\n "
70
+ + " groupId = 'org.opensearch.plugin' \n "
71
+ + " artifactId = 'sample-plugin' \n "
72
+ + " version = '2.0.0.0' \n "
73
+ + " artifact('sample-plugin.zip') \n "
74
+ + " }\n "
75
+ + " }\n "
76
+ + "}" ;
77
+ writeString (projectDir .newFile ("build.gradle" ), buildFileContent );
78
+ // Execute the task publishPluginZipPublicationToZipStagingRepository
79
+ List <String > allArguments = new ArrayList <String >();
80
+ allArguments .add ("build" );
81
+ allArguments .add (zipPublishTask );
82
+ GradleRunner runner = GradleRunner .create ();
83
+ runner .forwardOutput ();
84
+ runner .withPluginClasspath ();
85
+ runner .withArguments (allArguments );
86
+ runner .withProjectDir (projectDir .getRoot ());
87
+ BuildResult result = runner .build ();
88
+ // Check if task publishMavenzipPublicationToZipstagingRepository has ran well
89
+ assertEquals (SUCCESS , result .task (":" + zipPublishTask ).getOutcome ());
90
+ // check if the zip has been published to local staging repo
91
+ assertTrue (
92
+ new File (projectDir .getRoot (), "local-staging-repo/org/opensearch/plugin/sample-plugin/2.0.0.0/sample-plugin-2.0.0.0.zip" )
93
+ .exists ()
94
+ );
95
+ assertEquals (SUCCESS , result .task (":" + "build" ).getOutcome ());
96
+ // Parse the maven file and validate the groupID to org.opensearch.plugin
97
+ MavenXpp3Reader reader = new MavenXpp3Reader ();
98
+ Model model = reader .read (
99
+ new FileReader (
100
+ new File (projectDir .getRoot (), "local-staging-repo/org/opensearch/plugin/sample-plugin/2.0.0.0/sample-plugin-2.0.0.0.pom" )
101
+ )
102
+ );
103
+ assertEquals (model .getGroupId (), "org.opensearch.plugin" );
104
+ }
105
+
106
+ @ Test
107
+ public void testZipPublishWithPom () throws IOException , XmlPullParserException {
108
+ String zipPublishTask = "publishPluginZipPublicationToZipStagingRepository" ;
109
+ Project project = prepareProjectForPublishTask (zipPublishTask );
70
110
71
- // Create a sample plugin zip file
72
- File sampleZip = new File (projectDir .getRoot (), "sample-plugin.zip" );
73
- Files .createFile (sampleZip .toPath ());
74
- writeString (projectDir .newFile ("settings.gradle" ), "" );
75
111
// Generate the build.gradle file
76
112
String buildFileContent = "apply plugin: 'maven-publish' \n "
77
113
+ "apply plugin: 'java' \n "
@@ -88,6 +124,26 @@ public void testZipPublish() throws IOException, XmlPullParserException {
88
124
+ " artifactId = 'sample-plugin' \n "
89
125
+ " version = '2.0.0.0' \n "
90
126
+ " artifact('sample-plugin.zip') \n "
127
+ + " pom {\n "
128
+ + " name = 'sample-plugin'\n "
129
+ + " description = 'sample-description'\n "
130
+ + " licenses {\n "
131
+ + " license {\n "
132
+ + " name = \" The Apache License, Version 2.0\" \n "
133
+ + " url = \" http://www.apache.org/licenses/LICENSE-2.0.txt\" \n "
134
+ + " }\n "
135
+ + " }\n "
136
+ + " developers {\n "
137
+ + " developer {\n "
138
+ + " name = 'opensearch'\n "
139
+ + " url = 'https://github.com/opensearch-project/OpenSearch'\n "
140
+ + " }\n "
141
+ + " }\n "
142
+ + " url = 'https://github.com/opensearch-project/OpenSearch'\n "
143
+ + " scm {\n "
144
+ + " url = 'https://github.com/opensearch-project/OpenSearch'\n "
145
+ + " }\n "
146
+ + " }"
91
147
+ " }\n "
92
148
+ " }\n "
93
149
+ "}" ;
@@ -118,6 +174,32 @@ public void testZipPublish() throws IOException, XmlPullParserException {
118
174
)
119
175
);
120
176
assertEquals (model .getGroupId (), "org.opensearch.plugin" );
177
+ assertEquals (model .getUrl (), "https://github.com/opensearch-project/OpenSearch" );
178
+ }
179
+
180
+ protected Project prepareProjectForPublishTask (String zipPublishTask ) throws IOException {
181
+ Project project = ProjectBuilder .builder ().build ();
182
+
183
+ // Apply the opensearch.pluginzip plugin
184
+ project .getPluginManager ().apply ("opensearch.pluginzip" );
185
+ // Check if the plugin has been applied to the project
186
+ assertTrue (project .getPluginManager ().hasPlugin ("opensearch.pluginzip" ));
187
+ // Check if the project has the task from class PublishToMavenRepository after plugin apply
188
+ assertNotNull (project .getTasks ().withType (PublishToMavenRepository .class ));
189
+ // Create a mock bundlePlugin task
190
+ Zip task = project .getTasks ().create ("bundlePlugin" , Zip .class );
191
+ Publish .configMaven (project );
192
+ // Check if the main task publishPluginZipPublicationToZipStagingRepository exists after plugin apply
193
+ assertTrue (project .getTasks ().getNames ().contains (zipPublishTask ));
194
+ assertNotNull ("Task to generate: " , project .getTasks ().getByName (zipPublishTask ));
195
+ // Run Gradle functional tests, but calling a build.gradle file, that resembles the plugin publish behavior
196
+
197
+ // Create a sample plugin zip file
198
+ File sampleZip = new File (projectDir .getRoot (), "sample-plugin.zip" );
199
+ Files .createFile (sampleZip .toPath ());
200
+ writeString (projectDir .newFile ("settings.gradle" ), "" );
201
+
202
+ return project ;
121
203
}
122
204
123
205
private void writeString (File file , String string ) throws IOException {
0 commit comments