@Override
  public void execute() throws BuildException {
    if (port <= 0) {
      throw new BuildException("Port must be set to a positive integer");
    }

    if (scripts == null && script == null) {
      throw new BuildException("Scripts must be specified as an embedded resource collection");
    }

    if (scripts != null && script != null) {
      throw new BuildException(
          "Scripts can be specified either by the script attribute or as resource collections but not both.");
    }

    for (AddUser user : users) {
      user.validate();
    }

    if (skip) {
      log("Skipping excution");
    } else if (errorProperty == null) {
      doExecute();
    } else {
      try {
        doExecute();
      } catch (BuildException e) {
        final Project project = getProject();
        project.setProperty(errorProperty, e.getMessage());
        log(e, Project.MSG_DEBUG);
      }
    }
  }
  private void initDefaults() {
    RemoteRepository repo = new RemoteRepository();
    repo.setProject(project);
    repo.setId("central");
    repo.setUrl("http://repo1.maven.org/maven2/");
    project.addReference(Names.ID_CENTRAL, repo);

    repo = new RemoteRepository();
    repo.setProject(project);
    repo.setRefid(new Reference(project, Names.ID_CENTRAL));
    RemoteRepositories repos = new RemoteRepositories();
    repos.setProject(project);
    repos.addRemoterepo(repo);
    project.addReference(Names.ID_DEFAULT_REPOS, repos);

    // resolve maven.repo.local only once relative to project, as the basedir may change for <ant>
    // tasks
    String localRepoResolved = project.getProperty("maven.repo.local.resolved");
    if (localRepoResolved != null) {
      mavenRepoDirFromProperty = new File(localRepoResolved);
    } else {
      String mavenRepoProperty = project.getProperty("maven.repo.local");
      if (mavenRepoProperty != null) {
        mavenRepoDirFromProperty = project.resolveFile(mavenRepoProperty);
        project.setProperty(
            "maven.repo.local.resolved", mavenRepoDirFromProperty.getAbsolutePath());
      }
    }
  }
Esempio n. 3
0
 /** Tests that isActive returns false when "unless" references a set property. */
 public final void testIsActive5() {
   ProcessorDef arg = create();
   Project project = new Project();
   project.setProperty("cond", "");
   arg.setProject(project);
   arg.setUnless("cond");
   assertTrue(!arg.isActive());
 }
  protected void setUp() throws Exception {
    createCache();
    Project project = new Project();
    project.setProperty("ivy.settings.file", "test/repositories/ivysettings-1.xml");

    report = new IvyRepositoryReport();
    report.setProject(project);
    System.setProperty("ivy.cache.dir", cache.getAbsolutePath());
  }
 public void exportModuleOutputProperties() {
   for (JpsModule module : myModel.getProject().getModules()) {
     for (boolean test : new boolean[] {true, false}) {
       myProject.setProperty(
           "module." + module.getName() + ".output." + (test ? "test" : "main"),
           getModuleOutput(module, test));
     }
   }
 }
Esempio n. 6
0
 /**
  * Create ANT project that can be executed programatically
  *
  * @param scenariosPath
  * @param scenarioFile
  * @param sutFile
  * @return
  */
 private Project createNewAntProject(
     File scenariosPath, File scenarioFile, String scenarioName, String sutName) {
   System.setProperty(RunningProperties.CURRENT_SCENARIO_NAME, scenarioName);
   System.setProperty(RunningProperties.CURRENT_SUT, sutName);
   Project p = new Project();
   p.setName("JSystem Maven Plugin Project");
   p.setBaseDir(mavenProject.getBasedir());
   p.addBuildListener(new AntExecutionListener());
   p.setProperty("basedir", scenariosPath.getAbsolutePath());
   p.setProperty("scenarios.base", scenariosPath.getParentFile().getAbsolutePath());
   p.setProperty("sutFile", sutName);
   p.setProperty("ant.file", scenarioFile.getAbsolutePath());
   DefaultLogger consoleLogger = new DefaultLogger();
   consoleLogger.setErrorPrintStream(System.err);
   consoleLogger.setOutputPrintStream(System.out);
   consoleLogger.setMessageOutputLevel(Project.MSG_INFO);
   p.addBuildListener(consoleLogger);
   return p;
 }
 @Override
 public void execute() throws BuildException {
   try {
     String version = getProjectVersion(new File(dir));
     Project project = getProject();
     if (project != null) {
       project.setProperty(property, version);
     }
   } catch (Exception e) {
     throw new BuildException(e);
   }
 }
Esempio n. 8
0
 /**
  * Tests that evaluating isActive when "if" refernces a property with the value "false" throws an
  * exception to warn of a suspicious value.
  */
 public final void testIsActive4() {
   ProcessorDef arg = create();
   Project project = new Project();
   project.setProperty("cond", "false");
   arg.setProject(project);
   arg.setIf("cond");
   try {
     arg.isActive();
   } catch (BuildException ex) {
     return;
   }
   fail("Should throw exception for suspicious value");
 }
  protected Project getProject(String buildURLString, String topLevelSharedDir) {

    Project project = new Project();

    project.setProperty("build.url", buildURLString);
    project.setProperty("github.pull.request.head.branch", "junit-pr-head-branch");
    project.setProperty("github.pull.request.head.username", "junit-pr-head-username");
    project.setProperty("plugins.branch.name", "junit-plugins-branch-name");
    project.setProperty("plugins.repository", "junit-plugins-repository");
    project.setProperty("portal.repository", "junit-portal-repository");
    project.setProperty("repository", "junit-repository");
    project.setProperty("top.level.shared.dir", topLevelSharedDir);

    return project;
  }
 static {
   _project.setProperty("github.pull.request.head.branch", "junit-pr-head-branch");
   _project.setProperty("github.pull.request.head.username", "junit-pr-head-username");
   _project.setProperty("plugins.branch.name", "junit-plugins-branch-name");
   _project.setProperty("plugins.repository", "junit-plugins-repository");
   _project.setProperty("portal.repository", "junit-portal-repository");
   _project.setProperty("repository", "junit-repository");
 }
  protected Project getProject() {
    Project project = new Project();

    project.setProperty("github.origin.name", "junit-pr-origin-username");
    project.setProperty("github.sender.branch.name", "junit-pr-sender-branch");
    project.setProperty("plugins.branch.name", "junit-plugins-branch-name");
    project.setProperty("plugins.repository", "junit-plugins-repository");
    project.setProperty("portal.repository", "junit-portal-repository");
    project.setProperty("repository", "junit-repository");

    return project;
  }
Esempio n. 12
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;
  }
Esempio n. 13
0
  /**
   * Sets the project's properties. May be called to set project-wide properties, or just before a
   * target call to \ set target-related properties only.
   *
   * @param _properties A map containing the properties' name/value couples
   * @param _overridable If set, the provided properties values may be overriden \ by the config
   *     file's values
   * @throws Exception Exceptions are self-explanatory (read their Message)
   */
  public void setProperties(Map _properties, boolean _overridable) throws Exception {
    // Test if the project exists
    if (project == null)
      throw new Exception(
          "Properties cannot be set because the project has not been initialized. Please call the 'init' method first !");

    // Property hashmap is null
    if (_properties == null) throw new Exception("The provided property map is null.");

    // Loop through the property map
    Set propertyNames = _properties.keySet();
    Iterator iter = propertyNames.iterator();
    while (iter.hasNext()) {
      // Get the property's name and value
      String propertyName = (String) iter.next();
      String propertyValue = (String) _properties.get(propertyName);
      if (propertyValue == null) continue;

      // Set the properties
      if (_overridable) project.setProperty(propertyName, propertyValue);
      else project.setUserProperty(propertyName, propertyValue);
    }
  }
Esempio n. 14
0
  /**
   * Create project.properties file based on $RDECK_BASE/etc/project.properties
   *
   * @param overwrite Overwrite existing properties file
   */
  protected void generateProjectPropertiesFile(final boolean overwrite) {
    Copy copyTask = new Copy();
    Project antProject = new Project();
    antProject.setProperty("project.name", getName());
    Property propTask = new Property();
    propTask.setProject(antProject);
    propTask.setFile(
        new File(
            Constants.getFrameworkProperties(
                getFrameworkProjectMgr().getFramework().getBaseDir().getAbsolutePath())));
    propTask.execute();
    copyTask.setProject(antProject);
    copyTask.setOverwrite(overwrite);
    final File destfile = new File(getEtcDir(), PROP_FILENAME);
    copyTask.setTofile(destfile);
    copyTask.setFile(
        new File(getFrameworkProjectMgr().getFramework().getConfigDir(), PROP_FILENAME));
    copyTask.setFiltering(true);
    copyTask.createFilterChain().add(new ExpandProperties());

    // execute the task
    copyTask.execute();
    getLogger().debug("generated project.properties: " + destfile.getAbsolutePath());
  }
  public void execute() {
    if (applicationDir == null) {
      throw new BuildException("No applicationDir set!");
    }

    // Add the properties from application.conf as ant properties
    for (Map.Entry<String, String> entry : properties().entrySet()) {
      String key = entry.getKey();
      String value = project.replaceProperties(entry.getValue());
      project.setProperty(prefix + key, value);
      project.log("Loaded property '" + prefix + key + "'='" + value + "'", Project.MSG_VERBOSE);
    }

    // Add the module classpath as an ant property
    Path path = new Path(project);
    FilenameSelector endsToJar = new FilenameSelector();
    endsToJar.setName("*.jar");

    for (File module : modules()) {
      File moduleLib = new File(module, "lib");
      if (moduleLib.exists()) {
        FileSet fileSet = new FileSet();
        fileSet.setDir(moduleLib);
        fileSet.addFilename(endsToJar);
        path.addFileset(fileSet);
        project.log("Added fileSet to path: " + fileSet, Project.MSG_VERBOSE);
      } else {
        project.log(
            "Ignoring non existing lib dir: " + moduleLib.getAbsolutePath(), Project.MSG_VERBOSE);
      }
    }
    project.addReference(modulesClasspath, path);
    project.log(
        "Generated classpath '" + modulesClasspath + "':" + project.getReference(modulesClasspath),
        Project.MSG_VERBOSE);
  }
 public void setLogFile(String logFile) {
   this.logFile = logFile;
   project.setProperty("logFile", logFile);
 }
 public void setTimeToWait(int timeToWait) {
   this.timeToWait = timeToWait;
   project.setProperty("timeToWait", Long.toString(timeToWait));
 }
  @Override
  public void execute() throws BuildException {
    Project antProject = getProject();

    // get the SDK location
    String sdkLocation = antProject.getProperty(ProjectProperties.PROPERTY_SDK);

    // check if it's valid and exists
    if (sdkLocation == null || sdkLocation.length() == 0) {
      throw new BuildException("SDK Location is not set.");
    }

    File sdk = new File(sdkLocation);
    if (sdk.isDirectory() == false) {
      throw new BuildException(String.format("SDK Location '%s' is not valid.", sdkLocation));
    }

    // get the target property value
    String targetHashString = antProject.getProperty(ProjectProperties.PROPERTY_TARGET);
    if (targetHashString == null) {
      throw new BuildException("Android Target is not set.");
    }

    // load up the sdk targets.
    final ArrayList<String> messages = new ArrayList<String>();
    SdkManager manager =
        SdkManager.createManager(
            sdkLocation,
            new ISdkLog() {
              public void error(Throwable t, String errorFormat, Object... args) {
                if (errorFormat != null) {
                  messages.add(String.format("Error: " + errorFormat, args));
                }
                if (t != null) {
                  messages.add("Error: " + t.getMessage());
                }
              }

              public void printf(String msgFormat, Object... args) {
                messages.add(String.format(msgFormat, args));
              }

              public void warning(String warningFormat, Object... args) {
                messages.add(String.format("Warning: " + warningFormat, args));
              }
            });

    if (manager == null) {
      // since we failed to parse the SDK, lets display the parsing output.
      for (String msg : messages) {
        System.out.println(msg);
      }
      throw new BuildException("Failed to parse SDK content.");
    }

    // resolve it
    IAndroidTarget androidTarget = manager.getTargetFromHashString(targetHashString);

    if (androidTarget == null) {
      throw new BuildException(String.format("Unable to resolve target '%s'", targetHashString));
    }

    // display it
    System.out.println("Project Target: " + androidTarget.getName());
    if (androidTarget.isPlatform() == false) {
      System.out.println("Vendor: " + androidTarget.getVendor());
    }
    System.out.println("Platform Version: " + androidTarget.getApiVersionName());
    System.out.println("API level: " + androidTarget.getApiVersionNumber());

    // sets up the properties to find android.jar/framework.aidl
    String androidJar = androidTarget.getPath(IAndroidTarget.ANDROID_JAR);
    String androidAidl = androidTarget.getPath(IAndroidTarget.ANDROID_AIDL);
    antProject.setProperty(PROPERTY_ANDROID_JAR, androidJar);
    antProject.setProperty(PROPERTY_ANDROID_AIDL, androidAidl);

    // sets up the boot classpath

    // create the Path object
    Path bootclasspath = new Path(antProject);

    // create a PathElement for the framework jar
    PathElement element = bootclasspath.createPathElement();
    element.setPath(androidJar);

    // create PathElement for each optional library.
    IOptionalLibrary[] libraries = androidTarget.getOptionalLibraries();
    if (libraries != null) {
      HashSet<String> visitedJars = new HashSet<String>();
      for (IOptionalLibrary library : libraries) {
        String jarPath = library.getJarPath();
        if (visitedJars.contains(jarPath) == false) {
          visitedJars.add(jarPath);

          element = bootclasspath.createPathElement();
          element.setPath(library.getJarPath());
        }
      }
    }

    // finally sets the path in the project with a reference
    antProject.addReference(REF_CLASSPATH, bootclasspath);

    // find the file to import, and import it.
    String templateFolder = androidTarget.getPath(IAndroidTarget.TEMPLATES);

    // make sure the file exists.
    File templates = new File(templateFolder);
    if (templates.isDirectory() == false) {
      throw new BuildException(
          String.format("Template directory '%s' is missing.", templateFolder));
    }

    // now check the rules file exists.
    File rules = new File(templateFolder, ANDROID_RULES);
    if (rules.isFile() == false) {
      throw new BuildException(String.format("Build rules file '%s' is missing.", templateFolder));
    }

    // set the file location to import
    setFile(rules.getAbsolutePath());

    // and import it
    super.execute();
  }