Search in sources :

Example 6 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Tool method doJavadoc.

public Jar doJavadoc(Map<String, String> options, boolean exportsOnly) throws Exception {
    if (!hasSources())
        return new Jar("javadoc");
    IO.mkdirs(javadoc);
    List<String> args = new ArrayList<>();
    args.add("-quiet");
    args.add("-protected");
    args.add(String.format("%s '%s'", "-d", fileName(javadoc)));
    args.add("-charset 'UTF-8'");
    args.add(String.format("%s '%s'", "-sourcepath", fileName(sources)));
    Properties pp = new UTF8Properties();
    pp.putAll(options);
    String name = manifest.getBundleName();
    if (name == null)
        name = manifest.getBundleSymbolicName().getKey();
    String version = manifest.getBundleVersion();
    if (version == null)
        version = Version.LOWEST.toString();
    String bundleDescription = manifest.getBundleDescription();
    if (bundleDescription != null && !Strings.trim(bundleDescription).isEmpty()) {
        printOverview(name, version, bundleDescription);
    }
    set(pp, "-doctitle", name);
    set(pp, "-windowtitle", name);
    set(pp, "-header", manifest.getBundleVendor());
    set(pp, "-bottom", manifest.getBundleCopyright());
    set(pp, "-footer", manifest.getBundleDocURL());
    args.add("-tag 'Immutable:t:\"Immutable\"'");
    args.add("-tag 'ThreadSafe:t:\"ThreadSafe\"'");
    args.add("-tag 'NotThreadSafe:t:\"NotThreadSafe\"'");
    args.add("-tag 'GuardedBy:mf:\"Guarded By:\"'");
    args.add("-tag 'security:m:\"Required Permissions\"'");
    args.add("-tag 'noimplement:t:\"Consumers of this API must not implement this interface\"'");
    for (Enumeration<?> e = pp.propertyNames(); e.hasMoreElements(); ) {
        String key = (String) e.nextElement();
        String value = pp.getProperty(key);
        if (key.startsWith("-")) {
            //
            // Allow people to add the same command multiple times
            // by suffixing it with '.' something
            //
            int n = key.lastIndexOf('.');
            if (n > 0) {
                key = key.substring(0, n);
            }
            args.add(String.format("%s '%s'", key, escape(value)));
        }
    }
    FileSet set = new FileSet(sources, "**.java");
    for (File f : set.getFiles()) {
        args.add(String.format("'%s'", fileName(f)));
    }
    if (exportsOnly) {
        Parameters exports = manifest.getExportPackage();
        for (String packageName : exports.keySet()) {
            args.add(String.format("'%s'", packageName));
        }
    }
    StringBuilder sb = new StringBuilder();
    for (String arg : args) {
        sb.append(arg);
        sb.append('\n');
    }
    IO.store(sb, javadocOptions);
    Command command = new Command();
    command.add(getProperty("javadoc", "javadoc"));
    command.add("@" + fileName(javadocOptions));
    StringBuilder out = new StringBuilder();
    StringBuilder err = new StringBuilder();
    int result = command.execute(out, err);
    if (result != 0) {
        warning("Error during execution of javadoc command: %s\n******************\n%s", out, err);
    }
    return new Jar(javadoc);
}
Also used : Parameters(aQute.bnd.header.Parameters) FileSet(aQute.lib.fileset.FileSet) ArrayList(java.util.ArrayList) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Command(aQute.libg.command.Command) Jar(aQute.bnd.osgi.Jar) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 7 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class Env method setProperties.

public void setProperties(File file) throws Exception {
    if (!file.isFile())
        error("No such file %s", file);
    else {
        UTF8Properties props = new UTF8Properties();
        props.load(file, this);
        putAll(props);
    }
}
Also used : UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 8 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class BndTask method executeBackwardCompatible.

@SuppressWarnings("cast")
private void executeBackwardCompatible() throws BuildException {
    try {
        if (files == null)
            throw new BuildException("No files set");
        if (eclipse) {
            File project = getProject().getBaseDir();
            EclipseClasspath cp = new EclipseClasspath(this, project.getParentFile(), project);
            classpath.addAll(cp.getClasspath());
            classpath.addAll(cp.getBootclasspath());
            sourcepath.addAll(cp.getSourcepath());
            // classpath.add(cp.getOutput());
            if (report())
                throw new BuildException("Errors during Eclipse Path inspection");
        }
        if (output == null)
            output = getProject().getBaseDir();
        for (Iterator<File> f = files.iterator(); f.hasNext(); ) {
            File file = f.next();
            Builder builder = new Builder();
            builder.setPedantic(isPedantic());
            if (file.exists()) {
                // Do nice property calculations
                // merging includes etc.
                builder.setProperties(file);
            }
            // properties, if the inherit flag is specified
            if (inherit) {
                Properties projectProperties = new UTF8Properties();
                @SuppressWarnings("unchecked") Hashtable<Object, Object> antProps = getProject().getProperties();
                projectProperties.putAll(antProps);
                projectProperties.putAll(builder.getProperties());
                builder.setProperties(projectProperties);
            }
            builder.setClasspath(toFiles(classpath, "classpath"));
            builder.setSourcepath(toFiles(sourcepath, "sourcepath"));
            Jar[] jars = builder.builds();
            // Report both task failures and bnd build failures.
            boolean taskFailed = report();
            boolean bndFailed = report(builder);
            // failed or the bnd build failed.
            if (!failok && (taskFailed || bndFailed)) {
                throw new BuildException("bnd failed", new org.apache.tools.ant.Location(file.getAbsolutePath()));
            }
            for (int i = 0; i < jars.length; i++) {
                Jar jar = jars[i];
                String bsn = jar.getName();
                File base = file.getParentFile();
                File output = this.output;
                String path = builder.getProperty("-output");
                if (output == null) {
                    if (path == null)
                        output = getFile(base, bsn + ".jar");
                    else {
                        output = getFile(base, path);
                    }
                } else if (output.isDirectory()) {
                    if (path == null)
                        output = getFile(this.output, bsn + ".jar");
                    else
                        output = getFile(this.output, path);
                } else if (output.isFile()) {
                    if (files.size() > 1)
                        messages.GotFileNeedDir_(output.getAbsoluteFile());
                }
                String msg = "";
                if (!output.exists() || output.lastModified() <= jar.lastModified()) {
                    jar.write(output);
                } else {
                    msg = "(not modified)";
                }
                logger.debug("{} ({}) {} {}", jar.getName(), output.getName(), jar.getResources().size(), msg);
                report();
                jar.close();
            }
            builder.close();
        }
    } catch (Exception e) {
        // if (exceptions)
        e.printStackTrace();
        if (!failok)
            throw new BuildException("Failed to build jar file: ", e);
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) Builder(aQute.bnd.osgi.Builder) Properties(java.util.Properties) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) BuildException(org.apache.tools.ant.BuildException) Jar(aQute.bnd.osgi.Jar) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 9 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class MavenCommand method bundle.

/**
	 * Create a maven bundle.
	 * 
	 * @param args
	 * @param i
	 * @throws Exception
	 */
private void bundle(String[] args, int i) throws Exception {
    List<String> developers = new ArrayList<String>();
    Properties properties = new UTF8Properties();
    String scm = null;
    String passphrase = null;
    String javadoc = null;
    String source = null;
    String output = "bundle.jar";
    String url = null;
    String artifact = null;
    String group = null;
    String version = null;
    boolean nodelete = false;
    while (i < args.length && args[i].startsWith("-")) {
        String option = args[i++];
        logger.debug("bundle option {}", option);
        if (option.equals("-scm"))
            scm = args[i++];
        else if (option.equals("-group"))
            group = args[i++];
        else if (option.equals("-artifact"))
            artifact = args[i++];
        else if (option.equals("-version"))
            version = args[i++];
        else if (option.equals("-developer"))
            developers.add(args[i++]);
        else if (option.equals("-passphrase")) {
            passphrase = args[i++];
        } else if (option.equals("-url")) {
            url = args[i++];
        } else if (option.equals("-javadoc"))
            javadoc = args[i++];
        else if (option.equals("-source"))
            source = args[i++];
        else if (option.equals("-output"))
            output = args[i++];
        else if (option.equals("-nodelete"))
            nodelete = true;
        else if (option.startsWith("-properties")) {
            try (InputStream in = IO.stream(Paths.get(args[i++]))) {
                properties.load(in);
            } catch (Exception e) {
            }
        }
    }
    if (developers.isEmpty()) {
        String email = settings.remove("email");
        if (email == null)
            error("No developer email set, you can set global default email with: bnd global email Peter.Kriens@aQute.biz");
        else
            developers.add(email);
    }
    if (i == args.length) {
        error("too few arguments, no bundle specified");
        return;
    }
    if (i != args.length - 1) {
        error("too many arguments, only one bundle allowed");
        return;
    }
    String input = args[i++];
    Jar binaryJar = getJarFromFileOrURL(input);
    logger.debug("got {}", binaryJar);
    if (binaryJar == null) {
        error("JAR does not exist: %s", input);
        return;
    }
    File original = getFile(temp, "original");
    IO.mkdirs(original);
    binaryJar.expand(original);
    binaryJar.calcChecksums(null);
    Manifest manifest = binaryJar.getManifest();
    logger.debug("got manifest");
    @SuppressWarnings("resource") PomFromManifest pom = new PomFromManifest(manifest);
    if (scm != null)
        pom.setSCM(scm);
    if (url != null)
        pom.setURL(url);
    if (artifact != null)
        pom.setArtifact(artifact);
    if (artifact != null)
        pom.setGroup(group);
    if (version != null)
        pom.setVersion(version);
    logger.debug("{}", url);
    for (String d : developers) pom.addDeveloper(d);
    Set<String> exports = OSGiHeader.parseHeader(manifest.getMainAttributes().getValue(Constants.EXPORT_PACKAGE)).keySet();
    Jar sourceJar;
    if (source == null) {
        logger.debug("Splitting source code");
        sourceJar = new Jar("source");
        for (Map.Entry<String, Resource> entry : binaryJar.getResources().entrySet()) {
            if (entry.getKey().startsWith("OSGI-OPT/src")) {
                sourceJar.putResource(entry.getKey().substring("OSGI-OPT/src/".length()), entry.getValue());
            }
        }
        copyInfo(binaryJar, sourceJar, "source");
    } else {
        sourceJar = getJarFromFileOrURL(source);
    }
    sourceJar.calcChecksums(null);
    Jar javadocJar;
    if (javadoc == null) {
        logger.debug("creating javadoc because -javadoc not used");
        javadocJar = javadoc(getFile(original, "OSGI-OPT/src"), exports, manifest, properties);
        if (javadocJar == null) {
            error("Cannot find source code in OSGI-OPT/src to generate Javadoc");
            return;
        }
        copyInfo(binaryJar, javadocJar, "javadoc");
    } else {
        logger.debug("Loading javadoc externally {}", javadoc);
        javadocJar = getJarFromFileOrURL(javadoc);
    }
    javadocJar.calcChecksums(null);
    addClose(binaryJar);
    addClose(sourceJar);
    addClose(javadocJar);
    logger.debug("creating bundle dir");
    File bundle = new File(temp, "bundle");
    IO.mkdirs(bundle);
    String prefix = pom.getArtifactId() + "-" + pom.getVersion();
    File binaryFile = new File(bundle, prefix + ".jar");
    File sourceFile = new File(bundle, prefix + "-sources.jar");
    File javadocFile = new File(bundle, prefix + "-javadoc.jar");
    File pomFile = new File(bundle, "pom.xml").getAbsoluteFile();
    logger.debug("creating output files {}, {}, {}, and {}", binaryFile, sourceFile, javadocFile, pomFile);
    IO.copy(pom.openInputStream(), pomFile);
    logger.debug("copied pom");
    logger.debug("writing binary {}", binaryFile);
    binaryJar.write(binaryFile);
    logger.debug("writing source {}", sourceFile);
    sourceJar.write(sourceFile);
    logger.debug("writing javadoc {}", javadocFile);
    javadocJar.write(javadocFile);
    sign(binaryFile, passphrase);
    sign(sourceFile, passphrase);
    sign(javadocFile, passphrase);
    sign(pomFile, passphrase);
    logger.debug("create bundle");
    Jar bundleJar = new Jar(bundle);
    addClose(bundleJar);
    File outputFile = getFile(output);
    bundleJar.write(outputFile);
    logger.debug("created bundle {}", outputFile);
    binaryJar.close();
    sourceJar.close();
    javadocJar.close();
    bundleJar.close();
    if (!nodelete)
        IO.delete(temp);
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(aQute.bnd.osgi.Resource) UTF8Properties(aQute.lib.utf8properties.UTF8Properties) Properties(java.util.Properties) Manifest(java.util.jar.Manifest) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Map(java.util.Map) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Example 10 with UTF8Properties

use of aQute.lib.utf8properties.UTF8Properties in project bnd by bndtools.

the class MavenEntry method getProperties.

/**
	 * Answer the properties, loading if needed.
	 */
protected Properties getProperties() {
    if (properties == null) {
        properties = new UTF8Properties();
        File props = new File(dir, "bnd.properties");
        if (props.exists()) {
            try {
                properties.load(props, null);
            } catch (Exception e) {
            // we ignore for now, will handle it on safe
            }
        }
    }
    return properties;
}
Also used : File(java.io.File) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) UTF8Properties(aQute.lib.utf8properties.UTF8Properties)

Aggregations

UTF8Properties (aQute.lib.utf8properties.UTF8Properties)33 Properties (java.util.Properties)18 File (java.io.File)14 InputStream (java.io.InputStream)11 IOException (java.io.IOException)10 Jar (aQute.bnd.osgi.Jar)7 Attributes (java.util.jar.Attributes)5 Manifest (java.util.jar.Manifest)5 FileNotFoundException (java.io.FileNotFoundException)4 StringReader (java.io.StringReader)4 Parameters (aQute.bnd.header.Parameters)3 Processor (aQute.bnd.osgi.Processor)3 MalformedURLException (java.net.MalformedURLException)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Builder (aQute.bnd.osgi.Builder)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2 Resource (aQute.bnd.osgi.Resource)2 LauncherConstants (aQute.launcher.constants.LauncherConstants)2 Command (aQute.libg.command.Command)2