Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBorislav Kapukaranov2011-06-03 13:11:31 -0400
committerBorislav Kapukaranov2011-06-03 13:11:31 -0400
commitd2841e4f98d4443687d83e59a5848ace5802e7f6 (patch)
tree53fc73cd0d4d739117ed829beb3b6cd376fccba4 /org.eclipse.virgo.kernel.build.p2
parente8e3d5acd610a9e12609e41a3a59b721616bf18b (diff)
downloadorg.eclipse.virgo.kernel-d2841e4f98d4443687d83e59a5848ace5802e7f6.tar.gz
org.eclipse.virgo.kernel-d2841e4f98d4443687d83e59a5848ace5802e7f6.tar.xz
org.eclipse.virgo.kernel-d2841e4f98d4443687d83e59a5848ace5802e7f6.zip
bug343542 - Initial Provisioning scenario of Virgo: initial
contribution
Diffstat (limited to 'org.eclipse.virgo.kernel.build.p2')
-rw-r--r--org.eclipse.virgo.kernel.build.p2/.classpath21
-rw-r--r--org.eclipse.virgo.kernel.build.p2/.project33
-rw-r--r--org.eclipse.virgo.kernel.build.p2/META-INF/MANIFEST.MF21
-rw-r--r--org.eclipse.virgo.kernel.build.p2/bin/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.classbin0 -> 13639 bytes
-rw-r--r--org.eclipse.virgo.kernel.build.p2/build.xml9
-rw-r--r--org.eclipse.virgo.kernel.build.p2/findbugs-exclude.xml8
-rw-r--r--org.eclipse.virgo.kernel.build.p2/ivy.xml39
-rw-r--r--org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/Main.java66
-rw-r--r--org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/ProductFileBuilder.java164
-rw-r--r--org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java251
-rw-r--r--org.eclipse.virgo.kernel.build.p2/src/main/resources/OSGI-INF/kernel.build.p2.xml14
-rw-r--r--org.eclipse.virgo.kernel.build.p2/template.mf23
12 files changed, 649 insertions, 0 deletions
diff --git a/org.eclipse.virgo.kernel.build.p2/.classpath b/org.eclipse.virgo.kernel.build.p2/.classpath
new file mode 100644
index 00000000..44931cdd
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/.classpath
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" path="src/test/java"/>
+ <classpathentry kind="src" path="src/test/resources"/>
+ <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.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.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.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/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.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.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.engine/2.1.0.v20110511/org.eclipse.equinox.p2.engine-2.1.0.v20110511.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.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.director/2.1.0.v20110504-1715/org.eclipse.equinox.p2.director-2.1.0.v20110504-1715.jar"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/org.eclipse.virgo.kernel.deployer.p2"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.virgo.kernel.build.p2/.project b/org.eclipse.virgo.kernel.build.p2/.project
new file mode 100644
index 00000000..fc76eb0f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/.project
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.virgo.kernel.build.p2</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ds.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.virgo.kernel.build.p2/META-INF/MANIFEST.MF b/org.eclipse.virgo.kernel.build.p2/META-INF/MANIFEST.MF
new file mode 100644
index 00000000..deceb541
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/META-INF/MANIFEST.MF
@@ -0,0 +1,21 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: VirgoRepositoryPublisher
+Service-Component: OSGI-INF/virgo.repo.publisher.xml
+Bundle-Version: 1.0.0.qualifier
+Bundle-SymbolicName: org.eclipse.virgo.kernel.build.p2
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.equinox.internal.p2.artifact.repository,
+ org.eclipse.equinox.internal.p2.artifact.repository.simple,
+ org.eclipse.equinox.p2.core;version="2.0.0",
+ org.eclipse.equinox.p2.engine;version="2.0.0",
+ org.eclipse.equinox.p2.metadata;version="2.1.0",
+ org.eclipse.equinox.p2.planner;version="2.0.0",
+ org.eclipse.equinox.p2.query;version="2.0.0",
+ org.eclipse.equinox.p2.repository.artifact;version="2.0.0",
+ org.eclipse.equinox.p2.repository.metadata;version="2.0.0",
+ org.eclipse.virgo.kernel.p2.publisher,
+ org.osgi.framework;version="1.3.0",
+ org.osgi.service.component
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0"
diff --git a/org.eclipse.virgo.kernel.build.p2/bin/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.class b/org.eclipse.virgo.kernel.build.p2/bin/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.class
new file mode 100644
index 00000000..e42ee017
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/bin/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.class
Binary files differ
diff --git a/org.eclipse.virgo.kernel.build.p2/build.xml b/org.eclipse.virgo.kernel.build.p2/build.xml
new file mode 100644
index 00000000..890cc972
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/build.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="org.eclipse.virgo.kernel.build.p2">
+
+ <property name="findbugs.exclude.file" value="${basedir}/findbugs-exclude.xml"/>
+ <property file="${basedir}/../build.properties"/>
+ <property file="${basedir}/../build.versions"/>
+ <import file="${basedir}/../virgo-build/weaving/default.xml"/>
+
+</project>
diff --git a/org.eclipse.virgo.kernel.build.p2/findbugs-exclude.xml b/org.eclipse.virgo.kernel.build.p2/findbugs-exclude.xml
new file mode 100644
index 00000000..ca6b7edc
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/findbugs-exclude.xml
@@ -0,0 +1,8 @@
+<FindBugsFilter>
+ <!-- Exclusions -->
+ <Match>
+ <Bug pattern="ES_COMPARING_PARAMETER_STRING_WITH_EQ"/>
+ <Class name="org.eclipse.virgo.kernel.deployer.core.module.StandardModule"/>
+ <Method name="unwrapNull"/>
+ </Match>
+</FindBugsFilter>
diff --git a/org.eclipse.virgo.kernel.build.p2/ivy.xml b/org.eclipse.virgo.kernel.build.p2/ivy.xml
new file mode 100644
index 00000000..1e38e476
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/ivy.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?xml-stylesheet type="text/xsl" href="http://ivyrep.jayasoft.org/ivy-doc.xsl"?>
+<ivy-module
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd"
+ version="1.3">
+
+ <info organisation="org.eclipse.virgo.kernel" module="${ant.project.name}"/>
+
+ <configurations>
+ <include file="${virgo.build.dir}/common/default-ivy-configurations.xml"/>
+ </configurations>
+
+ <publications>
+ <artifact name="${ant.project.name}"/>
+ <artifact name="${ant.project.name}-sources" type="src" ext="jar"/>
+ </publications>
+
+ <dependencies>
+
+ <dependency org="org.eclipse.virgo.kernel" name="org.eclipse.virgo.kernel.deployer.p2" rev="latest.integration" conf="compile->runtime"/>
+
+ <dependency org="org.eclipse.osgi" name="org.eclipse.osgi" rev="${org.eclipse.osgi}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.core.runtime" rev="${org.eclipse.core.runtime}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.common" rev="${org.eclipse.equinox.common}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.osgi.services" rev="${org.eclipse.osgi.services}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.metadata.repository" rev="${org.eclipse.equinox.p2.metadata.repository}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.artifact.repository" rev="${org.eclipse.equinox.p2.artifact.repository}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.metadata" rev="${org.eclipse.equinox.p2.metadata}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.core" rev="${org.eclipse.equinox.p2.core}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.repository" rev="${org.eclipse.equinox.p2.repository}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.engine" rev="${org.eclipse.equinox.p2.engine}" conf="compile->runtime"/>
+ <dependency org="org.eclipse.osgi" name="org.eclipse.equinox.p2.director" rev="${org.eclipse.equinox.p2.director}" conf="compile->runtime"/>
+
+ <!-- Allow Equinox to be upgraded point-wise before rippling -->
+ <override org="org.eclipse.osgi" module="org.eclipse.osgi" rev="${org.eclipse.osgi}"/>
+ </dependencies>
+
+</ivy-module>
diff --git a/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/Main.java b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/Main.java
new file mode 100644
index 00000000..72c0ed17
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/Main.java
@@ -0,0 +1,66 @@
+
+package org.eclipse.virgo.kernel.p2.build;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+public class Main {
+
+ protected static final String SIMPLECONFIGURATOR_BSN = "org.eclipse.equinox.simpleconfigurator";
+
+ private static final String ORG_ECLIPSE_OSGI = "org.eclipse.osgi";
+
+ private static final String BSN_VERSION_SEPARATOR = "_";
+
+ private static final String SC_CONFIG_DIR = "configuration/" + SIMPLECONFIGURATOR_BSN;
+
+ private static final String BINFO_FILE_NAME = "bundles.info";
+
+ private static final String P2_CLIENT_DIR = "p2";
+
+ public static void main(String[] args) throws IOException {
+ if (args != null && args.length == 1) {
+ String baseDir = args[0];
+
+ String bundlesInfoContent = new String();
+ File baseDirFile = new File(baseDir + File.separatorChar + P2_CLIENT_DIR);
+ if (baseDirFile.isDirectory()) {
+ for (File file : baseDirFile.listFiles()) {
+ if (file.getName().endsWith(".jar") && file.getName().contains(BSN_VERSION_SEPARATOR)) {
+ String[] bsnVersionPair = file.getName().split(BSN_VERSION_SEPARATOR);
+ String name = bsnVersionPair[0];
+ String version = bsnVersionPair[1];
+ version = version.substring(0, version.indexOf(".jar"));
+ int startLevel = 4;
+ if (name.equals(SIMPLECONFIGURATOR_BSN)) {
+ startLevel = 1;
+ }
+ if (name.equals(ORG_ECLIPSE_OSGI)) {
+ startLevel = -1;
+ }
+ bundlesInfoContent = bundlesInfoContent + name + "," + version + "," + file.getName() + "," + startLevel + "," + "true\n";
+ }
+ }
+ }
+
+ File bundlesInfoFolder = new File(baseDir + File.separatorChar + P2_CLIENT_DIR + File.separatorChar + SC_CONFIG_DIR);
+ bundlesInfoFolder.mkdirs();
+ File bundlesInfo = new File(baseDir + File.separatorChar + P2_CLIENT_DIR + File.separatorChar + SC_CONFIG_DIR + File.separatorChar + BINFO_FILE_NAME);
+ bundlesInfo.createNewFile();
+ FileWriter writer = null;
+ try {
+ writer = new FileWriter(bundlesInfo);
+ writer.write(bundlesInfoContent);
+ } catch (IOException e) {
+ throw e;
+ } finally {
+ writer.flush();
+ writer.close();
+ }
+ } else {
+ throw new IllegalArgumentException("Required argument for build-kernel's location is missing or wrong.");
+ }
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/ProductFileBuilder.java b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/ProductFileBuilder.java
new file mode 100644
index 00000000..d6183ee4
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/ProductFileBuilder.java
@@ -0,0 +1,164 @@
+
+package org.eclipse.virgo.kernel.p2.build;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Helper class for building product files from a defined startup configuration
+ * <strong>Concurrent Semantics</strong><br />
+ * Thread-safe.
+ */
+public class ProductFileBuilder {
+
+ private static final String PROPERTY_PREFIX = "<property name=";
+
+ private static final String START_LEVEL_1 = "startLevel=\"1\"";
+
+ private static final String PRODUCT_SUFFIX = "</product>\n";
+
+ private static final String CONFIGURATIONS_SUFFIX = "</configurations>\n";
+
+ private static final String CONFIGURATIONS_PREFIX = "<configurations>\n";
+
+ private static final String PLUGINS_SUFFIX = "</plugins>\n";
+
+ private static final String PLUGINS_PREFIX = "<plugins>\n";
+
+ private static final String PRODUCT_PREFIX = "<?xml version=\"1.0\"?>\n<?pde version=\"3.5\"?>\n<product name=\"Virgo Kernel Distribution\" uid=\"virgo.product\" version=\"1.0.0\" useFeatures=\"false\" includeLaunchers=\"false\">\n";
+
+ private static final String ELEMENT_SUFFIX = "/>\n";
+
+ private static final String PLUGIN_ELEMENT_PREFIX = "<plugin id=";
+
+ private static final String AUTO_START_INSTRUCTION = "autoStart=\"true\"";
+
+ private static final String BSN_VERSION_SEPARATOR = "_";
+
+ private static final String PROP_LAUNCHER_BUNDLES = "launcher.bundles";
+
+ private final Object monitor = new Object();
+
+ /**
+ * Generates a product file from launch configuration
+ * @param targetLocation - the location where the product file will be saved
+ * @param productFileName - the product file's name
+ * @param launchConfigLocation - the location of the launch configuration
+ * @throws IOException - when the write operation on the product file failed
+ */
+ public void generateProductFile(String targetLocation, String productFileName, String launchConfigLocation) throws IOException {
+ synchronized (this.monitor) {
+ File bundlesDir = new File(targetLocation);
+ if (bundlesDir.isDirectory()) {
+ File productFile = new File(targetLocation + "/" + productFileName);
+ if (productFile.exists()) {
+ productFile.delete();
+ productFile.createNewFile();
+ }
+ FileWriter writer = new FileWriter(productFile);
+ writer.write(PRODUCT_PREFIX);
+
+ Map<String, String> productConfiguration = initializeProductConfiguration(launchConfigLocation);
+
+ writeProductPlugins(bundlesDir, writer, productConfiguration);
+ writeProductConfiguration(writer, productConfiguration);
+
+ writer.write(PRODUCT_SUFFIX);
+ writer.flush();
+ writer.close();
+ }
+ }
+ }
+
+ private void writeProductConfiguration(FileWriter writer, Map<String, String> productConfiguration) throws IOException {
+ writer.write(CONFIGURATIONS_PREFIX);
+ for (String configuration : productConfiguration.values()) {
+ writer.write(configuration);
+ }
+ writer.write(CONFIGURATIONS_SUFFIX);
+ }
+
+ private void writeProductPlugins(File bundlesDir, FileWriter writer, Map<String, String> productConfiguration) throws IOException {
+ writer.write(PLUGINS_PREFIX);
+ for (File bundle : bundlesDir.listFiles()) {
+ if (bundle.getName().endsWith(".jar")) {
+ String bsn = bundle.getName().substring(0, bundle.getName().indexOf(BSN_VERSION_SEPARATOR));
+ if (productConfiguration.containsKey(bsn)) {
+ writer.write(PLUGIN_ELEMENT_PREFIX + "\"" + bsn + "\"" + ELEMENT_SUFFIX);
+ }
+ }
+ }
+ writer.write(PLUGINS_SUFFIX);
+ }
+
+ private Properties parseConfigProperties(String configPath) throws IOException {
+ File file = new File(configPath);
+ if (!file.exists()) {
+ throw new FileNotFoundException("Config path '" + file.getAbsolutePath() + "' does not exist.");
+ }
+ Properties props = new Properties();
+ InputStream stream = null;
+ try {
+ stream = new FileInputStream(file);
+ props.load(stream);
+ return props;
+ } catch (IOException e) {
+ throw new IOException("Unable to read config properties file '" + file.getAbsolutePath() + "'.", e);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException ex) {
+ }
+ }
+ }
+ }
+
+ private Map<String, String> parseBundlesToBeStarted(String entryList) {
+ Map<String, String> bundlesConfiguration = new HashMap<String, String>();
+
+ String[] entries = entryList.split(",");
+ for (String entry : entries) {
+ boolean isAutoStart = entry.contains("@start");
+ String bsn = entry.substring(0, entry.indexOf(BSN_VERSION_SEPARATOR));
+ if (isAutoStart) {
+ bundlesConfiguration.put(bsn, createProductInstruction(bsn));
+ }
+ }
+ return bundlesConfiguration;
+ }
+
+ private String createProductInstruction(String bsn) {
+ if (bsn.equals(Main.SIMPLECONFIGURATOR_BSN)) {
+ return PLUGIN_ELEMENT_PREFIX + "\"" + bsn + "\" " + AUTO_START_INSTRUCTION + " " + START_LEVEL_1 + ELEMENT_SUFFIX;
+ }
+ return PLUGIN_ELEMENT_PREFIX + "\"" + bsn + "\" " + AUTO_START_INSTRUCTION + ELEMENT_SUFFIX;
+ }
+
+ private Map<String, String> initializeProductConfiguration(String launchConfigLocation) throws IOException {
+
+ Properties launchConfig = parseConfigProperties(launchConfigLocation);
+
+ Map<String, String> productConfiguration = new HashMap<String, String>();
+
+ String launcherBundles = launchConfig.getProperty(PROP_LAUNCHER_BUNDLES);
+ if (launcherBundles != null) {
+ productConfiguration.putAll(parseBundlesToBeStarted(launcherBundles));
+ }
+
+ launchConfig.remove(PROP_LAUNCHER_BUNDLES);
+
+ for (String propKey : launchConfig.stringPropertyNames()) {
+ productConfiguration.put(propKey, PROPERTY_PREFIX + "\"" + propKey + "\" value=\"" + launchConfig.getProperty(propKey) + "\"" + ELEMENT_SUFFIX);
+ }
+
+ return productConfiguration;
+ }
+}
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
new file mode 100644
index 00000000..c2521bd2
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/src/main/java/org/eclipse/virgo/kernel/p2/build/VirgoBuildP2RepoPublisher.java
@@ -0,0 +1,251 @@
+package org.eclipse.virgo.kernel.p2.build;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.IProvisioningAgentProvider;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.engine.IEngine;
+import org.eclipse.equinox.p2.engine.IProfile;
+import org.eclipse.equinox.p2.engine.IProfileRegistry;
+import org.eclipse.equinox.p2.engine.IProvisioningPlan;
+import org.eclipse.equinox.p2.engine.ProvisioningContext;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.planner.IPlanner;
+import org.eclipse.equinox.p2.planner.IProfileChangeRequest;
+import org.eclipse.equinox.p2.query.IQuery;
+import org.eclipse.equinox.p2.query.IQueryResult;
+import org.eclipse.equinox.p2.query.QueryUtil;
+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.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.
+ *
+ * <strong>Concurrent Semantics</strong><br />
+ * Not thread-safe.
+ */
+public class VirgoBuildP2RepoPublisher {
+
+ private static final String P2_FOLDER = "/p2";
+
+ private static final String OSGI_CONFIG_AREA = "/work/osgi/configuration";
+
+ private static final String TARGET_LOCATION_OFFSET = "/lib/kernel";
+
+ private static final String TARGET_PROFILE = "profile";
+
+ private static final String IU_TO_INSTALL = "installIU";
+
+ private static final String INSTALL_LOCATION = "install.location";
+
+ private static final String SOURCE_P2_REPO = "source.p2.repo";
+
+ private static final String LAUNCH_CONFIG_LOCATION = "launch.config.location";
+
+ private static final String VIRGO_PRODUCT = "virgo.product";
+
+ private static final String PRODUCT_LOCATION = "product.location";
+
+ private static final String INSTALL_KERNEL = "installKernel";
+
+ private static final String P2_REPO_PUBLISH = "p2repoPublish";
+
+ private static final String OPERATION_TYPE = "operationType";
+
+ public void activate(ComponentContext context) throws Exception {
+ BundleContext bundleContext = context.getBundleContext();
+
+ ServiceReference<VirgoPublisher> publisherRef = bundleContext.getServiceReference(VirgoPublisher.class);
+ VirgoPublisher publisher = bundleContext.getService(publisherRef);
+
+ String publishType = System.getProperty(OPERATION_TYPE);
+
+ if (publishType.equals(P2_REPO_PUBLISH)) {
+ String launchConfigLocation = System.getProperty(LAUNCH_CONFIG_LOCATION);
+ String productLocation = System.getProperty(PRODUCT_LOCATION);
+
+ launchConfigLocation = replaceBackslashesWithSlash(launchConfigLocation);
+ productLocation = replaceBackslashesWithSlash(productLocation);
+
+ new ProductFileBuilder().generateProductFile(productLocation, VIRGO_PRODUCT, launchConfigLocation);
+ publisher.publishProduct(productLocation, productLocation);
+ }
+
+ if (publishType.equals(INSTALL_KERNEL)) {
+ // sourceRepo location should start with 'file:' by default
+ String sourceRepo = System.getProperty(SOURCE_P2_REPO);
+ String installLocation = System.getProperty(INSTALL_LOCATION);
+ String installIU = System.getProperty(IU_TO_INSTALL);
+ String targetProfile = System.getProperty(TARGET_PROFILE);
+
+ installLocation = replaceBackslashesWithSlash(installLocation);
+ sourceRepo = replaceBackslashesWithSlash(sourceRepo);
+ installProduct(bundleContext, sourceRepo, installLocation, installIU, targetProfile);
+ }
+
+ // We are done - exit now.
+ System.exit(0);
+ }
+
+ private void installProduct(BundleContext bundleContext, String sourceRepoLocation, String installLocation, String installIU, String targetProfile)
+ throws ProvisionException, URISyntaxException {
+ IProvisioningAgent pAgent = initialiseProvisioningAgentForInstallLocation(bundleContext, installLocation);
+
+ IMetadataRepositoryManager metadataRepoManager = (IMetadataRepositoryManager) pAgent.getService(IMetadataRepositoryManager.class.getName());
+
+ ProvisioningContext provisioningContext = initialiseProvisioningContext(sourceRepoLocation, pAgent, metadataRepoManager);
+
+ IProfile targetSystemProfile = initialiseTargetP2Profile(installLocation, targetProfile, pAgent);
+
+ IInstallableUnit unitToInstall = getKernelProductInstallableUnit(sourceRepoLocation, installIU, metadataRepoManager);
+
+ IProvisioningPlan plan = createPlan(targetSystemProfile, provisioningContext, pAgent, new IInstallableUnit[] { unitToInstall });
+
+ IStatus status = executePlan(pAgent, plan);
+ if (!status.isOK()) {
+ throw new ProvisionException("Failed to install Virgo Kernel product");
+ }
+ }
+
+ private IInstallableUnit getKernelProductInstallableUnit(String sourceRepoLocation, String installIU,
+ IMetadataRepositoryManager metadataRepoManager) throws URISyntaxException, ProvisionException, OperationCanceledException {
+ IMetadataRepository metadataRepo = loadMetadataRepository(sourceRepoLocation, metadataRepoManager);
+
+ IQuery<IInstallableUnit> matchQuery = QueryUtil.createIUQuery(installIU);
+ IQueryResult<IInstallableUnit> result = metadataRepo.query(matchQuery, null);
+ IInstallableUnit unitToInstall = null;
+ if (result.iterator().hasNext()) {
+ unitToInstall = result.iterator().next();
+ }
+ return unitToInstall;
+ }
+
+ private ProvisioningContext initialiseProvisioningContext(String sourceRepoLocation, IProvisioningAgent pAgent,
+ IMetadataRepositoryManager metadataRepoManager) throws URISyntaxException, ProvisionException, OperationCanceledException {
+ IArtifactRepositoryManager artifactRepoManager = (IArtifactRepositoryManager) pAgent.getService(IArtifactRepositoryManager.class.getName());
+
+ metadataRepoManager.loadRepository(new URI(sourceRepoLocation), null);
+ artifactRepoManager.loadRepository(new URI(sourceRepoLocation), null);
+
+ ProvisioningContext provisioningContext = new ProvisioningContext(pAgent);
+ provisioningContext.setMetadataRepositories(metadataRepoManager.getKnownRepositories(0));
+ provisioningContext.setArtifactRepositories(artifactRepoManager.getKnownRepositories(0));
+ return provisioningContext;
+ }
+
+ private IMetadataRepository loadMetadataRepository(String sourceRepoLocation, IMetadataRepositoryManager metadataRepoManager)
+ throws URISyntaxException, ProvisionException, OperationCanceledException {
+ IMetadataRepository metadataRepo = metadataRepoManager.loadRepository(new URI(sourceRepoLocation), null);
+ return metadataRepo;
+ }
+
+ private IProfile initialiseTargetP2Profile(String installLocation, String targetProfile, IProvisioningAgent pAgent) throws ProvisionException {
+ IProfileRegistry registry = (IProfileRegistry) pAgent.getService(IProfileRegistry.class.getName());
+
+ Map<String, String> props = new HashMap<String, String>();
+ props.put(IProfile.PROP_INSTALL_FOLDER, installLocation + TARGET_LOCATION_OFFSET);
+ props.put(IProfile.PROP_CACHE, installLocation + TARGET_LOCATION_OFFSET);
+ props.put(IProfile.PROP_CONFIGURATION_FOLDER, installLocation + OSGI_CONFIG_AREA);
+ String env = getEnvironmentProperty();
+ if (env != null) {
+ props.put(IProfile.PROP_ENVIRONMENTS, env);
+ }
+
+ IProfile targetSystemProfile = registry.addProfile(targetProfile, props);
+ return targetSystemProfile;
+ }
+
+ private IProvisioningAgent initialiseProvisioningAgentForInstallLocation(BundleContext bundleContext, String installLocation)
+ throws URISyntaxException, ProvisionException {
+ ServiceReference<IProvisioningAgentProvider> pAgentRef = bundleContext.getServiceReference(IProvisioningAgentProvider.class);
+ IProvisioningAgentProvider pAgentProvider = bundleContext.getService(pAgentRef);
+
+ String agentInstallLocation = createAgentInstallLocation(installLocation);
+
+ IProvisioningAgent pAgent = pAgentProvider.createAgent(new URI(agentInstallLocation));
+ return pAgent;
+ }
+
+ private String createAgentInstallLocation(String installLocation) {
+ // this is done to avoid 'URI not hierarchical' issue as the ProvisioningAgentProvider accepts hierarchical URIs
+ String agentInstallLocation = "file:/" + installLocation;
+ agentInstallLocation = agentInstallLocation + TARGET_LOCATION_OFFSET + P2_FOLDER;
+ return agentInstallLocation;
+ }
+
+ private IStatus executePlan(IProvisioningAgent pAgent, IProvisioningPlan plan) {
+ IEngine engine = (IEngine) pAgent.getService(IEngine.class.getName());
+ IStatus planStatus = plan.getStatus();
+ if (planStatus.getSeverity() == IStatus.ERROR || planStatus.getSeverity() == IStatus.CANCEL) {
+ return planStatus;
+ }
+
+ if (plan.getInstallerPlan() != null) {
+ IStatus installerPlanStatus = engine.perform(plan.getInstallerPlan(), null);
+ if (!installerPlanStatus.isOK()) {
+ return installerPlanStatus;
+ }
+ }
+ return engine.perform(plan, null);
+ }
+
+ private IProvisioningPlan createPlan(IProfile profile, ProvisioningContext provisioningContext, IProvisioningAgent agent,
+ IInstallableUnit[] unitToInstall) {
+ IPlanner planner = (IPlanner) agent.getService(IPlanner.SERVICE_NAME);
+
+ IProfileChangeRequest request = planner.createChangeRequest(profile);
+ if (unitToInstall != null) {
+ request.addAll(Arrays.asList(unitToInstall));
+ }
+
+ return planner.getProvisioningPlan(request, provisioningContext, null);
+ }
+
+ private String getEnvironmentProperty() {
+ HashMap<String, String> values = new HashMap<String, String>();
+ values.put("osgi.os", "all");
+ values.put("osgi.ws", "all");
+ values.put("osgi.arch", "all");
+ return values.isEmpty() ? null : envToString(values);
+ }
+
+ private String envToString(Map<String, String> context) {
+ StringBuffer result = new StringBuffer();
+ for (Map.Entry<String, String> entry : context.entrySet()) {
+ if (result.length() > 0) {
+ result.append(',');
+ }
+ result.append(entry.getKey());
+ result.append('=');
+ result.append(entry.getValue());
+ }
+ return result.toString();
+ }
+
+ private String replaceBackslashesWithSlash(String location) {
+ location = location.replace("\\", "/");
+ return location;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
+ */
+ public void deactivate(ComponentContext bundleContext) throws Exception {
+
+ }
+
+}
diff --git a/org.eclipse.virgo.kernel.build.p2/src/main/resources/OSGI-INF/kernel.build.p2.xml b/org.eclipse.virgo.kernel.build.p2/src/main/resources/OSGI-INF/kernel.build.p2.xml
new file mode 100644
index 00000000..1e3b5c18
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/src/main/resources/OSGI-INF/kernel.build.p2.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0"
+ immediate="true" name="kernel.build.p2">
+ <implementation
+ class="org.eclipse.virgo.kernel.p2.build.VirgoBuildP2RepoPublisher" />
+
+ <reference name="VirgoPublisher"
+ interface="org.eclipse.virgo.kernel.deployer.p2.VirgoPublisher"
+ policy="static"/>
+
+ <reference name="IProvisioningAgent"
+ interface="org.eclipse.equinox.p2.core.IProvisioningAgent"
+ policy="static"/>
+</scr:component>
diff --git a/org.eclipse.virgo.kernel.build.p2/template.mf b/org.eclipse.virgo.kernel.build.p2/template.mf
new file mode 100644
index 00000000..2d80e33f
--- /dev/null
+++ b/org.eclipse.virgo.kernel.build.p2/template.mf
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Virgo Kernel P2 Builder
+Bundle-Version: 3.0.0
+Main-Class: org.eclipse.virgo.kernel.p2.build.Main
+Service-Component: OSGI-INF/kernel.build.p2.xml
+Bundle-SymbolicName: org.eclipse.virgo.kernel.build.p2
+Import-Template: org.eclipse.equinox.internal.p2.artifact.repository.*;version="0",
+ org.eclipse.equinox.p2.core;version="0",
+ org.eclipse.equinox.p2.engine;version="0",
+ org.eclipse.equinox.p2.metadata;version="0",
+ org.eclipse.equinox.p2.planner;version="0",
+ org.eclipse.equinox.p2.query;version="0",
+ org.eclipse.equinox.p2.repository.artifact;version="0",
+ org.eclipse.equinox.p2.repository.metadata;version="0",
+ org.eclipse.virgo.kernel.p2.publisher;version="0",
+ org.osgi.framework;version="0",
+ org.osgi.service.component;version="0",
+ org.eclipse.core.runtime;version="0",
+ org.eclipse.virgo.kernel.deployer.p2;version="0"
+Require-Bundle: org.eclipse.core.runtime;bundle-version="3.7.0"
+Excluded-Exports:
+ *.internal.*

Back to the top