Search in sources :

Example 1 with FilterLocator

use of org.apache.sling.ide.filter.FilterLocator in project sling by apache.

the class ProjectUtil method loadFilter.

/**
     * Loads a filter for the specified project
     * 
     * @param project the project to find a filter for
     * @return the found filter or null
     * @throws CoreException
     */
public static Filter loadFilter(final IProject project) throws CoreException {
    FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
    IPath filterPath = findFilterPath(project);
    if (filterPath == null) {
        return null;
    }
    IFile filterFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filterPath);
    Filter filter = null;
    if (filterFile != null && filterFile.exists()) {
        try (InputStream contents = filterFile.getContents()) {
            filter = filterLocator.loadFilter(contents);
        } catch (IOException e) {
            throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed loading filter file for project " + project.getName() + " from location " + filterFile, e));
        }
    }
    return filter;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) FilterLocator(org.apache.sling.ide.filter.FilterLocator) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) Filter(org.apache.sling.ide.filter.Filter) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with FilterLocator

use of org.apache.sling.ide.filter.FilterLocator in project sling by apache.

the class ProjectUtil method findFilterPath.

/**
     * Finds the path to a filter defined for the project
     * 
     * @param project the project
     * @return the path to the filter defined in the project, or null if no filter is found
     */
public static IPath findFilterPath(final IProject project) {
    FilterLocator filterLocator = Activator.getDefault().getFilterLocator();
    IFolder syncFolder = ProjectUtil.getSyncDirectory(project);
    if (syncFolder == null) {
        return null;
    }
    File filterLocation = filterLocator.findFilterLocation(syncFolder.getLocation().toFile());
    if (filterLocation == null) {
        return null;
    }
    return Path.fromOSString(filterLocation.getAbsolutePath());
}
Also used : FilterLocator(org.apache.sling.ide.filter.FilterLocator) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

FilterLocator (org.apache.sling.ide.filter.FilterLocator)2 IFile (org.eclipse.core.resources.IFile)2 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Filter (org.apache.sling.ide.filter.Filter)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1