Java Code Examples for org.eclipse.core.filesystem.EFS#getStore()

The following examples show how to use org.eclipse.core.filesystem.EFS#getStore() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildPathManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If a build path entry is added, we schedule a job to make sure the entry gets indexed (or it's index is
 * up-to-date).
 * 
 * @param entry
 */
private void index(IBuildPathEntry entry)
{
	try
	{
		IFileStore fileStore = EFS.getStore(entry.getPath());
		if (fileStore != null)
		{
			if (fileStore.fetchInfo().isDirectory())
			{
				new IndexContainerJob(entry.getDisplayName(), entry.getPath()).schedule();
			}
			else
			{
				new IndexFileJob(entry.getDisplayName(), entry.getPath()).schedule();
			}
		}
	}
	catch (Throwable e)
	{
		IdeLog.logError(BuildPathCorePlugin.getDefault(), e);
	}
}
 
Example 2
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testComplexInheritance() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/08/A/inner"; //$NON-NLS-1$
	String manifestName = "final-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent().getParent().getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(2, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$

		if ("A".equals(application.get("name").getValue())) //$NON-NLS-1$ //$NON-NLS-2$
			assertTrue("2".equals(application.get("instances").getValue())); //$NON-NLS-1$ //$NON-NLS-2$
	}
}
 
Example 3
Source File: BuildSettingWizardPage.java    From sarl with Apache License 2.0 6 votes vote down vote up
private void rememberExistingFiles(URI projectLocation) throws CoreException {
	this.dotProjectBackup = null;
	this.dotClasspathBackup = null;

	final IFileStore file = EFS.getStore(projectLocation);
	if (file.fetchInfo().exists()) {
		final IFileStore projectFile = file.getChild(FILENAME_PROJECT);
		if (projectFile.fetchInfo().exists()) {
			this.dotProjectBackup = createBackup(projectFile, "project-desc"); //$NON-NLS-1$
		}
		final IFileStore classpathFile = file.getChild(FILENAME_CLASSPATH);
		if (classpathFile.fetchInfo().exists()) {
			this.dotClasspathBackup = createBackup(classpathFile, "classpath-desc"); //$NON-NLS-1$
		}
	}
}
 
Example 4
Source File: PyEditorInputFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IAdaptable createElement(IMemento memento) {
    String fileStr = memento.getString(TAG_FILE);
    if (fileStr == null || fileStr.length() == 0) {
        return null;
    }

    String zipPath = memento.getString(TAG_ZIP_PATH);
    final File file = new File(fileStr);
    if (zipPath == null || zipPath.length() == 0) {
        //return EditorInputFactory.create(new File(file), false);
        final URI uri = file.toURI();
        IFile[] ret = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri,
                IContainer.INCLUDE_HIDDEN | IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
        if (ret != null && ret.length > 0) {
            return new FileEditorInput(ret[0]);
        }
        try {
            return new FileStoreEditorInput(EFS.getStore(uri));
        } catch (CoreException e) {
            return new PydevFileEditorInput(file);
        }
    }

    return new PydevZipFileEditorInput(new PydevZipFileStorage(file, zipPath));
}
 
Example 5
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSingleRelativeInheritance() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/02/inner"; //$NON-NLS-1$
	String manifestName = "prod-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent().getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(2, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("path")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$
	}
}
 
Example 6
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSingleInheritancePropagation() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/01"; //$NON-NLS-1$
	String manifestName = "prod-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(4, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("path")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$
	}
}
 
Example 7
Source File: PackagerTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCFIgnoreNegation() throws Exception {
	ZipOutputStream mockZos = mock(ZipOutputStream.class);

	String LOCATION = "testData/packagerTest/02"; //$NON-NLS-1$
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(LOCATION);
	IFileStore source = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath()));

	PackageUtils.writeZip(source, mockZos);

	/* what is... */
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry(".cfignore")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("A/B/.cfignore")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("A/B/test.in")))); //$NON-NLS-1$

	/* ... and what should never be */
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("A/B/test2.in")))); //$NON-NLS-1$
}
 
Example 8
Source File: PackagerTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCFIgnoreRules() throws Exception {

	ZipOutputStream mockZos = mock(ZipOutputStream.class);

	String LOCATION = "testData/packagerTest/01"; //$NON-NLS-1$
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(LOCATION);
	IFileStore source = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath()));

	PackageUtils.writeZip(source, mockZos);

	/* what is... */
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("test2.in")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry(".cfignore")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("A")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/test2.in")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/inner2/test3.in")))); //$NON-NLS-1$

	/* ... and what should never be */
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("test1.in")))); //$NON-NLS-1$
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/test1.in")))); //$NON-NLS-1$
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/inner2/inner3/test2.in")))); //$NON-NLS-1$
}
 
Example 9
Source File: FileGrepper.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void handleFile(File file, int depth, Collection<SearchResult> results) {
	if(options.isExcluded(file.getName())) {
		return;
	}
	if (results.size() >= options.getRows()) {
		// stop if we already have the max number of results to return
		return;
	}
	// Check if the path is acceptable
	if (!acceptFilename(file.getName()))
		return;
	// Add if it is a filename search or search the file contents.
	if (!options.isFileContentsSearch() || searchFile(file)) {
		IFileStore fileStore;
		try {
			fileStore = EFS.getStore(file.toURI());
		} catch (CoreException e) {
			logger.error("FileGrepper.handleFile: " + e.getLocalizedMessage(), e);
			return;
		}
		results.add(new SearchResult(fileStore, currentWorkspace, currentProject));
	}
}
 
Example 10
Source File: AdvancedFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testListenerMetadataHandling() throws JSONException, IOException, SAXException, CoreException {

	String fileName = "testListenerMetadataHandling.txt";

	//setup: create a file
	WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	TestFilesystemModificationListener l = new TestFilesystemModificationListener();
	try {
		//modify the metadata
		request = getPutFileRequest(fileName + "?parts=meta", getFileMetadataObject(true, true).toString());
		response = webConversation.getResponse(request);
		assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

		IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName));
		l.assertListenerNotified(fileStore, ChangeType.PUTINFO);
	} finally {
		TestFilesystemModificationListener.cleanup(l);
	}

	//make the file writeable again so test can clean up
	request = getPutFileRequest(fileName + "?parts=meta", getFileMetadataObject(false, false).toString());
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_NO_CONTENT, response.getResponseCode());

}
 
Example 11
Source File: AdvancedFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testETagPutNotMatch() throws JSONException, IOException, SAXException, CoreException {
	String fileName = "testfile.txt";

	//setup: create a file
	WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	//obtain file metadata and ensure data is correct
	request = getGetFilesRequest(fileName + "?parts=meta");
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG);
	assertNotNull(etag);

	//change the file on disk
	IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName));
	OutputStream out = fileStore.openOutputStream(EFS.NONE, null);
	out.write("New Contents".getBytes());
	out.close();

	//now a PUT should fail
	request = getPutFileRequest(fileName, "something");
	request.setHeaderField("If-Match", etag);
	try {
		response = webConversation.getResponse(request);
	} catch (IOException e) {
		//inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response
		assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0);
	}
}
 
Example 12
Source File: AdvancedFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testETagDeletedFile() throws JSONException, IOException, SAXException, CoreException {
	String fileName = "testfile.txt";

	//setup: create a file
	WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	//obtain file metadata and ensure data is correct
	request = getGetFilesRequest(fileName + "?parts=meta");
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG);
	assertNotNull(etag);

	//delete the file on disk
	IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName));
	fileStore.delete(EFS.NONE, null);

	//now a PUT should fail
	request = getPutFileRequest(fileName, "something");
	request.setHeaderField(ProtocolConstants.HEADER_IF_MATCH, etag);
	try {
		response = webConversation.getResponse(request);
	} catch (IOException e) {
		//inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response
		assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0);
	}
}
 
Example 13
Source File: BuildSettingWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static void deleteProjectFile(URI projectLocation) throws CoreException {
	final IFileStore file = EFS.getStore(projectLocation);
	if (file.fetchInfo().exists()) {
		final IFileStore projectFile = file.getChild(FILENAME_PROJECT);
		if (projectFile.fetchInfo().exists()) {
			projectFile.delete(EFS.NONE, null);
		}
	}
}
 
Example 14
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = AnalyzerException.class)
public void testSingleInheritanceOutsideSandbox() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/05"; //$NON-NLS-1$
	String manifestName = "prod-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));
	ManifestUtils.parse(fs.getParent(), fs);
}
 
Example 15
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deconfigures the classpath of the project after refactoring.
 *
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             if an error occurs while deconfiguring the classpath
 */
private void deconfigureClasspath(final IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(JarImportMessages.JarImportWizard_cleanup_import, 300);
		if (fJavaProject != null) {
			final IClasspathEntry[] entries= fJavaProject.readRawClasspath();
			final boolean changed= deconfigureClasspath(entries, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			final RefactoringHistory history= getRefactoringHistory();
			final boolean valid= history != null && !history.isEmpty();
			if (valid)
				RefactoringCore.getUndoManager().flush();
			if (valid || changed)
				fJavaProject.setRawClasspath(entries, changed, new SubProgressMonitor(monitor, 60, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		}
		if (fSourceFolder != null) {
			final IFileStore store= EFS.getStore(fSourceFolder.getRawLocationURI());
			if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
				store.delete(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder.delete(true, false, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder.clearHistory(new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder= null;
		}
		if (fJavaProject != null) {
			try {
				fJavaProject.getResource().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			} catch (CoreException exception) {
				JavaPlugin.log(exception);
			}
		}
	} finally {
		fJavaProject= null;
		monitor.done();
	}
}
 
Example 16
Source File: AbstractExportDialog.java    From ermasterr with Apache License 2.0 5 votes vote down vote up
@Override
protected void perfomeOK() throws Exception {
    try {
        final ProgressMonitorDialog monitor = new ProgressMonitorDialog(getShell());

        final ExportWithProgressManager manager = getExportWithProgressManager(settings.getExportSetting());

        manager.init(diagram, getBaseDir());

        final ExportManagerRunner runner = new ExportManagerRunner(manager);

        monitor.run(true, true, runner);

        if (runner.getException() != null) {
            throw runner.getException();
        }

        if (openAfterSavedButton != null && openAfterSavedButton.getSelection()) {
            final File openAfterSaved = openAfterSaved();

            final URI uri = openAfterSaved.toURI();

            final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

            if (openWithExternalEditor()) {
                IDE.openEditor(page, uri, IEditorRegistry.SYSTEM_EXTERNAL_EDITOR_ID, true);

            } else {
                final IFileStore fileStore = EFS.getStore(uri);
                IDE.openEditorOnFileStore(page, fileStore);
            }
        }

        // there is a case in another project
        diagram.getEditor().refreshProject();

    } catch (final InterruptedException e) {
        throw new InputException();
    }
}
 
Example 17
Source File: ClassFileSingleDocument.java    From eclipse-encoding-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void init(IEditorPart editor, IActiveDocumentAgentCallback callback) {
	if (!(editor.getEditorInput() instanceof FileStoreEditorInput)) {
		throw new IllegalArgumentException("part must provide FileStoreEditorInput.");
	}
	try {
		fileStore = EFS.getStore(((FileStoreEditorInput) editor.getEditorInput()).getURI());
	} catch (CoreException e) {
		throw new IllegalStateException(e);
	}
	super.init(editor, callback);
}
 
Example 18
Source File: NewTypeWizardPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Hook method that gets called when the type name has changed. The method validates the
 * type name and returns the status of the validation.
 * <p>
 * Subclasses may extend this method to perform their own validation.
 * </p>
 *
 * @return the status of the validation
 */
protected IStatus typeNameChanged() {
	StatusInfo status= new StatusInfo();
	fCurrType= null;
	String typeNameWithParameters= getTypeName();
	// must not be empty
	if (typeNameWithParameters.length() == 0) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
		return status;
	}

	String typeName= getTypeNameWithoutParameters();
	if (typeName.indexOf('.') != -1) {
		status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
		return status;
	}

	IJavaProject project= getJavaProject();
	IStatus val= validateJavaTypeName(typeName, project);
	if (val.getSeverity() == IStatus.ERROR) {
		status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
		return status;
	} else if (val.getSeverity() == IStatus.WARNING) {
		status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
		// continue checking
	}

	// must not exist
	if (!isEnclosingTypeSelected()) {
		IPackageFragment pack= getPackageFragment();
		if (pack != null) {
			ICompilationUnit cu= pack.getCompilationUnit(getCompilationUnitName(typeName));
			fCurrType= cu.getType(typeName);
			IResource resource= cu.getResource();

			if (resource.exists()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
				return status;
			}
			if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered);
				return status;
			}
			URI location= resource.getLocationURI();
			if (location != null) {
				try {
					IFileStore store= EFS.getStore(location);
					if (store.fetchInfo().exists()) {
						status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
						return status;
					}
				} catch (CoreException e) {
					status.setError(Messages.format(
						NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown,
						BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
				}
			}
		}
	} else {
		IType type= getEnclosingType();
		if (type != null) {
			fCurrType= type.getType(typeName);
			if (fCurrType.exists()) {
				status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
				return status;
			}
		}
	}

	if (!typeNameWithParameters.equals(typeName) && project != null) {
		if (!JavaModelUtil.is50OrHigher(project)) {
			status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
			return status;
		}
		String typeDeclaration= "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
		ASTParser parser= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
		parser.setSource(typeDeclaration.toCharArray());
		parser.setProject(project);
		CompilationUnit compilationUnit= (CompilationUnit) parser.createAST(null);
		IProblem[] problems= compilationUnit.getProblems();
		if (problems.length > 0) {
			status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
			return status;
		}
	}
	return status;
}
 
Example 19
Source File: VerySimpleBuilder.java    From textuml with Eclipse Public License 1.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
    IProject toBuild = getProject();

    // mark all referencing as needing rebuild
    for (IProject referencing : toBuild.getReferencingProjects())
        referencing.touch(monitor);

    // build location context
    IFileStore storeToBuild = EFS.getStore(toBuild.getLocationURI());
    LocationContext context = new LocationContext(storeToBuild);
    context.addSourcePath(storeToBuild, null);
    for (IProject referenced : toBuild.getReferencedProjects()) {
        URI referencedLocation = referenced.getLocationURI();
        if (referencedLocation != null) {
            IFileStore modelPathEntry = EFS.getStore(referencedLocation);
            context.addRelatedPath(modelPathEntry);
        }
    }

    removeMarkers(toBuild);
    IProblem[] problems = FrontEnd.getCompilationDirector().compile(null, null, context,
            ICompilationDirector.FULL_BUILD, monitor);
    toBuild.refreshLocal(IResource.DEPTH_INFINITE, null);
    Arrays.sort(problems, new Comparator<IProblem>() {
        public int compare(IProblem o1, IProblem o2) {
            if ((o1 instanceof InternalProblem) || (o2 instanceof InternalProblem)) {
                if (!(o1 instanceof InternalProblem))
                    return 1;
                if (!(o2 instanceof InternalProblem))
                    return -1;
                return 0;
            }
            int fileNameDelta = ((IFileStore) o1.getAttribute(IProblem.FILE_NAME)).toURI().compareTo(
                    ((IFileStore) o2.getAttribute(IProblem.FILE_NAME)).toURI());
            if (fileNameDelta != 0)
                return fileNameDelta;
            int lineNo1 = getLineNumber(o1);
            int lineNo2 = getLineNumber(o2);
            return lineNo1 - lineNo2;
        }

    });
    createMarkers(toBuild, problems);
    return null;
}
 
Example 20
Source File: IndexContainerJob.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
protected IFileStore getContainerFileStore() throws CoreException
{
	return EFS.getStore(getContainerURI());
}