Search in sources :

Example 96 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class RemoteTest method testUpdate.

public void testUpdate() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    File t1 = create("bsn-1", new Version(1, 0, 0));
    File t2 = create("bsn-2", new Version(1, 0, 0));
    assertTrue(t1.isFile());
    assertTrue(t2.isFile());
    String sha1 = supervisor.addFile(t1);
    String sha2 = supervisor.addFile(t2);
    Map<String, String> update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    String errors = supervisor.getAgent().update(update);
    assertNull(errors);
    //
    // Verify that t1 is installed and t2 not
    //
    Bundle b1 = context.getBundle(t1.getAbsolutePath());
    assertNotNull(b1);
    Bundle b2 = context.getBundle(t2.getAbsolutePath());
    assertNull(b2);
    //
    // Now add a new one
    //
    update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    assertNotNull(context.getBundle(t1.getAbsolutePath()));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));
    //
    // Now change a bundle
    //
    t1 = create("bsn-1", new Version(2, 0, 0));
    sha1 = supervisor.addFile(t1);
    update = new HashMap<String, String>();
    update.put(t1.getAbsolutePath(), sha1);
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    b1 = context.getBundle(t1.getAbsolutePath());
    assertNotNull(b1);
    b2 = context.getBundle(t2.getAbsolutePath());
    assertNotNull(b2);
    assertEquals(new Version(2, 0, 0).toString(), b1.getVersion().toString());
    assertEquals(Bundle.ACTIVE, b1.getState());
    assertEquals(Bundle.ACTIVE, b2.getState());
    //
    // Now delete t1
    //
    update = new HashMap<String, String>();
    update.put(t2.getAbsolutePath(), sha2);
    errors = supervisor.getAgent().update(update);
    assertNull(errors);
    assertNull(context.getBundle(t1.getAbsolutePath()));
    assertNotNull(context.getBundle(t2.getAbsolutePath()));
    //
    // Delete all
    //
    supervisor.getAgent().update(null);
    assertNull(context.getBundle(t1.getAbsolutePath()));
    assertNull(context.getBundle(t2.getAbsolutePath()));
}
Also used : Version(aQute.bnd.version.Version) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Bundle(org.osgi.framework.Bundle) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) File(java.io.File)

Example 97 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class NexusOBR method putArtifact.

protected URL putArtifact(File tmpFile) throws Exception {
    assert (tmpFile != null);
    assert (tmpFile.isFile());
    init();
    Version version;
    String bsn;
    try (Jar jar = new Jar(tmpFile)) {
        bsn = jar.getBsn();
        if (bsn == null || !Verifier.isBsn(bsn))
            throw new IllegalArgumentException("Jar does not have a " + Constants.BUNDLE_SYMBOLICNAME + " manifest header");
        String versionString = jar.getVersion();
        if (versionString == null)
            versionString = "0";
        else if (!Verifier.isVersion(versionString))
            throw new IllegalArgumentException("Invalid version " + versionString + " in file " + tmpFile);
        version = Version.parseVersion(versionString);
    }
    URL url = put(tmpFile, bsn, version);
    reset();
    return url;
}
Also used : Version(aQute.bnd.version.Version) Jar(aQute.bnd.osgi.Jar) URL(java.net.URL)

Example 98 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class AgentTest method setUp.

@Override
protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(2, 0, 0));
    t3 = create("bsn-3", new Version(3, 0, 0));
    ServiceLoader<FrameworkFactory> sl = ServiceLoader.load(FrameworkFactory.class, this.getClass().getClassLoader());
    FrameworkFactory ff = sl.iterator().next();
    Map<String, String> configuration = new HashMap<String, String>();
    configuration.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, new File(tmp, "fwstorage").getAbsolutePath());
    framework = ff.newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    String location = "reference:" + t1.toURI().toString();
    context.installBundle(location);
    location = "reference:" + t2.toURI().toString();
    context.installBundle(location);
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();
    supervisor = new TestSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    super.setUp();
}
Also used : Version(aQute.bnd.version.Version) HashMap(java.util.HashMap) File(java.io.File) FrameworkFactory(org.osgi.framework.launch.FrameworkFactory)

Example 99 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class AgentTest method testAgentUpdateBundle.

public void testAgentUpdateBundle() throws Exception {
    BundleDTO t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertEquals("bsn-2", t2Bundle.symbolicName);
    assertEquals("2.0.0", t2Bundle.version);
    long previousModified = t2Bundle.lastModified;
    File t2prime = create("bsn-2", new Version(2, 0, 1));
    String sha = supervisor.addFile(t2prime);
    assertNull(supervisor.getAgent().update(2, sha));
    t2Bundle = supervisor.getAgent().getBundles(2).get(0);
    assertTrue(previousModified != t2Bundle.lastModified);
}
Also used : Version(aQute.bnd.version.Version) BundleDTO(org.osgi.framework.dto.BundleDTO) File(java.io.File)

Example 100 with Version

use of aQute.bnd.version.Version in project bnd by bndtools.

the class AetherRepsitoryTests method testStrategyExactVersion.

public void testStrategyExactVersion() throws Exception {
    RepositoryPlugin repo = createRepo();
    Map<String, String> attrs = new HashMap<String, String>();
    attrs.put("version", "2.5");
    attrs.put("strategy", "exact");
    File file = repo.get("javax.servlet:servlet-api", new Version(2, 5, 0), attrs, listener);
    assertNotNull(file);
    assertEquals("servlet-api-2.5.jar", file.getName());
}
Also used : HashMap(java.util.HashMap) Version(aQute.bnd.version.Version) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) File(java.io.File)

Aggregations

Version (aQute.bnd.version.Version)171 File (java.io.File)67 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)29 ArrayList (java.util.ArrayList)21 Attrs (aQute.bnd.header.Attrs)19 MavenVersion (aQute.bnd.version.MavenVersion)19 HashMap (java.util.HashMap)18 IOException (java.io.IOException)17 Jar (aQute.bnd.osgi.Jar)16 Workspace (aQute.bnd.build.Workspace)13 Project (aQute.bnd.build.Project)12 RevisionRef (aQute.service.library.Library.RevisionRef)12 Matcher (java.util.regex.Matcher)12 Parameters (aQute.bnd.header.Parameters)11 VersionRange (aQute.bnd.version.VersionRange)11 SortedList (aQute.lib.collections.SortedList)9 Processor (aQute.bnd.osgi.Processor)8 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)8 FileNotFoundException (java.io.FileNotFoundException)8 LinkedHashMap (java.util.LinkedHashMap)8