Search in sources :

Example 1 with EclipseClasspath

use of aQute.bnd.osgi.eclipse.EclipseClasspath in project bnd by bndtools.

the class bnd method _buildx.

@Description("Build project, is deprecated but here for backward compatibility")
public void _buildx(buildxOptions options) throws Exception {
    // Create a build order
    List<Builder> builders = new ArrayList<Builder>();
    List<String> order = new ArrayList<String>();
    List<String> active = new ArrayList<String>();
    for (String s : options._arguments()) {
        prebuild(active, order, builders, s);
    }
    for (Builder b : builders) {
        if (options.classpath() != null) {
            for (String f : options.classpath()) {
                b.addClasspath(getFile(f));
            }
        }
        if (options.sourcepath() != null) {
            for (String f : options.sourcepath()) {
                b.addSourcepath(getFile(f));
            }
        }
        if (options.sources())
            b.setSources(true);
        if (options.eclipse()) {
            EclipseClasspath ep = new EclipseClasspath(this, getBase().getParentFile(), getBase());
            b.addClasspath(ep.getClasspath());
            b.addClasspath(ep.getBootclasspath());
            b.addSourcepath(ep.getSourcepath());
        }
        Jar jar = b.build();
        File outputFile = b.getOutputFile(options.output());
        if (options.pom()) {
            Resource r = new PomFromManifest(jar.getManifest());
            jar.putResource("pom.xml", r);
            String path = outputFile.getName().replaceAll("\\.jar$", ".pom");
            if (path.equals(outputFile.getName()))
                path = outputFile.getName() + ".pom";
            File pom = new File(outputFile.getParentFile(), path);
            try (OutputStream os = IO.outputStream(pom)) {
                r.write(os);
            }
        }
        getInfo(b, b.getPropertiesFile().getName());
        if (isOk()) {
            b.save(outputFile, options.force());
        }
        b.close();
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) Builder(aQute.bnd.osgi.Builder) DocumentBuilder(javax.xml.parsers.DocumentBuilder) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) FileResource(aQute.bnd.osgi.FileResource) Resource(aQute.bnd.osgi.Resource) PomFromManifest(aQute.bnd.maven.PomFromManifest) Jar(aQute.bnd.osgi.Jar) File(java.io.File) Description(aQute.lib.getopt.Description)

Example 2 with EclipseClasspath

use of aQute.bnd.osgi.eclipse.EclipseClasspath 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 3 with EclipseClasspath

use of aQute.bnd.osgi.eclipse.EclipseClasspath in project bnd by bndtools.

the class ProjectTest method testClasspath.

public void testClasspath() throws Exception {
    File project = new File("").getAbsoluteFile();
    File workspace = project.getParentFile();
    Processor processor = new Processor();
    EclipseClasspath p = new EclipseClasspath(processor, workspace, project);
    System.err.println(p.getDependents());
    System.err.println(p.getClasspath());
    System.err.println(p.getSourcepath());
    System.err.println(p.getOutput());
}
Also used : Processor(aQute.bnd.osgi.Processor) EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) File(java.io.File)

Example 4 with EclipseClasspath

use of aQute.bnd.osgi.eclipse.EclipseClasspath in project bnd by bndtools.

the class EclipseTask method execute.

@Override
public void execute() throws BuildException {
    try {
        if (projectLocation == null)
            projectLocation = getProject().getBaseDir();
        if (workspaceLocation == null)
            workspaceLocation = projectLocation.getParentFile();
        EclipseClasspath eclipse = new EclipseClasspath(this, workspaceLocation, projectLocation);
        if (report())
            throw new BuildException("Errors during Eclipse Path inspection");
        addProperty(prefix + "classpath", join(eclipse.getClasspath(), separator));
        addProperty(prefix + "bootclasspath", join(eclipse.getBootclasspath(), separator));
        if (!eclipse.getSourcepath().isEmpty())
            addProperty(prefix + "sourcepath", join(eclipse.getSourcepath(), separator));
        addProperty(prefix + "output", eclipse.getOutput().getAbsolutePath());
        /**
			 * The prebuild is an attribute that is prepended to the dependency
			 * path derived from the Eclipse project
			 */
        List<File> dependents = new ArrayList<File>();
        addCareful(dependents, prebuild);
        addCareful(dependents, eclipse.getDependents());
        if (dependents.size() > 0) {
            addProperty(prefix + "buildpath", join(dependents, separator));
        }
    } catch (Exception e) {
        throw new BuildException("Error during parsing Eclipse .classpath files", e);
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) ArrayList(java.util.ArrayList) BuildException(org.apache.tools.ant.BuildException) File(java.io.File) BuildException(org.apache.tools.ant.BuildException)

Example 5 with EclipseClasspath

use of aQute.bnd.osgi.eclipse.EclipseClasspath in project bnd by bndtools.

the class bnd method _eclipse.

@Description("Show info about the current directory's eclipse project")
public void _eclipse(eclipseOptions options) throws Exception {
    File dir = getBase();
    if (options.dir() != null)
        dir = getFile(options.dir());
    if (!dir.isDirectory())
        error("Eclipse requires a path to a directory: %s", dir.getAbsolutePath());
    if (options._arguments().size() != 0)
        error("Unnecessary arguments %s", options._arguments());
    if (!isOk())
        return;
    File cp = new File(dir, ".classpath");
    if (!cp.exists()) {
        error("Cannot find .classpath in project directory: %s", dir.getAbsolutePath());
    } else {
        EclipseClasspath eclipse = new EclipseClasspath(this, dir.getParentFile(), dir);
        err.println("Classpath    " + eclipse.getClasspath());
        err.println("Dependents   " + eclipse.getDependents());
        err.println("Sourcepath   " + eclipse.getSourcepath());
        err.println("Output       " + eclipse.getOutput());
        err.println();
    }
}
Also used : EclipseClasspath(aQute.bnd.osgi.eclipse.EclipseClasspath) File(java.io.File) Description(aQute.lib.getopt.Description)

Aggregations

EclipseClasspath (aQute.bnd.osgi.eclipse.EclipseClasspath)6 File (java.io.File)6 Builder (aQute.bnd.osgi.Builder)2 Jar (aQute.bnd.osgi.Jar)2 Description (aQute.lib.getopt.Description)2 ArrayList (java.util.ArrayList)2 BuildException (org.apache.tools.ant.BuildException)2 Attrs (aQute.bnd.header.Attrs)1 PomFromManifest (aQute.bnd.maven.PomFromManifest)1 FileResource (aQute.bnd.osgi.FileResource)1 Processor (aQute.bnd.osgi.Processor)1 Resource (aQute.bnd.osgi.Resource)1 UTF8Properties (aQute.lib.utf8properties.UTF8Properties)1 OutputStream (java.io.OutputStream)1 Properties (java.util.Properties)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1