bug343543 - Fixes permissions setting on Unix shell scripts during install time from the p2 repo
diff --git a/build-kernel/build.xml b/build-kernel/build.xml
index f65df76..6e07f17 100644
--- a/build-kernel/build.xml
+++ b/build-kernel/build.xml
@@ -177,43 +177,32 @@
 		<mkdir dir="${package.dir}/zip/repository/usr"/>

 		

 		<copy file="${basedir}/config/keystore" todir="${package.output.dir}/config" failonerror="false"/>

-

+		

 		<!-- zip the published Virgo repositories and configuration data -->

 		<zip destfile="${target.dir}/p2repo/virgo_resources.zip">

 			<zipfileset dir="${package.dir}/zip"/>

 		</zip>

-		

-		<delete dir="${package.dir}/zip" quiet="true"/>

-		

+	

 		<!-- execute product publisher -->

 		<echo message="Publishing Virgo kernel product in p2 repository" />

 		<java jar="${basedir}/p2/org.eclipse.osgi_3.7.0.v20110224.jar" fork="true" taskname="p2ProductPublishing" failonerror="true" maxmemory="256m">

 			<sysproperty key="operationType" value="p2repoPublish"/>

 			<sysproperty key="launch.config.location" value="${basedir}/lib/org.eclipse.virgo.kernel.launch.properties"/>

 			<sysproperty key="product.location" value="${target.dir}/p2repo"/>

+			<sysproperty key="additional.args" value="chmod.bin.location=${package.dir}/zip/bin;chmod.bin.permissions=755;chmod.jmx.location=${package.dir}/zip/config/org.eclipse.virgo.kernel.jmxremote.access.properties;chmod.jmx.permissions=600"/>

 		</java>

 		

+		<delete dir="${package.dir}/zip" quiet="true"/>

+		

 		<!-- execute product install -->

 		<echo message="Installing Virgo product to get the final assembly of Virgo kernel" />

 		<java jar="${basedir}/p2/org.eclipse.osgi_3.7.0.v20110224.jar" fork="true" taskname="p2ProductInstall" failonerror="true" maxmemory="256m">

 			<sysproperty key="operationType" value="installKernel"/>

-			<sysproperty key="source.p2.repo" value="file:${target.dir}/p2repo"/>

-			<sysproperty key="install.location" value="${package.output.dir}"/>

+			<sysproperty key="repository" value="file:${target.dir}/p2repo"/>

+			<sysproperty key="destination" value="${package.output.dir}"/>

 			<sysproperty key="installIU" value="virgo.product"/>

 			<sysproperty key="profile" value="VIRGO.kernel"/>

 		</java>

-        

-        <chmod perm="600">

-			<fileset dir="${package.output.dir}/config">

-				<include name="org.eclipse.virgo.kernel.jmxremote.access.properties"/>

-			</fileset>

-		</chmod>

-        

-		<chmod perm="755">

-			<fileset dir="${package.output.dir}/bin">

-				<include name="*.sh"/>

-			</fileset>

-		</chmod>

 		

 		<mkdir dir="${artifacts.dir}"/>

 		<zip destfile="${package.output.file}">

diff --git a/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java
index 500e22d..31d8e06 100644
--- a/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java
+++ b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java
@@ -1,3 +1,4 @@
+

 package org.eclipse.virgo.kernel.p2.build;

 

 import java.net.URI;

@@ -25,13 +26,14 @@
 import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;

 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;

+import org.eclipse.virgo.kernel.deployer.p2.VirgoPublisher;

 import org.osgi.framework.BundleContext;

 import org.osgi.framework.ServiceReference;

 import org.osgi.service.component.ComponentContext;

-import org.eclipse.virgo.kernel.deployer.p2.VirgoPublisher;

 

 /**

- * This is a helper class used during building the kernel distribution to create a p2 repository and create a kernel distro for zip operation.

+ * This is a helper class used during building the kernel distribution to create a p2 repository and create a kernel

+ * distro for zip operation.

  * 

  * <strong>Concurrent Semantics</strong><br />

  * Not thread-safe.

@@ -48,9 +50,9 @@
 

     private static final String IU_TO_INSTALL = "installIU";

 

-    private static final String INSTALL_LOCATION = "install.location";

+    private static final String INSTALL_LOCATION = "destination";

 

-    private static final String SOURCE_P2_REPO = "source.p2.repo";

+    private static final String SOURCE_P2_REPO = "repository";

 

     private static final String LAUNCH_CONFIG_LOCATION = "launch.config.location";

 

@@ -64,6 +66,8 @@
 

     private static final String OPERATION_TYPE = "operationType";

 

+    private static final String ADDITIONAL_ARGS = "additional.args";

+

     public void activate(ComponentContext context) throws Exception {

         BundleContext bundleContext = context.getBundleContext();

 

@@ -75,12 +79,14 @@
         if (publishType.equals(P2_REPO_PUBLISH)) {

             String launchConfigLocation = System.getProperty(LAUNCH_CONFIG_LOCATION);

             String productLocation = System.getProperty(PRODUCT_LOCATION);

-            

+            String additionalArgs = System.getProperty(ADDITIONAL_ARGS);

             launchConfigLocation = replaceBackslashesWithSlash(launchConfigLocation);

             productLocation = replaceBackslashesWithSlash(productLocation);

-            

+

+            Map<String, String> args = collectAdditionalArgs(additionalArgs);

+

             new ProductFileBuilder().generateProductFile(productLocation, VIRGO_PRODUCT, launchConfigLocation);

-            publisher.publishProduct(productLocation, productLocation);

+            publisher.publishProduct(productLocation, productLocation, args);

         }

 

         if (publishType.equals(INSTALL_KERNEL)) {

@@ -99,6 +105,24 @@
         System.exit(0);

     }

 

+    private Map<String, String> collectAdditionalArgs(String additionalArgs) {

+        if (additionalArgs != null) {

+            Map<String, String> args = new HashMap<String, String>();

+            String[] pairs = additionalArgs.split(";");

+            for (String pair : pairs) {

+                String[] splitPair = pair.split("=");

+                if (splitPair.length == 2) {

+                    args.put(splitPair[0], splitPair[1]);

+                } else {

+                    throw new IllegalArgumentException("The " + ADDITIONAL_ARGS

+                        + " property has incomplete or wrong value. It must contain key-value property pairs.");

+                }

+            }

+            return args;

+        }

+        return null;

+    }

+

     private void installProduct(BundleContext bundleContext, String sourceRepoLocation, String installLocation, String installIU, String targetProfile)

         throws ProvisionException, URISyntaxException {

         IProvisioningAgent pAgent = initialiseProvisioningAgentForInstallLocation(bundleContext, installLocation);

@@ -180,9 +204,9 @@
 

     private String createAgentInstallLocation(String installLocation) {

         // this is done to avoid 'URI not hierarchical' issue as the ProvisioningAgentProvider accepts hierarchical URIs

-    	if (!installLocation.startsWith("/")) {

-    		installLocation = "/" + installLocation;

-    	}

+        if (!installLocation.startsWith("/")) {

+            installLocation = "/" + installLocation;

+        }

         String agentInstallLocation = "file:" + installLocation;

         agentInstallLocation = agentInstallLocation + TARGET_LOCATION_OFFSET + P2_FOLDER;

         return agentInstallLocation;

diff --git a/org.eclipse.virgo.kernel.deployer.p2/.classpath b/org.eclipse.virgo.kernel.deployer.p2/.classpath
index 50eb4fe..52d92e6 100644
--- a/org.eclipse.virgo.kernel.deployer.p2/.classpath
+++ b/org.eclipse.virgo.kernel.deployer.p2/.classpath
@@ -1,20 +1,20 @@
-<?xml version="1.0" encoding="UTF-8"?>

-<classpath>

-	<classpathentry kind="src" path="src/main/java"/>

-	<classpathentry kind="src" path="src/test/resources"/>

-	<classpathentry kind="src" path="src/test/java"/>

-	<classpathentry kind="src" path="src/main/resources"/>

-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110224/org.eclipse.osgi-3.7.0.v20110224.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110224/org.eclipse.osgi-sources-3.7.0.v20110224.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.core.runtime/3.7.0.v20110110/org.eclipse.core.runtime-3.7.0.v20110110.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.publisher/1.2.0.v20110511/org.eclipse.equinox.p2.publisher-1.2.0.v20110511.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.repository/2.1.0.v20110510/org.eclipse.equinox.p2.repository-2.1.0.v20110510.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.core/2.1.0.v20110502-1955/org.eclipse.equinox.p2.core-2.1.0.v20110502-1955.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.artifact.repository/1.1.100.v20110511-1359/org.eclipse.equinox.p2.artifact.repository-1.1.100.v20110511-1359.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.metadata.repository/1.2.0.v20110511-1359/org.eclipse.equinox.p2.metadata.repository-1.2.0.v20110511-1359.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.common/3.6.0.v20110506/org.eclipse.equinox.common-3.6.0.v20110506.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.metadata/2.1.0.v20110510/org.eclipse.equinox.p2.metadata-2.1.0.v20110510.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/pdepublishing/1.0.0/pdepublishing-1.0.0.jar"/>

-	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-sources-3.3.0.v20110110.jar"/>

-	<classpathentry kind="output" path="target/classes"/>

-</classpath>

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main/java"/>
+	<classpathentry kind="src" path="src/test/resources"/>
+	<classpathentry kind="src" path="src/test/java"/>
+	<classpathentry kind="src" path="src/main/resources"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110224/org.eclipse.osgi-3.7.0.v20110224.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi/3.7.0.v20110224/org.eclipse.osgi-sources-3.7.0.v20110224.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.core.runtime/3.7.0.v20110110/org.eclipse.core.runtime-3.7.0.v20110110.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.publisher/1.2.0.v20110511/org.eclipse.equinox.p2.publisher-1.2.0.v20110511.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.repository/2.1.0.v20110510/org.eclipse.equinox.p2.repository-2.1.0.v20110510.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.core/2.1.0.v20110502-1955/org.eclipse.equinox.p2.core-2.1.0.v20110502-1955.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.artifact.repository/1.1.100.v20110511-1359/org.eclipse.equinox.p2.artifact.repository-1.1.100.v20110511-1359.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.metadata.repository/1.2.0.v20110511-1359/org.eclipse.equinox.p2.metadata.repository-1.2.0.v20110511-1359.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.common/3.6.0.v20110506/org.eclipse.equinox.common-3.6.0.v20110506.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.metadata/2.1.0.v20110510/org.eclipse.equinox.p2.metadata-2.1.0.v20110510.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-3.3.0.v20110110.jar" sourcepath="/KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.osgi.services/3.3.0.v20110110/org.eclipse.osgi.services-sources-3.3.0.v20110110.jar"/>
+	<classpathentry kind="var" path="KERNEL_IVY_CACHE/org.eclipse.osgi/org.eclipse.equinox.p2.publisher.eclipse.pdepublishing/1.0.0/org.eclipse.equinox.p2.publisher.eclipse.pdepublishing-1.0.0.jar"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>
diff --git a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/VirgoPublisher.java b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/VirgoPublisher.java
index de91d26..36d4702 100644
--- a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/VirgoPublisher.java
+++ b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/VirgoPublisher.java
@@ -1,6 +1,7 @@
 package org.eclipse.virgo.kernel.deployer.p2;

 

 import java.net.URISyntaxException;

+import java.util.Map;

 

 import org.eclipse.equinox.p2.core.ProvisionException;

 

@@ -18,5 +19,15 @@
      * @throws ProvisionException - when an error during publishing occurs

      * @throws URISyntaxException - when the locations have wrong syntax

      */

-    public void publishProduct(String sourceLocation, String targetLocation) throws ProvisionException, URISyntaxException;

+    public void publishProduct(String sourceLocation, String targetLocation) throws URISyntaxException;

+    

+    /**

+     * Publishes a product and its dependencies in a p2 repository 

+     * @param sourceLocation - the location of the folder where the product file is

+     * @param targetLocation - the location of the published repository

+     * @param additionalArgs - additional Virgo specific publisher configuration

+     * @throws ProvisionException - when an error during publishing occurs

+     * @throws URISyntaxException - when the locations have wrong syntax

+     */

+    public void publishProduct(String sourceLocation, String targetLocation, Map<String, String> additionalArgs) throws URISyntaxException;

 }

diff --git a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/LocalFSVirgoPublisher.java b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/LocalFSVirgoPublisher.java
index 84885d9..ce6464d 100644
--- a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/LocalFSVirgoPublisher.java
+++ b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/LocalFSVirgoPublisher.java
@@ -1,3 +1,4 @@
+

 package org.eclipse.virgo.kernel.deployer.p2.publish;

 

 import java.io.File;

@@ -6,23 +7,23 @@
 import java.util.ArrayList;

 import java.util.Collections;

 import java.util.List;

+import java.util.Map;

 

-import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRepositoryManager;

 import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository;

 import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryFactory;

-import org.eclipse.equinox.internal.p2.metadata.repository.MetadataRepositoryManager;

 import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;

 import org.eclipse.equinox.internal.p2.publisher.Messages;

 import org.eclipse.equinox.internal.p2.publisher.eclipse.IProductDescriptor;

 import org.eclipse.equinox.internal.p2.publisher.eclipse.ProductFile;

-import org.eclipse.equinox.p2.core.ProvisionException;

 import org.eclipse.equinox.p2.publisher.IPublisherAction;

 import org.eclipse.equinox.p2.publisher.IPublisherInfo;

 import org.eclipse.equinox.p2.publisher.Publisher;

 import org.eclipse.equinox.p2.publisher.PublisherInfo;

 import org.eclipse.equinox.p2.publisher.eclipse.ProductAction;

 import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;

+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;

 import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;

 import org.eclipse.osgi.util.NLS;

 import org.eclipse.virgo.kernel.deployer.p2.VirgoPublisher;

 import org.eclipse.virgo.kernel.deployer.p2.publish.actions.VirgoBundlesAction;

@@ -36,66 +37,78 @@
  * Thread-safe.

  */

 public class LocalFSVirgoPublisher implements VirgoPublisher {

- 

+

+    private static final String ZIP_EXT = ".zip";

+

+    private static final String JAR_EXT = ".jar";

+

     private static final String ENV_PROPERTY = "all.all.all";

 

     private static final String VIRGO_PRODUCT = "/virgo.product";

 

-    private static final String[][] VIRGO_MAPPING_RULES = new String[][] { 

-        { "(& (classifier=osgi.bundle))", "${repoUrl}/${id}_${version}.jar" },

-        { "(& (classifier=binary))", "${repoUrl}/${id}" },

-        { "(& (classifier=org.eclipse.update.feature))", "${repoUrl}/${id}_${version}.jar" } };;

-    

+    private static final String[][] VIRGO_MAPPING_RULES = new String[][] { { "(& (classifier=osgi.bundle))", "${repoUrl}/${id}_${version}.jar" },

+        { "(& (classifier=binary))", "${repoUrl}/${id}" }, { "(& (classifier=org.eclipse.update.feature))", "${repoUrl}/${id}_${version}.jar" } };;

+

     private final Object monitor = new Object();

-        

+

     public void activate(ComponentContext context) {

     }

 

     public void deactivate(ComponentContext context) {

     }

-    

+

     /**

      * {@inheritDoc}

      */

     @Override

-    public void publishProduct(String sourceLocation, String targetLocation) throws ProvisionException, URISyntaxException {

+    public void publishProduct(String sourceLocation, String targetLocation) throws URISyntaxException {

+        publishProduct(sourceLocation, targetLocation, null);

+    }

+

+    @Override

+    public void publishProduct(String sourceLocation, String targetLocation, Map<String, String> additionalArgs) throws URISyntaxException {

         synchronized (this.monitor) {

             IPublisherInfo info = createPublisherInfo(targetLocation);

             Publisher publisher = new Publisher(info);

-            publisher.publish(createPublisherActionsForQualifiedArtifacts(sourceLocation), null);

+            publisher.publish(createPublisherActionsForQualifiedArtifacts(sourceLocation, additionalArgs), null);

             publisher.publish(createProductAction(sourceLocation, targetLocation), null);

         }

+

     }

-    

+

     /**

-     * Create the product publisher action. This action will take care of updating the p2 metadata repository with the products description

+     * Create the product publisher action. This action will take care of updating the p2 metadata repository with the

+     * products description

+     * 

      * @param sourceLocation - the folder where the product file is located

-     * @param targetLocation - the location of the target repository that will be updated with the product file definition

+     * @param targetLocation - the location of the target repository that will be updated with the product file

+     *        definition

      * @return - return the {@link ProductAction} that will handle the publishing of the product

      */

     private IPublisherAction[] createProductAction(String sourceLocation, String targetLocation) {

         IProductDescriptor productDescriptor = null;

         String productFile = sourceLocation + VIRGO_PRODUCT;

-        try {            

+        try {

             productDescriptor = new ProductFile(productFile);

         } catch (Exception e) {

             throw new IllegalArgumentException(NLS.bind(Messages.exception_errorLoadingProductFile, productFile, e.toString()));

         }

-        return new IPublisherAction[] {new ProductAction(targetLocation, productDescriptor, "tooling", null)};

+        return new IPublisherAction[] { new ProductAction(targetLocation, productDescriptor, "tooling", null) };

     }

 

     /**

      * Initializes the publisher info used for the publishing operations.

+     * 

      * @param targetLocation - the location where a p2 repository will be created with that {@link IPublisherInfo}.

      * @return - the {@link IPublisherInfo} that will be used to create a p2 repository in the specified location

      * @throws URISyntaxException - when the URI for the p2 repository is with wrong syntax

      */

-    private IPublisherInfo createPublisherInfo(String targetLocation) throws URISyntaxException {        

+    private IPublisherInfo createPublisherInfo(String targetLocation) throws URISyntaxException {

         targetLocation = targetLocation.startsWith("file:") ? targetLocation : "file:" + targetLocation;

-        

+

         PublisherInfo pInfo = new PublisherInfo();

-        

-        pInfo.setConfigurations(new String[] {ENV_PROPERTY});

+

+        pInfo.setConfigurations(new String[] { ENV_PROPERTY });

 

         initialisePublisherInfoRepositories(targetLocation, pInfo);

         pInfo.setArtifactOptions(IPublisherInfo.A_PUBLISH | IPublisherInfo.A_INDEX);

@@ -104,6 +117,7 @@
 

     /**

      * Initializes the {@link IPublisherInfo} p2 metadata and artifact repositories on the specified location

+     * 

      * @param targetLocation - the location where the p2 repository will be published

      * @param pInfo - the {@link IPublisherInfo} created for the target p2 repository

      * @throws URISyntaxException - when the URI for the artifact or metadata p2 repositories is with wrong syntax

@@ -111,10 +125,10 @@
     @SuppressWarnings("unchecked")

     private void initialisePublisherInfoRepositories(String targetLocation, PublisherInfo pInfo) throws URISyntaxException {

         IMetadataRepository metadataRepository = new SimpleMetadataRepositoryFactory().create(new URI(targetLocation), "Virgo Metadata Repository",

-            MetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);

+            IMetadataRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);

 

         IArtifactRepository artifactRepository = new SimpleArtifactRepositoryFactory().create(new URI(targetLocation), "Virgo Artifact Repository",

-            ArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);

+            IArtifactRepositoryManager.TYPE_SIMPLE_REPOSITORY, Collections.EMPTY_MAP);

 

         ((SimpleArtifactRepository) artifactRepository).setRules(VIRGO_MAPPING_RULES);

         ((SimpleArtifactRepository) artifactRepository).initializeAfterLoad(new URI(targetLocation));

@@ -125,40 +139,53 @@
 

     /**

      * Creates {@link IPublisherAction} for each qualified file at the specified location

+     * 

      * @param location - a location containing the artifacts that will be published in a p2 repository

      * @return - an array of {@link IPublisherAction} that will be used for publishing to a p2 repository

      */

-    private IPublisherAction[] createPublisherActionsForQualifiedArtifacts(String location) {

+    private IPublisherAction[] createPublisherActionsForQualifiedArtifacts(String location, Map<String, String> args) {

         location = location.startsWith("file:") ? location.substring(5) : location;

-        

+

         File repository = new File(location);

         List<File> bundles = new ArrayList<File>();

         List<File> zippedFiles = new ArrayList<File>();

-        

-        if (repository.isDirectory()) { // TODO: handle single artifact as directory

-            for (File file : repository.listFiles()) {

-                if (file.getName().endsWith(".jar") || file.isDirectory()) {

-                    bundles.add(file);

-                }

-                if (file.getName().endsWith(".zip")) {

-                    zippedFiles.add(file);

-                }

-            }

-        } else {

-            if (location.endsWith(".jar")) {

-                bundles.add(new File(location));

-            }

-        }

+

+        collectQualifiedArtifacts(location, repository, bundles, zippedFiles);

+

+        List<IPublisherAction> publisherActions = createPublisherActions(bundles, zippedFiles, args);

+        return publisherActions.toArray(new IPublisherAction[publisherActions.size()]);

+    }

+

+    private List<IPublisherAction> createPublisherActions(List<File> bundles, List<File> zippedFiles, Map<String, String> args) {

         List<IPublisherAction> publisherActions = new ArrayList<IPublisherAction>();

         if (bundles.size() > 0) {

             VirgoBundlesAction bundleAction = new VirgoBundlesAction(bundles.toArray(new File[bundles.size()]));

             publisherActions.add(bundleAction);

         }

         if (zippedFiles.size() > 0) {

-            ZippedResourcesPublisherAction zippedAction = new ZippedResourcesPublisherAction(zippedFiles.toArray(new File[zippedFiles.size()]));

+            ZippedResourcesPublisherAction zippedAction = new ZippedResourcesPublisherAction(zippedFiles.toArray(new File[zippedFiles.size()]), args);

             publisherActions.add(zippedAction);

         }

-        return publisherActions.toArray(new IPublisherAction[publisherActions.size()]);

+        return publisherActions;

     }

 

+    private void collectQualifiedArtifacts(String location, File repository, List<File> bundles, List<File> zippedFiles) {

+        if (repository.isDirectory()) {

+            for (File file : repository.listFiles()) {

+                if (file.getName().endsWith(JAR_EXT) || file.isDirectory()) {

+                    bundles.add(file);

+                }

+                if (file.getName().endsWith(ZIP_EXT)) {

+                    zippedFiles.add(file);

+                }

+            }

+        } else {

+            if (location.endsWith(JAR_EXT)) {

+                bundles.add(new File(location));

+            }

+            if (location.endsWith(ZIP_EXT)) {

+                zippedFiles.add(new File(location));

+            }

+        }

+    }

 }

diff --git a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/actions/ZippedResourcesPublisherAction.java b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/actions/ZippedResourcesPublisherAction.java
index d7f5761..8e6ba6d 100644
--- a/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/actions/ZippedResourcesPublisherAction.java
+++ b/org.eclipse.virgo.kernel.deployer.p2/src/main/java/org/eclipse/virgo/kernel/deployer/p2/publish/actions/ZippedResourcesPublisherAction.java
@@ -27,12 +27,19 @@
 import org.eclipse.equinox.spi.p2.publisher.PublisherHelper;

 

 /**

- * Publishes a zipped resource artifact

- * <strong>Concurrent Semantics</strong><br />

+ * Publishes a zipped resource artifact <strong>Concurrent Semantics</strong><br />

  * Thread-safe.

  */

 public class ZippedResourcesPublisherAction extends AbstractPublisherAction {

 

+    private static final String CHMOD_JMX_PERMISSIONS = "chmod.jmx.permissions";

+

+    private static final String CHMOD_JMX_LOCATION = "chmod.jmx.location";

+

+    private static final String CHMOD_BIN_PERMISSIONS = "chmod.bin.permissions";

+

+    private static final String CHMOD_BIN_LOCATION = "chmod.bin.location";

+

     private static final Version DEFAULT_VERSION = Version.createOSGi(1, 0, 0);

 

     private static final String ZIPPED_RESOURCES_NAME = "zipped.resources";

@@ -41,14 +48,18 @@
 

     private final Object monitor = new Object();

 

-    public ZippedResourcesPublisherAction(File[] locations) {

+    private final Map<String, String> args;

+

+    public ZippedResourcesPublisherAction(File[] locations, Map<String, String> args) {

         this.locations = locations;

+        this.args = args;

     }

 

     /**

      * Executes the action, resulting in a published artifact and metadata for it

      * 

-     * @param publisherInfo - initialized {@link IPublisherInfo} with repositories to be used by this {@link IPublisherAction}

+     * @param publisherInfo - initialized {@link IPublisherInfo} with repositories to be used by this

+     *        {@link IPublisherAction}

      * @param results - {@link IPublisherResult} that will be passed on the next publishing stages

      * @param monitor - {@link IProgressMonitor} used for monitoring the progress of this action, can be <b>null</b>

      * @return - the {@link IStatus} containing the result of the operation

@@ -82,13 +93,40 @@
     }

 

     private void setTouchpointInstructionsToIUDescription(InstallableUnitDescription iuDescription) {

+        StringBuilder chmodTouchpointData = getCHMODConfiguration();

+

         Map<String, String> touchpointData = new HashMap<String, String>();

         // the install folder is moved two folders up in order to ensure Virgo's root structure is kept the same

-        touchpointData.put("install", "unzip(source:@artifact, target:${installFolder}/../../);");

+        touchpointData.put("install", "unzip(source:@artifact, target:${installFolder}/../../);" + chmodTouchpointData.toString());

         touchpointData.put("uninstall", "cleanupzip(source:@artifact, target:${installFolder}/../../);");

         iuDescription.addTouchpointData(MetadataFactory.createTouchpointData(touchpointData));

     }

 

+    private StringBuilder getCHMODConfiguration() {

+        StringBuilder chmodTouchpointData = new StringBuilder();

+        if (this.args != null) {

+            if (this.args.containsKey(CHMOD_BIN_LOCATION) && this.args.containsKey(CHMOD_BIN_PERMISSIONS)) {

+                File binFolder = new File(this.args.get(CHMOD_BIN_LOCATION));

+                if (binFolder.exists() && binFolder.isDirectory()) {

+                    for (File script : binFolder.listFiles()) {

+                        if (script.getName().endsWith(".sh")) {

+                            chmodTouchpointData.append("chmod(targetDir:${installFolder}/../../bin,targetFile:" + script.getName() + ",permissions:"

+                                + this.args.get(CHMOD_BIN_PERMISSIONS) + ");");

+                        }

+                    }

+                }

+            }

+            if (this.args.containsKey(CHMOD_JMX_LOCATION) && this.args.containsKey(CHMOD_JMX_PERMISSIONS)) {

+                File jmxPropFile = new File(this.args.get(CHMOD_JMX_LOCATION));

+                if (jmxPropFile.exists() && jmxPropFile.isFile()) {

+                    chmodTouchpointData.append("chmod(targetDir:${installFolder}/../../config,targetFile:" + jmxPropFile.getName() + ",permissions:"

+                        + this.args.get(CHMOD_JMX_PERMISSIONS) + ");");

+                }

+            }

+        }

+        return chmodTouchpointData;

+    }

+

     private void addZippedResourcesToIUDescription(IPublisherInfo publisherInfo, InstallableUnitDescription iuDescription) {

         List<IArtifactKey> zippedArtifacts = new ArrayList<IArtifactKey>();