ScannerFilter(String[] inclusionsx, String[] exclusionsx, File dirName) {
   project = new Project();
   project.setBaseDir(dirName);
   fileSet = new FileSet();
   fileSet.setProject(project);
   fileSet.setDir(dirName);
   fileSet.appendIncludes(Values.trimCopy(inclusionsx));
   fileSet.appendExcludes(Values.trimCopy(exclusionsx));
   fileSet.appendExcludes(DEFAULT_EXCLUDES);
 }
Ejemplo n.º 2
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());
    }
  }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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;
    }
  }
    /**
     * Initialisation routine called after handler creation with the element name and attributes.
     * The attributes which this handler can deal with are: <code>"default"</code>, <code>"name"
     * </code>, <code>"id"</code> and <code>"basedir"</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>
     *     "default"</code> attribute is missing.
     */
    public void onStartElement(
        String uri, String tag, String qname, Attributes attrs, AntXMLContext context)
        throws SAXParseException {
      String baseDir = null;
      boolean nameAttributeSet = false;

      Project project = context.getProject();
      // Set the location of the implicit target associated with the project tag
      context.getImplicitTarget().setLocation(new Location(context.getLocator()));

      /**
       * XXX I really don't like this - the XML processor is still too 'involved' in the processing.
       * A better solution (IMO) would be to create UE for Project and Target too, and then process
       * the tree and have Project/Target deal with its attributes ( similar with Description ).
       *
       * <p>If we eventually switch to ( or add support for ) DOM, things will work smoothly - UE
       * can be avoided almost completely ( it could still be created on demand, for backward
       * compatibility )
       */
      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("default")) {
          if (value != null && !value.equals("")) {
            if (!context.isIgnoringProjectTag()) {
              project.setDefault(value);
            }
          }
        } else if (key.equals("name")) {
          if (value != null) {
            context.setCurrentProjectName(value);
            nameAttributeSet = true;
            if (!context.isIgnoringProjectTag()) {
              project.setName(value);
              project.addReference(value, project);
            } else if (isInIncludeMode()) {
              if (!"".equals(value)
                  && (getCurrentTargetPrefix() == null || getCurrentTargetPrefix().length() == 0)) {
                // help nested include tasks
                setCurrentTargetPrefix(value);
              }
            }
          }
        } else if (key.equals("id")) {
          if (value != null) {
            // What's the difference between id and name ?
            if (!context.isIgnoringProjectTag()) {
              project.addReference(value, project);
            }
          }
        } else if (key.equals("basedir")) {
          if (!context.isIgnoringProjectTag()) {
            baseDir = value;
          }
        } else {
          // XXX ignore attributes in a different NS ( maybe store them ? )
          throw new SAXParseException(
              "Unexpected attribute \"" + attrs.getQName(i) + "\"", context.getLocator());
        }
      }

      // XXX Move to Project ( so it is shared by all helpers )
      String antFileProp = MagicNames.ANT_FILE + "." + context.getCurrentProjectName();
      String dup = project.getProperty(antFileProp);
      String typeProp = MagicNames.ANT_FILE_TYPE + "." + context.getCurrentProjectName();
      String dupType = project.getProperty(typeProp);
      if (dup != null && nameAttributeSet) {
        Object dupFile = null;
        Object contextFile = null;
        if (MagicNames.ANT_FILE_TYPE_URL.equals(dupType)) {
          try {
            dupFile = new URL(dup);
          } catch (java.net.MalformedURLException mue) {
            throw new BuildException(
                "failed to parse "
                    + dup
                    + " as URL while looking"
                    + " at a duplicate project"
                    + " name.",
                mue);
          }
          contextFile = context.getBuildFileURL();
        } else {
          dupFile = new File(dup);
          contextFile = context.getBuildFile();
        }

        if (context.isIgnoringProjectTag() && !dupFile.equals(contextFile)) {
          project.log(
              "Duplicated project name in import. Project "
                  + context.getCurrentProjectName()
                  + " defined first in "
                  + dup
                  + " and again in "
                  + contextFile,
              Project.MSG_WARN);
        }
      }
      if (nameAttributeSet) {
        if (context.getBuildFile() != null) {
          project.setUserProperty(antFileProp, context.getBuildFile().toString());
          project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_FILE);
        } else if (context.getBuildFileURL() != null) {
          project.setUserProperty(antFileProp, context.getBuildFileURL().toString());
          project.setUserProperty(typeProp, MagicNames.ANT_FILE_TYPE_URL);
        }
      }
      if (context.isIgnoringProjectTag()) {
        // no further processing
        return;
      }
      // set explicitly before starting ?
      if (project.getProperty("basedir") != null) {
        project.setBasedir(project.getProperty("basedir"));
      } else {
        // Default for baseDir is the location of the build file.
        if (baseDir == null) {
          project.setBasedir(context.getBuildFileParent().getAbsolutePath());
        } else {
          // check whether the user has specified an absolute path
          if ((new File(baseDir)).isAbsolute()) {
            project.setBasedir(baseDir);
          } else {
            project.setBaseDir(FILE_UTILS.resolveFile(context.getBuildFileParent(), baseDir));
          }
        }
      }
      project.addTarget("", context.getImplicitTarget());
      context.setCurrentTarget(context.getImplicitTarget());
    }
Ejemplo n.º 6
0
  public Map<String, Object> getBuildProperties(final boolean reload) throws CoreException {
    final Project project = new Project();

    Map<String, Object> sdkProperties = buildPropertiesCache.get(getLocation().toPortableString());

    try {
      if (sdkProperties == null || reload == true) {
        project.setBaseDir(new File(getLocation().toPortableString()));
        project.setSystemProperties();

        final Property envTask = new Property();
        envTask.setProject(project);
        envTask.setEnvironment("env");
        envTask.execute();

        loadPropertiesFile(project, "build." + project.getProperty("user.name") + ".properties");
        loadPropertiesFile(
            project, "build." + project.getProperty("env.COMPUTERNAME") + ".properties");
        loadPropertiesFile(project, "build." + project.getProperty("env.HOST") + ".properties");
        loadPropertiesFile(project, "build." + project.getProperty("env.HOSTNAME") + ".properties");
        loadPropertiesFile(project, "build.properties");

        if (project.getProperty("app.server.type") == null) {
          throw new CoreException(
              SDKCorePlugin.createErrorStatus(
                  "Missing ${app.server.type} setting in build.properties file."));
        }

        final Map<String, String> propertyCopyList = new HashMap<String, String>();
        propertyCopyList.put(
            "app.server." + project.getProperty("app.server.type") + ".dir", "app.server.dir");
        propertyCopyList.put(
            "app.server." + project.getProperty("app.server.type") + ".deploy.dir",
            "app.server.deploy.dir");
        propertyCopyList.put(
            "app.server." + project.getProperty("app.server.type") + ".lib.global.dir",
            "app.server.lib.global.dir");
        propertyCopyList.put(
            "app.server." + project.getProperty("app.server.type") + ".portal.dir",
            "app.server.portal.dir");

        for (String key : propertyCopyList.keySet()) {
          AntPropertyCopy propertyCopyTask = new AntPropertyCopy();
          propertyCopyTask.setOverride(true);
          propertyCopyTask.setProject(project);
          String from = key;
          String to = propertyCopyList.get(from);
          propertyCopyTask.setFrom(from);
          propertyCopyTask.setName(to);
          propertyCopyTask.execute();
        }

        sdkProperties = project.getProperties();

        for (String propertyKey : APP_SERVER_PROPERTIES_KEYS) {
          if (!sdkProperties.keySet().contains(propertyKey)) {
            throw new CoreException(
                SDKCorePlugin.createErrorStatus(
                    "Missing ${" + propertyKey + "} setting in build.properties file."));
          }
        }

        buildPropertiesCache.put(getLocation().toPortableString(), sdkProperties);
      }
    } catch (Exception e) {
      throw new CoreException(SDKCorePlugin.createErrorStatus(e.getMessage()));
    }

    return sdkProperties;
  }