Search in sources :

Example 1 with ProcessEngineInfo

use of org.camunda.bpm.engine.ProcessEngineInfo in project camunda-bpm-platform by camunda.

the class DeployBarTask method getErrorMessage.

private String getErrorMessage(List<ProcessEngineInfo> processEngineInfos, String name) {
    StringBuilder builder = new StringBuilder("Could not find a process engine with name ");
    builder.append(name).append(", engines loaded:\n");
    for (ProcessEngineInfo engineInfo : processEngineInfos) {
        String engineName = (engineInfo.getName() != null) ? engineInfo.getName() : "unknown";
        builder.append("Process engine name: ").append(engineName);
        builder.append(" - resource: ").append(engineInfo.getResourceUrl());
        builder.append(" - status: ");
        if (engineInfo.getException() != null) {
            builder.append("Error while initializing engine. ");
            if (engineInfo.getException().indexOf("driver on UnpooledDataSource") != -1) {
                builder.append("Exception while initializing process engine! Database or database driver might not have been configured correctly.").append("Please consult the user guide for supported database environments or build.properties. Stacktrace: ").append(engineInfo.getException());
            } else {
                builder.append("Stacktrace: ").append(engineInfo.getException());
            }
        } else {
            // Process engine initialised without exception
            builder.append("Initialised");
        }
        builder.append("\n");
    }
    return builder.toString();
}
Also used : ProcessEngineInfo(org.camunda.bpm.engine.ProcessEngineInfo)

Example 2 with ProcessEngineInfo

use of org.camunda.bpm.engine.ProcessEngineInfo in project camunda-bpm-platform by camunda.

the class DeployBarTask method execute.

public void execute() throws BuildException {
    List<File> files = new ArrayList<File>();
    if (file != null) {
        files.add(file);
    }
    if (fileSets != null) {
        for (FileSet fileSet : fileSets) {
            DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(getProject());
            File baseDir = directoryScanner.getBasedir();
            String[] includedFiles = directoryScanner.getIncludedFiles();
            String[] excludedFiles = directoryScanner.getExcludedFiles();
            List<String> excludedFilesList = Arrays.asList(excludedFiles);
            for (String includedFile : includedFiles) {
                if (!excludedFilesList.contains(includedFile)) {
                    files.add(new File(baseDir, includedFile));
                }
            }
        }
    }
    Thread currentThread = Thread.currentThread();
    ClassLoader originalClassLoader = currentThread.getContextClassLoader();
    currentThread.setContextClassLoader(DeployBarTask.class.getClassLoader());
    LogUtil.readJavaUtilLoggingConfigFromClasspath();
    try {
        log("Initializing process engine " + processEngineName);
        ProcessEngines.init();
        ProcessEngine processEngine = ProcessEngines.getProcessEngine(processEngineName);
        if (processEngine == null) {
            List<ProcessEngineInfo> processEngineInfos = ProcessEngines.getProcessEngineInfos();
            if (processEngineInfos != null && processEngineInfos.size() > 0) {
                // Since no engine with the given name is found, we can't be 100% sure which ProcessEngineInfo
                // is causing the error. We should show ALL errors and process engine names / resource URL's.
                String message = getErrorMessage(processEngineInfos, processEngineName);
                throw new ProcessEngineException(message);
            } else
                throw new ProcessEngineException("Could not find a process engine with name '" + processEngineName + "', no engines found. " + "Make sure an engine configuration is present on the classpath");
        }
        RepositoryService repositoryService = processEngine.getRepositoryService();
        log("Starting to deploy " + files.size() + " files");
        for (File file : files) {
            String path = file.getAbsolutePath();
            log("Handling file " + path);
            try {
                FileInputStream inputStream = new FileInputStream(file);
                try {
                    log("deploying bar " + path);
                    repositoryService.createDeployment().name(file.getName()).addZipInputStream(new ZipInputStream(inputStream)).deploy();
                } finally {
                    IoUtil.closeSilently(inputStream);
                }
            } catch (Exception e) {
                throw new BuildException("couldn't deploy bar " + path + ": " + e.getMessage(), e);
            }
        }
    } finally {
        currentThread.setContextClassLoader(originalClassLoader);
    }
}
Also used : FileSet(org.apache.tools.ant.types.FileSet) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) BuildException(org.apache.tools.ant.BuildException) ProcessEngineInfo(org.camunda.bpm.engine.ProcessEngineInfo) ZipInputStream(java.util.zip.ZipInputStream) DirectoryScanner(org.apache.tools.ant.DirectoryScanner) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException) ProcessEngine(org.camunda.bpm.engine.ProcessEngine) RepositoryService(org.camunda.bpm.engine.RepositoryService)

Example 3 with ProcessEngineInfo

use of org.camunda.bpm.engine.ProcessEngineInfo in project camunda-bpm-platform by camunda.

the class ProcessEnginesTest method testProcessEngineInfo.

public void testProcessEngineInfo() {
    List<ProcessEngineInfo> processEngineInfos = ProcessEngines.getProcessEngineInfos();
    assertEquals(1, processEngineInfos.size());
    ProcessEngineInfo processEngineInfo = processEngineInfos.get(0);
    assertNull(processEngineInfo.getException());
    assertNotNull(processEngineInfo.getName());
    assertNotNull(processEngineInfo.getResourceUrl());
    ProcessEngine processEngine = ProcessEngines.getProcessEngine(ProcessEngines.NAME_DEFAULT);
    assertNotNull(processEngine);
}
Also used : ProcessEngineInfo(org.camunda.bpm.engine.ProcessEngineInfo) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Aggregations

ProcessEngineInfo (org.camunda.bpm.engine.ProcessEngineInfo)3 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ZipInputStream (java.util.zip.ZipInputStream)1 BuildException (org.apache.tools.ant.BuildException)1 DirectoryScanner (org.apache.tools.ant.DirectoryScanner)1 FileSet (org.apache.tools.ant.types.FileSet)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 RepositoryService (org.camunda.bpm.engine.RepositoryService)1