Search in sources :

Example 6 with Document

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();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) Version(aQute.bnd.version.Version) Properties(java.util.Properties) Document(aQute.bnd.properties.Document) IFile(org.eclipse.core.resources.IFile) File(java.io.File) BndEditModel(aQute.bnd.build.model.BndEditModel) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with Document

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;
}
Also used : StringResource(org.bndtools.templating.StringResource) VersionedClause(aQute.bnd.build.model.clauses.VersionedClause) ExportedPackage(aQute.bnd.build.model.clauses.ExportedPackage) Attrs(aQute.bnd.header.Attrs) ArrayList(java.util.ArrayList) Document(aQute.bnd.properties.Document) BndEditModel(aQute.bnd.build.model.BndEditModel)

Example 8 with Document

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);
}
Also used : IFile(org.eclipse.core.resources.IFile) BndPreferences(bndtools.preferences.BndPreferences) VersionControlIgnoresManager(org.bndtools.versioncontrol.ignores.manager.api.VersionControlIgnoresManager) HeadlessBuildManager(org.bndtools.headless.build.manager.api.HeadlessBuildManager) SubMonitor(org.eclipse.core.runtime.SubMonitor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Document(aQute.bnd.properties.Document) BndProject(bndtools.editor.model.BndProject) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) BndProjectResource(org.bndtools.api.BndProjectResource)

Example 9 with Document

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 ♉");
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Document(aQute.bnd.properties.Document) Properties(java.util.Properties) BndEditModel(aQute.bnd.build.model.BndEditModel) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

Document (aQute.bnd.properties.Document)9 BndEditModel (aQute.bnd.build.model.BndEditModel)8 File (java.io.File)5 IFile (org.eclipse.core.resources.IFile)4 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)3 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 CoreException (org.eclipse.core.runtime.CoreException)3 ExportedPackage (aQute.bnd.build.model.clauses.ExportedPackage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Properties (java.util.Properties)2 IProject (org.eclipse.core.resources.IProject)2 Workspace (aQute.bnd.build.Workspace)1 ImportPattern (aQute.bnd.build.model.clauses.ImportPattern)1 Attrs (aQute.bnd.header.Attrs)1 Processor (aQute.bnd.osgi.Processor)1 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)1 IDocument (aQute.bnd.properties.IDocument)1