Adding OnosCfgMojo to the onos maven plugin.
Removing previously manuall generated files since they are now auto-generated.
Change-Id: I1f8361f97db74c9e2f077b3d5e7a6e65876561ef
diff --git a/apps/fwd/src/main/resources/org/onosproject/fwd/ReactiveForwarding.cfgdef b/apps/fwd/src/main/resources/org/onosproject/fwd/ReactiveForwarding.cfgdef
deleted file mode 100644
index 47f481c..0000000
--- a/apps/fwd/src/main/resources/org/onosproject/fwd/ReactiveForwarding.cfgdef
+++ /dev/null
@@ -1,14 +0,0 @@
-# Temporary: to be auto-generated in near future
-packetOutOnly|BOOLEAN|false|Enable packet-out only forwarding; default is false
-packetOutOfppTable|BOOLEAN|false|Enable first packet forwarding using OFPP_TABLE port instead of PacketOut with actual port; default is false
-flowTimeout|INTEGER|10|Configure Flow Timeout for installed flow rules; default is 10 sec
-flowPriority|INTEGER|10|Configure Flow Priority for installed flow rules; default is 10
-ipv6Forwarding|BOOLEAN|false|Enable IPv6 forwarding; default is false
-matchDstMacOnly|BOOLEAN|false|Enable matching Dst Mac Only; default is false
-matchVlanId|BOOLEAN|false|Enable matching Vlan ID; default is false
-matchIpv4Address|BOOLEAN|false|Enable matching IPv4 Addresses; default is false
-matchIpv4Dscp|BOOLEAN|false|Enable matching IPv4 DSCP and ECN; default is false
-matchIpv6Address|BOOLEAN|false|Enable matching IPv6 Addresses; default is false
-matchIpv6FlowLabel|BOOLEAN|false|Enable matching IPv6 FlowLabel; default is false
-matchTcpUdpPorts|BOOLEAN|false|Enable matching TCP/UDP ports; default is false
-matchIcmpFields|BOOLEAN|false|Enable matching ICMPv4 and ICMPv6 fields; default is false
diff --git a/apps/intent-perf/src/main/resources/org/onosproject/intentperf/IntentPerfInstaller.cfgdef b/apps/intent-perf/src/main/resources/org/onosproject/intentperf/IntentPerfInstaller.cfgdef
deleted file mode 100644
index ae2f195..0000000
--- a/apps/intent-perf/src/main/resources/org/onosproject/intentperf/IntentPerfInstaller.cfgdef
+++ /dev/null
@@ -1,3 +0,0 @@
-numKeys|INTEGER|40000|Number of keys (i.e. unique intents) to generate per instance
-cyclePeriod|INTEGER|1000|Goal for cycle period (in ms)
-numNeighbors|INTEGER|0|Number of neighbors to generate intents for
\ No newline at end of file
diff --git a/apps/pom.xml b/apps/pom.xml
index 9b9f09d..131aa7c 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -85,6 +85,11 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
+
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
diff --git a/apps/proxyarp/src/main/resources/org/onosproject/proxyarp/ProxyArp.cfgdef b/apps/proxyarp/src/main/resources/org/onosproject/proxyarp/ProxyArp.cfgdef
deleted file mode 100644
index c39bcb4..0000000
--- a/apps/proxyarp/src/main/resources/org/onosproject/proxyarp/ProxyArp.cfgdef
+++ /dev/null
@@ -1,2 +0,0 @@
-# Temporary: to be auto-generated in near future
-ipv6NeighborDiscovery|BOOLEAN|false|Enable IPv6 Neighbor Discovery; default is false
diff --git a/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef b/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef
deleted file mode 100644
index c380f70..0000000
--- a/core/net/src/main/resources/org/onosproject/net/topology/impl/DefaultTopologyProvider.cfgdef
+++ /dev/null
@@ -1,4 +0,0 @@
-# Temporary: to be auto-generated in near future
-maxEvents|INTEGER|1000|Maximum number of events to accumulate
-maxIdleMs|INTEGER|10|Maximum number of millis between events
-maxBatchMs|INTEGER|50|Maximum number of millis for whole batch
diff --git a/core/pom.xml b/core/pom.xml
index 97c33d8..0b4e8e4 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -64,6 +64,11 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
diff --git a/core/store/dist/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef b/core/store/dist/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
deleted file mode 100644
index a579a92..0000000
--- a/core/store/dist/src/main/resources/org/onosproject/store/flow/impl/DistributedFlowRuleStore.cfgdef
+++ /dev/null
@@ -1,3 +0,0 @@
-# Temporary: to be auto-generated in near future
-msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
-backupEnabled|BOOLEAN|false|Indicates whether backups are enabled or not
diff --git a/pom.xml b/pom.xml
index 23ee5b3..48ad2d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -47,6 +47,7 @@
<description>Open Network Operating System root project</description>
<modules>
+ <module>tools/package/maven-plugin</module>
<module>utils</module>
<module>core</module>
<module>web</module>
@@ -539,38 +540,19 @@
</configuration>
</plugin>
- <!-- TODO: add findbugs plugin for static code analysis; for explicit invocation only -->
- <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
- <!--
<plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>org.jacoco</groupId>
- <artifactId>
- jacoco-maven-plugin
- </artifactId>
- <versionRange>
- [0.7.1.201405082137,)
- </versionRange>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>cfg</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
- -->
</plugins>
</pluginManagement>
diff --git a/providers/host/src/main/resources/org/onosproject/provider/host/impl/HostLocationProvider.cfgdef b/providers/host/src/main/resources/org/onosproject/provider/host/impl/HostLocationProvider.cfgdef
deleted file mode 100644
index 0412408..0000000
--- a/providers/host/src/main/resources/org/onosproject/provider/host/impl/HostLocationProvider.cfgdef
+++ /dev/null
@@ -1,3 +0,0 @@
-# Temporary: to be auto-generated in near future
-hostRemovalEnabled|BOOLEAN|true|Enable host removal on port/device down events
-ipv6NeighborDiscovery|BOOLEAN|false|Enable using IPv6 Neighbor Discovery by the Host Location Provider; default is false
diff --git a/providers/lldp/src/main/resources/org/onosproject/provider/lldp/impl/LLDPLinkProvider.cfgdef b/providers/lldp/src/main/resources/org/onosproject/provider/lldp/impl/LLDPLinkProvider.cfgdef
deleted file mode 100644
index 588e4f3..0000000
--- a/providers/lldp/src/main/resources/org/onosproject/provider/lldp/impl/LLDPLinkProvider.cfgdef
+++ /dev/null
@@ -1,4 +0,0 @@
-# Temporary: to be auto-generated in near future
-useBDDP|BOOLEAN|true|Use BDDP for link discovery
-disableLinkDiscovery|BOOLEAN|false|Permanently disable link discovery
-lldpSuppression|STRING|../config/lldp_suppression.json|Path to LLDP suppression configuration file
diff --git a/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java b/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
index 9cbd7c5..0766917 100644
--- a/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
+++ b/providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
@@ -25,6 +25,7 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onlab.packet.ChassisId;
+import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
import org.onosproject.net.Device;
@@ -73,6 +74,9 @@
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceProviderRegistry providerRegistry;
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected ComponentConfigService cfgService;
+
private DeviceProviderService providerService;
private ExecutorService deviceBuilder =
@@ -88,11 +92,11 @@
private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap();
@Property(name = "devConfigs", value = "", label = "Instance-specific configurations")
- private String devConfigs = "";
+ private String devConfigs = null;
private int numDevices = DEF_NUMDEVICES;
- @Property(name = "numPorts", value = "10", label = "Number of ports per devices")
+ @Property(name = "numPorts", intValue = 10, label = "Number of ports per devices")
private int numPorts = DEF_NUMPORTS;
private DeviceCreator creator;
@@ -108,6 +112,7 @@
@Activate
public void activate(ComponentContext context) {
+ cfgService.registerProperties(getClass());
providerService = providerRegistry.register(this);
if (!modified(context)) {
deviceBuilder.submit(new DeviceCreator(true));
@@ -118,6 +123,7 @@
@Deactivate
public void deactivate(ComponentContext context) {
+ cfgService.unregisterProperties(getClass(), false);
deviceBuilder.submit(new DeviceCreator(false));
try {
deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
diff --git a/providers/null/link/src/main/resources/org/onosproject/provider/nil/link/impl/NullLinkProvider.cfgdef b/providers/null/link/src/main/resources/org/onosproject/provider/nil/link/impl/NullLinkProvider.cfgdef
deleted file mode 100644
index f1dda76..0000000
--- a/providers/null/link/src/main/resources/org/onosproject/provider/nil/link/impl/NullLinkProvider.cfgdef
+++ /dev/null
@@ -1,3 +0,0 @@
-# Temporary: to be auto-generated in near future
- "eventRate"|INTEGER|0|Duration between Link Event
- "cfgFile"|STRING|"/opt/onos/apache-karaf-3.0.2/etc/linkGraph.cfg"|Topology file location
diff --git a/providers/null/packet/src/main/resources/org/onosproject/provider/nil/packet/impl/NullPacketProvider.cfgdef b/providers/null/packet/src/main/resources/org/onosproject/provider/nil/packet/impl/NullPacketProvider.cfgdef
deleted file mode 100644
index b71929c..0000000
--- a/providers/null/packet/src/main/resources/org/onosproject/provider/nil/packet/impl/NullPacketProvider.cfgdef
+++ /dev/null
@@ -1,2 +0,0 @@
-# Temporary: to be auto-generated in near future
- "pktRate"|INTEGER|5|Rate of PacketEvent generation
diff --git a/providers/pom.xml b/providers/pom.xml
index 4ca6f93..6507acb 100644
--- a/providers/pom.xml
+++ b/providers/pom.xml
@@ -70,6 +70,11 @@
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
</plugin>
+
+ <plugin>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
diff --git a/tools/package/maven-plugin/pom.xml b/tools/package/maven-plugin/pom.xml
new file mode 100644
index 0000000..2260ce9
--- /dev/null
+++ b/tools/package/maven-plugin/pom.xml
@@ -0,0 +1,86 @@
+<!--
+ ~ Copyright 2015 Open Networking Laboratory
+ ~
+ ~ Licensed under the Apache License, Version 2.0 (the "License");
+ ~ you may not use this file except in compliance with the License.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-base</artifactId>
+ <version>1</version>
+ <relativePath>../../build/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>onos-maven-plugin</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <packaging>maven-plugin</packaging>
+
+ <description>Maven plugin for packaging ONOS applications or generating component configuration resources</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven</groupId>
+ <artifactId>maven-plugin-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.thoughtworks.qdox</groupId>
+ <artifactId>qdox</artifactId>
+ <version>2.0-M3</version>
+ </dependency>
+
+ <!-- dependencies to annotations -->
+ <dependency>
+ <groupId>org.apache.maven.plugin-tools</groupId>
+ <artifactId>maven-plugin-annotations</artifactId>
+ <version>3.4</version>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <source>1.8</source>
+ <target>1.8</target>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-plugin-plugin</artifactId>
+ <version>3.4</version>
+ <executions>
+ <execution>
+ <id>default-descriptor</id>
+ <phase>process-classes</phase>
+ </execution>
+ <!-- if you want to generate help goal -->
+ <execution>
+ <id>help-goal</id>
+ <goals>
+ <goal>helpmojo</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java b/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java
new file mode 100644
index 0000000..9b39903
--- /dev/null
+++ b/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosAppMojo.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.maven;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+import java.util.List;
+
+/**
+ * Produces ONOS application archive.
+ */
+@Mojo(name = "app", defaultPhase = LifecyclePhase.PACKAGE)
+public class OnosAppMojo extends AbstractMojo {
+
+ @Parameter
+ private String name;
+
+ @Parameter
+ private String version;
+
+ @Parameter
+ private String origin;
+
+ @Parameter
+ private String description;
+
+ @Parameter
+ private String featuresRepo;
+
+ @Parameter
+ private String features;
+
+ @Parameter
+ private String permissions;
+
+ @Parameter
+ private List<String> artifacts;
+
+
+ public void execute() throws MojoExecutionException {
+ getLog().info("Building ONOS application archive " + name + " version " + version);
+
+ }
+}
+
+
diff --git a/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosCfgMojo.java b/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosCfgMojo.java
new file mode 100644
index 0000000..b2742d7
--- /dev/null
+++ b/tools/package/maven-plugin/src/main/java/org/onosproject/maven/OnosCfgMojo.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.maven;
+
+import com.thoughtworks.qdox.JavaProjectBuilder;
+import com.thoughtworks.qdox.model.JavaAnnotation;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaField;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Produces ONOS component configuration catalogue resources.
+ */
+@Mojo(name = "cfg", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
+public class OnosCfgMojo extends AbstractMojo {
+
+ private static final String COMPONENT = "org.apache.felix.scr.annotations.Component";
+ private static final String PROPERTY = "org.apache.felix.scr.annotations.Property";
+ private static final String SEP = "|";
+
+ /**
+ * The directory where the generated catalogue file will be put.
+ */
+ @Parameter( defaultValue = "${basedir}" )
+ protected File srcDirectory;
+
+ /**
+ * The directory where the generated catalogue file will be put.
+ */
+ @Parameter( defaultValue = "${project.build.outputDirectory}" )
+ protected File dstDirectory;
+
+ @Override
+ public void execute() throws MojoExecutionException {
+ getLog().info("Generating ONOS component configuration catalogues...");
+ try {
+ JavaProjectBuilder builder = new JavaProjectBuilder();
+ builder.addSourceTree(new File(srcDirectory, "src/main/java"));
+ builder.getClasses().forEach(this::processClass);
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ private void processClass(JavaClass javaClass) {
+ boolean isComponent = javaClass.getAnnotations().stream()
+ .map(ja -> ja.getType().getName().equals(COMPONENT))
+ .findFirst().isPresent();
+ if (isComponent) {
+ List<String> lines = new ArrayList<>();
+ javaClass.getFields().forEach(field -> processField(lines, javaClass, field));
+ if (!lines.isEmpty()) {
+ writeCatalog(javaClass, lines);
+ }
+ }
+ }
+
+ private void writeCatalog(JavaClass javaClass, List<String> lines) {
+ File dir = new File(dstDirectory, javaClass.getPackageName().replace('.', '/'));
+ dir.mkdirs();
+
+ File cfgDef = new File(dir, javaClass.getName().replace('.', '/') + ".cfgdef");
+ try (FileWriter fw = new FileWriter(cfgDef);
+ PrintWriter pw = new PrintWriter(fw)) {
+ pw.println("# This file is auto-generated by onos-maven-plugin");
+ lines.forEach(pw::println);
+ } catch (IOException e) {
+ System.err.println("Unable to write catalog for " + javaClass.getName());
+ e.printStackTrace();
+ }
+ }
+
+ private void processField(List<String> lines, JavaClass javaClass, JavaField field) {
+ field.getAnnotations().forEach(ja -> {
+ if (ja.getType().getName().equals(PROPERTY)) {
+ lines.add(expand(javaClass, ja.getNamedParameter("name").toString()) +
+ SEP + type(field) +
+ SEP + defaultValue(javaClass, field, ja) +
+ SEP + description(ja));
+ }
+ });
+ }
+
+ // TODO: Stuff below is very much hack-ish and should be redone; it works for now though.
+
+ private String description(JavaAnnotation annotation) {
+ String description = (String) annotation.getNamedParameter("label");
+ return description.replaceAll("\" \\+ \"", "")
+ .replaceFirst("^[^\"]*\"", "").replaceFirst("\"$", "");
+ }
+
+ private String type(JavaField field) {
+ String ft = field.getType().getName().toUpperCase();
+ return ft.equals("INT") ? "INTEGER" : ft;
+ }
+
+ private String defaultValue(JavaClass javaClass, JavaField field,
+ JavaAnnotation annotation) {
+ String ft = field.getType().getName().toLowerCase();
+ String defValueName = ft.equals("boolean") ? "boolValue" :
+ ft.equals("string") ? "value" : ft + "Value";
+ Object dv = annotation.getNamedParameter(defValueName);
+ return dv == null ? "" : expand(javaClass, dv.toString());
+ }
+
+ private String stripQuotes(String string) {
+ return string.trim().replaceFirst("^[^\"]*\"", "").replaceFirst("\"$", "");
+ }
+
+ private String expand(JavaClass javaClass, String value) {
+ JavaField field = javaClass.getFieldByName(value);
+ return field == null ? stripQuotes(value) :
+ stripQuotes(field.getCodeBlock().replaceFirst(".*=", "").replaceFirst(";$", ""));
+ }
+
+}