protected Map<String, String> initialValue() {
   Map<String, String> map = new HashMap<String, String>();
   ClasspathResourceMap resources =
       scanner
           .matchResource(".*[.]gwt[.]*xml")
           .scan(Thread.currentThread().getContextClassLoader());
   for (StringDataResource resource : resources.findResources("", GWT_XML_PATTERN)) {
     try {
       Xpp3Dom dom = Xpp3DomBuilder.build(resource.open(), "UTF-8");
       String rename = dom.getAttribute("rename-to");
       if (rename != null) {
         String resName = resource.getResourceName().replace('/', '.');
         resName = resName.substring(0, resName.lastIndexOf("gwt") - 1);
         map.put(rename, resName);
         X_Log.trace("Found gwt module rename; ", rename, " -> ", resName);
       }
     } catch (Exception e) {
       X_Log.error(
           "Error reading xml from ",
           resource.getResourceName(),
           e,
           "\nSet xapi.log.level=TRACE to see the faulty xml");
       X_Log.trace("Faulty xml: ", resource.readAll());
     }
   }
   ;
   return map;
 };
Beispiel #2
0
 public static void parsePluginXml(
     InputStream is, List<String> configurators, List<String> mappingStrategies)
     throws XmlPullParserException, IOException {
   Xpp3Dom plugin = Xpp3DomBuilder.build(is, "UTF-8"); // $NON-NLS-1$
   Xpp3Dom[] extensions = plugin.getChildren("extension"); // $NON-NLS-1$
   for (Xpp3Dom extension : extensions) {
     String extensionPoint = extension.getAttribute("point"); // $NON-NLS-1$
     if (LifecycleMappingFactory.EXTENSION_PROJECT_CONFIGURATORS.equals(extensionPoint)) {
       Xpp3Dom[] configuratorsDom = extension.getChildren("configurator"); // $NON-NLS-1$
       for (Xpp3Dom configurator : configuratorsDom) {
         String id = configurator.getAttribute("id"); // $NON-NLS-1$
         if (id != null) {
           configurators.add(id);
         }
       }
     } else if (LifecycleMappingFactory.EXTENSION_LIFECYCLE_MAPPINGS.equals(extensionPoint)) {
       Xpp3Dom[] lifecycleMappingsDom = extension.getChildren("lifecycleMapping"); // $NON-NLS-1$
       for (Xpp3Dom lifecycleMapping : lifecycleMappingsDom) {
         String id = lifecycleMapping.getAttribute("id"); // $NON-NLS-1$
         if (id != null) {
           mappingStrategies.add(id);
         }
       }
     }
   }
 }
  private void fixRemoteUrl(ResourceStoreRequest request) {
    if (overwriteRemoteUrl != null) {
      return;
    }

    if (P2Constants.SITE_XML.equals(request.getRequestPath())) {
      return;
    }

    try {
      RepositoryItemUid siteUID = createUid(P2Constants.SITE_XML);
      ResourceStoreRequest siteRequest = new ResourceStoreRequest(siteUID.getPath());
      StorageFileItem siteItem;
      try {
        siteItem = (StorageFileItem) getLocalStorage().retrieveItem(this, siteRequest);
      } catch (ItemNotFoundException e) {
        siteItem =
            (StorageFileItem) getRemoteStorage().retrieveItem(this, siteRequest, getRemoteUrl());
      }

      PlexusConfiguration plexusConfig =
          new XmlPlexusConfiguration(
              Xpp3DomBuilder.build(new InputStreamReader(siteItem.getInputStream())));

      this.overwriteRemoteUrl = plexusConfig.getAttribute("url");
      getLogger()
          .info("Remote update site does overwrite the remote url " + this.overwriteRemoteUrl);
    } catch (Exception e) {
      getLogger().debug(e.getMessage(), e);
      this.overwriteRemoteUrl = "";
    }
  }
  private void convertToKazuki(final File configFile) throws Exception {
    try (Reader r = new FileReader(configFile);
        FileInputStream is = new FileInputStream(configFile);
        Reader fr = new InputStreamReader(is)) {

      Xpp3DomBuilder.build(r);
      Configuration configuration = new NexusCapabilitiesConfigurationXpp3Reader().read(fr);
      List<CCapability> capabilities = configuration.getCapabilities();

      if (capabilities != null) {
        for (final CCapability c : capabilities) {

          // NEXUS-6349: do not convert outreach related capabilities and let outreach plugin
          // recreate them
          if ("OutreachMarkerCapability".equals(c.getTypeId())
              || "OutreachManagementCapability".equals(c.getTypeId())) {
            continue;
          }

          Map<String, String> properties = Maps.newHashMap();
          if (c.getProperties() != null) {
            for (final CCapabilityProperty property : c.getProperties()) {
              properties.put(property.getKey(), property.getValue());
            }
          }

          capabilityStorage.add(
              new CapabilityStorageItem(
                  c.getVersion(), c.getTypeId(), c.isEnabled(), c.getNotes(), properties));
        }
        log.info("Converted {} capabilities from capabilities.xml to Kazuki", capabilities.size());
      }
    }
  }
 @SuppressWarnings("deprecation")
 public static ProductConfiguration read(File file) throws IOException, XmlPullParserException {
   XmlStreamReader reader = ReaderFactory.newXmlReader(file);
   try {
     return new ProductConfiguration(Xpp3DomBuilder.build(reader));
   } finally {
     reader.close();
   }
 }
  @Override
  public boolean install() {
    if (!this.isInstalled()) {
      for (DirectoryResource folder : this.getSourceFolders()) {
        folder.mkdirs();
      }

      // FIXME WOW this needs to be simplified somehow...
      MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
      Model pom = maven.getPOM();
      Build build = pom.getBuild();
      if (build == null) {
        build = new Build();
      }
      List<Plugin> plugins = build.getPlugins();
      Plugin javaSourcePlugin = null;
      for (Plugin plugin : plugins) {
        if ("org.apache.maven.plugins".equals(plugin.getGroupId())
            && "maven-compiler-plugin".equals(plugin.getArtifactId())) {
          javaSourcePlugin = plugin;
        }
      }

      if (javaSourcePlugin == null) {
        javaSourcePlugin = new Plugin();
        // FIXME this should find the most recent version using DependencyResolver
        javaSourcePlugin.setGroupId("org.apache.maven.plugins");
        javaSourcePlugin.setArtifactId("maven-compiler-plugin");
        javaSourcePlugin.setVersion("2.3.2");

        try {
          Xpp3Dom dom =
              Xpp3DomBuilder.build(
                  new ByteArrayInputStream(
                      "<configuration><source>1.6</source><target>1.6</target></configuration>"
                          .getBytes()),
                  "UTF-8");

          javaSourcePlugin.setConfiguration(dom);
        } catch (Exception e) {
          throw new ProjectModelException(e);
        }
      }

      build.addPlugin(javaSourcePlugin);
      pom.setBuild(build);
      maven.setPOM(pom);
    }
    return true;
  }
  @Test
  public void checkMetadataOnRepository() throws Exception {
    TestContainer.getInstance().getTestContext().setUsername(TEST_USER_NAME);
    TestContainer.getInstance().getTestContext().setPassword(TEST_USER_PASSWORD);

    File file =
        downloadFile(
            new URL(
                nexusBaseUrl
                    + REPOSITORY_RELATIVE_URL
                    + REPO_TEST_HARNESS_REPO
                    + "/nexus1560/artifact/maven-metadata.xml"),
            "./target/downloads/nexus1560/repo-maven-metadata.xml");
    Xpp3Dom dom = Xpp3DomBuilder.build(new FileReader(file));
    Xpp3Dom[] versions = dom.getChild("versioning").getChild("versions").getChildren("version");
    for (Xpp3Dom version : versions) {
      Assert.assertEquals(
          version.getValue(), "1.0", "Invalid version available on metadata" + dom.toString());
    }
  }
  private void loadDefaultProfileName(URL url) throws MojoExecutionException {
    Reader reader = null;
    try {
      reader = new InputStreamReader(url.openStream());
      Xpp3Dom dom = Xpp3DomBuilder.build(reader);

      Xpp3Dom[] existingProfiles = dom.getChildren(ELT_PROFILE);
      if (existingProfiles.length != 0) {
        Xpp3Dom firstProfile = existingProfiles[0];
        this.profileName = firstProfile.getAttribute("name");
      }
    } catch (XmlPullParserException e) {
      throw new MojoExecutionException(
          Messages.getString("EclipsePlugin.cantparseexisting", url.toString())); // $NON-NLS-1$
    } catch (IOException e) {
      throw new MojoExecutionException(
          Messages.getString("EclipsePlugin.cantparseexisting", url.toString())); // $NON-NLS-1$
    } finally {
      IOUtil.close(reader);
    }
  }
  /**
   * Remove from the dominant plugin all the properties that are identical in the recessive plugin
   * If a property exist in the recessive plugin but not in dominant, it will be ignored
   * <b>Important: the artifactId and groupId properties are not affected</b>
   */
  private MavenPluginAdapter diff(final MavenPlugin dominant, final MavenPlugin recessive) {
    MavenPluginAdapter merged = new MavenPluginAdapter(dominant);
    if (Dependencies.areEquivalent(dominant.getCoordinate(), recessive.getCoordinate())) {
      // Version
      if (Strings.compare(
          dominant.getCoordinate().getVersion(), recessive.getCoordinate().getVersion())) {
        // Remove version as dominant and recessive have the same one
        merged.setVersion(null);
      }

      // Extension
      if (dominant.isExtensionsEnabled() == recessive.isExtensionsEnabled()) {
        // Remove extension as dominant and recessive have the same one
        merged.setExtensions(null);
      }
      // Config
      Map<String, String> cfgElmtsRefMap = new HashMap<>();
      Configuration mergedConfiguration = merged.getConfig();
      if (dominant.getConfig() != null && recessive.getConfig() != null) {
        for (ConfigurationElement e : dominant.getConfig().listConfigurationElements()) {
          // FIXME: recursively do a diff of childrens, if any
          cfgElmtsRefMap.put(e.getName(), e.toString());
        }
        for (ConfigurationElement e : recessive.getConfig().listConfigurationElements()) {
          if (cfgElmtsRefMap.containsKey(e.getName())) {
            if (Strings.compare(cfgElmtsRefMap.get(e.getName()), e.toString())) {
              // Remove the configuration element as dominant and recessive have the same element
              mergedConfiguration.removeConfigurationElement(e.getName());
            }
          }
        }
      }
      merged.setConfig(mergedConfiguration);
      // Executions
      Map<String, PluginExecution> dominantExec =
          new MavenPluginAdapter(dominant).getExecutionsAsMap();
      Map<String, PluginExecution> recessiveExec =
          new MavenPluginAdapter(recessive).getExecutionsAsMap();
      Map<String, PluginExecution> mergedExec = merged.getExecutionsAsMap();
      if (dominantExec != null && recessiveExec != null) {
        for (Map.Entry<String, PluginExecution> entry : recessiveExec.entrySet()) {
          PluginExecution pluginExecutionRecessive = entry.getValue();
          PluginExecution pluginExecutionDominant = dominantExec.get(entry.getKey());
          if (pluginExecutionRecessive != null && pluginExecutionDominant != null) {
            PluginExecution pluginExecutionMerged = mergedExec.get(entry.getKey());
            // Phase
            if (Strings.compare(
                pluginExecutionRecessive.getPhase(), pluginExecutionDominant.getPhase())) {
              // Remove the phase as dominant and recessive are identical
              pluginExecutionMerged.setPhase(null);
            }
            // Goals
            Map<String, Boolean> hasGoals = new HashMap<>();
            for (String goal : pluginExecutionRecessive.getGoals()) {
              hasGoals.put(goal, new Boolean(true));
            }
            for (String goal : pluginExecutionDominant.getGoals()) {
              if (hasGoals.get(goal)) {
                // Remove the goal as dominant and recessive have the same goal
                pluginExecutionMerged.removeGoal(goal);
              }
            }
            // Configurations
            Map<String, String> cfgExecElmtsRefMap = new HashMap<>();
            if (pluginExecutionRecessive.getConfiguration() != null
                && pluginExecutionDominant.getConfiguration() != null) {
              Configuration pluginExecutionRecessiveCfg =
                  new ConfigurationImpl((Xpp3Dom) pluginExecutionRecessive.getConfiguration());
              Configuration pluginExecutionDominantCfg =
                  new ConfigurationImpl((Xpp3Dom) pluginExecutionDominant.getConfiguration());
              Configuration pluginExecutionMergedCfg =
                  new ConfigurationImpl((Xpp3Dom) pluginExecutionMerged.getConfiguration());

              for (ConfigurationElement e :
                  pluginExecutionDominantCfg.listConfigurationElements()) {
                // FIXME: recursively do a diff of childrens, if any
                cfgExecElmtsRefMap.put(e.getName(), e.toString());
              }
              for (ConfigurationElement e :
                  pluginExecutionRecessiveCfg.listConfigurationElements()) {
                if (cfgExecElmtsRefMap.containsKey(e.getName())) {
                  if (Strings.compare(cfgExecElmtsRefMap.get(e.getName()), e.toString())) {
                    // Remove the execution configuration element as dominant and recessive have the
                    // same
                    // element
                    pluginExecutionMergedCfg.removeConfigurationElement(e.getName());
                  }
                }
              }
              if (!pluginExecutionMergedCfg.hasConfigurationElements()) {
                pluginExecutionMerged.setConfiguration(null);
              }
              try {
                pluginExecutionMerged.setConfiguration(
                    Xpp3DomBuilder.build(
                        new ByteArrayInputStream(pluginExecutionMergedCfg.toString().getBytes()),
                        "UTF-8"));
              } catch (Exception ex) {
                throw new RuntimeException("Exception while parsing configuration", ex);
              }
            }
          }
        }
      }
    }
    return merged;
  }
Beispiel #10
0
 public static PlexusConfiguration buildConfiguration(Reader configuration) throws Exception {
   return new XmlPlexusConfiguration(Xpp3DomBuilder.build(configuration));
 }