Search in sources :

Example 1 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class SFTPClientImpl method mput.

public void mput(String local, String remoteDir, String mode) throws SFTPException {
    if (channel == null) {
        throw new SFTPException("Connection is not established!");
    }
    if (remoteDir == null) {
        remoteDir = "./";
    } else if (!remoteDir.endsWith("/")) {
        remoteDir += "/";
    }
    RecurciveSearchFile rsf = new RecurciveSearchFile(lpwd().getPath());
    File[] localFiles = rsf.listAllTreeFiles(local);
    for (int i = 0; i < localFiles.length; i++) {
        if (mode == null) {
            put(localFiles[i].getAbsolutePath(), remoteDir + localFiles[i].getName());
        } else {
            put(localFiles[i].getAbsolutePath(), remoteDir + localFiles[i].getName(), mode);
        }
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) SFTPException(jp.ossc.nimbus.service.sftp.SFTPException)

Example 2 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class SCPClientImpl method mput.

public void mput(String local, String remoteDir, String mode) throws SCPException {
    if (connection == null) {
        throw new SCPException("Connection is not established!");
    }
    if (scpClient == null) {
        throw new SCPException("It is not authenticated!");
    }
    RecurciveSearchFile rsf = new RecurciveSearchFile(".");
    File[] localFiles = rsf.listAllTreeFiles(local);
    try {
        for (int i = 0; i < localFiles.length; i++) {
            if (mode == null) {
                scpClient.put(localFiles[i].getPath(), remoteDir);
            } else {
                scpClient.put(localFiles[i].getPath(), remoteDir, mode);
            }
        }
    } catch (IOException e) {
        throw new SCPException("It failed to mput! local=" + local, e);
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) SCPException(jp.ossc.nimbus.service.scp.SCPException) IOException(java.io.IOException) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile)

Example 3 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class CashedClassLoader method setupDirPropList.

// 
/**
 * Method ディレクトリ指定でクラス名を抽出する.
 * @param item
 */
protected void setupDirPropList(URL item) {
    String dirPath = StringOperator.replaceString(item.getFile(), C_BK_SRASH, C_SRASH);
    if (!item.getFile().endsWith(C_SRASH)) {
        dirPath = dirPath + C_SRASH;
    }
    RecurciveSearchFile file = new RecurciveSearchFile(dirPath);
    ExtentionFileFilter filter = new ExtentionFileFilter(C_CLASS_EXT, true);
    File[] list = file.listAllTreeFiles(filter);
    for (int cnt = 0; cnt < list.length; cnt++) {
        String path = list[cnt].getAbsolutePath();
        // int pos = item.getFile().length();
        // 2003.11.13 Hirokado -1追加
        int pos = item.getFile().length() - 1;
        path = path.substring(pos, path.length() - C_CLASS_EXT.length());
        path = StringOperator.replaceString(path, C_SRASH, C_DOT);
        Class cls = null;
        try {
            cls = this.loadClass(path);
        } catch (ClassNotFoundException e) {
            // $NON-NLS-1$//$NON-NLS-2$
            throw new ServiceException("CASHCLASSLODER003", "ClassNotFoundException clsename = " + path, e);
        }
        mClassHash.put(path, cls);
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ServiceException(jp.ossc.nimbus.lang.ServiceException) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) JarFile(java.util.jar.JarFile) File(java.io.File) ExtentionFileFilter(jp.ossc.nimbus.io.ExtentionFileFilter)

Example 4 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class ResourceBundlePropertiesFactoryService method setupDirPropList.

// 
/**
 * Method ディレクトリ指定でプロパティファイルを抽出する.
 * @param item
 */
protected void setupDirPropList(String item) {
    String dirPath = StringOperator.replaceString(item, C_BK_SRASH, C_SRASH);
    if (!item.endsWith(C_SRASH)) {
        dirPath = dirPath + C_SRASH;
    }
    File dirPathFile = new File(dirPath);
    int pos = dirPathFile.getAbsolutePath().length();
    RecurciveSearchFile file = new RecurciveSearchFile(dirPath);
    ExtentionFileFilter filter = new ExtentionFileFilter(C_PROP_EXT, true);
    File[] list = file.listAllTreeFiles(filter);
    for (int cnt = 0; cnt < list.length; cnt++) {
        FileInputStream stream;
        try {
            stream = new FileInputStream(list[cnt]);
        } catch (FileNotFoundException e) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new ServiceException("PROPFACTORY002", "FileNotFoundException name = " + list[cnt], e);
        }
        ArrayProperties prop = new ArrayProperties(mEncode);
        try {
            prop.load(stream);
        } catch (IOException e) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new ServiceException("PROPFACTORY003", "IOException filename = " + list[cnt], e);
        }
        try {
            stream.close();
        } catch (IOException e) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new ServiceException("PROPFACTORY004", "IOException filename = " + list[cnt], e);
        }
        String path = list[cnt].getAbsolutePath();
        path = path.substring(pos + 1, path.length() - C_PROP_EXT.length());
        path = StringOperator.replaceString(path, C_BK_SRASH, C_DOT);
        path = StringOperator.replaceString(path, C_SRASH, C_DOT);
        mPropHash.put(path, prop);
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ServiceException(jp.ossc.nimbus.lang.ServiceException) ArrayProperties(jp.ossc.nimbus.util.ArrayProperties) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) ExtentionFileFilter(jp.ossc.nimbus.io.ExtentionFileFilter) FileInputStream(java.io.FileInputStream)

Example 5 with RecurciveSearchFile

use of jp.ossc.nimbus.io.RecurciveSearchFile in project nimbus by nimbus-org.

the class TestControllerService method startScenario.

public synchronized void startScenario(String userId, String scenarioId) throws Exception {
    getLogger().write("TC___00009", new Object[] { currentTestScenarioGroup.getScenarioGroupId(), scenarioId, userId });
    try {
        setUserId(userId);
        if (currentTestScenarioGroup == null) {
            throw new TestException("ScenarioGroup is not start.");
        }
        if (currentTestScenario != null) {
            throw new TestException("Scenario is already started. ScenarioGroupId=" + currentTestScenario.getScenarioGroupId() + " ScenarioId=" + currentTestScenario.getScenarioId() + " UserId=" + currentTestScenario.getStatus().getUserId());
        }
        String[] scenarioIds = testResourceManager.getScenarioIds(currentTestScenarioGroup.getScenarioGroupId());
        if (!Arrays.asList(scenarioIds).contains(scenarioId)) {
            throw new TestException("This ScenarioId does not exist. ScenarioGroupId=" + currentTestScenarioGroup.getScenarioGroupId() + " ScenarioId=" + scenarioId);
        }
        TestScenarioGroupContext groupContext = (TestScenarioGroupContext) contextMap.get(currentTestScenarioGroup.getScenarioGroupId());
        TestScenarioContext context = groupContext.getTestScenarioContext(scenarioId);
        if (context != null) {
            ((TestScenarioImpl) context.getTestScenario()).clearResource();
            TestScenario.Status scenarioStatus = context.getStatus();
            if (scenarioStatus.getState() == TestScenario.Status.STARTED) {
                if (scenarioStatus.getUserId() != null && !scenarioStatus.getUserId().equals(userId)) {
                    throw new TestException("TestScenario is Stated by another user. testScenarioId=" + scenarioId + " userId=" + scenarioStatus.getUserId());
                }
                cancelScenario(scenarioId);
            }
        }
        context = new TestScenarioContext();
        RecurciveSearchFile resourceDir = new RecurciveSearchFile(testResourceFileBaseDirectory, currentTestScenarioGroup.getScenarioGroupId() + File.separator + scenarioId);
        downloadTestScenarioResource(resourceDir, currentTestScenarioGroup.getScenarioGroupId(), scenarioId);
        if (testStubs != null) {
            for (int i = 0; i < testStubs.length; i++) {
                String stubId = testStubs[i].getId();
                File tempDir = null;
                try {
                    tempDir = new File(internalTestResourceFileTempDirectory, new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()));
                    if (!tempDir.mkdirs()) {
                        throw new IOException("Directory can not make. path=" + tempDir);
                    }
                    File[] caseDirs = resourceDir.listFiles();
                    if (caseDirs != null && caseDirs.length > 0) {
                        for (int j = 0; j < caseDirs.length; j++) {
                            RecurciveSearchFile caseDir = new RecurciveSearchFile(caseDirs[j]);
                            File[] files = caseDir.listAllTreeFiles("**/" + stubId, RecurciveSearchFile.SEARCH_TYPE_DIR);
                            if (files != null && files.length > 0) {
                                for (int k = 0; k < files.length; k++) {
                                    File testcaseDir = new File(tempDir, files[k].getParentFile().getName());
                                    if (!testcaseDir.exists()) {
                                        if (!testcaseDir.mkdirs()) {
                                            throw new IOException("Directory can not make. path=" + testcaseDir);
                                        }
                                    }
                                    if (!RecurciveSearchFile.copyAllTree(files[k], testcaseDir)) {
                                        throw new IOException("Directory can not copy. From=" + files[k] + " To=" + testcaseDir);
                                    }
                                }
                            }
                        }
                    }
                    stubResourceManager.uploadScenarioResource(tempDir, currentTestScenarioGroup.getScenarioGroupId(), scenarioId, stubId);
                    testStubs[i].startScenario(userId, currentTestScenarioGroup.getScenarioGroupId(), scenarioId);
                } finally {
                    if (tempDir != null && tempDir.exists()) {
                        if (!RecurciveSearchFile.deleteAllTree(tempDir)) {
                            RecurciveSearchFile.deleteOnExitAllTree(tempDir);
                        }
                    }
                }
            }
        }
        if (testEventListeners != null) {
            for (int i = 0; i < testEventListeners.length; i++) {
                testEventListeners[i].startScenario(userId, scenarioId);
            }
        }
        TestScenarioImpl testScenario = new TestScenarioImpl(currentTestScenarioGroup.getScenarioGroupId(), scenarioId);
        testScenario.setController(this);
        context.setTestScenario(testScenario);
        groupContext.putTestScenarioContext(context);
        TestScenarioImpl.StatusImpl status = new TestScenarioImpl.StatusImpl(userId);
        context.setStatus(status);
        TestContextImpl scenarioTestContext = new TestContextImpl();
        scenarioTestContext.setCurrentDirectory(resourceDir);
        context.setScenarioTestContext(scenarioTestContext);
        TestContextImpl testCaseTestContext = new TestContextImpl();
        context.setTestCaseTestContext(testCaseTestContext);
        scenarioTestContext.setTestScenario(testScenario);
        TestScenarioResource testScenarioResource = testScenario.getTestScenarioResource();
        if (testPhase == null || testScenarioResource.isExecutable(testPhase)) {
            String[] beforeActionIds = testScenario.getTestScenarioResource().getBeforeActionIds();
            try {
                executeAction(context, scenarioTestContext, status, beforeActionIds, true, true, true);
            } catch (NotSupportActionException e) {
                throw new TestException("This action is not support at BeforeAction of Scenario. action=" + e.getAction().getClass().getName());
            }
            boolean result = context.isAllActionSuccess();
            status.setResult(result);
            status.setStartTime(new Date());
            if (result) {
                status.setState(TestScenario.Status.STARTED);
            } else {
                status.setState(TestScenario.Status.ERROR);
            }
        }
        currentTestScenario = testScenario;
    } catch (Exception e) {
        if (testStubs != null) {
            for (int i = 0; i < testStubs.length; i++) {
                testStubs[i].cancelScenario();
            }
        }
        currentTestScenario = null;
        currentTestCase = null;
        getLogger().write("TC___00010", new Object[] { currentTestScenarioGroup.getScenarioGroupId(), scenarioId }, e);
        throw e;
    }
}
Also used : RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) IOException(java.io.IOException) Date(java.util.Date) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException) TestScenarioResource(jp.ossc.nimbus.service.test.TestScenario.TestScenarioResource) RecurciveSearchFile(jp.ossc.nimbus.io.RecurciveSearchFile) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

RecurciveSearchFile (jp.ossc.nimbus.io.RecurciveSearchFile)14 File (java.io.File)11 IOException (java.io.IOException)6 ExtentionFileFilter (jp.ossc.nimbus.io.ExtentionFileFilter)4 FileInputStream (java.io.FileInputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 JarFile (java.util.jar.JarFile)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 ServiceException (jp.ossc.nimbus.lang.ServiceException)2 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1