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 List<String> getPackages(
     List<String> exportedPackagesList, MavenProject mavenProject, String packagetype)
     throws CoreException, JavaModelException, Exception {
   List<Plugin> plugins = mavenProject.getBuild().getPlugins();
   for (Plugin plugin : plugins) {
     if ("maven-bundle-plugin".equalsIgnoreCase(plugin.getArtifactId())) {
       Xpp3Dom configurationNode = (Xpp3Dom) plugin.getConfiguration();
       Xpp3Dom[] instructions = configurationNode.getChildren("instructions");
       if (instructions.length == 1) {
         Xpp3Dom[] exportPackage = instructions[0].getChildren(packagetype);
         if (exportPackage.length == 1) {
           exportedPackagesList.clear(); // clear default configuration (All packages by default)
           String exportpackages = exportPackage[0].getValue();
           if (exportpackages != null) {
             exportedPackagesList.addAll(Arrays.asList(exportpackages.split(",")));
           }
         } else {
           log.warn(
               "Invalid configuration for <Export-Package> entry"
                   + " using default configuration for <Export-Package>");
         }
       } else {
         log.warn(
             "Invalid instructions configuration for plugin : maven-bundle-plugin"
                 + " using default configuration for <Export-Package>");
       }
       break; // not considering multiple versions of the maven-bundle-plugin
     }
   }
   return exportedPackagesList;
 }
  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 JBossPackagingPluginConfiguration(MavenProject mavenProject) {
   this.mavenProject = mavenProject;
   Plugin plugin = mavenProject.getPlugin("org.codehaus.mojo:jboss-packaging-maven-plugin");
   if (plugin != null) {
     configuration = (Xpp3Dom) plugin.getConfiguration();
   }
 }
Пример #5
0
 protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) {
   Plugin plugin =
       MavenUtils.createPluginEntry(
           artifactMavenProject, "org.wso2.maven", "maven-car-plugin", "1.0-SNAPSHOT", true);
   Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
   // add configuration
   Xpp3Dom aritfact = MavenUtils.createConfigurationNode(configuration, "archiveLocation");
   aritfact.setValue(archiveLocation);
 }
  protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) {
    Plugin pluginAxis2 =
        CAppMavenUtils.createPluginEntry(
            artifactMavenProject,
            "org.wso2.maven",
            "maven-bpel-plugin",
            WSO2MavenPluginConstantants.MAVEN_BPEL_PLUGIN_VERSION,
            true);
    PluginExecution executionAxis2 = new PluginExecution();
    executionAxis2.setId("package-bpel");
    executionAxis2.setPhase("package");
    List goalsAxis2 = new ArrayList<String>();
    goalsAxis2.add("package-bpel");
    executionAxis2.setGoals(goalsAxis2);
    pluginAxis2.addExecution(executionAxis2);

    Xpp3Dom config = (Xpp3Dom) pluginAxis2.getConfiguration();
    Xpp3Dom artifactItems = CAppMavenUtils.createConfigurationNode(config, "artifact");
    //		String relativePath =
    //		                      org.wso2.carbonstudio.eclipse.utils.file.FileUtils.getRelativePath(new
    // File(
    //
    //      artifact.getFile()
    //
    //              .getParentFile()
    //
    //              .getParentFile()
    //
    //              .getParentFile()
    //
    //              .getParentFile()
    //
    //              .getParentFile()
    //
    //              .getPath() +
    //
    //              File.separator +
    //
    //              "target" +
    //
    //              File.separator +
    //
    //              "capp" +
    //
    //              File.separator +
    //
    //              "artifacts" +
    //
    //              File.separator +
    //
    //              artifactMavenProject.getArtifactId()),
    //
    // artifact.getFile());
    String relativePath = artifact.getFile().getName();
    artifactItems.setValue(relativePath);
  }
 protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) {
   Plugin plugin =
       CAppMavenUtils.createPluginEntry(
           artifactMavenProject,
           "org.wso2.maven",
           "wso2-esb-messagestore-plugin",
           WSO2MavenPluginConstantants.WSO2_ESB_MESSAGE_STORE_PLUGIN_VERSION,
           true);
   Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
   // add configuration
   Xpp3Dom aritfact = CAppMavenUtils.createConfigurationNode(configuration, "artifact");
   aritfact.setValue(artifact.getFile().getName());
 }
 protected void addPlugins(MavenProject artifactMavenProject, Artifact artifact) {
   Plugin plugin =
       CAppMavenUtils.createPluginEntry(
           artifactMavenProject,
           "org.wso2.maven",
           "maven-proxy-plugin",
           WSO2MavenPluginConstantants.MAVEN_PROXY_PLUGIN_VERSION,
           true);
   Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
   // add configuration
   Xpp3Dom aritfact = CAppMavenUtils.createConfigurationNode(configuration, "artifact");
   aritfact.setValue(artifact.getFile().getName());
 }
    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 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 List<MavenProblemInfo> findLiferayMavenPluginProblems(
      IProject project, MavenProject mavenProject) {
    final List<MavenProblemInfo> errors = new ArrayList<MavenProblemInfo>();

    // first check to make sure that the AppServer* properties are available and pointed to valid
    // location
    final Plugin liferayMavenPlugin = LiferayMavenUtil.getLiferayMavenPlugin(mavenProject);

    if (liferayMavenPlugin != null) {
      final Xpp3Dom config = (Xpp3Dom) liferayMavenPlugin.getConfiguration();

      final MavenProblemInfo valueProblemInfo =
          checkValidLiferayVersion(liferayMavenPlugin, config);

      if (valueProblemInfo != null) {
        errors.add(valueProblemInfo);
      }

      final String[] configDirParams =
          new String[] {
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_AUTO_DEPLOY_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_CLASSES_PORTAL_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_DEPLOY_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_LIB_GLOBAL_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_LIB_PORTAL_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_PORTAL_DIR,
            ILiferayMavenConstants.PLUGIN_CONFIG_APP_SERVER_TLD_PORTAL_DIR,
          };

      for (final String configParam : configDirParams) {
        final MavenProblemInfo configProblemInfo =
            checkValidConfigDir(liferayMavenPlugin, config, configParam);

        if (configProblemInfo != null) {
          errors.add(configProblemInfo);
        }
      }
    }

    return errors;
  }
 /**
  * Create plugin descriptors for the given plugins.
  *
  * @param plugins The plugins.
  * @param context The scanner context.
  * @return The plugin descriptors.
  */
 private List<MavenPluginDescriptor> createMavenPluginDescriptors(
     List<Plugin> plugins, ScannerContext context) {
   Store store = context.getStore();
   List<MavenPluginDescriptor> pluginDescriptors = new ArrayList<>();
   for (Plugin plugin : plugins) {
     MavenPluginDescriptor mavenPluginDescriptor = store.create(MavenPluginDescriptor.class);
     MavenArtifactDescriptor artifactDescriptor =
         getArtifactResolver(context).resolve(new PluginCoordinates(plugin), context);
     mavenPluginDescriptor.setArtifact(artifactDescriptor);
     mavenPluginDescriptor.setInherited(plugin.isInherited());
     addDependencies(
         mavenPluginDescriptor,
         plugin.getDependencies(),
         PluginDependsOnDescriptor.class,
         context);
     addPluginExecutions(mavenPluginDescriptor, plugin, store);
     addConfiguration(mavenPluginDescriptor, (Xpp3Dom) plugin.getConfiguration(), store);
     pluginDescriptors.add(mavenPluginDescriptor);
   }
   return pluginDescriptors;
 }
 /** @return war plugin configuration or null. */
 private Xpp3Dom getConfiguration() {
   if (plugin == null) {
     return null;
   }
   return (Xpp3Dom) plugin.getConfiguration();
 }
  public TargetPlatformConfiguration getTargetPlatformConfiguration(
      MavenSession session, MavenProject project) {
    TargetPlatformConfiguration result = new TargetPlatformConfiguration();

    // Use org.eclipse.tycho:target-platform-configuration/configuration/environment, if provided
    Plugin plugin = project.getPlugin("org.eclipse.tycho:target-platform-configuration");

    if (plugin != null) {
      Xpp3Dom configuration = (Xpp3Dom) plugin.getConfiguration();
      if (configuration != null) {
        if (logger.isDebugEnabled()) {
          logger.debug(
              "target-platform-configuration for "
                  + project.toString()
                  + ":\n"
                  + configuration.toString());
        }

        addTargetEnvironments(result, project, configuration);

        setTargetPlatformResolver(result, configuration);

        setTarget(result, session, project, configuration);

        setPomDependencies(result, configuration);

        setAllowConflictingDependencies(result, configuration);

        setDisableP2Mirrors(result, configuration);

        setExecutionEnvironment(result, configuration);

        readFilters(result, configuration);

        readExtraRequirements(result, configuration);

        setOptionalDependencies(result, configuration);

        setIncludePackedArtifacts(result, configuration);
      }
    }

    if (result.getEnvironments().isEmpty()) {
      TychoProject projectType = projectTypes.get(project.getPackaging());
      if (projectType != null) {
        TargetEnvironment env = projectType.getImplicitTargetEnvironment(project);
        if (env != null) {
          if (logger.isDebugEnabled()) {
            logger.debug(
                "Implicit target environment for " + project.toString() + ": " + env.toString());
          }

          result.addEnvironment(env);
        }
      }
    }

    if (result.getEnvironments().isEmpty()) {
      // applying defaults
      logger.warn(
          "No explicit target runtime environment configuration. Build is platform dependent.");

      // Otherwise, use project or execution properties, if provided
      Properties properties =
          (Properties) project.getContextValue(TychoConstants.CTX_MERGED_PROPERTIES);

      // Otherwise, use current system os/ws/nl/arch
      String os = PlatformPropertiesUtils.getOS(properties);
      String ws = PlatformPropertiesUtils.getWS(properties);
      String arch = PlatformPropertiesUtils.getArch(properties);

      result.addEnvironment(new TargetEnvironment(os, ws, arch));

      result.setImplicitTargetEnvironment(true);
    } else {
      result.setImplicitTargetEnvironment(false);
    }

    return result;
  }
 private static void assertPluginEquals(Plugin expected, Plugin actual) {
   assertEquals(expected, actual);
   assertEquals(expected.getVersion(), actual.getVersion());
   assertEquals(expected.getConfiguration(), actual.getConfiguration());
 }
Пример #16
0
  public static void mergePluginDefinitions(
      Plugin child, Plugin parent, boolean handleAsInheritance) {
    if ((child == null) || (parent == null)) {
      // nothing to do.
      return;
    }

    if (parent.isExtensions()) {
      child.setExtensions(true);
    }

    if ((child.getVersion() == null) && (parent.getVersion() != null)) {
      child.setVersion(parent.getVersion());
    }

    Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
    Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();

    childConfiguration = Xpp3Dom.mergeXpp3Dom(childConfiguration, parentConfiguration);

    child.setConfiguration(childConfiguration);

    child.setDependencies(mergeDependencyList(child.getDependencies(), parent.getDependencies()));

    // from here to the end of the method is dealing with merging of the <executions/> section.
    String parentInherited = parent.getInherited();

    boolean parentIsInherited =
        (parentInherited == null) || Boolean.valueOf(parentInherited).booleanValue();

    List parentExecutions = parent.getExecutions();

    if ((parentExecutions != null) && !parentExecutions.isEmpty()) {
      List mergedExecutions = new ArrayList();

      Map assembledExecutions = new TreeMap();

      Map childExecutions = child.getExecutionsAsMap();

      for (Iterator it = parentExecutions.iterator(); it.hasNext(); ) {
        PluginExecution parentExecution = (PluginExecution) it.next();

        String inherited = parentExecution.getInherited();

        boolean parentExecInherited =
            parentIsInherited && ((inherited == null) || Boolean.valueOf(inherited).booleanValue());

        if (!handleAsInheritance || parentExecInherited) {
          PluginExecution assembled = parentExecution;

          PluginExecution childExecution =
              (PluginExecution) childExecutions.get(parentExecution.getId());

          if (childExecution != null) {
            mergePluginExecutionDefinitions(childExecution, parentExecution);

            assembled = childExecution;
          } else if (handleAsInheritance && (parentInherited == null)) {
            parentExecution.unsetInheritanceApplied();
          }

          assembledExecutions.put(assembled.getId(), assembled);
          mergedExecutions.add(assembled);
        }
      }

      for (Iterator it = child.getExecutions().iterator(); it.hasNext(); ) {
        PluginExecution childExecution = (PluginExecution) it.next();

        if (!assembledExecutions.containsKey(childExecution.getId())) {
          mergedExecutions.add(childExecution);
        }
      }

      child.setExecutions(mergedExecutions);

      child.flushExecutionMap();
    }
  }
  public JettyWebAppContext configureWebApplication(MavenProject project, Log log)
      throws Exception {
    JettyWebAppContext webAppConfig = new JettyWebAppContext();

    Plugin plugin = project.getPlugin("com.polopoly.jetty:jetty-maven-plugin");
    Xpp3Dom config = (Xpp3Dom) plugin.getConfiguration();
    applyPOMWebAppConfig(config, webAppConfig);

    if (webAppConfig.getContextPath() == null || webAppConfig.getContextPath().length() < 1) {
      webAppConfig.setContextPath("/" + project.getArtifactId());
    }

    final File baseDir = project.getBasedir();
    final File webAppSourceDirectory = new File(baseDir, "src/main/webapp");
    final File classesDirectory = new File(baseDir, "target/classes");

    Resource webAppSourceDirectoryResource =
        Resource.newResource(webAppSourceDirectory.getCanonicalPath());
    if (webAppConfig.getWar() == null) {
      webAppConfig.setWar(webAppSourceDirectoryResource.toString());
    }

    if (webAppConfig.getBaseResource() == null) {
      webAppConfig.setBaseResource(webAppSourceDirectoryResource);
    }

    webAppConfig.setWebInfClasses(
        new ArrayList<File>() {
          {
            add(classesDirectory);
          }
        });
    addDependencies(project, webAppConfig);

    // if we have not already set web.xml location, need to set one up
    if (webAppConfig.getDescriptor() == null) {
      // Still don't have a web.xml file: try the resourceBase of the webapp, if it is set
      if (webAppConfig.getDescriptor() == null && webAppConfig.getBaseResource() != null) {
        Resource r = webAppConfig.getBaseResource().addPath("WEB-INF/web.xml");
        if (r.exists() && !r.isDirectory()) {
          webAppConfig.setDescriptor(r.toString());
        }
      }

      // Still don't have a web.xml file: finally try the configured static resource directory if
      // there is one
      if (webAppConfig.getDescriptor() == null && (webAppSourceDirectory != null)) {
        File f = new File(new File(webAppSourceDirectory, "WEB-INF"), "web.xml");
        if (f.exists() && f.isFile()) {
          webAppConfig.setDescriptor(f.getCanonicalPath());
        }
      }
    }

    // Turn off some default settings in jetty
    URL overrideWebXMLUrl = this.getClass().getResource("/com/polopoly/web_override.xml");
    if (overrideWebXMLUrl != null) {
      webAppConfig.addOverrideDescriptor(overrideWebXMLUrl.toExternalForm());
    }

    return webAppConfig;
  }