Search in sources :

Example 86 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class DefaultBuildErrorDetailsHandler method getMarkerData.

/**
     * Use the location object to find the line number and text part.
     */
public static MarkerData getMarkerData(IProject p, Processor model, Location location) throws Exception {
    File file = model.getPropertiesFile();
    if (file == null) {
        if (model instanceof Project) {
            file = model.getFile(Project.BNDFILE);
        } else if (model instanceof Workspace) {
            file = model.getFile(Workspace.BUILDFILE);
        }
    }
    if (location.file != null)
        file = new File(location.file);
    int start = -1, end = -1, line = location.line;
    if (location.header != null && location.line == 0) {
        Processor rover = model;
        if (location.file != null && !model.getPropertiesFile().equals(location.file)) {
            File props = new File(location.file);
            if (props.isFile()) {
                rover = new Processor(model);
                rover.setProperties(props);
            }
        }
        try {
            FileLine fl = rover.getHeader(location.header, location.context);
            if (fl != null) {
                file = fl.file;
                line = fl.line;
                start = fl.start;
                end = fl.end;
            }
        } catch (Exception e) {
        // ignore, this was a bug in bnd. It could not handle if certain
        // files were not there during starting
        }
    }
    IResource resource = Central.toResource(file);
    String extra = "";
    if (resource == null)
        resource = AbstractBuildErrorDetailsHandler.getDefaultResource(p);
    else if (resource.getProject() != p) {
        //
        // Make sure we never escape our project
        //
        extra = ": see " + resource + "#" + line + 1;
        resource = p;
        line = 1;
        end = start = -1;
    }
    Map<String, Object> attribs = new HashMap<String, Object>();
    attribs.put(IMarker.MESSAGE, location.message.trim() + extra);
    attribs.put(IMarker.LINE_NUMBER, line + 1);
    if (end != -1 && start != -1) {
        attribs.put(IMarker.CHAR_START, start);
        attribs.put(IMarker.CHAR_END, end);
    }
    return new MarkerData(resource, attribs, false);
}
Also used : Processor(aQute.bnd.osgi.Processor) HashMap(java.util.HashMap) FileLine(aQute.bnd.osgi.Processor.FileLine) Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) File(java.io.File) IResource(org.eclipse.core.resources.IResource) Workspace(aQute.bnd.build.Workspace)

Example 87 with Project

use of aQute.bnd.build.Project in project bnd by bndtools.

the class LauncherTest method testSimpleLauncher.

/*
	 * Launches against the agent
	 */
public void testSimpleLauncher() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "test");
    final RemoteProjectLauncherPlugin pl = (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicInteger exitCode = new AtomicInteger(-1);
    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(1, sessions.size());
    final RunSession session = sessions.get(0);
    Thread t = new Thread("test-launch") {

        public void run() {
            try {
                exitCode.set(session.launch());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                latch.countDown();
            }
        }
    };
    t.start();
    Thread.sleep(500);
    for (Bundle b : context.getBundles()) {
        System.out.println(b.getLocation());
    }
    assertEquals(4, context.getBundles().length);
    String p1 = t1.getAbsolutePath();
    System.out.println(p1);
    assertNotNull(context.getBundle(p1));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));
    pl.cancel();
    latch.await();
    assertEquals(-3, exitCode.get());
    bndrun.close();
}
Also used : Project(aQute.bnd.build.Project) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Bundle(org.osgi.framework.Bundle) RemoteProjectLauncherPlugin(aQute.remote.plugin.RemoteProjectLauncherPlugin) Run(aQute.bnd.build.Run) CountDownLatch(java.util.concurrent.CountDownLatch) RunSession(aQute.bnd.build.RunSession)

Example 88 with Project

use of aQute.bnd.build.Project in project bnd by bndtools.

the class LauncherTest method testAgentAndMain.

/*
	 * Launches against the agent& main
	 */
public void testAgentAndMain() throws Exception {
    Project project = workspace.getProject("p1");
    Run bndrun = new Run(workspace, project.getBase(), project.getFile("one.bndrun"));
    bndrun.setProperty("-runpath", "biz.aQute.remote.launcher");
    bndrun.setProperty("-runbundles", "bsn-1,bsn-2");
    bndrun.setProperty("-runremote", "agent,main;agent=1090");
    final RemoteProjectLauncherPlugin pl = (RemoteProjectLauncherPlugin) bndrun.getProjectLauncher();
    pl.prepare();
    List<? extends RunSession> sessions = pl.getRunSessions();
    assertEquals(2, sessions.size());
    RunSession agent = sessions.get(0);
    RunSession main = sessions.get(1);
    CountDownLatch agentLatch = launch(agent);
    CountDownLatch mainLatch = launch(main);
    agent.waitTillStarted(1000);
    main.waitTillStarted(1000);
    Thread.sleep(500);
    agent.cancel();
    main.cancel();
    agentLatch.await();
    mainLatch.await();
    assertEquals(-3, agent.getExitCode());
    assertEquals(-3, main.getExitCode());
    bndrun.close();
}
Also used : Project(aQute.bnd.build.Project) RemoteProjectLauncherPlugin(aQute.remote.plugin.RemoteProjectLauncherPlugin) Run(aQute.bnd.build.Run) RunSession(aQute.bnd.build.RunSession) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 89 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class CnfWatcher method processEvent.

private void processEvent(IResourceChangeEvent event) {
    try {
        final Workspace workspace = Central.getWorkspaceIfPresent();
        if (workspace == null) {
            // this can happen during first project creation in an empty workspace
            logger.logInfo("Unable to get workspace", null);
            return;
        }
        final IProject cnfProject = WorkspaceUtils.findCnfProject(ResourcesPlugin.getWorkspace().getRoot(), workspace);
        if (cnfProject == null)
            return;
        IResourceDelta delta = event.getDelta();
        if (delta.findMember(cnfProject.getFullPath()) == null)
            return;
        Collection<Project> allProjects = workspace.getAllProjects();
        if (allProjects.isEmpty())
            return;
        Project p = allProjects.iterator().next();
        DeltaWrapper dw = new DeltaWrapper(p, delta, new BuildLogger(0));
        if (dw.hasCnfChanged()) {
            workspace.clear();
            workspace.forceRefresh();
            workspace.getPlugins();
            BndtoolsBuilder.dirty.addAll(allProjects);
            WorkspaceJob j = new WorkspaceJob("Update errors on workspace") {

                @Override
                public IStatus runInWorkspace(IProgressMonitor arg0) throws CoreException {
                    try {
                        MarkerSupport ms = new MarkerSupport(cnfProject);
                        ms.deleteMarkers("*");
                        ms.setMarkers(workspace, BndtoolsConstants.MARKER_BND_WORKSPACE_PROBLEM);
                        return Status.OK_STATUS;
                    } catch (Exception e) {
                        return new Status(IStatus.ERROR, BndtoolsBuilder.PLUGIN_ID, "updating errors for workspace", e);
                    }
                }
            };
            j.schedule();
        }
    } catch (Exception e) {
        logger.logError("Detecting changes in cnf failed, ignoring", e);
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) Project(aQute.bnd.build.Project) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) Workspace(aQute.bnd.build.Workspace) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 90 with Project

use of aQute.bnd.build.Project in project bndtools by bndtools.

the class ProjectPathsValidator method validateProject.

/**
     * Validate the project
     */
@Override
public void validateProject(Project model) throws Exception {
    //
    if (model == null) {
        return;
    }
    IJavaProject javaProject = Central.getJavaProject(model);
    if (javaProject == null) {
        model.error("Bndtools: The project in %s is not linked with a Java project.", model.getBase());
        return;
    }
    //
    // Verify if we have the right relation to the cnf folder ...
    //
    Project w;
    try {
        w = Central.getWorkspace().getProjectFromFile(model.getBase());
    } catch (Exception e) {
        w = null;
    }
    if (w == null || w != model) {
        model.error("Bndtools: Error in setup, likely the cnf folder is not ../cnf relative to the project folder '%s'. The workspace is in '%s'.", model.getBase(), model.getWorkspace().getBase());
        return;
    }
    //
    // Get the different bnd directories ...
    //
    File bin = model.getOutput();
    File testsrc = model.getTestSrc();
    File testbin = model.getTestOutput();
    Set<File> sourcePath = new HashSet<File>(model.getSourcePath());
    //
    // All the things we should find when we have traversed the build path
    //
    Set<SetupTypes> found = EnumSet.allOf(SetupTypes.class);
    for (IClasspathEntry cpe : javaProject.getRawClasspath()) {
        int kind = cpe.getEntryKind();
        switch(kind) {
            case IClasspathEntry.CPE_VARIABLE:
                warning(model, null, null, cpe, "Bndtools: Found a variable in the eclipse build path, this variable is not available during continuous integration", cpe).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                break;
            case IClasspathEntry.CPE_LIBRARY:
                warning(model, null, null, cpe, "Bndtools: The .classpath contains a library that will not be available during continuous integration: %s", cpe.getPath()).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                break;
            case IClasspathEntry.CPE_CONTAINER:
                if (BndtoolsConstants.BND_CLASSPATH_ID.segment(0).equals(cpe.getPath().segment(0)))
                    found.remove(SetupTypes.bndcontainer);
                else {
                    IPath path = cpe.getPath();
                    if (JRE_CONTAINER.segment(0).equals(path.segment(0))) {
                        if (path.segmentCount() == 1) {
                            // warning because default might vary <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
                            warning(model, null, path.toString(), cpe, "Bndtools: The .classpath contains a default JRE container: %s. This makes it undefined to what version you compile and this might differ between Continuous Integration and Eclipse", path).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                        } else {
                            String segment = path.segment(1);
                            if ("org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType".equals(segment) && path.segmentCount() == 3) {
                                // check javac version <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
                                String javac = model.getProperty(Constants.JAVAC_SOURCE, "1.5");
                                if (!path.segment(2).endsWith(javac)) {
                                    warning(model, null, path.toString(), cpe, "Bndtools: The .JRE container is set to %s but bnd is compiling against %s", path.segment(2), javac).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                                }
                            } else {
                                // warning because local/machine specific <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.launching.macosx.MacOSXType/Java SE 7 [1.7.0_71]"/>
                                warning(model, null, path.toString(), cpe, "Bndtools: The .classpath contains an non-portable JRE container: %s. This makes it undefined to what version you compile and this might differ between Continuous Integration and Eclipse", path).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                            }
                        }
                    } else {
                        warning(model, null, path.toString(), cpe, "Bndtools: The .classpath contains an unknown container: %s. This could make your build less portable.", path).file(new File(model.getBase(), ".classpath").getAbsolutePath());
                    }
                }
                break;
            case IClasspathEntry.CPE_SOURCE:
                File file = toFile(cpe.getPath());
                if (file == null) {
                    model.warning("Bndtools: Found virtual file for '%s'", cpe.getPath()).details(cpe);
                } else {
                    File output = toFile(cpe.getOutputLocation());
                    if (output == null)
                        output = toFile(javaProject.getOutputLocation());
                    if (file.equals(testsrc)) {
                        //
                        // We're talking about the test source directory
                        // This should be linked to testbin
                        //
                        found.remove(SetupTypes.testsrc);
                        if (!testbin.equals(output)) {
                            warning(model, DEFAULT_PROP_TESTBIN_DIR, testbin, cpe, "Bndtools: testsrc folder '%s' has output folder set to '%s', which does not match bnd's testbin folder '%s'", file, output, testbin);
                        }
                    } else {
                        //
                        if (sourcePath.remove(file)) {
                            if (!bin.equals(output)) {
                                warning(model, DEFAULT_PROP_BIN_DIR, bin, cpe, "Bndtools: src folder '%s' has output folder set to '%s', which does not match bnd's bin folder '%s'", file, output, bin);
                            }
                        } else {
                            warning(model, DEFAULT_PROP_SRC_DIR, null, cpe, "Bndtools: Found source folder '%s' that is not on bnd's source path '%s'", file, model.getProperty(Constants.DEFAULT_PROP_SRC_DIR));
                        }
                    }
                }
                break;
            default:
                break;
        }
    }
    //
    for (File file : sourcePath) {
        warning(model, DEFAULT_PROP_SRC_DIR, file, null, "Bndtools: bnd's src folder '%s' is not in the Eclipse build path", file);
    }
    //
    for (SetupTypes t : found) {
        switch(t) {
            case testsrc:
                if (// if the testsrc directory does not exist, then don't warn
                testsrc.isDirectory())
                    warning(model, DEFAULT_PROP_TESTSRC_DIR, null, null, "Bndtools: bnd's testsrc folder '%s' is not in the Eclipse build path", testsrc);
                break;
            case bndcontainer:
                warning(model, null, null, null, "Bndtools: The build path does not refer to the bnd container '%s'", BndtoolsConstants.BND_CLASSPATH_ID.segment(0));
                break;
            default:
                break;
        }
    }
}
Also used : Project(aQute.bnd.build.Project) IJavaProject(org.eclipse.jdt.core.IJavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) File(java.io.File) IFile(org.eclipse.core.resources.IFile) HashSet(java.util.HashSet)

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