Search in sources :

Example 76 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class TalendProcessJavaProject method createFolder.

private IFolder createFolder(String path) {
    IProject p = getProject();
    if (p != null) {
        try {
            IFolder folder = p.getFolder(path);
            createSubFolder(null, folder);
            return folder;
        } catch (CoreException e) {
            ExceptionHandler.process(e);
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 77 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class JavaProcessor method initCodePath.

public void initCodePath(IContext c) throws ProcessorException {
    if (buildChildrenJobs != null) {
        buildChildrenJobs.clear();
    }
    ITalendProcessJavaProject tProcessJavaProject = getTalendJavaProject();
    IProgressMonitor monitor = new NullProgressMonitor();
    IFolder srcFolder = null;
    IFolder resourcesFolder = null;
    IFolder outputFolder = null;
    if (isTestJob) {
        srcFolder = tProcessJavaProject.getTestSrcFolder();
        resourcesFolder = tProcessJavaProject.getTestResourcesFolder();
        outputFolder = tProcessJavaProject.getTestOutputFolder();
    } else {
        srcFolder = tProcessJavaProject.getSrcFolder();
        resourcesFolder = tProcessJavaProject.getResourcesFolder();
        outputFolder = tProcessJavaProject.getOutputFolder();
    }
    /*
         * assume the job is "TestJob 0.1", project is "Test" .
         */
    String jobClassPackageFolder = null;
    String jobClassFilePath = null;
    // only for "standard" job
    if (isStandardJob()) {
        Item item = property.getItem();
        // test/testjob_0_1
        jobClassPackageFolder = JavaResourcesHelper.getJobClassPackageFolder(item, isTestJob);
        // test/testjob_0_1/TestJob.java
        jobClassFilePath = JavaResourcesHelper.getJobClassFilePath(item, filenameFromLabel, isTestJob);
        // test.testjob_0_1.TestJob
        this.mainClass = JavaResourcesHelper.getJobPackagedClass(item, filenameFromLabel, isTestJob);
    } else {
        // for shadow process, or preview process
        // test/shadowfileinputtodelimitedoutput_0_1, test/preview_data
        jobClassPackageFolder = JavaResourcesHelper.getProjectFolderName(property) + JavaUtils.PATH_SEPARATOR + JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion());
        // test/shadowfileinputtodelimitedoutput_0_1/ShadowFileInputToDelimitedOutput.java,
        // test/preview_data/Preview_Data.java
        jobClassFilePath = jobClassPackageFolder + JavaUtils.PATH_SEPARATOR + (filenameFromLabel ? JavaResourcesHelper.escapeFileName(process.getName()) : process.getId()) + JavaUtils.JAVA_EXTENSION;
        // test.shadowfileinputtodelimitedoutput_0_1.ShadowFileInputToDelimitedOutput,
        // test.preview_data.Preview_Data
        this.mainClass = new Path(jobClassFilePath).removeFileExtension().toString().replace('/', '.');
    }
    // create job packages, src/main/java/test/testjob_0_1
    // or test job packages, src/main/java/test/testjob_0_1/testjunitjob_0_1
    tProcessJavaProject.createSubFolder(monitor, srcFolder, jobClassPackageFolder);
    // src/main/java/test/testjob_0_1/TestJob.java
    // or src/main/java/test/testjob_0_1/testjunitjob_0_1/TestjunitJob.java
    this.codePath = srcFolder.getProjectRelativePath().append(jobClassFilePath);
    // target/classes/test/testjob_0_1
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1
    IFolder jobClassFolder = outputFolder.getFolder(jobClassPackageFolder);
    // TestJob
    String jobName = new Path(jobClassFilePath).removeFileExtension().lastSegment();
    // target/classes/test/testjob_0_1/TestJob
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/TestjunitJob
    this.compiledCodePath = jobClassFolder.getProjectRelativePath().append(jobName);
    if (isTestJob) {
        // test/testjob_0_1/datas
        IPath dataPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_DATAS_DIRECTORY);
        this.dataFilePath = resourcesFolder.getFolder(dataPath).getProjectRelativePath();
    }
    /*
         * for context.
         */
    // test/testjob_0_1/contexts
    // or test/testjob_0_1/testjunitjob_0_1/contexts
    IPath jobContextFolderPath = new Path(jobClassPackageFolder).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY);
    // src/main/resources/test/testjob_0_1/contexts
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts
    tProcessJavaProject.createSubFolder(monitor, resourcesFolder, jobContextFolderPath.toString());
    // for example, Default
    String contextFileName = JavaResourcesHelper.getJobContextFileName(c);
    // test/testjob_0_1/contexts/Default.properties
    // or test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    IPath jobContextPath = jobContextFolderPath.append(contextFileName);
    // src/main/resources/test/testjob_0_1/contexts/Default.properties
    // or src/test/resources/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.contextPath = resourcesFolder.getFile(jobContextPath).getProjectRelativePath();
    // target/classes/test/testjob_0_1/contexts/Default.properties
    // or target/test-classes/test/testjob_0_1/testjunitjob_0_1/contexts/Default.properties
    this.compiledContextPath = outputFolder.getFile(jobContextPath).getProjectRelativePath();
}
Also used : Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IPath(org.eclipse.core.runtime.IPath) ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Example 78 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class TalendProcessJavaProject method createSubFolder.

/**
     * 
     * will try to create the sub folders which under the base folder.
     */
@Override
public IFolder createSubFolder(IProgressMonitor monitor, IFolder baseFolder, String path) {
    if (baseFolder != null && path != null && path.length() > 0) {
        try {
            IFolder subFolder = baseFolder.getFolder(path);
            createSubFolder(monitor, subFolder);
            return subFolder;
        } catch (CoreException e) {
            ExceptionHandler.process(e);
            return null;
        }
    }
    return null;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 79 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class JavaProcessor method writeCodesToFile.

/**
     *
     * Test the formating source codes,only when talend debug mode
     */
private void writeCodesToFile(String contents, String fileBaseName) {
    if (!CommonsPlugin.isDebugMode()) {
        return;
    }
    //$NON-NLS-1$
    IFolder folder = this.getTalendJavaProject().getTempFolder().getFolder("--CodesFormat");
    File codesDir = folder.getLocation().toFile();
    codesDir.mkdirs();
    FileWriter fw = null;
    try {
        fw = new FileWriter(new File(codesDir, this.getProcess().getName() + '_' + fileBaseName));
        fw.write(contents);
        fw.flush();
    } catch (IOException e) {
        ExceptionHandler.process(e);
    } finally {
        if (fw != null) {
            try {
                fw.close();
            } catch (IOException e) {
            //
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 80 with IFolder

use of org.eclipse.core.resources.IFolder in project tdi-studio-se by Talend.

the class MavenJavaProcessor method getBasePathClasspath.

@Override
protected String getBasePathClasspath() throws ProcessorException {
    final boolean exportingJob = ProcessorUtilities.isExportConfig();
    String basePathClasspath = super.getBasePathClasspath();
    if (!exportingJob && isTestJob) {
        // for test job, need add the test-classes in classpath.
        final String classPathSeparator = extractClassPathSeparator();
        ITalendProcessJavaProject tProcessJvaProject = this.getTalendJavaProject();
        IFolder testClassesFolder = tProcessJvaProject.getTestOutputFolder();
        String testOutputPath = testClassesFolder.getLocation().toPortableString();
        basePathClasspath = testOutputPath + classPathSeparator + basePathClasspath;
    }
    return basePathClasspath;
}
Also used : ITalendProcessJavaProject(org.talend.core.runtime.process.ITalendProcessJavaProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IFolder (org.eclipse.core.resources.IFolder)299 IFile (org.eclipse.core.resources.IFile)129 IPath (org.eclipse.core.runtime.IPath)90 IProject (org.eclipse.core.resources.IProject)77 CoreException (org.eclipse.core.runtime.CoreException)72 IResource (org.eclipse.core.resources.IResource)66 Path (org.eclipse.core.runtime.Path)47 IContainer (org.eclipse.core.resources.IContainer)45 File (java.io.File)43 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)26 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)23 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)19 InputStream (java.io.InputStream)18 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)17 IRunProcessService (org.talend.designer.runprocess.IRunProcessService)17 PersistenceException (org.talend.commons.exception.PersistenceException)16 ByteArrayInputStream (java.io.ByteArrayInputStream)15