コード例 #1
0
ファイル: JSystemMojo.java プロジェクト: Top-Q/jsystem
 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("------------------------------------------------------------------------");
 }
  /** 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;
    }
  }
コード例 #3
0
ファイル: DebAntTaskTestCase.java プロジェクト: urchinly/jdeb
  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());
    }
  }
コード例 #4
0
 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);
 }
コード例 #5
0
 public void execute() {
   if (this.nestedTask == null) {
     throw new BuildException("Missing nested element");
   }
   if (this.name == null) {
     throw new BuildException("Name not specified");
   }
   this.name = ProjectHelper.genComponentName(this.getURI(), this.name);
   final ComponentHelper helper = ComponentHelper.getComponentHelper(this.getProject());
   final String componentName =
       ProjectHelper.genComponentName(this.nestedTask.getNamespace(), this.nestedTask.getTag());
   final AntTypeDefinition def = helper.getDefinition(componentName);
   if (def == null) {
     throw new BuildException("Unable to find typedef " + componentName);
   }
   final PreSetDefinition newDef = new PreSetDefinition(def, this.nestedTask);
   newDef.setName(this.name);
   helper.addDataTypeDefinition(newDef);
   this.log("defining preset " + this.name, 3);
 }
コード例 #6
0
ファイル: AntRunner.java プロジェクト: robayet/openiot
  /**
   * 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.");
    }
  }
コード例 #7
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;
    }
  }
コード例 #8
0
ファイル: AntRunner.java プロジェクト: andrewoma/quokka
  /** 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);
    }
  }
コード例 #9
0
    /**
     * Initialisation routine called after handler creation with the element name and attributes.
     * The attributes which this handler can deal with are: <code>"name"</code>, <code>"depends"
     * </code>, <code>"if"</code>, <code>"unless"</code>, <code>"id"</code> and <code>"description"
     * </code>.
     *
     * @param uri The namespace URI for this element.
     * @param tag Name of the element which caused this handler to be created. Should not be <code>
     *     null</code>. Ignored in this implementation.
     * @param qname The qualified name for this element.
     * @param attrs Attributes of the element which caused this handler to be created. Must not be
     *     <code>null</code>.
     * @param context The current context.
     * @exception SAXParseException if an unexpected attribute is encountered or if the <code>"name"
     *     </code> attribute is missing.
     */
    public void onStartElement(
        String uri, String tag, String qname, Attributes attrs, AntXMLContext context)
        throws SAXParseException {
      String name = null;
      String depends = "";
      String extensionPoint = null;
      OnMissingExtensionPoint extensionPointMissing = null;

      Project project = context.getProject();
      Target target = "target".equals(tag) ? new Target() : new ExtensionPoint();
      target.setProject(project);
      target.setLocation(new Location(context.getLocator()));
      context.addTarget(target);

      for (int i = 0; i < attrs.getLength(); i++) {
        String attrUri = attrs.getURI(i);
        if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
          continue; // Ignore attributes from unknown uris
        }
        String key = attrs.getLocalName(i);
        String value = attrs.getValue(i);

        if (key.equals("name")) {
          name = value;
          if ("".equals(name)) {
            throw new BuildException("name attribute must " + "not be empty");
          }
        } else if (key.equals("depends")) {
          depends = value;
        } else if (key.equals("if")) {
          target.setIf(value);
        } else if (key.equals("unless")) {
          target.setUnless(value);
        } else if (key.equals("id")) {
          if (value != null && !value.equals("")) {
            context.getProject().addReference(value, target);
          }
        } else if (key.equals("description")) {
          target.setDescription(value);
        } else if (key.equals("extensionOf")) {
          extensionPoint = value;
        } else if (key.equals("onMissingExtensionPoint")) {
          try {
            extensionPointMissing = OnMissingExtensionPoint.valueOf(value);
          } catch (IllegalArgumentException e) {
            throw new BuildException("Invalid onMissingExtensionPoint " + value);
          }
        } else {
          throw new SAXParseException("Unexpected attribute \"" + key + "\"", context.getLocator());
        }
      }

      if (name == null) {
        throw new SAXParseException(
            "target element appears without a name attribute", context.getLocator());
      }

      String prefix = null;
      boolean isInIncludeMode = context.isIgnoringProjectTag() && isInIncludeMode();
      String sep = getCurrentPrefixSeparator();

      if (isInIncludeMode) {
        prefix = getTargetPrefix(context);
        if (prefix == null) {
          throw new BuildException(
              "can't include build file "
                  + context.getBuildFileURL()
                  + ", no as attribute has been given"
                  + " and the project tag doesn't"
                  + " specify a name attribute");
        }
        name = prefix + sep + name;
      }

      // Check if this target is in the current build file
      if (context.getCurrentTargets().get(name) != null) {
        throw new BuildException("Duplicate target '" + name + "'", target.getLocation());
      }
      Hashtable projectTargets = project.getTargets();
      boolean usedTarget = false;
      // If the name has not already been defined define it
      if (projectTargets.containsKey(name)) {
        project.log(
            "Already defined in main or a previous import, ignore " + name, Project.MSG_VERBOSE);
      } else {
        target.setName(name);
        context.getCurrentTargets().put(name, target);
        project.addOrReplaceTarget(name, target);
        usedTarget = true;
      }

      if (depends.length() > 0) {
        if (!isInIncludeMode) {
          target.setDepends(depends);
        } else {
          for (Iterator iter = Target.parseDepends(depends, name, "depends").iterator();
              iter.hasNext(); ) {
            target.addDependency(prefix + sep + iter.next());
          }
        }
      }
      if (!isInIncludeMode
          && context.isIgnoringProjectTag()
          && (prefix = getTargetPrefix(context)) != null) {
        // In an imported file (and not completely
        // ignoring the project tag or having a preconfigured prefix)
        String newName = prefix + sep + name;
        Target newTarget = usedTarget ? new Target(target) : target;
        newTarget.setName(newName);
        context.getCurrentTargets().put(newName, newTarget);
        project.addOrReplaceTarget(newName, newTarget);
      }
      if (extensionPointMissing != null && extensionPoint == null) {
        throw new BuildException(
            "onMissingExtensionPoint attribute cannot "
                + "be specified unless extensionOf is specified",
            target.getLocation());
      }
      if (extensionPoint != null) {
        ProjectHelper helper =
            (ProjectHelper)
                context.getProject().getReference(ProjectHelper.PROJECTHELPER_REFERENCE);
        for (Iterator iter = Target.parseDepends(extensionPoint, name, "extensionOf").iterator();
            iter.hasNext(); ) {
          String tgName = (String) iter.next();
          if (isInIncludeMode()) {
            tgName = prefix + sep + tgName;
          }
          if (extensionPointMissing == null) {
            extensionPointMissing = OnMissingExtensionPoint.FAIL;
          }
          // defer extensionpoint resolution until the full
          // import stack has been processed
          helper.getExtensionStack().add(new String[] {tgName, name, extensionPointMissing.name()});
        }
      }
    }
コード例 #10
0
    /**
     * Initialisation routine called after handler creation with the element name and attributes.
     * This configures the element with its attributes and sets it up with its parent container (if
     * any). Nested elements are then added later as the parser encounters them.
     *
     * @param uri The namespace URI for this element.
     * @param tag Name of the element which caused this handler to be created. Must not be <code>
     *     null</code>.
     * @param qname The qualified name for this element.
     * @param attrs Attributes of the element which caused this handler to be created. Must not be
     *     <code>null</code>.
     * @param context The current context.
     * @exception SAXParseException in case of error (not thrown in this implementation)
     */
    public void onStartElement(
        String uri, String tag, String qname, Attributes attrs, AntXMLContext context)
        throws SAXParseException {
      RuntimeConfigurable parentWrapper = context.currentWrapper();
      Object parent = null;

      if (parentWrapper != null) {
        parent = parentWrapper.getProxy();
      }

      /* UnknownElement is used for tasks and data types - with
      delayed eval */
      UnknownElement task = new UnknownElement(tag);
      task.setProject(context.getProject());
      task.setNamespace(uri);
      task.setQName(qname);
      task.setTaskType(ProjectHelper.genComponentName(task.getNamespace(), tag));
      task.setTaskName(qname);

      Location location =
          new Location(
              context.getLocator().getSystemId(),
              context.getLocator().getLineNumber(),
              context.getLocator().getColumnNumber());
      task.setLocation(location);
      task.setOwningTarget(context.getCurrentTarget());

      if (parent != null) {
        // Nested element
        ((UnknownElement) parent).addChild(task);
      } else {
        // Task included in a target ( including the default one ).
        context.getCurrentTarget().addTask(task);
      }

      context.configureId(task, attrs);

      // container.addTask(task);
      // This is a nop in UE: task.init();

      RuntimeConfigurable wrapper = new RuntimeConfigurable(task, task.getTaskName());

      for (int i = 0; i < attrs.getLength(); i++) {
        String name = attrs.getLocalName(i);
        String attrUri = attrs.getURI(i);
        if (attrUri != null && !attrUri.equals("") && !attrUri.equals(uri)) {
          name = attrUri + ":" + attrs.getQName(i);
        }
        String value = attrs.getValue(i);
        // PR: Hack for ant-type value
        //  an ant-type is a component name which can
        // be namespaced, need to extract the name
        // and convert from qualified name to uri/name
        if (ANT_TYPE.equals(name)
            || (ANT_CORE_URI.equals(attrUri) && ANT_TYPE.equals(attrs.getLocalName(i)))) {
          name = ANT_TYPE;
          int index = value.indexOf(":");
          if (index >= 0) {
            String prefix = value.substring(0, index);
            String mappedUri = context.getPrefixMapping(prefix);
            if (mappedUri == null) {
              throw new BuildException("Unable to find XML NS prefix \"" + prefix + "\"");
            }
            value = ProjectHelper.genComponentName(mappedUri, value.substring(index + 1));
          }
        }
        wrapper.setAttribute(name, value);
      }
      if (parentWrapper != null) {
        parentWrapper.addChild(wrapper);
      }
      context.pushWrapper(wrapper);
    }