Exemplo n.º 1
0
 /**
  * Does replacement on the given string with token matching. This uses the defined begintoken and
  * endtoken values which default to @ for both.
  *
  * @param line The line to process the tokens in.
  * @return The string with the tokens replaced.
  */
 public String replaceTokens(String line) {
   String replacedLine = line;
   for (Enumeration e = filterSets.elements(); e.hasMoreElements(); ) {
     FilterSet filterSet = (FilterSet) e.nextElement();
     replacedLine = filterSet.replaceTokens(replacedLine);
   }
   return replacedLine;
 }
Exemplo n.º 2
0
 /**
  * Test to see if this filter set it empty.
  *
  * @return Return true if there are filter in this set otherwise false.
  */
 public boolean hasFilters() {
   for (Enumeration e = filterSets.elements(); e.hasMoreElements(); ) {
     FilterSet filterSet = (FilterSet) e.nextElement();
     if (filterSet.hasFilters()) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 3
0
 /**
  * Clone the filterset.
  *
  * @return a deep clone of this filterset.
  * @throws BuildException if the clone cannot be performed.
  */
 public synchronized Object clone() throws BuildException {
   if (isReference()) {
     return ((FilterSet) getRef()).clone();
   } else {
     try {
       FilterSet fs = (FilterSet) super.clone();
       fs.filters = (Vector) getFilters().clone();
       fs.setProject(getProject());
       return fs;
     } catch (CloneNotSupportedException e) {
       throw new BuildException(e);
     }
   }
 }
Exemplo n.º 4
0
 protected FilterSet createFilterSet() {
   FilterSet filterSet = new MyFilterSet();
   String projectName = null;
   if (context.isOptionLimitToSingleModule())
     projectName = context.getApplication().getArtifactId();
   else projectName = context.getModule().getArtifactId();
   filterSet.addFilter("template1ContextRoot", projectName);
   filterSet.addFilter("${template1_artifactId}", context.getModule().getArtifactId());
   filterSet.addFilter("${template1_groupId}", context.getModule().getGroupId());
   filterSet.addFilter("${template1_moduleName}", context.getModule().getName());
   filterSet.addFilter(
       "${template1_packageName}",
       NamespaceUtil.getPackageName(context.getModule().getNamespace()));
   return filterSet;
 }
Exemplo n.º 5
0
 /**
  * Add a Filterset to this filter set.
  *
  * @param filterSet the filterset to be added to this filterset
  */
 public synchronized void addConfiguredFilterSet(FilterSet filterSet) {
   if (isReference()) {
     throw noChildrenAllowed();
   }
   for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements(); ) {
     addFilter((Filter) e.nextElement());
   }
 }
Exemplo n.º 6
0
 /**
  * Create a Filterset from another filterset.
  *
  * @param filterset the filterset upon which this filterset will be based.
  */
 protected FilterSet(FilterSet filterset) {
   super();
   this.filters = (Vector) filterset.getFilters().clone();
 }
  @Override
  protected boolean createTestProject() {
    if (!(Boolean) model.getProperty(ISeamFacetDataModelProperties.TEST_PROJECT_CREATING)
        || !shouldCopyLibrariesAndTemplates(model)) return false;

    File testProjectDir =
        new File(
            seamWebProject.getLocation().removeLastSegments(1).toFile(),
            testProjectName); //$NON-NLS-1$
    testProjectDir.mkdir();

    IVirtualComponent component = ComponentCore.createComponent(seamWebProject);
    IVirtualFolder webRootVirtFolder =
        component.getRootFolder().getFolder(new Path("/")); // $NON-NLS-1$

    File testLibDir = new File(testProjectDir, "lib"); // $NON-NLS-1$
    File embededEjbDir = new File(testProjectDir, "bootstrap"); // $NON-NLS-1$
    File testSrcDir = new File(testProjectDir, "test-src"); // $NON-NLS-1$
    String seamGenResFolder = seamRuntime.getResourceTemplatesDir();
    File dataSourceFile = new File(seamGenResFolder, "datasource-ds.xml");
    File seamPropertiesFile = new File(seamGenResFolder, "seam.properties");
    // File jbossBeansFile = new File(seamGenResFolder ,"META-INF/jboss-beans.xml"); //$NON-NLS-1$
    FilterSet filterSet = new FilterSet();
    filterSet.addFilter("projectName", seamWebProject.getName()); // $NON-NLS-1$
    filterSet.addFilter("earProjectName", earProjectName); // $NON-NLS-1$
    filterSet.addFilter("ejbProjectName", ejbProjectName); // $NON-NLS-1$
    filterSet.addFilter("testProjectName", testProjectName); // $NON-NLS-1$

    filterSet.addFilter(
        "runtimeName", WtpUtils.getServerRuntimeName(seamWebProject)); // $NON-NLS-1$
    filterSet.addFilter(
        "webRootFolder",
        webRootVirtFolder
            .getUnderlyingFolder()
            .getFullPath()
            .removeFirstSegments(1)
            .toString()); //$NON-NLS-1$

    FilterSet jdbcFilterSet = SeamFacetFilterSetFactory.createJdbcFilterSet(model);
    // TODO: why are these filters not shared!?
    filterSet.addConfiguredFilterSet(
        SeamFacetFilterSetFactory.createHibernateDialectFilterSet(model));

    AntCopyUtils.FileSet includeLibs =
        new AntCopyUtils.FileSet(getJBossTestLibFileset())
            .dir(new File(seamRuntime.getHomeDir(), "lib")); // $NON-NLS-1$
    AntCopyUtils.FileSet secondSetincludeLibs =
        new AntCopyUtils.FileSet(getJBossTestLibFileset())
            .dir(new File(seamRuntime.getHomeDir(), "lib/test")); // $NON-NLS-1$

    File[] firstlibs =
        includeLibs.getDir().listFiles(new AntCopyUtils.FileSetFileFilter(includeLibs));
    File[] secondLibs =
        secondSetincludeLibs
            .getDir()
            .listFiles(new AntCopyUtils.FileSetFileFilter(secondSetincludeLibs));
    Set<String> allLibs =
        new HashSet<String>(); // HACK: needed to be unique because some jboss-*.jars are duplicated
    if (firstlibs != null)
      for (File f : firstlibs) {
        allLibs.add(f.getName());
      }
    if (secondLibs != null)
      for (File f : secondLibs) {
        allLibs.add(f.getName());
      }

    StringBuffer testLibraries = new StringBuffer();

    if (!SeamCorePlugin.getDefault().hasM2Facet(seamWebProject)) {
      for (String file : allLibs) {
        testLibraries.append(
            "\t<classpathentry kind=\"lib\" path=\"lib/"
                + file
                + "\"/>\n"); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }

    StringBuffer requiredProjects = new StringBuffer();
    requiredProjects.append(
        "\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/"
            + seamWebProject.getName()
            + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
    if (!SeamFacetAbstractInstallDelegate.isWarConfiguration(model)) {
      requiredProjects.append(
          "\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/"
              + ejbProjectName
              + "\"/>"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    filterSet.addFilter("testLibraries", testLibraries.toString()); // $NON-NLS-1$
    filterSet.addFilter("requiredProjects", requiredProjects.toString()); // $NON-NLS-1$
    File testTemplateDir = null;
    try {
      testTemplateDir =
          new File(
              SeamFacetInstallDataModelProvider.getTemplatesFolder(), "test-seam2"); // $NON-NLS-1$
    } catch (IOException e) {
      SeamCorePlugin.getPluginLog().logError(e);
      return false;
    }
    AntCopyUtils.FileSet excludeCvsSvn =
        new AntCopyUtils.FileSet(SeamFacetAbstractInstallDelegate.CVS_SVN).dir(testTemplateDir);

    AntCopyUtils.copyFilesAndFolders(
        testTemplateDir,
        testProjectDir,
        new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
        new FilterSetCollection(filterSet),
        true);

    excludeCvsSvn.dir(new File(seamRuntime.getHomeDir(), "bootstrap")); // $NON-NLS-1$
    AntCopyUtils.copyFilesAndFolders(
        new File(seamRuntime.getHomeDir(), "bootstrap"), // $NON-NLS-1$
        embededEjbDir,
        new AntCopyUtils.FileSetFileFilter(excludeCvsSvn),
        new FilterSetCollection(),
        true);

    //			AntCopyUtils.copyFileToFile(
    //					persistenceFile,
    //					new File(testProjectDir,"test-src/META-INF/persistence.xml"), //$NON-NLS-1$
    //					new FilterSetCollection(filterSet), true);

    FilterSetCollection f = new FilterSetCollection();
    f.addFilterSet(filterSet);
    f.addFilterSet(jdbcFilterSet);

    AntCopyUtils.copyFileToFile(
        dataSourceFile,
        new File(
            testProjectDir,
            "test-src/META-INF/" + seamWebProject.getName() + "-test-ds.xml"), // $NON-NLS-1$
        f,
        true);

    AntCopyUtils.copyFileToFolder(
        seamPropertiesFile,
        testSrcDir, //$NON-NLS-1$
        new FilterSetCollection(filterSet),
        true);

    // Add "org.jboss.seam.core.init.debug=false" for Seam 2.1/2.2/2.3
    // to seam.properties file to avoid https://jira.jboss.org/jira/browse/JBIDE-3623
    if (getVersion() == SeamVersion.SEAM_2_1
        || getVersion() == SeamVersion.SEAM_2_2
        || getVersion() == SeamVersion.SEAM_2_3) {
      Properties seamProperties = new Properties();
      File testSeamPropertiesFile = new File(testSrcDir, "seam.properties");
      FileInputStream inStream = null;
      FileOutputStream out = null;
      try {
        inStream = new FileInputStream(testSeamPropertiesFile);
        seamProperties.load(inStream);
        seamProperties.setProperty(
            "org.jboss.seam.core.init.debug", "false"); // $NON-NLS-1$ //$NON-NLS-2$

        out = new FileOutputStream(testSeamPropertiesFile);
        seamProperties.store(out, "debug is explicitly disabled in test to avoid JBIDE-3623");
      } catch (FileNotFoundException e) {
        SeamCorePlugin.getPluginLog().logError(e);
      } catch (IOException e) {
        SeamCorePlugin.getPluginLog().logError(e);
      } finally {
        if (inStream != null) {
          try {
            inStream.close();
          } catch (IOException e) {
            /** ignore */
          }
        }
        if (out != null) {
          try {
            out.close();
          } catch (IOException e) {
            /** ignore */
          }
        }
      }
    }

    if (!SeamCorePlugin.getDefault().hasM2Facet(seamWebProject) && shouldCopyLibraries(model)) {
      AntCopyUtils.copyFiles(
          new File(seamRuntime.getHomeDir(), "lib"), // $NON-NLS-1$
          testLibDir,
          new AntCopyUtils.FileSetFileFilter(includeLibs));

      // seam2 has a lib/test
      AntCopyUtils.copyFiles(
          new File(seamRuntime.getHomeDir(), "lib/test"), // $NON-NLS-1$
          testLibDir,
          new AntCopyUtils.FileSetFileFilter(includeLibs));
    }

    SeamFacetAbstractInstallDelegate.createComponentsProperties(
        testSrcDir, "", true); // $NON-NLS-1$
    return true;
  }