public static XModelObject getJarEntryObject(IProject p, String jarFile, String entry) {
   if (p == null) {
     IFile f = EclipseResourceUtil.getFile(jarFile);
     if (f == null) return null;
     p = f.getProject();
   }
   if (p == null) return null;
   IModelNature n = EclipseResourceUtil.getModelNature(p);
   XModel model = null;
   if (n != null) {
     model = n.getModel();
   } else {
     XModelObject o = EclipseResourceUtil.createObjectForResource(p);
     if (o != null) model = o.getModel();
   }
   if (model == null) return null;
   XModelObject[] fs = FileSystemsHelper.getFileSystems(model).getChildren();
   for (XModelObject s : fs) {
     String loc =
         Paths.expand(s.get(XModelObjectConstants.ATTR_NAME_LOCATION), model.getProperties());
     if (new File(loc).equals(new File(jarFile))) {
       XModelObject result = s.getChildByPath(entry);
       if (result == null && entry != null) {
         int q = entry.indexOf('/');
         int d = entry.indexOf('.');
         if (q > d && d >= 0) {
           String entry1 = entry.substring(0, q).replace('.', '/') + entry.substring(q);
           result = s.getChildByPath(entry1);
         }
       }
       if (result != null) return result;
     }
   }
   return (n == null) ? null : n.getModel().getByPath("/" + entry); // $NON-NLS-1$
 }
 private static String getNextSrcName(XModelObject object) {
   if (object.getChildByPath("src") == null) return "src"; // $NON-NLS-1$ //$NON-NLS-2$
   int i = 1;
   while (true) {
     String s = "src-" + i; // $NON-NLS-1$
     if (object.getChildByPath(s) == null) return s;
     i++;
   }
 }
  public VResult[] check(VObject object) {
    XModelObject o = ((VObjectImpl) object).getModelObject();
    String paramName = o.getAttributeValue("param-name");
    if (paramName == null) return null;
    XModelObject parent = o.getParent();
    if (parent == null || !"WebAppServlet".equals(parent.getModelEntity().getName())) {
      return null;
    }
    if (!paramName.equals("config") && !paramName.startsWith("config/")) return null;

    String value = o.getAttributeValue("param-value");
    if (value == null || value.length() == 0) return null;
    XModel model = getXModel(object);
    XModelObject webRoot = model == null ? null : model.getByPath("FileSystems/WEB-ROOT");
    if (webRoot == null) return null;
    StringTokenizer st = new StringTokenizer(value, ",");
    while (st.hasMoreTokens()) {
      String path = st.nextToken().trim();
      if (path.length() == 0) continue;
      XModelObject fc = XModelImpl.getByRelativePath(model, path);
      if (fc == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      String path2 = path.startsWith("/") ? path.substring(1) : path;
      XModelObject fc2 = webRoot.getChildByPath(path2);
      if (fc2 == null) {
        return fire(object, "config.exists", "param-value", path);
      }
      if (!fc2.getModelEntity().getName().startsWith("StrutsConfig")) {
        return fire(object, "config.valid", "param-value", path);
      }
    }
    return null;
  }
Esempio n. 4
0
  private void parseTLD(XModelObject o, IPath source, LoadedDeclarations ds) {
    TLDLibrary library = new TLDLibrary();
    library.setId(o);
    library.setURI(new XMLValueInfo(o, AbstractTagLib.URI));
    library.setDisplayName(new XMLValueInfo(o, TLDLibrary.DISPLAY_NAME));
    library.setShortName(new XMLValueInfo(o, ATTR_SHORTNAME));
    String version = o.getAttributeValue(TLDLibrary.VERSION);
    if (version == null) {
      if ("FileTLD_1_2".equals(o.getModelEntity().getName())) { // $NON-NLS-1$
        version = "1.2"; // $NON-NLS-1$
      } else {
        version = "1.1"; // $NON-NLS-1$
      }
      library.setVersion(version);
    } else {
      library.setVersion(new XMLValueInfo(o, TLDLibrary.VERSION));
    }

    ds.getLibraries().add(library);

    XModelObject[] ts = o.getChildren();
    for (XModelObject t : ts) {
      if (t.getModelEntity().getName().startsWith("TLDTag")) { // $NON-NLS-1$
        AbstractComponent tag = new TLDTag();
        tag.setId(t);

        tag.setName(new XMLValueInfo(t, XMLStoreConstants.ATTR_NAME));
        tag.setDescription(new XMLValueInfo(t, AbstractComponent.DESCRIPTION));
        tag.setComponentClass(new XMLValueInfo(t, ATTR_TAGCLASS));
        tag.setCanHaveBody(new XMLValueInfo(t, ATTR_BODY_CONTENT));

        XModelObject[] as = t.getChildren();
        for (XModelObject a : as) {
          if (a.getModelEntity().getName().startsWith("TLDAttribute")) { // $NON-NLS-1$
            AbstractAttribute attr = new TLDAttribute();
            attr.setId(a);
            attr.setName(new XMLValueInfo(a, XMLStoreConstants.ATTR_NAME));
            attr.setDescription(new XMLValueInfo(a, AbstractComponent.DESCRIPTION));
            attr.setRequired(new XMLValueInfo(a, AbstractAttribute.REQUIRED));

            tag.addAttribute(attr);
          }
        }

        library.addComponent(tag);
      }
    }
    XModelObject functions = o.getChildByPath("Functions"); // $NON-NLS-1$
    if (functions != null) {
      ts = functions.getChildren();
      for (XModelObject t : ts) {
        ELFunction f = new ELFunction();
        f.setId(t);
        f.setName(new XMLValueInfo(t, XModelObjectConstants.ATTR_NAME));
        f.setSignature(new XMLValueInfo(t, ATTR_FUNC_SIGN));
        f.setFunctionClass(new XMLValueInfo(t, ELFunction.FUNCTION_CLASS));
        library.addFunction(f);
      }
    }
  }
 private XModelObject validateLib(XModelObject object) {
   XModelObject lib = object.getChildByPath("lib"); // $NON-NLS-1$
   if (lib == null) {
     XModelObject wi = object.getChildByPath("WEB-INF"); // $NON-NLS-1$
     if (wi == null) return null;
     XModelObject lb = wi.getChildByPath("lib"); // $NON-NLS-1$
     if (lb == null) return null;
     lib = wi.getModel().createModelObject(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER, null);
     lib.setAttributeValue(XModelObjectConstants.ATTR_NAME, "lib"); // $NON-NLS-1$
     lib.setAttributeValue(
         XModelObjectConstants.ATTR_NAME_LOCATION,
         wi.getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION) + "/lib"); // $NON-NLS-1$
     object.addChild(lib);
     object.setModified(true);
   }
   return lib;
 }
Esempio n. 6
0
  private void parseFaceletTaglib(XModelObject o, IPath source, LoadedDeclarations ds) {
    FaceletTagLibrary library = new FaceletTagLibrary();
    library.setId(o);
    library.setURI(new XMLValueInfo(o, AbstractTagLib.URI));

    ds.getLibraries().add(library);

    XModelObject[] os = o.getChildren();
    for (XModelObject t : os) {
      String entity = t.getModelEntity().getName();
      if (entity.startsWith("FaceletTaglibTag")) { // $NON-NLS-1$
        FaceletTag tag = new FaceletTag();
        tag.setId(t);
        tag.setName(new XMLValueInfo(t, ATTR_TAG_NAME));
        tag.setDescription(new XMLValueInfo(t, AbstractComponent.DESCRIPTION));
        XModelObject d = t.getChildByPath("declaration"); // $NON-NLS-1$
        if (d != null
            && d.getModelEntity().getName().startsWith("FaceletTaglibComponent")) { // $NON-NLS-1$
          String componentType = d.getAttributeValue(ATTR_COMPONENT_TYPE); // $NON-NLS-1$
          if (componentType != null && componentType.length() > 0) {
            tag.setComponentType(new XMLValueInfo(d, ATTR_COMPONENT_TYPE)); // $NON-NLS-1$
          }
        }
        XModelObject[] as = t.getChildren();
        for (XModelObject a : as) {
          String entity2 = a.getModelEntity().getName();
          if (entity2.startsWith("FaceletTaglibAttribute")) { // $NON-NLS-1$
            FaceletAttribute attr = new FaceletAttribute();
            attr.setId(a);
            attr.setName(new XMLValueInfo(a, XMLStoreConstants.ATTR_NAME));
            attr.setDescription(new XMLValueInfo(a, AbstractComponent.DESCRIPTION));
            attr.setRequired(new XMLValueInfo(a, AbstractAttribute.REQUIRED));

            tag.addAttribute(attr);
          }
        }
        library.addComponent(tag);
      } else if (entity.startsWith("FaceletTaglibFunction")) { // $NON-NLS-1$
        ELFunction f = new ELFunction();
        f.setId(t);
        f.setName(new XMLValueInfo(t, ATTR_FUNC_NAME));
        f.setSignature(new XMLValueInfo(t, ATTR_FUNC_SIGN));
        f.setFunctionClass(new XMLValueInfo(t, ELFunction.FUNCTION_CLASS));
        library.addFunction(f);
      }
    }
  }
Esempio n. 7
0
  private void parseFacesConfig(XModelObject o, IPath source, LoadedDeclarations ds) {
    FacesConfigTagLibrary library = new FacesConfigTagLibrary();
    library.setId(o);
    library.setURI("TODO"); // TODO what is the URI? //$NON-NLS-1$

    ds.getLibraries().add(library);

    XModelObject componentFolder = o.getChildByPath("Components"); // $NON-NLS-1$
    if (componentFolder == null) return;
    XModelObject[] os = componentFolder.getChildren();
    for (XModelObject c : os) {
      FacesConfigComponent component = new FacesConfigComponent();
      component.setId(c);
      // what else can we take for the name? only attribute 'component-type' is available
      component.setName(new XMLValueInfo(c, AbstractComponent.COMPONENT_TYPE));

      component.setComponentClass(new XMLValueInfo(c, AbstractComponent.COMPONENT_CLASS));
      component.setComponentType(new XMLValueInfo(c, AbstractComponent.COMPONENT_TYPE));
      component.setDescription(new XMLValueInfo(c, AbstractComponent.DESCRIPTION));

      XModelObject[] as = c.getChildren();
      for (XModelObject child : as) {
        String entity = child.getModelEntity().getName();
        if (entity.startsWith("JSFAttribute")) { // $NON-NLS-1$
          FacesConfigAttribute attr = new FacesConfigAttribute();
          attr.setId(child);
          attr.setName(new XMLValueInfo(child, ATTR_ATTRIBUTE_NAME));
          component.addAttribute(attr);
        } else if (entity.startsWith("JSFFacet")) { // $NON-NLS-1$
          Facet f = new Facet();
          f.setId(child);
          f.setName(new XMLValueInfo(child, ATTR_FACET_NAME));
          f.setDescription(new XMLValueInfo(child, AbstractComponent.DESCRIPTION));
          component.addFacet(f);
        }
      }
      library.addComponent(component);
    }
  }
  /**
   * Existing interceptor binding, taken from TCK, is annotated @Inherited @Target({TYPE}) If this
   * test fails, first check that the existing interceptor binding has not been moved or modified.
   * In the previous version, the result of testNewInterceptorBindingWizard() was used, but that
   * turned to be not safe, since the order of tests is not guaranteed.
   *
   * @throws CoreException
   */
  public void testNewInterceptorWizard() throws CoreException {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewInterceptorCreationWizard", PACK_NAME, INTERCEPTOR_NAME);

    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    ICDIAnnotation a =
        cdi.getInterceptorBinding(EXISTING_PACK_NAME + "." + EXISTING_INTERCEPTOR_BINDING_NAME);
    assertNotNull(a);

    try {
      NewInterceptorWizardPage page = (NewInterceptorWizardPage) context.page;

      page.addInterceptorBinding(a);

      assertTrue(page.isToBeRegisteredInBeansXML());
      context.setTypeName("com.acme", "Foo");
      assertFalse(page.isToBeRegisteredInBeansXML());
      context.setTypeName(PACK_NAME, INTERCEPTOR_NAME);
      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Interceptor"));
      assertTrue(text.contains("@" + EXISTING_INTERCEPTOR_BINDING_NAME));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Interceptors/" + PACK_NAME + "." + INTERCEPTOR_NAME);
      assertNotNull(c);
    } finally {
      context.close();
    }
  }
  public void testNewStereotypeWizard() {
    WizardContext context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE_NAME);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);
      page.setAlternative(true);
      page.setToBeRegisteredInBeansXML(true);

      assertTrue(page.isToBeRegisteredInBeansXML());

      context.wizard.performFinish();

      String text = context.getNewTypeContent();

      assertTrue(text.contains("@Stereotype"));
      assertTrue(text.contains("@Inherited"));
      assertTrue(text.contains("@Named"));
      assertTrue(text.contains("@Target({ METHOD, FIELD })"));
      assertTrue(text.contains("@Retention(RUNTIME)"));

      IProject tck = ResourcesPlugin.getWorkspace().getRoot().getProject("tck");
      IFile f = tck.getFile("WebContent/WEB-INF/beans.xml");
      XModelObject o = EclipseResourceUtil.createObjectForResource(f);
      XModelObject c = o.getChildByPath("Alternatives/" + PACK_NAME + "." + STEREOTYPE_NAME);
      assertNotNull(c);

    } finally {
      context.close();
    }

    // testNewStereotypeWizardWithStereotype()
    context = new WizardContext();
    context.init(
        "org.jboss.tools.cdi.ui.wizard.NewStereotypeCreationWizard", PACK_NAME, STEREOTYPE2_NAME);
    try {
      context.tck.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
    } catch (CoreException e) {
      e.printStackTrace();
    }
    ICDIProject cdi = CDICorePlugin.getCDIProject(context.tck, true);
    IStereotype s = cdi.getStereotype(PACK_NAME + "." + STEREOTYPE_NAME);
    IStereotype d = cdi.getStereotype(CDIConstants.DECORATOR_STEREOTYPE_TYPE_NAME);
    assertNotNull(s);
    assertNotNull(d);

    try {
      NewStereotypeWizardPage page = (NewStereotypeWizardPage) context.page;
      page.setInherited(true);
      page.setTarget("METHOD,FIELD");
      page.setNamed(true);

      page.addStereotype(d);
      String message = page.getErrorMessage();
      assertNull(message);
      message = page.getMessage();
      assertNotNull(message);
      int messageType = page.getMessageType();
      assertEquals(IMessageProvider.WARNING, messageType);
      String testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_IS_NOT_COMPATIBLE,
              d.getSourceType().getElementName());
      assertEquals(testmessage, message);

      page.addStereotype(s);
      message = page.getErrorMessage();
      testmessage =
          NLS.bind(
              CDIUIMessages.MESSAGE_STEREOTYPE_CANNOT_BE_APPLIED_TO_TYPE,
              s.getSourceType().getElementName());
      assertEquals(testmessage, message);
    } finally {
      context.close();
    }
  }