コード例 #1
0
  private void parseLifecyclePhaseDefinitions(
      Map<Plugin, Plugin> plugins, String phase, LifecyclePhase goals) {
    List<LifecycleMojo> mojos = goals.getMojos();
    if (mojos != null) {

      for (int i = 0; i < mojos.size(); i++) {
        LifecycleMojo mojo = mojos.get(i);

        GoalSpec gs = parseGoalSpec(mojo.getGoal());

        if (gs == null) {
          logger.warn(
              "Ignored invalid goal specification '"
                  + mojo.getGoal()
                  + "' from lifecycle mapping for phase "
                  + phase);
          continue;
        }

        Plugin plugin = new Plugin();
        plugin.setGroupId(gs.groupId);
        plugin.setArtifactId(gs.artifactId);
        plugin.setVersion(gs.version);

        Plugin existing = plugins.get(plugin);
        if (existing != null) {
          if (existing.getVersion() == null) {
            existing.setVersion(plugin.getVersion());
          }
          plugin = existing;
        } else {
          plugins.put(plugin, plugin);
        }

        PluginExecution execution = new PluginExecution();
        execution.setId(getExecutionId(plugin, gs.goal));
        execution.setPhase(phase);
        execution.setPriority(i - mojos.size());
        execution.getGoals().add(gs.goal);
        execution.setConfiguration(mojo.getConfiguration());

        plugin.setDependencies(mojo.getDependencies());
        plugin.getExecutions().add(execution);
      }
    }
  }
 /**
  * Set the versions of any plugins which match the contents of the list of plugin overrides
  *
  * @param plugins The list of plugins to modify
  * @param pluginVersionOverrides The list of version overrides to apply to the plugins
  */
 private static void applyOverrides(
     List<Plugin> plugins, Map<String, String> pluginVersionOverrides) {
   for (Plugin plugin : plugins) {
     String groupIdArtifactId = plugin.getGroupId() + GAV_SEPERATOR + plugin.getArtifactId();
     if (pluginVersionOverrides.containsKey(groupIdArtifactId)) {
       String overrideVersion = pluginVersionOverrides.get(groupIdArtifactId);
       plugin.setVersion(overrideVersion);
       Log.getLog().debug("Altered plugin: " + groupIdArtifactId + "=" + overrideVersion);
     }
   }
 }
コード例 #3
0
  @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;
  }
コード例 #4
0
  @Command
  public void custom(
      PipeOut out,
      @Option(name = "artifact", required = true) String artifact,
      @Option(name = "group", required = true) String group,
      @Option(name = "version", required = true) String version) {
    final MavenCoreFacet mvnFacet = project.getFacet(MavenCoreFacet.class);

    Model pom = mvnFacet.getPOM();

    org.apache.maven.model.Plugin plugin = new org.apache.maven.model.Plugin();

    plugin.setGroupId(group);
    plugin.setArtifactId(artifact);
    plugin.setVersion(version);

    if (pom.getBuild().getPlugins().contains(plugin)) {
      return;
    }

    pom.getBuild().getPlugins().add(plugin);

    mvnFacet.setPOM(pom);
  }
コード例 #5
0
ファイル: MojoExecutor.java プロジェクト: jhyle/qulice
 /**
  * Find and configure a mojor.
  *
  * @param coords Maven coordinates, e.g. "com.qulice:maven-qulice-plugin:1.0"
  * @param goal Maven plugin goal to execute
  * @param config The configuration to set
  * @throws ValidationException If something is wrong inside
  */
 public void execute(final String coords, final String goal, final Properties config)
     throws ValidationException {
   final Plugin plugin = new Plugin();
   final String[] sectors = StringUtils.split(coords, ':');
   plugin.setGroupId(sectors[0]);
   plugin.setArtifactId(sectors[1]);
   plugin.setVersion(sectors[2]);
   final MojoDescriptor descriptor = this.descriptor(plugin, goal);
   try {
     this.helper.setupPluginRealm(
         descriptor.getPluginDescriptor(),
         this.session,
         Thread.currentThread().getContextClassLoader(),
         new LinkedList<String>(),
         new LinkedList<String>());
   } catch (final PluginResolutionException ex) {
     throw new IllegalStateException("Plugin resolution problem", ex);
   } catch (final PluginContainerException ex) {
     throw new IllegalStateException("Can't setup realm", ex);
   }
   final Xpp3Dom xpp =
       Xpp3Dom.mergeXpp3Dom(
           this.toXppDom(config, "configuration"),
           this.toXppDom(descriptor.getMojoConfiguration()));
   final MojoExecution execution = new MojoExecution(descriptor, xpp);
   final Mojo mojo = this.mojo(execution);
   Logger.info(this, "Calling %s:%s...", coords, goal);
   try {
     mojo.execute();
   } catch (final MojoExecutionException ex) {
     throw new IllegalArgumentException(ex);
   } catch (final MojoFailureException ex) {
     throw new ValidationException(ex);
   }
   this.manager.releaseMojo(mojo, execution);
 }
コード例 #6
0
ファイル: Maven.java プロジェクト: neminovno/intellij-plugins
  public MojoExecution createMojoExecution(Plugin plugin, String goal, MavenProject project)
      throws Exception {
    if (plugin.getVersion() == null) {
      plugin.setVersion(
          plexusContainer
              .lookup(PluginVersionResolver.class)
              .resolve(new DefaultPluginVersionRequest(plugin, session))
              .getVersion());
    }

    MojoDescriptor mojoDescriptor =
        pluginManager.getMojoDescriptor(
            plugin, goal, project.getRemotePluginRepositories(), session.getRepositorySession());
    List<PluginExecution> executions = plugin.getExecutions();
    MojoExecution mojoExecution =
        new MojoExecution(
            mojoDescriptor,
            executions.isEmpty() ? null : executions.get(executions.size() - 1).getId(),
            MojoExecution.Source.CLI);
    plexusContainer
        .lookup(LifecycleExecutionPlanCalculator.class)
        .setupMojoExecution(session, project, mojoExecution);
    return mojoExecution;
  }
コード例 #7
0
  private MavenPlugin install(Project project, final MavenPlugin plugin, boolean managed) {
    MavenPluginFacet plugins = project.getFacet(MavenPluginFacet.class);
    DependencyFacet deps = project.getFacet(DependencyFacet.class);
    Coordinate pluginCoordinates =
        CoordinateBuilder.create()
            .setGroupId(plugin.getCoordinate().getGroupId())
            .setArtifactId(plugin.getCoordinate().getArtifactId());
    MavenPlugin managedPlugin = null;
    if (plugins.hasManagedPlugin(pluginCoordinates)) {
      managedPlugin = plugins.getManagedPlugin(pluginCoordinates);
    }

    MavenPlugin existing = null;
    // existing represents the plugin(management) as it exists currently throughout the entire
    // hierarchy
    if (managed && plugins.hasEffectiveManagedPlugin(pluginCoordinates)) {
      existing = plugins.getEffectiveManagedPlugin(pluginCoordinates);
    } else if (plugins.hasEffectivePlugin(pluginCoordinates)) {
      existing = plugins.getEffectivePlugin(pluginCoordinates);
    }

    MavenPlugin filteredPlugin = plugin;
    // The filtered plugin preserve the hierarchy, by preventing installing properties already
    // defined with the same
    // values
    if (existing != null && preserveHierarchyPrecedence) {
      filteredPlugin = diff(plugin, existing);
    }
    // Preserve direct plugin-management inheritance
    if (!managed && managedPlugin != null) {
      // The plugin section does not exists but a plugin management section in the direct pom does
      filteredPlugin = diff(filteredPlugin, managedPlugin);
    }

    MavenPlugin mergedPlugin = filteredPlugin;
    // merged plugin is a merge with the direct plugin(management)
    if (managed && managedPlugin != null) {
      mergedPlugin = plugins.merge(mergedPlugin, managedPlugin);
    } else if (!managed && plugins.hasPlugin(pluginCoordinates)) {
      mergedPlugin = plugins.merge(mergedPlugin, plugins.getPlugin(pluginCoordinates));
    }

    // Resolve version
    String versionToInstall = plugin.getCoordinate().getVersion();
    if (mergedPlugin.getCoordinate().getVersion() == null) {
      // null version means no version was specified or already defined in the hierarchy
      if (versionToInstall == null) {
        versionToInstall = promptVersion(deps, pluginCoordinates, null).getVersion();
      }
    }

    // Install the plugin
    MavenPluginAdapter pluginToInstall = new MavenPluginAdapter(mergedPlugin);
    pluginToInstall.setVersion(versionToInstall);
    if (!managed) {
      // In case of a direct plugin install
      // We want it's version being managed in the plugin management section
      MavenPluginAdapter mavenManagedPlugin = null;
      if (managedPlugin != null) {
        // A plugin managemement section already exists, update version
        mavenManagedPlugin = new MavenPluginAdapter(managedPlugin);
        mavenManagedPlugin.setVersion(pluginToInstall.getVersion());
      } else {
        // Create a new plugin management, that will handle the minimal configuration: groupId,
        // artifactId and
        // version
        Plugin newManagedPlugin = new Plugin();
        newManagedPlugin.setGroupId(pluginToInstall.getGroupId());
        newManagedPlugin.setArtifactId(pluginToInstall.getArtifactId());
        newManagedPlugin.setVersion(pluginToInstall.getVersion());
        mavenManagedPlugin = new MavenPluginAdapter(newManagedPlugin);
      }

      // Install the plugin management, if needed
      addOrUpdatePlugin(deps, plugins, mavenManagedPlugin, true);
      pluginToInstall.setVersion(null); // handled by the plugin management section
    } else {
      if (existing != null
          && Strings.compare(versionToInstall, existing.getCoordinate().getVersion())) {
        // Same version in the hierarchy, no need to specify the version
        pluginToInstall.setVersion(null);
      }
    }

    return addOrUpdatePlugin(deps, plugins, pluginToInstall, managed);
  }
コード例 #8
0
  @Override
  public Collection<MavenArtifact> resolvePlugin(
      @NotNull MavenPlugin plugin,
      @NotNull List<MavenRemoteRepository> repositories,
      int nativeMavenProjectId,
      boolean transitive)
      throws RemoteException, MavenServerProcessCanceledException {
    try {
      Plugin mavenPlugin = new Plugin();
      mavenPlugin.setGroupId(plugin.getGroupId());
      mavenPlugin.setArtifactId(plugin.getArtifactId());
      mavenPlugin.setVersion(plugin.getVersion());
      MavenProject project = RemoteNativeMavenProjectHolder.findProjectById(nativeMavenProjectId);

      MavenExecutionRequest request =
          createRequest(
              null,
              Collections.<String>emptyList(),
              Collections.<String>emptyList(),
              Collections.<String>emptyList());

      DefaultMaven maven = (DefaultMaven) getComponent(Maven.class);
      RepositorySystemSession repositorySystemSession = maven.newRepositorySession(request);

      if (plugin.getVersion() == null) {
        PluginVersionRequest versionRequest =
            new DefaultPluginVersionRequest(
                mavenPlugin, repositorySystemSession, project.getRemotePluginRepositories());
        mavenPlugin.setVersion(
            getComponent(PluginVersionResolver.class).resolve(versionRequest).getVersion());
      }

      PluginDescriptor result =
          getComponent(MavenPluginManager.class)
              .getPluginDescriptor(
                  mavenPlugin, project.getRemotePluginRepositories(), repositorySystemSession);

      Map<MavenArtifactInfo, MavenArtifact> resolvedArtifacts =
          new THashMap<MavenArtifactInfo, MavenArtifact>();

      Artifact pluginArtifact = result.getPluginArtifact();

      MavenArtifactInfo artifactInfo =
          new MavenArtifactInfo(
              pluginArtifact.getGroupId(),
              pluginArtifact.getArtifactId(),
              pluginArtifact.getVersion(),
              pluginArtifact.getType(),
              null);

      resolveIfNecessary(artifactInfo, repositories, resolvedArtifacts);

      if (transitive) {
        // todo try to use parallel downloading
        for (Artifact each : result.getIntroducedDependencyArtifacts()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
        for (ComponentDependency each : result.getDependencies()) {
          resolveIfNecessary(
              new MavenArtifactInfo(
                  each.getGroupId(), each.getArtifactId(), each.getVersion(), each.getType(), null),
              repositories,
              resolvedArtifacts);
        }
      }

      return new THashSet<MavenArtifact>(resolvedArtifacts.values());
    } catch (Exception e) {
      Maven3ServerGlobals.getLogger().info(e);
      return Collections.emptyList();
    }
  }
コード例 #9
0
ファイル: YangProjectWizard.java プロジェクト: cyqw/yang-ide
  public void updateModel(
      Model model, String yangVersion, List<CodeGeneratorConfig> generators, String yangRoot) {
    // Model model = super.getModel();
    model.setBuild(new Build());
    Plugin plugin = new Plugin();
    plugin.setGroupId("org.opendaylight.yangtools");
    plugin.setArtifactId("yang-maven-plugin");
    plugin.setVersion(yangVersion);

    for (CodeGeneratorConfig genConf : generators) {
      Dependency dependency = new Dependency();
      dependency.setGroupId(genConf.getGroupId());
      dependency.setArtifactId(genConf.getArtifactId());
      dependency.setVersion(genConf.getVersion());
      dependency.setType("jar");
      plugin.addDependency(dependency);
    }

    PluginExecution pluginExecution = new PluginExecution();
    pluginExecution.setId("generate-sources");
    pluginExecution.addGoal("generate-sources");
    Xpp3Dom config = new Xpp3Dom("configuration");

    Xpp3Dom codeGenerators = new Xpp3Dom("codeGenerators");
    for (CodeGeneratorConfig genConf : generators) {
      Xpp3Dom generator = new Xpp3Dom("generator");
      generator.addChild(createSingleParameter("codeGeneratorClass", genConf.getGenClassName()));
      generator.addChild(createSingleParameter("outputBaseDir", genConf.getGenOutputDirectory()));
      codeGenerators.addChild(generator);
    }
    config.addChild(createSingleParameter("yangFilesRootDir", yangRoot));
    config.addChild(codeGenerators);
    config.addChild(createSingleParameter("inspectDependencies", "false"));
    pluginExecution.setConfiguration(config);

    plugin.addExecution(pluginExecution);
    model.getBuild().addPlugin(plugin);
    model.addPluginRepository(
        createRepoParameter(
            "opendaylight-release",
            "http://nexus.opendaylight.org/content/repositories/opendaylight.release/"));
    model.addPluginRepository(
        createRepoParameter(
            "opendaylight-snapshot",
            "http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/"));
    model.addRepository(
        createRepoParameter(
            "opendaylight-release",
            "http://nexus.opendaylight.org/content/repositories/opendaylight.release/"));
    model.addRepository(
        createRepoParameter(
            "opendaylight-snapshot",
            "http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/"));

    model.getProperties().put("maven.compiler.source", "1.7");
    model.getProperties().put("maven.compiler.target", "1.7");

    Dependency dependency2 = new Dependency();
    dependency2.setGroupId("org.opendaylight.yangtools");
    dependency2.setArtifactId("yang-binding");
    dependency2.setVersion(yangVersion);
    dependency2.setType("jar");
    model.addDependency(dependency2);
  }
コード例 #10
0
ファイル: ModelUtils.java プロジェクト: heeckhau/tesla
  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();
    }
  }
  /**
   * If enabled, grab the execution root pom (which will be the topmost POM in terms of directory
   * structure). Check for the presence of the project-sources-maven-plugin in the base build
   * (/project/build/plugins/). Inject a new plugin execution for creating project sources if this
   * plugin has not already been declared in the base build section.
   */
  @Override
  public Set<Project> applyChanges(final List<Project> projects, final ManipulationSession session)
      throws ManipulationException {
    final ProjectSourcesInjectingState state = session.getState(ProjectSourcesInjectingState.class);

    // This manipulator will only run if its enabled *and* at least one other manipulator is
    // enabled.
    if (state.isEnabled() && session.anyStateEnabled(State.activeByDefault)) {
      for (final Project project : projects) {
        if (project.isExecutionRoot()) {
          logger.info("Examining {} to apply sources/metadata plugins.", project);

          final Model model = project.getModel();
          Build build = model.getBuild();
          if (build == null) {
            build = new Build();
            model.setBuild(build);
          }

          boolean changed = false;
          final Map<String, Plugin> pluginMap = build.getPluginsAsMap();
          if (state.isProjectSourcesPluginEnabled()
              && !pluginMap.containsKey(PROJECT_SOURCES_COORD)) {
            final PluginExecution execution = new PluginExecution();
            execution.setId(PROJECT_SOURCES_EXEC_ID);
            execution.setPhase(INITIALIZE_PHASE);
            execution.setGoals(Collections.singletonList(PROJECT_SOURCES_GOAL));

            final Plugin plugin = new Plugin();
            plugin.setGroupId(PROJECT_SOURCES_GID);
            plugin.setArtifactId(PROJECT_SOURCES_AID);
            plugin.setVersion(state.getProjectSourcesPluginVersion());
            plugin.addExecution(execution);

            build.addPlugin(plugin);

            changed = true;
          }

          if (state.isBuildMetadataPluginEnabled() && !pluginMap.containsKey(BMMP_COORD)) {
            final PluginExecution execution = new PluginExecution();
            execution.setId(BMMP_EXEC_ID);
            execution.setPhase(VALIDATE_PHASE);
            execution.setGoals(Collections.singletonList(BMMP_GOAL));

            final Xpp3Dom xml = new Xpp3Dom("configuration");

            final Map<String, Object> config = new HashMap<>();
            config.put("createPropertiesReport", true);
            config.put("hideCommandLineInfo", false);
            config.put("hideJavaOptsInfo", false);
            config.put("activateOutputFileMapping", true);
            config.put("addJavaRuntimeInfo", true);

            // Default name is build.properties but we currently prefer build.metadata.
            config.put("propertiesOutputFile", "build.metadata");
            // Deactivate features we don't want.
            config.put("createXmlReport", false);
            config.put("addLocallyModifiedTagToFullVersion", false);
            config.put("addToGeneratedSources", false);
            config.put("validateCheckout", false);
            config.put("forceNewProperties", true);
            config.put("addBuildDateToFullVersion", false);
            config.put("addHostInfo", false);
            config.put("addBuildDateInfo", false);
            config.put("addOsInfo", false);
            config.put("addMavenExecutionInfo", false);
            config.put("addToFilters", false);

            final Xpp3Dom additionalLocations = new Xpp3Dom("addToLocations");
            final Xpp3Dom additionalLocation = new Xpp3Dom("addToLocation");

            xml.addChild(additionalLocations);
            additionalLocations.addChild(additionalLocation);
            additionalLocation.setValue("${session.executionRootDirectory}");

            for (final Map.Entry<String, Object> entry : config.entrySet()) {
              final Xpp3Dom child = new Xpp3Dom(entry.getKey());
              if (entry.getValue() != null) {
                child.setValue(entry.getValue().toString());
              }

              xml.addChild(child);
            }

            execution.setConfiguration(xml);

            final Plugin plugin = new Plugin();
            plugin.setGroupId(BMMP_GID);
            plugin.setArtifactId(BMMP_AID);
            plugin.setVersion(state.getBuildMetadataPluginVersion());
            plugin.addExecution(execution);

            build.addPlugin(plugin);

            changed = true;
          }

          if (changed) {
            return Collections.singleton(project);
          }
        }
      }
    }

    return Collections.emptySet();
  }