Skip to content

Commit 1811356

Browse files
committed
Changing the POM to use plugin for building
1 parent 24aa87a commit 1811356

File tree

3 files changed

+105
-252
lines changed

3 files changed

+105
-252
lines changed

pom.xml

Lines changed: 19 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -139,94 +139,25 @@
139139
<groupId>org.apache.maven.plugins</groupId>
140140
<artifactId>maven-antrun-plugin</artifactId>
141141
</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>
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[3.0.0,10.0.0)</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>
230161
</plugins>
231162
</build>
232163

pom.xml.default

Lines changed: 0 additions & 164 deletions
This file was deleted.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright © 2017 Cask Data, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://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, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package org.example.directives;
18+
19+
import co.cask.cdap.api.annotation.Description;
20+
import co.cask.cdap.api.annotation.Name;
21+
import co.cask.cdap.api.annotation.Plugin;
22+
import co.cask.cdap.api.common.Bytes;
23+
import co.cask.wrangler.api.Arguments;
24+
import co.cask.wrangler.api.Directive;
25+
import co.cask.wrangler.api.DirectiveExecutionException;
26+
import co.cask.wrangler.api.DirectiveParseException;
27+
import co.cask.wrangler.api.ErrorRowException;
28+
import co.cask.wrangler.api.ExecutorContext;
29+
import co.cask.wrangler.api.Row;
30+
import co.cask.wrangler.api.parser.ColumnName;
31+
import co.cask.wrangler.api.parser.TokenType;
32+
import co.cask.wrangler.api.parser.UsageDefinition;
33+
34+
import java.util.List;
35+
36+
/**
37+
* This class <code>TextReverse</code>implements a <code>Directive</code> interface
38+
* for reversing the text specified by the value of the <code>column</code>.
39+
*/
40+
@Plugin(type = Directive.Type)
41+
@Name(TextLength.DIRECTIVE_NAME)
42+
@Description("Computes tthe length of the string.")
43+
public final class TextLength implements Directive {
44+
public static final String DIRECTIVE_NAME = "text-length";
45+
private String column;
46+
47+
@Override
48+
public UsageDefinition define() {
49+
// Usage : text-reverse :column;
50+
UsageDefinition.Builder builder = UsageDefinition.builder(DIRECTIVE_NAME);
51+
builder.define("column", TokenType.COLUMN_NAME);
52+
return builder.build();
53+
}
54+
55+
@Override
56+
public void initialize(Arguments args)
57+
throws DirectiveParseException {
58+
column = ((ColumnName) args.value("column")).value();
59+
}
60+
61+
@Override
62+
public List<Row> execute(List<Row> rows, ExecutorContext context)
63+
throws DirectiveExecutionException, ErrorRowException {
64+
for (Row row : rows) {
65+
int idx = row.find(column);
66+
if (idx != -1) {
67+
Object object = row.getValue(idx);
68+
if (object instanceof String) {
69+
if (object != null) {
70+
String value = (String) object;
71+
row.setValue(idx, value.length());
72+
}
73+
} else if (object instanceof byte[]) {
74+
String value = Bytes.toString((byte[])object);
75+
row.setValue(idx, value.length());
76+
}
77+
}
78+
}
79+
return rows;
80+
}
81+
82+
@Override
83+
public void destroy() {
84+
// no-op
85+
}
86+
}

0 commit comments

Comments
 (0)