You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:16:24 UTC
[sling-maven-sling-plugin] 11/28: SLING-798 : Get available
configurations from web console before creating configs
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to annotated tag maven-sling-plugin-2.0.4-incubator
in repository https://gitbox.apache.org/repos/asf/sling-maven-sling-plugin.git
commit 8db8a257cf928f4d3a19251f931745ff3578f2c2
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Wed Jan 14 21:09:21 2009 +0000
SLING-798 : Get available configurations from web console before creating configs
git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/maven/maven-sling-plugin@734513 13f79535-47bb-0310-9956-ffa450edef68
---
.../bundlesupport/AbstractBundleInstallMojo.java | 64 +++++++++++++++++++++-
1 file changed, 61 insertions(+), 3 deletions(-)
diff --git a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
index 5da5bfe..bbf4e12 100644
--- a/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
+++ b/src/main/java/org/apache/sling/maven/bundlesupport/AbstractBundleInstallMojo.java
@@ -21,8 +21,10 @@ package org.apache.sling.maven.bundlesupport;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -32,6 +34,7 @@ import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.FilePartSource;
@@ -41,6 +44,9 @@ import org.apache.commons.httpclient.methods.multipart.StringPart;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
+import org.apache.sling.commons.json.JSONArray;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.osgi.ManifestHeader;
import org.apache.sling.commons.osgi.ManifestHeader.Entry;
@@ -137,9 +143,9 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
getLog().info(
"Installing Bundle " + bundleName + "(" + bundleFile + ") to "
+ slingUrl);
- configure(slingUrl, bundleFile);
+ post(slingUrl, bundleFile);
if ( mountByFS ) {
- post(slingUrl, bundleFile);
+ configure(slingUrl, bundleFile);
}
}
@@ -221,7 +227,7 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
// authentication stuff
client.getParams().setAuthenticationPreemptive(true);
- Credentials defaultcreds = new UsernamePasswordCredentials(user,
+ final Credentials defaultcreds = new UsernamePasswordCredentials(user,
password);
client.getState().setCredentials(AuthScope.ANY, defaultcreds);
@@ -231,6 +237,13 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
if ( resources == null || resources.size() == 0 ) {
throw new MojoExecutionException("No resources configured for this project.");
}
+ // now get current configurations
+ final Map configs = this.getCurrentFileProviderConfigs(targetURL, client);
+ final Iterator configIter = configs.keySet().iterator();
+ while ( configIter.hasNext() ) {
+ final String key = configIter.next().toString();
+ getLog().info("Found " + key + " : " + configs.get(key));
+ }
final Entry[] entries = header.getEntries();
for(final Entry entry : entries) {
final String path = entry.getValue();
@@ -292,6 +305,51 @@ abstract class AbstractBundleInstallMojo extends AbstractBundlePostMojo {
}
/**
+ * Return all file provider configs for this project
+ * @param targetURL The targetURL of the webconsole
+ * @param client The http client
+ * @return A map (may be empty) with the pids as keys and the path as value
+ * @throws MojoExecutionException
+ */
+ protected Map getCurrentFileProviderConfigs(final String targetURL, final HttpClient client)
+ throws MojoExecutionException {
+ getLog().debug("Getting current file provider configurations.");
+ final Map result = new HashMap();
+ final String getUrl = targetURL + "/configMgr/(service.factoryPid=" + FS_FACTORY + ").json";
+ final GetMethod get = new GetMethod(getUrl);
+
+ try {
+ final int status = client.executeMethod(get);
+ if ( status == 200 )
+ {
+ final String jsonText = get.getResponseBodyAsString();
+ try {
+ JSONArray array = new JSONArray(jsonText);
+ for(int i=0; i<array.length(); i++) {
+ final JSONObject obj = array.getJSONObject(i);
+ final String pid = obj.getString("pid");
+ final String path = obj.getJSONObject("provider.file").getString("value");
+ if ( path != null && path.startsWith(this.project.getBasedir().getAbsolutePath()) ) {
+ getLog().debug("Found configuration with pid: " + pid + ", path: " + path);
+ result.put(pid, path);
+ }
+ }
+ } catch (JSONException ex) {
+ throw new MojoExecutionException("Reading configuration from " + getUrl
+ + " failed, cause: " + ex.getMessage(), ex);
+ }
+ }
+ } catch (HttpException ex) {
+ throw new MojoExecutionException("Reading configuration from " + getUrl
+ + " failed, cause: " + ex.getMessage(), ex);
+ } catch (IOException ex) {
+ throw new MojoExecutionException("Reading configuration from " + getUrl
+ + " failed, cause: " + ex.getMessage(), ex);
+ }
+ return result;
+ }
+
+ /**
* Get the manifest from the File.
* @param bundleFile The bundle jar
* @return The manifest.
--
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.