1. 程式人生 > >opendaylight(Li) l2switch 原始碼分析(2)--parent

opendaylight(Li) l2switch 原始碼分析(2)--parent

本文主要介紹l2switch中的parent工程,該工程定義了執行L2switch所使用的依賴模組以及版本等。
該工程下只有一個pom.xml檔案,下面對該檔案中的主要內容進行說明:

1.
<parent>
    <groupId>org.opendaylight.odlparent</groupId>
    <artifactId>odlparent</artifactId>
    <version>1.7.0-SNAPSHOT</version>
    <relativePath/>
</parent>
該工程繼承了工程“org.opendaylight.odlparent”,這個工程在l2 switch中不存在,檢視opendaylight
的github(https://github.com/opendaylight/odlparent),確實有一個odlparent工程,檢視該工程
的pom.xml:
<parent>
   <groupId>org.opendaylight.odlparent</groupId>
   <artifactId>odlparent-lite</artifactId>
   <version>1.7.0-SNAPSHOT</version>
   <relativePath>odlparent-lite</relativePath>
</parent>
貌似odlparent還繼承於odlparent-lite,在odlparent工程目錄下找到了odlparent-lite檔案下的pom.xml,
貌似該pom.xml不再繼承於其他的工程,應該找到源頭了。
後面會介紹到其他的工程,如packethandler、loopremover等,它們的pom.xml都會繼承於parent工程,即在
這些工程的pom.xml下面都有一下內容:
    <parent>
        <groupId>org.opendaylight.l2switch</groupId>
        <artifactId>l2switch-parent</artifactId>
        <version>0.4.0-SNAPSHOT</version>
        <relativePath>../parent</relativePath>
    </parent>

2.
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.opendaylight.yangtools</groupId>
        <artifactId>yangtools-artifacts</artifactId>
        <version>${yangtools.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.mdsal</groupId>
        <artifactId>mdsal-artifacts</artifactId>
        <version>2.1.0-SNAPSHOT</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.mdsal.model</groupId>
        <artifactId>mdsal-model-artifacts</artifactId>
        <version>0.9.0-SNAPSHOT</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.controller</groupId>
        <artifactId>config-artifacts</artifactId>
        <version>${config.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.controller</groupId>
        <artifactId>mdsal-artifacts</artifactId>
        <version>${mdsal.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.openflowplugin</groupId>
        <artifactId>openflowplugin-artifacts</artifactId>
        <version>${openflow.plugin.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.opendaylight.l2switch</groupId>
        <artifactId>l2switch-artifacts</artifactId>
        <version>${project.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>

      <dependency>
        <groupId>org.opendaylight.controller.thirdparty</groupId>
        <artifactId>net.sf.jung2</artifactId>
        <version>${jung2.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
這邊定義了l2switch需要依賴的工程:yangtools,mdsal,controller,openflowplugin,jung2......
子pom會繼承父pom中配置的所有依賴,子pom中只需配置自己特需的依賴就行了。

3.
  <build>
      <pluginManagement>
          <plugins>
              <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>${maven.compile.plugin.version}</version>
                  <configuration>
                      <source>${java.version.source}</source>
                      <target>${java.version.target}</target>
                  </configuration>
              </plugin>

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>${checkstyle.version}</version>
                <configuration>
                  <failsOnError>true</failsOnError>
                  <configLocation>controller/checkstyle.xml</configLocation>
                  <consoleOutput>true</consoleOutput>
                  <includeTestSourceDirectory>true</includeTestSourceDirectory>
                  <sourceDirectory>${project.basedir}</sourceDirectory>
                  <includes>**\/*.java,**\/*.yang,**\/*.xml,**\/*.ini,**\/*.sh,**\/*.bat</includes>
                  <excludes>**\/target\/,**\/bin\/,**\/target-ide\/,\/,**\/xtend-gen\/,**\/yang-gen-code\/,**\/${codeGeneratorPath}\/,**\/${configCodeGeneratorPath}\/,</excludes>
                </configuration>
                <dependencies>
                  <dependency>
                    <groupId>org.opendaylight.controller</groupId>
                    <artifactId>checkstyle</artifactId>
                    <version>0.3.0-SNAPSHOT</version>
                  </dependency>
                </dependencies>
                <executions>
                  <execution>
                    <id>check</id>
                    <goals>
                      <goal>check</goal>
                    </goals>
                    <phase>process-sources</phase>
                  </execution>
                </executions>
              </plugin>

              <!--  tells eclipse to import these folders into the package explorer as "source" folders
                    which allows eclipse to resolve the classes correctly during an eclipse build -->
              <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>build-helper-maven-plugin</artifactId>
                  <version>1.8</version>
                  <executions>
                      <execution>
                          <id>add-source</id>
                          <goals>
                              <goal>add-source</goal>
                          </goals>
                          <phase>generate-sources</phase>
                          <configuration>
                              <sources>
                                  <source>src/main/yang</source>
                                  <source>${codeGeneratorPath}</source>
                                  <source>${configCodeGeneratorPath}</source>
                              </sources>
                          </configuration>
                      </execution>
                  </executions>
              </plugin>
              <!--  cleans up auto generated code  -->
              <plugin>
                  <artifactId>maven-clean-plugin</artifactId>
                  <configuration>
                      <filesets>
                          <fileset>
                              <directory>${codeGeneratorPath}</directory>
                              <directory>${configCodeGeneratorPath}</directory>
                              <includes>
                                  <include>**</include>
                              </includes>
                          </fileset>
                      </filesets>
                  </configuration>
              </plugin>

              <!-- Ignore/Execute plugin execution -->
              <plugin>
                  <groupId>org.eclipse.m2e</groupId>
                  <artifactId>lifecycle-mapping</artifactId>
                  <version>1.0.0</version>
                  <configuration>
                      <lifecycleMappingMetadata>
                          <pluginExecutions>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.codehaus.mojo</groupId>
                                      <artifactId>properties-maven-plugin</artifactId>
                                      <versionRange>[0.0,)</versionRange>
                                      <goals>
                                          <goal>set-system-properties</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <ignore />
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.jacoco</groupId>
                                      <artifactId>jacoco-maven-plugin</artifactId>
                                      <versionRange>[0.0,)</versionRange>
                                      <goals>
                                          <goal>prepare-agent</goal>
                                          <goal>pre-test</goal>
                                          <goal>post-test</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <ignore />
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.ops4j.pax.exam</groupId>
                                      <artifactId>maven-paxexam-plugin</artifactId>
                                      <versionRange>[1.2.4,)</versionRange>
                                      <goals>
                                          <goal>generate-depends-file</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <execute>
                                          <runOnIncremental>false</runOnIncremental>
                                      </execute>
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.apache.maven.plugins</groupId>
                                      <artifactId>maven-checkstyle-plugin</artifactId>
                                      <versionRange>[2.0,)</versionRange>
                                      <goals>
                                          <goal>check</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <ignore />
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.opendaylight.yangtools</groupId>
                                      <artifactId>yang-maven-plugin</artifactId>
                                      <versionRange>[0.5,)</versionRange>
                                      <goals>
                                          <goal>generate-sources</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <execute />
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.codehaus.groovy.maven</groupId>
                                      <artifactId>gmaven-plugin</artifactId>
                                      <versionRange>1.0</versionRange>
                                      <goals>
                                          <goal>execute</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <ignore />
                                  </action>
                              </pluginExecution>
                              <pluginExecution>
                                  <pluginExecutionFilter>
                                      <groupId>org.apache.maven.plugins</groupId>
                                      <artifactId>maven-enforcer-plugin</artifactId>
                                      <versionRange>${enforcer.version}</versionRange>
                                      <goals>
                                          <goal>enforce</goal>
                                      </goals>
                                  </pluginExecutionFilter>
                                  <action>
                                      <ignore />
                                  </action>
                              </pluginExecution>
                          </pluginExecutions>
                      </lifecycleMappingMetadata>
                  </configuration>
              </plugin>
          </plugins>
      </pluginManagement>
      <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-checkstyle-plugin</artifactId>
          </plugin>
      </plugins>
  </build>
這一段定義了在編譯時用到的外掛。