Search in sources :

Example 1 with Version

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

the class WorkspaceRepositoryTest method testGetExact.

public void testGetExact() throws Exception {
    File file = repo.get("p2", new Version("1.2.3"), new HashMap<String, String>());
    assertTrue(workspace.check());
    assertNotNull(file);
}
Also used : Version(aQute.bnd.version.Version) File(java.io.File)

Example 2 with Version

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

the class Analyzer method parsePackageInfoClass.

private Attrs parsePackageInfoClass(Resource r) throws Exception {
    final Attrs info = new Attrs();
    final Clazz clazz = new Clazz(this, "", r);
    clazz.parseClassFileWithCollector(new ClassDataCollector() {

        @Override
        public void annotation(Annotation a) {
            String name = a.getName().getFQN();
            switch(name) {
                case "aQute.bnd.annotation.Version":
                    warning("%s annotation used in class %s. Bnd versioning annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi versioning annotations.", name, clazz);
                case "org.osgi.annotation.versioning.Version":
                    // Check version
                    String version = a.get("value");
                    if (!info.containsKey(Constants.VERSION_ATTRIBUTE)) {
                        if (version != null) {
                            version = getReplacer().process(version);
                            if (Verifier.VERSION.matcher(version).matches())
                                info.put(VERSION_ATTRIBUTE, version);
                            else
                                error("Version annotation in %s has invalid version info: %s", clazz, version);
                        }
                    } else {
                        // Verify this matches with packageinfo
                        String presentVersion = info.get(VERSION_ATTRIBUTE);
                        try {
                            Version av = new Version(presentVersion).getWithoutQualifier();
                            Version bv = new Version(version).getWithoutQualifier();
                            if (!av.equals(bv)) {
                                error("Version from annotation for %s differs with packageinfo or Manifest", clazz.getClassName().getFQN());
                            }
                        } catch (Exception e) {
                        // Ignore
                        }
                    }
                    break;
                case "aQute.bnd.annotation.Export":
                    // Check mandatory attributes
                    Attrs attrs = doAttrbutes((Object[]) a.get(Export.MANDATORY), clazz, getReplacer());
                    if (!attrs.isEmpty()) {
                        info.putAll(attrs);
                        info.put(MANDATORY_DIRECTIVE, Processor.join(attrs.keySet()));
                    }
                    // Check optional attributes
                    attrs = doAttrbutes((Object[]) a.get(Export.OPTIONAL), clazz, getReplacer());
                    if (!attrs.isEmpty()) {
                        info.putAll(attrs);
                    }
                    // Check Included classes
                    Object[] included = a.get(Export.INCLUDE);
                    if (included != null && included.length > 0) {
                        StringBuilder sb = new StringBuilder();
                        String del = "";
                        for (Object i : included) {
                            Matcher m = OBJECT_REFERENCE.matcher(((TypeRef) i).getFQN());
                            if (m.matches()) {
                                sb.append(del);
                                sb.append(m.group(2));
                                del = ",";
                            }
                        }
                        info.put(INCLUDE_DIRECTIVE, sb.toString());
                    }
                    // Check Excluded classes
                    Object[] excluded = a.get(Export.EXCLUDE);
                    if (excluded != null && excluded.length > 0) {
                        StringBuilder sb = new StringBuilder();
                        String del = "";
                        for (Object i : excluded) {
                            Matcher m = OBJECT_REFERENCE.matcher(((TypeRef) i).getFQN());
                            if (m.matches()) {
                                sb.append(del);
                                sb.append(m.group(2));
                                del = ",";
                            }
                        }
                        info.put(EXCLUDE_DIRECTIVE, sb.toString());
                    }
                    // Check Uses
                    Object[] uses = a.get(Export.USES);
                    if (uses != null && uses.length > 0) {
                        String old = info.get(USES_DIRECTIVE);
                        if (old == null)
                            old = "";
                        StringBuilder sb = new StringBuilder(old);
                        String del = sb.length() == 0 ? "" : ",";
                        for (Object use : uses) {
                            sb.append(del);
                            sb.append(use);
                            del = ",";
                        }
                        info.put(USES_DIRECTIVE, sb.toString());
                    }
                    break;
            }
        }
    });
    return info;
}
Also used : Version(aQute.bnd.version.Version) Matcher(java.util.regex.Matcher) TypeRef(aQute.bnd.osgi.Descriptors.TypeRef) Attrs(aQute.bnd.header.Attrs) ParseException(java.text.ParseException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 3 with Version

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

the class Analyzer method getOutputFile.

/**
	 * Calculate the output file for the given target. The strategy is:
	 * 
	 * <pre>
	 * parameter given if not null and not directory if directory, this will be
	 * the output directory based on bsn-version.jar name of the source file if
	 * exists Untitled-[n]
	 * </pre>
	 * 
	 * @param output may be null, otherwise a file path relative to base
	 */
public File getOutputFile(String output) {
    if (output == null)
        output = get(Constants.OUTPUT);
    File outputDir;
    if (output != null) {
        File outputFile = getFile(output);
        if (outputFile.isDirectory())
            outputDir = outputFile;
        else
            return outputFile;
    } else
        outputDir = getBase();
    Entry<String, Attrs> name = getBundleSymbolicName();
    if (name != null) {
        String bsn = name.getKey();
        String version = getBundleVersion();
        Version v = Version.parseVersion(version);
        String outputName = bsn + "-" + v.getWithoutQualifier() + Constants.DEFAULT_JAR_EXTENSION;
        return new File(outputDir, outputName);
    }
    File source = getJar().getSource();
    if (source != null) {
        String outputName = source.getName();
        return new File(outputDir, outputName);
    }
    if (getPropertiesFile() != null) {
        String nm = getPropertiesFile().getName();
        if (nm.endsWith(Constants.DEFAULT_BND_EXTENSION)) {
            nm = nm.substring(0, nm.length() - Constants.DEFAULT_BND_EXTENSION.length()) + Constants.DEFAULT_JAR_EXTENSION;
            logger.debug("name is {}", nm);
            return new File(outputDir, nm);
        }
    }
    error("Cannot establish an output name from %s, nor bsn, nor source file name, using Untitled", output);
    int n = 0;
    File f = getFile(outputDir, "Untitled");
    while (f.isFile()) {
        f = getFile(outputDir, "Untitled-" + n++);
    }
    return f;
}
Also used : Version(aQute.bnd.version.Version) Attrs(aQute.bnd.header.Attrs) File(java.io.File)

Example 4 with Version

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

the class LauncherTest method setUp.

@Override
protected void setUp() throws Exception {
    tmp = IO.getFile("generated/tmp");
    tmp.mkdirs();
    IO.copy(IO.getFile("testdata/ws"), tmp);
    workspace = Workspace.getWorkspace(tmp);
    workspace.refresh();
    InfoRepository repo = workspace.getPlugin(InfoRepository.class);
    t1 = create("bsn-1", new Version(1, 0, 0));
    t2 = create("bsn-2", new Version(1, 0, 0));
    repo.put(new FileInputStream(t1), null);
    repo.put(new FileInputStream(t2), null);
    t1 = repo.get("bsn-1", new Version(1, 0, 0), null);
    t2 = repo.get("bsn-2", new Version(1, 0, 0), null);
    repo.put(new FileInputStream(IO.getFile("generated/biz.aQute.remote.launcher.jar")), null);
    workspace.getPlugins().add(repo);
    File storage = IO.getFile("generated/storage-1");
    storage.mkdirs();
    configuration = new HashMap<String, Object>();
    configuration.put(Constants.FRAMEWORK_STORAGE_CLEAN, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
    configuration.put(Constants.FRAMEWORK_STORAGE, storage.getAbsolutePath());
    configuration.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, "org.osgi.framework.launch;version=1.2");
    framework = new org.apache.felix.framework.FrameworkFactory().newFramework(configuration);
    framework.init();
    framework.start();
    context = framework.getBundleContext();
    location = "reference:" + IO.getFile("generated/biz.aQute.remote.agent.jar").toURI().toString();
    agent = context.installBundle(location);
    agent.start();
    thread = new Thread() {

        @Override
        public void run() {
            try {
                Main.main(new String[] { "-s", "generated/storage", "-c", "generated/cache", "-p", "1090", "-et" });
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    thread.setDaemon(true);
    thread.start();
    super.setUp();
}
Also used : InfoRepository(aQute.bnd.service.repository.InfoRepository) FileInputStream(java.io.FileInputStream) Version(aQute.bnd.version.Version) File(java.io.File)

Example 5 with Version

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

the class RemoteTest method testUpdateOrder.

public void testUpdateOrder() throws Exception {
    LauncherSupervisor supervisor = new LauncherSupervisor();
    supervisor.connect("localhost", Agent.DEFAULT_PORT);
    List<String> bundles = new ArrayList<String>();
    LinkedHashMap<String, String> update = new LinkedHashMap<String, String>();
    for (int i = 0; i < 50; i++) {
        String name = UUID.randomUUID().toString();
        File f = create(name, new Version(1, 0, 0));
        assertTrue(f.isFile());
        String sha = supervisor.addFile(f);
        update.put(f.getAbsolutePath(), sha);
        bundles.add(name);
    }
    String errors = supervisor.getAgent().update(update);
    assertNull(errors);
    //
    // Now check installed bundle order
    //
    Bundle[] installed = context.getBundles();
    for (int i = 2; i < installed.length; i++) {
        Bundle b = installed[i];
        assertTrue(b.getLocation().endsWith(bundles.get(i - 2) + "-1.0.0.jar"));
    }
    // delete
    supervisor.getAgent().update(null);
}
Also used : Version(aQute.bnd.version.Version) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) LauncherSupervisor(aQute.remote.plugin.LauncherSupervisor) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

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