Return-Path: Delivered-To: apmail-tuscany-commits-archive@www.apache.org Received: (qmail 28690 invoked from network); 8 Dec 2010 05:47:43 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Dec 2010 05:47:43 -0000 Received: (qmail 50895 invoked by uid 500); 8 Dec 2010 05:47:43 -0000 Delivered-To: apmail-tuscany-commits-archive@tuscany.apache.org Received: (qmail 50830 invoked by uid 500); 8 Dec 2010 05:47:43 -0000 Mailing-List: contact commits-help@tuscany.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tuscany.apache.org Delivered-To: mailing list commits@tuscany.apache.org Received: (qmail 50817 invoked by uid 99); 8 Dec 2010 05:47:42 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 05:47:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Dec 2010 05:47:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B72E923889B9; Wed, 8 Dec 2010 05:47:21 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1043310 - /tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java Date: Wed, 08 Dec 2010 05:47:21 -0000 To: commits@tuscany.apache.org From: lresende@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101208054721.B72E923889B9@eris.apache.org> Author: lresende Date: Wed Dec 8 05:47:21 2010 New Revision: 1043310 URL: http://svn.apache.org/viewvc?rev=1043310&view=rev Log: Allowing more flexible resolution for the widget artifact Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java Modified: tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java?rev=1043310&r1=1043309&r2=1043310&view=diff ============================================================================== --- tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java (original) +++ tuscany/sca-java-2.x/trunk/modules/implementation-widget/src/main/java/org/apache/tuscany/sca/implementation/widget/WidgetImplementationProcessor.java Wed Dec 8 05:47:21 2010 @@ -20,7 +20,11 @@ package org.apache.tuscany.sca.implement import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import java.io.File; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import javax.xml.namespace.QName; @@ -61,7 +65,6 @@ public class WidgetImplementationProcess implementationFactory = modelFactories.getFactory(WidgetImplementationFactory.class); } - public QName getArtifactType() { // Returns the QName of the XML element processed by this processor return WidgetImplementation.TYPE; @@ -103,26 +106,48 @@ public class WidgetImplementationProcess public void resolve(WidgetImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { if (implementation != null) { - // Resolve the resource directory location + // Resolve the resource directory location Artifact artifact = contributionFactory.createArtifact(); artifact.setURI(implementation.getLocation()); Artifact resolved = resolver.resolveModel(Artifact.class, artifact, context); - if (resolved.getLocation() != null) { - try { - implementation.setLocationURL(new URL(resolved.getLocation())); - - //introspect implementation - WidgetImplementationIntrospector widgetIntrospector = - new WidgetImplementationIntrospector(registry, implementation); - widgetIntrospector.introspectImplementation(); - - implementation.setUnresolved(false); - } catch (IOException e) { - ContributionResolveException ce = new ContributionResolveException(e); - error(context.getMonitor(), "ContributionResolveException", resolver, ce); - //throw ce; + + if(resolved.getLocation() == null) { + URL resource = null; + URI uri = URI.create(implementation.getLocation()); + Artifact parent = context.getArtifact(); + if (!uri.isAbsolute()) { + if (parent != null && parent.getURI() != null) { + URI base = URI.create("/" + parent.getURI()); + uri = base.resolve(uri); + // Remove the leading / to make artifact resolver happy + if (uri.toString().startsWith("/")) { + uri = URI.create(uri.toString().substring(1)); + } + } } - } else { + + + // The resource can be out of scope of the contribution root + if (parent != null && parent.getLocation() != null) { + try { + resource = new URL(new URL(parent.getLocation()), implementation.getLocation()); + + implementation.setLocationURL(resource); + + //introspect implementation + WidgetImplementationIntrospector widgetIntrospector = + new WidgetImplementationIntrospector(registry, implementation); + widgetIntrospector.introspectImplementation(); + + implementation.setUnresolved(false); + } catch (MalformedURLException e) { + ContributionResolveException ce = new ContributionResolveException(e); + error(context.getMonitor(), "ContributionResolveException", resolver, ce); + } + } + } + + if (implementation.isUnresolved()) { error(context.getMonitor(), "CouldNotResolveLocation", resolver, implementation.getLocation()); //throw new ContributionResolveException("Could not resolve implementation.widget location: " + implementation.getLocation()); }