private void setArtifactResourceProcessor(String processorPID) { // Not explicitly mentioned in the spec, but just to be sure... m_processorPID = removeParameters(processorPID); } }
/** * Adds a bundle to the deployment package. * * @param url * a url that refers to the bundle * @return a builder to further add data to the deployment package * @throws Exception * if something goes wrong while building */ public DeploymentPackageBuilder addBundle(URL url) throws Exception { return addBundleArtifact(url, false); }
/** * Creates a new deployment package. * * @param name * the name of the deployment package * @param version * the version of the deployment package * @return a builder to further add data to the deployment package */ public static DeploymentPackageBuilder createDeploymentPackage(String name, String version) { return new DeploymentPackageBuilder(name, version); }
@Test() public void testCreateBundleWithoutParametersOk() throws Exception { ArtifactData artifact = ArtifactData.createBundle(m_fakeURL, m_filename, "my.bundle.name", "1.0.0"); assertNotNull(artifact); assertEquals(artifact.getSymbolicName(), "my.bundle.name"); assertEquals(artifact.getVersion(), "1.0.0"); assertNull(artifact.getProcessorPid()); assertFalse(artifact.isCustomizer()); assertTrue(artifact.isBundle()); }
@Test() public void testCreateResourceProcessorWithParametersOk() throws Exception { ArtifactData artifact = ArtifactData.createResourceProcessor(m_fakeURL, m_filename, "my.bundle.name;singleton:=true, foo:=bar", "1.0.0", "rp;qux:=quu"); assertNotNull(artifact); assertEquals(artifact.getSymbolicName(), "my.bundle.name"); assertEquals(artifact.getVersion(), "1.0.0"); assertEquals(artifact.getProcessorPid(), "rp"); assertTrue(artifact.isCustomizer()); assertTrue(artifact.isBundle()); } }
@Test() public void testCreateArtifactWithoutParametersOk() throws Exception { ArtifactData artifact = ArtifactData.createArtifact(m_fakeURL, m_filename, "rp"); assertNotNull(artifact); assertNull(artifact.getSymbolicName()); assertNull(artifact.getVersion()); assertEquals(artifact.getProcessorPid(), "rp"); assertFalse(artifact.isCustomizer()); assertFalse(artifact.isBundle()); }
@Test() public void testSingleBundleDeploymentPackage() throws Exception { File tempFile = File.createTempFile("output-", ".jar"); FileOutputStream output = new FileOutputStream(tempFile); String name = "test"; String version = "1.0.0"; String bundleSymbolicName = "bundle"; String bundleVersion = "1.0.0"; File tempBundleFile = File.createTempFile(bundleSymbolicName + "-" + bundleVersion + "-", ".jar"); DeploymentPackageBuilder.createDeploymentPackage(name, version) .addBundle(createBundle(bundleSymbolicName, bundleVersion, tempBundleFile)) .generate(output); // the deployment package should have a name and a version, and a single entry (our bundle) Manifest m = getManifest(tempFile); Assert.assertEquals(name, m.getMainAttributes().getValue("DeploymentPackage-SymbolicName")); Assert.assertEquals(version, m.getMainAttributes().getValue("DeploymentPackage-Version")); Assert.assertEquals(1, m.getEntries().size()); contains(m.getEntries().values(), "Bundle-SymbolicName", bundleSymbolicName, "Bundle-Version", bundleVersion); }
@Test(expectedExceptions = { Exception.class }) public void testResourceWithoutProcessorDeploymentPackage() throws Exception { File tempFile = File.createTempFile("output-", ".jar"); FileOutputStream output = new FileOutputStream(tempFile); String name = "test"; String version = "1.0.0"; String pid = "my.processor"; File tempArtifactFile = File.createTempFile("artifact-", ".jar"); DeploymentPackageBuilder.createDeploymentPackage(name, version) .addArtifact(createArtifact(pid, tempArtifactFile), pid) .generate(output); }
public static ArtifactData createResourceProcessor(URL url, String filename, String bundleSymbolicName, String bundleVersion, String processorPID) { ArtifactData data = new ArtifactData(url, filename); data.setBundleMetadata(bundleSymbolicName, bundleVersion); data.setResourceProcessor(processorPID); return data; }
private void validateArtifacts() throws Exception { for (ArtifactData data : m_artifacts) { String pid = data.getProcessorPid(); boolean found = false; for (ArtifactData processor : m_processors) { if (pid.equals(processor.getProcessorPid())) { found = true; break; } } if (!found) { throw new Exception("No resource processor found for artifact " + data.getURL() + " with processor PID " + pid); } } }
/** * Generates a deployment package and streams it to the output stream you provide. Before it starts generating, it * will first validate that you have actually specified a resource processor for each type of artifact you provided. * * @param output * the output stream to write to * @throws Exception * if something goes wrong while validating or generating */ public void generate(OutputStream output) throws Exception { validateArtifacts(); List<ArtifactData> artifacts = new ArrayList<>(); artifacts.addAll(m_bundles); artifacts.addAll(m_processors); artifacts.addAll(m_artifacts); Manifest m = createManifest(artifacts); writeStream(artifacts, m, output); }
/** * Adds an artifact to the deployment package. * * @param url * a url that refers to the artifact * @param processorPID * the PID of the processor for this artifact * @return a builder to further add data to the deployment package * @throws Exception * if something goes wrong while building */ public DeploymentPackageBuilder addArtifact(URL url, String processorPID) throws Exception { String path = url.getPath(); int i = path.lastIndexOf('/'); if (i > 0 && i < (path.length() - 1)) { path = path.substring(i + 1); } String name = PREFIX_ARTIFACT + getUniqueID() + "-" + path; m_artifacts.add(ArtifactData.createArtifact(url, name, processorPID)); return this; }
@Test() public void testEmptyDeploymentPackage() throws Exception { File tempFile = File.createTempFile("output-", ".jar"); System.out.println("File: " + tempFile); FileOutputStream output = new FileOutputStream(tempFile); String name = "test"; String version = "1.0.0"; DeploymentPackageBuilder.createDeploymentPackage(name, version).generate(output); Manifest m = getManifest(tempFile); // the deployment package should have just a name and a version, but no entries Assert.assertEquals(name, m.getMainAttributes().getValue("DeploymentPackage-SymbolicName")); Assert.assertEquals(version, m.getMainAttributes().getValue("DeploymentPackage-Version")); Assert.assertTrue(m.getEntries().isEmpty()); }
public static ArtifactData createBundle(URL url, String filename, String bundleSymbolicName, String bundleVersion) { ArtifactData data = new ArtifactData(url, filename); data.setBundleMetadata(bundleSymbolicName, bundleVersion); return data; }
public static ArtifactData createArtifact(URL url, String filename, String processorPID) { ArtifactData data = new ArtifactData(url, filename); data.setArtifactResourceProcessor(processorPID); return data; }
@Test() public void testCreateBundleWithParametersOk() throws Exception { ArtifactData artifact = ArtifactData.createBundle(m_fakeURL, m_filename, "my.bundle.name;singleton:=true, foo:=bar", "1.0.0"); assertNotNull(artifact); assertEquals(artifact.getSymbolicName(), "my.bundle.name"); assertEquals(artifact.getVersion(), "1.0.0"); assertNull(artifact.getProcessorPid()); assertFalse(artifact.isCustomizer()); assertTrue(artifact.isBundle()); }
@Test() public void testCreateResourceProcessorWithoutParametersOk() throws Exception { ArtifactData artifact = ArtifactData.createResourceProcessor(m_fakeURL, m_filename, "my.bundle.name", "1.0.0", "rp"); assertNotNull(artifact); assertEquals(artifact.getSymbolicName(), "my.bundle.name"); assertEquals(artifact.getVersion(), "1.0.0"); assertEquals(artifact.getProcessorPid(), "rp"); assertTrue(artifact.isCustomizer()); assertTrue(artifact.isBundle()); }
private void setBundleMetadata(String bundleSymbolicName, String bundleVersion) { m_isBundle = true; // See OSGi spec, section 3.5.2 (v4.2)... m_bundleSymbolicName = removeParameters(bundleSymbolicName); m_bundleVersion = bundleVersion; }
/** * Adds a resource processor to the deployment package. A resource processor is a special type of bundle. * * @param url * a url that refers to the resource processor * @return a builder to further add data to the deployment package * @throws Exception * if something goes wrong while building */ public DeploymentPackageBuilder addResourceProcessor(URL url) throws Exception { return addBundleArtifact(url, true); }
private void setResourceProcessor(String processorPID) { m_isCustomizer = true; // Not explicitly mentioned in the spec, but just to be sure... m_processorPID = removeParameters(processorPID); }