Ejemplo n.º 1
0
  public static void setCollectionValues(
      Xpp3Dom parent, String nodeName, String childName, Collection<String> values) {
    Xpp3Dom node = parent.getChild(nodeName);

    if (node != null) {
      for (int i = 0; i < parent.getChildCount(); i++) {
        Xpp3Dom existing = parent.getChild(i);

        if (StringUtils.equals(nodeName, existing.getName())) {
          parent.removeChild(i);

          break;
        }
      }

      node = null;
    }

    node = new Xpp3Dom(nodeName);

    parent.addChild(node);

    for (String childVal : values) {
      Xpp3Dom childNode = new Xpp3Dom(childName);
      node.addChild(childNode);
      childNode.setValue(childVal);
    }
  }
  public List<String> getW32Icons() {
    Xpp3Dom domLauncher = dom.getChild("launcher");
    if (domLauncher == null) {

      return null;
    }
    Xpp3Dom win = domLauncher.getChild("win");
    if (win == null) {
      return null;
    }
    List<String> icons = new ArrayList<String>();
    String useIco = win.getAttribute("useIco");
    if (Boolean.valueOf(useIco)) {
      // for (Xpp3Dom ico : win.getChildren("ico"))
      {
        Xpp3Dom ico = win.getChild("ico");
        // should be only 1
        icons.add(ico.getAttribute("path"));
      }
    } else {
      for (Xpp3Dom bmp : win.getChildren("bmp")) {
        String[] attibuteNames = bmp.getAttributeNames();
        if (attibuteNames != null && attibuteNames.length > 0)
          icons.add(bmp.getAttribute(bmp.getAttributeNames()[0]));
      }
    }
    return icons;
  }
 public String getValueForWebResource(Xpp3Dom dom, String value) {
   Xpp3Dom resource = dom.getChild("resource");
   if (resource != null) {
     Xpp3Dom child = resource.getChild(value);
     if (child != null) {
       return child.getValue();
     }
   }
   return null;
 }
  public String getMacIcon() {
    Xpp3Dom domLauncher = dom.getChild("launcher");
    if (domLauncher == null) {

      return null;
    }
    Xpp3Dom linux = domLauncher.getChild("macosx");
    if (linux == null) {
      return null;
    }
    return linux.getAttribute("icon");
  }
    private void readConfiguration() throws IOException {
      Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
      defaultBundleList = null;
      jarWebSupport = null;
      includeDefaultBundles = true;
      bundleListFile = new File(project.getBasedir(), "src/main/bundles/list.xml");
      if (configuration != null) {
        includeDefaultBundles = nodeValue(configuration, "includeDefaultBundles", true);
        Xpp3Dom defaultBundleListConfig = configuration.getChild("defaultBundleList");
        if (defaultBundleListConfig != null) {
          defaultBundleList = new ArtifactDefinition(defaultBundleListConfig);
        }
        Xpp3Dom jarWebSupportConfig = configuration.getChild("jarWebSupport");
        if (jarWebSupportConfig != null) {
          jarWebSupport = new ArtifactDefinition(jarWebSupportConfig);
        }
        Xpp3Dom bundleListFileConfig = configuration.getChild("bundleListFile");
        if (bundleListFileConfig != null) {
          bundleListFile = new File(project.getBasedir(), bundleListFileConfig.getValue());
        }

        configureAdditionalBundles(configuration);
      }

      for (PluginExecution execution : plugin.getExecutions()) {
        Xpp3Dom executionConfiguration = (Xpp3Dom) execution.getConfiguration();
        if (executionConfiguration != null) {
          configureAdditionalBundles(executionConfiguration);
        }
      }

      initArtifactDefinitions(
          getClass().getClassLoader(),
          new ArtifactDefinitionsCallback() {

            public void initArtifactDefinitions(Properties dependencies) {
              if (defaultBundleList == null) {
                defaultBundleList = new ArtifactDefinition();
              }
              defaultBundleList.initDefaults(dependencies.getProperty("defaultBundleList"));

              if (jarWebSupport == null) {
                jarWebSupport = new ArtifactDefinition();
              }
              jarWebSupport.initDefaults(dependencies.getProperty("jarWebSupport"));
            }
          });
    }
  private List<String> findModules(Plugin pluginConfig, IJavaProject javaProject) {
    List<String> modNames = new ArrayList<String>();
    Xpp3Dom gwtConfig = (Xpp3Dom) pluginConfig.getConfiguration();

    if (gwtConfig != null) {
      Xpp3Dom[] moduleNodes = gwtConfig.getChildren("module");
      if (moduleNodes.length > 0) {
        String moduleQNameTrimmed = null;
        for (Xpp3Dom mNode : moduleNodes) {
          moduleQNameTrimmed = mNode.getValue().trim();
        }
        if (moduleQNameTrimmed != null) {
          modNames.add(moduleQNameTrimmed);
        }
      } else {
        Xpp3Dom modulesNode = gwtConfig.getChild("modules");
        if (modulesNode != null) {
          moduleNodes = modulesNode.getChildren("module");
          for (Xpp3Dom mNode : moduleNodes) {
            String moduleQNameTrimmed = mNode.getValue().trim();
            modNames.add(moduleQNameTrimmed);
          }
        }
      }
    }
    if (modNames.size() == 0) {
      IModule[] modules = ModuleUtils.findAllModules(javaProject, false);
      modNames = new ArrayList<String>();
      for (IModule iModule : modules) {
        modNames.add(iModule.getQualifiedName());
        log.debug("\t{}", iModule.getQualifiedName());
      }
    }
    return modNames;
  }
  public void refreshSiblingProject(IMavenProjectFacade projectFacade, IProgressMonitor monitor)
      throws CoreException {
    // need to look up project configuration and refresh the *-service project associated with this
    // project
    try {
      // not doing any null checks since this is in large try/catch
      final Plugin liferayMavenPlugin = MavenUtil.getLiferayMavenPlugin(projectFacade, monitor);
      final Xpp3Dom config = (Xpp3Dom) liferayMavenPlugin.getConfiguration();
      final Xpp3Dom apiBaseDir = config.getChild(ILiferayMavenConstants.PLUGIN_CONFIG_API_BASE_DIR);
      // this should be the name path of a project that should be in user's workspace that we can
      // refresh
      final String apiBaseDirValue = apiBaseDir.getValue();

      final IFile apiBasePomFile =
          ResourcesPlugin.getWorkspace()
              .getRoot()
              .getFileForLocation(new Path(apiBaseDirValue).append(IMavenConstants.POM_FILE_NAME));
      final IMavenProjectFacade apiBaseFacade =
          this.projectManager.create(apiBasePomFile, true, monitor);

      apiBaseFacade.getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (Exception e) {
      LiferayMavenCore.logError("Could not refresh sibling service project.", e); // $NON-NLS-1$
    }
  }
 public boolean isAddManifestClasspath() {
   Xpp3Dom config = getConfiguration();
   if (config != null) {
     Xpp3Dom arch = config.getChild("archive");
     if (arch != null) {
       Xpp3Dom manifest = arch.getChild("manifest");
       if (manifest != null) {
         Xpp3Dom addToClp = manifest.getChild("addClasspath");
         if (addToClp != null) {
           return Boolean.valueOf(addToClp.getValue());
         }
       }
     }
   }
   return false;
 }
 private void setDisableP2Mirrors(TargetPlatformConfiguration result, Xpp3Dom configuration) {
   Xpp3Dom disableP2mirrorsDom = configuration.getChild("disableP2Mirrors");
   if (disableP2mirrorsDom != null) {
     logger.warn(
         "Unsupported target-platform-configuration <disableP2Mirrors>. Use tycho.disableP2Mirrors -D command line parameter or settings.xml property.");
   }
 }
 public Launcher getLauncher() {
   Xpp3Dom domLauncher = dom.getChild("launcher");
   if (domLauncher == null) {
     return null;
   }
   return new Launcher(domLauncher);
 }
  public void testCompleteWiring() throws Exception {
    ModelBuilder builder = new DefaultModelBuilderFactory().newInstance();
    assertNotNull(builder);

    DefaultModelBuildingRequest request = new DefaultModelBuildingRequest();
    request.setProcessPlugins(true);
    request.setPomFile(getPom("simple"));

    ModelBuildingResult result = builder.build(request);
    assertNotNull(result);
    assertNotNull(result.getEffectiveModel());
    assertEquals("activated", result.getEffectiveModel().getProperties().get("profile.file"));
    Xpp3Dom conf =
        (Xpp3Dom) result.getEffectiveModel().getBuild().getPlugins().get(0).getConfiguration();
    assertEquals("1.5", conf.getChild("source").getValue());
    assertEquals("  1.5  ", conf.getChild("target").getValue());
  }
  private void setPomDependencies(TargetPlatformConfiguration result, Xpp3Dom configuration) {
    String value = getStringValue(configuration.getChild("pomDependencies"));

    if (value == null) {
      return;
    }
    result.setPomDependencies(value);
  }
  private void setAllowConflictingDependencies(
      TargetPlatformConfiguration result, Xpp3Dom configuration) {
    String value = getStringValue(configuration.getChild("allowConflictingDependencies"));

    if (value == null) {
      return;
    }
    result.setAllowConflictingDependencies(Boolean.parseBoolean(value));
  }
 protected TargetEnvironment getDeprecatedTargetEnvironment(Xpp3Dom configuration) {
   Xpp3Dom environmentDom = configuration.getChild("environment");
   if (environmentDom != null) {
     logger.warn(
         "target-platform-configuration <environment> element is deprecated; use <environments> instead");
     return newTargetEnvironment(environmentDom);
   }
   return null;
 }
  private void setTargetPlatformResolver(
      TargetPlatformConfiguration result, Xpp3Dom configuration) {
    String value = getStringValue(configuration.getChild("resolver"));

    if (value == null) {
      return;
    }
    result.setResolver(value);
  }
  private static TargetEnvironment newTargetEnvironment(Xpp3Dom environmentDom) {
    Xpp3Dom osDom = environmentDom.getChild("os");
    if (osDom == null) {
      return null;
    }

    Xpp3Dom wsDom = environmentDom.getChild("ws");
    if (wsDom == null) {
      return null;
    }

    Xpp3Dom archDom = environmentDom.getChild("arch");
    if (archDom == null) {
      return null;
    }

    return new TargetEnvironment(osDom.getValue(), wsDom.getValue(), archDom.getValue());
  }
 private void applyPOMWebAppConfig(
     final Xpp3Dom configuration, final JettyWebAppContext webAppConfig)
     throws BeanConfigurationException {
   BeanConfigurationRequest beanConfigurationRequest = new DefaultBeanConfigurationRequest();
   beanConfigurationRequest
       .setBean(webAppConfig)
       .setConfiguration(configuration.getChild("webAppConfig"));
   beanConfigurator.configureBean(beanConfigurationRequest);
 }
  private void setIncludePackedArtifacts(
      TargetPlatformConfiguration result, Xpp3Dom configuration) {
    String value = getStringValue(configuration.getChild("includePackedArtifacts"));

    if (value == null) {
      return;
    }
    result.setIncludePackedArtifacts(Boolean.parseBoolean(value));
  }
 public Xpp3Dom[] getWebResources() {
   Xpp3Dom config = getConfiguration();
   if (config != null) {
     Xpp3Dom webResources = config.getChild("webResources");
     if (webResources != null && webResources.getChildCount() > 0) {
       return webResources.getChildren();
     }
   }
   return null;
 }
 public String[] getPackagingIncludes() {
   Xpp3Dom config = getConfiguration();
   if (config != null) {
     Xpp3Dom incl = config.getChild("packagingIncludes");
     if (incl != null && incl.getValue() != null) {
       return StringUtils.tokenizeToStringArray(incl.getValue(), ",");
     }
   }
   return new String[0];
 }
  private void readExtraRequirements(TargetPlatformConfiguration result, Xpp3Dom configuration) {
    Xpp3Dom resolverDom = getDependencyResolutionDom(configuration);
    if (resolverDom == null) {
      return;
    }

    Xpp3Dom requirementsDom = resolverDom.getChild("extraRequirements");
    if (requirementsDom == null) {
      return;
    }

    for (Xpp3Dom requirementDom : requirementsDom.getChildren("requirement")) {
      Dependency d = new Dependency();
      d.setType(requirementDom.getChild("type").getValue());
      d.setArtifactId(requirementDom.getChild("id").getValue());
      d.setVersion(requirementDom.getChild("versionRange").getValue());
      result.addExtraRequirement(d);
    }
  }
 private void configureAdditionalBundles(Xpp3Dom configuration) {
   Xpp3Dom additionalBundlesConfig = configuration.getChild("additionalBundles");
   if (additionalBundlesConfig != null) {
     Xpp3Dom[] bundleConfigs = additionalBundlesConfig.getChildren("bundle");
     if (bundleConfigs != null) {
       for (Xpp3Dom bundleConfig : bundleConfigs) {
         additionalBundles.add(new ArtifactDefinition(bundleConfig));
       }
     }
   }
 }
 public String getManifestClasspathPrefix() {
   Xpp3Dom config = getConfiguration();
   if (config != null) {
     Xpp3Dom arch = config.getChild("archive");
     if (arch != null) {
       Xpp3Dom manifest = arch.getChild("manifest");
       if (manifest != null) {
         Xpp3Dom prefix = manifest.getChild("classpathPrefix");
         if (prefix != null && !StringUtils.nullOrEmpty(prefix.getValue())) {
           String rawPrefix = prefix.getValue().trim();
           if (!rawPrefix.endsWith("/")) {
             rawPrefix += "/";
           }
           return rawPrefix;
         }
       }
     }
   }
   return null;
 }
 /**
  * Get the custom location of web.xml, as set in &lt;webXml&gt;.
  *
  * @return the custom location of web.xml or null if &lt;webXml&gt; is not set
  */
 public String getCustomWebXml(IProject project) {
   Xpp3Dom config = getConfiguration();
   if (config != null) {
     Xpp3Dom webXmlDom = config.getChild("webXml");
     if (webXmlDom != null && webXmlDom.getValue() != null) {
       String webXmlFile = webXmlDom.getValue().trim();
       webXmlFile = ProjectUtils.getRelativePath(project, webXmlFile);
       return webXmlFile;
     }
   }
   return null;
 }
  public List<FeatureRef> getFeatures() {
    Xpp3Dom featuresDom = dom.getChild("features");
    if (featuresDom == null) {
      return Collections.emptyList();
    }

    ArrayList<FeatureRef> features = new ArrayList<FeatureRef>();
    for (Xpp3Dom pluginDom : featuresDom.getChildren("feature")) {
      features.add(new FeatureRef(pluginDom));
    }
    return Collections.unmodifiableList(features);
  }
  public List<PluginRef> getPlugins() {
    Xpp3Dom pluginsDom = dom.getChild("plugins");
    if (pluginsDom == null) {
      return Collections.emptyList();
    }

    ArrayList<PluginRef> plugins = new ArrayList<PluginRef>();
    for (Xpp3Dom pluginDom : pluginsDom.getChildren("plugin")) {
      plugins.add(new PluginRef(pluginDom));
    }
    return Collections.unmodifiableList(plugins);
  }
  private void setTarget(
      TargetPlatformConfiguration result,
      MavenSession session,
      MavenProject project,
      Xpp3Dom configuration) {
    Xpp3Dom targetDom = configuration.getChild("target");
    if (targetDom == null) {
      return;
    }

    Xpp3Dom artifactDom = targetDom.getChild("artifact");
    if (artifactDom == null) {
      return;
    }

    Xpp3Dom groupIdDom = artifactDom.getChild("groupId");
    Xpp3Dom artifactIdDom = artifactDom.getChild("artifactId");
    Xpp3Dom versionDom = artifactDom.getChild("version");
    if (groupIdDom == null || artifactIdDom == null || versionDom == null) {
      return;
    }
    Xpp3Dom classifierDom = artifactDom.getChild("classifier");

    String groupId = groupIdDom.getValue();
    String artifactId = artifactIdDom.getValue();
    String version = versionDom.getValue();
    String classifier = classifierDom != null ? classifierDom.getValue() : null;

    File targetFile = null;
    for (MavenProject otherProject : session.getProjects()) {
      if (groupId.equals(otherProject.getGroupId())
          && artifactId.equals(otherProject.getArtifactId())
          && version.equals(otherProject.getVersion())) {
        targetFile = new File(otherProject.getBasedir(), classifier + ".target");
        break;
      }
    }

    if (targetFile == null) {
      Artifact artifact =
          repositorySystem.createArtifactWithClassifier(
              groupId, artifactId, version, "target", classifier);
      ArtifactResolutionRequest request = new ArtifactResolutionRequest();
      request.setArtifact(artifact);
      request.setLocalRepository(session.getLocalRepository());
      request.setRemoteRepositories(project.getRemoteArtifactRepositories());
      repositorySystem.resolve(request);

      if (!artifact.isResolved()) {
        throw new RuntimeException(
            "Could not resolve target platform specification artifact " + artifact);
      }

      targetFile = artifact.getFile();
    }

    result.setTarget(targetFile);
  }
 public boolean isExcludeAll() {
   if (excludeAll == null) {
     if (configuration != null) {
       Xpp3Dom excludeAllDom = configuration.getChild("excludeAll");
       if (excludeAllDom != null) {
         excludeAll = Boolean.valueOf(excludeAllDom.getValue());
       }
     }
     if (excludeAll == null) {
       excludeAll = Boolean.FALSE;
     }
   }
   return excludeAll.booleanValue();
 }
 public boolean isRemoveDependencyVersions() {
   if (removeDependencyVersions == null) {
     if (configuration != null) {
       Xpp3Dom removeVersionDom = configuration.getChild("removeDependencyVersions");
       if (removeVersionDom != null) {
         removeDependencyVersions = Boolean.valueOf(removeVersionDom.getValue());
       }
     }
     if (removeDependencyVersions == null) {
       removeDependencyVersions = Boolean.FALSE;
     }
   }
   return removeDependencyVersions.booleanValue();
 }
 public String getLibDirectory() {
   if (libDirectory == null) {
     if (configuration != null) {
       Xpp3Dom libDom = configuration.getChild("libDirectory");
       if (libDom != null) {
         libDirectory = libDom.getValue();
       }
     }
     if (StringUtils.isEmpty(libDirectory)) {
       libDirectory = DEFAULT_LIB_DIRECTORY;
     }
   }
   return libDirectory;
 }