use of aQute.bnd.version.Version in project bnd by bndtools.
the class ProjectTest method testBumpIncludeFile.
public void testBumpIncludeFile() throws Exception {
Workspace ws = getWorkspace("testresources/ws");
Project project = ws.getProject("bump-included");
project.setTrace(true);
Version old = new Version(project.getProperty("Bundle-Version"));
assertEquals(new Version(1, 0, 0), old);
project.bump("=+0");
Processor processor = new Processor();
processor.setProperties(project.getFile("include.txt"));
Version newv = new Version(processor.getProperty("Bundle-Version"));
System.err.println("New version " + newv);
assertEquals(1, newv.getMajor());
assertEquals(1, newv.getMinor());
assertEquals(0, newv.getMicro());
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class ProjectTest method testBump.
public void testBump() throws Exception {
Workspace ws = getWorkspace("testresources/ws");
Project project = ws.getProject("p1");
int size = project.getProperties().size();
Version old = new Version(project.getProperty("Bundle-Version"));
System.err.println("Old version " + old);
project.bump("=+0");
Version newv = new Version(project.getProperty("Bundle-Version"));
System.err.println("New version " + newv);
assertEquals(old.getMajor(), newv.getMajor());
assertEquals(old.getMinor() + 1, newv.getMinor());
assertEquals(0, newv.getMicro());
assertEquals(size, project.getProperties().size());
assertEquals("sometime", newv.getQualifier());
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class ProjectTest method testPackageInfoType.
/*
* Verify that that -versionannotations works. We can be osgi, bnd,
* packageinfo, or an annotation. When not set, we are packageinfo
*/
public void testPackageInfoType() throws Exception {
Workspace ws = getWorkspace("testresources/ws");
Project project = ws.getProject("p5");
project.setTrace(true);
Version newVersion = new Version(2, 0, 0);
project.setProperty(Constants.PACKAGEINFOTYPE, "bnd");
// Package with no package info
project.setPackageInfo("pkg1", newVersion);
Version version = project.getPackageInfo("pkg1");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg1", false, true);
String content = IO.collect(project.getFile("src/pkg1/package-info.java"));
assertTrue(content.contains("import aQute.bnd.annotation.Version"));
// Package with package-info.java containing @Version("1.0.0")
project.setPackageInfo("pkg2", newVersion);
version = project.getPackageInfo("pkg2");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg2", false, true);
// new packageinfo must now contain osgi ann.
project.setProperty(Constants.PACKAGEINFOTYPE, "osgi");
// Package with package-info.java containing version + packageinfo
project.setPackageInfo("pkg5", newVersion);
version = project.getPackageInfo("pkg5");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg5", true, true);
content = IO.collect(project.getFile("src/pkg5/package-info.java"));
assertTrue(content.contains("import aQute.bnd.annotation.Version"));
// Package with package-info.java NOT containing version +
// packageinfo
project.setPackageInfo("pkg6", newVersion);
version = project.getPackageInfo("pkg6");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg6", true, true);
content = IO.collect(project.getFile("src/pkg6/package-info.java"));
assertTrue(content.contains("import org.osgi.annotation.versioning.Version"));
// Package with package-info.java NOT containing version
project.setPackageInfo("pkg7", newVersion);
version = project.getPackageInfo("pkg7");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg7", false, true);
newVersion = new Version(2, 2, 0);
// Update packageinfo file
project.setPackageInfo("pkg1", newVersion);
version = project.getPackageInfo("pkg1");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg1", false, true);
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class ProjectTest method testSetPackageVersion.
public void testSetPackageVersion() throws Exception {
Workspace ws = getWorkspace("testresources/ws");
Project project = ws.getProject("p5");
project.setTrace(true);
Version newVersion = new Version(2, 0, 0);
// Package with no package info
project.setPackageInfo("pkg1", newVersion);
Version version = project.getPackageInfo("pkg1");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg1", true, false);
// Package with package-info.java containing @Version("1.0.0")
project.setPackageInfo("pkg2", newVersion);
version = project.getPackageInfo("pkg2");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg2", false, true);
// Package with package-info.java containing
// @aQute.bnd.annotations.Version("1.0.0")
project.setPackageInfo("pkg3", newVersion);
version = project.getPackageInfo("pkg3");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg3", false, true);
// Package with package-info.java containing
// @aQute.bnd.annotations.Version(value="1.0.0")
project.setPackageInfo("pkg4", newVersion);
version = project.getPackageInfo("pkg4");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg4", false, true);
// Package with package-info.java containing version + packageinfo
project.setPackageInfo("pkg5", newVersion);
version = project.getPackageInfo("pkg5");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg5", true, true);
// Package with package-info.java NOT containing version +
// packageinfo
project.setPackageInfo("pkg6", newVersion);
version = project.getPackageInfo("pkg6");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg6", true, true);
// Package with package-info.java NOT containing version
project.setPackageInfo("pkg7", newVersion);
version = project.getPackageInfo("pkg7");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg7", true, true);
newVersion = new Version(2, 2, 0);
// Update packageinfo file
project.setPackageInfo("pkg1", newVersion);
version = project.getPackageInfo("pkg1");
assertEquals(newVersion, version);
checkPackageInfoFiles(project, "pkg1", true, false);
}
use of aQute.bnd.version.Version in project bnd by bndtools.
the class Project method getBundle.
/**
* Get a bundle from one of the plugin repositories. If an exact version is
* required we just return the first repository found (in declaration order
* in the build.bnd file).
*
* @param bsn The bundle symbolic name
* @param range The version range
* @param strategy set to LOWEST or HIGHEST
* @return the file object that points to the bundle or null if not found
* @throws Exception when something goes wrong
*/
public Container getBundle(String bsn, String range, Strategy strategy, Map<String, String> attrs) throws Exception {
if (range == null)
range = "0";
if (VERSION_ATTR_SNAPSHOT.equals(range) || VERSION_ATTR_PROJECT.equals(range)) {
return getBundleFromProject(bsn, attrs);
} else if (VERSION_ATTR_HASH.equals(range)) {
return getBundleByHash(bsn, attrs);
}
Strategy useStrategy = strategy;
if (VERSION_ATTR_LATEST.equals(range)) {
Container c = getBundleFromProject(bsn, attrs);
if (c != null)
return c;
useStrategy = Strategy.HIGHEST;
}
useStrategy = overrideStrategy(attrs, useStrategy);
RepoFilter repoFilter = parseRepoFilter(attrs);
List<RepositoryPlugin> plugins = workspace.getRepositories();
if (useStrategy == Strategy.EXACT) {
if (!Verifier.isVersion(range))
return new Container(this, bsn, range, Container.TYPE.ERROR, null, bsn + ";version=" + range + " Invalid version", null, null);
// For an exact range we just iterate over the repos
// and return the first we find.
Version version = new Version(range);
for (RepositoryPlugin plugin : plugins) {
DownloadBlocker blocker = new DownloadBlocker(this);
File result = plugin.get(bsn, version, attrs, blocker);
if (result != null)
return toContainer(bsn, range, attrs, result, blocker);
}
} else {
VersionRange versionRange = VERSION_ATTR_LATEST.equals(range) ? new VersionRange("0") : new VersionRange(range);
// We have a range search. Gather all the versions in all the repos
// and make a decision on that choice. If the same version is found
// in
// multiple repos we take the first
SortedMap<Version, RepositoryPlugin> versions = new TreeMap<Version, RepositoryPlugin>();
for (RepositoryPlugin plugin : plugins) {
if (repoFilter != null && !repoFilter.match(plugin))
continue;
try {
SortedSet<Version> vs = plugin.versions(bsn);
if (vs != null) {
for (Version v : vs) {
if (!versions.containsKey(v) && versionRange.includes(v))
versions.put(v, plugin);
}
}
} catch (UnsupportedOperationException ose) {
// To query, we must have a real version
if (!versions.isEmpty() && Verifier.isVersion(range)) {
Version version = new Version(range);
DownloadBlocker blocker = new DownloadBlocker(this);
File file = plugin.get(bsn, version, attrs, blocker);
// if it does, return this as a result
if (file != null)
return toContainer(bsn, range, attrs, file, blocker);
}
}
}
//
// We have to augment the list of returned versions
// with info from the workspace. We use null as a marker
// to indicate that it is a workspace project
//
SortedSet<Version> localVersions = getWorkspace().getWorkspaceRepository().versions(bsn);
for (Version v : localVersions) {
if (!versions.containsKey(v) && versionRange.includes(v))
versions.put(v, null);
}
if (!versions.isEmpty()) {
Version provider = null;
switch(useStrategy) {
case HIGHEST:
provider = versions.lastKey();
break;
case LOWEST:
provider = versions.firstKey();
break;
case EXACT:
// TODO need to handle exact better
break;
}
if (provider != null) {
RepositoryPlugin repo = versions.get(provider);
if (repo == null) {
// project
return getBundleFromProject(bsn, attrs);
}
String version = provider.toString();
DownloadBlocker blocker = new DownloadBlocker(this);
File result = repo.get(bsn, provider, attrs, blocker);
if (result != null)
return toContainer(bsn, version, attrs, result, blocker);
} else {
msgs.FoundVersions_ForStrategy_ButNoProvider(versions, useStrategy);
}
}
}
return new Container(this, bsn, range, Container.TYPE.ERROR, null, bsn + ";version=" + range + " Not found in " + plugins, null, null);
}
Aggregations