View Javadoc

1   package com.atlassian.theplugin.idea;
2   
3   import com.atlassian.theplugin.util.PluginUtil;
4   import com.atlassian.theplugin.commons.util.LoggerImpl;
5   import com.intellij.openapi.application.ApplicationInfo;
6   
7   import java.util.HashMap;
8   import java.util.Map;
9   import java.net.URLEncoder;
10  import java.io.UnsupportedEncodingException;
11  
12  public class BugReporting {
13  
14  	// TODO: this version list needs updating every time we add some new version to Jira.
15  	// This is all basically incorrect code and will break beyond 2.0, but whatever
16  	// - parsing Jira form source would be a ridiculous thing to do at this point
17  
18  	private static Map<String, String> versionMap = new HashMap<String, String>();
19  
20  	static {
21  		versionMap.put("0", "10031"); // don't remove this entry or I will kill you
22  		versionMap.put("0.0.1", "10010");
23  		versionMap.put("0.1.0", "10011");
24  		versionMap.put("0.2.0", "10012");
25  		versionMap.put("0.3.1", "10013");
26  		versionMap.put("0.4.0", "10014");
27  		versionMap.put("0.5.0", "10015");
28  		versionMap.put("0.5.1", "10423");
29  		versionMap.put("1.0.0", "10016");
30  		versionMap.put("1.0.1", "10440");
31  		versionMap.put("1.1.0", "10017");
32  		versionMap.put("1.2.0", "10018");
33  		versionMap.put("1.2.1", "10470");
34  		versionMap.put("1.3.0", "10019");
35  		versionMap.put("1.3.1", "10472");
36  		versionMap.put("1.4.0", "10020");
37  		versionMap.put("1.4.1", "10482");
38  		versionMap.put("1.5.0", "10021");
39  		versionMap.put("1.6.0", "10022");
40  		versionMap.put("1.7.0", "10496");
41  		versionMap.put("1.8.0", "10497");
42  		versionMap.put("2.0.0", "10498");
43  	}
44  
45  	private static final String BASE = "https://studio.atlassian.com/secure/CreateIssueDetails!init.jspa";
46  	private static final String PROJECT_ID = "10024";
47  	private static final String TICKET_TYPE_BUG = "1";
48  	private static final String TICKET_TYPE_STORY = "5";
49  	private static String bugUrl;
50  	private static String storyUrl;
51  	private static String versionName;
52  
53  	static {
54  		versionName = PluginUtil.getInstance().getVersion();
55  		// versions seen here are formatted:
56  		// "x.y.z-SNAPSHOT, SVN:ijk" or "x.y.z, SVN:ijk"
57  		// let's check for both possibilities
58  		int i = versionName.indexOf('-');
59  		if (i == -1) {
60  			i = versionName.indexOf(',');
61  		}
62  
63  		String versionForJira;
64  		if (i != -1) {
65  			versionForJira = versionName.substring(0, i);
66  		} else {
67  			// this is going to suck and Jira is unlikely to find such a version, but
68  			// if we are here, this means that the version string is screwed up somehow
69  			// so whatever - it is b0rked anyway. let's pick "0" - it is the first pseudo-version
70  			// we have in Jira
71  			versionForJira = "0";
72  		}
73  
74  		String versionCodeForJira = versionMap.get(versionForJira);
75  		if (versionCodeForJira == null) {
76  			// this is broken, but whatever. The user can always reselect the version manually. I hope :)
77  			versionCodeForJira = versionMap.get("0");
78  		}
79  
80  		String environment = "";
81  		try {
82  			final String rawEnvironment =
83  				"Java version=" + System.getProperty("java.version")
84  				+ ", Java vendor=" + System.getProperty("java.vendor")
85  				+ ", OS name=" + System.getProperty("os.name")
86  				+ ", OS architecture=" + System.getProperty("os.arch")
87  				+ ", IDEA build number=" + ApplicationInfo.getInstance().getBuildNumber();
88  			environment = URLEncoder.encode(rawEnvironment, "UTF-8");
89  		} catch (UnsupportedEncodingException e) {
90  			LoggerImpl.getInstance().info(e);
91  		}
92  
93  		bugUrl = BASE
94  				+ "?pid=" + PROJECT_ID
95  				+ "&versions=" + versionCodeForJira
96  				+ "&issuetype=" + TICKET_TYPE_BUG
97  				+ "&environment=" + environment;
98  
99  
100 		storyUrl = BASE
101 				+ "?pid=" + PROJECT_ID
102 				+ "&versions=" + versionCodeForJira
103 				+ "&issuetype=" + TICKET_TYPE_STORY;
104 	}
105 
106 	public static String getBugUrl() {
107 		return bugUrl;
108 	}
109 
110 	public static String getStoryUrl() {
111 		return storyUrl;
112 	}
113 
114 	public static String getVersionString() {
115 		return versionName;
116 	}
117 
118 	public static String getBugWithDescriptionUrl(String description) {
119 		try {
120 			return bugUrl + "&description=" + URLEncoder.encode(description, "UTF-8");
121 		} catch (UnsupportedEncodingException e) {
122 			return bugUrl;
123 		}
124 	}
125 
126 	private BugReporting() {
127 	}
128 }