use of aQute.bnd.build.Project in project bndtools by bndtools.
the class BuiltBundleIndexer method builtBundles.
@Override
public void builtBundles(final IProject project, IPath[] paths) {
IWorkspaceRoot wsroot = ResourcesPlugin.getWorkspace().getRoot();
final URI workspaceRootUri = wsroot.getLocationURI();
Set<File> files = new HashSet<File>();
for (IPath path : paths) {
try {
IFile ifile = wsroot.getFile(path);
IPath location = ifile.getLocation();
if (location != null)
files.add(location.toFile());
} catch (IllegalArgumentException e) {
System.err.println("### Error processing path: " + path);
e.printStackTrace();
}
}
// Generate the index file
File indexFile;
try {
Project model = Central.getProject(project);
File target = model.getTarget();
indexFile = new File(target, INDEX_FILENAME);
IFile indexPath = wsroot.getFile(Central.toPath(indexFile));
// Create the indexer and add ResourceAnalyzers from plugins
RepoIndex indexer = new RepoIndex(logAdapter);
List<ResourceAnalyzer> analyzers = Central.getWorkspace().getPlugins(ResourceAnalyzer.class);
for (ResourceAnalyzer analyzer : analyzers) {
indexer.addAnalyzer(analyzer, null);
}
// Use an analyzer to add a marker capability to workspace resources
indexer.addAnalyzer(new ResourceAnalyzer() {
@Override
public void analyzeResource(Resource resource, List<Capability> capabilities, List<Requirement> requirements) throws Exception {
Capability cap = new Builder().setNamespace("bndtools.workspace").addAttribute("bndtools.workspace", workspaceRootUri.toString()).addAttribute("project.path", project.getFullPath().toString()).buildCapability();
capabilities.add(cap);
}
}, null);
Map<String, String> config = new HashMap<String, String>();
config.put(ResourceIndexer.REPOSITORY_NAME, project.getName());
config.put(ResourceIndexer.ROOT_URL, project.getLocation().toFile().toURI().toString());
config.put(ResourceIndexer.PRETTY, "true");
try (OutputStream output = IO.outputStream(indexFile)) {
indexer.index(files, output, config);
}
indexPath.refreshLocal(IResource.DEPTH_ZERO, null);
if (indexPath.exists())
indexPath.setDerived(true, null);
} catch (Exception e) {
logger.logError(MessageFormat.format("Failed to generate index file for bundles in project {0}.", project.getName()), e);
return;
}
// Parse the index and add to the workspace repository
try (InputStream input = IO.stream(indexFile)) {
WorkspaceR5Repository workspaceRepo = Central.getWorkspaceR5Repository();
workspaceRepo.loadProjectIndex(project, input, project.getLocation().toFile().toURI());
} catch (Exception e) {
logger.logError("Failed to update workspace index.", e);
}
}
use of aQute.bnd.build.Project in project bndtools by bndtools.
the class MarkerSupport method createMarker.
void createMarker(Processor model, int severity, String formatted, String markerType) throws Exception {
Location location = model != null ? model.getLocation(formatted) : null;
if (location != null) {
String type = location.details != null ? location.details.getClass().getName() : null;
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
List<MarkerData> markers = handler.generateMarkerData(project, model, location);
for (MarkerData markerData : markers) {
IResource resource = markerData.getResource();
if (resource != null && resource.exists()) {
String typeOverride = markerData.getTypeOverride();
IMarker marker = resource.createMarker(typeOverride != null ? typeOverride : markerType);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute("$bndType", type);
// Set location information
if (location.header != null)
marker.setAttribute(BNDTOOLS_MARKER_HEADER_ATTR, location.header);
if (location.context != null)
marker.setAttribute(BNDTOOLS_MARKER_CONTEXT_ATTR, location.context);
if (location.file != null)
marker.setAttribute(BNDTOOLS_MARKER_FILE_ATTR, location.file);
if (location.reference != null)
marker.setAttribute(BNDTOOLS_MARKER_REFERENCE_ATTR, location.reference);
marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, markerData.hasResolutions());
for (Entry<String, Object> attrib : markerData.getAttribs().entrySet()) marker.setAttribute(attrib.getKey(), attrib.getValue());
}
}
return;
}
String defaultResource = model instanceof Project ? Project.BNDFILE : model instanceof Workspace ? Workspace.BUILDFILE : null;
IResource resource = DefaultBuildErrorDetailsHandler.getDefaultResource(project, defaultResource);
if (resource.exists()) {
IMarker marker = resource.createMarker(markerType);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute(IMarker.MESSAGE, formatted);
}
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class MavenBndRepoTest method testPutReleaseAndThenIndex.
public void testPutReleaseAndThenIndex() throws Exception {
Workspace ws = Workspace.findWorkspace(IO.getFile("testdata/releasews"));
Project p1 = ws.getProject("p1");
Project indexProject = ws.getProject("index");
Map<String, String> map = new HashMap<>();
map.put("releaseUrl", remote.toURI().toString());
config(map);
repo.begin(indexProject);
File jar = IO.getFile("testresources/release.jar");
PutOptions po = new PutOptions();
po.context = p1;
PutResult put = repo.put(new FileInputStream(jar), po);
File demoJar = IO.getFile("testresources/demo.jar");
PutOptions indexPo = new PutOptions();
indexPo.context = indexProject;
put = repo.put(new FileInputStream(demoJar), indexPo);
repo.end(indexProject);
assertTrue(indexProject.check());
assertTrue(IO.getFile(remote, "biz/aQute/bnd/demo/1.0.0/demo-1.0.0-index.xml").isFile());
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class Repository method cleanUp.
/**
* Remove any unused entries in this repository
*
* @throws Exception
*/
void cleanUp() throws Exception {
Workspace workspace = registry.getPlugin(Workspace.class);
Set<Container> set = new HashSet<Container>();
for (Project project : workspace.getAllProjects()) {
set.addAll(project.getBuildpath());
set.addAll(project.getRunbundles());
set.addAll(project.getRunpath());
set.addAll(project.getTestpath());
set.addAll(project.getBootclasspath());
set.addAll(project.getClasspath());
//
// This should be replaced with project.getRunfw()
//
String s = project.getProperty(Constants.RUNFW);
List<Container> bundles = project.getBundles(Strategy.HIGHEST, s, Constants.RUNFW);
set.addAll(bundles);
File base = project.getBase();
for (File sub : base.listFiles()) {
if (sub.getName().endsWith(".bndrun")) {
try (Project bndrun = new Project(workspace, base, sub)) {
set.addAll(bndrun.getRunbundles());
set.addAll(bndrun.getRunpath());
set.addAll(bndrun.getTestpath());
set.addAll(bndrun.getBootclasspath());
set.addAll(bndrun.getClasspath());
}
}
}
}
Set<RevisionRef> refs = new HashSet<RevisionRef>(index.getRevisionRefs());
Set<RevisionRef> keep = new HashSet<RevisionRef>();
for (Container libOrRev : set) {
for (Container c : libOrRev.getMembers()) {
logger.debug("Dependency {}", c);
if (!Verifier.isVersion(c.getVersion()))
continue;
RevisionRef ref = index.getRevisionRef(c.getBundleSymbolicName(), new Version(c.getVersion()));
if (ref != null)
refs.remove(ref);
else {
// missing!
logger.debug("Missing {}", c.getBundleSymbolicName());
Coordinate coord = new Coordinate(c.getBundleSymbolicName());
Revision rev = getLibrary().getRevisionByCoordinate(coord);
if (rev != null) {
index.addRevision(new RevisionRef(rev));
} else
System.out.printf("not found %s\n", c);
}
keep.add(ref);
}
}
for (RevisionRef ref : refs) {
index.delete(ref.bsn, Index.toVersion(ref));
}
index.save();
}
use of aQute.bnd.build.Project in project bnd by bndtools.
the class TestCommandLine method setUp.
@Override
protected void setUp() throws Exception {
ws = new Workspace(IO.getFile(".."));
Project cli = ws.getProject(CLI);
jarFile = cli.getBundle(CLI, "latest", Strategy.HIGHEST, null).getFile();
File index = new File("index.xml");
if (index.exists())
index.delete();
File gzipIndex = new File("index.xml.gz");
if (gzipIndex.exists())
gzipIndex.delete();
tempDir = createTempDir();
}
Aggregations