use of aQute.bnd.properties.Document in project bndtools by bndtools.
the class ReleaseHelper method updateBundleVersion.
private static void updateBundleVersion(ReleaseContext context, Baseline current, Builder builder) throws IOException, CoreException {
Version bundleVersion = current.getSuggestedVersion();
if (bundleVersion != null) {
File file = builder.getPropertiesFile();
Properties properties = builder.getProperties();
if (file == null) {
file = context.getProject().getPropertiesFile();
properties = context.getProject().getProperties();
}
final IFile resource = (IFile) ReleaseUtils.toResource(file);
final Document document;
if (resource.exists()) {
byte[] bytes = readFully(resource.getContents());
document = new Document(new String(bytes, resource.getCharset()));
} else {
//$NON-NLS-1$
document = new Document("");
}
final BndEditModel model;
BndEditModel model2;
try {
model2 = new BndEditModel(Central.getWorkspace());
} catch (Exception e) {
System.err.println("Unable to create BndEditModel with Workspace, defaulting to without Workspace");
model2 = new BndEditModel();
}
model = model2;
model.loadFrom(document);
String currentVersion = model.getBundleVersionString();
String templateVersion = updateTemplateVersion(currentVersion, bundleVersion);
model.setBundleVersion(templateVersion);
properties.setProperty(Constants.BUNDLE_VERSION, templateVersion);
final Document finalDoc = document;
Runnable run = new Runnable() {
@Override
public void run() {
model.saveChangesTo(finalDoc);
try {
writeFully(finalDoc.get(), resource, false);
resource.refreshLocal(IResource.DEPTH_ZERO, null);
} catch (CoreException e) {
throw new RuntimeException(e);
}
}
};
if (Display.getCurrent() == null) {
Display.getDefault().syncExec(run);
} else
run.run();
}
}
use of aQute.bnd.properties.Document in project bndtools by bndtools.
the class EnrouteProjectTemplate method generateBndFile.
private Resource generateBndFile(String projectName, String pkg) {
BndEditModel model = new BndEditModel();
model.setPrivatePackages(Arrays.asList(new String[] { pkg + ".provider" }));
model.setExportedPackages(Arrays.asList(new ExportedPackage(projectName + ".api", new Attrs())));
model.setBundleDescription("${warning:please explain what this bundle does}");
model.setBundleVersion("1.0.0.${tstamp}");
List<VersionedClause> buildPath = new ArrayList<VersionedClause>();
List<VersionedClause> tmp;
tmp = model.getBuildPath();
if (tmp != null)
buildPath.addAll(tmp);
Attrs attrs = new Attrs();
attrs.put("version", "@1.0");
buildPath.add(new VersionedClause("osgi.enroute.base.api", attrs));
buildPath.add(new VersionedClause("osgi.enroute.base.junit", attrs));
model.setBuildPath(buildPath);
Document doc = new Document("");
model.saveChangesTo(doc);
StringResource bndBndResource = new StringResource(doc.get());
return bndBndResource;
}
use of aQute.bnd.properties.Document in project bndtools by bndtools.
the class AbstractNewBndProjectWizard method processGeneratedProject.
/**
* Modify the newly generated Java project; this method is executed from within a workspace operation so is free to
* make workspace resource modifications.
*
* @throws CoreException
*/
protected void processGeneratedProject(ProjectPaths projectPaths, BndEditModel bndModel, IJavaProject project, IProgressMonitor monitor) throws CoreException {
SubMonitor progress = SubMonitor.convert(monitor, 3);
Document document = new Document("");
bndModel.saveChangesTo(document);
progress.worked(1);
ByteArrayInputStream bndInput;
try {
bndInput = new ByteArrayInputStream(document.get().getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
return;
}
IFile bndBndFile = project.getProject().getFile(Project.BNDFILE);
if (bndBndFile.exists()) {
bndBndFile.setContents(bndInput, false, false, progress.newChild(1));
}
BndProject proj = generateBndProject(project.getProject(), progress.newChild(1));
progress.setWorkRemaining(proj.getResources().size());
for (Map.Entry<String, BndProjectResource> resource : proj.getResources().entrySet()) {
importResource(project.getProject(), resource.getKey(), resource.getValue(), progress.newChild(1));
}
if (!bndBndFile.exists()) {
bndBndFile.create(bndInput, false, progress.newChild(1));
}
/* Version control ignores */
VersionControlIgnoresManager versionControlIgnoresManager = Plugin.getDefault().getVersionControlIgnoresManager();
Set<String> enabledIgnorePlugins = new BndPreferences().getVersionControlIgnoresPluginsEnabled(versionControlIgnoresManager, project, null);
Map<String, String> sourceOutputLocations = JavaProjectUtils.getSourceOutputLocations(project);
versionControlIgnoresManager.createProjectIgnores(enabledIgnorePlugins, project.getProject().getLocation().toFile(), sourceOutputLocations, projectPaths.getTargetDir());
/* Headless build files */
HeadlessBuildManager headlessBuildManager = Plugin.getDefault().getHeadlessBuildManager();
Set<String> enabledPlugins = new BndPreferences().getHeadlessBuildPluginsEnabled(headlessBuildManager, null);
headlessBuildManager.setup(enabledPlugins, false, project.getProject().getLocation().toFile(), true, enabledIgnorePlugins, new LinkedList<String>());
/* refresh the project; files were created outside of Eclipse API */
project.getProject().refreshLocal(IResource.DEPTH_INFINITE, progress);
project.getProject().build(IncrementalProjectBuilder.CLEAN_BUILD, progress);
}
use of aQute.bnd.properties.Document in project bnd by bndtools.
the class PropertiesTest method testBndEditModel.
public static void testBndEditModel() throws Exception {
Document doc = new Document("# Hello\nBundle-Description:\tTest ♉\n" + "\n\nBundle-SymbolicName:\ttest.properties\n" + "Private-Package:\tpp1\n");
BndEditModel model = new BndEditModel();
model.loadFrom(doc);
model.addPrivatePackage("pp2");
model.addPrivatePackage("pp3");
model.setBundleVersion("1.0.0");
model.setBundleVersion("1.1.0");
System.out.println(doc.get());
File file = File.createTempFile("test", ".properties");
IO.copy(model.toAsciiStream(doc), file);
model = new BndEditModel();
model.loadFrom(file);
Properties props = new Properties();
try (InputStream in = new FileInputStream(file)) {
props.load(in);
}
assertEquals(props.getProperty("Bundle-Version"), model.getBundleVersionString());
List<String> privatePackages = model.getPrivatePackages();
String s = props.getProperty("Private-Package");
String[] pkgs = s.split("\\,");
for (String pkg : pkgs) {
assertTrue(privatePackages.remove(pkg));
}
assertEquals(0, privatePackages.size());
String desc = props.getProperty("Bundle-Description");
assertEquals(desc, "Test ♉");
}
Aggregations