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$
 }
 public static XModel getXModel(IFile file) {
   if (file == null) return null;
   XModelObject fs = EclipseResourceUtil.getObjectByResource(file);
   if (fs != null) return fs.getModel();
   IProject project = file.getProject();
   IModelNature nature = EclipseResourceUtil.getModelNature(project);
   return (nature == null) ? null : nature.getModel();
 }
  public void load(XModelObject object) {
    if (EclipseResourceUtil.isProjectFragment(object.getModel())) return;

    IAutoLoad auto = (IAutoLoad) object.getModel().getProperties().get(XModelConstants.AUTOLOAD);
    if (auto != null) {
      auto.load(object.getModel());
      updateLibs(object);
      _updateSrcs(object);
      ((FileSystemsImpl) object).updateOverlapped();
      return;
    }

    String f = getEclipseFileName(object, true);
    if (f == null) super.load(object);
    else util().load(new File(f), object);

    XModelObject[] os = object.getChildren();
    for (int i = 0; i < os.length; i++) {
      String s = os[i].getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION);
      if (s == null || !s.startsWith(XModelConstants.WORKSPACE_OLD_REF)) continue;
      s = XModelConstants.WORKSPACE_REF + s.substring(XModelConstants.WORKSPACE_OLD_REF.length());
      os[i].setAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION, s);
    }

    removeMissingJarSystems(object);
  }
Ejemplo n.º 4
0
  public LoadedDeclarations parse(XModelObject o, IPath source, IKbProject sp) {
    if (o == null) return null;

    if (o.getParent() instanceof FolderImpl) {
      IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(source);
      if (f != null && f.exists()) {
        try {
          ((FolderImpl) o.getParent()).updateChildFile(o, f.getLocation().toFile());
        } catch (XModelException e) {
          ModelPlugin.getPluginLog().logError(e);
        }
        if (o.getParent() == null) {
          boolean b = isLikelyComponentSource(f);
          if (!b) return null;
          o = EclipseResourceUtil.getObjectByResource(o.getModel(), f);
          if (o == null) return null;
        }
      }
    }

    LoadedDeclarations ds = new LoadedDeclarations();
    if (LibraryScanner.isTLDFile(o)) {
      parseTLD(o, source, ds);
    } else if (LibraryScanner.isFaceletTaglibFile(o)) {
      parseFaceletTaglib(o, source, ds);
    } else if (LibraryScanner.isFacesConfigFile(o)) {
      parseFacesConfig(o, source, ds);
    }
    return ds;
  }
 /**
  * @see
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkPartitionRecognizer#recognize(org.eclipse.jface.text.IDocument,
  *     com.ibm.sse.editor.extensions.hyperlink.IHyperlinkRegion)
  */
 public boolean recognize(IDocument document, int offset, IHyperlinkRegion region) {
   StructuredModelWrapper smw = new StructuredModelWrapper();
   smw.init(document);
   try {
     IFile documentFile = smw.getFile();
     if (documentFile == null) {
       return false;
     }
     IProject project = documentFile.getProject();
     if (project == null) {
       return false;
     }
     if (EclipseResourceUtil.getModelNature(project) != null) {
       for (int i = 0; i < JSF_PROJECT_NATURES.length; i++) {
         if (project.getNature(JSF_PROJECT_NATURES[i]) != null) return true;
       }
       return false;
     }
     return true;
   } catch (CoreException x) {
     JSFExtensionsPlugin.log("", x); // $NON-NLS-1$
     return false;
   } finally {
     smw.dispose();
   }
 }
Ejemplo n.º 6
0
 public void testWebApp() {
   String testName = "WebAppModelTest:testPaths:attribute";
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   doAttributeTest(n.getModel(), testName);
   XModelObject o = n.getModel().getByPath("/web30.xml");
   printPaths(o);
 }
Ejemplo n.º 7
0
  public void testPaths() {
    IModelNature n = EclipseResourceUtil.getModelNature(project);
    String testName = "JSFModelTest:testPaths";
    IFile f = project.getFile(new Path("/testCases.xml"));
    ArrayList<TestDescription> tests = new TestDescriptionFactory(f).getTestDescriptions(testName);
    System.out.println(testName + " " + (tests == null ? -1 : tests.size()));
    StringBuilder sb = new StringBuilder();
    int errorCount = 0;

    if (tests != null)
      for (int i = 0; i < tests.size(); i++) {
        TestDescription t = tests.get(i);
        String path = t.getProperty("path");
        XModelObject o = n.getModel().getByPath(path);
        if (o == null) {
          sb.append(path).append("\n");
          errorCount++;
        }
      }
    assertTrue(
        "Cannot find objects at " + errorCount + " paths\n" + sb.toString(), errorCount == 0);

    testName = "JSFModelTest:testPaths:attribute";
    doAttributeTest(n.getModel(), testName);
  }
Ejemplo n.º 8
0
 public void testJSFProjectStructure() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   JSFProjectsRoot root = JSFProjectsTree.getProjectsRoot(n.getModel());
   assertTrue("Cannot find root object.", root != null);
   XModelObject[] cs = root.getTreeChildren();
   for (int i = 0; i < cs.length; i++) {
     System.out.println(cs[i].getPath());
   }
 }
 private static IEditorInput convertFileInput(IFileEditorInput input) {
   IFileEditorInput fi = (IFileEditorInput) input;
   IFile f = fi.getFile();
   if (f != null && !f.isSynchronized(IResource.DEPTH_INFINITE)) {
     try {
       f.refreshLocal(IResource.DEPTH_INFINITE, null);
     } catch (CoreException e) {
       // ignore
     }
   }
   XModelObject o = EclipseResourceUtil.getObjectByResource(f);
   if (o == null) {
     o = EclipseResourceUtil.createObjectForResource(f);
   }
   return (o == null || o.getFileType() != XModelObject.FILE)
       ? input
       : new XModelObjectEditorInput(getMainObject(o));
 }
Ejemplo n.º 10
0
 /**
  * This method should be called only if isRelevant returns true; Makes simple check if this java
  * file contains annotation Name.
  *
  * @param resource
  * @return
  */
 public boolean isLikelyComponentSource(IFile f) {
   if (!f.isSynchronized(IFile.DEPTH_ZERO) || !f.exists()) return false;
   XModel model = InnerModelHelper.createXModel(f.getProject());
   if (model == null) return false;
   XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
   return (o != null)
       && (LibraryScanner.isTLDFile(o)
           || LibraryScanner.isFaceletTaglibFile(o)
           || LibraryScanner.isFacesConfigFile(o));
 }
 /**
  * Returns true if XModelObject corresponding to the file is replaced.
  *
  * @return
  */
 public boolean updateXModelObject() {
   IFile file = getFile();
   XModelObject o = EclipseResourceUtil.createObjectForResource(file);
   if (o != null && o != object) {
     object = o;
     cache = new XModelObjectCache(object);
     return true;
   }
   return false;
 }
 public Object getAdapter(Class adapter) {
   if (adapter == XModelObject.class) return getXModelObject();
   Object result = null;
   if (IFile.class.isAssignableFrom(adapter)) {
     result = EclipseResourceUtil.getResource(object);
     if (result != null && !adapter.isAssignableFrom(result.getClass())) result = null;
   } else {
     result = super.getAdapter(adapter);
   }
   return result;
 }
  private void updateLibs(XModelObject object) {
    if (WatcherLoader.isLocked(object.getModel())) {
      return;
    }
    IProject project = EclipseResourceUtil.getProject(object);
    if (project == null) return;
    XModelObject lib = validateLib(object);
    //    	if(lib == null) {
    //    		return;
    //    	}

    Libs libs = FileSystemsHelper.getLibs(object);
    if (libs != null) libs.update();
  }
 XFilteredTree createTree(String name, XModel model) {
   if (model == null || name == null) return null;
   String classname =
       model.getMetaData().getMapping("FilteredTrees").getValue(name); // $NON-NLS-1$
   XFilteredTree result = null;
   try {
     result = (XFilteredTree) ModelFeatureFactory.getInstance().createFeatureInstance(classname);
   } catch (ClassCastException e) {
     ModelUIPlugin.getPluginLog().logError(e);
     return null;
   }
   result.setModel(model);
   if (result.getRoot() == null) {
     result = null;
     IProject p = EclipseResourceUtil.getProject(model.getRoot());
     IModelNature nature = EclipseResourceUtil.getModelNature(p);
     if (nature != null) {
       ModelUIPlugin.getPluginLog()
           .logInfo(
               "Red Hat Project " + p.getName() + " is corrupted."); // $NON-NLS-1$ //$NON-NLS-2$
     }
   }
   return result;
 }
 private boolean saveEclipse(XModelObject object) {
   String f = getEclipseFileName(object, false);
   boolean b = f != null && util().save(new File(f), object);
   if (b) {
     IFile file = EclipseResourceUtil.getFile(f);
     if (file != null) {
       try {
         file.refreshLocal(0, null);
       } catch (CoreException e) {
         // ignore
       }
     }
   }
   return b;
 }
 private static void _updateSrcs(XModelObject object) {
   IProject p = EclipseResourceUtil.getProject(object);
   if (p == null || !p.isAccessible()) return;
   String[] srcs = EclipseResourceUtil.getJavaProjectSrcLocations(p);
   Set<String> paths = new HashSet<String>();
   for (int i = 0; i < srcs.length; i++) {
     String path = EclipseResourceUtil.getRelativeLocation(object.getModel(), srcs[i]);
     if (path == null) continue;
     paths.add(path);
   }
   XModelObject[] cs = object.getChildren(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER);
   for (int i = 0; i < cs.length; i++) {
     if (cs[i]
         .getAttributeValue(XModelObjectConstants.ATTR_NAME)
         .startsWith("src")) { // $NON-NLS-1$
       String loc = cs[i].getAttributeValue(XModelObjectConstants.ATTR_NAME_LOCATION);
       if (!paths.contains(loc)) {
         object.removeChild(cs[i]);
       } else {
         paths.remove(loc);
       }
     }
   }
   for (String path : paths) {
     String n = getNextSrcName(object);
     Properties properties = new Properties();
     properties.setProperty(XModelObjectConstants.ATTR_NAME_LOCATION, path);
     properties.setProperty(XModelObjectConstants.ATTR_NAME, n);
     FileSystemImpl s =
         (FileSystemImpl)
             object
                 .getModel()
                 .createModelObject(XModelObjectConstants.ENT_FILE_SYSTEM_FOLDER, properties);
     object.addChild(s);
   }
 }
 public static IEditorInput checkInput(IEditorInput input) {
   if (input instanceof IModelObjectEditorInput) return input;
   if (input instanceof ILocationProvider) return convertExternalInput((ILocationProvider) input);
   if (input instanceof IFileEditorInput) return convertFileInput((IFileEditorInput) input);
   if (input instanceof IStorageEditorInput)
     return convertStorageEditorInput((IStorageEditorInput) input);
   if (input instanceof IURIEditorInput) {
     URI uri = ((IURIEditorInput) input).getURI();
     String f = uri.getPath();
     XModelObject o = EclipseResourceUtil.createObjectForLocation(f);
     return (o == null || o.getFileType() != XModelObject.FILE)
         ? (IEditorInput) input
         : new ModelObjectLocationEditorInput(getMainObject(o), new Path(f));
   }
   return input;
 }
  /**
   * If there are several f:views on the page. Only the last f:view one should be applied on server,
   * but each f:view should have its own locale.
   *
   * @throws Throwable
   */
  public void testSeveralFViewsWithLocales() throws Throwable {

    IFile file =
        (IFile)
            TestUtil.getComponentPath(SEVERAL_FVIEWS_PAGE, JsfAllTests.IMPORT_JSF_20_PROJECT_NAME);
    assertNotNull(
        "Could not open specified file." //$NON-NLS-1$
            + " componentPage = "
            + SEVERAL_FVIEWS_PAGE //$NON-NLS-1$
            + ";projectName = "
            + JsfAllTests.IMPORT_JSF_20_PROJECT_NAME,
        file); //$NON-NLS-1$
    IEditorInput input = new FileEditorInput(file);
    assertNotNull("Editor input is null", input); // $NON-NLS-1$
    /*
     * open and get the editor
     */
    JSPMultiPageEditor part = openEditor(input);
    VpeController controller = TestUtil.getVpeController(part);

    javaSources = EclipseResourceUtil.getJavaProjectSrcLocations(file.getProject());
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "de", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    /*
     * f:view will use default locale if nothing is specified.
     */
    checkLocaleStrings(file, "en_US", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en_GB", localizedText); // $NON-NLS-1$

    closeEditors();
  }
  private String[] getAvailableProperties(String value) {
    if (value == null || value.length() == 0) {
      return new String[0];
    }
    JSFPromptingProvider provider = new JSFPromptingProvider();

    XModel xModel = getXModel();
    if (xModel == null) {
      // lets create fake model, which can build properties for the value.
      IFile file = (IFile) properties.get("file"); // $NON-NLS-1$
      if (file != null) {
        XModelObject f = EclipseResourceUtil.createObjectForResource(file);
        if (f != null) {
          xModel = f.getModel();
        }
      }
    }
    if (xModel == null) {
      return new String[0];
    }

    return (String[]) provider.buildBeanProperties(xModel, value, null).toArray(new String[0]);
  }
Ejemplo n.º 20
0
  /**
   * 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 String getToolTipText() {
   IFile f = (IFile) EclipseResourceUtil.getResource(object);
   if (f != null && f.exists()) return f.getLocation().toString();
   return object.getPresentationString();
 }
 private static IFile getFileByObject(XModelObject object) {
   return (IFile) EclipseResourceUtil.getResource(object);
 }
 private static IEditorInput convertExternalInput(ILocationProvider input) {
   XModelObject o = EclipseResourceUtil.createObjectForLocation(input.getPath(input).toString());
   return (o == null || o.getFileType() != XModelObject.FILE)
       ? (IEditorInput) input
       : new ModelObjectLocationEditorInput(getMainObject(o), input.getPath(input));
 }
Ejemplo n.º 24
0
 public void testRecognizer() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   EntityRecognizer recognizer = n.getModel().getEntityRecognizer();
   String entity = recognizer.getEntityName(new EntityRecognizerContext("tld", TLD_FILE));
   assertEquals("FileTLD_1_2", entity);
 }
Ejemplo n.º 25
0
 public void testModelExists() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   assertTrue("Test project " + project.getName() + " has no model nature.", n != null);
   assertTrue("XModel for project " + project.getName() + " is not loaded.", n.getModel() != null);
 }
Ejemplo n.º 26
0
 public void testWebAppLoader() {
   IModelNature n = EclipseResourceUtil.getModelNature(project);
   XModelObject o = n.getModel().getByPath("/web30.xml");
   String error = ((AbstractXMLFileImpl) o).getLoaderError();
   assertNull("Loader reported an error.", error);
 }
Ejemplo n.º 27
0
  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();
    }
  }
Ejemplo n.º 28
0
 /**
  * Returns list of components
  *
  * @param f
  * @return
  * @throws ScannerException
  */
 public LoadedDeclarations parse(IFile f, IKbProject sp) throws ScannerException {
   XModel model = InnerModelHelper.createXModel(f.getProject());
   if (model == null) return null;
   XModelObject o = EclipseResourceUtil.getObjectByResource(model, f);
   return parse(o, f.getFullPath(), sp);
 }