karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5810) No config file installed in custom distribution.
Date Fri, 03 Aug 2018 07:53:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5810?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16567914#comment-16567914
] 

ASF GitHub Bot commented on KARAF-5810:
---------------------------------------

jbonofre closed pull request #553: [KARAF-5810] No config file installed in custom distribution.
(On master)
URL: https://github.com/apache/karaf/pull/553
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java
b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java
index ba2ffedf43..ccbd1d34d6 100644
--- a/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java
+++ b/features/core/src/main/java/org/apache/karaf/features/internal/download/impl/DownloadManagerHelper.java
@@ -77,4 +77,14 @@ public static String removeInlinedMavenRepositoryUrl(String url) {
         }
         return url;
     }
+
+    /**
+     * Remove the tailing '/' of bad formed URL (like in Camel for mustache-compiler).
+     *
+     * @param url the given URL.
+     * @return the stripped URL.
+     */
+    public static String removeTrailingSlash(String url) {
+        return url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
+    }
 }
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/ArtifactInstaller.java
b/profile/src/main/java/org/apache/karaf/profile/assembly/ArtifactInstaller.java
index f1b280fa9d..a30ef59f3a 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/ArtifactInstaller.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/ArtifactInstaller.java
@@ -30,6 +30,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.karaf.features.internal.download.impl.DownloadManagerHelper.removeTrailingSlash;
 import static org.apache.karaf.features.internal.download.impl.DownloadManagerHelper.stripUrl;
 
 /**
@@ -73,7 +74,6 @@ public void installArtifact(BundleInfo bundle) throws Exception {
         }
         final String finalLocation = location;
         downloader.download(location, provider -> {
-            String uri = provider.getUrl();
             Path path = pathFromProviderUrl(systemDirectory, finalLocation);
             synchronized (provider) {
                 Files.createDirectories(path.getParent());
@@ -97,7 +97,6 @@ public void installArtifact(String location) throws Exception {
         }
         final String finalLocation = location;
         downloader.download(location, provider -> {
-            String uri = provider.getUrl();
             if (blacklist.isBundleBlacklisted(finalLocation)) {
                 throw new RuntimeException("Bundle " + finalLocation + " is blacklisted");
             }
@@ -109,13 +108,6 @@ public void installArtifact(String location) throws Exception {
         });
     }
 
-    /**
-     * for bad formed URL (like in Camel for mustache-compiler), we remove the trailing /
-     */
-    private String removeTrailingSlash(String location) {
-        return location.endsWith("/") ? location.substring(0, location.length() - 1) : location;
-    }
-    
     public static Path pathFromProviderUrl(Path systemDirectory, String url) throws MalformedURLException
{
         String pathString;
         if (url.startsWith("file:")) {
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
index 8e403f7ddd..22ad104196 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/Builder.java
@@ -1655,7 +1655,7 @@ private void installStage(Profile installedProfile, Set<Feature>
allBootFeatures
                 }
             }
 
-            new ConfigInstaller(etcDirectory, pidsToExtract)
+            new ConfigInstaller(homeDirectory, etcDirectory, pidsToExtract)
                 .installConfigs(feature, downloader, installer);
             // Install libraries
             List<String> libraries = new ArrayList<>();
diff --git a/profile/src/main/java/org/apache/karaf/profile/assembly/ConfigInstaller.java
b/profile/src/main/java/org/apache/karaf/profile/assembly/ConfigInstaller.java
index df928f5851..d40cc9e5ce 100644
--- a/profile/src/main/java/org/apache/karaf/profile/assembly/ConfigInstaller.java
+++ b/profile/src/main/java/org/apache/karaf/profile/assembly/ConfigInstaller.java
@@ -16,6 +16,9 @@
  */
 package org.apache.karaf.profile.assembly;
 
+import static org.apache.karaf.features.internal.download.impl.DownloadManagerHelper.removeTrailingSlash;
+import static org.apache.karaf.features.internal.download.impl.DownloadManagerHelper.stripUrl;
+
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
@@ -24,6 +27,7 @@
 import java.util.List;
 import java.util.regex.Pattern;
 
+import org.apache.commons.io.FilenameUtils;
 import org.apache.karaf.features.internal.download.Downloader;
 import org.apache.karaf.features.internal.model.Config;
 import org.apache.karaf.features.internal.model.ConfigFile;
@@ -38,9 +42,11 @@
 public class ConfigInstaller {
     private static final Logger LOGGER = LoggerFactory.getLogger(ConfigInstaller.class);
     private Path etcDirectory;
+    private Path baseDirectory;
     private List<String> pidsToExtract;
-    
-    public ConfigInstaller(Path etcDirectory, List<String> pidsToExtract) {
+
+    public ConfigInstaller(Path baseDirectory, Path etcDirectory, List<String> pidsToExtract)
{
+        this.baseDirectory = baseDirectory;
         this.etcDirectory = etcDirectory;
         this.pidsToExtract = pidsToExtract;
     }
@@ -93,7 +99,55 @@ public void installConfigs(Feature feature, Downloader downloader, ArtifactInsta
                     }
                 }
             }
+            for (ConfigFile configFile : content.getConfigfile()) {
+                if (pidMatching(FilenameUtils.getBaseName(configFile.getFinalname()))) {
+                    installConfigFile(downloader, configFile);
+                }
+            }
+        }
+    }
+
+    private void installConfigFile(Downloader downloader, ConfigFile configFile) throws Exception
{
+        String path = configFile.getFinalname();
+        if (path.startsWith("/")) {
+            path = path.substring(1);
+        }
+
+        Path configFileTarget = baseDirectory.resolve(substFinalName(path));
+        LOGGER.info("      adding config file: {}", baseDirectory.relativize(configFileTarget));
+
+        String location = removeTrailingSlash(stripUrl(configFile.getLocation().trim()));
+        if (!location.startsWith("mvn:")) {
+            LOGGER.warn("Ignoring non maven artifact " + location);
+            return;
+        }
+
+        downloader.download(location, provider -> {
+            synchronized (provider) {
+                Files.createDirectories(configFileTarget.getParent());
+                Files.copy(provider.getFile().toPath(), configFileTarget, StandardCopyOption.REPLACE_EXISTING);
+            }
+        });
+    }
+
+    private String substFinalName(String finalname) {
+        final String markerVarBeg = "${";
+        final String markerVarEnd = "}";
+
+        boolean startsWithVariable = finalname.startsWith(markerVarBeg) && finalname.contains(markerVarEnd);
+        if (startsWithVariable) {
+            String marker = finalname.substring(markerVarBeg.length(), finalname.indexOf(markerVarEnd));
+            switch (marker) {
+                case "karaf.home":
+                case "karaf.base":
+                    return this.baseDirectory + finalname.substring(finalname.indexOf(markerVarEnd)
+ markerVarEnd.length());
+                case "karaf.etc":
+                    return this.etcDirectory + finalname.substring(finalname.indexOf(markerVarEnd)
+ markerVarEnd.length());
+                default:
+                    break;
+            }
         }
+        return finalname;
     }
 
     private boolean pidMatching(String name) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> No config file installed in custom distribution.
> ------------------------------------------------
>
>                 Key: KARAF-5810
>                 URL: https://issues.apache.org/jira/browse/KARAF-5810
>             Project: Karaf
>          Issue Type: Bug
>          Components: karaf-tooling
>    Affects Versions: 4.1.5, 4.2.0.M2
>            Reporter: svs
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>              Labels: maven
>
> Configuration files (<configfile finalname=mvn ..../>) specified in the feature
file are not installed when a custom distribution is created.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Mime
View raw message