Author: hibou
Date: Sat Aug 16 06:13:50 2008
New Revision: 686494

URL: http://svn.apache.org/viewvc?rev=686494&view=rev
Log:
IVYDE-94 :
 - add of the new scheme "project:"
 - backward compatibility is kept, file://./ivysettings.xml will be 
autimatically changed to project:///ivysettings.xml

Added:
    ant/ivy/ivyde/trunk/test/local-settings/   (with props)
    ant/ivy/ivyde/trunk/test/local-settings/.classpath
    ant/ivy/ivyde/trunk/test/local-settings/.project
    ant/ivy/ivyde/trunk/test/local-settings/ivy.xml   (with props)
    ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml   (with props)
    ant/ivy/ivyde/trunk/test/local-settings/src/
    ant/ivy/ivyde/trunk/test/project-dependent-settings/   (with props)
    ant/ivy/ivyde/trunk/test/project-dependent-settings/.classpath
    ant/ivy/ivyde/trunk/test/project-dependent-settings/.project
    ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml   (with props)
    ant/ivy/ivyde/trunk/test/project-dependent-settings/src/
Modified:
    ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
    
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java

Modified: ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt?rev=686494&r1=686493&r2=686494&view=diff
==============================================================================
--- ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt (original)
+++ ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/CHANGES.txt Sat Aug 16 
06:13:50 2008
@@ -6,6 +6,7 @@
 - NEW: settings files code completion support (IVYDE-22)
 - NEW: Option to resolve to local eclipse projects (IVYDE-89) (thanks to 
Antony James Wilkins and Matt Goldspink)
 - NEW: Add errors marker to the Ivy container (IVYDE-78)
+- NEW: Handle a project: scheme for the path of the ivysettings.xml (IVYDE-94)
 
 - IMPROVE: Retrieve after resolve feature does not clean target directory 
first (IVYDE-105)
 

Modified: 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java?rev=686494&r1=686493&r2=686494&view=diff
==============================================================================
--- 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java
 (original)
+++ 
ant/ivy/ivyde/trunk/org.apache.ivyde.eclipse/src/java/org/apache/ivyde/eclipse/cpcontainer/IvyClasspathContainerConfiguration.java
 Sat Aug 16 06:13:50 2008
@@ -37,14 +37,16 @@
 import org.apache.ivyde.eclipse.IvyPlugin;
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
 
 /**
  * path: org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER? 
ivyXmlPath=ivy.xml &confs=default
@@ -55,6 +57,10 @@
  */
 public class IvyClasspathContainerConfiguration {
 
+    private static final String PROJECT_SCHEME_PREFIX = "project://";
+
+    private static final int PROJECT_SCHEME_PREFIX_LENGTH = 
PROJECT_SCHEME_PREFIX.length();
+
     final IJavaProject javaProject;
 
     String ivyXmlPath;
@@ -168,7 +174,7 @@
             } else if (parameter[0].equals("confs")) {
                 confs = IvyClasspathUtil.split(value);
             } else if (parameter[0].equals("ivySettingsPath")) {
-                ivySettingsPath = value;
+                ivySettingsPath = readOldIvySettings(value);
                 isProjectSpecific = true;
             } else if (parameter[0].equals("acceptedTypes")) {
                 acceptedTypes = IvyClasspathUtil.split(value);
@@ -212,6 +218,33 @@
         }
     }
 
+    /**
+     * Read old configuration that were based on relative urls, like: 
"file://./ivysettings.xml".
+     * This kind of URL "project:///ivysettings.xml" should be used now.
+     * 
+     * @param value
+     *            the value to read
+     * @return
+     */
+    private String readOldIvySettings(String value) {
+        if (javaProject == null) {
+            return value;
+        }
+        URL url;
+        try {
+            url = new URL(value);
+        } catch (MalformedURLException e) {
+            return value;
+        }
+        File file = new File(url.getPath());
+        if (file.exists()) {
+            return value;
+        }
+        // the file doesn't exist, so try to find out if it is a relative path 
to the project.
+        file = new 
File(javaProject.getProject().getFile(url.getPath()).getLocation().toOSString());
+        return PROJECT_SCHEME_PREFIX + url.getPath();
+    }
+
     private void checkNonNullConf() {
         if (ivySettingsPath == null) {
             ivySettingsPath = 
IvyPlugin.getPreferenceStoreHelper().getIvySettingsPath();
@@ -355,6 +388,41 @@
             return ivy;
         }
 
+        if (ivySettingsPath.startsWith(PROJECT_SCHEME_PREFIX)) {
+            int pathIndex = ivySettingsPath.indexOf("/", 
PROJECT_SCHEME_PREFIX_LENGTH);
+            String projectName = 
ivySettingsPath.substring(PROJECT_SCHEME_PREFIX_LENGTH, pathIndex);
+            String path = ivySettingsPath.substring(pathIndex + 1);
+            if (projectName.equals("")) {
+                IFile f = javaProject.getProject().getFile(path);
+                File file = new File(f.getLocation().toOSString());
+                return getIvy(file);
+            } else {
+                try {
+                    IJavaProject[] javaProjects = JavaCore.create(
+                        
ResourcesPlugin.getWorkspace().getRoot()).getJavaProjects();
+                    int i;
+                    for (i = 0; i < javaProjects.length; i++) {
+                        if 
(javaProjects[i].getProject().getName().equals(projectName)) {
+                            break;
+                        }
+                    }
+                    if (i == javaProjects.length) {
+                        IvyDEException ex = new IvyDEException("Project '" + 
projectName
+                                + "' not found", "The project name '" + 
projectName + "' from '"
+                                + ivySettingsPath + "' was not found (" + 
this.toString() + ")",
+                                null);
+                        setConfStatus(ex);
+                        throw ex;
+                    }
+                    IFile f = javaProjects[i].getProject().getFile(path);
+                    File file = new File(f.getLocation().toOSString());
+                    return getIvy(file);
+                } catch (JavaModelException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+        }
         // before returning the found ivy, try to refresh it if the settings 
changed
         URL url;
         try {
@@ -368,40 +436,7 @@
         }
         if (url.getProtocol().startsWith("file")) {
             File file = new File(url.getPath());
-
-            if (!file.exists()) {
-                IvyDEException ex = new IvyDEException("Ivy settings file not 
found",
-                        "The Ivy settings file '" + ivySettingsPath + "' 
cannot be found ("
-                                + this.toString() + ")", null);
-                setConfStatus(ex);
-                throw ex;
-            }
-
-            if (file.lastModified() != ivySettingsLastModified) {
-                ivy = new Ivy();
-                if (ivySettingsLastModified == -1) {
-                    Message.info("\n\n");
-                } else {
-                    Message.info("\n\nIVYDE: ivysettings has changed, 
configuring ivy again\n");
-                }
-                try {
-                    ivy.configure(file);
-                } catch (ParseException e) {
-                    IvyDEException ex = new IvyDEException("Parsing error of 
the Ivy settings",
-                            "The ivy settings file '" + ivySettingsPath + "' 
could not be parsed ("
-                                    + this.toString() + ")", e);
-                    setConfStatus(ex);
-                    throw ex;
-                } catch (IOException e) {
-                    IvyDEException ex = new IvyDEException("Read error of the 
Ivy settings",
-                            "The ivy settings file '" + ivySettingsPath + "' 
could not be read ("
-                                    + this.toString() + ")", e);
-                    setConfStatus(ex);
-                    throw ex;
-                }
-                ivySettingsLastModified = file.lastModified();
-            }
-
+            return getIvy(file);
         } else {
             // an URL but not a file
             if (ivy == null || ivySettingsLastModified == -1) {
@@ -428,32 +463,48 @@
         return ivy;
     }
 
+    private Ivy getIvy(File file) throws IvyDEException {
+        if (!file.exists()) {
+            IvyDEException ex = new IvyDEException("Ivy settings file not 
found",
+                    "The Ivy settings file '" + ivySettingsPath + "' cannot be 
found ("
+                            + this.toString() + ")", null);
+            setConfStatus(ex);
+            throw ex;
+        }
+
+        if (file.lastModified() != ivySettingsLastModified) {
+            ivy = new Ivy();
+            if (ivySettingsLastModified == -1) {
+                Message.info("\n\n");
+            } else {
+                Message.info("\n\nIVYDE: ivysettings has changed, configuring 
ivy again\n");
+            }
+            try {
+                ivy.configure(file);
+            } catch (ParseException e) {
+                IvyDEException ex = new IvyDEException("Parsing error of the 
Ivy settings",
+                        "The ivy settings file '" + ivySettingsPath + "' could 
not be parsed ("
+                                + this.toString() + ")", e);
+                setConfStatus(ex);
+                throw ex;
+            } catch (IOException e) {
+                IvyDEException ex = new IvyDEException("Read error of the Ivy 
settings",
+                        "The ivy settings file '" + ivySettingsPath + "' could 
not be read ("
+                                + this.toString() + ")", e);
+                setConfStatus(ex);
+                throw ex;
+            }
+            ivySettingsLastModified = file.lastModified();
+        }
+
+        return ivy;
+    }
+
     public String getInheritedIvySettingsPath() {
         if (ivySettingsPath == null) {
             return IvyPlugin.getPreferenceStoreHelper().getIvySettingsPath();
         }
-        if (javaProject == null || ivySettingsPath.trim().length() == 0) {
-            return ivySettingsPath;
-        }
-        URL url;
-        try {
-            url = new URL(ivySettingsPath);
-        } catch (MalformedURLException e) {
-            throw new RuntimeException(e);
-        }
-        File file = new File(url.getPath());
-        if (file.exists()) {
-            return ivySettingsPath;
-        }
-        // the file doesn't exist, so try to find out if it is a relative path 
to the project.
-        IProject project = javaProject.getProject();
-        File loc = project.getLocation().toFile();
-        file = new File(loc, url.getPath());
-        try {
-            return file.toURL().toString();
-        } catch (MalformedURLException e) {
-            throw new RuntimeException(e);
-        }
+        return ivySettingsPath;
     }
 
     public Collection getInheritedAcceptedTypes() {

Propchange: ant/ivy/ivyde/trunk/test/local-settings/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Aug 16 06:13:50 2008
@@ -0,0 +1,2 @@
+bin
+

Added: ant/ivy/ivyde/trunk/test/local-settings/.classpath
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/local-settings/.classpath?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/local-settings/.classpath (added)
+++ ant/ivy/ivyde/trunk/test/local-settings/.classpath Sat Aug 16 06:13:50 2008
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="con" 
path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=*&amp;ivySettingsPath=project%3A%2F%2F%2Fivysettings.xml&amp;acceptedTypes=jar&amp;sourceTypes=source&amp;javadocTypes=javadoc&amp;sourceSuffixes=-source%2C-sources%2C-src&amp;javadocSuffixes=-javadoc%2C-javadocs%2C-doc%2C-docs&amp;doRetrieve=false&amp;retrievePattern=lib%2F%5Bconf%5D%2F%5Bartifact%5D.%5Bext%5D&amp;retrieveSync=false&amp;alphaOrder=false&amp;resolveInWorkspace=false"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>

Added: ant/ivy/ivyde/trunk/test/local-settings/.project
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/local-settings/.project?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/local-settings/.project (added)
+++ ant/ivy/ivyde/trunk/test/local-settings/.project Sat Aug 16 06:13:50 2008
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>ivydetest-local-settings</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>
+</projectDescription>

Added: ant/ivy/ivyde/trunk/test/local-settings/ivy.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/local-settings/ivy.xml?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/local-settings/ivy.xml (added)
+++ ant/ivy/ivyde/trunk/test/local-settings/ivy.xml Sat Aug 16 06:13:50 2008
@@ -0,0 +1,30 @@
+<!--
+   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.    
+-->
+<ivy-module version="1.0"> 
+       <info organisation="org.apache.ivyde" module="ivytest-local-settings">
+               <description>
+               </description>
+       </info>
+       <configurations>
+               <conf name="default" />
+       </configurations>
+       <dependencies>
+               <dependency org="myorg" name="mymodule" rev="1.1" 
conf="default" />
+       </dependencies>
+</ivy-module>

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivy.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivy.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivy.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml (added)
+++ ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml Sat Aug 16 06:13:50 
2008
@@ -0,0 +1,10 @@
+<ivysettings>
+    <caches defaultCacheDir="${ivy.settings.dir}/../cache-fakerepo" 
useOrigin="false" />
+    <settings defaultResolver="fakerepo" checkUpToDate="false" />
+    <resolvers>
+        <filesystem name="fakerepo">
+            <ivy 
pattern="${ivy.settings.dir}/../fakerepo/[organisation]/[module]/ivy-[revision].xml"/>
+            <artifact 
pattern="${ivy.settings.dir}/../fakerepo/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
+        </filesystem>
+    </resolvers>
+</ivysettings>

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/test/local-settings/ivysettings.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Propchange: ant/ivy/ivyde/trunk/test/project-dependent-settings/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Aug 16 06:13:50 2008
@@ -0,0 +1,2 @@
+bin
+

Added: ant/ivy/ivyde/trunk/test/project-dependent-settings/.classpath
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/project-dependent-settings/.classpath?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/project-dependent-settings/.classpath (added)
+++ ant/ivy/ivyde/trunk/test/project-dependent-settings/.classpath Sat Aug 16 
06:13:50 2008
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="con" 
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+       <classpathentry kind="con" 
path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=*&amp;ivySettingsPath=project%3A%2F%2Fivydetest-local-settings%2Fivysettings.xml&amp;acceptedTypes=jar&amp;sourceTypes=source&amp;javadocTypes=javadoc&amp;sourceSuffixes=-source%2C-sources%2C-src&amp;javadocSuffixes=-javadoc%2C-javadocs%2C-doc%2C-docs&amp;doRetrieve=false&amp;retrievePattern=lib%2F%5Bconf%5D%2F%5Bartifact%5D.%5Bext%5D&amp;retrieveSync=false&amp;alphaOrder=false&amp;resolveInWorkspace=false"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>

Added: ant/ivy/ivyde/trunk/test/project-dependent-settings/.project
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/project-dependent-settings/.project?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/project-dependent-settings/.project (added)
+++ ant/ivy/ivyde/trunk/test/project-dependent-settings/.project Sat Aug 16 
06:13:50 2008
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>ivydetest-project-dependent-settings</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>
+</projectDescription>

Added: ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml
URL: 
http://svn.apache.org/viewvc/ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml?rev=686494&view=auto
==============================================================================
--- ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml (added)
+++ ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml Sat Aug 16 
06:13:50 2008
@@ -0,0 +1,30 @@
+<!--
+   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.    
+-->
+<ivy-module version="1.0"> 
+       <info organisation="org.apache.ivyde" 
module="ivytest-project-dependent-settings">
+               <description>
+               </description>
+       </info>
+       <configurations>
+               <conf name="default" />
+       </configurations>
+       <dependencies>
+               <dependency org="myorg" name="mymodule" rev="1.1" 
conf="default" />
+       </dependencies>
+</ivy-module>

Propchange: ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: ant/ivy/ivyde/trunk/test/project-dependent-settings/ivy.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml


Reply via email to