private File transformArtifact()

in filemonitor/src/main/java/org/apache/servicemix/kernel/filemonitor/FileMonitor.java [330:371]


    private File transformArtifact(File file) throws Exception {
        // Check registered deployers
        ServiceReference[] srvRefs = getContext().getAllServiceReferences(DeploymentListener.class.getName(),
                                                                          null);
        if (srvRefs != null) {
            for (ServiceReference sr : srvRefs) {
                try {
                    DeploymentListener deploymentListener = (DeploymentListener)getContext().getService(sr);
                    if (deploymentListener.canHandle(file)) {
                        File transformedFile = deploymentListener.handle(file, getGenerateDir());
                        artifactToBundle.put(file.getAbsolutePath(), transformedFile.getAbsolutePath());
                        return transformedFile;
                    }
                } finally {
                    getContext().ungetService(sr);
                }
            }
        }
        JarFile jar = null;
        try {
            // Handle OSGi bundles with the default deployer
            if (file.getName().endsWith("txt") || file.getName().endsWith("xml")
                || file.getName().endsWith("properties")) {
                // that's file type which is not supported as bundle and avoid
                // exception in the log
                return null;
            }
            jar = new JarFile(file);
            Manifest m = jar.getManifest();
            if (m.getMainAttributes().getValue(new Attributes.Name("Bundle-SymbolicName")) != null
                && m.getMainAttributes().getValue(new Attributes.Name("Bundle-Version")) != null) {
                return file;
            }
        } catch (Exception e) {
            LOGGER.debug("Error transforming artifact " + file.getName(), e);
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
        return null;
    }