Example #1
0
 public static 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());
 }
Example #2
0
  @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);
        }

        // get them and merge them with the project
        // 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);

        // Fail this build if failure is not ok and either the task
        // 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)";
          }
          trace("%s (%s) %s %s", 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);
    }
  }