Thomas Vachuska
Committed by Gerrit Code Review

Adding OnosCfgMojo to the onos maven plugin.

Removing previously manuall generated files since they are now auto-generated.

Change-Id: I1f8361f97db74c9e2f077b3d5e7a6e65876561ef
# 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
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
......@@ -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>
......
# Temporary: to be auto-generated in near future
ipv6NeighborDiscovery|BOOLEAN|false|Enable IPv6 Neighbor Discovery; default is false
# 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
......@@ -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>
......
# 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
......@@ -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>
<groupId>org.onosproject</groupId>
<artifactId>onos-maven-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>prepare-agent</goal>
<goal>cfg</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</execution>
</executions>
</plugin>
-->
</plugins>
</pluginManagement>
......
# 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
# 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
......@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Property;
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 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
@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 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
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 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
@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 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
@Deactivate
public void deactivate(ComponentContext context) {
cfgService.unregisterProperties(getClass(), false);
deviceBuilder.submit(new DeviceCreator(false));
try {
deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
......
# 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
# Temporary: to be auto-generated in near future
"pktRate"|INTEGER|5|Rate of PacketEvent generation
......@@ -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>
......
<!--
~ 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
/*
* 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);
}
}
/*
* 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(";$", ""));
}
}