Search in sources :

Example 36 with Workspace

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

the class ProjectTest method testLastModified.

/**
	 * Two subsequent builds should not change the last modified if none of the
	 * source inputs have been modified.
	 *
	 * @throws Exception
	 */
public void testLastModified() throws Exception {
    Workspace ws = getWorkspace("testresources/ws");
    Project project = ws.getProject("p6");
    File bnd = IO.getFile("testresources/ws/p6/bnd.bnd");
    assertTrue(bnd.exists());
    project.clean();
    File pt = project.getTarget();
    if (!pt.exists() && !pt.mkdirs()) {
        throw new IOException("Could not create directory " + pt);
    }
    try {
        // Now we build it.
        File[] files = project.build();
        assertTrue(project.check());
        assertNotNull(files);
        assertEquals(1, files.length);
        byte[] olderDigest;
        try (Jar older = new Jar(files[0])) {
            olderDigest = older.getTimelessDigest();
        }
        System.out.println();
        // Ensure system time granularity is < than
        Thread.sleep(3000);
        // wait
        files[0].delete();
        project.build();
        assertTrue(project.check());
        assertNotNull(files);
        assertEquals(1, files.length);
        byte[] newerDigest;
        try (Jar newer = new Jar(files[0])) {
            newerDigest = newer.getTimelessDigest();
        }
        assertTrue(Arrays.equals(olderDigest, newerDigest));
    } finally {
        project.clean();
    }
}
Also used : Project(aQute.bnd.build.Project) Jar(aQute.bnd.osgi.Jar) IOException(java.io.IOException) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 37 with Workspace

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

the class ProjectTest method testSub.

/**
	 * Tests the handling of the -sub facility
	 *
	 * @throws Exception
	 */
public void testSub() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project project = ws.getProject("p4-sub");
    File[] files = project.build();
    Arrays.sort(files);
    System.err.println(Processor.join(project.getErrors(), "\n"));
    System.err.println(Processor.join(project.getWarnings(), "\n"));
    assertEquals(0, project.getErrors().size());
    assertEquals(0, project.getWarnings().size());
    assertNotNull(files);
    assertEquals(3, files.length);
    try (Jar a = new Jar(files[0]);
        Jar b = new Jar(files[1])) {
        Manifest ma = a.getManifest();
        Manifest mb = b.getManifest();
        assertEquals("base", ma.getMainAttributes().getValue("Base-Header"));
        assertEquals("base", mb.getMainAttributes().getValue("Base-Header"));
        assertEquals("a", ma.getMainAttributes().getValue("Sub-Header"));
        assertEquals("b", mb.getMainAttributes().getValue("Sub-Header"));
    }
}
Also used : Project(aQute.bnd.build.Project) Jar(aQute.bnd.osgi.Jar) Manifest(java.util.jar.Manifest) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Example 38 with Workspace

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

the class ProjectTest method testRunBundlesContainsSelf.

/**
	 * Test bnd.bnd of project `foo`: `-runbundles: foo;version=latest`
	 */
public void testRunBundlesContainsSelf() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project top = ws.getProject("p1");
    top.setDelayRunDependencies(false);
    top.setProperty("-runbundles", "p1;version=latest");
    top.setChanged();
    top.isStale();
    Collection<Container> runbundles = top.getRunbundles();
    assertTrue(top.check("Circular dependency"));
    assertNotNull(runbundles);
    assertEquals(0, runbundles.size());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Workspace(aQute.bnd.build.Workspace)

Example 39 with Workspace

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

the class ProjectTest method testSameBsnRunBundles.

/**
	 * Test 2 equal bsns but diff. versions
	 */
public void testSameBsnRunBundles() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project top = ws.getProject("p1");
    top.setProperty("-runbundles", "org.apache.felix.configadmin;version='[1.0.1,1.0.1]',org.apache.felix.configadmin;version='[1.1.0,1.1.0]'");
    Collection<Container> runbundles = top.getRunbundles();
    assertTrue(top.check());
    assertNotNull(runbundles);
    assertEquals(2, runbundles.size());
}
Also used : Project(aQute.bnd.build.Project) Container(aQute.bnd.build.Container) Workspace(aQute.bnd.build.Workspace)

Example 40 with Workspace

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

the class ProjectTest method testOutofDate.

public void testOutofDate() throws Exception {
    Workspace ws = getWorkspace(IO.getFile("testresources/ws"));
    Project project = ws.getProject("p3");
    File bnd = IO.getFile("testresources/ws/p3/bnd.bnd");
    assertTrue(bnd.exists());
    project.clean();
    File pt = project.getTarget();
    if (!pt.exists() && !pt.mkdirs()) {
        throw new IOException("Could not create directory " + pt);
    }
    try {
        // Now we build it.
        File[] files = project.build();
        System.err.println(project.getErrors());
        System.err.println(project.getWarnings());
        assertTrue(project.isOk());
        assertNotNull(files);
        assertEquals(1, files.length);
        // Now we should not rebuild it
        long lastTime = files[0].lastModified();
        files = project.build();
        assertEquals(1, files.length);
        assertTrue(files[0].lastModified() == lastTime);
        Thread.sleep(2000);
        project.updateModified(System.currentTimeMillis(), "Testing");
        files = project.build();
        assertEquals(1, files.length);
        assertTrue("Must have newer files now", files[0].lastModified() > lastTime);
    } finally {
        project.clean();
    }
}
Also used : Project(aQute.bnd.build.Project) IOException(java.io.IOException) File(java.io.File) Workspace(aQute.bnd.build.Workspace)

Aggregations

Workspace (aQute.bnd.build.Workspace)171 Project (aQute.bnd.build.Project)71 File (java.io.File)66 Processor (aQute.bnd.osgi.Processor)27 HashMap (java.util.HashMap)22 IOException (java.io.IOException)20 ArrayList (java.util.ArrayList)19 Container (aQute.bnd.build.Container)17 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)13 Version (aQute.bnd.version.Version)13 Run (aQute.bnd.build.Run)11 IProject (org.eclipse.core.resources.IProject)11 CoreException (org.eclipse.core.runtime.CoreException)10 IResource (org.eclipse.core.resources.IResource)8 BndEditModel (aQute.bnd.build.model.BndEditModel)7 Description (aQute.lib.getopt.Description)7 Bndrun (biz.aQute.resolve.Bndrun)7 Attrs (aQute.bnd.header.Attrs)5 HttpClient (aQute.bnd.http.HttpClient)5 Jar (aQute.bnd.osgi.Jar)5