Skip to content

Commit 884d2d8

Browse files
committed
Adding javascript way of building plugin
1 parent cd1c082 commit 884d2d8

File tree

3 files changed

+486
-20
lines changed

3 files changed

+486
-20
lines changed

pom.xml

Lines changed: 89 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<!-- this is here because project.basedir evaluates to null in the script build step -->
1818
<main.basedir>${project.basedir}</main.basedir>
1919
<cdap.version>4.3.1</cdap.version>
20-
<wrangler.version>3.0.0</wrangler.version>
20+
<wrangler.version>3.0.1</wrangler.version>
2121
<commons.codec.version>1.10</commons.codec.version>
2222
<junit.version>4.12</junit.version>
2323
</properties>
@@ -139,25 +139,94 @@
139139
<groupId>org.apache.maven.plugins</groupId>
140140
<artifactId>maven-antrun-plugin</artifactId>
141141
</plugin>
142-
<plugin>
143-
<groupId>co.cask</groupId>
144-
<artifactId>cdap-maven-plugin</artifactId>
145-
<version>1.0.0-SNAPSHOT</version>
146-
<configuration>
147-
<cdapArtifacts>
148-
<parent>system:wrangler-transform[1.0.0-SNAPSHOT, 10.0.0-SNAPSHOT]</parent>
149-
</cdapArtifacts>
150-
</configuration>
151-
<executions>
152-
<execution>
153-
<id>create-artifact-config</id>
154-
<phase>prepare-package</phase>
155-
<goals>
156-
<goal>create-plugin-json</goal>
157-
</goals>
158-
</execution>
159-
</executions>
160-
</plugin>
142+
<plugin>
143+
<groupId>org.apache.maven.plugins</groupId>
144+
<artifactId>maven-antrun-plugin</artifactId>
145+
<version>1.7</version>
146+
<executions>
147+
<!-- Create the config file for artifact which can be used to deploy the artifact.
148+
Sets the parents field to system:cdap-etl-batch and system:cdap-etl-realtime with whatever
149+
version range is set in the etl.versionRange property.
150+
also sets a widget and doc property for each file contained in the widgets and docs directories. -->
151+
<execution>
152+
<id>create-artifact-config</id>
153+
<phase>prepare-package</phase>
154+
<configuration>
155+
<target>
156+
<script language="javascript"> <![CDATA[
157+
158+
// for some reason, project.basedir evaluates to null if we just get the property here.
159+
// so we set main.basedir to project.basedir in the pom properties, then main.basedir is used here
160+
// where it evaluates correctly for whatever reason
161+
var baseDir = project.getProperty("main.basedir");
162+
var targetDir = project.getProperty("project.build.directory");
163+
var artifactId = project.getProperty("project.artifactId");
164+
var version = project.getProperty("project.version");
165+
166+
var cfgFile = new java.io.File(targetDir, artifactId + "-" + version + ".json");
167+
if (!cfgFile.exists()) {
168+
cfgFile.createNewFile();
169+
}
170+
171+
var etlRange = project.getProperty("etl.versionRange");
172+
var config = {
173+
"parents": [
174+
"system:wrangler-transform[1.0.0-SNAPSHOT, 10.0.0-SNAPSHOT]"
175+
],
176+
"properties": {}
177+
}
178+
179+
// look in widgets directory for widget config for each plugin
180+
var widgetsDir = new java.io.File(baseDir, "widgets");
181+
if (widgetsDir.isDirectory()) {
182+
var widgetsFiles = widgetsDir.listFiles();
183+
for (i = 0; i < widgetsFiles.length; i++) {
184+
var widgetsFile = widgetsFiles[i];
185+
if (widgetsFile.isFile()) {
186+
var propertyName = "widgets." + widgetsFile.getName();
187+
// if the filename ends with .json
188+
if (propertyName.indexOf(".json", propertyName.length - 5) !== -1) {
189+
// strip the .json
190+
propertyName = propertyName.slice(0, -5);
191+
var contents = new java.lang.String(java.nio.file.Files.readAllBytes(widgetsFile.toPath()), java.nio.charset.StandardCharsets.UTF_8);
192+
var contentsAsJson = JSON.parse(contents);
193+
config.properties[propertyName] = JSON.stringify(contentsAsJson);
194+
}
195+
}
196+
}
197+
}
198+
199+
// look in the docs directory for docs for each plugin
200+
var docsDir = new java.io.File(baseDir, "docs");
201+
if (docsDir.isDirectory()) {
202+
var docFiles = docsDir.listFiles();
203+
for (i = 0; i < docFiles.length; i++) {
204+
var docFile = docFiles[i];
205+
if (docFile.isFile()) {
206+
var propertyName = "doc." + docFile.getName();
207+
// if the filename ends with .md
208+
if (propertyName.indexOf(".md", propertyName.length - 3) !== -1) {
209+
// strip the extension
210+
propertyName = propertyName.slice(0, -3);
211+
var contents = new java.lang.String(java.nio.file.Files.readAllBytes(docFile.toPath()), java.nio.charset.StandardCharsets.UTF_8);
212+
config.properties[propertyName] = contents + "";
213+
}
214+
}
215+
}
216+
}
217+
218+
var fw = new java.io.BufferedWriter(new java.io.FileWriter(cfgFile.getAbsoluteFile()));
219+
fw.write(JSON.stringify(config, null, 2));
220+
fw.close();
221+
]]></script>
222+
</target>
223+
</configuration>
224+
<goals>
225+
<goal>run</goal>
226+
</goals>
227+
</execution>
228+
</executions>
229+
</plugin>
161230
</plugins>
162231
</build>
163232

pom.xml.default

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.example</groupId>
8+
<artifactId>simple-udds</artifactId>
9+
<name>Simple User Defined Directives</name>
10+
<version>1.0-SNAPSHOT</version>
11+
<packaging>jar</packaging>
12+
13+
<properties>
14+
<!-- properties for script build step that creates the config files for the artifacts -->
15+
<widgets.dir>widgets</widgets.dir>
16+
<docs.dir>docs</docs.dir>
17+
<!-- this is here because project.basedir evaluates to null in the script build step -->
18+
<main.basedir>${project.basedir}</main.basedir>
19+
<cdap.version>4.3.1</cdap.version>
20+
<wrangler.version>3.0.1</wrangler.version>
21+
<commons.codec.version>1.10</commons.codec.version>
22+
<junit.version>4.12</junit.version>
23+
</properties>
24+
25+
<distributionManagement>
26+
<repository>
27+
<id>sonatype.release</id>
28+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>
29+
</repository>
30+
<snapshotRepository>
31+
<id>sonatype.snapshots</id>
32+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
33+
</snapshotRepository>
34+
</distributionManagement>
35+
36+
<!-- Include the Maven Plugin Repository -->
37+
<pluginRepositories>
38+
<pluginRepository>
39+
<id>sonatype</id>
40+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
41+
</pluginRepository>
42+
</pluginRepositories>
43+
44+
<dependencies>
45+
<!-- Core Dependencies -->
46+
47+
<dependency>
48+
<groupId>co.cask.wrangler</groupId>
49+
<artifactId>wrangler-api</artifactId>
50+
<version>${wrangler.version}</version>
51+
<scope>provided</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>co.cask.cdap</groupId>
55+
<artifactId>cdap-api</artifactId>
56+
<version>${cdap.version}</version>
57+
<scope>provided</scope>
58+
</dependency>
59+
<dependency>
60+
<groupId>co.cask.cdap</groupId>
61+
<artifactId>cdap-etl-api</artifactId>
62+
<version>${cdap.version}</version>
63+
<scope>provided</scope>
64+
</dependency>
65+
66+
<!-- External Dependencies -->
67+
68+
<dependency>
69+
<groupId>commons-codec</groupId>
70+
<artifactId>commons-codec</artifactId>
71+
<version>${commons.codec.version}</version>
72+
</dependency>
73+
74+
<!-- Testing Dependencies -->
75+
<dependency>
76+
<groupId>co.cask.wrangler</groupId>
77+
<artifactId>wrangler-test</artifactId>
78+
<version>${wrangler.version}</version>
79+
<scope>test</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>junit</groupId>
84+
<artifactId>junit</artifactId>
85+
<version>${junit.version}</version>
86+
<scope>test</scope>
87+
</dependency>
88+
</dependencies>
89+
90+
<build>
91+
<pluginManagement>
92+
<plugins>
93+
<plugin>
94+
<groupId>org.apache.maven.plugins</groupId>
95+
<artifactId>maven-compiler-plugin</artifactId>
96+
<version>3.1</version>
97+
<configuration>
98+
<source>1.7</source>
99+
<target>1.7</target>
100+
</configuration>
101+
</plugin>
102+
<plugin>
103+
<groupId>org.apache.felix</groupId>
104+
<artifactId>maven-bundle-plugin</artifactId>
105+
<version>2.3.7</version>
106+
<extensions>true</extensions>
107+
<configuration>
108+
<instructions>
109+
<Embed-Dependency>*;inline=false;scope=compile</Embed-Dependency>
110+
<Embed-Transitive>true</Embed-Transitive>
111+
<Embed-Directory>lib</Embed-Directory>
112+
<!--Only @Plugin classes in the export packages will be included as plugin-->
113+
<_exportcontents>org.example.directives.*</_exportcontents>
114+
</instructions>
115+
</configuration>
116+
<executions>
117+
<execution>
118+
<phase>package</phase>
119+
<goals>
120+
<goal>bundle</goal>
121+
</goals>
122+
</execution>
123+
</executions>
124+
</plugin>
125+
</plugins>
126+
</pluginManagement>
127+
128+
<plugins>
129+
<plugin>
130+
<groupId>org.apache.maven.plugins</groupId>
131+
<artifactId>maven-surefire-plugin</artifactId>
132+
<version>2.14.1</version>
133+
</plugin>
134+
<plugin>
135+
<groupId>org.apache.felix</groupId>
136+
<artifactId>maven-bundle-plugin</artifactId>
137+
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-antrun-plugin</artifactId>
141+
</plugin>
142+
<plugin>
143+
<groupId>co.cask</groupId>
144+
<artifactId>cdap-maven-plugin</artifactId>
145+
<version>1.0.0-SNAPSHOT</version>
146+
<configuration>
147+
<cdapArtifacts>
148+
<parent>system:wrangler-transform[1.0.0-SNAPSHOT, 10.0.0-SNAPSHOT]</parent>
149+
</cdapArtifacts>
150+
</configuration>
151+
<executions>
152+
<execution>
153+
<id>create-artifact-config</id>
154+
<phase>prepare-package</phase>
155+
<goals>
156+
<goal>create-plugin-json</goal>
157+
</goals>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
</plugins>
162+
</build>
163+
164+
</project>

0 commit comments

Comments
 (0)