public void setSpecificConfiguration(
     Map<String, String> newPropertyValues,
     Map<String, Integer> newMessageSeverities,
     IProject project) {
   if (project != null && hasProjectSpecificOptions(project)) {
     for (Map.Entry<String, String> entry : newPropertyValues.entrySet()) {
       SpringCorePreferences.getProjectPreferences(project)
           .putString(PROPERTY_PREFIX + entry.getKey(), entry.getValue());
     }
     for (Map.Entry<String, Integer> entry : newMessageSeverities.entrySet()) {
       SpringCorePreferences.getProjectPreferences(project)
           .putString(MESSAGE_PREFIX + entry.getKey(), Integer.toString(entry.getValue()));
     }
   } else {
     for (Map.Entry<String, String> entry : newPropertyValues.entrySet()) {
       SpringCore.getDefault()
           .getPluginPreferences()
           .setValue(PROPERTY_PREFIX + entry.getKey(), entry.getValue());
     }
     for (Map.Entry<String, Integer> entry : newMessageSeverities.entrySet()) {
       SpringCore.getDefault()
           .getPluginPreferences()
           .setValue(MESSAGE_PREFIX + entry.getKey(), Integer.toString(entry.getValue()));
     }
   }
 }
  // changed API of IBinaryMethod (between Eclipse 4.5 and Eclipse 4.6)
  // therefore adapting to this via reflection to use the correct existing method
  private static IBinaryAnnotation[] getParameterAnnotation(
      IBinaryMethod newMethod, int i, char[] fileName) {
    IBinaryAnnotation[] result = null;

    // try the old method first
    try {

      try {
        Method getParameterAnnotationsMethod =
            newMethod.getClass().getMethod("getParameterAnnotations", int.class);
        if (getParameterAnnotationsMethod != null) {
          getParameterAnnotationsMethod.setAccessible(true);
          result = (IBinaryAnnotation[]) getParameterAnnotationsMethod.invoke(newMethod, i);
        }
      } catch (NoSuchMethodException e) {

        // if the old method is not there, try the new one
        Method getParameterAnnotationsMethod =
            newMethod.getClass().getMethod("getParameterAnnotations", int.class, char[].class);
        if (getParameterAnnotationsMethod != null) {
          getParameterAnnotationsMethod.setAccessible(true);
          result =
              (IBinaryAnnotation[]) getParameterAnnotationsMethod.invoke(newMethod, i, fileName);
        }
      }

    } catch (Exception e) {
      SpringCore.log(e);
    }

    return result;
  }
Пример #3
0
  public static IType getAjdtType(IProject project, String className) {
    IJavaProject javaProject = getJavaProject(project);
    if (IS_AJDT_PRESENT && javaProject != null && className != null) {

      try {
        IType type = null;

        // First look for the type in the project
        if (isAjdtProject(project)) {
          type = AjdtUtils.getAjdtType(project, className);
          if (type != null) {
            return type;
          }
        }

        // Then look for the type in the referenced Java projects
        for (IProject refProject : project.getReferencedProjects()) {
          if (isAjdtProject(refProject)) {
            type = AjdtUtils.getAjdtType(refProject, className);
            if (type != null) {
              return type;
            }
          }
        }
      } catch (CoreException e) {
        SpringCore.log("Error getting Java type '" + className + "'", e);
      }
    }
    return null;
  }
Пример #4
0
  /**
   * Returns the corresponding Java type for given full-qualified class name.
   *
   * @param project the JDT project the class belongs to
   * @param className the full qualified class name of the requested Java type
   * @return the requested Java type or null if the class is not defined or the project is not
   *     accessible
   */
  public static IType getJavaType(IProject project, String className) {
    IJavaProject javaProject = JdtUtils.getJavaProject(project);

    if (className != null) {

      // For inner classes replace '$' by '.'
      String unchangedClassName = null;
      int pos = className.lastIndexOf('$');
      if (pos > 0) {
        unchangedClassName = className;
        className = className.replace('$', '.');
      }

      try {
        IType type = null;
        // First look for the type in the Java project
        if (javaProject != null) {
          type = javaProject.findType(className, new NullProgressMonitor());

          if (type == null && unchangedClassName != null) {
            type =
                findTypeWithInnerClassesInvolved(
                    javaProject, unchangedClassName, new NullProgressMonitor());
          }

          if (type != null) {
            return type;
          }
        }

        // Then look for the type in the referenced Java projects
        for (IProject refProject : project.getReferencedProjects()) {
          IJavaProject refJavaProject = JdtUtils.getJavaProject(refProject);
          if (refJavaProject != null) {
            type = refJavaProject.findType(className);

            if (type == null && unchangedClassName != null) {
              type =
                  findTypeWithInnerClassesInvolved(
                      javaProject, unchangedClassName, new NullProgressMonitor());
            }

            if (type != null) {
              return type;
            }
          }
        }

        // fall back and try to locate the class using AJDT
        return getAjdtType(project, className);
      } catch (CoreException e) {
        SpringCore.log("Error getting Java type '" + className + "'", e);
      }
    }

    return null;
  }
  /** Check if a given {@link IResource} representing a class file has structural changes. */
  public boolean hasStructuralChanges(IResource resource, int flags) {
    try {
      r.lock();
      if (!hasRecordedTypeStructures(resource.getProject())) {
        return true;
      }

      Map<String, TypeStructure> typeStructures =
          typeStructuresByProject.get(resource.getProject());

      if (resource != null
          && resource.getFileExtension() != null
          && resource.getFileExtension().equals("java")) {
        IJavaElement element = JavaCore.create(resource);
        if (element instanceof ICompilationUnit && ((ICompilationUnit) element).isOpen()) {
          try {
            IType[] types = ((ICompilationUnit) element).getAllTypes();
            for (IType type : types) {
              String fqn = type.getFullyQualifiedName();
              TypeStructure typeStructure = typeStructures.get(fqn);
              if (typeStructure == null) {
                return true;
              }
              ClassFileReader reader =
                  getClassFileReaderForClassName(
                      type.getFullyQualifiedName(), resource.getProject());
              if (reader != null && hasStructuralChanges(reader, typeStructure, flags)) {
                return true;
              }
            }
            return false;
          } catch (JavaModelException e) {
            SpringCore.log(e);
          } catch (MalformedURLException e) {
            SpringCore.log(e);
          }
        }
      }
      return true;
    } finally {
      r.unlock();
    }
  }
  private static File toLocalFile(URI locationURI) {
    if (locationURI == null) return null;

    try {
      IFileStore store = EFS.getStore(locationURI);
      return store.toLocalFile(0, null);
    } catch (CoreException ex) {
      SpringCore.log("Error while converting URI to local file: " + locationURI.toString(), ex);
    }

    return null;
  }
Пример #7
0
 /**
  * Returns the corresponding Java project or <code>null</code> a for given project.
  *
  * @param project the project the Java project is requested for
  * @return the requested Java project or <code>null</code> if the Java project is not defined or
  *     the project is not accessible
  */
 public static IJavaProject getJavaProject(IProject project) {
   if (project.isAccessible()) {
     try {
       if (project.hasNature(JavaCore.NATURE_ID)) {
         return (IJavaProject) project.getNature(JavaCore.NATURE_ID);
       }
     } catch (CoreException e) {
       SpringCore.log("Error getting Java project for project '" + project.getName() + "'", e);
     }
   }
   return null;
 }
Пример #8
0
 /** Returns true if given resource's project is a Java project. */
 public static boolean isJavaProject(IResource resource) {
   if (resource != null && resource.isAccessible()) {
     IProject project = resource.getProject();
     if (project != null) {
       try {
         return project.hasNature(JavaCore.NATURE_ID);
       } catch (CoreException e) {
         SpringCore.log(e);
       }
     }
   }
   return false;
 }
Пример #9
0
 /** Creates a Set of {@link URL}s from the OSGi bundle class path manifest entry. */
 public static Set<URL> getBundleClassPath(String bundleId) {
   Set<URL> paths = new HashSet<URL>();
   try {
     Bundle bundle = Platform.getBundle(bundleId);
     if (bundle != null) {
       String bundleClassPath =
           (String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_CLASSPATH);
       if (bundleClassPath != null) {
         String[] classPathEntries = StringUtils.delimitedListToStringArray(bundleClassPath, ",");
         for (String classPathEntry : classPathEntries) {
           if (".".equals(classPathEntry.trim())) {
             paths.add(FileLocator.toFileURL(bundle.getEntry("/")));
           } else {
             try {
               paths.add(
                   FileLocator.toFileURL(
                       new URL(bundle.getEntry("/"), "/" + classPathEntry.trim())));
             } catch (FileNotFoundException e) {
               SpringCore.log(
                   "bundle classpath entry \""
                       + classPathEntry.trim()
                       + "\" of bundle "
                       + bundle.getSymbolicName()
                       + " not found and therefore ignored",
                   e);
             }
           }
         }
       } else {
         paths.add(FileLocator.toFileURL(bundle.getEntry("/")));
       }
     }
   } catch (MalformedURLException e) {
     SpringCore.log(e);
   } catch (IOException e) {
     SpringCore.log(e);
   }
   return paths;
 }
Пример #10
0
  /** Checks if the given <code>type</code> implements/extends <code>className</code>. */
  public static boolean doesImplement(IResource resource, IType type, String className) {
    if (resource == null || type == null || className == null) {
      return false;
    }
    if (className.startsWith("java.") || className.startsWith("javax.")) {
      try {
        ClassLoader cls = getClassLoader(resource.getProject(), null);
        Class<?> typeClass = cls.loadClass(type.getFullyQualifiedName('$'));
        Class<?> interfaceClass = cls.loadClass(className);
        return typeClass.equals(interfaceClass) || interfaceClass.isAssignableFrom(typeClass);
      } catch (Throwable e) {
        // ignore this and fall back to JDT does implement checks
      }
    }

    if (System.getProperty(TypeHierarchyEngine.ENABLE_PROPERTY, "true").equals("true")) {
      return SpringCore.getTypeHierarchyEngine().doesImplement(type, className, true)
          || SpringCore.getTypeHierarchyEngine().doesExtend(type, className, true);
    } else {
      return doesImplementWithJdt(resource, type, className);
    }
  }
 public IValidationRule getRule() {
   if (propertyValues.size() > 0 && !rulePropertiesInitialized) {
     BeanWrapper wrapper = new BeanWrapperImpl(rule);
     for (Map.Entry<String, String> entry : propertyValues.entrySet()) {
       try {
         wrapper.setPropertyValue(entry.getKey(), entry.getValue());
       } catch (BeansException e) {
         SpringCore.log(e);
       }
     }
     rulePropertiesInitialized = true;
   }
   return rule;
 }
 protected void readSpecificConfiguration(IProject project) {
   if (project != null && hasProjectSpecificOptions(project)) {
     for (Map.Entry<String, String> entry : originalPropertyValues.entrySet()) {
       String value =
           SpringCorePreferences.getProjectPreferences(project)
               .getString(PROPERTY_PREFIX + entry.getKey(), entry.getValue());
       propertyValues.put(entry.getKey(), value);
     }
     for (Map.Entry<String, Integer> entry : originalMessageSeverities.entrySet()) {
       String value =
           SpringCorePreferences.getProjectPreferences(project)
               .getString(MESSAGE_PREFIX + entry.getKey(), Integer.toString(entry.getValue()));
       messageSeverities.put(entry.getKey(), Integer.valueOf(value));
     }
   } else {
     for (Map.Entry<String, String> entry : originalPropertyValues.entrySet()) {
       String value =
           SpringCore.getDefault()
               .getPluginPreferences()
               .getString(PROPERTY_PREFIX + entry.getKey());
       if (StringUtils.hasText(value)) {
         propertyValues.put(entry.getKey(), value);
       }
     }
     for (Map.Entry<String, Integer> entry : originalMessageSeverities.entrySet()) {
       String value =
           SpringCore.getDefault()
               .getPluginPreferences()
               .getString(MESSAGE_PREFIX + entry.getKey());
       if (StringUtils.hasText(value)) {
         messageSeverities.put(entry.getKey(), Integer.valueOf(value));
       }
     }
   }
   rulePropertiesInitialized = false;
 }
Пример #13
0
 private static boolean doesImplementWithJdt(IResource resource, IType type, String className) {
   IType interfaceType = getJavaType(resource.getProject(), className);
   if (type != null && interfaceType != null) {
     try {
       IType[] subTypes =
           SuperTypeHierarchyCache.getTypeHierarchy(interfaceType).getAllSubtypes(interfaceType);
       if (subTypes != null) {
         for (IType subType : subTypes) {
           if (subType.equals(type)) {
             return true;
           }
         }
       }
     } catch (JavaModelException ex) {
       SpringCore.log(ex);
     }
   }
   return false;
 }
  @Override
  public boolean performFinish() {

    URI tempLocation = projectPage.getProjectLocationURI();
    if (tempLocation == null) {
      tempLocation = ResourcesPlugin.getWorkspace().getRoot().getLocationURI();
    }
    if (tempLocation == null) {
      tempLocation = ResourcesPlugin.getWorkspace().getRoot().getRawLocationURI();
    }
    final URI location = tempLocation;
    final String rooInstall = projectPage.getRooInstallName();
    final boolean useDefault = projectPage.useDefaultRooInstall();
    final DependencyManagement dependencyManagement = projectPage.getDependencyManagement();
    final String packagingProvider = projectPage.getPackagingProvider();

    WorkspaceModifyOperation operation =
        new WorkspaceModifyOperation() {

          @Override
          protected void execute(IProgressMonitor monitor)
              throws CoreException, InvocationTargetException, InterruptedException {

            monitor.beginTask("Creating Roo project: ", 6);
            monitor.subTask("loading Spring Roo");
            IRooInstall install =
                (useDefault
                    ? RooCoreActivator.getDefault().getInstallManager().getDefaultRooInstall()
                    : RooCoreActivator.getDefault().getInstallManager().getRooInstall(rooInstall));
            monitor.worked(1);

            Bootstrap bootstrap = null;
            try {
              // Create project location
              monitor.subTask("creating project location");
              File projectFile = new File(new File(location), projectPage.getProjectName());
              if (!projectFile.exists()) {
                projectFile.mkdirs();
              }
              monitor.worked(2);
              monitor.subTask("starting Spring Roo shell");

              String javaVersion = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance");
              String rooJavaVersion =
                  (ROO_JAVA_VERSION_MAPPING.containsKey(javaVersion)
                      ? ROO_JAVA_VERSION_MAPPING.get(javaVersion)
                      : "8");

              // Create Roo project by launching Roo and invoking the
              // create project command
              String projectLocation = projectFile.getCanonicalPath();

              bootstrap =
                  new Bootstrap(
                      null,
                      projectLocation,
                      install.getHome(),
                      install.getVersion(),
                      new ProjectRefresher(null));

              // Init Roo shell
              bootstrap.start(
                  new StyledTextAppender(shellPage.getRooShell()), projectPage.getProjectName());
              monitor.worked(3);

              ProjectType type = projectPage.getProjectType();

              // Command used to create new project
              String createCommand = type.getCommand();

              // If maven project will be generated using Spring Roo 2.0+, is necessary to add
              // setup instruction on command
              if (createCommand.equals("project") && !install.getVersion().startsWith("1")) {
                createCommand = createCommand.concat(" setup");
              }

              // Create project
              monitor.subTask(String.format("execute Spring Roo '%s' command", type.getCommand()));
              StringBuilder builder = new StringBuilder();
              builder.append(createCommand);
              builder.append(" --topLevelPackage ").append(projectPage.getPackageName());
              if (type == ProjectType.PROJECT) {
                builder
                    .append(" --projectName ")
                    .append("\"")
                    .append(projectPage.getProjectName())
                    .append("\"");
                builder.append(" --java ").append(rooJavaVersion);
                if (RooUiUtil.isRoo120OrGreater(install)) {
                  builder.append(" --packaging ").append(packagingProvider);
                }
              } else if (type == ProjectType.MULTIMODULE_STANDARD) {
                builder
                    .append(" --projectName ")
                    .append("\"")
                    .append(projectPage.getProjectName())
                    .append("\"");
                builder.append(" --java ").append(rooJavaVersion);
                builder.append(" --multimodule STANDARD");
              } else if (type == ProjectType.MULTIMODULE_BASIC) {
                builder
                    .append(" --projectName ")
                    .append("\"")
                    .append(projectPage.getProjectName())
                    .append("\"");
                builder.append(" --java ").append(rooJavaVersion);
                builder.append(" --multimodule BASIC");
              } else if (type == ProjectType.ADDON_SUITE) {
                builder
                    .append(" --projectName ")
                    .append("\"")
                    .append(projectPage.getProjectName())
                    .append("\"");
                builder
                    .append(" --description \"")
                    .append(projectPage.getDescription())
                    .append("\"");

              } else {
                builder
                    .append(" --description \"")
                    .append(projectPage.getDescription())
                    .append("\"");
              }

              final String commandString = builder.toString();

              Display.getDefault()
                  .asyncExec(
                      new Runnable() {

                        public void run() {
                          shellPage.getRooShell().append(commandString + StyledTextAppender.NL);
                        }
                      });

              bootstrap.execute(commandString);

              // Shutdown Roo
              bootstrap.shutdown();
              bootstrap = null;
              monitor.worked(4);

              // Write our own .classpath file if M2E can't provide one for us
              if (!DependencyManagementUtils.IS_M2ECLIPSE_PRESENT) {
                monitor.subTask("configuring Eclipse project meta data");
                // Setup Eclipse metadata
                File classpathDescriptor = new File(projectFile, ".classpath");
                FileWriter writer = new FileWriter(classpathDescriptor);
                if (type == ProjectType.PROJECT) {
                  // For now, only Java projects & web projects
                  if (!RooUiUtil.isRoo120OrGreater(install)
                      || "jar".equalsIgnoreCase(packagingProvider)
                      || "war".equalsIgnoreCase(packagingProvider)) {
                    writer.write(CLASSPATH_FILE);
                  }
                } else {
                  // Add-on projects
                  writer.write(CLASSPATH_FILE);
                }
                writer.flush();
                writer.close();
              }

              monitor.subTask("importing project into workspace");
              IWorkspace workspace = ResourcesPlugin.getWorkspace();
              IProject project = workspace.getRoot().getProject(projectPage.getProjectName());
              IProjectDescription desc =
                  workspace.newProjectDescription(projectPage.getProjectName());
              if (projectPage.isExternalProject()) {
                desc.setLocation(new Path(projectLocation));
              }

              project.create(desc, new NullProgressMonitor());
              project.open(0, new NullProgressMonitor());
              project.setDescription(desc, new NullProgressMonitor());

              // ROO-3726: Also check MULTIMODULE projects
              if (type == ProjectType.PROJECT
                  || type == ProjectType.MULTIMODULE_STANDARD
                  || type == ProjectType.MULTIMODULE_BASIC) {
                if (!RooUiUtil.isRoo120OrGreater(install)
                    || "jar".equalsIgnoreCase(packagingProvider)
                    || "war".equalsIgnoreCase(packagingProvider)) {
                  // For now, only Java projects & web projects
                  SpringCoreUtils.addProjectBuilder(
                      project, "org.eclipse.ajdt.core.ajbuilder", new NullProgressMonitor());
                  SpringCoreUtils.addProjectBuilder(
                      project, SpringCore.BUILDER_ID, new NullProgressMonitor());
                  SpringCoreUtils.addProjectNature(
                      project, JavaCore.NATURE_ID, new NullProgressMonitor());
                  SpringCoreUtils.addProjectNature(
                      project, "org.eclipse.ajdt.ui.ajnature", new NullProgressMonitor());
                }
                SpringCoreUtils.addProjectNature(
                    project, SpringCore.NATURE_ID, new NullProgressMonitor());
                SpringCoreUtils.addProjectNature(
                    project, RooCoreActivator.NATURE_ID, new NullProgressMonitor());
              } else {
                // Add-ons
                SpringCoreUtils.addProjectBuilder(
                    project, JavaCore.BUILDER_ID, new NullProgressMonitor());
                SpringCoreUtils.addProjectNature(
                    project, JavaCore.NATURE_ID, new NullProgressMonitor());
                SpringCoreUtils.addProjectBuilder(
                    project, SpringCore.BUILDER_ID, new NullProgressMonitor());
                SpringCoreUtils.addProjectNature(
                    project, SpringCore.NATURE_ID, new NullProgressMonitor());
              }

              SpringCorePreferences.getProjectPreferences(project, RooCoreActivator.PLUGIN_ID)
                  .putBoolean(RooCoreActivator.PROJECT_PROPERTY_ID, useDefault);
              SpringCorePreferences.getProjectPreferences(project, RooCoreActivator.PLUGIN_ID)
                  .putString(RooCoreActivator.ROO_INSTALL_PROPERTY, rooInstall);

              configureProjectUi(project);

              if (DependencyManagementUtils.IS_M2ECLIPSE_PRESENT) {
                DependencyManagementUtils.installDependencyManagement(
                    project, dependencyManagement);
              }

              // ROO-3726: If project type is MULTIMODULE_BASIC or MULTIMODULE_STANDARD, also import
              // modules
              List<IProject> modules = new ArrayList<IProject>();

              if (type == ProjectType.MULTIMODULE_BASIC) {
                // Import application module project
                IProject applicationModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("application"));
                IProjectDescription applicationModuleDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("application"));
                applicationModuleDescription.setLocation(
                    new Path(projectLocation + "/application"));
                applicationModuleProject.create(
                    applicationModuleDescription, new NullProgressMonitor());
                applicationModuleProject.open(0, new NullProgressMonitor());
                applicationModuleProject.setDescription(
                    applicationModuleDescription, new NullProgressMonitor());
                modules.add(applicationModuleProject);
              } else if (type == ProjectType.MULTIMODULE_STANDARD) {
                // Import model module project
                IProject modelModuleProject =
                    workspace.getRoot().getProject(project.getName().concat(".").concat("model"));
                IProjectDescription modelModuleDescription =
                    workspace.newProjectDescription(project.getName().concat(".").concat("model"));
                modelModuleDescription.setLocation(new Path(projectLocation + "/model"));
                modelModuleProject.create(modelModuleDescription, new NullProgressMonitor());
                modelModuleProject.open(0, new NullProgressMonitor());
                modelModuleProject.setDescription(
                    modelModuleDescription, new NullProgressMonitor());
                modules.add(modelModuleProject);

                // Import repository module project
                IProject repositoryModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("repository"));
                IProjectDescription repositoryModuleDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("repository"));
                repositoryModuleDescription.setLocation(new Path(projectLocation + "/repository"));
                repositoryModuleProject.create(
                    repositoryModuleDescription, new NullProgressMonitor());
                repositoryModuleProject.open(0, new NullProgressMonitor());
                repositoryModuleProject.setDescription(
                    repositoryModuleDescription, new NullProgressMonitor());
                modules.add(repositoryModuleProject);

                // Import service-api module project
                IProject serviceApiModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("service-api"));
                IProjectDescription serviceApiModuleDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("service-api"));
                serviceApiModuleDescription.setLocation(new Path(projectLocation + "/service-api"));
                serviceApiModuleProject.create(
                    serviceApiModuleDescription, new NullProgressMonitor());
                serviceApiModuleProject.open(0, new NullProgressMonitor());
                serviceApiModuleProject.setDescription(
                    serviceApiModuleDescription, new NullProgressMonitor());
                modules.add(serviceApiModuleProject);

                // Import service-impl module project
                IProject serviceImplModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("service-impl"));
                IProjectDescription serviceApiImplDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("service-impl"));
                serviceApiImplDescription.setLocation(new Path(projectLocation + "/service-impl"));
                serviceImplModuleProject.create(
                    serviceApiImplDescription, new NullProgressMonitor());
                serviceImplModuleProject.open(0, new NullProgressMonitor());
                serviceImplModuleProject.setDescription(
                    serviceApiImplDescription, new NullProgressMonitor());
                modules.add(serviceImplModuleProject);

                // Import integration module project
                IProject integrationModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("integration"));
                IProjectDescription integrationModuleDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("integration"));
                integrationModuleDescription.setLocation(
                    new Path(projectLocation + "/integration"));
                integrationModuleProject.create(
                    integrationModuleDescription, new NullProgressMonitor());
                integrationModuleProject.open(0, new NullProgressMonitor());
                integrationModuleProject.setDescription(
                    integrationModuleDescription, new NullProgressMonitor());
                modules.add(integrationModuleProject);

                // Import application module project
                IProject applicationModuleProject =
                    workspace
                        .getRoot()
                        .getProject(project.getName().concat(".").concat("application"));
                IProjectDescription applicationModuleDescription =
                    workspace.newProjectDescription(
                        project.getName().concat(".").concat("application"));
                applicationModuleDescription.setLocation(
                    new Path(projectLocation + "/application"));
                applicationModuleProject.create(
                    applicationModuleDescription, new NullProgressMonitor());
                applicationModuleProject.open(0, new NullProgressMonitor());
                applicationModuleProject.setDescription(
                    applicationModuleDescription, new NullProgressMonitor());
                modules.add(applicationModuleProject);
              }

              // ROO-3726: If some modules have been imported, configure them.
              for (IProject module : modules) {
                SpringCoreUtils.addProjectNature(
                    module, SpringCore.NATURE_ID, new NullProgressMonitor());
                SpringCoreUtils.addProjectNature(
                    module, RooCoreActivator.NATURE_ID, new NullProgressMonitor());

                SpringCorePreferences.getProjectPreferences(module, RooCoreActivator.PLUGIN_ID)
                    .putBoolean(RooCoreActivator.PROJECT_PROPERTY_ID, useDefault);
                SpringCorePreferences.getProjectPreferences(module, RooCoreActivator.PLUGIN_ID)
                    .putString(RooCoreActivator.ROO_INSTALL_PROPERTY, rooInstall);

                configureProjectUi(module);

                if (DependencyManagementUtils.IS_M2ECLIPSE_PRESENT) {
                  DependencyManagementUtils.installDependencyManagement(
                      module, dependencyManagement);
                }
              }

              new OpenShellJob(project).schedule();

              monitor.worked(6);
              monitor.done();
            } catch (Throwable e) {
              SpringCore.log(e);
            } finally {
              if (bootstrap != null) {
                // Shutdown Roo
                try {
                  bootstrap.shutdown();
                } catch (Throwable e) {
                }
              }
            }
          }
        };

    try {
      getContainer().run(true, true, operation);
    } catch (InvocationTargetException e) {
      SpringCore.log(e);
    } catch (InterruptedException e) {
      SpringCore.log(e);
    }

    return true;
  }
Пример #15
0
  public static String resolveClassName(String className, IType type) {
    if (className == null || type == null) {
      return className;
    }
    // replace binary $ inner class name syntax with . for source level
    className = className.replace('$', '.');
    String dotClassName = new StringBuilder().append('.').append(className).toString();

    IProject project = type.getJavaProject().getProject();

    try {
      // Special handling for some well-know classes
      if (className.startsWith("java.lang") && getJavaType(project, className) != null) {
        return className;
      }

      // Check if the class is imported
      if (!type.isBinary()) {

        // Strip className to first segment to support ReflectionUtils.MethodCallback
        int ix = className.lastIndexOf('.');
        String firstClassNameSegment = className;
        if (ix > 0) {
          firstClassNameSegment = className.substring(0, ix);
        }

        // Iterate the imports
        for (IImportDeclaration importDeclaration : type.getCompilationUnit().getImports()) {
          String importName = importDeclaration.getElementName();
          // Wildcard imports -> check if the package + className is a valid type
          if (importDeclaration.isOnDemand()) {
            String newClassName =
                new StringBuilder(importName.substring(0, importName.length() - 1))
                    .append(className)
                    .toString();
            if (getJavaType(project, newClassName) != null) {
              return newClassName;
            }
          }
          // Concrete import matching .className at the end -> check if type exists
          else if (importName.endsWith(dotClassName) && getJavaType(project, importName) != null) {
            return importName;
          }
          // Check if className is multi segmented (ReflectionUtils.MethodCallback)
          // -> check if the first segment
          else if (!className.equals(firstClassNameSegment)) {
            if (importName.endsWith(firstClassNameSegment)) {
              String newClassName =
                  new StringBuilder(importName.substring(0, importName.lastIndexOf('.') + 1))
                      .append(className)
                      .toString();
              if (getJavaType(project, newClassName) != null) {
                return newClassName;
              }
            }
          }
        }
      }

      // Check if the class is in the same package as the type
      String packageName = type.getPackageFragment().getElementName();
      String newClassName = new StringBuilder(packageName).append(dotClassName).toString();
      if (getJavaType(project, newClassName) != null) {
        return newClassName;
      }

      // Check if the className is sufficient (already fully-qualified)
      if (getJavaType(project, className) != null) {
        return className;
      }

      // Check if the class is coming from the java.lang
      newClassName = new StringBuilder("java.lang").append(dotClassName).toString();
      if (getJavaType(project, newClassName) != null) {
        return newClassName;
      }

      // Fall back to full blown resolution
      String[][] fullInter = type.resolveType(className);
      if (fullInter != null && fullInter.length > 0) {
        return fullInter[0][0] + "." + fullInter[0][1];
      }
    } catch (JavaModelException e) {
      SpringCore.log(e);
    }

    return className;
  }