Skip to content

Commit 85772c0

Browse files
committed
Added JavaNativeTypeHandler.
Trying to resolve issue when org.apache.httpclient is imported.
1 parent 7f1bb64 commit 85772c0

File tree

11 files changed

+288
-10
lines changed

11 files changed

+288
-10
lines changed

src/ServiceStackEclipse/.classpath

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
44
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
55
<classpathentry kind="src" path="src"/>
6+
<classpathentry kind="lib" path="libs/maven-core-3.0.5.jar"/>
7+
<classpathentry kind="lib" path="libs/maven-model-3.0.5.jar"/>
8+
<classpathentry kind="lib" path="libs/plexus-utils-2.0.6.jar"/>
69
<classpathentry kind="output" path="bin"/>
710
</classpath>

src/ServiceStackEclipse/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Bundle-Version: 1.0.0.qualifier
66
Bundle-Vendor: ServiceStack
77
Require-Bundle: org.eclipse.ui,
88
org.eclipse.core.resources,
9-
org.eclipse.jdt.core;bundle-version="3.11.0"
9+
org.eclipse.jdt.core;bundle-version="3.10.0"
1010
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
1111
Import-Package: org.eclipse.core.runtime,
1212
org.eclipse.jdt.core
546 KB
Binary file not shown.
160 KB
Binary file not shown.
218 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package net.servicestack.eclipse.maven;
2+
3+
import java.io.File;
4+
import java.io.FileReader;
5+
import java.io.FileWriter;
6+
import java.io.IOException;
7+
import java.util.List;
8+
import java.util.Objects;
9+
10+
import org.apache.maven.model.Dependency;
11+
import org.apache.maven.model.Model;
12+
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
13+
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
14+
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
15+
16+
public class EclipseMavenHelper {
17+
public boolean addMavenDependencyIfRequired(File pomFile, String groupId, String packageId, String version) throws Exception {
18+
boolean noDependencyAdded = true;
19+
MavenXpp3Reader reader = new MavenXpp3Reader();
20+
Model pomModel;
21+
try {
22+
pomModel = reader.read(new FileReader(pomFile));
23+
final List<Dependency> dependencies= pomModel.getDependencies();
24+
boolean requiresPomDependency = true;
25+
for (Dependency dep : dependencies) {
26+
if(Objects.equals(dep.getGroupId(), groupId) && Objects.equals(dep.getArtifactId(), packageId)) {
27+
requiresPomDependency = false;
28+
}
29+
}
30+
31+
if(requiresPomDependency) {
32+
Dependency dependency = new Dependency();
33+
dependency.setGroupId(groupId);
34+
dependency.setArtifactId(packageId);
35+
dependency.setVersion(version);
36+
FileWriter writer = new FileWriter(pomFile.getAbsolutePath());
37+
pomModel.addDependency(dependency);
38+
new MavenXpp3Writer().write(writer, pomModel);
39+
noDependencyAdded = false;
40+
}
41+
42+
} catch (IOException | XmlPullParserException e) {
43+
e.printStackTrace();
44+
throw new Exception("Unable to process pom.xml to add " + groupId + ":" + packageId + ":" + version);
45+
}
46+
return noDependencyAdded;
47+
}
48+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.servicestack.eclipse.nativetypes;
2+
3+
import java.io.IOException;
4+
import java.util.Map;
5+
6+
public interface INativeTypesHandler {
7+
Map<String, String> parseComments(String codeOutput);
8+
String generateUrl(String baseUrl, Map<String, String> options);
9+
String getUpdatedCode(String baseUrl, Map<String, String> options) throws IOException;
10+
NativeTypesLanguage getTypesLanguage();
11+
boolean isFileAServiceStackReference(String fileContents);
12+
String getRelativeTypesUrl();
13+
boolean validateServiceStackEndpoint(String baseUrl) throws IOException;
14+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package net.servicestack.eclipse.nativetypes;
2+
3+
//import org.apache.http.client.utils.URIBuilder;
4+
5+
import java.io.BufferedReader;
6+
import java.io.IOException;
7+
import java.io.InputStreamReader;
8+
import java.net.MalformedURLException;
9+
import java.net.URISyntaxException;
10+
import java.net.URL;
11+
import java.net.URLConnection;
12+
import java.util.*;
13+
14+
public class JavaNativeTypesHandler implements INativeTypesHandler {
15+
16+
public Map<String, String> parseComments(String codeOutput) {
17+
Map<String, String> result = new HashMap<>();
18+
Scanner scanner = new Scanner(codeOutput);
19+
List<String> linesOfCode = new ArrayList<>();
20+
Integer i = 0;
21+
while (scanner.hasNextLine()) {
22+
String line = scanner.nextLine();
23+
linesOfCode.add(line);
24+
String configLine = linesOfCode.get(i);
25+
if (!configLine.startsWith("//") && configLine.contains(":")) {
26+
String[] keyVal = configLine.split(":");
27+
result.put(keyVal[0].substring(2).trim(), keyVal[1].trim());
28+
}
29+
if (line.startsWith("*/")) break;
30+
i++;
31+
}
32+
scanner.close();
33+
return result;
34+
}
35+
36+
37+
public String generateUrl(String baseUrl, Map<String, String> options) {
38+
if (!baseUrl.endsWith("/")) {
39+
baseUrl += "/";
40+
}
41+
return null;
42+
43+
// URIBuilder builder;
44+
// try {
45+
// builder = new URIBuilder(baseUrl);
46+
// } catch (URISyntaxException e) {
47+
// //Log error to IDEA warning bubble/window.
48+
// return null;
49+
// }
50+
//
51+
// String existingPath = builder.getPath();
52+
// if (existingPath == null || existingPath.equals("/")) {
53+
// builder.setPath("/types/java");
54+
// } else {
55+
// builder.setPath(existingPath + "/types/java");
56+
// }
57+
// if(options != null) {
58+
// for (Map.Entry<String, String> item : options.entrySet()) {
59+
// builder.addParameter(item.getKey(), item.getValue().trim());
60+
// }
61+
// }
62+
// try {
63+
// return builder.build().toString();
64+
// } catch (URISyntaxException e) {
65+
// e.printStackTrace();
66+
// return null;
67+
// }
68+
}
69+
70+
71+
public String getUpdatedCode(String baseUrl, Map<String, String> options) throws IOException {
72+
String result = null;
73+
String url = generateUrl(baseUrl, options);
74+
URL javaCodeUrl = new URL(url);
75+
76+
URLConnection javaCodeConnection = javaCodeUrl.openConnection();
77+
javaCodeConnection.setRequestProperty("content-type", "application/json; charset=utf-8");
78+
BufferedReader javaCodeBufferReader = new BufferedReader(
79+
new InputStreamReader(
80+
javaCodeConnection.getInputStream()));
81+
String javaCodeInput;
82+
StringBuilder javaCodeResponse = new StringBuilder();
83+
while ((javaCodeInput = javaCodeBufferReader.readLine()) != null) {
84+
javaCodeResponse.append(javaCodeInput);
85+
//All documents inside IntelliJ IDEA always use \n line separators.
86+
//http://confluence.jetbrains.net/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview
87+
javaCodeResponse.append("\n");
88+
}
89+
90+
String javaCode = javaCodeResponse.toString();
91+
if (!javaCode.startsWith("/* Options:")) {
92+
return null;
93+
}
94+
result = javaCode;
95+
return result;
96+
}
97+
98+
99+
public NativeTypesLanguage getTypesLanguage() {
100+
return NativeTypesLanguage.Java;
101+
}
102+
103+
@Override
104+
public boolean validateServiceStackEndpoint(String baseUrl) throws IOException {
105+
String javaCode = getUpdatedCode(baseUrl, null);
106+
return javaCode != null && isFileAServiceStackReference(javaCode);
107+
}
108+
109+
public boolean isFileAServiceStackReference(String fileContents) {
110+
return fileContents.startsWith("/* Options:");
111+
}
112+
113+
114+
public String getRelativeTypesUrl() {
115+
return "types/java";
116+
}
117+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.servicestack.eclipse.nativetypes;
2+
3+
public enum NativeTypesLanguage {
4+
Java
5+
//TypeScript
6+
}
7+

src/ServiceStackEclipse/src/net/servicestack/eclipse/wizard/AddReferencePage.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class AddReferencePage extends WizardPage {
1515

1616
Button _enabled;
17-
private boolean _enabledValue = true;
17+
private boolean _enabledValue = true;
1818
private String _applicationFolder;
1919

2020
private Text addressUrlTextField;
@@ -80,6 +80,14 @@ public void verifyText(VerifyEvent event) {
8080
dialogChanged();
8181
}
8282

83+
public String getAddressUrl() {
84+
return addressUrlTextField.getText();
85+
}
86+
87+
public String getFileName() {
88+
return nameTextField.getText();
89+
}
90+
8391
private void dialogChanged() {
8492
updateStatus(null);
8593
}

0 commit comments

Comments
 (0)