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
1 -# Temporary: to be auto-generated in near future
2 -packetOutOnly|BOOLEAN|false|Enable packet-out only forwarding; default is false
3 -packetOutOfppTable|BOOLEAN|false|Enable first packet forwarding using OFPP_TABLE port instead of PacketOut with actual port; default is false
4 -flowTimeout|INTEGER|10|Configure Flow Timeout for installed flow rules; default is 10 sec
5 -flowPriority|INTEGER|10|Configure Flow Priority for installed flow rules; default is 10
6 -ipv6Forwarding|BOOLEAN|false|Enable IPv6 forwarding; default is false
7 -matchDstMacOnly|BOOLEAN|false|Enable matching Dst Mac Only; default is false
8 -matchVlanId|BOOLEAN|false|Enable matching Vlan ID; default is false
9 -matchIpv4Address|BOOLEAN|false|Enable matching IPv4 Addresses; default is false
10 -matchIpv4Dscp|BOOLEAN|false|Enable matching IPv4 DSCP and ECN; default is false
11 -matchIpv6Address|BOOLEAN|false|Enable matching IPv6 Addresses; default is false
12 -matchIpv6FlowLabel|BOOLEAN|false|Enable matching IPv6 FlowLabel; default is false
13 -matchTcpUdpPorts|BOOLEAN|false|Enable matching TCP/UDP ports; default is false
14 -matchIcmpFields|BOOLEAN|false|Enable matching ICMPv4 and ICMPv6 fields; default is false
1 -numKeys|INTEGER|40000|Number of keys (i.e. unique intents) to generate per instance
2 -cyclePeriod|INTEGER|1000|Goal for cycle period (in ms)
3 -numNeighbors|INTEGER|0|Number of neighbors to generate intents for
...\ No newline at end of file ...\ No newline at end of file
...@@ -85,6 +85,11 @@ ...@@ -85,6 +85,11 @@
85 <groupId>org.apache.felix</groupId> 85 <groupId>org.apache.felix</groupId>
86 <artifactId>maven-scr-plugin</artifactId> 86 <artifactId>maven-scr-plugin</artifactId>
87 </plugin> 87 </plugin>
88 +
89 + <plugin>
90 + <groupId>org.onosproject</groupId>
91 + <artifactId>onos-maven-plugin</artifactId>
92 + </plugin>
88 </plugins> 93 </plugins>
89 </build> 94 </build>
90 95
......
1 -# Temporary: to be auto-generated in near future
2 -ipv6NeighborDiscovery|BOOLEAN|false|Enable IPv6 Neighbor Discovery; default is false
1 -# Temporary: to be auto-generated in near future
2 -maxEvents|INTEGER|1000|Maximum number of events to accumulate
3 -maxIdleMs|INTEGER|10|Maximum number of millis between events
4 -maxBatchMs|INTEGER|50|Maximum number of millis for whole batch
...@@ -64,6 +64,11 @@ ...@@ -64,6 +64,11 @@
64 <groupId>org.apache.felix</groupId> 64 <groupId>org.apache.felix</groupId>
65 <artifactId>maven-bundle-plugin</artifactId> 65 <artifactId>maven-bundle-plugin</artifactId>
66 </plugin> 66 </plugin>
67 +
68 + <plugin>
69 + <groupId>org.onosproject</groupId>
70 + <artifactId>onos-maven-plugin</artifactId>
71 + </plugin>
67 </plugins> 72 </plugins>
68 </build> 73 </build>
69 74
......
1 -# Temporary: to be auto-generated in near future
2 -msgHandlerPoolSize|INTEGER|8|Number of threads in the message handler pool
3 -backupEnabled|BOOLEAN|false|Indicates whether backups are enabled or not
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
47 <description>Open Network Operating System root project</description> 47 <description>Open Network Operating System root project</description>
48 48
49 <modules> 49 <modules>
50 + <module>tools/package/maven-plugin</module>
50 <module>utils</module> 51 <module>utils</module>
51 <module>core</module> 52 <module>core</module>
52 <module>web</module> 53 <module>web</module>
...@@ -539,38 +540,19 @@ ...@@ -539,38 +540,19 @@
539 </configuration> 540 </configuration>
540 </plugin> 541 </plugin>
541 542
542 - <!-- TODO: add findbugs plugin for static code analysis; for explicit invocation only -->
543 - <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.-->
544 - <!--
545 <plugin> 543 <plugin>
546 - <groupId>org.eclipse.m2e</groupId> 544 + <groupId>org.onosproject</groupId>
547 - <artifactId>lifecycle-mapping</artifactId> 545 + <artifactId>onos-maven-plugin</artifactId>
548 - <version>1.0.0</version> 546 + <version>${project.version}</version>
549 - <configuration> 547 + <executions>
550 - <lifecycleMappingMetadata> 548 + <execution>
551 - <pluginExecutions> 549 + <phase>generate-resources</phase>
552 - <pluginExecution>
553 - <pluginExecutionFilter>
554 - <groupId>org.jacoco</groupId>
555 - <artifactId>
556 - jacoco-maven-plugin
557 - </artifactId>
558 - <versionRange>
559 - [0.7.1.201405082137,)
560 - </versionRange>
561 <goals> 550 <goals>
562 - <goal>prepare-agent</goal> 551 + <goal>cfg</goal>
563 </goals> 552 </goals>
564 - </pluginExecutionFilter> 553 + </execution>
565 - <action> 554 + </executions>
566 - <ignore></ignore>
567 - </action>
568 - </pluginExecution>
569 - </pluginExecutions>
570 - </lifecycleMappingMetadata>
571 - </configuration>
572 </plugin> 555 </plugin>
573 - -->
574 </plugins> 556 </plugins>
575 </pluginManagement> 557 </pluginManagement>
576 558
......
1 -# Temporary: to be auto-generated in near future
2 -hostRemovalEnabled|BOOLEAN|true|Enable host removal on port/device down events
3 -ipv6NeighborDiscovery|BOOLEAN|false|Enable using IPv6 Neighbor Discovery by the Host Location Provider; default is false
1 -# Temporary: to be auto-generated in near future
2 -useBDDP|BOOLEAN|true|Use BDDP for link discovery
3 -disableLinkDiscovery|BOOLEAN|false|Permanently disable link discovery
4 -lldpSuppression|STRING|../config/lldp_suppression.json|Path to LLDP suppression configuration file
...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Property; ...@@ -25,6 +25,7 @@ import org.apache.felix.scr.annotations.Property;
25 import org.apache.felix.scr.annotations.Reference; 25 import org.apache.felix.scr.annotations.Reference;
26 import org.apache.felix.scr.annotations.ReferenceCardinality; 26 import org.apache.felix.scr.annotations.ReferenceCardinality;
27 import org.onlab.packet.ChassisId; 27 import org.onlab.packet.ChassisId;
28 +import org.onosproject.cfg.ComponentConfigService;
28 import org.onosproject.cluster.ClusterService; 29 import org.onosproject.cluster.ClusterService;
29 import org.onosproject.cluster.NodeId; 30 import org.onosproject.cluster.NodeId;
30 import org.onosproject.net.Device; 31 import org.onosproject.net.Device;
...@@ -73,6 +74,9 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -73,6 +74,9 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
73 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
74 protected DeviceProviderRegistry providerRegistry; 75 protected DeviceProviderRegistry providerRegistry;
75 76
77 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
78 + protected ComponentConfigService cfgService;
79 +
76 private DeviceProviderService providerService; 80 private DeviceProviderService providerService;
77 81
78 private ExecutorService deviceBuilder = 82 private ExecutorService deviceBuilder =
...@@ -88,11 +92,11 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -88,11 +92,11 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
88 private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap(); 92 private final Map<Integer, DeviceDescription> descriptions = Maps.newHashMap();
89 93
90 @Property(name = "devConfigs", value = "", label = "Instance-specific configurations") 94 @Property(name = "devConfigs", value = "", label = "Instance-specific configurations")
91 - private String devConfigs = ""; 95 + private String devConfigs = null;
92 96
93 private int numDevices = DEF_NUMDEVICES; 97 private int numDevices = DEF_NUMDEVICES;
94 98
95 - @Property(name = "numPorts", value = "10", label = "Number of ports per devices") 99 + @Property(name = "numPorts", intValue = 10, label = "Number of ports per devices")
96 private int numPorts = DEF_NUMPORTS; 100 private int numPorts = DEF_NUMPORTS;
97 101
98 private DeviceCreator creator; 102 private DeviceCreator creator;
...@@ -108,6 +112,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -108,6 +112,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
108 112
109 @Activate 113 @Activate
110 public void activate(ComponentContext context) { 114 public void activate(ComponentContext context) {
115 + cfgService.registerProperties(getClass());
111 providerService = providerRegistry.register(this); 116 providerService = providerRegistry.register(this);
112 if (!modified(context)) { 117 if (!modified(context)) {
113 deviceBuilder.submit(new DeviceCreator(true)); 118 deviceBuilder.submit(new DeviceCreator(true));
...@@ -118,6 +123,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid ...@@ -118,6 +123,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid
118 123
119 @Deactivate 124 @Deactivate
120 public void deactivate(ComponentContext context) { 125 public void deactivate(ComponentContext context) {
126 + cfgService.unregisterProperties(getClass(), false);
121 deviceBuilder.submit(new DeviceCreator(false)); 127 deviceBuilder.submit(new DeviceCreator(false));
122 try { 128 try {
123 deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS); 129 deviceBuilder.awaitTermination(1000, TimeUnit.MILLISECONDS);
......
1 -# Temporary: to be auto-generated in near future
2 - "eventRate"|INTEGER|0|Duration between Link Event
3 - "cfgFile"|STRING|"/opt/onos/apache-karaf-3.0.2/etc/linkGraph.cfg"|Topology file location
1 -# Temporary: to be auto-generated in near future
2 - "pktRate"|INTEGER|5|Rate of PacketEvent generation
...@@ -70,6 +70,11 @@ ...@@ -70,6 +70,11 @@
70 <groupId>org.apache.felix</groupId> 70 <groupId>org.apache.felix</groupId>
71 <artifactId>maven-bundle-plugin</artifactId> 71 <artifactId>maven-bundle-plugin</artifactId>
72 </plugin> 72 </plugin>
73 +
74 + <plugin>
75 + <groupId>org.onosproject</groupId>
76 + <artifactId>onos-maven-plugin</artifactId>
77 + </plugin>
73 </plugins> 78 </plugins>
74 </build> 79 </build>
75 80
......
1 +<!--
2 + ~ Copyright 2015 Open Networking Laboratory
3 + ~
4 + ~ Licensed under the Apache License, Version 2.0 (the "License");
5 + ~ you may not use this file except in compliance with the License.
6 + ~ You may obtain a copy of 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,
12 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + ~ See the License for the specific language governing permissions and
14 + ~ limitations under the License.
15 + -->
16 +<project>
17 + <modelVersion>4.0.0</modelVersion>
18 +
19 + <parent>
20 + <groupId>org.onosproject</groupId>
21 + <artifactId>onos-base</artifactId>
22 + <version>1</version>
23 + <relativePath>../../build/pom.xml</relativePath>
24 + </parent>
25 +
26 + <artifactId>onos-maven-plugin</artifactId>
27 + <version>1.1.0-SNAPSHOT</version>
28 + <packaging>maven-plugin</packaging>
29 +
30 + <description>Maven plugin for packaging ONOS applications or generating component configuration resources</description>
31 +
32 + <dependencies>
33 + <dependency>
34 + <groupId>org.apache.maven</groupId>
35 + <artifactId>maven-plugin-api</artifactId>
36 + <version>2.0</version>
37 + </dependency>
38 +
39 + <dependency>
40 + <groupId>com.thoughtworks.qdox</groupId>
41 + <artifactId>qdox</artifactId>
42 + <version>2.0-M3</version>
43 + </dependency>
44 +
45 + <!-- dependencies to annotations -->
46 + <dependency>
47 + <groupId>org.apache.maven.plugin-tools</groupId>
48 + <artifactId>maven-plugin-annotations</artifactId>
49 + <version>3.4</version>
50 + <scope>provided</scope>
51 + </dependency>
52 + </dependencies>
53 +
54 + <build>
55 + <plugins>
56 + <plugin>
57 + <groupId>org.apache.maven.plugins</groupId>
58 + <artifactId>maven-compiler-plugin</artifactId>
59 + <version>2.5.1</version>
60 + <configuration>
61 + <source>1.8</source>
62 + <target>1.8</target>
63 + </configuration>
64 + </plugin>
65 +
66 + <plugin>
67 + <groupId>org.apache.maven.plugins</groupId>
68 + <artifactId>maven-plugin-plugin</artifactId>
69 + <version>3.4</version>
70 + <executions>
71 + <execution>
72 + <id>default-descriptor</id>
73 + <phase>process-classes</phase>
74 + </execution>
75 + <!-- if you want to generate help goal -->
76 + <execution>
77 + <id>help-goal</id>
78 + <goals>
79 + <goal>helpmojo</goal>
80 + </goals>
81 + </execution>
82 + </executions>
83 + </plugin>
84 + </plugins>
85 + </build>
86 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of 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,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.maven;
17 +
18 +import org.apache.maven.plugin.AbstractMojo;
19 +import org.apache.maven.plugin.MojoExecutionException;
20 +import org.apache.maven.plugins.annotations.LifecyclePhase;
21 +import org.apache.maven.plugins.annotations.Mojo;
22 +import org.apache.maven.plugins.annotations.Parameter;
23 +
24 +import java.util.List;
25 +
26 +/**
27 + * Produces ONOS application archive.
28 + */
29 +@Mojo(name = "app", defaultPhase = LifecyclePhase.PACKAGE)
30 +public class OnosAppMojo extends AbstractMojo {
31 +
32 + @Parameter
33 + private String name;
34 +
35 + @Parameter
36 + private String version;
37 +
38 + @Parameter
39 + private String origin;
40 +
41 + @Parameter
42 + private String description;
43 +
44 + @Parameter
45 + private String featuresRepo;
46 +
47 + @Parameter
48 + private String features;
49 +
50 + @Parameter
51 + private String permissions;
52 +
53 + @Parameter
54 + private List<String> artifacts;
55 +
56 +
57 + public void execute() throws MojoExecutionException {
58 + getLog().info("Building ONOS application archive " + name + " version " + version);
59 +
60 + }
61 +}
62 +
63 +
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of 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,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + */
16 +package org.onosproject.maven;
17 +
18 +import com.thoughtworks.qdox.JavaProjectBuilder;
19 +import com.thoughtworks.qdox.model.JavaAnnotation;
20 +import com.thoughtworks.qdox.model.JavaClass;
21 +import com.thoughtworks.qdox.model.JavaField;
22 +import org.apache.maven.plugin.AbstractMojo;
23 +import org.apache.maven.plugin.MojoExecutionException;
24 +import org.apache.maven.plugins.annotations.LifecyclePhase;
25 +import org.apache.maven.plugins.annotations.Mojo;
26 +import org.apache.maven.plugins.annotations.Parameter;
27 +
28 +import java.io.File;
29 +import java.io.FileWriter;
30 +import java.io.IOException;
31 +import java.io.PrintWriter;
32 +import java.util.ArrayList;
33 +import java.util.List;
34 +
35 +/**
36 + * Produces ONOS component configuration catalogue resources.
37 + */
38 +@Mojo(name = "cfg", defaultPhase = LifecyclePhase.GENERATE_RESOURCES)
39 +public class OnosCfgMojo extends AbstractMojo {
40 +
41 + private static final String COMPONENT = "org.apache.felix.scr.annotations.Component";
42 + private static final String PROPERTY = "org.apache.felix.scr.annotations.Property";
43 + private static final String SEP = "|";
44 +
45 + /**
46 + * The directory where the generated catalogue file will be put.
47 + */
48 + @Parameter( defaultValue = "${basedir}" )
49 + protected File srcDirectory;
50 +
51 + /**
52 + * The directory where the generated catalogue file will be put.
53 + */
54 + @Parameter( defaultValue = "${project.build.outputDirectory}" )
55 + protected File dstDirectory;
56 +
57 + @Override
58 + public void execute() throws MojoExecutionException {
59 + getLog().info("Generating ONOS component configuration catalogues...");
60 + try {
61 + JavaProjectBuilder builder = new JavaProjectBuilder();
62 + builder.addSourceTree(new File(srcDirectory, "src/main/java"));
63 + builder.getClasses().forEach(this::processClass);
64 + } catch (Exception e) {
65 + e.printStackTrace();
66 + throw e;
67 + }
68 + }
69 +
70 + private void processClass(JavaClass javaClass) {
71 + boolean isComponent = javaClass.getAnnotations().stream()
72 + .map(ja -> ja.getType().getName().equals(COMPONENT))
73 + .findFirst().isPresent();
74 + if (isComponent) {
75 + List<String> lines = new ArrayList<>();
76 + javaClass.getFields().forEach(field -> processField(lines, javaClass, field));
77 + if (!lines.isEmpty()) {
78 + writeCatalog(javaClass, lines);
79 + }
80 + }
81 + }
82 +
83 + private void writeCatalog(JavaClass javaClass, List<String> lines) {
84 + File dir = new File(dstDirectory, javaClass.getPackageName().replace('.', '/'));
85 + dir.mkdirs();
86 +
87 + File cfgDef = new File(dir, javaClass.getName().replace('.', '/') + ".cfgdef");
88 + try (FileWriter fw = new FileWriter(cfgDef);
89 + PrintWriter pw = new PrintWriter(fw)) {
90 + pw.println("# This file is auto-generated by onos-maven-plugin");
91 + lines.forEach(pw::println);
92 + } catch (IOException e) {
93 + System.err.println("Unable to write catalog for " + javaClass.getName());
94 + e.printStackTrace();
95 + }
96 + }
97 +
98 + private void processField(List<String> lines, JavaClass javaClass, JavaField field) {
99 + field.getAnnotations().forEach(ja -> {
100 + if (ja.getType().getName().equals(PROPERTY)) {
101 + lines.add(expand(javaClass, ja.getNamedParameter("name").toString()) +
102 + SEP + type(field) +
103 + SEP + defaultValue(javaClass, field, ja) +
104 + SEP + description(ja));
105 + }
106 + });
107 + }
108 +
109 + // TODO: Stuff below is very much hack-ish and should be redone; it works for now though.
110 +
111 + private String description(JavaAnnotation annotation) {
112 + String description = (String) annotation.getNamedParameter("label");
113 + return description.replaceAll("\" \\+ \"", "")
114 + .replaceFirst("^[^\"]*\"", "").replaceFirst("\"$", "");
115 + }
116 +
117 + private String type(JavaField field) {
118 + String ft = field.getType().getName().toUpperCase();
119 + return ft.equals("INT") ? "INTEGER" : ft;
120 + }
121 +
122 + private String defaultValue(JavaClass javaClass, JavaField field,
123 + JavaAnnotation annotation) {
124 + String ft = field.getType().getName().toLowerCase();
125 + String defValueName = ft.equals("boolean") ? "boolValue" :
126 + ft.equals("string") ? "value" : ft + "Value";
127 + Object dv = annotation.getNamedParameter(defValueName);
128 + return dv == null ? "" : expand(javaClass, dv.toString());
129 + }
130 +
131 + private String stripQuotes(String string) {
132 + return string.trim().replaceFirst("^[^\"]*\"", "").replaceFirst("\"$", "");
133 + }
134 +
135 + private String expand(JavaClass javaClass, String value) {
136 + JavaField field = javaClass.getFieldByName(value);
137 + return field == null ? stripQuotes(value) :
138 + stripQuotes(field.getCodeBlock().replaceFirst(".*=", "").replaceFirst(";$", ""));
139 + }
140 +
141 +}