/** * Updates an existing entry in the S-RAMP archive. This method will close the content * {@link InputStream}. * @param entry the archive entry (or null if just udpating the content) * @param content the entry content (or null if just updating meta data) * @throws SrampArchiveException */ public void updateEntry(SrampArchiveEntry entry, InputStream content) throws SrampArchiveException { if (entry.getPath() == null) throw new SrampArchiveException(Messages.i18n.format("INVALID_ENTRY_PATH")); //$NON-NLS-1$ File contentFile = new File(this.workDir, entry.getPath()); File metaDataFile = new File(this.workDir, entry.getPath() + ".atom"); //$NON-NLS-1$ if (content != null) writeContent(contentFile, content); if (entry.getMetaData() != null) { try { SrampArchiveJaxbUtils.writeMetaData(metaDataFile, entry.getMetaData()); } catch (JAXBException e) { throw new SrampArchiveException(e); } } }
/** * Gets a single entry in the archive by path. * @param archivePath the path of the entry within the archive * @return the archive entry, or null if not found */ public SrampArchiveEntry getEntry(String archivePath) { File contentFile = new File(this.workDir, archivePath); File metaDataFile = new File(this.workDir, archivePath + ".atom"); //$NON-NLS-1$ SrampArchiveEntry rval = null; if (metaDataFile.exists()) { rval = new SrampArchiveEntry(archivePath, metaDataFile, contentFile); } return rval; }
/** * Constructor. * @param path * @param metaDataFile * @param contentFile */ public SrampArchiveEntry(String path, File metaDataFile, File contentFile) { setPath(path); setMetaData(null); this.metaDataFile = metaDataFile; this.contentFile = contentFile; }
private void assertXsd( final SrampArchive srampArchive, final String fileEntryPath ) { final SrampArchiveEntry manifestEntry = srampArchive.getEntry(fileEntryPath); assertThat(manifestEntry, is(not(nullValue()))); final BaseArtifactType manifestArtifact = manifestEntry.getMetaData(); assertThat(manifestArtifact, is(instanceOf(XsdDocument.class))); }
/** * Gets the content {@link InputStream} for the given S-RAMP archive entry. * @param entry the s-ramp archive entry * @return an {@link InputStream} over the artifact content or null if no content found (meta-data only) * @throws IOException */ public InputStream getInputStream(SrampArchiveEntry entry) throws IOException { File artifactPath = new File(this.workDir, entry.getPath()); if (artifactPath.exists()) return FileUtils.openInputStream(artifactPath); else return null; }
private void assertManifest( final SrampArchive srampArchive ) { final SrampArchiveEntry manifestEntry = srampArchive.getEntry(VdbManifest.PATH); assertThat(manifestEntry, is(not(nullValue()))); final BaseArtifactType manifestArtifact = manifestEntry.getMetaData(); assertThat(manifestArtifact, is(instanceOf(ExtendedDocument.class))); assertThat(((ExtendedDocument)manifestArtifact).getExtendedType(), is(VdbManifest.ARTIFACT_TYPE.extendedType())); }
/** * Test method for {@link org.overlord.sramp.atom.archive.jar.ZipToSrampArchive.jar.JarToSrampArchive#createSrampArchive()}. */ @Test public void testCreateSrampArchive() throws Exception { InputStream resourceAsStream = ZipToSrampArchiveTest.class.getResourceAsStream("sample-webservice-0.0.1.jar"); //$NON-NLS-1$ ZipToSrampArchive j2sramp = null; SrampArchive archive = null; try { j2sramp = new ZipToSrampArchive(resourceAsStream){}; archive = j2sramp.createSrampArchive(); Assert.assertNotNull(archive); Collection<SrampArchiveEntry> entries = archive.getEntries(); Assert.assertEquals(2, entries.size()); Set<String> paths = new HashSet<String>(); for (SrampArchiveEntry entry : entries) { paths.add(entry.getPath()); } Assert.assertEquals(2, entries.size()); Assert.assertTrue(paths.contains("schema/teetime.xsd")); //$NON-NLS-1$ Assert.assertTrue(paths.contains("wsdl/teetime.wsdl")); //$NON-NLS-1$ } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive); } }
zipOutputStream.putNextEntry(new ZipEntry(entry.getPath())); try { IOUtils.copy(contentStream, zipOutputStream); zipOutputStream.putNextEntry(new ZipEntry(entry.getPath() + ".atom")); //$NON-NLS-1$ try { SrampArchiveJaxbUtils.writeMetaData(zipOutputStream, entry.getMetaData()); } finally {
private void assertModel( final SrampArchive srampArchive, final String modelEntryPath ) { final SrampArchiveEntry manifestEntry = srampArchive.getEntry(modelEntryPath); assertThat(manifestEntry, is(not(nullValue()))); final BaseArtifactType manifestArtifact = manifestEntry.getMetaData(); assertThat(manifestArtifact, is(instanceOf(ExtendedDocument.class))); assertThat(((ExtendedDocument)manifestArtifact).getExtendedType(), is(TeiidArtifactType.MODEL.extendedType())); }
Set<String> paths = new HashSet<String>(); for (SrampArchiveEntry entry : entries) { paths.add(entry.getPath());
/** * Gets all of the entries found in this S-RAMP archive. It does this by scanning the * archive looking for all *.atom files. One entry will be returned for each *.atom * file found in the archive (assuming it has associated content and the *.atom file is * properly formatted). * @throws SrampArchiveException */ public Collection<SrampArchiveEntry> getEntries() throws SrampArchiveException { Collection<File> files = FileUtils.listFiles(workDir, new String[] { "atom" }, true); //$NON-NLS-1$ Collection<SrampArchiveEntry> entries = new ArrayList<SrampArchiveEntry>(files.size()); for (File metaDataFile : files) { String metaDataAbsPath = metaDataFile.getAbsolutePath(); File contentFile = new File(metaDataAbsPath.substring(0, metaDataAbsPath.length() - 5)); String path = contentFile.getAbsolutePath(); path = path.substring(this.workDir.getAbsolutePath().length() + 1); path = path.replace('\\', '/'); // just in case we're in Windows :( entries.add(new SrampArchiveEntry(path, metaDataFile, contentFile)); } return entries; }
/** * Asserts that the s-ramp archive was properly created. * @param archive * @throws SrampArchiveException */ private void doAllAssertions(SrampArchive archive) throws SrampArchiveException { Collection<SrampArchiveEntry> entries = archive.getEntries(); // Make sure all the entries we expect to be there are there. TreeSet<String> entryNames = new TreeSet<String>(); for (SrampArchiveEntry srampArchiveEntry : entries) { entryNames.add(srampArchiveEntry.getPath()); } StringBuilder buff = new StringBuilder(); for (String entryName : entryNames) { buff.append(entryName).append("\n"); //$NON-NLS-1$ } Assert.assertEquals(EXPECTED_ENTRIES, buff.toString()); // Now spot-check some representative entries. // Check the kmodule.xml SrampArchiveEntry entry = archive.getEntry("META-INF/kmodule.xml"); //$NON-NLS-1$ Assert.assertNotNull(entry); Assert.assertEquals("kmodule.xml", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, entry.getMetaData().getArtifactType()); ExtendedDocument kieXmlDoc = (ExtendedDocument) entry.getMetaData(); Assert.assertEquals(KieJarModel.KieXmlDocument, kieXmlDoc.getExtendedType()); }
/** * Test method for {@link org.overlord.sramp.atom.archive.jar.ZipToSrampArchive.jar.JarToSrampArchive#createSrampArchive()}. */ @Test public void testMetaData() throws Exception { InputStream resourceAsStream = ZipToSrampArchiveTest.class.getResourceAsStream("sample-webservice-0.0.1.jar"); //$NON-NLS-1$ ZipToSrampArchive j2sramp = null; SrampArchive archive = null; try { j2sramp = new ZipToSrampArchive(resourceAsStream){}; archive = j2sramp.createSrampArchive(); Assert.assertNotNull(archive); SrampArchiveEntry entry = archive.getEntry("schema/teetime.xsd"); //$NON-NLS-1$ Assert.assertNotNull(entry); BaseArtifactType metaData = entry.getMetaData(); Assert.assertNotNull(metaData); Assert.assertTrue(metaData instanceof XsdDocument); XsdDocument md = (XsdDocument) metaData; Assert.assertEquals("teetime.xsd", md.getName()); //$NON-NLS-1$ Assert.assertNotNull(md.getUuid()); } finally { ZipToSrampArchive.closeQuietly(j2sramp); SrampArchive.closeQuietly(archive); } }
Assert.assertEquals(1, entries.size()); SrampArchiveEntry entry = entries.iterator().next(); Assert.assertEquals("simple-sramp-archive/sample.xsd", entry.getPath()); //$NON-NLS-1$ Assert.assertNotNull(entry.getMetaData()); Assert.assertEquals("d658b181-975c-42c5-ad5c-dc65cb9aa4a1", entry.getMetaData().getUuid()); //$NON-NLS-1$ Assert.assertEquals("sample.xsd", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals("1.0", entry.getMetaData().getVersion()); //$NON-NLS-1$ } finally { FileUtils.deleteQuietly(tempFile);
SrampArchiveEntry entry = archive.getEntry("schema/teetime.xsd"); //$NON-NLS-1$ Assert.assertNotNull(entry); BaseArtifactType metaData = entry.getMetaData(); Assert.assertNotNull(metaData); Assert.assertTrue(metaData instanceof Document);
entryNames.add(srampArchiveEntry.getPath()); Assert.assertEquals("switchyard.xml", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, entry.getMetaData().getArtifactType()); ExtendedDocument switchyardXmlDoc = (ExtendedDocument) entry.getMetaData(); Assert.assertEquals(SwitchYardModel.SwitchYardXmlDocument, switchyardXmlDoc.getExtendedType()); Assert.assertEquals("InventoryService.class", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.EXTENDED_DOCUMENT, entry.getMetaData().getArtifactType()); ExtendedDocument inventoryServiceClass = (ExtendedDocument) entry.getMetaData(); Assert.assertEquals("JavaClass", inventoryServiceClass.getExtendedType()); //$NON-NLS-1$ Assert.assertEquals("OrderService.wsdl", entry.getMetaData().getName()); //$NON-NLS-1$ Assert.assertEquals(BaseArtifactEnum.WSDL_DOCUMENT, entry.getMetaData().getArtifactType());
Map<String, SrampArchiveEntry> entryMap = new HashMap<String, SrampArchiveEntry>(); for (SrampArchiveEntry entry : entries) entryMap.put(entry.getPath(), entry); XsdDocument sampleXsdMetaData = (XsdDocument) entryMap.get("sample/sample.xsd").getMetaData(); //$NON-NLS-1$ Assert.assertNotNull(sampleXsdMetaData); Assert.assertEquals("sample.xsd", sampleXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("Just a sample XML Schema.", sampleXsdMetaData.getDescription()); //$NON-NLS-1$ XsdDocument poXsdMetaData = (XsdDocument) entryMap.get("sample/PO.xsd").getMetaData(); //$NON-NLS-1$ Assert.assertNotNull(poXsdMetaData); Assert.assertEquals("PO.xsd", poXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("The Purchase Order schema.", poXsdMetaData.getDescription()); //$NON-NLS-1$ XsdDocument coremodelXsdMetaData = (XsdDocument) entryMap.get("s-ramp/coremodel.xsd").getMetaData(); //$NON-NLS-1$ Assert.assertNotNull(coremodelXsdMetaData); Assert.assertEquals("coremodel.xsd", coremodelXsdMetaData.getName()); //$NON-NLS-1$ Assert.assertEquals("S-RAMP core schema.", coremodelXsdMetaData.getDescription()); //$NON-NLS-1$ XsdDocument xlinkXsdMetaData = (XsdDocument) entryMap.get("s-ramp/xlink.xsd").getMetaData(); //$NON-NLS-1$ Assert.assertNotNull(xlinkXsdMetaData); Assert.assertEquals("xlink.xsd", xlinkXsdMetaData.getName()); //$NON-NLS-1$