use of org.talend.core.runtime.process.ITalendProcessJavaProject 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();
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject 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;
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class EditPropertiesAction method processRename.
protected void processRename(IRepositoryNode node, String originalName) {
try {
IRunProcessService runProcessService = CorePlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = runProcessService.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IPackageFragmentRoot root = talendProcessJavaProject.getJavaProject().getPackageFragmentRoot(srcFolder);
// add for bug TDI-24379 on August 23, 2013.
IFolder srcInterFolder = srcFolder.getFolder(JavaUtils.JAVA_INTERNAL_DIRECTORY);
if (srcInterFolder.exists()) {
File file = new File(srcInterFolder.getLocationURI());
for (File f : file.listFiles()) {
if (f.isFile()) {
f.delete();
}
}
}
// qli modified to fix the bug 5400 and 6185.
// update for fix [TESB-6784]
IPackageFragment routinesPkg = getPackageFragment(root, node);
// ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName +
// SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit unit = routinesPkg.getCompilationUnit(originalName + ".java");
if (unit == null) {
return;
}
String newName = node.getObject().getProperty().getLabel();
JavaRenameProcessor processor = new RenameCompilationUnitProcessor(unit);
// processor.setNewElementName(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
processor.setNewElementName(newName + ".java");
RenameRefactoring ref = new RenameRefactoring(processor);
final PerformRefactoringOperation operation = new PerformRefactoringOperation(ref, CheckConditionsOperation.ALL_CONDITIONS);
IRunnableWithProgress r = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
operation.run(monitor);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
}
});
}
};
PlatformUI.getWorkbench().getProgressService().run(true, true, r);
RefactoringStatus conditionStatus = operation.getConditionStatus();
if (conditionStatus.hasError()) {
//$NON-NLS-1$
String errorMessage = Messages.getString("EditPropertiesAction.renameError", unit.getElementName(), newName);
RefactoringStatusEntry[] entries = conditionStatus.getEntries();
for (RefactoringStatusEntry entry : entries) {
//$NON-NLS-1$
errorMessage += "\n>>>" + entry.getMessage();
}
Shell shell = null;
IRepositoryView viewPart = getViewPart();
if (viewPart != null) {
shell = viewPart.getViewSite().getShell();
} else {
shell = Display.getCurrent().getActiveShell();
}
//$NON-NLS-1$
MessageDialog.openError(shell, Messages.getString("EditPropertiesAction.warning"), errorMessage);
return;
}
// ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + SuffixConstants.SUFFIX_STRING_java);
//$NON-NLS-1$
ICompilationUnit newUnit = routinesPkg.getCompilationUnit(newName + ".java");
if (newUnit == null) {
return;
}
RoutineItem item = (RoutineItem) node.getObject().getProperty().getItem();
IFile javaFile = (IFile) newUnit.getAdapter(IResource.class);
try {
ByteArray byteArray = item.getContent();
byteArray.setInnerContentFromFile(javaFile);
IRepositoryService service = CorePlugin.getDefault().getRepositoryService();
IProxyRepositoryFactory repFactory = service.getProxyRepositoryFactory();
repFactory.save(item);
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
} catch (Exception e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class ContextModifyCommand method getContextResource.
/**
* Gets the context file resource according to the project type.
*
* @param process
* @param context
* @return
*/
private IResource getContextResource(IProcess2 process, IContext context) throws Exception {
IPath path = new Path(JavaResourcesHelper.getProjectFolderName(process.getProperty().getItem())).append(JavaResourcesHelper.getJobFolderName(process.getName(), process.getVersion())).append(JavaUtils.JAVA_CONTEXTS_DIRECTORY).append(context.getName() + JavaUtils.JAVA_CONTEXT_EXTENSION);
if (GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
IRunProcessService service = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject != null) {
IFolder srcFolder = talendProcessJavaProject.getResourcesFolder();
return srcFolder.getFile(path);
}
}
return null;
}
use of org.talend.core.runtime.process.ITalendProcessJavaProject in project tdi-studio-se by Talend.
the class WSDL2JAVAController method syncRoutine.
/**
* DOC xtan there will be refactor for this method with JavaRoutineSynchronizer.syncRoutine().
*
* @param routineItem
* @param copyToTemp
* @return
* @throws SystemException
*/
private IFile syncRoutine(RoutineItem routineItem, boolean copyToTemp, String name) throws SystemException {
FileOutputStream fos = null;
try {
IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
ITalendProcessJavaProject talendProcessJavaProject = service.getTalendProcessJavaProject();
if (talendProcessJavaProject == null) {
return null;
}
IFolder srcFolder = talendProcessJavaProject.getSrcFolder();
IFile file = srcFolder.getFile(JavaUtils.JAVA_ROUTINES_DIRECTORY + '/' + routineItem.getProperty().getLabel() + JavaUtils.JAVA_EXTENSION);
if (copyToTemp) {
String routineContent = new String(routineItem.getContent().getInnerContent());
routineContent = chanageRoutinesPackage(routineContent, name);
String label = routineItem.getProperty().getLabel();
if (!label.equals(ITalendSynchronizer.TEMPLATE)) {
routineContent = routineContent.replaceAll(ITalendSynchronizer.TEMPLATE, label);
File f = file.getLocation().toFile();
fos = new FileOutputStream(f);
fos.write(routineContent.getBytes());
fos.close();
}
}
if (!file.exists()) {
file.refreshLocal(1, null);
}
return file;
} catch (CoreException e) {
throw new SystemException(e);
} catch (IOException e) {
throw new SystemException(e);
} finally {
try {
fos.close();
} catch (Exception e) {
// ignore me even if i'm null
ExceptionHandler.process(e);
}
}
}
Aggregations