KeelMavenTool...
"Vidakovic Aleksandar" <[email protected]> Wed, 25 May 2005 14:27:06 +0200
| Newsgroups | gmane.comp.java.keel.devel |
|---|---|
| Message-ID | <7440600321F19B40B01B38AC516A082501505F6C@kingofvolke.volke-muc.de> |
Salut all, just wanted to tell you that with the attached patches KeelMavenTool can be used behind a firewall. If maven proxy properties are set (in build.properties, project.properties) then KeelMavenTool authenticates with these properties to the proxy using commons-httpclient. If these properties are not set URL.openStream() is used (as before). As I'm behind a firewall ;-) I can't commit it right now... but here are the patches. I'll try to commit this as soon as possible. Cheers, Aleks
tool-maven-patch.txt
(text/plain, 15.1 KB)
Index: .classpath
===================================================================
RCS file: /cvsroot/keel/tool-maven/.classpath,v
retrieving revision 1.4
diff -u -r1.4 .classpath
--- .classpath 4 Apr 2005 02:18:48 -0000 1.4
+++ .classpath 25 May 2005 12:15:49 -0000
@@ -13,6 +13,10 @@
</classpathentry>
<classpathentry kind="var" path="MAVEN_REPO/xerces/jars/xercesImpl-2.6.2.jar">
</classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/xml-resolver/jars/xml-resolver-1.1.jar">
+ </classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-httpclient/jars/commons-httpclient-3.0-rc2.jar">
+ </classpathentry>
<classpathentry kind="output" path="target/classes">
</classpathentry>
</classpath>
\ No newline at end of file
Index: .project
===================================================================
RCS file: /cvsroot/keel/tool-maven/.project,v
retrieving revision 1.4
diff -u -r1.4 .project
--- .project 4 Apr 2005 02:18:48 -0000 1.4
+++ .project 25 May 2005 12:15:49 -0000
@@ -1,18 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<projectDescription>
- <name>tool-maven</name>
- <comment>This project contains a tool used by the Keel Maven plug-in. It allows an existing project.xml file for a property to be automatically updated to include all necessary dependencies for Keel services, as specified by the ant.properties file.</comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
\ No newline at end of file
+ <name>tool-maven</name>
+ <comment>This project contains a tool used by the Keel Maven plug-in. It allows an existing project.xml file for a property to be automatically updated to include all necessary dependencies for Keel services, as specified by the ant.properties file.</comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.ibm.sse.model.structuredbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
Index: project.xml
===================================================================
RCS file: /cvsroot/keel/tool-maven/project.xml,v
retrieving revision 1.15
diff -u -r1.15 project.xml
--- project.xml 16 May 2005 22:39:15 -0000 1.15
+++ project.xml 25 May 2005 12:15:49 -0000
@@ -32,6 +32,16 @@
<artifactId>xercesImpl</artifactId>
<version>2.6.2</version>
</dependency>
+ <dependency>
+ <groupId>xml-resolver</groupId>
+ <artifactId>xml-resolver</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.0-rc2</version>
+ </dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/src/java</sourceDirectory>
@@ -47,6 +57,13 @@
<include>LICENSE*</include>
</includes>
</resource>
+ <resource>
+ <directory>${basedir}/resources</directory>
+ <targetpath>/</targetpath>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
</resources>
</build>
</project>
Index: src/java/org/keel/tools/maven/KeelMavenTool.java
===================================================================
RCS file: /cvsroot/keel/tool-maven/src/java/org/keel/tools/maven/KeelMavenTool.java,v
retrieving revision 1.13
diff -u -r1.13 KeelMavenTool.java
--- src/java/org/keel/tools/maven/KeelMavenTool.java 16 May 2005 22:38:08 -0000 1.13
+++ src/java/org/keel/tools/maven/KeelMavenTool.java 25 May 2005 12:15:50 -0000
@@ -18,6 +18,7 @@
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -32,7 +33,14 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-
+import javax.xml.transform.Source;
+import javax.xml.transform.URIResolver;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.w3c.dom.DOMException;
@@ -41,6 +49,8 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@@ -58,8 +68,12 @@
private static final String PREFIX = "[KeelMavenTool] ";
private static String mavenRepoRemote = null;
private static boolean online = true;
+ private static String proxyHost = null;
+ private static int proxyPort = 80;
+ private static String proxyUser = null;
+ private static String proxyPassword = null;
private static Set checkedDeps = new HashSet();
-
+
/*
* Set by the system property "debug" (e.g. -Ddebug=true) for detailed
* debugging
@@ -198,7 +212,9 @@
ParserConfigurationException, IOException {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
+ docBuilderFactory.setValidating(false);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ docBuilder.setEntityResolver(new ProxyResolver());
Document doc = docBuilder.parse(new File(fileName));
// normalize text representation
@@ -210,7 +226,9 @@
ParserConfigurationException, IOException {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
.newInstance();
+ docBuilderFactory.setValidating(false);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
+ docBuilder.setEntityResolver(new ProxyResolver());
Document doc = docBuilder.parse(in);
// normalize text representation
@@ -265,7 +283,7 @@
+ pomUrl.toExternalForm());
try {
/* Try to open stream, just to be sure it's there */
- new BufferedInputStream(pomUrl.openStream());
+ new BufferedInputStream(openUrl(pomUrl));
debug("Found POM at URL " + oneDlUrl + "/" + group + "/"
+ moduleName + ", copying to local file");
copyUrlToFile(oneDlUrl + "/" + group + "/" + moduleName, pomFileName);
@@ -297,8 +315,7 @@
iDir.mkdirs();
long count = 0;
- BufferedInputStream ibin = new BufferedInputStream(inputUrl
- .openStream());
+ BufferedInputStream ibin = new BufferedInputStream(openUrl(inputUrl));
BufferedOutputStream bout = new BufferedOutputStream(
new FileOutputStream(dest));
int c = ibin.read();
@@ -311,7 +328,117 @@
bout.close();
return count;
}
+
+ private InputStream openUrl(URL url)
+ throws FileNotFoundException
+ {
+ InputStream is = null;
+
+ debug("[URL] " + url.toString());
+
+ try
+ {
+ if(url.toString().contains("file") || proxyHost==null || proxyUser==null || proxyPassword==null)
+ {
+ is = url.openStream();
+ }
+ else
+ {
+ HttpClient httpclient = new HttpClient();
+ httpclient.getHostConfiguration().setProxy(proxyHost, proxyPort);
+ httpclient.getState().setProxyCredentials(null, proxyHost, new UsernamePasswordCredentials(proxyUser, proxyPassword));
+ GetMethod httpget = new GetMethod(url.toString());
+
+ httpclient.executeMethod(httpget);
+ debug("[STATUS] " + httpget.getStatusCode());
+ //debug(httpget.getResponseBodyAsString());
+
+ if (httpget.getResponseBodyAsString().contains("<html"))
+ {
+ // NOTE: workaround for sites that have a redirect to error pages
+ throw new FileNotFoundException();
+ }
+ else if(httpget.getStatusCode()!=200)
+ {
+ throw new FileNotFoundException();
+ }
+ else
+ {
+ is = httpget.getResponseBodyAsStream();
+ }
+
+// httpget.releaseConnection();
+ }
+ }
+ catch (HttpException e)
+ {
+ throw new FileNotFoundException(e.toString());
+ }
+ catch (IOException e)
+ {
+ throw new FileNotFoundException(e.toString());
+ }
+
+ return is;
+ }
+
+ // Just in case DTDs are referenced
+ class ProxyResolver
+ implements EntityResolver, URIResolver
+ {
+ public InputSource resolveEntity (String publicId, String systemId)
+ {
+ try
+ {
+ debug("[SYSTEM ID]" + systemId);
+ debug("[PUBLIC ID]" + publicId);
+ InputSource is = new InputSource(openUrl(new URL(systemId)));
+ is.setPublicId(publicId);
+ is.setSystemId(systemId);
+
+ return is;
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+ public Source resolve(String href, String base)
+ {
+ debug("[HREF] " + href);
+ debug("[BASE] " + base);
+
+ try
+ {
+ if(href.startsWith("http"))
+ {
+ return new StreamSource(openUrl(new URL(href)));
+ }
+ else
+ {
+ return new StreamSource(openUrl(new URL(base + "/" + href)));
+ }
+ }
+ catch (FileNotFoundException e)
+ {
+ e.printStackTrace();
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+
+ return null;
+ }
+ }
+
public void clearDeps() {
checkedDeps = new HashSet();
}
@@ -744,6 +871,18 @@
if (props.getProperty("maven.mode.online") != null) {
online = new Boolean(props.getProperty("maven.mode.online")).booleanValue();
}
+ if (props.getProperty("maven.proxy.host") != null) {
+ proxyHost = props.getProperty("maven.proxy.host");
+ }
+ if (props.getProperty("maven.proxy.port") != null) {
+ proxyPort = Integer.valueOf(props.getProperty("maven.proxy.port")).intValue();
+ }
+ if (props.getProperty("maven.proxy.username") != null) {
+ proxyUser = props.getProperty("maven.proxy.username");
+ }
+ if (props.getProperty("maven.proxy.password") != null) {
+ proxyPassword = props.getProperty("maven.proxy.password");
+ }
}
/* look in project.properties */
@@ -762,6 +901,18 @@
if (props.getProperty("maven.mode.online") != null) {
online = new Boolean(props.getProperty("maven.mode.online")).booleanValue();
}
+ if (props.getProperty("maven.proxy.host") != null) {
+ proxyHost = props.getProperty("maven.proxy.host");
+ }
+ if (props.getProperty("maven.proxy.port") != null) {
+ proxyPort = Integer.valueOf(props.getProperty("maven.proxy.port")).intValue();
+ }
+ if (props.getProperty("maven.proxy.username") != null) {
+ proxyUser = props.getProperty("maven.proxy.username");
+ }
+ if (props.getProperty("maven.proxy.password") != null) {
+ proxyPassword = props.getProperty("maven.proxy.password");
+ }
}
/* then current dir build.properties */
name = System.getProperty("user.dir") + "/build.properties";
@@ -779,6 +930,18 @@
if (props.getProperty("maven.mode.online") != null) {
online = new Boolean(props.getProperty("maven.mode.online")).booleanValue();
}
+ if (props.getProperty("maven.proxy.host") != null) {
+ proxyHost = props.getProperty("maven.proxy.host");
+ }
+ if (props.getProperty("maven.proxy.port") != null) {
+ proxyPort = Integer.valueOf(props.getProperty("maven.proxy.port")).intValue();
+ }
+ if (props.getProperty("maven.proxy.username") != null) {
+ proxyUser = props.getProperty("maven.proxy.username");
+ }
+ if (props.getProperty("maven.proxy.password") != null) {
+ proxyPassword = props.getProperty("maven.proxy.password");
+ }
}
/* then current dir project.properties */
name = System.getProperty("user.dir") + "/project.properties";
@@ -796,6 +959,18 @@
if (props.getProperty("maven.mode.online") != null) {
online = new Boolean(props.getProperty("maven.mode.online")).booleanValue();
}
+ if (props.getProperty("maven.proxy.host") != null) {
+ proxyHost = props.getProperty("maven.proxy.host");
+ }
+ if (props.getProperty("maven.proxy.port") != null) {
+ proxyPort = Integer.valueOf(props.getProperty("maven.proxy.port")).intValue();
+ }
+ if (props.getProperty("maven.proxy.username") != null) {
+ proxyUser = props.getProperty("maven.proxy.username");
+ }
+ if (props.getProperty("maven.proxy.password") != null) {
+ proxyPassword = props.getProperty("maven.proxy.password");
+ }
}
} catch (IOException ie) {
System.err.println(PREFIX
tool-maven-plugin-patch.txt
(text/plain, 4.1 KB)
Index: .classpath
===================================================================
RCS file: /cvsroot/keel/tool-maven-plugin/.classpath,v
retrieving revision 1.9
diff -u -r1.9 .classpath
--- .classpath 17 Apr 2005 17:24:44 -0000 1.9
+++ .classpath 25 May 2005 12:16:54 -0000
@@ -9,7 +9,7 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
</classpathentry>
- <classpathentry kind="var" path="MAVEN_REPO/keel/jars/tool-maven-3.2.3.jar">
+ <classpathentry kind="var" path="MAVEN_REPO/keel/jars/tool-maven-3.2.4.jar">
</classpathentry>
<classpathentry kind="var" path="MAVEN_REPO/keel/jars/keel-build-3.2.2.jar">
</classpathentry>
@@ -55,6 +55,8 @@
</classpathentry>
<classpathentry kind="var" path="MAVEN_REPO/excalibur-instrument/jars/excalibur-instrument-client-1.2-dev.jar">
</classpathentry>
+ <classpathentry kind="var" path="MAVEN_REPO/commons-httpclient/jars/commons-httpclient-3.0-rc2.jar">
+ </classpathentry>
<classpathentry kind="output" path="target/classes">
</classpathentry>
</classpath>
\ No newline at end of file
Index: .project
===================================================================
RCS file: /cvsroot/keel/tool-maven-plugin/.project,v
retrieving revision 1.2
diff -u -r1.2 .project
--- .project 14 May 2005 15:54:48 -0000 1.2
+++ .project 25 May 2005 12:16:54 -0000
@@ -1,19 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
-
<projectDescription>
- <name>tool-maven-plugin</name>
- <comment>
+ <name>tool-maven-plugin</name>
+ <comment>
</comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.ibm.sse.model.structuredbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
</projectDescription>
Index: plugin.jelly
===================================================================
RCS file: /cvsroot/keel/tool-maven-plugin/plugin.jelly,v
retrieving revision 1.24
diff -u -r1.24 plugin.jelly
--- plugin.jelly 17 May 2005 20:25:49 -0000 1.24
+++ plugin.jelly 25 May 2005 12:16:55 -0000
@@ -136,6 +136,9 @@
<ant:pathelement path="${plugin.getDependencyPath('keel:tool-maven')}"/>
<ant:pathelement path="${plugin.getDependencyPath('xerces:xmlParserAPIs')}"/>
<ant:pathelement path="${plugin.getDependencyPath('xerces:xercesImpl')}"/>
+ <ant:pathelement path="${plugin.getDependencyPath('commons-httpclient:commons-httpclient')}"/>
+ <ant:pathelement path="${plugin.getDependencyPath('commons-logging:commons-logging')}"/>
+ <ant:pathelement path="${plugin.getDependencyPath('commons-codec:commons-codec')}"/>
</ant:path>
<property name="maventool.path" refid="maventool.classpath"/>
<java classname="org.keel.tools.maven.KeelMavenTool" fork="yes" failonerror="true"
Index: project.xml
===================================================================
RCS file: /cvsroot/keel/tool-maven-plugin/project.xml,v
retrieving revision 1.15
diff -u -r1.15 project.xml
--- project.xml 16 May 2005 22:37:18 -0000 1.15
+++ project.xml 25 May 2005 12:16:55 -0000
@@ -179,6 +179,16 @@
<artifactId>excalibur-instrument-client</artifactId>
<version>1.2-dev</version>
</dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.0-rc2</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>1.3</version>
+ </dependency>
</dependencies>
<build>
<sourceDirectory>src/java</sourceDirectory>