Exemple #1
0
  /**
   * Checks if the file paths in the md5sums file use only unix file separators (this test can only
   * fail on Windows)
   */
  public void testBuildDataWithFileSet() throws Exception {
    Processor processor =
        new Processor(
            new Console() {
              public void println(String s) {}
            },
            null);

    Project project = new Project();
    project.setCoreLoader(getClass().getClassLoader());
    project.init();

    FileSet fileset = new FileSet();
    fileset.setDir(new File(getClass().getResource("deb/data").toURI()));
    fileset.setIncludes("**/*");
    fileset.setProject(project);

    StringBuffer md5s = new StringBuffer();
    processor.buildData(
        new DataProducer[] {new FileSetDataProducer(fileset)},
        new File("target/data.tar"),
        md5s,
        "tar");

    assertTrue("empty md5 file", md5s.length() > 0);
    assertFalse("windows path separator found", md5s.indexOf("\\") != -1);
  }
  protected void setUp() throws Exception {
    project = new Project();
    project.setCoreLoader(getClass().getClassLoader());
    project.init();

    File buildFile = new File("target/test-classes/testbuild.xml");
    project.setBaseDir(buildFile.getParentFile());

    final ProjectHelper helper = ProjectHelper.getProjectHelper();
    helper.parse(project, buildFile);

    // remove the package previously build
    File deb = new File("target/test.deb");
    if (deb.exists()) {
      assertTrue("Unable to remove the test archive", deb.delete());
    }
  }
Exemple #3
0
  /** Runs the given targets for the test project specified */
  public Map run(
      File buildFile, List targets, Properties projectProperties, Properties pluginState) {
    Project project = new Project();
    project.setCoreLoader(getClass().getClassLoader());
    antListener = new AntRunner.AntListener();

    project.addBuildListener(
        createLogger(projectProperties.getProperty("quokka.debugger.logLevel")));
    project.addBuildListener(antListener);

    //        project.setInputHandler(new DefaultInputHandler());
    project.setInputHandler(
        new InputHandler() {
          public void handleInput(InputRequest request) throws BuildException {
            System.out.println(request.getPrompt());

            try {
              String line = new BufferedReader(new InputStreamReader(System.in)).readLine();
              request.setInput(line);
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
    project.setKeepGoingMode(false);

    //        PrintStream err = System.err;
    //        PrintStream out = System.out;
    //        InputStream in = System.in;
    project.setDefaultInputStream(System.in);

    //        System.setIn(new DemuxInputStream(project));
    //        System.setOut(new PrintStream(new DemuxOutputStream(project, false)));
    //        System.setErr(new PrintStream(new DemuxOutputStream(project, true)));
    for (Iterator i = projectProperties.entrySet().iterator(); i.hasNext(); ) {
      Map.Entry entry = (Map.Entry) i.next();
      project.setUserProperty((String) entry.getKey(), (String) entry.getValue());
    }

    Exception exception = null;

    try {
      project.fireBuildStarted();

      project.init();
      project.setUserProperty("ant.version", "1.7.0");
      project.setUserProperty("ant.file", buildFile.getAbsolutePath());

      // Remove hard dependency on core.main to allow integration tests to be
      // done within the core.main package. This is ok as AntRunner is loaded via the integration
      // test class loader.
      org.apache.tools.ant.ProjectHelper helper =
          (org.apache.tools.ant.ProjectHelper)
              getClass()
                  .getClassLoader()
                  .loadClass("ws.quokka.core.main.ant.ProjectHelper")
                  .newInstance();
      project.addReference("ant.projectHelper", helper);
      helper.parse(project, buildFile);

      // Add any plugin state
      PluginState state = (PluginState) project.getReference("quokka.pluginState");

      for (Iterator i = pluginState.entrySet().iterator(); i.hasNext(); ) {
        Map.Entry entry = (Map.Entry) i.next();
        state.put((String) entry.getKey(), entry.getValue());
      }

      Vector targetsVector = new Vector();
      targetsVector.addAll(targets);

      // make sure that we have a target to execute
      if (targets.size() == 0) {
        if (project.getDefaultTarget() != null) {
          targetsVector.add(project.getDefaultTarget());
        }
      }

      project.executeTargets(targetsVector);

      Map results = antListener.toMap();
      results.put("antProperties", new HashMap(project.getProperties()));

      return results;
    } catch (Exception e) {
      exception = e;

      if (e instanceof RuntimeException) {
        throw (RuntimeException) e;
      } else {
        throw new BuildException(e);
      }
    } finally {
      //            System.setOut(out);
      //            System.setErr(err);
      //            System.setIn(in);
      project.fireBuildFinished(exception);
    }
  }