@Override
  protected void doHadoopWork() throws BuildException {
    Tuple tuple = ContextManager.getCurrentTuple();
    if (tuple == null) {
      throw new BuildException(
          this.getTaskName()
              + " should be put inside task container which provides tuple to execution context");
    }

    try {
      if (tuple.getType(fieldNumber) != DataType.TUPLE
          || !(tuple.get(fieldNumber) instanceof Tuple)) {
        throw new BuildException("Tuple field " + fieldNumber + " doesn't represent a Tuple");
      }

      ContextManager.setCurrentTupleContext((Tuple) tuple.get(fieldNumber));

      try {
        for (Task task : tasks) {
          task.perform();
        }
      } finally {
        ContextManager.resetCurrentTupleContext();
      }
    } catch (ExecException e) {
      throw new BuildException("Failed to check type of tuple field " + fieldNumber, e);
    }
  }
 /**
  * Fired when a task finishes building, this adds the time taken and any error stacktrace to the
  * appropriate task element in the log.
  *
  * @param event An event with any relevant extra information. Will not be <code>null</code>.
  */
 public void taskFinished(BuildEvent event) {
   Task task = event.getTask();
   TimedElement taskElement = (TimedElement) tasks.get(task);
   if (taskElement != null) {
     long totalTime = System.currentTimeMillis() - taskElement.startTime;
     // taskElement.element.setAttribute(TIME_ATTR,
     // DefaultLogger.formatTime(totalTime));
     Target target = task.getOwningTarget();
     TimedElement targetElement = null;
     if (target != null) {
       targetElement = (TimedElement) targets.get(target);
     }
     if (targetElement == null) {
       buildElement.element.appendChild(taskElement.element);
     } else {
       targetElement.element.appendChild(taskElement.element);
     }
     Stack threadStack = getStack();
     if (!threadStack.empty()) {
       TimedElement poppedStack = (TimedElement) threadStack.pop();
       if (poppedStack != taskElement) {
         throw new RuntimeException(
             "Mismatch - popped element = "
                 + poppedStack
                 + " finished task element = "
                 + taskElement);
       }
     }
     tasks.remove(task);
   } else {
     throw new RuntimeException("Unknown task " + task + " not in " + tasks);
   }
 }
 public void execute() throws BuildException {
   int size = itsTasks.size();
   for (int i = 0; i < size; i++) {
     Task aTask = ((Task) itsTasks.get(i));
     aTask.perform();
   }
 }
 /**
  * check for invalid options
  *
  * @throws BuildException if something goes wrong.
  */
 protected void checkOptions() throws BuildException {
   // set the destination directory relative from the project if needed.
   if (toDir == null) {
     toDir = task.getProject().resolveFile(".");
   } else if (!toDir.isAbsolute()) {
     toDir = task.getProject().resolveFile(toDir.getPath());
   }
 }
示例#5
0
 void handleExit(Task task, int sc, String message) {
   if (errorProperty != null) {
     task.getProject().setNewProperty(errorProperty, "true");
   }
   if (failOnError) {
     throw new BuildException(message, task.getLocation());
   } else {
     task.log(message, Project.MSG_ERR);
   }
 }
示例#6
0
 protected List<File> getSrc() {
   if (this.src == null) {
     return Collections.singletonList(task.getProject().resolveFile("source"));
   }
   String[] paths = this.src.list();
   ArrayList<File> result = new ArrayList<File>(paths.length);
   for (String path : paths) {
     result.add(task.getProject().resolveFile(path));
   }
   return result;
 }
  /**
   * transformation
   *
   * @throws BuildException exception if something goes wrong with the transformation.
   */
  public void transform() throws BuildException {
    checkOptions();
    Project project = task.getProject();

    TempFile tempFileTask = new TempFile();
    tempFileTask.bindToOwner(task);

    XSLTProcess xsltTask = new XSLTProcess();
    xsltTask.bindToOwner(task);

    xsltTask.setXslResource(getStylesheet());

    // acrobatic cast.
    xsltTask.setIn(((XMLResultAggregator) task).getDestinationFile());
    File outputFile = null;
    if (format.equals(FRAMES)) {
      String tempFileProperty = getClass().getName() + String.valueOf(counter++);
      File tmp =
          FILE_UTILS.resolveFile(project.getBaseDir(), project.getProperty("java.io.tmpdir"));
      tempFileTask.setDestDir(tmp);
      tempFileTask.setProperty(tempFileProperty);
      tempFileTask.execute();
      outputFile = new File(project.getProperty(tempFileProperty));
    } else {
      outputFile = new File(toDir, "junit-noframes.html");
    }
    xsltTask.setOut(outputFile);
    for (Iterator i = params.iterator(); i.hasNext(); ) {
      XSLTProcess.Param param = (XSLTProcess.Param) i.next();
      XSLTProcess.Param newParam = xsltTask.createParam();
      newParam.setProject(task.getProject());
      newParam.setName(param.getName());
      newParam.setExpression(param.getExpression());
    }
    XSLTProcess.Param paramx = xsltTask.createParam();
    paramx.setProject(task.getProject());
    paramx.setName("output.dir");
    paramx.setExpression(toDir.getAbsolutePath());
    final long t0 = System.currentTimeMillis();
    try {
      xsltTask.execute();
    } catch (Exception e) {
      throw new BuildException("Errors while applying transformations: " + e.getMessage(), e);
    }
    final long dt = System.currentTimeMillis() - t0;
    task.log("Transform time: " + dt + "ms");
    if (format.equals(FRAMES)) {
      Delete delete = new Delete();
      delete.bindToOwner(task);
      delete.setFile(outputFile);
      delete.execute();
    }
  }
  /**
   * @throws BuildException
   * @see Task#execute()
   */
  @Override
  public void execute() throws BuildException {

    super.execute();

    if ((null == configurationFileName) || "".equals(configurationFileName)) {

      throw new IllegalStateException("set configurationFileName property");
    }

    /** 1. load configuration */
    final ConfigurationFactory configurationFactory =
        new DigesterConfigurationFactory(configurationFileName);
    this.configuration.getRules().addAll(configurationFactory.getRules());
    this.configuration.getSources().addAll(configurationFactory.getSources());
    this.configuration.setDoCyclicDependencyTest(configurationFactory.doCyclicDependencyTest());
    this.configuration.setThrowExceptionWhenNoPackages(
        configurationFactory.throwExceptionWhenNoPackages());

    /** 2. assert configuration rules */
    Configuration configuration = new UnmodifiableConfiguration(this.configuration);
    final RulesService rulesService = new RulesServiceImpl(configuration);
    rulesService.performRulesTest();

    /** 3. check for cyclic dependency, if requested */
    if (this.configuration.shouldDoCyclicDependencyTest()) {

      configuration = new UnmodifiableConfiguration(this.configuration);

      final CyclicRedundancyService redundancyService =
          new CyclicRedundancyServiceImpl(configuration);
      redundancyService.performCyclicRedundancyCheck();
    }
  }
示例#9
0
 public void log(String message) {
   if (task == null) {
     // System.out.println(message);
   } else {
     task.log(message, Project.MSG_DEBUG);
   }
 }
示例#10
0
 /**
  * Pass output sent to System.err to the new project.
  *
  * @param output The error output to log. Should not be <code>null</code>.
  * @since Ant 1.6.2
  */
 public void handleErrorFlush(String output) {
   if (ant != null) {
     ant.handleErrorFlush(output);
   } else {
     super.handleErrorFlush(output);
   }
 }
示例#11
0
 protected void handleErrorOutput(String line) {
   if (callee != null) {
     callee.handleErrorOutput(line);
   } else {
     super.handleErrorOutput(line);
   }
 }
示例#12
0
 public void log(String msg, int level) {
   if (task != null) {
     task.log(msg, level);
   } else if (debug) {
     project.log(msg, level);
   }
 }
示例#13
0
 /**
  * Pass output sent to System.err to the new project and flush stream.
  *
  * @since Ant 1.5.2
  */
 public void handleErrorFlush(String output) {
   if (callee != null) {
     callee.handleErrorFlush(output);
   } else {
     super.handleErrorFlush(output);
   }
 }
示例#14
0
 /**
  * Pass output sent to System.out to the new project.
  *
  * @since Ant 1.5
  */
 public void handleOutput(String output) {
   if (callee != null) {
     callee.handleOutput(output);
   } else {
     super.handleOutput(output);
   }
 }
示例#15
0
  public <InfoType> void processExisting(Task task, InfoType[] existing) {
    if (operation == null) {

      if (key != null) {
        InfoType found = null;
        if (existing != null) {
          for (InfoType info : existing) {
            try {
              Method getKey = info.getClass().getMethod("getKey");
              Object infoKey = getKey.invoke(info);
              if (key.equals(infoKey)) {
                found = info;
              }
            } catch (Exception ex) {
              throw new RuntimeException("Error getting key from info object", ex);
            }
          }
        }
        operation = found == null ? ArrayUpdateOperation.add : ArrayUpdateOperation.edit;
      } else {
        operation = ArrayUpdateOperation.add;
      }
      task.log(
          "Auto set "
              + operation
              + " array operation for "
              + spec.getClass().getSimpleName()
              + " key "
              + key);
      spec.setOperation(operation);
    }
  }
示例#16
0
 /**
  * Pass output sent to System.out to the new project.
  *
  * @param output a line of output
  * @since Ant 1.6.2
  */
 public void handleOutput(String output) {
   if (ant != null) {
     ant.handleOutput(output);
   } else {
     super.handleOutput(output);
   }
 }
  @Override
  public void doWork() throws BuildException {
    Object[] array = (Object[]) this.getReference(arrayRef);

    for (Object obj : array) {
      if (property != null) {
        this.setPropertyThreadSafe(property, obj == null ? null : obj.toString());
      }

      if (reference != null) {
        this.setReference(reference, obj);
      }

      for (Task task : tasks) {
        task.perform();
      }
    }
  }
  @Override
  public void init() throws BuildException {
    super.init();

    /*
     * Configure the logger.
     */
    Logger.getLogger("").setLevel(Level.OFF);
  }
  /**
   * Initializes this task.
   *
   * <p>
   */
  public void init() {

    super.init();
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
      // noop
    }
  }
示例#20
0
 /**
  * Initializes the task ready to process a WADL file.
  *
  * @throws org.apache.tools.ant.BuildException if an error occurs during initialization.
  */
 public void init() throws BuildException {
   super.init();
   pkg = null;
   autoPackage = false;
   target = null;
   desc = null;
   producedFileSets = new ArrayList<FileSet>();
   consumedFileSets = new ArrayList<FileSet>();
   customizationFileSets = new ArrayList<FileSet>();
 }
 /** {@inheritDoc} */
 @Override
 public final void execute() throws BuildException {
   try {
     super.execute();
     EMFTVMBuildListener.attachBuildListener(getProject());
     innerExecute();
   } catch (Exception e) {
     e.printStackTrace();
     throw new BuildException(e);
   }
 }
示例#22
0
  @Override
  public void doWork() throws BuildException {
    DescribeVpnGatewaysRequest request = new DescribeVpnGatewaysRequest();

    if (gatewayIds != null) {
      request.setVpnGatewayIds(CollectionsHelper.asList(gatewayIds));
    }

    if (filters != null) {
      request.setFilters(filters);
    }

    DescribeVpnGatewaysResult result = getEc2Client().describeVpnGateways(request);

    for (VpnGateway gateway : result.getVpnGateways()) {
      this.setPropertyThreadSafe(property, gateway.toString());

      for (Task task : tasks) {
        task.perform();
      }
    }
  }
示例#23
0
文件: ApbTask.java 项目: emiliolg/apb
  public void execute() throws BuildException {
    super.execute();

    final Environment env = apb.getEnvironment();
    env.setNonRecursive(!recurse);

    if (module == null) {
      throw new BuildException("You must specify a module name");
    }

    try {
      final File dir = defdir == null ? null : new File(defdir);
      apb.build(dir, module, command);
    } catch (Throwable throwable) {
      throw new BuildException(throwable);
    }
  }
  public Model loadModel(
      Task task, File pomFile, boolean local, RemoteRepositories remoteRepositories) {
    RepositorySystemSession session = getSession(task, null);

    remoteRepositories =
        remoteRepositories == null
            ? AetherUtils.getDefaultRepositories(project)
            : remoteRepositories;

    List<org.sonatype.aether.repository.RemoteRepository> repositories =
        ConverterUtils.toRepositories(
            task.getProject(), session, remoteRepositories, getRemoteRepoMan());

    ModelResolver modelResolver =
        new AntModelResolver(session, "project", getSystem(), getRemoteRepoMan(), repositories);

    Settings settings = getSettings();

    try {
      DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
      request.setLocationTracking(true);
      request.setProcessPlugins(false);
      if (local) {
        request.setPomFile(pomFile);
        request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_STRICT);
      } else {
        request.setModelSource(new FileModelSource(pomFile));
        request.setValidationLevel(ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL);
      }
      request.setSystemProperties(getSystemProperties());
      request.setUserProperties(getUserProperties());
      request.setProfiles(SettingsUtils.convert(settings.getProfiles()));
      request.setActiveProfileIds(settings.getActiveProfiles());
      request.setModelResolver(modelResolver);
      return modelBuilder.build(request).getEffectiveModel();
    } catch (ModelBuildingException e) {
      throw new BuildException("Could not load POM " + pomFile + ": " + e.getMessage(), e);
    }
  }
 /**
  * set the extension of the output files
  *
  * @param ext extension.
  */
 public void setExtension(String ext) {
   task.log("extension is not used anymore", Project.MSG_WARN);
 }
示例#26
0
 /* (non-Javadoc)
  * @see org.mybatis.generator.internal.NullProgressCallback#startTask(java.lang.String)
  */
 @Override
 public void startTask(String subTaskName) {
   if (verbose) {
     task.log(subTaskName, Project.MSG_VERBOSE);
   }
 }
 /**
  * Log a message with <code>MSG_DEBUG</code> priority
  *
  * @param message the message to log
  */
 public void debug(final String message) {
   task.log(message, Project.MSG_DEBUG);
 }
 /**
  * Log a message with <code>MSG_VERBOSE</code> priority
  *
  * @param message the message to log
  */
 public void verbose(final String message) {
   task.log(message, Project.MSG_VERBOSE);
 }
 /**
  * Log a message with <code>MSG_WARN</code> priority
  *
  * @param message the message to log
  */
 public void warning(final String message) {
   task.log(message, Project.MSG_WARN);
 }
 /**
  * Log a message with <code>MSG_ERR</code> priority
  *
  * @param message the message to log
  */
 public void error(final String message) {
   task.log(message, Project.MSG_ERR);
 }