Search in sources :

Example 26 with JarInputStream

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;
    }
}
Also used : Path(java.nio.file.Path) JarInputStream(java.util.jar.JarInputStream) JarOutputStream(java.util.jar.JarOutputStream)

Example 27 with JarInputStream

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());
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) SimplePrefixSet(org.forgerock.openam.utils.collections.SimplePrefixSet) PrefixSet(org.forgerock.openam.utils.collections.PrefixSet) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 28 with JarInputStream

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();
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ITransformService(org.talend.core.service.ITransformService) HashMap(java.util.HashMap) JarInputStream(java.util.jar.JarInputStream) JarInputStream(java.util.jar.JarInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) Properties(java.util.Properties) JarEntry(java.util.jar.JarEntry) ZipFile(java.util.zip.ZipFile) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ZipFile(java.util.zip.ZipFile) File(java.io.File) Test(org.junit.Test)

Example 29 with JarInputStream

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();
}
Also used : Enumeration(java.util.Enumeration) JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipEntry(java.util.zip.ZipEntry) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile)

Example 30 with JarInputStream

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;
}
Also used : JarInputStream(java.util.jar.JarInputStream) Bundle(org.osgi.framework.Bundle) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException) Manifest(java.util.jar.Manifest)

Aggregations

JarInputStream (java.util.jar.JarInputStream)154 JarEntry (java.util.jar.JarEntry)72 IOException (java.io.IOException)66 FileInputStream (java.io.FileInputStream)63 Manifest (java.util.jar.Manifest)50 File (java.io.File)46 InputStream (java.io.InputStream)45 ZipEntry (java.util.zip.ZipEntry)29 JarOutputStream (java.util.jar.JarOutputStream)27 FileOutputStream (java.io.FileOutputStream)24 ByteArrayInputStream (java.io.ByteArrayInputStream)22 URL (java.net.URL)20 Test (org.junit.Test)20 OutputStream (java.io.OutputStream)13 JarFile (java.util.jar.JarFile)13 BufferedInputStream (java.io.BufferedInputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ArrayList (java.util.ArrayList)10 Attributes (java.util.jar.Attributes)10 HashSet (java.util.HashSet)8