Search in sources :

Example 1 with PathElement

use of org.activiti.osgi.HeaderParser.PathElement in project Activiti by Activiti.

the class Extender method checkBundle.

private void checkBundle(Bundle bundle) {
    LOGGER.debug("Scanning bundle {} for activiti process", bundle.getSymbolicName());
    try {
        List<URL> pathList = new ArrayList<URL>();
        String activitiHeader = (String) bundle.getHeaders().get(BUNDLE_ACTIVITI_HEADER);
        if (activitiHeader == null) {
            activitiHeader = "OSGI-INF/activiti/";
        }
        List<PathElement> paths = HeaderParser.parseHeader(activitiHeader);
        for (PathElement path : paths) {
            String name = path.getName();
            if (name.endsWith("/")) {
                addEntries(bundle, name, "*.*", pathList);
            } else {
                String baseName;
                String filePattern;
                int pos = name.lastIndexOf('/');
                if (pos < 0) {
                    baseName = "/";
                    filePattern = name;
                } else {
                    baseName = name.substring(0, pos + 1);
                    filePattern = name.substring(pos + 1);
                }
                if (hasWildcards(filePattern)) {
                    addEntries(bundle, baseName, filePattern, pathList);
                } else {
                    addEntry(bundle, name, pathList);
                }
            }
        }
        if (!pathList.isEmpty()) {
            LOGGER.debug("Found activiti process in bundle {} with paths: {}", bundle.getSymbolicName(), pathList);
            ProcessEngine engine = (ProcessEngine) engineServiceTracker.waitForService(timeout);
            if (engine == null) {
                throw new IllegalStateException("Unable to find a ProcessEngine service");
            }
            RepositoryService service = engine.getRepositoryService();
            DeploymentBuilder builder = service.createDeployment();
            builder.name(bundle.getSymbolicName());
            for (URL url : pathList) {
                InputStream is = url.openStream();
                if (is == null) {
                    throw new IOException("Error opening url: " + url);
                }
                try {
                    builder.addInputStream(getPath(url), is);
                } finally {
                    is.close();
                }
            }
            builder.enableDuplicateFiltering();
            builder.deploy();
        } else {
            LOGGER.debug("No activiti process found in bundle {}", bundle.getSymbolicName());
        }
    } catch (Throwable t) {
        LOGGER.error("Unable to deploy activiti bundle", t);
    }
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URL(java.net.URL) PathElement(org.activiti.osgi.HeaderParser.PathElement) DeploymentBuilder(org.activiti.engine.repository.DeploymentBuilder) ProcessEngine(org.activiti.engine.ProcessEngine) RepositoryService(org.activiti.engine.RepositoryService)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 ProcessEngine (org.activiti.engine.ProcessEngine)1 RepositoryService (org.activiti.engine.RepositoryService)1 DeploymentBuilder (org.activiti.engine.repository.DeploymentBuilder)1 PathElement (org.activiti.osgi.HeaderParser.PathElement)1