use maven instead of vicci for offline karaf

- pom.xml to create offline karaf tarballs
- download offline karaf tarball from maven to benefit from CDN
   buck's MavenUrlDecoder currently has issue handling non-jar type
   in maven coordinate

Change-Id: Id25e286ec87426814002ed6d8cca6e66a4b80110
diff --git a/lib/BUCK b/lib/BUCK
index 4d53ed0..d36cfe7 100644
--- a/lib/BUCK
+++ b/lib/BUCK
@@ -1,4 +1,4 @@
-# ***** This file was auto-generated at Mon, 18 Dec 2017 23:41:30 GMT. Do not edit this file manually. *****
+# ***** This file was auto-generated at Tue, 19 Dec 2017 23:17:29 GMT. Do not edit this file manually. *****
 # ***** Use onos-lib-gen *****
 
 pass_thru_pom(
@@ -1143,9 +1143,9 @@
 
 remote_file (
   name = 'apache-karaf',
-  out = 'apache-karaf-3.0.8-offline-20170825.tar.gz',
-  url = 'http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.8-offline-20170825.tar.gz',
-  sha1 = '4d9b5c69aba48854744aa4aee5431930c1271c59',
+  out = 'apache-karaf-offline-3.0.8.tar.gz',
+  url = 'https://repo1.maven.org/maven2/org/onosproject/apache-karaf-offline/3.0.8/apache-karaf-offline-3.0.8.tar.gz',
+  sha1 = '2503c5853285e3414da15aef8d8f3f629747c927',
   visibility = [ 'PUBLIC' ],
 )
 
diff --git a/lib/deps.json b/lib/deps.json
index aa46009..4a8c5dd 100644
--- a/lib/deps.json
+++ b/lib/deps.json
@@ -220,7 +220,9 @@
     "typesafe-config": "mvn:com.typesafe:config:1.2.1",
     "validation-api": "mvn:javax.validation:validation-api:1.1.0.Final",
     "checkstyle": "mvn:com.puppycrawl.tools:checkstyle:6.19",
-    "apache-karaf": "http://onlab.vicci.org/onos/third-party/apache-karaf-3.0.8-offline-20170825.tar.gz",
+    // buck's MavenUrlDecoder cannot handle tar.gz type
+    //"apache-karaf": "mvn:org.onosproject:apache-karaf-offline:tar.gz:3.0.8",
+    "apache-karaf": "https://repo1.maven.org/maven2/org/onosproject/apache-karaf-offline/3.0.8/apache-karaf-offline-3.0.8.tar.gz",
     "bndlib": "mvn:biz.aQute.bnd:biz.aQute.bndlib:jar:3.1.0",
     "bndexe": "mvn:biz.aQute.bnd:biz.aQute.bnd:3.1.0",
     "libthrift": "mvn:org.apache.thrift:libthrift:0.9.3",
diff --git a/tools/build/libgen/src/main/java/org/onosproject/libgen/AetherResolver.java b/tools/build/libgen/src/main/java/org/onosproject/libgen/AetherResolver.java
index 132cc13..1850779 100644
--- a/tools/build/libgen/src/main/java/org/onosproject/libgen/AetherResolver.java
+++ b/tools/build/libgen/src/main/java/org/onosproject/libgen/AetherResolver.java
@@ -39,6 +39,7 @@
 
 import java.io.BufferedReader;
 import java.io.FileReader;
+import java.io.IOException;
 import java.io.Reader;
 import java.nio.file.Paths;
 import java.util.Arrays;
@@ -142,6 +143,9 @@
             Attributes attrs = jar.getManifest().getMainAttributes();
             return attrs.getValue("Bundle-SymbolicName") != null &&
                     attrs.getValue("Bundle-Version") != null;
+        } catch (IOException e) {
+            // wasn't jar
+            return false;
         }
     }
 
diff --git a/tools/package/karaf-offline/pom.xml b/tools/package/karaf-offline/pom.xml
new file mode 100644
index 0000000..b37022b
--- /dev/null
+++ b/tools/package/karaf-offline/pom.xml
@@ -0,0 +1,211 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>org.onosproject</groupId>
+    <artifactId>apache-karaf-offline</artifactId>
+    <version>3.0.8</version>
+    <name>${project.artifactId}</name>
+    <description>Maven POM for Offline Karaf server</description>
+    <packaging>karaf-assembly</packaging>
+
+    <!-- based on https://github.com/juttayaya/karaf/tree/master/karaf3/offline-karaf-->
+    <url>http://onosproject.org/</url>
+
+    <scm>
+        <connection>scm:git:https://gerrit.onosproject.org/onos</connection>
+        <developerConnection>scm:git:https://gerrit.onosproject.org/onos
+        </developerConnection>
+        <url>http://gerrit.onosproject.org/</url>
+    </scm>
+
+    <licenses>
+        <license>
+            <name>Apache License, Version 2.0</name>
+            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
+        </license>
+    </licenses>
+
+    <developers>
+        <developer>
+            <organization>Open Networking Lab</organization>
+            <url>http://onlab.us</url>
+        </developer>
+    </developers>
+
+    <properties>
+        <karaf.version>3.0.8</karaf.version>
+        <!-- maven-compiler-plugin setting.
+             Karaf 3 runs on Java 7 or later -->
+        <!-- Specific Maven Plugin Versions -->
+        <!-- Karaf Maven Plugin does not have to be same as Karaf Server version
+             For example, Karaf Maven Plugin 3.0.2 has bug uploading to password protected Nexus Repo
+             So I used Karaf Maven Plugin 3.0.3 to build a Karaf 3.0.2 Server -->
+        <karaf.plugin.version>${karaf.version}</karaf.plugin.version>
+    </properties>
+
+    <distributionManagement>
+        <snapshotRepository>
+            <id>ossrh</id>
+            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
+        </snapshotRepository>
+        <repository>
+          <id>ossrh</id>
+          <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+        </repository>
+    </distributionManagement>
+
+    <dependencyManagement>
+        <!-- Import Karaf POM to use the correct version of the Karaf dependencies -->
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.karaf</groupId>
+                <artifactId>karaf</artifactId>
+                <version>${karaf.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+    <dependencies>
+        <dependency>
+            <!-- scope is compile so all features (there is only one) are installed into startup.properties and
+                 the feature repo itself is not added in etc/org.apache.karaf.features.cfg file -->
+            <groupId>org.apache.karaf.features</groupId>
+            <artifactId>framework</artifactId>
+            <type>kar</type>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <!-- Scope is runtime so the feature repo is listed in etc/org.apache.karaf.features.cfg file,
+                 and features will installed into the system directory.
+
+                 This imports the standard Karaf features described at
+                 https://repo1.maven.org/maven2/org/apache/karaf/features/standard/3.0.4/standard-3.0.4-features.xml
+                 These features are installed in the karaf-maven-plugin configuration
+            -->
+            <groupId>org.apache.karaf.features</groupId>
+            <artifactId>standard</artifactId>
+            <classifier>features</classifier>
+            <type>xml</type>
+            <scope>runtime</scope>
+        </dependency>
+        <!-- https://repo1.maven.org/maven2/org/apache/camel/karaf/apache-camel/2.15.2/apache-camel-2.15.2-features.xml -->
+        <!-- <dependency>
+            <groupId>org.apache.camel.karaf</groupId>
+            <artifactId>apache-camel</artifactId>
+            <version>${camel.version}</version>
+            <classifier>features</classifier>
+            <type>xml</type>
+            <scope>runtime</scope>
+        </dependency> -->
+        <!-- https://repo1.maven.org/maven2/org/apache/karaf/features/spring/3.0.4/spring-3.0.4-features.xml
+             Needed for Camel feature dependency
+        -->
+        <!-- <dependency>
+            <groupId>org.apache.karaf.features</groupId>
+            <artifactId>spring</artifactId>
+            <version>${karaf.version}</version>
+            <classifier>features</classifier>
+            <type>xml</type>
+            <scope>runtime</scope>
+        </dependency> -->
+    </dependencies>
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.karaf.tooling</groupId>
+                <artifactId>karaf-maven-plugin</artifactId>
+                <!-- Plugin requires at minimum 3.0.3 version for dependency=true bug fix
+                     https://issues.apache.org/jira/browse/KARAF-2596 -->
+                <version>${karaf.plugin.version}</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <karafVersion>${karaf.version}</karafVersion>
+                    <!-- ignoreDependencyFlag is true forces plugin to also
+                         download feature dependent libraries -->
+                    <ignoreDependencyFlag>true</ignoreDependencyFlag>
+                    <!-- bootFeatures starts up these features when Karaf first boots up.
+                         The feature names are obtained from the features.xml in the
+                         dependencies section
+                     -->
+                    <bootFeatures>
+                        <feature>standard</feature>
+                        <feature>ssh</feature>
+                        <feature>scr</feature>
+                        <feature>war</feature>
+                        <feature>webconsole</feature>
+                    </bootFeatures>
+                    <!-- installedFeatures only installs the libraries in the ${KARAF_HOME}/system directory
+                         but the user will have to start it up manually via Karaf command line feature:install
+                    -->
+                    <installedFeatures>
+                        <!-- <feature>jndi</feature> -->
+                    </installedFeatures>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <!-- <executions>
+                    <execution>
+                        <id>copy</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>copy</goal>
+                        </goals>
+                        <configuration>
+                            <artifactItems>
+                                <artifactItem>
+                                    <groupId>org.apache.karaf.jaas</groupId>
+                                    <artifactId>org.apache.karaf.jaas.boot</artifactId>
+                                    <version>${karaf.version}</version>
+                                    <outputDirectory>target/assembly/system/org/apache/karaf/jaas/org.apache.karaf.jaas.boot</outputDirectory>
+                                </artifactItem>
+                            </artifactItems>
+                        </configuration>
+                    </execution>
+                </executions> -->
+            </plugin>
+
+            <plugin>
+              <groupId>org.sonatype.plugins</groupId>
+              <artifactId>nexus-staging-maven-plugin</artifactId>
+              <version>1.6.8</version>
+              <extensions>true</extensions>
+              <configuration>
+                <serverId>ossrh</serverId>
+                <nexusUrl>https://oss.sonatype.org/</nexusUrl>
+                <autoReleaseAfterClose>true</autoReleaseAfterClose>
+              </configuration>
+            </plugin>
+
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-gpg-plugin</artifactId>
+              <version>1.6</version>
+              <executions>
+                <execution>
+                  <id>sign-artifacts</id>
+                  <phase>verify</phase>
+                  <goals>
+                    <goal>sign</goal>
+                  </goals>
+                </execution>
+              </executions>
+            </plugin>
+
+        </plugins>
+    </build>
+    <repositories>
+        <!-- This is the repository location of org.eclipse.equinox:region:jar:1.0.0.v20110506
+             for the "region" Karaf feature
+         -->
+        <!-- <repository>
+            <id>servicemix</id>
+            <name>ServiceMix Repo for Karaf</name>
+            <url>http://svn.apache.org/repos/asf/servicemix/m2-repo</url>
+        </repository> -->
+    </repositories>
+</project>
diff --git a/tools/package/onos-prep-karaf b/tools/package/onos-prep-karaf
index ed89fb2..718630c 100755
--- a/tools/package/onos-prep-karaf
+++ b/tools/package/onos-prep-karaf
@@ -18,6 +18,9 @@
 # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
 tar xf $KARAF_TAR
 
+# rename path name to match what was distributed with vicci
+mv "$(ls -d apache*)" "apache-karaf-$KARAF_VERSION" || true
+
 # Unroll the Apache Karaf bits, prune them and make ONOS top-level directories.
 KARAF_DIR=$(ls -d apache*)
 rm -rf $KARAF_DIR/demos
@@ -38,7 +41,7 @@
     $KARAF_DIR/etc/org.apache.karaf.features.cfg
 
 # Patch the Apache Karaf distribution file to load default ONOS boot features
-perl -pi.old -e "s|^(featuresBoot=).*|\1$BOOT_FEATURES|" \
+perl -pi.old -e "s|^(featuresBoot ?= ?).*|\1$BOOT_FEATURES|" \
     $KARAF_DIR/etc/org.apache.karaf.features.cfg