2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.jetbrains
.idea
.maven
.utils
;
18 import org
.jdom
.Element
;
19 import org
.jetbrains
.idea
.maven
.project
.MavenId
;
21 import static org
.jetbrains
.idea
.maven
.project
.MavenId
.append
;
23 import java
.util
.Collection
;
24 import java
.util
.LinkedHashMap
;
27 public class MavenPluginInfo
{
28 private final String myGroupId
;
29 private final String myArtifactId
;
30 private final String myVersion
;
31 private final String myGoalPrefix
;
32 private final Map
<String
, Mojo
> myMojos
;
34 public MavenPluginInfo(byte[] text
) {
35 Element plugin
= MavenJDOMUtil
.read(text
, null);
37 myGroupId
= MavenJDOMUtil
.findChildValueByPath(plugin
, "groupId", MavenId
.UNKNOWN_VALUE
);
38 myArtifactId
= MavenJDOMUtil
.findChildValueByPath(plugin
, "artifactId",MavenId
.UNKNOWN_VALUE
);
39 myVersion
= MavenJDOMUtil
.findChildValueByPath(plugin
, "version", MavenId
.UNKNOWN_VALUE
);
41 myGoalPrefix
= MavenJDOMUtil
.findChildValueByPath(plugin
, "goalPrefix", "unknown");
43 myMojos
= readMojos(plugin
);
46 private Map
<String
, Mojo
> readMojos(Element plugin
) {
47 Map
<String
, Mojo
> result
= new LinkedHashMap
<String
, Mojo
>();
48 for (Element each
: MavenJDOMUtil
.findChildrenByPath(plugin
, "mojos", "mojo")) {
49 String goal
= MavenJDOMUtil
.findChildValueByPath(each
, "goal", "unknown");
50 result
.put(goal
, new Mojo(goal
));
55 public String
getGroupId() {
59 public String
getArtifactId() {
63 public String
getVersion() {
67 public String
getGoalPrefix() {
71 public Collection
<Mojo
> getMojos() {
72 return myMojos
.values();
75 public Mojo
findMojo(String name
) {
76 return myMojos
.get(name
);
80 private final String myGoal
;
82 private Mojo(String goal
) {
86 public String
getGoal() {
90 public String
getDisplayName() {
91 return myGoalPrefix
+ ":" + myGoal
;
94 public String
getQualifiedGoal() {
95 StringBuilder builder
= new StringBuilder();
97 append(builder
, myGroupId
);
98 append(builder
, myArtifactId
);
99 append(builder
, myVersion
);
100 append(builder
, myGoal
);
102 return builder
.toString();