You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ivy-commits@incubator.apache.org by gs...@apache.org on 2007/06/28 19:04:20 UTC
svn commit: r551661 - in /incubator/ivy/core/trunk: ./
src/java/org/apache/ivy/core/ src/java/org/apache/ivy/core/settings/
src/java/org/apache/ivy/plugins/parser/xml/ test/java/org/apache/ivy/core/
Author: gscokart
Date: Thu Jun 28 12:04:18 2007
New Revision: 551661
URL: http://svn.apache.org/viewvc?view=rev&rev=551661
Log:
IVY-347 Allow relative path in ivy.xml files
Added:
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java (with props)
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java (with props)
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java (with props)
incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java (with props)
Modified:
incubator/ivy/core/trunk/CHANGES.txt
incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
Modified: incubator/ivy/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=551661&r1=551660&r2=551661
==============================================================================
--- incubator/ivy/core/trunk/CHANGES.txt (original)
+++ incubator/ivy/core/trunk/CHANGES.txt Thu Jun 28 12:04:18 2007
@@ -86,6 +86,8 @@
- FIX: buildlist broken - regression in 2.0.0-alpha1-incubating (IVY-493)
- FIX: Circular dependency startegy in buildlist (IVY-509)
- FIX: ivy should stop telling me off twice for ivyconf.xml files (IVY-513)
+- FIX: Allow relative path in ivy.xml files (IVY-347)
+
2.0.0-alpha1-incubating
=====================================
Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java?view=auto&rev=551661
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java Thu Jun 28 12:04:18 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Resolve relative url relatively to the current execution directory instead
+ * of relatively to the context.
+ * This is was actually done prior 2.0. This class allow thus to work
+ * in a backward compatible mode.
+ */
+public class ExecutionRelativeUrlResolver implements RelativeUrlResolver {
+
+ public URL getURL(URL context, String url) throws MalformedURLException {
+ return new URL(url);
+ }
+
+}
Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java?view=auto&rev=551661
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java Thu Jun 28 12:04:18 2007
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Normal implementation of RelativeUrlResolver.
+ */
+public class NormalRelativeUrlResolver implements RelativeUrlResolver {
+
+ public URL getURL(URL context, String url) throws MalformedURLException {
+ return new URL(context , url);
+ }
+
+}
Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java?view=auto&rev=551661
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java (added)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java Thu Jun 28 12:04:18 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * Resolve an file or url relatively to its context.
+ */
+public interface RelativeUrlResolver {
+
+ public URL getURL(URL context , String url) throws MalformedURLException;
+}
Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?view=diff&rev=551661&r1=551660&r2=551661
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java Thu Jun 28 12:04:18 2007
@@ -38,6 +38,8 @@
import org.apache.ivy.Ivy;
import org.apache.ivy.core.IvyPatternHelper;
+import org.apache.ivy.core.NormalRelativeUrlResolver;
+import org.apache.ivy.core.RelativeUrlResolver;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.status.StatusManager;
import org.apache.ivy.core.sort.SortEngineSettings;
@@ -1154,4 +1156,8 @@
variableContainer = variables;
}
+
+ public RelativeUrlResolver getRelativeUrlResolver() {
+ return new NormalRelativeUrlResolver();
+ }
}
Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java?view=diff&rev=551661&r1=551660&r2=551661
==============================================================================
--- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java (original)
+++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java Thu Jun 28 12:04:18 2007
@@ -93,14 +93,15 @@
*/
public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL xmlURL, Resource res,
boolean validate) throws ParseException, IOException {
- Parser parser = new Parser(this, ivySettings, validate);
- parser.parse(xmlURL, res, validate);
+ Parser parser = new Parser(this, ivySettings, validate, xmlURL);
+ parser.parse(res, validate);
return parser.getModuleDescriptor();
}
- public ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor,
+ /** Used for test purpose */
+ ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor,
Resource res, boolean validate) throws ParseException, IOException {
- Parser parser = new Parser(this, ivySettings, validate);
+ Parser parser = new Parser(this, ivySettings, validate, null);
parser.parse(descriptor, res, validate);
return parser.getModuleDescriptor();
}
@@ -174,13 +175,16 @@
private int _state = NONE;
- public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate) {
+ private final URL xmlURL;
+
+ public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate, URL xmlURL) {
super(parser);
_ivy = ivySettings;
_validate = validate;
+ this.xmlURL = xmlURL;
}
- private void parse(URL xmlURL, Resource res, boolean validate) throws ParseException,
+ private void parse(Resource res, boolean validate) throws ParseException,
IOException {
try {
setResource(res);
@@ -490,21 +494,20 @@
parseRule(qName, attributes);
md.addExcludeRule((ExcludeRule) _confAware);
} else if ("include".equals(qName) && _state == CONF) {
- URL url;
- String fileName = _ivy.substitute(attributes.getValue("file"));
- if (fileName == null) {
- String urlStr = _ivy.substitute(attributes.getValue("url"));
- url = new URL(urlStr);
- } else {
- url = new File(fileName).toURL();
+ String file = attributes.getValue("file");
+ String pathUrl = file == null ? attributes.getValue("url") : "file://" + file;
+ if (pathUrl == null) {
+ throw new SAXException("include tag must have a file or an url attribute");
}
+ String substitutedPathUrl = _ivy.substitute(pathUrl);
+ URL url = _ivy.getRelativeUrlResolver().getURL(xmlURL, substitutedPathUrl);
// create a new temporary parser to read the configurations from
// the specified file.
- Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false);
+ Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false, url);
parser.md = new DefaultModuleDescriptor(getModuleDescriptorParser(),
new URLResource(url));
- XMLHelper.parse(url, null, parser);
+ XMLHelper.parse(url , null, parser);
// add the configurations from this temporary parser to this module descriptor
Configuration[] configs = parser.getModuleDescriptor().getConfigurations();
@@ -517,8 +520,8 @@
setDefaultConfMapping(parser.getDefaultConfMapping());
}
if (parser.md.isMappingOverride()) {
- Message
- .debug("enabling mapping-override from imported configurations file");
+ Message.debug("enabling mapping-override from imported configurations"
+ + " file");
md.setMappingOverride(true);
}
} else if (_validate && _state != INFO) {
Added: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java
URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java?view=auto&rev=551661
==============================================================================
--- incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java (added)
+++ incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java Thu Jun 28 12:04:18 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.ivy.core;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+public class NormalRelativeUrlResolverTest extends TestCase {
+
+
+ public void testRelativeHttpURL() throws MalformedURLException {
+ URL base = new URL("http://xxx/file.txt");
+ NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
+ assertEquals(new URL("http://xxx/file2.txt"), t.getURL(base , "file2.txt"));
+ }
+
+ public void testRelativeFileURL() throws MalformedURLException {
+ URL base = new URL("file://xxx/file.txt");
+ NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
+ assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base , "file2.txt"));
+ }
+
+ public void testRelativeMixedURL() throws MalformedURLException {
+ URL base = new URL("http://xxx/file.txt");
+ NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
+ assertEquals(new URL("file://file2.txt"), t.getURL(base , "file://file2.txt"));
+ }
+
+}
Propchange: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Re: svn commit: r551661 - in /incubator/ivy/core/trunk: ./ src/java/org/apache/ivy/core/ src/java/org/apache/ivy/core/settings/ src/java/org/apache/ivy/plugins/parser/xml/ test/java/org/apache/ivy/core/
Posted by Gilles Scokart <gs...@gmail.com>.
Oups, it seems that I broke a test. I will look at it.
Gilles
2007/6/28, gscokart@apache.org <gs...@apache.org>:
> Author: gscokart
> Date: Thu Jun 28 12:04:18 2007
> New Revision: 551661
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=551661
> Log:
> IVY-347 Allow relative path in ivy.xml files
>
> Added:
> incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java (with props)
> incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java (with props)
> incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java (with props)
> incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java (with props)
> Modified:
> incubator/ivy/core/trunk/CHANGES.txt
> incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
> incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
>
> Modified: incubator/ivy/core/trunk/CHANGES.txt
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/CHANGES.txt?view=diff&rev=551661&r1=551660&r2=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/CHANGES.txt (original)
> +++ incubator/ivy/core/trunk/CHANGES.txt Thu Jun 28 12:04:18 2007
> @@ -86,6 +86,8 @@
> - FIX: buildlist broken - regression in 2.0.0-alpha1-incubating (IVY-493)
> - FIX: Circular dependency startegy in buildlist (IVY-509)
> - FIX: ivy should stop telling me off twice for ivyconf.xml files (IVY-513)
> +- FIX: Allow relative path in ivy.xml files (IVY-347)
> +
>
> 2.0.0-alpha1-incubating
> =====================================
>
> Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java?view=auto&rev=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java (added)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java Thu Jun 28 12:04:18 2007
> @@ -0,0 +1,35 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +package org.apache.ivy.core;
> +
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> +/**
> + * Resolve relative url relatively to the current execution directory instead
> + * of relatively to the context.
> + * This is was actually done prior 2.0. This class allow thus to work
> + * in a backward compatible mode.
> + */
> +public class ExecutionRelativeUrlResolver implements RelativeUrlResolver {
> +
> + public URL getURL(URL context, String url) throws MalformedURLException {
> + return new URL(url);
> + }
> +
> +}
>
> Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/ExecutionRelativeUrlResolver.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java?view=auto&rev=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java (added)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java Thu Jun 28 12:04:18 2007
> @@ -0,0 +1,32 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +package org.apache.ivy.core;
> +
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> +/**
> + * Normal implementation of RelativeUrlResolver.
> + */
> +public class NormalRelativeUrlResolver implements RelativeUrlResolver {
> +
> + public URL getURL(URL context, String url) throws MalformedURLException {
> + return new URL(context , url);
> + }
> +
> +}
>
> Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/NormalRelativeUrlResolver.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Added: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java?view=auto&rev=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java (added)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java Thu Jun 28 12:04:18 2007
> @@ -0,0 +1,29 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +package org.apache.ivy.core;
> +
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> +/**
> + * Resolve an file or url relatively to its context.
> + */
> +public interface RelativeUrlResolver {
> +
> + public URL getURL(URL context , String url) throws MalformedURLException;
> +}
>
> Propchange: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/RelativeUrlResolver.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
> Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java?view=diff&rev=551661&r1=551660&r2=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java (original)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/core/settings/IvySettings.java Thu Jun 28 12:04:18 2007
> @@ -38,6 +38,8 @@
>
> import org.apache.ivy.Ivy;
> import org.apache.ivy.core.IvyPatternHelper;
> +import org.apache.ivy.core.NormalRelativeUrlResolver;
> +import org.apache.ivy.core.RelativeUrlResolver;
> import org.apache.ivy.core.module.id.ModuleId;
> import org.apache.ivy.core.module.status.StatusManager;
> import org.apache.ivy.core.sort.SortEngineSettings;
> @@ -1154,4 +1156,8 @@
> variableContainer = variables;
> }
>
> +
> + public RelativeUrlResolver getRelativeUrlResolver() {
> + return new NormalRelativeUrlResolver();
> + }
> }
>
> Modified: incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java?view=diff&rev=551661&r1=551660&r2=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java (original)
> +++ incubator/ivy/core/trunk/src/java/org/apache/ivy/plugins/parser/xml/XmlModuleDescriptorParser.java Thu Jun 28 12:04:18 2007
> @@ -93,14 +93,15 @@
> */
> public ModuleDescriptor parseDescriptor(IvySettings ivySettings, URL xmlURL, Resource res,
> boolean validate) throws ParseException, IOException {
> - Parser parser = new Parser(this, ivySettings, validate);
> - parser.parse(xmlURL, res, validate);
> + Parser parser = new Parser(this, ivySettings, validate, xmlURL);
> + parser.parse(res, validate);
> return parser.getModuleDescriptor();
> }
>
> - public ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor,
> + /** Used for test purpose */
> + ModuleDescriptor parseDescriptor(IvySettings ivySettings, InputStream descriptor,
> Resource res, boolean validate) throws ParseException, IOException {
> - Parser parser = new Parser(this, ivySettings, validate);
> + Parser parser = new Parser(this, ivySettings, validate, null);
> parser.parse(descriptor, res, validate);
> return parser.getModuleDescriptor();
> }
> @@ -174,13 +175,16 @@
>
> private int _state = NONE;
>
> - public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate) {
> + private final URL xmlURL;
> +
> + public Parser(ModuleDescriptorParser parser, IvySettings ivySettings, boolean validate, URL xmlURL) {
> super(parser);
> _ivy = ivySettings;
> _validate = validate;
> + this.xmlURL = xmlURL;
> }
>
> - private void parse(URL xmlURL, Resource res, boolean validate) throws ParseException,
> + private void parse(Resource res, boolean validate) throws ParseException,
> IOException {
> try {
> setResource(res);
> @@ -490,21 +494,20 @@
> parseRule(qName, attributes);
> md.addExcludeRule((ExcludeRule) _confAware);
> } else if ("include".equals(qName) && _state == CONF) {
> - URL url;
> - String fileName = _ivy.substitute(attributes.getValue("file"));
> - if (fileName == null) {
> - String urlStr = _ivy.substitute(attributes.getValue("url"));
> - url = new URL(urlStr);
> - } else {
> - url = new File(fileName).toURL();
> + String file = attributes.getValue("file");
> + String pathUrl = file == null ? attributes.getValue("url") : "file://" + file;
> + if (pathUrl == null) {
> + throw new SAXException("include tag must have a file or an url attribute");
> }
> + String substitutedPathUrl = _ivy.substitute(pathUrl);
> + URL url = _ivy.getRelativeUrlResolver().getURL(xmlURL, substitutedPathUrl);
>
> // create a new temporary parser to read the configurations from
> // the specified file.
> - Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false);
> + Parser parser = new Parser(getModuleDescriptorParser(), _ivy, false, url);
> parser.md = new DefaultModuleDescriptor(getModuleDescriptorParser(),
> new URLResource(url));
> - XMLHelper.parse(url, null, parser);
> + XMLHelper.parse(url , null, parser);
>
> // add the configurations from this temporary parser to this module descriptor
> Configuration[] configs = parser.getModuleDescriptor().getConfigurations();
> @@ -517,8 +520,8 @@
> setDefaultConfMapping(parser.getDefaultConfMapping());
> }
> if (parser.md.isMappingOverride()) {
> - Message
> - .debug("enabling mapping-override from imported configurations file");
> + Message.debug("enabling mapping-override from imported configurations"
> + + " file");
> md.setMappingOverride(true);
> }
> } else if (_validate && _state != INFO) {
>
> Added: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java
> URL: http://svn.apache.org/viewvc/incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java?view=auto&rev=551661
> ==============================================================================
> --- incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java (added)
> +++ incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java Thu Jun 28 12:04:18 2007
> @@ -0,0 +1,46 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements. See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License. You may obtain a copy of the License at
> + *
> + * http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + *
> + */
> +package org.apache.ivy.core;
> +
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> +import junit.framework.TestCase;
> +
> +public class NormalRelativeUrlResolverTest extends TestCase {
> +
> +
> + public void testRelativeHttpURL() throws MalformedURLException {
> + URL base = new URL("http://xxx/file.txt");
> + NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
> + assertEquals(new URL("http://xxx/file2.txt"), t.getURL(base , "file2.txt"));
> + }
> +
> + public void testRelativeFileURL() throws MalformedURLException {
> + URL base = new URL("file://xxx/file.txt");
> + NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
> + assertEquals(new URL("file://xxx/file2.txt"), t.getURL(base , "file2.txt"));
> + }
> +
> + public void testRelativeMixedURL() throws MalformedURLException {
> + URL base = new URL("http://xxx/file.txt");
> + NormalRelativeUrlResolver t = new NormalRelativeUrlResolver();
> + assertEquals(new URL("file://file2.txt"), t.getURL(base , "file://file2.txt"));
> + }
> +
> +}
>
> Propchange: incubator/ivy/core/trunk/test/java/org/apache/ivy/core/NormalRelativeUrlResolverTest.java
> ------------------------------------------------------------------------------
> svn:eol-style = native
>
>
>
--
Gilles SCOKART