Search in sources :

Example 91 with Project

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);
    }
}
Also used : ResourceAnalyzer(org.osgi.service.indexer.ResourceAnalyzer) IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) Builder(org.osgi.service.indexer.Builder) OutputStream(java.io.OutputStream) URI(java.net.URI) WorkspaceR5Repository(bndtools.central.WorkspaceR5Repository) HashSet(java.util.HashSet) IPath(org.eclipse.core.runtime.IPath) Capability(org.osgi.service.indexer.Capability) InputStream(java.io.InputStream) Resource(org.osgi.service.indexer.Resource) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) Requirement(org.osgi.service.indexer.Requirement) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IFile(org.eclipse.core.resources.IFile) File(java.io.File) RepoIndex(org.osgi.service.indexer.impl.RepoIndex)

Example 92 with Project

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);
    }
}
Also used : DefaultBuildErrorDetailsHandler(org.bndtools.build.api.DefaultBuildErrorDetailsHandler) BuildErrorDetailsHandler(org.bndtools.build.api.BuildErrorDetailsHandler) IProject(org.eclipse.core.resources.IProject) Project(aQute.bnd.build.Project) MarkerData(org.bndtools.build.api.MarkerData) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) SetLocation(aQute.service.reporter.Reporter.SetLocation) Location(aQute.service.reporter.Report.Location) Workspace(aQute.bnd.build.Workspace)

Example 93 with Project

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());
}
Also used : Project(aQute.bnd.build.Project) HashMap(java.util.HashMap) File(java.io.File) PutResult(aQute.bnd.service.RepositoryPlugin.PutResult) PutOptions(aQute.bnd.service.RepositoryPlugin.PutOptions) FileInputStream(java.io.FileInputStream) Workspace(aQute.bnd.build.Workspace)

Example 94 with Project

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();
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) RevisionRef(aQute.service.library.Library.RevisionRef) Revision(aQute.service.library.Library.Revision) Version(aQute.bnd.version.Version) Coordinate(aQute.service.library.Coordinate) File(java.io.File) Workspace(aQute.bnd.build.Workspace) HashSet(java.util.HashSet)

Example 95 with Project

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();
}
Also used : Project(aQute.bnd.build.Project) File(java.io.File) Utils.copyToTempFile(org.example.tests.utils.Utils.copyToTempFile) Workspace(aQute.bnd.build.Workspace)

Aggregations

Project (aQute.bnd.build.Project)140 Workspace (aQute.bnd.build.Workspace)70 File (java.io.File)45 ArrayList (java.util.ArrayList)22 IProject (org.eclipse.core.resources.IProject)21 Container (aQute.bnd.build.Container)19 IOException (java.io.IOException)17 ProjectLauncher (aQute.bnd.build.ProjectLauncher)15 Version (aQute.bnd.version.Version)12 Description (aQute.lib.getopt.Description)12 Jar (aQute.bnd.osgi.Jar)11 Builder (aQute.bnd.osgi.Builder)10 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)10 IJavaProject (org.eclipse.jdt.core.IJavaProject)9 Run (aQute.bnd.build.Run)8 BuildException (org.apache.tools.ant.BuildException)8 CoreException (org.eclipse.core.runtime.CoreException)8 IFile (org.eclipse.core.resources.IFile)7 ProjectBuilder (aQute.bnd.build.ProjectBuilder)6 ProjectTester (aQute.bnd.build.ProjectTester)5