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 2013/10/22 16:31:34 UTC
svn commit: r1534644 - in /sling/trunk/tooling/support/install: pom.xml
src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
Author: rombert
Date: Tue Oct 22 14:31:34 2013
New Revision: 1534644
URL: http://svn.apache.org/r1534644
Log:
SLING-3019 - Provide a mechanism to install a bundle based on a
directory
Added JSON rendering of responses.
Added:
sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java (with props)
Modified:
sling/trunk/tooling/support/install/pom.xml
sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
Modified: sling/trunk/tooling/support/install/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/install/pom.xml?rev=1534644&r1=1534643&r2=1534644&view=diff
==============================================================================
--- sling/trunk/tooling/support/install/pom.xml (original)
+++ sling/trunk/tooling/support/install/pom.xml Tue Oct 22 14:31:34 2013
@@ -81,5 +81,23 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.json</artifactId>
+ <version>2.0.6</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.4</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
Modified: sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java?rev=1534644&r1=1534643&r2=1534644&view=diff
==============================================================================
--- sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java (original)
+++ sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallServlet.java Tue Oct 22 14:31:34 2013
@@ -18,6 +18,7 @@ package org.apache.sling.tooling.support
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -73,9 +74,20 @@ public class InstallServlet extends Http
if ( dirPath == null ) {
logger.error("No dir parameter specified : {}", req.getParameterMap());
resp.setStatus(500);
+ InstallationResult result = new InstallationResult(false, "No dir parameter specified: "
+ + req.getParameterMap());
+ result.render(resp.getWriter());
return;
}
final File dir = new File(dirPath);
+ installBasedOnDirectory(resp, dir);
+ }
+
+ private void installBasedOnDirectory(HttpServletResponse resp, final File dir) throws FileNotFoundException,
+ IOException {
+
+ InstallationResult result = null;
+
if ( dir.exists() && dir.isDirectory() ) {
logger.info("Checking dir {} for bundle install", dir);
final File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
@@ -110,16 +122,21 @@ public class InstallServlet extends Http
final Bundle b = bundleContext.installBundle(dir.getAbsolutePath(), in);
b.start();
}
+ result = new InstallationResult(true, null);
resp.setStatus(200);
+ result.render(resp.getWriter());
return;
} catch ( final BundleException be ) {
logger.info("Unable to install/update bundle from dir " + dir, be);
+ result = new InstallationResult(false,
+ "Unable to install/update bundle from dir " + dir);
}
} finally {
tempFile.delete();
}
} else {
logger.info("Manifest in {} does not have a symbolic name", dir);
+ result = new InstallationResult(false, "Manifest in " + dir + " does not have a symbolic name");
}
} finally {
if ( fis != null ) {
@@ -127,12 +144,17 @@ public class InstallServlet extends Http
}
}
} else {
+ result = new InstallationResult(false, "Dir " + dir + " does not have a manifest");
logger.info("Dir {} does not have a manifest", dir);
}
} else {
+ result = new InstallationResult(false, "Dir " + dir + " does not exist");
logger.info("Dir {} does not exist", dir);
}
resp.setStatus(500);
+ if (result != null) {
+ result.render(resp.getWriter());
+ }
}
private static void createJar(final File sourceDir, final File jarFile, final Manifest mf)
Added: sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
URL: http://svn.apache.org/viewvc/sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java?rev=1534644&view=auto
==============================================================================
--- sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java (added)
+++ sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java Tue Oct 22 14:31:34 2013
@@ -0,0 +1,51 @@
+/*
+ * 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.sling.tooling.support.install.impl;
+
+import java.io.Writer;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
+
+public class InstallationResult {
+
+ private final boolean status;
+ private final String message;
+
+ public InstallationResult(boolean status, String message) {
+ this.status = status;
+ this.message = message;
+ }
+
+ public void render(Writer out) {
+
+ try {
+ JSONWriter writer = new JSONWriter(out);
+ writer.object();
+ writer.key("status").value(status ? "OK" : "FAILURE");
+ if (!StringUtils.isEmpty(message)) {
+ writer.key("message").value(message);
+ }
+ writer.endObject();
+ } catch (JSONException e) {
+ // never happens
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Propchange: sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/tooling/support/install/src/main/java/org/apache/sling/tooling/support/install/impl/InstallationResult.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL