Java Code Examples for org.eclipse.core.filesystem.IFileStore#childStores()

The following examples show how to use org.eclipse.core.filesystem.IFileStore#childStores() . 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: PackageUtils.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
public static String getApplicationPackageType(IFileStore applicationStore) throws CoreException {

		if (applicationStore == null || !applicationStore.fetchInfo().exists())
			return "unknown"; //$NON-NLS-1$

		/* check whether the application store is a war file */
		if (applicationStore.getName().endsWith(".war")) { //$NON-NLS-1$
			return "war"; //$NON-NLS-1$
		}

		/* check whether the application store contains a war file */
		for (IFileStore child : applicationStore.childStores(EFS.NONE, null)) {
			if (child.getName().endsWith(".war")) { //$NON-NLS-1$
				return "war"; //$NON-NLS-1$
			}
		}

		return "zip"; //$NON-NLS-1$
	}
 
Example 2
Source File: LeakTest.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
public void testLeak2() throws Exception {
    ICompilationDirector director = CompilationDirector.getInstance();

    IFileStore sourceRoot = EFS.getStore(java.net.URI
            .create("file:///C:/Users/rafael/AppData/Local/Temp/kirra/perf2/src"));
    IFileStore output = sourceRoot.getParent();
    LocationContext context = new LocationContext(output);
    context.addSourcePath(sourceRoot, output);
    IFileStore[] allChildren = sourceRoot.childStores(EFS.NONE, null);
    List<IFileStore> source = new ArrayList<IFileStore>();
    for (IFileStore iFileStore : allChildren)
        if (iFileStore.getName().endsWith("tuml"))
            source.add(iFileStore);
    IProblem[] problems = director.compile(source.toArray(new IFileStore[0]), null, context,
            ICompilationDirector.FULL_BUILD | ICompilationDirector.CLEAN, null);
    FixtureHelper.assertCompilationSuccessful(problems);
    showMemory("after test");
}
 
Example 3
Source File: Packager.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
protected void writeZip(IFileStore source, IPath path, ZipOutputStream zos) throws CoreException, IOException {

		/* load .cfignore if present */
		IFileStore cfIgnoreFile = source.getChild(CF_IGNORE_FILE);
		if (cfIgnoreFile.fetchInfo().exists()) {

			IgnoreNode node = new IgnoreNode();
			InputStream is = null;

			try {

				is = cfIgnoreFile.openInputStream(EFS.NONE, null);
				node.parse(is);

				cfIgnore.put(source.toURI(), node);

			} finally {
				if (is != null)
					is.close();
			}
		}

		IFileInfo info = source.fetchInfo(EFS.NONE, null);

		if (info.isDirectory()) {

			if (!isIgnored(source, path, true))
				for (IFileStore child : source.childStores(EFS.NONE, null))
					writeZip(child, path.append(child.getName()), zos);

		} else {

			if (!isIgnored(source, path, false)) {
				ZipEntry entry = new ZipEntry(path.toString());
				zos.putNextEntry(entry);
				IOUtilities.pipe(source.openInputStream(EFS.NONE, null), zos, true, false);
			}
		}
	}
 
Example 4
Source File: EFSUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * getFiles
 * 
 * @param file
 * @param recurse
 * @param list
 * @param includeCloakedFiles
 * @param monitor
 *            the progress monitor to use for reporting progress to the user. It is the caller's responsibility to
 *            call done() on the given monitor. Accepts null, indicating that no progress should be reported and
 *            that the operation cannot be cancelled.
 * @throws CoreException
 */
private static void getFiles(IFileStore file, boolean recurse, List<IFileStore> list, boolean includeCloakedFiles,
		IProgressMonitor monitor) throws CoreException
{
	if (file == null)
	{
		return;
	}

	if (monitor != null)
	{
		Policy.checkCanceled(monitor);
	}

	if (isFolder(file, monitor))
	{
		IFileStore[] children = file.childStores(EFS.NONE, monitor);
		if (children != null)
		{
			SubMonitor progress = SubMonitor.convert(monitor, children.length);
			boolean addingFile;
			for (IFileStore child : children)
			{
				Policy.checkCanceled(progress);
				addingFile = false;
				if (includeCloakedFiles || !CloakingUtils.isFileCloaked(child))
				{
					list.add(child);
					addingFile = true;
				}

				if (recurse && addingFile && isFolder(child, progress))
				{
					getFiles(child, recurse, list, includeCloakedFiles, progress.newChild(1));
				}
			}
		}
	}
}
 
Example 5
Source File: Repository.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void loadFrom(IFileStore store) throws CoreException {
    if (!store.fetchInfo().exists())
        return;
    if (store.fetchInfo().isDirectory())
        for (IFileStore current : store.childStores(EFS.NONE, null))
            loadFrom(current);
    else if (store.getName().endsWith(".uml"))
        this.loadPackage(URI.createURI(store.toURI().toString()));
}
 
Example 6
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void clean(IFileStore root, boolean deleteIfEmpty, IProgressMonitor monitor) throws CoreException {
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    if (isUMLFile(root) && MDDUtil.isGenerated(root.toURI())) {
        safeDelete(root);
        return;
    }
    IFileStore[] children = root.childStores(EFS.NONE, null);
    for (int i = 0; i < children.length; i++)
        clean(children[i], false, monitor);
    if (deleteIfEmpty && root.childStores(EFS.NONE, null).length == 0)
        root.delete(EFS.NONE, null);
}
 
Example 7
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private int compileTree(IRepository newRepo, IFileStore store, IFileStore baseDestination, int mode,
        IProgressMonitor monitor, IReferenceTracker refTracker, IProblemTracker problems,
        Map<IFileStore, ICompiler> auxiliaryUnits) throws CoreException {
    try {
        if (!store.fetchInfo().exists())
            return 0;
        if (!store.fetchInfo().isDirectory()) {
            FrontEndLanguage language = findLanguage(store,
                    newRepo.getProperties().getProperty(IRepository.DEFAULT_LANGUAGE));
            if (language == null)
                return 0;
            ICompiler compiler = language.createCompiler();
            if (language.isAuxiliary()) {
                auxiliaryUnits.put(store, compiler);
            } else {
                compileUnit(newRepo, store, mode, refTracker, problems, compiler, new SubProgressMonitor(monitor,
                        IProgressMonitor.UNKNOWN));
            }
            return 1;
        }
        IFileStore[] children = store.childStores(EFS.NONE, null);
        // sort files so order of classes in the resulting model is
        // predictable
        Arrays.sort(children, new Comparator<IFileStore>() {
            @Override
            public int compare(IFileStore o1, IFileStore o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        int compiledUnits = 0;
        for (int i = 0; i < children.length; i++)
            compiledUnits += compileTree(newRepo, children[i], baseDestination, mode, new SubProgressMonitor(
                    monitor, IProgressMonitor.UNKNOWN), refTracker, problems, auxiliaryUnits);
        return compiledUnits;
    } finally {
        monitor.done();
    }
}
 
Example 8
Source File: RemoteGenerateManifestOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Scan traceFolder for files that match the patterns specified in the
 * template file. When there is a match, the trace package element is used
 * to determine the trace name and trace type.
 *
 * @param traceGroup
 *                The parent trace group element
 * @param parentElement
 *                The immediate parent trace group or folder element
 * @param traceFolder
 *                The folder to scan
 * @param recursionLevel
 *                The recursion level (needed to find directory traces under the traceFolder
 * @param monitor
 *                The progress monitor
 * @throws CoreException
 *                Thrown by the file system implementation
 * @throws InterruptedException
 *                Thrown if operation was cancelled
 */
private void generateElementsFromArchive(
        final RemoteImportTraceGroupElement traceGroup,
        final TracePackageElement parentElement,
        final IFileStore traceFolder,
        final int recursionLevel,
        IProgressMonitor monitor)
                throws CoreException, InterruptedException {

    int localRecursionLevel = recursionLevel + 1;
    IFileStore[] sources = traceFolder.childStores(EFS.NONE, monitor);

    for (int i = 0; i < sources.length; i++) {
        ModalContext.checkCanceled(monitor);
        SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);

        IFileStore fileStore = sources[i];
        IPath fullArchivePath = TmfTraceCoreUtils.newSafePath(fileStore.toURI().getPath());

        IFileInfo sourceInfo = fileStore.fetchInfo();
        if (!sourceInfo.isDirectory()) {

            String rootPathString = traceGroup.getRootImportPath();
            IPath rootPath = TmfTraceCoreUtils.newSafePath(rootPathString);
            IPath relativeTracePath = Path.EMPTY;
            if (rootPath.isPrefixOf(fullArchivePath)) {
                relativeTracePath = fullArchivePath.makeRelativeTo(rootPath);
            }
            Entry<Pattern, TracePackageTraceElement> matchingTemplateEntry = getMatchingTemplateElement(relativeTracePath);
            if (matchingTemplateEntry != null) {
                TracePackageTraceElement matchingTemplateElement = matchingTemplateEntry.getValue();
                String traceType = matchingTemplateElement.getTraceType();

                // If a single file is part of a directory trace, use the parent directory instead
                TracePackageElement parent = parentElement;
                if (matchesDirectoryTrace(relativeTracePath, matchingTemplateEntry)) {
                    fullArchivePath = fullArchivePath.removeLastSegments(1);
                    fDirectoryTraces.add(fullArchivePath);
                    fileStore = fileStore.getParent();
                    sourceInfo = fileStore.fetchInfo();
                    parent = parentElement.getParent();
                    // Let the auto-detection choose the best trace type
                    traceType = null;
                } else if ((localRecursionLevel > 1) && (!traceGroup.isRecursive())) {
                    // Don't consider file traces on level 2 if it's not recursive
                    continue;
                }

                if (sourceInfo.getLength() > 0 || sourceInfo.isDirectory()) {
                    // Only add non-empty files
                    String traceName = fullArchivePath.lastSegment();
                    String fileName = fileStore.getName();
                    // create new elements to decouple from input elements
                    TracePackageTraceElement traceElement = new TracePackageTraceElement(parent, traceName, traceType);
                    RemoteImportTraceFilesElement tracePackageFilesElement = new RemoteImportTraceFilesElement(traceElement, fileName, fileStore);
                    tracePackageFilesElement.setVisible(false);
                }
            }
        } else {
            if (traceGroup.isRecursive() || localRecursionLevel < 2) {
                RemoteImportFolderElement folder = new RemoteImportFolderElement(parentElement, fileStore.getName());
                generateElementsFromArchive(traceGroup, folder, fileStore, localRecursionLevel, subMonitor);
            }
        }
    }
}
 
Example 9
Source File: RemoteImportTracesOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private IResource downloadDirectoryTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {

        IFileStore[] sources = trace.childStores(EFS.NONE, monitor);

        // Don't import just the metadata file
        if (sources.length > 1) {
            String traceName = trace.getName();

            traceName = TmfTraceCoreUtils.validateName(traceName);

            IFolder folder = traceFolder.getFolder(traceName);
            String newName = fConflictHandler.checkAndHandleNameClash(folder.getFullPath(), monitor);
            if (newName == null) {
                return null;
            }

            folder = traceFolder.getFolder(newName);
            folder.create(true, true, null);

            SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);
            subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, sources.length);

            for (IFileStore source : sources) {
                if (subMonitor.isCanceled()) {
                    throw new InterruptedException();
                }

                IPath destination = folder.getLocation().addTrailingSeparator().append(source.getName());
                IFileInfo info = source.fetchInfo();
                // TODO allow for downloading index directory and files
                if (!info.isDirectory()) {
                    SubMonitor childMonitor = subMonitor.newChild(1);
                    childMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + source.getName());
                    try (InputStream in = source.openInputStream(EFS.NONE, new NullProgressMonitor())) {
                        copy(in, folder, destination, childMonitor, info.getLength());
                    }
                }
            }
            folder.refreshLocal(IResource.DEPTH_INFINITE, null);
            return folder;
        }
        return null;
    }
 
Example 10
Source File: HTMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param offset
 * @param valuePrefix
 * @param editorStoreURI
 *            The URI of the current file. We use this to eliminate it from list of possible completions.
 * @param parent
 *            The parent we're grabbing children for.
 * @return
 * @throws CoreException
 */
protected List<ICompletionProposal> suggestChildrenOfFileStore(int offset, String valuePrefix, URI editorStoreURI,
		IFileStore parent) throws CoreException
{
	IFileStore[] children = parent.childStores(EFS.NONE, new NullProgressMonitor());
	if (children == null || children.length == 0)
	{
		return Collections.emptyList();
	}

	List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
	Image[] userAgentIcons = this.getAllUserAgentIcons();
	for (IFileStore f : children)
	{
		String name = f.getName();
		// Don't include the current file in the list
		// FIXME this is a possible perf issue. We really only need to check for editor store on local URIs
		if (name.charAt(0) == '.' || f.toURI().equals(editorStoreURI))
		{
			continue;
		}
		if (valuePrefix != null && valuePrefix.length() > 0 && !name.startsWith(valuePrefix))
		{
			continue;
		}

		IFileInfo info = f.fetchInfo();
		boolean isDir = false;
		if (info.isDirectory())
		{
			isDir = true;
		}

		// build proposal
		int replaceOffset = offset;
		int replaceLength = 0;
		if (this._replaceRange != null)
		{
			replaceOffset = this._replaceRange.getStartingOffset();
			replaceLength = this._replaceRange.getLength();
		}

		CommonCompletionProposal proposal = new URIPathProposal(name, replaceOffset, replaceLength, isDir,
				userAgentIcons);
		proposals.add(proposal);
	}
	return proposals;
}