public boolean perform(Build build, Launcher launcher, BuildListener listener) {
    // this is where you 'build' the project
    // since this is a dummy, we just say 'hello world' and call that a build

    // this also shows how you can consult the global configuration of the builder
    if (DESCRIPTOR.useFrench()) listener.getLogger().println("Bonjour, " + name + "!");
    else listener.getLogger().println("Hello, " + name + "!");

    listener.getLogger().println("START");

    Project project = new HelloAntProject();
    project.init();

    BuildLogger logger = new DefaultLogger();
    logger.setMessageOutputLevel(Project.MSG_INFO);
    logger.setOutputPrintStream(new java.io.PrintStream(System.out));
    logger.setErrorPrintStream(new java.io.PrintStream(System.err));
    logger.setEmacsMode(false);
    //		project.addBuildListener((org.apache.tools.ant.BuildListener) listener);
    project.addBuildListener(logger);

    java.util.Vector list = new java.util.Vector();

    /*
     * ターゲットを指定 list.add("compile"); のようにすれば任意のターゲットを指定できます。
     */
    list.add(project.getDefaultTarget());
    // project.executeTargets(new java.util.Vector(list));

    listener.getLogger().println("DONE");
    return true;
  }
Пример #2
0
 private void executeSingleScenario(final File scenarioFile, final Project p) {
   getLog()
       .info(
           "Executing scenario "
               + scenarioFile.getName()
               + " with sut "
               + p.getProperty("sutFile"));
   try {
     p.fireBuildStarted();
     p.init();
     ProjectHelper helper = ProjectHelper.getProjectHelper();
     p.addReference("ant.projectHelper", helper);
     helper.parse(p, scenarioFile);
     p.executeTarget(p.getDefaultTarget());
   } catch (Exception e) {
     getLog().error("Failed to execute scenario " + scenarioFile.getName());
     getLog().error(e);
   } finally {
     p.fireBuildFinished(null);
   }
   getLog()
       .info(
           "Execution of scenario "
               + scenarioFile.getName()
               + " with sut "
               + p.getProperty("sutFile")
               + " has ended");
   getLog().info("------------------------------------------------------------------------");
 }
Пример #3
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);
  }
  /** Prepare the callable ant environment for the test. */
  private void init() {
    if (!isInited()) {

      err = System.err;
      out = System.out;
      in = System.in;

      /*
       *Use the build.xml in the current directory.
       */
      buildFile = new File("build.xml");

      /*
       *To call into ant, create a new Project and prepare it for use.
       */
      project = new Project();
      //            msgOutputLevel = Project.MSG_VERBOSE;
      project.addBuildListener(createLogger());
      project.setBasedir(".");

      project.init();

      /*
       *Set up the project to use the build.xml in the current directory.
       */
      ProjectHelper helper = ProjectHelper.getProjectHelper();
      helper.parse(project, buildFile);

      isInited = true;
    }
  }
 public MonitoredBuild(File buildFile, String target) {
   myBuildFile = buildFile;
   this.target = target;
   project = new Project();
   project = new Project();
   project.init();
   project.setUserProperty("ant.file", myBuildFile.getAbsolutePath());
   ProjectHelper.configureProject(project, myBuildFile);
 }
Пример #6
0
  /** Test execution with a valid <code>RefId</code>. */
  public void testExecuteWhenUsingValidRefId() {
    Project antProject = new Project();
    antProject.init();

    this.task.setProject(antProject);
    this.task.setId("testRefId");
    this.task.setHome("home");
    this.task.execute();

    CargoTask task2 = new CargoTask();
    task2.setProject(antProject);
    task2.setRefId(new Reference("testRefId"));
    task2.setAction("start");
    task2.execute();
  }
Пример #7
0
  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());
    }
  }
Пример #8
0
  /** Test execution with an invalid <code>RefId</code>. */
  public void testExecuteWhenUsingInvalidRefId() {
    Project antProject = new Project();
    antProject.init();

    this.task.setProject(antProject);
    this.task.setRefId(new Reference("someInexistentReference"));

    try {
      this.task.execute();
      fail("Should have thrown an exception for a non-inexistent reference here");
    } catch (BuildException expected) {
      assertEquals(
          "The [someInexistentReference] reference does not exist. You must first "
              + "define a Cargo container reference.",
          expected.getMessage());
    }
  }
Пример #9
0
  // Lazy eval - if we don't need to compile we probably don't need the project
  protected Project getProject() {

    if (project != null) return project;

    // Initializing project
    project = new Project();
    logger = new JasperAntLogger();
    logger.setOutputPrintStream(System.out);
    logger.setErrorPrintStream(System.err);
    logger.setMessageOutputLevel(Project.MSG_INFO);
    project.addBuildListener(logger);
    if (System.getProperty(Constants.CATALINA_HOME_PROP) != null) {
      project.setBasedir(System.getProperty(Constants.CATALINA_HOME_PROP));
    }

    if (options.getCompiler() != null) {
      if (log.isDebugEnabled()) log.debug("Compiler " + options.getCompiler());
      project.setProperty("build.compiler", options.getCompiler());
    }
    project.init();
    return project;
  }
Пример #10
0
  /**
   * Initializes a new Ant Project.
   *
   * @param _buildFile The build File to use. If none is provided, it will be \ defaulted to
   *     "build.xml".
   * @param _baseDir The project's base directory. If none is provided, will be \ defaulted to "."
   *     (the current directory).
   * @throws Exception Exceptions are self-explanatory (read their Message)
   */
  public void init(String _buildFile, String _baseDir) throws Exception {
    // Create a new project, and perform some default initialization
    project = new Project();
    try {
      project.init();
    } catch (BuildException e) {
      throw new Exception("The default task list could not be loaded.");
    }

    // Set the base directory. If none is given, "." is used.
    if (_baseDir == null) _baseDir = new String(".");
    try {
      project.setBasedir(_baseDir);
    } catch (BuildException e) {
      throw new Exception("The given basedir doesn't exist, or isn't a directory.");
    }

    if (_buildFile == null) _buildFile = new String("build.xml");
    try {
      ProjectHelper.getProjectHelper().parse(project, new File(_buildFile));
    } catch (BuildException e) {
      throw new Exception("Configuration file " + _buildFile + " is invalid, or cannot be read.");
    }
  }
Пример #11
0
  /**
   * Attempt to build this entry.
   *
   * @param packagerResource packager metadata resource
   * @param properties a map of properties to pass to the child Ant build responsible for dependency
   *     packaging
   * @throws IllegalStateException if this entry has already been built
   */
  public synchronized void build(Resource packagerResource, Map properties) throws IOException {
    // Sanity check
    if (this.built) {
      throw new IllegalStateException("build in directory `" + this.dir + "' already completed");
    }

    // Remove work directory if it exists (e.g. left over from last time)
    if (this.dir.exists()) {
      if (!cleanup()) {
        throw new IOException("can't remove directory `" + this.dir + "'");
      }
    }

    // Create work directory
    if (!this.dir.mkdirs()) {
      throw new IOException("can't create directory `" + this.dir + "'");
    }

    // Write out packager XML
    InputStream packagerXML = packagerResource.openStream();
    saveFile("packager.xml", packagerXML);

    // Write packager XSLT
    saveFile("packager.xsl");

    // Write packager XSD
    saveFile("packager-1.0.xsd");

    // Write master Ant build file
    saveFile("build.xml");

    // Execute the Ant build file
    Project project = new Project();
    project.init();
    project.setUserProperty("ant.file", new File(dir, "build.xml").getAbsolutePath());
    ProjectHelper.configureProject(project, new File(dir, "build.xml"));
    project.setBaseDir(dir);

    // Configure logging verbosity
    BuildLogger logger = new DefaultLogger();
    logger.setMessageOutputLevel(
        this.verbose ? Project.MSG_VERBOSE : this.quiet ? Project.MSG_WARN : Project.MSG_INFO);
    logger.setOutputPrintStream(System.out);
    logger.setErrorPrintStream(System.err);
    project.addBuildListener(logger);

    // Set properties
    project.setUserProperty(
        "ivy.packager.organisation", "" + this.mr.getModuleId().getOrganisation());
    project.setUserProperty("ivy.packager.module", "" + this.mr.getModuleId().getName());
    project.setUserProperty("ivy.packager.revision", "" + this.mr.getRevision());
    project.setUserProperty("ivy.packager.branch", "" + this.mr.getBranch());
    if (this.resourceCache != null) {
      project.setUserProperty(
          "ivy.packager.resourceCache", "" + this.resourceCache.getCanonicalPath());
    }
    if (this.resourceURL != null) {
      project.setUserProperty("ivy.packager.resourceURL", "" + getResourceURL());
    }
    if (this.validate) {
      project.setUserProperty("ivy.packager.validate", "true");
    }
    project.setUserProperty("ivy.packager.restricted", "" + this.restricted);
    project.setUserProperty("ivy.packager.quiet", String.valueOf(quiet));
    if (properties != null) {
      for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
        Entry entry = (Entry) it.next();
        project.setUserProperty((String) entry.getKey(), (String) entry.getValue());
      }
    }

    // Execute task
    Message.verbose("performing packager resolver build in " + this.dir);
    try {
      project.executeTarget("build");
      this.built = true;
    } catch (BuildException e) {
      Message.verbose("packager resolver build failed: " + e);
      throw e;
    }
  }
Пример #12
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);
    }
  }
Пример #13
0
 @Before
 public void setUp() {
   p = new Project();
   p.init();
 }