Как я выполняю ряд целей перед моими выполнениями плагина Знатока?

Если у Вас есть ссылка на объект иглы, почему Вы ищете его?:) Проблемная область и примеры использования говорят Вам, что Вам не нужно точное положение иголки в стоге сена (как то, что Вы могли получить от list.indexOf (элемент)), Вам просто нужна игла. И у Вас еще нет его. Таким образом, мой ответ - что-то вроде этого

Needle needle = (Needle)haystack.searchByName("needle");

или

Needle needle = (Needle)haystack.searchWithFilter(new Filter(){
    public boolean isWhatYouNeed(Object obj)
    {
        return obj instanceof Needle;
    }
});

, или

Needle needle = (Needle)haystack.searchByPattern(Size.SMALL, 
                                                 Sharpness.SHARP, 
                                                 Material.METAL);

я соглашаюсь, что существуют более возможные решения, которые основаны на различных поисковых стратегиях, таким образом, они представляют искателя. Было достаточно комментариев к этому, таким образом, я не плачу attentiont ему здесь. Моя точка является решениями выше, забывают о примерах использования - какой смысл для поиска чего-то, если у Вас уже есть ссылка на нее? В самом естественном примере использования у Вас еще нет иглы, таким образом, Вы не используете переменную иглу.

14
задан talk to frank 15 September 2009 в 15:02
поделиться

1 ответ

You can do this by defining a custom lifecycle and invoking that lifecycle before your Mojo is executed via the execute annotation.

In your Mojo, declare in the Javadoc the lifecycle to be executed:

/**
 * Invoke the custom lifecycle before executing this goal.
 * 
 * @goal my-goal
 * @execute lifecycle="my-custom-lifecycle" phase="process-resources"
 */
public class MyMojo extends AbstractMojo {
...

Then define a custom lifecycle in src/main/resources/META-INF/maven/lifecycle.xml.

The lifecycle is a bit like plexus' components.xml, but allows you to specify configuration for those goals.

Note the syntax is slightly different to plugin configurations in the pom. You define a goal using : as a separator rather than specifying separate groupId, artifactId and version elements, otherwise it is largely the same notation as the execution element of a plugin configuration in the pom. You can even use some properties in the lifecycle.xml (though possibly not all properties are supported, I'll need to check that).

The following example invokes the dependency plugin twice with different configurations in the process-resources phase:

<lifecycles>
  <lifecycle>
    <id>download-dependencies</id>
    <phases>
      <phase>
        <id>process-resources</id>
        <executions>
          <execution>
            <goals>
              <goal>
                org.apache.maven.plugins:maven-dependency-plugin:copy-dependencies
              </goal>
            </goals>
            <configuration>
              <includeScope>compile</includeScope>
              <includeTypes>war</includeTypes>
              <overWrite>true</overWrite>
              <outputDirectory>
                ${project.build.outputDirectory}/wars
              </outputDirectory>
            </configuration>
          </execution>
          <execution>
            <goals>
              <goal>
                org.apache.maven.plugins:maven-dependency-plugin:copy-dependencies
              </goal>
            </goals>
            <configuration>
              <includeScope>compile</includeScope>
              <includeTypes>jar</includeTypes>
              <overWrite>true</overWrite>
              <outputDirectory>
                ${project.build.outputDirectory}/jars
              </outputDirectory>
            </configuration>
          </execution>
        </executions>
      </phase>
    </phases>
  </lifecycle>
</lifecycles>

With this approach, the dependency plugin will be invoked once with each configuration in the process-resources phase of the forked lifecycle (all happening within the execution defined in the Mojo).

In the lifecycle.xml, you can define multiple phases, and multiple executions per phase of the lifecycle. The available phases are defined in the Maven lifecycle.

You can find out more about lifecycles in the Creating a Custom Lifecycle section of the Maven book. It doesn't give an exhaustive list of what is allowed though. The only other reference I know if is from the Maven 2 alpha, so is possibly not that up-to-date

17
ответ дан 1 December 2019 в 13:47
поделиться
Другие вопросы по тегам:

Похожие вопросы: