use of java.util.jar.JarInputStream in project OpenAM by OpenRock.
the class CreateSoapSTSDeployment method execute.
@SuppressWarnings("unchecked")
@Override
public String execute(Locale locale, Map mapParams) throws WorkflowException {
try {
validatePresenceOfMandatoryParams(mapParams);
final JarInputStream soapSTSServerWar = getJarInputStream();
final Path outputJarPath = getOutputJarFilePath(getStringParam(mapParams, REALM_PARAM));
final JarOutputStream modifiedSoapSTSServerWar = getJarOutputStream(outputJarPath, soapSTSServerWar.getManifest());
processFileContents(soapSTSServerWar, modifiedSoapSTSServerWar, mapParams);
return getCompletionMessage(locale, outputJarPath);
} catch (WorkflowException e) {
Debug.getInstance("workflow").error("Exception caught in CreateSoapSTSDeployment#execute: " + e.getMessage());
throw e;
}
}
use of java.util.jar.JarInputStream in project OpenAM by OpenRock.
the class CreateFedlet method extractJars.
private void extractJars(ServletContext servletCtx, String workDir) throws WorkflowException {
for (final Map.Entry<String, PrefixSet> jarFilter : jarExtracts.entrySet()) {
final String fileName = jarFilter.getKey();
final PrefixSet pkgNames = jarFilter.getValue();
if (StringUtils.isEmpty(fileName)) {
continue;
}
try (JarInputStream jarInputStream = new JarInputStream(servletCtx.getResourceAsStream(fileName));
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(workDir + fileName))) {
JarEntry entry = jarInputStream.getNextJarEntry();
while (entry != null) {
if (entry.getSize() != 0) {
String name = entry.getName();
if (pkgNames.containsPrefixOf(name)) {
jarOutputStream.putNextEntry(entry);
IOUtils.copyStream(jarInputStream, jarOutputStream);
}
}
entry = jarInputStream.getNextJarEntry();
}
} catch (IOException ex) {
throw new WorkflowException(ex.getMessage());
}
}
}
use of java.util.jar.JarInputStream in project tdi-studio-se by Talend.
the class BuildJobHandlerTest method testBuildJob.
@Test
public void testBuildJob() throws Exception {
Map<ExportChoice, Object> exportChoiceMap = new HashMap<ExportChoice, Object>();
exportChoiceMap.put(ExportChoice.needLauncher, true);
exportChoiceMap.put(ExportChoice.needSystemRoutine, true);
exportChoiceMap.put(ExportChoice.needUserRoutine, true);
exportChoiceMap.put(ExportChoice.needTalendLibraries, true);
exportChoiceMap.put(ExportChoice.needJobItem, false);
exportChoiceMap.put(ExportChoice.needJobScript, true);
exportChoiceMap.put(ExportChoice.needSourceCode, true);
exportChoiceMap.put(ExportChoice.includeLibs, true);
exportChoiceMap.put(ExportChoice.includeTestSource, false);
exportChoiceMap.put(ExportChoice.executeTests, false);
exportChoiceMap.put(ExportChoice.binaries, true);
exportChoiceMap.put(ExportChoice.needContext, true);
exportChoiceMap.put(ExportChoice.contextName, "Default");
exportChoiceMap.put(ExportChoice.applyToChildren, false);
exportChoiceMap.put(ExportChoice.needLog4jLevel, false);
exportChoiceMap.put(ExportChoice.log4jLevel, null);
exportChoiceMap.put(ExportChoice.needDependencies, true);
exportChoiceMap.put(ExportChoice.needParameterValues, false);
destinationPath = ExportJobUtil.getTmpFolderPath() + "/testBuildJob.zip";
BuildJobManager.getInstance().buildJob(destinationPath, processItem, "0.1", "Default", exportChoiceMap, JobExportType.POJO, new NullProgressMonitor());
assertTrue(new File(destinationPath).exists());
ZipFile zip = null;
try {
zip = new ZipFile(destinationPath);
// jobInfo
ZipEntry jobInfoEntry = zip.getEntry("jobInfo.properties");
assertNotNull("Can't find the jobInfo.properties", jobInfoEntry);
final InputStream jobInfoStream = zip.getInputStream(jobInfoEntry);
Properties jobInfoProp = new Properties();
jobInfoProp.load(jobInfoStream);
assertEquals("testBuildJob", jobInfoProp.getProperty("job"));
assertEquals("0.1", jobInfoProp.getProperty("jobVersion"));
assertEquals("Default", jobInfoProp.getProperty("contextName"));
assertEquals("_bWyBUAYbEeapTZ0aKwL_YA", jobInfoProp.getProperty("jobId"));
assertEquals("Standard", jobInfoProp.getProperty("jobType"));
final String technicalLabel = ProjectManager.getInstance().getCurrentProject().getTechnicalLabel();
assertEquals(technicalLabel, jobInfoProp.getProperty("project"));
ZipEntry libEntry = zip.getEntry("lib");
assertNotNull("No lib folder", libEntry);
// log4j
ZipEntry log4jXmlEntry = zip.getEntry("testBuildJob/log4j.xml");
assertNotNull("No log4j.xml", log4jXmlEntry);
// shell+bat
ZipEntry batEntry = zip.getEntry("testBuildJob/testBuildJob_run.bat");
assertNotNull("No bat file", batEntry);
ZipEntry shEntry = zip.getEntry("testBuildJob/testBuildJob_run.sh");
assertNotNull("No shell file", shEntry);
ZipEntry jarEntry = zip.getEntry("testBuildJob/testbuildjob_0_1.jar");
assertNotNull("No shell file", jarEntry);
// src
ZipEntry javaEntry = zip.getEntry("testBuildJob/src/main/java/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/testBuildJob.java");
assertNotNull("No job source code file", javaEntry);
ZipEntry routinesEntry = zip.getEntry("testBuildJob/src/main/java/routines/");
assertNotNull("No routines source code files", routinesEntry);
assertTrue(routinesEntry.isDirectory());
ZipEntry contextEntry = zip.getEntry("testBuildJob/src/main/resources/" + technicalLabel.toLowerCase() + "/testbuildjob_0_1/contexts/Default.properties");
assertNotNull("No context file", contextEntry);
// dq
ZipEntry tdq = zip.getEntry("testBuildJob/items/reports/");
assertNotNull("Can't find the dq reports items", tdq);
assertTrue(tdq.isDirectory());
// if the tdm is load
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITransformService.class)) {
ITransformService tdmService = (ITransformService) GlobalServiceRegister.getDefault().getService(ITransformService.class);
if (tdmService.isTransformItem(processItem)) {
ZipEntry tdmSettingEntry = zip.getEntry("testBuildJob/items/" + technicalLabel.toLowerCase() + "/.settings/com.oaklandsw.base.projectProps");
assertNotNull("Can't export tdm rightly", tdmSettingEntry);
/*
* the __tdm has been moved into job jar. so need test it in jar.
*/
// ZipEntry tdmEntry = zip.getEntry("testBuildJob/__tdm/");
// assertNotNull("Can't export tdm rightly", tdmEntry);
// assertTrue("build job with tdm failure", tdmEntry.isDirectory());
// testbuildjob_0_1.jar!/__tdm/TEST_NOLOGIN.zip
final JarInputStream jarStream = new JarInputStream(zip.getInputStream(jarEntry));
boolean found = false;
JarEntry entry;
while ((entry = jarStream.getNextJarEntry()) != null) {
final String name = entry.getName();
if (name.contains("__tdm") && name.endsWith(technicalLabel + ".zip")) {
found = true;
}
}
jarStream.close();
assertTrue("Can't find the __tdm in job jar after build", found);
}
}
} finally {
if (zip != null) {
zip.close();
}
}
}
use of java.util.jar.JarInputStream in project zm-mailbox by Zimbra.
the class ZimletFile method initialize.
@SuppressWarnings("unchecked")
private void initialize(String name) throws IOException, ZimletException {
if (!name.matches(ZimletUtil.ZIMLET_NAME_REGEX)) {
//so there is no need to try and load a zimlet with a bad name
throw ZimletException.INVALID_ZIMLET_NAME();
}
if (name.endsWith(ZIP_SUFFIX)) {
name = name.substring(0, name.length() - 4);
}
mDescFile = name + XML_SUFFIX;
mEntries = new HashMap<String, ZimletEntry>();
if (mBaseStream != null) {
mCopy = ByteUtil.getContent(mBaseStream, 0);
JarInputStream zis = new JarInputStream(new ByteArrayInputStream(mCopy));
Manifest mf = zis.getManifest();
if (mf != null) {
mDescFile = mf.getMainAttributes().getValue("Zimlet-Description-File");
}
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
if (entry.getSize() > 0)
mEntries.put(entry.getName().toLowerCase(), new ZimletRawEntry(zis, entry.getName(), (int) entry.getSize()));
zis.closeEntry();
entry = zis.getNextEntry();
}
zis.close();
} else if (mBase.isDirectory()) {
addFileEntry(mBase, "");
} else {
JarFile jar = new JarFile(mBase);
Manifest mf = jar.getManifest();
if (mf != null) {
mDescFile = mf.getMainAttributes().getValue("Zimlet-Description-File");
}
Enumeration entries = jar.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
if (entry.getSize() > 0)
mEntries.put(entry.getName().toLowerCase(), new ZimletZipEntry(jar, entry));
}
}
initZimletDescription();
mZimletName = mDesc.getName();
}
use of java.util.jar.JarInputStream in project aries by apache.
the class BundleContextMock method installBundle.
/**
* This method implements the installBundle method from BundleContext. It
* makes use of the java.util.jar package to parse the manifest from the input
* stream.
*
* @param location the location of the bundle.
* @param is the input stream to read from.
* @return the created bundle.
* @throws BundleException
*/
public Bundle installBundle(String location, InputStream is) throws BundleException {
Bundle b;
JarInputStream jis;
try {
jis = new JarInputStream(is);
Manifest man = jis.getManifest();
b = createBundle(man, null);
} catch (IOException e) {
throw new BundleException(e.getMessage(), e);
}
return b;
}
Aggregations