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;
  }
  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 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];
 }
 /**
  * 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 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$
    }
  }
  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());
  }
 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 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;
 }
예제 #9
0
  private void addChildren(final Xpp3Dom xpp3Dom, final ConfigurationElementBuilder builder) {
    builder.setText(xpp3Dom.getValue());
    for (String attributeName : xpp3Dom.getAttributeNames()) {
      String attributeValue = xpp3Dom.getAttribute(attributeName);
      if (attributeValue != null) builder.addAttribute(attributeName, attributeValue);
    }

    for (Xpp3Dom child : xpp3Dom.getChildren()) {
      ConfigurationElementBuilder elementBuilder = builder.addChild(child.getName());
      addChildren(child, elementBuilder);
    }
  }
  /**
   * Returns the string value of the given node, with all "value not set" cases normalized to <code>
   * null</code>.
   */
  private static String getStringValue(Xpp3Dom element) {
    if (element == null) {
      return null;
    }

    String value = element.getValue().trim();
    if ("".equals(value)) {
      return null;
    } else {
      return value;
    }
  }
 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();
 }
예제 #13
0
  public ConfigurationImpl(final Xpp3Dom configXml) {
    this.configuration = configXml;
    if (configuration != null) {

      for (Xpp3Dom xpp3Dom : configuration.getChildren()) {
        ConfigurationElementBuilder builder =
            ConfigurationElementBuilder.create()
                .setName(xpp3Dom.getName())
                .setText(xpp3Dom.getValue());
        addChildren(xpp3Dom, builder);
        configurationElements.add(builder);
      }
    }
  }
 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;
 }
 /**
  * Returns information about child config entries.
  *
  * @param node Current config node.
  * @param store The database.
  * @return Child config information.
  */
 private ValueDescriptor<?> getConfigChildNodes(Xpp3Dom node, Store store) {
   Xpp3Dom[] children = node.getChildren();
   if (children.length == 0) {
     PropertyDescriptor propertyDescriptor = store.create(PropertyDescriptor.class);
     propertyDescriptor.setName(node.getName());
     propertyDescriptor.setValue(node.getValue());
     return propertyDescriptor;
   }
   ArrayValueDescriptor childDescriptor = store.create(ArrayValueDescriptor.class);
   childDescriptor.setName(node.getName());
   for (Xpp3Dom child : children) {
     childDescriptor.getValue().add(getConfigChildNodes(child, store));
   }
   return childDescriptor;
 }
    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"));
            }
          });
    }
 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;
 }
  public List<IResource> exportArtifact(IProject project) throws Exception {
    String projectPath = project.getLocation().toFile().toString();
    List<IResource> exportResources = new ArrayList<IResource>();
    clearTarget(project);
    IFile pomFile = project.getFile("pom.xml");

    if (pomFile.exists()) {
      MavenProject mavenProject = MavenUtils.getMavenProject(pomFile.getLocation().toFile());
      List<Plugin> plugins = mavenProject.getBuild().getPlugins();
      for (Plugin plugin : plugins) {
        if (plugin.getArtifactId().equals("maven-dataservice-plugin")
            && plugin.getGroupId().equals("org.wso2.maven")) {
          Xpp3Dom artifactNode = ((Xpp3Dom) plugin.getConfiguration()).getChild("artifact");
          String dbsFile = artifactNode.getValue();
          String[] pathArray = dbsFile.split("/");
          IFile dbsFileRef =
              project
                  .getFolder("src")
                  .getFolder("main")
                  .getFolder("dataservice")
                  .getFile(pathArray[pathArray.length - 1]);
          if (dbsFileRef.exists()) {
            exportResources.add((IResource) dbsFileRef);
          }
        }
      }
    } else {
      File[] dbsFiles =
          FileUtils.getAllMatchingFiles(
              project.getLocation().toString(), null, DBS_FILE_EXTENSION, new ArrayList<File>());
      for (File dbsFile : dbsFiles) {
        String filePath = dbsFile.toString();
        // excluded any files inside target dir
        if (!filePath
            .substring(projectPath.length())
            .startsWith(File.separator + "target" + File.separator)) {
          IFile dbsFileRef =
              ResourcesPlugin.getWorkspace()
                  .getRoot()
                  .getFileForLocation(Path.fromOSString(dbsFile.getAbsolutePath()));
          exportResources.add((IResource) dbsFileRef);
        }
      }
    }

    return exportResources;
  }
 private boolean hasJarPackagingExecution() {
   if (AbstractUsingBundleListMojo.JAR.equals(project.getPackaging())) {
     return true;
   } else {
     for (PluginExecution execution : plugin.getExecutions()) {
       if (execution.getGoals().contains("prepare-package")) {
         Xpp3Dom executionConfig = (Xpp3Dom) execution.getConfiguration();
         if (executionConfig != null) {
           Xpp3Dom packagingConfig = executionConfig.getChild("packaging");
           if (packagingConfig != null
               && AbstractUsingBundleListMojo.JAR.equals(packagingConfig.getValue())) {
             return true;
           }
         }
       }
     }
     return false;
   }
 }
 private Set<String> getExcludes() {
   if (excludes == null) {
     excludes = new HashSet<String>();
     if (configuration != null) {
       Xpp3Dom excludesDom = configuration.getChild("excludes");
       if (excludesDom != null) {
         for (Xpp3Dom excludeDom : excludesDom.getChildren("exclude")) {
           if (excludeDom != null) {
             String exclude = excludeDom.getValue();
             if (StringUtils.isNotEmpty(exclude)) {
               excludes.add(exclude);
             }
           }
         }
       }
     }
   }
   return excludes;
 }
예제 #21
0
  @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 MavenProblemInfo checkValidLiferayVersion(Plugin liferayMavenPlugin, Xpp3Dom config) {
    MavenProblemInfo retval = null;
    Version liferayVersion = null;
    String liferayVersionValue = null;

    if (config != null) {
      // check for liferayVersion
      final Xpp3Dom liferayVersionNode =
          config.getChild(ILiferayMavenConstants.PLUGIN_CONFIG_LIFERAY_VERSION);

      if (liferayVersionNode != null) {
        liferayVersionValue = liferayVersionNode.getValue();

        // handle the case where user specifies SNAPSHOT version
        liferayVersionValue =
            liferayVersionValue.replaceAll("-SNAPSHOT$", ""); // $NON-NLS-1$ //$NON-NLS-2$

        try {
          liferayVersion = new Version(liferayVersionValue);
        } catch (IllegalArgumentException e) {
          // bad version
        }
      }
    }

    if (liferayVersion == null) {
      // could not get valid liferayVersion
      final SourceLocation location = SourceLocationHelper.findLocation(liferayMavenPlugin, null);
      final String problemMsg =
          NLS.bind(
              Msgs.invalidConfigValue,
              ILiferayMavenConstants.PLUGIN_CONFIG_LIFERAY_VERSION,
              liferayVersionValue);
      retval = new MavenProblemInfo(problemMsg, IMarker.SEVERITY_ERROR, location);
    }

    return retval;
  }
  private MavenProblemInfo checkValidConfigDir(
      Plugin liferayMavenPlugin, Xpp3Dom config, String configParam) {
    MavenProblemInfo retval = null;

    if (configParam != null && config != null) {
      final Xpp3Dom configNode = config.getChild(configParam);

      if (configNode != null) {
        final String value = configNode.getValue();

        if (!new File(value).exists()) {
          SourceLocation location =
              SourceLocationHelper.findLocation(liferayMavenPlugin, configParam);
          retval =
              new MavenProblemInfo(
                  NLS.bind(Msgs.invalidConfigValue, configParam, value),
                  IMarker.SEVERITY_ERROR,
                  location);
        }
      }
    }

    return retval;
  }