Author: cschneider
Date: Fri Jun 15 15:45:18 2012
New Revision: 1350661

URL: http://svn.apache.org/viewvc?rev=1350661&view=rev
Log:
KARAF-1524 kar:create command to create kars from the console, small 
refactoring inside feature service

Added:
    
karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/CreateKarCommand.java
Modified:
    
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
    
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
    
karaf/trunk/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
    karaf/trunk/kar/   (props changed)
    
karaf/trunk/kar/command/src/main/resources/OSGI-INF/blueprint/kar-command.xml
    karaf/trunk/kar/core/pom.xml
    karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/KarService.java
    
karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
    
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java

Modified: 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
 (original)
+++ 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/FeaturesService.java
 Fri Jun 15 15:45:18 2012
@@ -52,6 +52,8 @@ public interface FeaturesService {
     void restoreRepository(URI uri) throws Exception;
 
     Repository[] listRepositories();
+    
+    Repository getRepository(String repoName);
 
     void installFeature(String name) throws Exception;
     

Modified: 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
 (original)
+++ 
karaf/trunk/features/core/src/main/java/org/apache/karaf/features/internal/FeaturesServiceImpl.java
 Fri Jun 15 15:45:18 2012
@@ -360,6 +360,16 @@ public class FeaturesServiceImpl impleme
         Collection<RepositoryImpl> repos = repositories.values();
         return repos.toArray(new Repository[repos.size()]);
     }
+    
+    @Override
+    public Repository getRepository(String repoName) {
+        for (Repository repo : this.repositories.values()) {
+            if (repoName.equals(repo.getName())) {
+                return repo;
+            }
+        }
+        return null;
+    }
 
     /**
      * Install a feature identified by a name.
@@ -506,10 +516,7 @@ public class FeaturesServiceImpl impleme
      * @throws Exception in case of start failure.
      */
        private void startBundle(InstallationState state, Bundle bundle) throws 
Exception {
-               // do not start fragment bundles
-               Dictionary d = bundle.getHeaders();
-               String fragmentHostHeader = (String) 
d.get(Constants.FRAGMENT_HOST);
-               if (fragmentHostHeader == null || 
fragmentHostHeader.trim().length() == 0) {
+               if (!isFragment(bundle)) {
                    // do not start bundles that are persistently stopped
                    if (state.installed.contains(bundle)
                            || (bundle.getState() != Bundle.STARTING && 
bundle.getState() != Bundle.ACTIVE
@@ -528,6 +535,13 @@ public class FeaturesServiceImpl impleme
                    }
                }
        }
+       
+       private boolean isFragment(Bundle b) {
+           @SuppressWarnings("rawtypes")
+        Dictionary d = b.getHeaders();
+        String fragmentHostHeader = (String) d.get(Constants.FRAGMENT_HOST);
+        return fragmentHostHeader != null && 
fragmentHostHeader.trim().length() > 0;
+       }
 
        private void cleanUpOnFailure(InstallationState state, 
InstallationState failure, boolean noCleanIfFailure) {
                // cleanup on error
@@ -572,11 +586,47 @@ public class FeaturesServiceImpl impleme
             System.out.println("Installing feature " + feature.getName() + " " 
+ feature.getVersion());
         }
         for (Dependency dependency : feature.getDependencies()) {
-            VersionRange range = 
org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency.getVersion())
-                        ? VersionRange.ANY_VERSION : new 
VersionRange(dependency.getVersion(), true, true);
-            Feature fi = null;
-            for (Feature f : installed.keySet()) {
-                if (f.getName().equals(dependency.getName())) {
+            installFeatureDependency(dependency, state, verbose);
+        }
+        installFeatureConfigs(feature, verbose);
+        Set<Long> bundles = new TreeSet<Long>();
+        
+        for (BundleInfo bInfo : resolve(feature)) {
+            Bundle b = installBundleIfNeeded(state, bInfo, 
feature.getStartLevel(), verbose);
+            bundles.add(b.getBundleId());
+            state.bundleInfos.put(b.getBundleId(), bInfo);
+            String region = feature.getRegion();
+            if (region != null && state.installed.contains(b)) {
+                RegionsPersistence regionsPersistence = 
getRegionsPersistence(regionsPersistenceTimeout);
+                if (regionsPersistence != null) {
+                    regionsPersistence.install(b, region);
+                } else {
+                    throw new Exception("Unable to find RegionsPersistence 
service, while installing "+ feature.getName());
+                }
+            }
+        }
+        state.features.put(feature, bundles);
+    }
+
+    private void installFeatureDependency(Dependency dependency, 
InstallationState state, boolean verbose)
+            throws Exception {
+        VersionRange range = 
org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency.getVersion())
+                    ? VersionRange.ANY_VERSION : new 
VersionRange(dependency.getVersion(), true, true);
+        Feature fi = null;
+        for (Feature f : installed.keySet()) {
+            if (f.getName().equals(dependency.getName())) {
+                Version v = VersionTable.getVersion(f.getVersion());
+                if (range.contains(v)) {
+                    if (fi == null || 
VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0) {
+                        fi = f;
+                    }
+                }
+            }
+        }
+        if (fi == null) {
+            Map<String, Feature> avail = 
getFeatures().get(dependency.getName());
+            if (avail != null) {
+                for (Feature f : avail.values()) {
                     Version v = VersionTable.getVersion(f.getVersion());
                     if (range.contains(v)) {
                         if (fi == null || 
VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0) {
@@ -585,25 +635,15 @@ public class FeaturesServiceImpl impleme
                     }
                 }
             }
-            if (fi == null) {
-                Map<String, Feature> avail = 
getFeatures().get(dependency.getName());
-                if (avail != null) {
-                    for (Feature f : avail.values()) {
-                        Version v = VersionTable.getVersion(f.getVersion());
-                        if (range.contains(v)) {
-                            if (fi == null || 
VersionTable.getVersion(fi.getVersion()).compareTo(v) < 0) {
-                                fi = f;
-                            }
-                        }
-                    }
-                }
-            }
-            if (fi == null) {
-                throw new Exception("No feature named '" + dependency.getName()
-                        + "' with version '" + dependency.getVersion() + "' 
available");
-            }
-            doInstallFeature(state, fi, verbose);
         }
+        if (fi == null) {
+            throw new Exception("No feature named '" + dependency.getName()
+                    + "' with version '" + dependency.getVersion() + "' 
available");
+        }
+        doInstallFeature(state, fi, verbose);
+    }
+    
+    private void installFeatureConfigs(Feature feature, boolean verbose) 
throws IOException, InvalidSyntaxException {
         for (String config : feature.getConfigurations().keySet()) {
             Dictionary<String,String> props = new Hashtable<String, 
String>(feature.getConfigurations().get(config));
             String[] pid = parsePid(config);
@@ -619,26 +659,8 @@ public class FeaturesServiceImpl impleme
             }
         }
         for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
-               installConfigurationFile(configFile.getLocation(), 
configFile.getFinalname(), configFile.isOverride()
-                               ,verbose);
-        }
-        Set<Long> bundles = new TreeSet<Long>();
-        String region = feature.getRegion();
-
-        for (BundleInfo bInfo : resolve(feature)) {
-            Bundle b = installBundleIfNeeded(state, bInfo, 
feature.getStartLevel(), verbose);
-            bundles.add(b.getBundleId());
-            state.bundleInfos.put(b.getBundleId(), bInfo);
-            if (region != null && state.installed.contains(b)) {
-                RegionsPersistence regionsPersistence = 
getRegionsPersistence(regionsPersistenceTimeout);
-                if (regionsPersistence != null) {
-                    regionsPersistence.install(b, region);
-                } else {
-                    throw new Exception("Unable to find RegionsPersistence 
service, while installing "+ feature.getName());
-                }
-            }
+            installConfigurationFile(configFile.getLocation(), 
configFile.getFinalname(), configFile.isOverride(), verbose);
         }
-        state.features.put(feature, bundles);
     }
 
     private String createConfigurationKey(String pid, String factoryPid) {
@@ -658,6 +680,7 @@ public class FeaturesServiceImpl impleme
         }
         // Else, find the resolver
         String filter = "(&(" + Constants.OBJECTCLASS + "=" + 
Resolver.class.getName() + ")(name=" + resolver + "))";
+        @SuppressWarnings({ "rawtypes", "unchecked" })
         ServiceTracker tracker = new ServiceTracker(bundleContext, 
FrameworkUtil.createFilter(filter), null);
         tracker.open();
         try {
@@ -1296,7 +1319,7 @@ public class FeaturesServiceImpl impleme
 
     protected Map<Feature, Set<Long>> loadMap(Properties props, String prefix) 
{
         Map<Feature, Set<Long>> map = new HashMap<Feature, Set<Long>>();
-        for (Enumeration e = props.propertyNames(); e.hasMoreElements();) {
+        for (@SuppressWarnings("rawtypes") Enumeration e = 
props.propertyNames(); e.hasMoreElements();) {
             String key = (String) e.nextElement();
             if (key.startsWith(prefix)) {
                 String val = (String) props.get(key);

Modified: 
karaf/trunk/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
 (original)
+++ 
karaf/trunk/features/core/src/test/java/org/apache/karaf/features/FeaturesServiceTest.java
 Fri Jun 15 15:45:18 2012
@@ -517,8 +517,15 @@ public class FeaturesServiceTest extends
         pw.close();
 
         URI uri = tmp.toURI();
+        
+        BundleContext bundleContext = EasyMock.createMock(BundleContext.class);
+        
+        bundleContext.getDataFile((String) EasyMock.anyObject());
+        EasyMock.expectLastCall().andReturn(File.createTempFile("test", 
"test")); 
+        EasyMock.replay(bundleContext);
 
         FeaturesServiceImpl svc = new FeaturesServiceImpl();
+        svc.setBundleContext(bundleContext);
         svc.addRepository(uri);
 
         Feature feature = svc.getFeature("f2", "[0.1,0.3)");

Propchange: karaf/trunk/kar/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Fri Jun 15 15:45:18 2012
@@ -1,3 +1,5 @@
 target
 
 *.iml
+.project
+.settings

Added: 
karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/CreateKarCommand.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/CreateKarCommand.java?rev=1350661&view=auto
==============================================================================
--- 
karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/CreateKarCommand.java
 (added)
+++ 
karaf/trunk/kar/command/src/main/java/org/apache/karaf/kar/command/CreateKarCommand.java
 Fri Jun 15 15:45:18 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.karaf.kar.command;
+
+import java.util.Set;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "kar", name = "create", description = "Create a kar file for 
a list of feature repos")
+public class CreateKarCommand extends KarCommandSupport {
+    
+    @Argument(index = 0, name = "repoName", description = "Repository name. 
The kar will contain all features of the named repository by default", required 
= true, multiValued = false)
+    private String repoName;
+    
+    @Argument(index = 1, name = "features", description = "Names of the 
features to include. If set then only these features will be added", required = 
false, multiValued = false)
+    private Set<String> features;
+    
+    public Object doExecute() throws Exception {
+        this.getKarService().create(repoName, features, System.out);
+        return null;
+    }
+    
+}

Modified: 
karaf/trunk/kar/command/src/main/resources/OSGI-INF/blueprint/kar-command.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/kar/command/src/main/resources/OSGI-INF/blueprint/kar-command.xml?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/kar/command/src/main/resources/OSGI-INF/blueprint/kar-command.xml 
(original)
+++ 
karaf/trunk/kar/command/src/main/resources/OSGI-INF/blueprint/kar-command.xml 
Fri Jun 15 15:45:18 2012
@@ -36,6 +36,11 @@
                 <ref component-id="karCompleter"/>
             </completers>
         </command>
+        <command>
+            <action class="org.apache.karaf.kar.command.CreateKarCommand">
+                <property name="karService" ref="karService"/>
+            </action>
+        </command>
     </command-bundle>
 
     <reference id="karService" interface="org.apache.karaf.kar.KarService"/>

Modified: karaf/trunk/kar/core/pom.xml
URL: 
http://svn.apache.org/viewvc/karaf/trunk/kar/core/pom.xml?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- karaf/trunk/kar/core/pom.xml (original)
+++ karaf/trunk/kar/core/pom.xml Fri Jun 15 15:45:18 2012
@@ -39,6 +39,10 @@
 
     <dependencies>
         <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-aether</artifactId>
+        </dependency>
+        <dependency>
             <groupId>org.apache.karaf.features</groupId>
             <artifactId>org.apache.karaf.features.core</artifactId>
             <scope>provided</scope>

Modified: 
karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/KarService.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/KarService.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/KarService.java 
(original)
+++ karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/KarService.java Fri 
Jun 15 15:45:18 2012
@@ -16,8 +16,10 @@
  */
 package org.apache.karaf.kar;
 
+import java.io.PrintStream;
 import java.net.URI;
 import java.util.List;
+import java.util.Set;
 
 /**
  * The service managing KAR.
@@ -58,4 +60,15 @@ public interface KarService {
      */
     List<String> list() throws Exception;
     
+    /**
+     * Create a kar from the given feature and repo names.
+     * Each named feature including all transitive deps will be added.
+     * For each named repo all features in the repo and their transitive deps 
will be added.
+     * 
+     * @param repoName
+     * @param features 
+     * @param console
+     */
+    void create(String repoName, Set<String> features, PrintStream console);
+    
 }

Modified: 
karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
 (original)
+++ 
karaf/trunk/kar/core/src/main/java/org/apache/karaf/kar/internal/KarServiceImpl.java
 Fri Jun 15 15:45:18 2012
@@ -18,35 +18,52 @@
  */
 package org.apache.karaf.kar.internal;
 
-import org.apache.karaf.features.Feature;
-import org.apache.karaf.features.FeaturesService;
-import org.apache.karaf.features.Repository;
-import org.apache.karaf.kar.KarService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.xml.sax.ErrorHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.karaf.features.BundleInfo;
+import org.apache.karaf.features.ConfigFileInfo;
+import org.apache.karaf.features.Feature;
+import org.apache.karaf.features.FeaturesService;
+import org.apache.karaf.features.Repository;
+import org.apache.karaf.kar.KarService;
+import org.ops4j.pax.url.mvn.Parser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
 /**
  * Implementation of the KAR service.
  */
 public class KarServiceImpl implements KarService {
 
+    private static final String MANIFEST_ATTR_KARAF_FEATURE_START = 
"Karaf-Feature-Start";
+
     public static final Logger LOGGER = 
LoggerFactory.getLogger(KarServiceImpl.class);
 
     private String storage = "./target/data/kar"; // ${KARAF.DATA}/kar
@@ -97,6 +114,7 @@ public class KarServiceImpl implements K
         
         List<URI> featuresRepositoriesInKar = new ArrayList<URI>();
         
+        @SuppressWarnings("unchecked")
         Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) 
zipFile.entries();
         while (entries.hasMoreElements()) {
             ZipEntry entry = entries.nextElement();
@@ -110,6 +128,7 @@ public class KarServiceImpl implements K
                     featuresRepositoriesInKar.add(extract.toURI());
                 }
             }
+
             if (entry.getName().startsWith("resource")) {
                 String resourceEntryName = 
entry.getName().substring("resource/".length());
                 extract(zipFile, entry, resourceEntryName, base);
@@ -137,6 +156,7 @@ public class KarServiceImpl implements K
             LOGGER.debug("Looking for KAR entries to purge the local 
repository");
             List<URI> featuresRepositories = new ArrayList<URI>();
             ZipFile zipFile = new ZipFile(karFile);
+            @SuppressWarnings("unchecked")
             Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) 
zipFile.entries();
             while (entries.hasMoreElements()) {
                 ZipEntry entry = entries.nextElement();
@@ -196,12 +216,7 @@ public class KarServiceImpl implements K
         try {
             is = url.toURL().openStream();
             fos = new FileOutputStream(file);
-            byte[] buffer = new byte[8192];
-            int count = is.read(buffer);
-            while (count >= 0) {
-                fos.write(buffer, 0, count);
-                count = is.read(buffer);
-            }
+            copyStream(is,  fos);
         } finally {
             if (is != null) {
                 is.close();
@@ -355,6 +370,92 @@ public class KarServiceImpl implements K
             }
         }
     }
+    
+    @Override
+    public void create(String repoName, Set<String> features, PrintStream 
console) {
+        FileOutputStream fos = null;
+        JarOutputStream jos = null;
+        try {
+            String karPath = base + File.separator + "data" + File.separator + 
"kar" + File.separator + repoName + ".kar";
+            File karFile = new File(karPath);
+            karFile.getParentFile().mkdirs();
+            fos = new FileOutputStream(karFile);
+            String manifestSt = "Manifest-Version: 1.0\n" +
+                MANIFEST_ATTR_KARAF_FEATURE_START +": true\n";
+            InputStream manifestIs = new 
ByteArrayInputStream(manifestSt.getBytes("UTF-8"));
+            Manifest manifest = new Manifest(manifestIs);
+            jos = new JarOutputStream(new BufferedOutputStream(fos, 100000), 
manifest);
+            
+            Map<URI, Integer> locationMap = new HashMap<URI, Integer>();
+
+            Repository repo = featuresService.getRepository(repoName);
+            copyResourceToJar(jos, repo.getURI(), locationMap, console);
+            
+            for (Feature feature : repo.getFeatures()) {
+                List<BundleInfo> bundles = feature.getBundles();
+                for (BundleInfo bundleInfo : bundles) {
+                    URI location = new URI(bundleInfo.getLocation());
+                    copyResourceToJar(jos, location, locationMap, console);
+                }
+                List<ConfigFileInfo> configFiles = 
feature.getConfigurationFiles();
+                for (ConfigFileInfo configFileInfo : configFiles) {
+                    URI location = new URI(configFileInfo.getLocation());
+                    copyResourceToJar(jos, location, locationMap, console);
+                }
+            }
+            
+            console.println("Kar file created : " + karPath);
+        } catch (Exception e) {
+            throw new RuntimeException("Error creating kar " + e.getMessage(), 
e);
+        } finally {
+            if (jos != null) {
+                try {
+                    jos.close();
+                } catch (IOException e) {
+                    LOGGER.warn("Error closing jar stream", e);
+                }
+            }
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    LOGGER.warn("Error closing jar file stream", e);
+                }
+            }
+        }
+        
+    }
+
+    private void copyResourceToJar(JarOutputStream jos, URI location, Map<URI, 
Integer> locationMap, PrintStream console) {
+        if (locationMap.containsKey(location)) {
+            return;
+        }
+        try {
+            console.println("Adding " + location);
+            String noPrefixLocation = 
location.toString().substring(location.toString().lastIndexOf(":") + 1);
+            Parser parser = new Parser(noPrefixLocation);
+            InputStream is = location.toURL().openStream();
+            String path = "repository/" + parser.getArtifactPath();
+            jos.putNextEntry(new JarEntry(path));
+            copyStream(is, jos);
+            is.close();
+            locationMap.put(location, 1);
+        } catch (Exception e) {
+            LOGGER.error("Error adding " + location, e);
+        }
+    }
+    
+    public static long copyStream(InputStream input, OutputStream output)
+            throws IOException {
+        byte[] buffer = new byte[10000];
+        long count = 0;
+        int n = 0;
+        while (-1 != (n = input.read(buffer))) {
+            output.write(buffer, 0, n);
+            count += n;
+        }
+        return count;
+    }
 
     /**
      * Uninstall all features contained in the list of features XML.

Modified: 
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
URL: 
http://svn.apache.org/viewvc/karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java?rev=1350661&r1=1350660&r2=1350661&view=diff
==============================================================================
--- 
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
 (original)
+++ 
karaf/trunk/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/InstallKarsMojo.java
 Fri Jun 15 15:45:18 2012
@@ -545,6 +545,12 @@ public class InstallKarsMojo extends Moj
         public org.apache.karaf.features.Feature getFeature(String name) 
throws Exception {
             return null;
         }
+
+        @Override
+        public Repository getRepository(String repoName) {
+            // TODO Auto-generated method stub
+            return null;
+        }
     }
 
     // when FELIX-2887 is ready we can use plain Properties again


Reply via email to