@Override
  public Object getAdapter(
      final Object adaptableObject, @SuppressWarnings("rawtypes") final Class adapterType) {

    // TODO: This entire method is ugly and needs to be cleaned up

    final Object adapted;
    if (KarafPlatformModel.class.equals(adapterType)
        && adaptableObject instanceof ILaunchConfiguration) {
      final ILaunchConfiguration configuration = (ILaunchConfiguration) adaptableObject;
      try {
        if (configuration
            .getAttributes()
            .containsKey(KarafLaunchConfigurationConstants.KARAF_LAUNCH_SOURCE_RUNTIME)) {
          final String platformPath =
              (String)
                  configuration
                      .getAttributes()
                      .get(KarafLaunchConfigurationConstants.KARAF_LAUNCH_SOURCE_RUNTIME);
          adapted = KarafPlatformModelRegistry.findPlatformModel(new Path(platformPath));
        } else {
          adapted = null;
        }
      } catch (final CoreException e) {
        KarafUIPluginActivator.getLogger().error("Unable to find Karaf Platform model", e);
        return null;
      }
    } else if (IKarafProject.class.equals(adapterType)
        && adaptableObject instanceof KarafPlatformModel) {
      IKarafProject karafProject = null;
      final KarafPlatformModel karafPlatformModel = (KarafPlatformModel) adaptableObject;
      for (final IProject project : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
        if (KarafProject.isKarafProject(project)) {
          karafProject = new KarafProject(project);
          if (karafPlatformModel
              .getRootDirectory()
              .equals(karafProject.getPlatformRootDirectory())) {
            break;
          }
        }
      }

      adapted = karafProject;
    } else if (IKarafProject.class.equals(adapterType) && adaptableObject instanceof IProject) {
      if (KarafProject.isKarafProject((IProject) adaptableObject)) {
        adapted = new KarafProject((IProject) adaptableObject);
      } else {
        return null;
      }
    } else {
      adapted = null;
    }

    return adapted;
  }
 public void initializeFrom(ILaunchConfiguration conf) {
   debug(">>> initializing Gradle launch tab");
   try {
     for (Object attName : conf.getAttributes().keySet()) {
       debug("" + attName);
     }
   } catch (CoreException e) {
     GradleCore.log(e);
   }
   debug("<<< initializing Gradle launch tab");
   setProject(GradleLaunchConfigurationDelegate.getProject(conf));
   setChecked(GradleLaunchConfigurationDelegate.getTasks(conf));
 }
Exemplo n.º 3
0
  /**
   * Try to get the war output path from server launch config.
   *
   * @param server is the server launcher
   * @param serverLaunchConfig server launcher config
   * @return string path to the output war
   */
  private String getLauncherDirFromServerLaunchConfigAttributes(
      IServer server, ILaunchConfiguration serverLaunchConfig) {
    if (server == null || serverLaunchConfig == null) {
      return null;
    }

    // First get wtp.deploy from the server attributes
    Map<String, Object> launchConfigAttributes = null;
    try {
      launchConfigAttributes = serverLaunchConfig.getAttributes();
    } catch (CoreException e) {
      logError(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't find launcher directory in ATTR_VM_ARGUMENTS.",
          e);
    }

    // Get the vm arguments in the launch configs vm args
    String vmArgsString =
        (String) launchConfigAttributes.get("org.eclipse.jdt.launching.VM_ARGUMENTS");
    if (vmArgsString == null || vmArgsString.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't get org.eclipse.jdt.launching.VM_ARGUMENTS from the launch config.");
      return null;
    }

    // Create an array from the vm args string
    String[] vmArgsArray = DebugPlugin.parseArguments(vmArgsString);
    if (vmArgsArray == null || vmArgsString.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't parse vm args into an array.");
      return null;
    }

    String wtpDeployArg = null;
    for (int i = 0; i < vmArgsArray.length; i++) {
      String arg = vmArgsArray[i];
      if (arg != null && arg.startsWith("-Dwtp.deploy")) {
        wtpDeployArg = arg.replaceFirst("-Dwtp.deploy=", "");
        wtpDeployArg = wtpDeployArg.replace("\"", "").trim();
        break;
      }
    }

    if (wtpDeployArg == null || wtpDeployArg.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't get \"-Dwtp.deploy=\" (w/no spaces) arg from vm args list.");
      return null;
    }

    // Next get the server project deploy name or deploy context relative path
    String launcherDir = null;
    String deployName = null;
    IModule[] modules = server.getModules();
    if (modules != null && modules.length > 0) {
      if (modules.length > 0) {
        logMessage(
            "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: launcherDir will use the first module for the deploy path.");
      }
      IModule2 module = (IModule2) modules[0];
      deployName = module.getProperty(IModule2.PROP_DEPLOY_NAME);
      if (deployName == null) {
        logMessage(
            "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: Couldn't get the deploy path for the module.");
      } else {
        launcherDir = wtpDeployArg + File.separator + deployName;
      }
    } else {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: the modules are empty, add a wtp module.");
    }

    if (launcherDir == null) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: couldn't construct the launcherDir Path from server launch config.");
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: wtpDeployArg="
              + wtpDeployArg);
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: wtpDeployArg="
              + deployName);
    }

    logMessage(
        "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: Success, found the launcherDir="
            + launcherDir);

    return launcherDir;
  }