All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bndtools.builder.BndtoolsDynamicReferenceProvider Maven / Gradle / Ivy

There is a newer version: 7.0.0
Show newest version
package org.bndtools.builder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IDynamicReferenceProvider;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;

import aQute.bnd.build.Project;
import aQute.bnd.build.Workspace;
import bndtools.central.Central;

public class BndtoolsDynamicReferenceProvider implements IDynamicReferenceProvider {
	private static IWorkspaceRoot eclipse = ResourcesPlugin.getWorkspace()
		.getRoot();

	@Override
	public List getDependentProjects(IBuildConfiguration buildConfiguration) throws CoreException {
		try {
			IProject project = buildConfiguration.getProject();
			Workspace ws = Central.getWorkspace();
			if (!ws.isDefaultWorkspace()) {
				return ws.readLocked(() -> getDependencies(project, ws));
			}
			return Collections.emptyList();
		} catch (Exception e) {
			Status status = new Status(Status.ERROR, "bndtools.builder", "Failed dependencies " + e.getMessage());
			throw new CoreException(status);
		}
	}

	private List getDependencies(IProject project, Workspace ws) throws Exception {
		Project model = ws.getProject(project.getName());
		if (model != null) {
			List result = new ArrayList<>();
			for (Project dep : model.getBuildDependencies()) {
				IProject idep = eclipse.getProject(dep.getName());
				if (idep != null)
					result.add(idep);
			}
			return result;
		} else
			return Collections.emptyList();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy