Search in sources :

Example 1 with BundleFile

use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.

the class DevClassLoadingHook method findFragmentSource.

private Generation findFragmentSource(Generation hostGeneration, String cp, ClasspathManager manager, boolean fromFragment) {
    if (hostGeneration != manager.getGeneration())
        return hostGeneration;
    File file = new File(cp);
    if (!file.isAbsolute())
        return hostGeneration;
    FragmentClasspath[] fragCP = manager.getFragmentClasspaths();
    for (int i = 0; i < fragCP.length; i++) {
        BundleFile fragBase = fragCP[i].getGeneration().getBundleFile();
        File fragFile = fragBase.getBaseFile();
        if (fragFile != null && file.getPath().startsWith(fragFile.getPath()))
            return fragCP[i].getGeneration();
    }
    return fromFragment ? null : hostGeneration;
}
Also used : BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) File(java.io.File)

Example 2 with BundleFile

use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.

the class SignatureBlockProcessor method process.

public SignedContentImpl process() throws IOException, InvalidKeyException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException {
    BundleFile wrappedBundleFile = signedBundle.getBundleFile();
    BundleEntry be = wrappedBundleFile.getEntry(META_INF_MANIFEST_MF);
    if (be == null)
        return createUnsignedContent();
    // read all the signature block file names into a list
    Enumeration<String> en = wrappedBundleFile.getEntryPaths(META_INF);
    List<String> signers = new ArrayList<>(2);
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        if ((name.endsWith(DOT_DSA) || name.endsWith(DOT_RSA)) && name.indexOf('/') == name.lastIndexOf('/'))
            signers.add(name);
    }
    // this means the jar is not signed
    if (signers.size() == 0)
        return createUnsignedContent();
    byte[] manifestBytes = readIntoArray(be);
    for (Iterator<String> iSigners = signers.iterator(); iSigners.hasNext(); ) processSigner(wrappedBundleFile, manifestBytes, iSigners.next());
    // done processing now create a SingedContent to return
    SignerInfo[] allSigners = signerInfos.toArray(new SignerInfo[signerInfos.size()]);
    for (Iterator<Map.Entry<String, Object>> iResults = contentMDResults.entrySet().iterator(); iResults.hasNext(); ) {
        Map.Entry<String, Object> entry = iResults.next();
        @SuppressWarnings("unchecked") List<Object>[] value = (List<Object>[]) entry.getValue();
        SignerInfo[] entrySigners = value[0].toArray(new SignerInfo[value[0].size()]);
        byte[][] entryResults = value[1].toArray(new byte[value[1].size()][]);
        entry.setValue(new Object[] { entrySigners, entryResults });
    }
    SignedContentImpl result = new SignedContentImpl(allSigners, (supportFlags & SignedBundleHook.VERIFY_RUNTIME) != 0 ? contentMDResults : null);
    result.setContent(signedBundle);
    result.setTSASignerInfos(tsaSignerInfos);
    return result;
}
Also used : BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry) SignerInfo(org.eclipse.osgi.signedcontent.SignerInfo) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile)

Example 3 with BundleFile

use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.

the class Storage method createBundleFile.

public BundleFile createBundleFile(File content, Generation generation, boolean isDirectory, boolean isBase) {
    BundleFile result;
    try {
        if (isDirectory) {
            boolean strictPath = Boolean.parseBoolean(equinoxContainer.getConfiguration().getConfiguration(EquinoxConfiguration.PROPERTY_STRICT_BUNDLE_ENTRY_PATH, Boolean.FALSE.toString()));
            result = new DirBundleFile(content, strictPath);
        } else {
            result = new ZipBundleFile(content, generation, mruList, getConfiguration().getDebug());
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        throw new RuntimeException("Could not create bundle file.", e);
    }
    return wrapBundleFile(result, generation, isBase);
}
Also used : ZipBundleFile(org.eclipse.osgi.storage.bundlefile.ZipBundleFile) IOException(java.io.IOException) NestedDirBundleFile(org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile) ZipBundleFile(org.eclipse.osgi.storage.bundlefile.ZipBundleFile) DirBundleFile(org.eclipse.osgi.storage.bundlefile.DirBundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) NestedDirBundleFile(org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile) DirBundleFile(org.eclipse.osgi.storage.bundlefile.DirBundleFile)

Example 4 with BundleFile

use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.

the class Storage method findEntries.

public static Enumeration<URL> findEntries(List<Generation> generations, String path, String filePattern, int options) {
    List<BundleFile> bundleFiles = new ArrayList<>(generations.size());
    for (Generation generation : generations) bundleFiles.add(generation.getBundleFile());
    // search all the bundle files
    List<String> pathList = listEntryPaths(bundleFiles, path, filePattern, options);
    // return null if no entries found
    if (pathList.size() == 0)
        return null;
    // create an enumeration to enumerate the pathList
    final String[] pathArray = pathList.toArray(new String[pathList.size()]);
    final Generation[] generationArray = generations.toArray(new Generation[generations.size()]);
    return new Enumeration<URL>() {

        private int curPathIndex = 0;

        private int curDataIndex = 0;

        private URL nextElement = null;

        public boolean hasMoreElements() {
            if (nextElement != null)
                return true;
            getNextElement();
            return nextElement != null;
        }

        public URL nextElement() {
            if (!hasMoreElements())
                throw new NoSuchElementException();
            URL result = nextElement;
            // force the next element search
            getNextElement();
            return result;
        }

        private void getNextElement() {
            nextElement = null;
            if (curPathIndex >= pathArray.length)
                // reached the end of the pathArray; no more elements
                return;
            while (nextElement == null && curPathIndex < pathArray.length) {
                String curPath = pathArray[curPathIndex];
                // search the generation until we have searched them all
                while (nextElement == null && curDataIndex < generationArray.length) nextElement = generationArray[curDataIndex++].getEntry(curPath);
                // we have searched all datas then advance to the next path
                if (curDataIndex >= generationArray.length) {
                    curPathIndex++;
                    curDataIndex = 0;
                }
            }
        }
    };
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) NestedDirBundleFile(org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile) ZipBundleFile(org.eclipse.osgi.storage.bundlefile.ZipBundleFile) DirBundleFile(org.eclipse.osgi.storage.bundlefile.DirBundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) URL(java.net.URL) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with BundleFile

use of org.eclipse.osgi.storage.bundlefile.BundleFile in project rt.equinox.framework by eclipse.

the class Storage method listEntryPaths.

/**
 * Returns the names of resources available from a list of bundle files.
 * No duplicate resource names are returned, each name is unique.
 * @param bundleFiles the list of bundle files to search in
 * @param path The path name in which to look.
 * @param filePattern The file name pattern for selecting resource names in
 *        the specified path.
 * @param options The options for listing resource names.
 * @return a list of resource names.  If no resources are found then
 * the empty list is returned.
 * @see BundleWiring#listResources(String, String, int)
 */
public static List<String> listEntryPaths(List<BundleFile> bundleFiles, String path, String filePattern, int options) {
    // Use LinkedHashSet for optimized performance of contains() plus
    // ordering guarantees.
    LinkedHashSet<String> pathList = new LinkedHashSet<>();
    Filter patternFilter = null;
    Hashtable<String, String> patternProps = null;
    if (filePattern != null) {
        // Avoid pattern matching and use BundleFile.getEntry() if recursion was not requested.
        if ((options & BundleWiring.FINDENTRIES_RECURSE) == 0 && filePattern.indexOf('*') == -1 && filePattern.indexOf('\\') == -1) {
            if (path.length() == 0)
                path = filePattern;
            else
                path += path.charAt(path.length() - 1) == '/' ? filePattern : '/' + filePattern;
            for (BundleFile bundleFile : bundleFiles) {
                if (bundleFile.getEntry(path) != null && !pathList.contains(path))
                    pathList.add(path);
            }
            return new ArrayList<>(pathList);
        }
        // For when the file pattern includes a wildcard.
        try {
            // create a file pattern filter with 'filename' as the key
            // $NON-NLS-1$ //$NON-NLS-2$
            patternFilter = FilterImpl.newInstance("(filename=" + sanitizeFilterInput(filePattern) + ")");
            // create a single hashtable to be shared during the recursive search
            patternProps = new Hashtable<>(2);
        } catch (InvalidSyntaxException e) {
            // eventPublisher.publishFrameworkEvent(FrameworkEvent.ERROR, b, e);
            return new ArrayList<>(pathList);
        }
    }
    // find the entry paths for the datas
    for (BundleFile bundleFile : bundleFiles) {
        listEntryPaths(bundleFile, path, patternFilter, patternProps, options, pathList);
    }
    return new ArrayList<>(pathList);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Filter(org.osgi.framework.Filter) ArrayList(java.util.ArrayList) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) NestedDirBundleFile(org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile) ZipBundleFile(org.eclipse.osgi.storage.bundlefile.ZipBundleFile) DirBundleFile(org.eclipse.osgi.storage.bundlefile.DirBundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile)

Aggregations

BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)13 File (java.io.File)7 ArrayList (java.util.ArrayList)5 BundleEntry (org.eclipse.osgi.storage.bundlefile.BundleEntry)5 IOException (java.io.IOException)3 URL (java.net.URL)3 DirBundleFile (org.eclipse.osgi.storage.bundlefile.DirBundleFile)3 NestedDirBundleFile (org.eclipse.osgi.storage.bundlefile.NestedDirBundleFile)3 ZipBundleFile (org.eclipse.osgi.storage.bundlefile.ZipBundleFile)3 InputStream (java.io.InputStream)2 MalformedURLException (java.net.MalformedURLException)2 URLClassLoader (java.net.URLClassLoader)2 LinkedHashSet (java.util.LinkedHashSet)2 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Closeable (java.io.Closeable)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1