private List<File> getMatchingFiles(final File baseDir, final String extension) { final List<File> files = new ArrayList<File>(); this.getMatchingFiles(baseDir, files, extension); return files; }
private void getMatchingFiles(final File dir, final List<File> matchingFiles, final String extension) { for (final File f : dir.listFiles()) { if (f.getName().endsWith(extension)) { matchingFiles.add(f); } else if (f.isDirectory()) { this.getMatchingFiles(f, matchingFiles, extension); } } }
private Set<byte[]> getClasses(final File tmpDir) throws DeploymentException { if (ManagementAPIImpl.LOG.isLoggable(Level.FINE)) { ManagementAPIImpl.LOG.fine("Looking for datas in directory: " + tmpDir); } final List<File> classFiles = this.getMatchingFiles(tmpDir, ".class"); final Set<byte[]> classes = new HashSet<byte[]>(); try { for (final File classFile : classFiles) { final String className = this.getClassName(classFile, tmpDir); final URL classURL = classFile.toURL(); if (ManagementAPIImpl.LOG.isLoggable(Level.FINE)) { ManagementAPIImpl.LOG.fine("Found class: " + className + " with URL: " + classURL); } classes.add(Misc.getAllContentFrom(classURL)); } } catch (final IOException e) { throw new DeploymentException("Error when getting classDatas at deployment ", e); } return classes; }
private Map<String, ProcessDefinition> deployArchive(final byte[] barFile) throws DeploymentException { File tmpDir = null; Map<String, ProcessDefinition> processes = null; try { tmpDir = this.explodeArchive(barFile, "tmpBonitaBar"); final List<File> xpdlFiles = this.getMatchingFiles(tmpDir, ".xpdl"); if (xpdlFiles.isEmpty()) { throw new DeploymentException("The given bar archive does not contain any '.xpdl' file"); } if (xpdlFiles.size() > 1) { throw new DeploymentException("The given bar archive contains many '.xpdl' files"); } URL xpdlURL; try { xpdlURL = xpdlFiles.get(0).toURL(); if (ManagementAPIImpl.LOG.isLoggable(Level.FINE)) { ManagementAPIImpl.LOG.fine("Xpdl file currently deployed: " + xpdlURL); } } catch (final MalformedURLException e) { throw new DeploymentException("Error when deploying the bar file", e); } processes = this.deploy(new Deployment(xpdlURL, this.getClasses(tmpDir))); } finally { if (tmpDir != null) { Misc.deleteDir(tmpDir); } } return processes; }