use of org.eclipse.jdt.core.IJavaProject in project tdi-studio-se by Talend.
the class DeleteAllJobWhenStartUp method earlyStartup.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.IStartup#earlyStartup()
*/
@Override
public void earlyStartup() {
if (!GlobalServiceRegister.getDefault().isServiceRegistered(IRunProcessService.class)) {
return;
}
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject codeProject = root.getProject(TalendMavenConstants.PROJECT_NAME);
if (!codeProject.exists() || !codeProject.isAccessible()) {
return;
}
final IWorkspaceRunnable op = new IWorkspaceRunnable() {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
IRunProcessService processService = (IRunProcessService) GlobalServiceRegister.getDefault().getService(IRunProcessService.class);
ITalendProcessJavaProject talendJavaProject = processService.getTalendProcessJavaProject();
if (talendJavaProject != null) {
IJavaProject jProject = talendJavaProject.getJavaProject();
if (!jProject.isOpen()) {
jProject.open(monitor);
}
// empty the src/main/java...
IFolder srcFolder = talendJavaProject.getSrcFolder();
talendJavaProject.cleanFolder(monitor, srcFolder);
// contexts
IFolder resourcesFolder = talendJavaProject.getResourcesFolder();
emptyContexts(monitor, resourcesFolder, talendJavaProject);
// empty the outputs, target
IFolder targetFolder = talendJavaProject.getTargetFolder();
talendJavaProject.cleanFolder(monitor, targetFolder);
// empty the src/test/java
IFolder testSrcFolder = talendJavaProject.getTestSrcFolder();
talendJavaProject.cleanFolder(monitor, testSrcFolder);
// empty the src/test/java (main for contexts)
IFolder testResourcesFolder = talendJavaProject.getTestResourcesFolder();
talendJavaProject.cleanFolder(monitor, testResourcesFolder);
// empty temp
IFolder tempFolder = talendJavaProject.getTempFolder();
talendJavaProject.cleanFolder(monitor, tempFolder);
// empty lib/...
IFolder libFolder = talendJavaProject.getLibFolder();
talendJavaProject.cleanFolder(monitor, libFolder);
// rules
IFolder rulesResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_RULES_DIRECTORY);
talendJavaProject.cleanFolder(monitor, rulesResFolder);
// sqltempalte
IFolder sqlTemplateResFolder = talendJavaProject.getResourceSubFolder(monitor, JavaUtils.JAVA_SQLPATTERNS_DIRECTORY);
talendJavaProject.cleanFolder(monitor, sqlTemplateResFolder);
}
}
;
};
IWorkspace workspace = ResourcesPlugin.getWorkspace();
try {
ISchedulingRule schedulingRule = workspace.getRoot();
// the update the project files need to be done in the workspace runnable to avoid all
// notification
// of changes before the end of the modifications.
workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, new NullProgressMonitor());
} catch (CoreException e) {
if (e.getCause() != null) {
ExceptionHandler.process(e.getCause());
} else {
ExceptionHandler.process(e);
}
}
executed = true;
}
use of org.eclipse.jdt.core.IJavaProject in project AutoRefactor by JnRouvignac.
the class PrepareApplyRefactoringsJob method addAll.
private void addAll(Queue<RefactoringUnit> results, List<IJavaElement> javaElements) throws JavaModelException {
for (IJavaElement javaElement : javaElements) {
final JavaProjectOptions options = getJavaProjectOptions(javaElement);
if (javaElement instanceof ICompilationUnit) {
add(results, (ICompilationUnit) javaElement, options);
} else if (javaElement instanceof IPackageFragment) {
final IPackageFragment pf = (IPackageFragment) javaElement;
addAll(results, pf.getCompilationUnits(), options);
} else if (javaElement instanceof IPackageFragmentRoot) {
final IPackageFragmentRoot pfr = (IPackageFragmentRoot) javaElement;
addAll(results, Arrays.asList(pfr.getChildren()));
} else if (javaElement instanceof IJavaProject) {
IJavaProject javaProject = (IJavaProject) javaElement;
for (IPackageFragment pf : javaProject.getPackageFragments()) {
addAll(results, pf.getCompilationUnits(), options);
}
}
}
}
use of org.eclipse.jdt.core.IJavaProject in project azure-tools-for-java by Microsoft.
the class SDKJarsFilter method getSelectedProject.
private IProject getSelectedProject() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
ISelectionService service = window.getSelectionService();
ISelection selection = service.getSelection();
Object element = null;
IResource resource;
IProject selProject = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSel = (IStructuredSelection) selection;
element = structuredSel.getFirstElement();
}
if (element instanceof IProject) {
resource = (IResource) element;
selProject = resource.getProject();
} else if (element instanceof IJavaProject) {
IJavaProject proj = ((IJavaElement) element).getJavaProject();
selProject = proj.getProject();
}
return selProject;
}
use of org.eclipse.jdt.core.IJavaProject in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method getCurrentSelectedProject.
public static IProject getCurrentSelectedProject() {
IProject project = null;
ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
ISelection selection = selectionService.getSelection();
if (selection instanceof IStructuredSelection) {
Object element = ((IStructuredSelection) selection).getFirstElement();
if (element instanceof IResource) {
project = ((IResource) element).getProject();
} else if (element instanceof PackageFragmentRoot) {
IJavaProject jProject = ((PackageFragmentRoot) element).getJavaProject();
project = jProject.getProject();
} else if (element instanceof IJavaElement) {
IJavaProject jProject = ((IJavaElement) element).getJavaProject();
project = jProject.getProject();
}
}
if (project == null) {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
if (workspace.getRoot() != null && workspace.getRoot().getProjects().length > 0) {
IProject[] projects = workspace.getRoot().getProjects();
project = projects[projects.length - 1];
} else {
PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "No Active Project", "Must have a project first");
}
}
return project;
}
use of org.eclipse.jdt.core.IJavaProject in project XobotOS by xamarin.
the class SharpenBuilder method build.
@Override
protected IProject[] build(int kind, Map<String, String> args, IProgressMonitor monitor) throws CoreException {
final ConfigFile configFile = getConfigFile();
final SourceInfo sourceInfo = configFile.getSourceInfo();
final IFolder outputFolder = getProject().getFolder(sourceInfo.getOutputFolder());
try {
if (kind == CLEAN_BUILD) {
outputFolder.delete(true, false, monitor);
return null;
} else if (kind == FULL_BUILD)
outputFolder.delete(true, false, null);
else if (kind == AUTO_BUILD || kind == INCREMENTAL_BUILD)
WorkspaceUtilities.initializeTree(outputFolder, null);
else
return null;
} catch (Exception e) {
throw new RuntimeException("Cannot setup build environment: " + e);
}
Map<ICompilationUnit, Boolean> sources = new HashMap<ICompilationUnit, Boolean>();
final IJavaProject javaProject = JavaCore.create(getProject());
final List<ICompilationUnit> allUnits = JavaModelUtility.collectCompilationUnits(javaProject);
if (kind == FULL_BUILD) {
for (final ICompilationUnit unit : allUnits) {
sources.put(unit, true);
}
} else {
for (final ICompilationUnit unit : allUnits) {
sources.put(unit, false);
}
IResourceDelta delta = getDelta(getProject());
ChangedCompilationUnitCollector collector = new ChangedCompilationUnitCollector();
delta.accept(collector);
for (final ICompilationUnit unit : collector.changes()) {
sources.put(unit, true);
}
}
XobotBuilder.run(configFile, getProject(), sources, monitor);
return null;
}
Aggregations