Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed the AJDT weaving dependency so that we are more

compatible with Spring IDE and AJDT.

Copied the corresponding code from the AJDT plugin
to our aspects code. Kept the same two extension points.

Changed the update site to show only the Scala IDE
feature (binary and source). The weaving feature is
a nested feature in the SDT feature, because it needs its
own license.

Added LICENSE files. The Scala license for the project,
and the EPL for the org.scala-ide.sdt.aspects bundle.

Fixed #1000780.
(cherry picked from commit 6883910)
  • Loading branch information...
commit c9822465a88bf6f9aaa999ab998a22aa232246ac 1 parent 7517a03
Iulian Dragos authored December 02, 2011

Showing 24 changed files with 1,370 additions and 65 deletions. Show diff stats Hide diff stats

  1. 35  LICENSE
  2. 70  org.scala-ide.sdt.aspects/LICENSE
  3. 6  org.scala-ide.sdt.aspects/META-INF/MANIFEST.MF
  4. 3  org.scala-ide.sdt.aspects/META-INF/aop.xml
  5. 114  org.scala-ide.sdt.aspects/cuprovider.exsd
  6. 102  org.scala-ide.sdt.aspects/imagedescriptorselector.exsd
  7. 2  org.scala-ide.sdt.aspects/plugin.xml
  8. 1  org.scala-ide.sdt.aspects/pom.xml
  9. 37  org.scala-ide.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/configuration/IsWovenTester.aj
  10. 425  ...-ide.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/configuration/WeavingStateConfigurer.java
  11. 101  ...de.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/cuprovider/CompilationUnitProviderAspect.aj
  12. 89  ...dt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/cuprovider/CompilationUnitProviderRegistry.java
  13. 29  ...a-ide.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/cuprovider/ICompilationUnitProvider.java
  14. 37  ....sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/imagedescriptor/IImageDescriptorSelector.java
  15. 145  ...t.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/imagedescriptor/ImageDescriptorSelectorAspect.aj
  16. 89  ...pects/src/scala/tools/eclipse/contribution/weaving/jdt/imagedescriptor/ImageDescriptorSelectorRegistry.java
  17. 12  org.scala-ide.sdt.core/META-INF/MANIFEST.MF
  18. 4  org.scala-ide.sdt.core/plugin.xml
  19. 4  org.scala-ide.sdt.core/src/scala/tools/eclipse/diagnostic/DiagnosticDialog.scala
  20. 2  org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaCompilationUnitProvider.scala
  21. 2  org.scala-ide.sdt.core/src/scala/tools/eclipse/javaelements/ScalaImageDescriptorSelector.scala
  22. 15  org.scala-ide.sdt.feature/feature.xml
  23. 8  org.scala-ide.sdt.update-site/site.xml
  24. 103  org.scala-ide.sdt.weaving.feature/feature.xml
35  LICENSE
... ...
@@ -0,0 +1,35 @@
  1
+SCALA LICENSE
  2
+
  3
+Copyright (c) 2002-2011 EPFL, Lausanne, unless otherwise specified.
  4
+All rights reserved.
  5
+
  6
+This software was developed by the Programming Methods Laboratory of the
  7
+Swiss Federal Institute of Technology (EPFL), Lausanne, Switzerland.
  8
+
  9
+Permission to use, copy, modify, and distribute this software in source
  10
+or binary form for any purpose with or without fee is hereby granted,
  11
+provided that the following conditions are met:
  12
+
  13
+   1. Redistributions of source code must retain the above copyright
  14
+      notice, this list of conditions and the following disclaimer.
  15
+
  16
+   2. Redistributions in binary form must reproduce the above copyright
  17
+      notice, this list of conditions and the following disclaimer in the
  18
+      documentation and/or other materials provided with the distribution.
  19
+
  20
+   3. Neither the name of the EPFL nor the names of its contributors
  21
+      may be used to endorse or promote products derived from this
  22
+      software without specific prior written permission.
  23
+
  24
+
  25
+THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28
+ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35
+SUCH DAMAGE.
70  org.scala-ide.sdt.aspects/LICENSE
... ...
@@ -0,0 +1,70 @@
  1
+Eclipse Public License - v 1.0
  2
+
  3
+THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
  4
+
  5
+1. DEFINITIONS
  6
+
  7
+"Contribution" means:
  8
+
  9
+a) in the case of the initial Contributor, the initial code and documentation distributed under this Agreement, and
  10
+b) in the case of each subsequent Contributor:
  11
+i) changes to the Program, and
  12
+ii) additions to the Program;
  13
+where such changes and/or additions to the Program originate from and are distributed by that particular Contributor. A Contribution 'originates' from a Contributor if it was added to the Program by such Contributor itself or anyone acting on such Contributor's behalf. Contributions do not include additions to the Program which: (i) are separate modules of software distributed in conjunction with the Program under their own license agreement, and (ii) are not derivative works of the Program.
  14
+"Contributor" means any person or entity that distributes the Program.
  15
+
  16
+"Licensed Patents" mean patent claims licensable by a Contributor which are necessarily infringed by the use or sale of its Contribution alone or when combined with the Program.
  17
+
  18
+"Program" means the Contributions distributed in accordance with this Agreement.
  19
+
  20
+"Recipient" means anyone who receives the Program under this Agreement, including all Contributors.
  21
+
  22
+2. GRANT OF RIGHTS
  23
+
  24
+a) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, distribute and sublicense the Contribution of such Contributor, if any, and such derivative works, in source code and object code form.
  25
+b) Subject to the terms of this Agreement, each Contributor hereby grants Recipient a non-exclusive, worldwide, royalty-free patent license under Licensed Patents to make, use, sell, offer to sell, import and otherwise transfer the Contribution of such Contributor, if any, in source code and object code form. This patent license shall apply to the combination of the Contribution and the Program if, at the time the Contribution is added by the Contributor, such addition of the Contribution causes such combination to be covered by the Licensed Patents. The patent license shall not apply to any other combinations which include the Contribution. No hardware per se is licensed hereunder.
  26
+c) Recipient understands that although each Contributor grants the licenses to its Contributions set forth herein, no assurances are provided by any Contributor that the Program does not infringe the patent or other intellectual property rights of any other entity. Each Contributor disclaims any liability to Recipient for claims brought by any other entity based on infringement of intellectual property rights or otherwise. As a condition to exercising the rights and licenses granted hereunder, each Recipient hereby assumes sole responsibility to secure any other intellectual property rights needed, if any. For example, if a third party patent license is required to allow Recipient to distribute the Program, it is Recipient's responsibility to acquire that license before distributing the Program.
  27
+d) Each Contributor represents that to its knowledge it has sufficient copyright rights in its Contribution, if any, to grant the copyright license set forth in this Agreement.
  28
+3. REQUIREMENTS
  29
+
  30
+A Contributor may choose to distribute the Program in object code form under its own license agreement, provided that:
  31
+
  32
+a) it complies with the terms and conditions of this Agreement; and
  33
+b) its license agreement:
  34
+i) effectively disclaims on behalf of all Contributors all warranties and conditions, express and implied, including warranties or conditions of title and non-infringement, and implied warranties or conditions of merchantability and fitness for a particular purpose;
  35
+ii) effectively excludes on behalf of all Contributors all liability for damages, including direct, indirect, special, incidental and consequential damages, such as lost profits;
  36
+iii) states that any provisions which differ from this Agreement are offered by that Contributor alone and not by any other party; and
  37
+iv) states that source code for the Program is available from such Contributor, and informs licensees how to obtain it in a reasonable manner on or through a medium customarily used for software exchange.
  38
+When the Program is made available in source code form:
  39
+
  40
+a) it must be made available under this Agreement; and
  41
+b) a copy of this Agreement must be included with each copy of the Program.
  42
+Contributors may not remove or alter any copyright notices contained within the Program.
  43
+
  44
+Each Contributor must identify itself as the originator of its Contribution, if any, in a manner that reasonably allows subsequent Recipients to identify the originator of the Contribution.
  45
+
  46
+4. COMMERCIAL DISTRIBUTION
  47
+
  48
+Commercial distributors of software may accept certain responsibilities with respect to end users, business partners and the like. While this license is intended to facilitate the commercial use of the Program, the Contributor who includes the Program in a commercial product offering should do so in a manner which does not create potential liability for other Contributors. Therefore, if a Contributor includes the Program in a commercial product offering, such Contributor ("Commercial Contributor") hereby agrees to defend and indemnify every other Contributor ("Indemnified Contributor") against any losses, damages and costs (collectively "Losses") arising from claims, lawsuits and other legal actions brought by a third party against the Indemnified Contributor to the extent caused by the acts or omissions of such Commercial Contributor in connection with its distribution of the Program in a commercial product offering. The obligations in this section do not apply to any claims or Losses relating to any actual or alleged intellectual property infringement. In order to qualify, an Indemnified Contributor must: a) promptly notify the Commercial Contributor in writing of such claim, and b) allow the Commercial Contributor to control, and cooperate with the Commercial Contributor in, the defense and any related settlement negotiations. The Indemnified Contributor may participate in any such claim at its own expense.
  49
+
  50
+For example, a Contributor might include the Program in a commercial product offering, Product X. That Contributor is then a Commercial Contributor. If that Commercial Contributor then makes performance claims, or offers warranties related to Product X, those performance claims and warranties are such Commercial Contributor's responsibility alone. Under this section, the Commercial Contributor would have to defend claims against the other Contributors related to those performance claims and warranties, and if a court requires any other Contributor to pay any damages as a result, the Commercial Contributor must pay those damages.
  51
+
  52
+5. NO WARRANTY
  53
+
  54
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely responsible for determining the appropriateness of using and distributing the Program and assumes all risks associated with its exercise of rights under this Agreement , including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and unavailability or interruption of operations.
  55
+
  56
+6. DISCLAIMER OF LIABILITY
  57
+
  58
+EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  59
+
  60
+7. GENERAL
  61
+
  62
+If any provision of this Agreement is invalid or unenforceable under applicable law, it shall not affect the validity or enforceability of the remainder of the terms of this Agreement, and without further action by the parties hereto, such provision shall be reformed to the minimum extent necessary to make such provision valid and enforceable.
  63
+
  64
+If Recipient institutes patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Program itself (excluding combinations of the Program with other software or hardware) infringes such Recipient's patent(s), then such Recipient's rights granted under Section 2(b) shall terminate as of the date such litigation is filed.
  65
+
  66
+All Recipient's rights under this Agreement shall terminate if it fails to comply with any of the material terms or conditions of this Agreement and does not cure such failure in a reasonable period of time after becoming aware of such noncompliance. If all Recipient's rights under this Agreement terminate, Recipient agrees to cease use and distribution of the Program as soon as reasonably practicable. However, Recipient's obligations under this Agreement and any licenses granted by Recipient relating to the Program shall continue and survive.
  67
+
  68
+Everyone is permitted to copy and distribute copies of this Agreement, but in order to avoid inconsistency the Agreement is copyrighted and may only be modified in the following manner. The Agreement Steward reserves the right to publish new versions (including revisions) of this Agreement from time to time. No one other than the Agreement Steward has the right to modify this Agreement. The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation may assign the responsibility to serve as the Agreement Steward to a suitable separate entity. Each new version of the Agreement will be given a distinguishing version number. The Program (including Contributions) may always be distributed subject to the version of the Agreement under which it was received. In addition, after a new version of the Agreement is published, Contributor may elect to distribute the Program (including its Contributions) under the new version. Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives no rights or licenses to the intellectual property of any Contributor under this Agreement, whether expressly, by implication, estoppel or otherwise. All rights in the Program not expressly granted under this Agreement are reserved.
  69
+
  70
+This Agreement is governed by the laws of the State of New York and the intellectual property laws of the United States of America. No party to this Agreement will bring a legal action under this Agreement more than one year after the cause of action arose. Each party waives its rights to a jury trial in any resulting litigation.
6  org.scala-ide.sdt.aspects/META-INF/MANIFEST.MF
@@ -33,8 +33,11 @@ Eclipse-SupplementBundle:
33 33
 Bundle-ActivationPolicy: lazy
34 34
 Export-Package: 
35 35
  scala.tools.eclipse.contribution.weaving.jdt,
  36
+ scala.tools.eclipse.contribution.weaving.jdt.configuration,
36 37
  scala.tools.eclipse.contribution.weaving.jdt.builderoptions,
37 38
  scala.tools.eclipse.contribution.weaving.jdt.cfprovider,
  39
+ scala.tools.eclipse.contribution.weaving.jdt.cuprovider,
  40
+ scala.tools.eclipse.contribution.weaving.jdt.imagedescriptor,
38 41
  scala.tools.eclipse.contribution.weaving.jdt.core,
39 42
  scala.tools.eclipse.contribution.weaving.jdt.debug,
40 43
  scala.tools.eclipse.contribution.weaving.jdt.hierarchy,
@@ -48,3 +51,6 @@ Export-Package:
48 51
  scala.tools.eclipse.contribution.weaving.jdt.ui.javaeditor.formatter,
49 52
  scala.tools.eclipse.contribution.weaving.pde.ui
50 53
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
  54
+Import-Package: org.eclipse.equinox.frameworkadmin,
  55
+ org.eclipse.equinox.internal.simpleconfigurator.manipulator,
  56
+ org.eclipse.equinox.simpleconfigurator.manipulator
3  org.scala-ide.sdt.aspects/META-INF/aop.xml
... ...
@@ -1,8 +1,11 @@
1 1
 <aspectj>
2 2
 <aspects>
  3
+<aspect name="scala.tools.eclipse.contribution.weaving.jdt.configuration.IsWovenTester"/>
3 4
 <aspect name="org.eclipse.jdt.core.dom.ASTConverterAspect"/>
4 5
 <aspect name="scala.tools.eclipse.contribution.weaving.jdt.builderoptions.ScalaJavaBuilderAspect"/>
5 6
 <aspect name="scala.tools.eclipse.contribution.weaving.jdt.cfprovider.ClassFileProviderAspect"/>
  7
+<aspect name="scala.tools.eclipse.contribution.weaving.jdt.cuprovider.CompilationUnitProviderAspect"/>
  8
+<aspect name="scala.tools.eclipse.contribution.weaving.jdt.imagedescriptor.ImageDescriptorSelectorAspect"/>
6 9
 <aspect name="scala.tools.eclipse.contribution.weaving.jdt.core.BindingKeyAspect"/>
7 10
 <aspect name="scala.tools.eclipse.contribution.weaving.jdt.core.CompilationUnitProblemFinderAspect"/>
8 11
 <aspect name="scala.tools.eclipse.contribution.weaving.jdt.core.CompilationUnitNameAspect"/>
114  org.scala-ide.sdt.aspects/cuprovider.exsd
... ...
@@ -0,0 +1,114 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<!-- Schema file written by PDE -->
  3
+<schema targetNamespace="scala.tools.eclipse.contribution.weaving.jdt" xmlns="http://www.w3.org/2001/XMLSchema">
  4
+<annotation>
  5
+      <appInfo>
  6
+         <meta.schema plugin="scala.tools.eclipse.contribution.weaving.jdt" id="cuprovider" name="Compilation Unit Provider"/>
  7
+      </appInfo>
  8
+      <documentation>
  9
+         Provides an alternate implementation of org.eclipse.jdt.internal.core.CompilationUnit based on file extension.
  10
+      </documentation>
  11
+   </annotation>
  12
+
  13
+   <element name="extension">
  14
+      <annotation>
  15
+         <appInfo>
  16
+            <meta.element />
  17
+         </appInfo>
  18
+      </annotation>
  19
+      <complexType>
  20
+         <sequence minOccurs="1" maxOccurs="unbounded">
  21
+            <element ref="provider"/>
  22
+         </sequence>
  23
+         <attribute name="point" type="string" use="required">
  24
+            <annotation>
  25
+               <documentation>
  26
+                  
  27
+               </documentation>
  28
+            </annotation>
  29
+         </attribute>
  30
+         <attribute name="id" type="string">
  31
+            <annotation>
  32
+               <documentation>
  33
+                  
  34
+               </documentation>
  35
+            </annotation>
  36
+         </attribute>
  37
+         <attribute name="name" type="string">
  38
+            <annotation>
  39
+               <documentation>
  40
+                  
  41
+               </documentation>
  42
+               <appInfo>
  43
+                  <meta.attribute translatable="true"/>
  44
+               </appInfo>
  45
+            </annotation>
  46
+         </attribute>
  47
+      </complexType>
  48
+   </element>
  49
+
  50
+   <element name="provider">
  51
+      <annotation>
  52
+         <documentation>
  53
+            Declares the class of the compilation unit provider for compilation units with a given file extension.
  54
+         </documentation>
  55
+      </annotation>
  56
+      <complexType>
  57
+         <attribute name="class" type="string" use="required">
  58
+            <annotation>
  59
+               <documentation>
  60
+                  
  61
+               </documentation>
  62
+               <appInfo>
  63
+                  <meta.attribute kind="java" basedOn=":scala.tools.eclipse.contribution.weaving.jdt.cuprovider.ICompilationUnitProvider"/>
  64
+               </appInfo>
  65
+            </annotation>
  66
+         </attribute>
  67
+         <attribute name="file_extension" type="string" use="required">
  68
+            <annotation>
  69
+               <documentation>
  70
+                  
  71
+               </documentation>
  72
+            </annotation>
  73
+         </attribute>
  74
+      </complexType>
  75
+   </element>
  76
+
  77
+   <annotation>
  78
+      <appInfo>
  79
+         <meta.section type="since"/>
  80
+      </appInfo>
  81
+      <documentation>
  82
+         1.6.2
  83
+      </documentation>
  84
+   </annotation>
  85
+
  86
+   <annotation>
  87
+      <appInfo>
  88
+         <meta.section type="examples"/>
  89
+      </appInfo>
  90
+      <documentation>
  91
+         [Enter extension point usage example here.]
  92
+      </documentation>
  93
+   </annotation>
  94
+
  95
+   <annotation>
  96
+      <appInfo>
  97
+         <meta.section type="apiinfo"/>
  98
+      </appInfo>
  99
+      <documentation>
  100
+         [Enter API information here.]
  101
+      </documentation>
  102
+   </annotation>
  103
+
  104
+   <annotation>
  105
+      <appInfo>
  106
+         <meta.section type="implementation"/>
  107
+      </appInfo>
  108
+      <documentation>
  109
+         [Enter information about supplied implementation of this extension point.]
  110
+      </documentation>
  111
+   </annotation>
  112
+
  113
+
  114
+</schema>
102  org.scala-ide.sdt.aspects/imagedescriptorselector.exsd
... ...
@@ -0,0 +1,102 @@
  1
+<?xml version='1.0' encoding='UTF-8'?>
  2
+<!-- Schema file written by PDE -->
  3
+<schema targetNamespace="scala.tools.eclipse.contribution.weaving.jdt" xmlns="http://www.w3.org/2001/XMLSchema">
  4
+<annotation>
  5
+      <appinfo>
  6
+         <meta.schema plugin="scala.tools.eclipse.contribution.weaving.jdt" id="imagedescriptorselector" name="Image Descriptor Selector"/>
  7
+      </appinfo>
  8
+      <documentation>
  9
+         Selects an icon for a given element.  Enables the ability to override the default icons.
  10
+      </documentation>
  11
+   </annotation>
  12
+
  13
+   <element name="extension">
  14
+      <annotation>
  15
+         <appinfo>
  16
+            <meta.element />
  17
+         </appinfo>
  18
+      </annotation>
  19
+      <complexType>
  20
+         <sequence>
  21
+            <element ref="selector"/>
  22
+         </sequence>
  23
+         <attribute name="point" type="string" use="required">
  24
+            <annotation>
  25
+               <documentation>
  26
+                  
  27
+               </documentation>
  28
+            </annotation>
  29
+         </attribute>
  30
+         <attribute name="id" type="string">
  31
+            <annotation>
  32
+               <documentation>
  33
+                  
  34
+               </documentation>
  35
+            </annotation>
  36
+         </attribute>
  37
+         <attribute name="name" type="string">
  38
+            <annotation>
  39
+               <documentation>
  40
+                  
  41
+               </documentation>
  42
+               <appinfo>
  43
+                  <meta.attribute translatable="true"/>
  44
+               </appinfo>
  45
+            </annotation>
  46
+         </attribute>
  47
+      </complexType>
  48
+   </element>
  49
+
  50
+   <element name="selector">
  51
+      <complexType>
  52
+         <attribute name="class" type="string" use="required">
  53
+            <annotation>
  54
+               <documentation>
  55
+                  The class that creates alternative image descriptors.
  56
+               </documentation>
  57
+               <appinfo>
  58
+                  <meta.attribute kind="java" basedOn=":org.eclipse.contribution.jdt.imagedescriptor.IImageDescriptorSelector"/>
  59
+               </appinfo>
  60
+            </annotation>
  61
+         </attribute>
  62
+      </complexType>
  63
+   </element>
  64
+
  65
+   <annotation>
  66
+      <appinfo>
  67
+         <meta.section type="since"/>
  68
+      </appinfo>
  69
+      <documentation>
  70
+         1.6.2
  71
+      </documentation>
  72
+   </annotation>
  73
+
  74
+   <annotation>
  75
+      <appinfo>
  76
+         <meta.section type="examples"/>
  77
+      </appinfo>
  78
+      <documentation>
  79
+         [Enter extension point usage example here.]
  80
+      </documentation>
  81
+   </annotation>
  82
+
  83
+   <annotation>
  84
+      <appinfo>
  85
+         <meta.section type="apiinfo"/>
  86
+      </appinfo>
  87
+      <documentation>
  88
+         [Enter API information here.]
  89
+      </documentation>
  90
+   </annotation>
  91
+
  92
+   <annotation>
  93
+      <appinfo>
  94
+         <meta.section type="implementation"/>
  95
+      </appinfo>
  96
+      <documentation>
  97
+         [Enter information about supplied implementation of this extension point.]
  98
+      </documentation>
  99
+   </annotation>
  100
+
  101
+
  102
+</schema>
2  org.scala-ide.sdt.aspects/plugin.xml
@@ -6,4 +6,6 @@
6 6
    <extension-point id="indexerprovider" name="Indexer Provider" schema="indexerprovider.exsd"/>
7 7
    <extension-point id="formatterCleanUp" name="Formatter Clean Up" schema="formatterCleanUp.exsd"/>
8 8
    <extension-point id="method_verifier" name="Method Verifier" schema="methodVerifier.exsd"/>
  9
+   <extension-point id="cuprovider" name="Compilation Unit Provider" schema="cuprovider.exsd"/>
  10
+   <extension-point id="imagedescriptorselector" name="Image Descriptor Selector" schema="imagedescriptorselector.exsd"/>
9 11
 </plugin>
1  org.scala-ide.sdt.aspects/pom.xml
@@ -45,6 +45,7 @@
45 45
         <version>1.3</version>
46 46
         <executions>
47 47
           <execution>
  48
+            <phase>process-sources</phase>
48 49
             <id>compile</id>
49 50
             <configuration>
50 51
               <source>1.5</source>
37  org.scala-ide.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/configuration/IsWovenTester.aj
... ...
@@ -0,0 +1,37 @@
  1
+package scala.tools.eclipse.contribution.weaving.jdt.configuration;
  2
+
  3
+import org.eclipse.jdt.core.ToolFactory;
  4
+
  5
+/*******************************************************************************
  6
+ * Added to the Scala plugin to fix interoperability issues between the 
  7
+ * Spring IDE and the Scala IDE. This plugin now implements the cuprovider and
  8
+ * imagedescriptorselector extension points, previously provided by the 
  9
+ * JDT weaving plugin.
  10
+ * 
  11
+ *******************************************************************************/
  12
+
  13
+
  14
+/**
  15
+ * This aspect tests to see if the weaving service is properly installed.
  16
+ * 
  17
+ * @author andrew
  18
+ * @created Dec 3, 2008
  19
+ *
  20
+ */
  21
+public aspect IsWovenTester {
  22
+
  23
+    interface ScalaWeavingMarker { }
  24
+    
  25
+    /**
  26
+     * add a marker interface to an arbitrary class in JDT
  27
+     * later, we can see if the marker has been added.
  28
+     */
  29
+    declare parents : ToolFactory implements ScalaWeavingMarker;
  30
+    
  31
+    private static boolean weavingActive = new ToolFactory() instanceof ScalaWeavingMarker;
  32
+    
  33
+    public static boolean isWeavingActive() {
  34
+        return weavingActive;
  35
+    }
  36
+    
  37
+}
425  ...e.sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/configuration/WeavingStateConfigurer.java
... ...
@@ -0,0 +1,425 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2009 SpringSource and others.
  3
+ * All rights reserved. This program and the accompanying materials 
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ * 
  8
+ * Contributors:
  9
+ *     Andrew Eisenberg - initial API and implementation
  10
+ *******************************************************************************/
  11
+
  12
+/*******************************************************************************
  13
+ * Added to the Scala plugin to fix interoperability issues between the 
  14
+ * Spring IDE and the Scala IDE. This plugin now implements the cuprovider and
  15
+ * imagedescriptorselector extension points, previously provided by the 
  16
+ * JDT weaving plugin.
  17
+ * 
  18
+ *******************************************************************************/
  19
+
  20
+package scala.tools.eclipse.contribution.weaving.jdt.configuration;
  21
+
  22
+import java.io.BufferedReader;
  23
+import java.io.BufferedWriter;
  24
+import java.io.File;
  25
+import java.io.FileNotFoundException;
  26
+import java.io.FileReader;
  27
+import java.io.FileWriter;
  28
+import java.io.IOException;
  29
+import java.net.URI;
  30
+import java.net.URL;
  31
+
  32
+import org.eclipse.core.runtime.IStatus;
  33
+import org.eclipse.core.runtime.MultiStatus;
  34
+import org.eclipse.core.runtime.Platform;
  35
+import org.eclipse.core.runtime.Status;
  36
+import org.eclipse.equinox.frameworkadmin.BundleInfo;
  37
+import org.eclipse.equinox.internal.simpleconfigurator.manipulator.SimpleConfiguratorManipulatorImpl;
  38
+import org.eclipse.equinox.simpleconfigurator.manipulator.SimpleConfiguratorManipulator;
  39
+import org.eclipse.osgi.framework.internal.core.FrameworkProperties;
  40
+import org.eclipse.osgi.service.resolver.BundleDescription;
  41
+import org.eclipse.osgi.service.resolver.DisabledInfo;
  42
+import org.eclipse.osgi.service.resolver.State;
  43
+import org.osgi.framework.Bundle;
  44
+import org.osgi.framework.BundleContext;
  45
+import org.osgi.framework.Version;
  46
+
  47
+import scala.tools.eclipse.contribution.weaving.jdt.ScalaJDTWeavingPlugin;
  48
+import scala.tools.eclipse.contribution.weaving.jdt.configuration.IsWovenTester;
  49
+
  50
+/**
  51
+ * @author Andrew Eisenberg
  52
+ * @created Jan 19, 2009
  53
+ *
  54
+ * Object that controls the state of the Equinox aspects weaver
  55
+ */
  56
+public class WeavingStateConfigurer {
  57
+    
  58
+    private final static Version MIN_WEAVER_VERSION = new Version(1, 6, 1);
  59
+
  60
+    private final static boolean IS_WEAVING = IsWovenTester.isWeavingActive();
  61
+
  62
+    
  63
+    public String getWeaverVersionInfo() {
  64
+        BundleDescription weaver = 
  65
+            Platform.getPlatformAdmin().getState(false).
  66
+            getBundle("org.aspectj.weaver", null);
  67
+        
  68
+        if (weaver != null) {
  69
+            if (MIN_WEAVER_VERSION.compareTo(weaver.getVersion()) <= 0) {
  70
+                return "";
  71
+//                return "AspectJ weaver version " + weaver.getVersion().toString() + " OK!";
  72
+            } else {
  73
+                return "No compatible version of org.aspectj.weaver found.  " +
  74
+                "JDT Weaving requires 1.6.1 or higher.  Found version " +
  75
+                weaver.getVersion();
  76
+            }
  77
+        } else {
  78
+            return "org.aspectj.weaver not installed.  JDT Weaving requires 1.6.3 or higher.";
  79
+        }
  80
+    }
  81
+    
  82
+    public IStatus changeWeavingState(boolean becomeEnabled) {
  83
+        // now, weaving service is controlled by 
  84
+        // starting and stopping weaving.aspectj bundle
  85
+        // this method is used only to ensure the hook exists
  86
+        IStatus success;
  87
+        boolean isCurrentlyWeaving = false;
  88
+        try {
  89
+            isCurrentlyWeaving = currentConfigStateIsWeaving();
  90
+        } catch (Exception e) {
  91
+            ScalaJDTWeavingPlugin.logException(e);
  92
+        }
  93
+        if (becomeEnabled && !isCurrentlyWeaving) {
  94
+            success = changeConfigDotIni(becomeEnabled);
  95
+        } else {
  96
+            // do nothing
  97
+            success = Status.OK_STATUS;
  98
+        }
  99
+        
  100
+        
  101
+        IStatus success2 = changeAutoStartupAspectsBundle(becomeEnabled);
  102
+        
  103
+        IStatus success3 = changeSimpleConfiguratorManipulator(becomeEnabled);
  104
+        if (success.getSeverity() >= IStatus.ERROR || success2.getSeverity() >= IStatus.ERROR || success3.getSeverity() >= IStatus.ERROR) {
  105
+            return new MultiStatus(ScalaJDTWeavingPlugin.ID, IStatus.ERROR, 
  106
+                    new IStatus[] { success, success2, success3, getInstalledBundleInformation() }, "Could not "
  107
+                    + (becomeEnabled ? "ENABLED" : "DISABLED") + " weaving service",
  108
+                    null);
  109
+        } else if (success.getSeverity() >= IStatus.WARNING || success2.getSeverity() >= IStatus.WARNING || success3.getSeverity() >= IStatus.WARNING) {
  110
+            return new MultiStatus(ScalaJDTWeavingPlugin.ID, IStatus.WARNING, 
  111
+                    new IStatus[] { success, success2, success3, getInstalledBundleInformation() }, "Weaving service "
  112
+                    + (becomeEnabled ? "ENABLED" : "DISABLED") + " with warnings",
  113
+                    null);
  114
+        } else {
  115
+            // if successful, also schedule to ask for reindexing on startup
  116
+            if (becomeEnabled) {
  117
+              // We don't ask to reindex (anyway, the Scala nature was not part of the 'weavable natures' list) 
  118
+              // while using the JDT weaving plugin
  119
+//                JDTWeavingPreferences.setAskToReindex(true);
  120
+            }
  121
+            return new MultiStatus(ScalaJDTWeavingPlugin.ID, IStatus.OK, 
  122
+                    new IStatus[] { getInstalledBundleInformation() },
  123
+                    "Weaving service successfully "
  124
+                    + (becomeEnabled ? "ENABLED" : "DISABLED"), null);
  125
+        } 
  126
+    }
  127
+
  128
+    /**
  129
+     * Change the default startup state of the aspectj weaving bundle using the 
  130
+     * {@link SimpleConfiguratorManipulator}
  131
+     * @param becomeEnabled if true, then ensure that the bundle is set to autostarted 
  132
+     * if false, the bundle should not be autostarted
  133
+     * @return {@link Status#OK_STATUS} if all goes well, otherwise returns the exception
  134
+     */
  135
+    private IStatus changeSimpleConfiguratorManipulator(boolean becomeEnabled) {
  136
+        SimpleConfiguratorManipulator manipulator = new SimpleConfiguratorManipulatorImpl();
  137
+        BundleContext bundleContext = null;
  138
+        try {
  139
+            bundleContext = Platform.getBundle(ScalaJDTWeavingPlugin.ID).getBundleContext();
  140
+        } catch (Exception e) {
  141
+            return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Cannot get bundleContext", e);
  142
+        }
  143
+        if (bundleContext == null) {
  144
+            return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Cannot get bundleContext", new Exception());
  145
+        }
  146
+        
  147
+        try {
  148
+            BundleInfo[] infos = manipulator.loadConfiguration(bundleContext, null);
  149
+            BundleInfo weavingInfo = null;
  150
+            for (BundleInfo info : infos) {
  151
+                if (info.getSymbolicName().equals("org.eclipse.equinox.weaving.aspectj")) {
  152
+                    weavingInfo = info;
  153
+                    break;
  154
+                }
  155
+            }
  156
+            if (weavingInfo == null) {
  157
+                return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Could not find equinox aspects bundle", new Exception());
  158
+            }
  159
+            
  160
+            weavingInfo.setMarkedAsStarted(becomeEnabled);
  161
+            
  162
+            URL configURL = Platform.getConfigurationLocation().getURL();
  163
+            if (configURL == null || !"file".equals(configURL.getProtocol())) {
  164
+                throw new IOException("Platform configuration location is not found: " + configURL);
  165
+            }
  166
+            
  167
+            URL installURL = Platform.getInstallLocation().getURL();
  168
+            if (installURL == null || !"file".equals(installURL.getProtocol())) {
  169
+                throw new IOException("Platform install location is not found: " + installURL);
  170
+            }
  171
+            manipulator.saveConfiguration(infos, new File(configURL.getFile() + SimpleConfiguratorManipulator.BUNDLES_INFO_PATH), new File(installURL.getFile()).toURI());
  172
+            
  173
+            return Status.OK_STATUS;
  174
+        } catch (IOException e) {
  175
+            return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Cannot load configuration", e);
  176
+        }
  177
+    }
  178
+
  179
+    private IStatus getInstalledBundleInformation() {
  180
+        StringBuffer sb = new StringBuffer();
  181
+        sb.append("Information on currently installed bundles:\n");
  182
+        
  183
+        Bundle[] allEABundles = Platform.getBundles("org.eclipse.equinox.weaving.aspectj", null); //$NON-NLS-1$
  184
+        if (allEABundles != null) {
  185
+            for (int i = 0; i < allEABundles.length; i++) {
  186
+                Bundle bundle = allEABundles[i];
  187
+                sb.append(createBundleNameString(bundle));
  188
+            }
  189
+        } else {
  190
+            sb.append("org.eclipse.equinox.weaving.aspectj not installed\n");
  191
+        }
  192
+        
  193
+        Bundle[] allWeaverBundles = Platform.getBundles("org.aspectj.weaver", null);
  194
+        if (allWeaverBundles != null) {
  195
+            for (int i = 0; i < allWeaverBundles.length; i++) {
  196
+                Bundle bundle = allWeaverBundles[i];
  197
+                sb.append(createBundleNameString(bundle));
  198
+            }
  199
+        } else {
  200
+            sb.append("org.aspectj.weaver not installed\n");
  201
+        }
  202
+        
  203
+        allWeaverBundles = Platform.getBundles("com.springsource.org.aspectj.weaver", null);
  204
+        if (allWeaverBundles != null) {
  205
+            for (int i = 0; i < allWeaverBundles.length; i++) {
  206
+                Bundle bundle = allWeaverBundles[i];
  207
+                sb.append(createBundleNameString(bundle));
  208
+            }
  209
+        } else {
  210
+            sb.append("com.springsource.org.aspectj.weaver not installed\n");
  211
+        }
  212
+        
  213
+        Bundle[] allWeavingHooks = Platform.getBundles("org.eclipse.equinox.weaving.hook", null);
  214
+        if (allWeavingHooks != null) {
  215
+            for (int i = 0; i < allWeavingHooks.length; i++) {
  216
+                Bundle bundle = allWeavingHooks[i];
  217
+                sb.append(createBundleNameString(bundle));
  218
+            }
  219
+        } else {
  220
+            sb.append("org.eclipse.equinox.weaving.hook not installed\n");
  221
+        }
  222
+
  223
+        
  224
+        return new Status(IStatus.INFO, ScalaJDTWeavingPlugin.ID, sb.toString());
  225
+    }
  226
+
  227
+    private StringBuffer createBundleNameString(Bundle bundle) {
  228
+        StringBuffer sb = new StringBuffer();
  229
+        sb.append(bundle.getSymbolicName()).append("_")
  230
+            .append(bundle.getVersion()).append(" : ID ")
  231
+            .append(bundle.getBundleId()).append(": STATE ");
  232
+        switch (bundle.getState()) {
  233
+            case Bundle.ACTIVE:
  234
+                sb.append("ACTIVE");
  235
+                break;
  236
+
  237
+            case Bundle.INSTALLED:
  238
+                sb.append("INSTALLED");
  239
+                break;
  240
+
  241
+            case Bundle.RESOLVED:
  242
+                sb.append("RESOLVED");
  243
+                break;
  244
+
  245
+            case Bundle.STARTING:
  246
+                sb.append("STARTING");
  247
+                break;
  248
+
  249
+            case Bundle.STOPPING:
  250
+                sb.append("STOPPING");
  251
+                break;
  252
+        }
  253
+        
  254
+        sb.append("\n");
  255
+        return sb;
  256
+    }
  257
+    
  258
+    private IStatus changeAutoStartupAspectsBundle(boolean becomeEnabled) {
  259
+        
  260
+        // get all versions of weaving.aspectj in the platform.  
  261
+        // disable and stop all but the most receent
  262
+        Bundle[] allEABundles = Platform.getBundles("org.eclipse.equinox.weaving.aspectj", null); //$NON-NLS-1$
  263
+        if (allEABundles == null || allEABundles.length == 0) {
  264
+            return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Could not find org.eclipse.equinox.weaving.aspectj" +
  265
+            		" so weaving service cannot be " + 
  266
+            		(becomeEnabled ? "enabled" : "disabled") + ".");
  267
+        }
  268
+        try {
  269
+            State state = Platform.getPlatformAdmin().getState(false);
  270
+            if (becomeEnabled) {
  271
+                allEABundles[0].start();
  272
+                for (int i = 1; i < allEABundles.length; i++) {
  273
+                    allEABundles[i].stop();
  274
+                    BundleDescription desc = state.getBundle(allEABundles[i].getBundleId());
  275
+                    DisabledInfo info = new DisabledInfo(
  276
+                            "org.eclipse.contribution.weaving.jdt", //$NON-NLS-1$
  277
+                            "Disabled older version of Equinox Aspects", desc); //$NON-NLS-1$
  278
+                    try {
  279
+                        Platform.getPlatformAdmin().addDisabledInfo(info);
  280
+                    } catch (IllegalArgumentException e) {
  281
+                        // can ignore
  282
+                    }
  283
+                }
  284
+            } else {
  285
+                for (int i = 0; i < allEABundles.length; i++) {
  286
+                    switch(allEABundles[i].getState()) {
  287
+                        case Bundle.ACTIVE:
  288
+                        case Bundle.INSTALLED:
  289
+                        case Bundle.STARTING:
  290
+                        case Bundle.RESOLVED:
  291
+                            allEABundles[i].stop();
  292
+                    }
  293
+                }
  294
+            }
  295
+            
  296
+            return Status.OK_STATUS;
  297
+        } catch (Exception e) {
  298
+            return new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Error occurred in setting org.eclipse.equinox.weaving.aspectj to autostart" +
  299
+                    " so weaving service cannot be " + 
  300
+                    (becomeEnabled ? "enabled" : "disabled") + ".", e);
  301
+        }
  302
+    }
  303
+
  304
+    private IStatus changeConfigDotIni(boolean becomeEnabled) {
  305
+        
  306
+        // a little crude find the config.ini go through each 
  307
+        // line and filter out the osgi.framework.extensions line
  308
+        IStatus success;
  309
+        try {
  310
+            String configArea = getConfigArea();
  311
+            File f = new File(new URI(configArea));
  312
+            if (f.canWrite()) {
  313
+                BufferedReader br = new BufferedReader(new FileReader(f));
  314
+                
  315
+                String newConfig = internalChangeWeavingState(becomeEnabled, br);
  316
+                BufferedWriter bw = new BufferedWriter(new FileWriter(f));
  317
+                bw.write(newConfig);
  318
+                bw.close();
  319
+    
  320
+                
  321
+                if (becomeEnabled == currentConfigStateIsWeaving()) {
  322
+                    success = Status.OK_STATUS;
  323
+                } else {
  324
+                    success = new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, "Could not add or remove org.eclipse.equinox.weaving.hook as a framework adaptor.");
  325
+                }
  326
+            } else {
  327
+                // cannot write to file...most likely this is because the config.ini 
  328
+                // is in a global location that is read-only.
  329
+                success = new Status(IStatus.WARNING, ScalaJDTWeavingPlugin.ID, "Could not add " +
  330
+                		"'osgi.framework.extensions=org.eclipse.equinox.weaving.hook'\n " +
  331
+                		"to the config.ini because the file is read-only.  Weaving may not be enabled.");
  332
+            }
  333
+        } catch (Exception e) {
  334
+            success = new Status(IStatus.ERROR, ScalaJDTWeavingPlugin.ID, e
  335
+                    .getMessage(), e);
  336
+        }
  337
+        return success;
  338
+    }
  339
+
  340
+    protected String internalChangeWeavingState(boolean becomeEnabled, 
  341
+            BufferedReader br) throws IOException {
  342
+        StringBuffer sb = new StringBuffer();
  343
+        String line = null;
  344
+        boolean hookAdded = false;
  345
+        while ((line = br.readLine()) != null) {
  346
+            if (line.trim().startsWith("osgi.framework.extensions=")) {
  347
+                String[] split = line.split("=");
  348
+                if (split.length > 1) {
  349
+                    String[] extNames = split[1].split(",");
  350
+                    boolean shouldAddLine = false;
  351
+                    StringBuffer sb2 = new StringBuffer();
  352
+                    sb2.append("osgi.framework.extensions=");
  353
+                    for (int i = 0; i < extNames.length; i++) {
  354
+                        String extName = extNames[i].trim();
  355
+                        // don't add hook, we add it later in needed
  356
+                        if (!extName.equals("org.eclipse.equinox.weaving.hook")) {
  357
+                            sb2.append(extName + ",");
  358
+                            shouldAddLine = true;
  359
+                        }
  360
+                    }
  361
+                    if (shouldAddLine) {
  362
+                        if (becomeEnabled) {
  363
+                            sb2.append("org.eclipse.equinox.weaving.hook\n");
  364
+                            hookAdded = true;
  365
+                        } else {
  366
+                            // replace last comma
  367
+                            sb2.replace(sb2.length() - 1, sb2.length(), "\n");
  368
+                        }
  369
+                        sb.append(sb2);
  370
+                    }
  371
+                }
  372
+            } else {
  373
+                sb.append(line + "\n");
  374
+            }
  375
+        }
  376
+
  377
+        // if line didn't exist before
  378
+        if (becomeEnabled && !hookAdded) {
  379
+            sb.append("osgi.framework.extensions=org.eclipse.equinox.weaving.hook\n");
  380
+        }
  381
+        try {
  382
+            br.close();
  383
+        } catch (IOException e) {
  384
+            ScalaJDTWeavingPlugin.logException(e);
  385
+        }
  386
+        return sb.toString();
  387
+    }
  388
+
  389
+    private String getConfigArea() {
  390
+        String configArea = FrameworkProperties.getProperty("osgi.configuration.area") + "config.ini";
  391
+        configArea = configArea.replaceAll(" ", "%20");
  392
+        return configArea;
  393
+    }
  394
+    
  395
+    
  396
+    public boolean currentConfigStateIsWeaving() throws Exception {
  397
+        String configArea = getConfigArea();
  398
+        
  399
+        File f = new File(new URI(configArea));
  400
+        if (! f.exists()) {
  401
+            throw new FileNotFoundException("Could not find config file: " + f.getAbsolutePath());
  402
+        }
  403
+        if (! f.canWrite()) {
  404
+            throw new IOException("Could not write to config file: " + f.getAbsolutePath());
  405
+        }
  406
+        BufferedReader br = new BufferedReader(new FileReader(f));
  407
+        return internalCurrentConfigStateIsWeaving(br);
  408
+    }
  409
+
  410
+    protected boolean internalCurrentConfigStateIsWeaving(BufferedReader br)
  411
+            throws IOException {
  412
+        String line = null;
  413
+        while ((line = br.readLine()) != null) {
  414
+            if (line.trim().startsWith("osgi.framework.extensions=") &&
  415
+                    line.contains("org.eclipse.equinox.weaving.hook")) {
  416
+                return true;
  417
+            }
  418
+        }
  419
+        return false;
  420
+    }
  421
+    
  422
+    public boolean isWeaving() {
  423
+        return IS_WEAVING;
  424
+    }
  425
+}
101  ...sdt.aspects/src/scala/tools/eclipse/contribution/weaving/jdt/cuprovider/CompilationUnitProviderAspect.aj
... ...
@@ -0,0 +1,101 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2008 SpringSource and others.
  3
+ * All rights reserved. This program and the accompanying materials 
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ * 
  8
+ * Contributors:
  9
+ *      SpringSource
  10
+ *      Andrew Eisenberg (initial implementation)
  11
+ *******************************************************************************/
  12
+package scala.tools.eclipse.contribution.weaving.jdt.cuprovider;
  13
+
  14
+/*******************************************************************************
  15
+ * Added to the Scala plugin to fix interoperability issues between the 
  16
+ * Spring IDE and the Scala IDE. This plugin now implements the cuprovider and
  17
+ * imagedescriptorselector extension points, previously provided by the 
  18
+ * JDT weaving plugin.
  19
+ * 
  20
+ *******************************************************************************/
  21
+
  22
+
  23
+import org.eclipse.jdt.core.WorkingCopyOwner;
  24
+import org.eclipse.jdt.internal.core.CompilationUnit;
  25
+import org.eclipse.jdt.internal.core.PackageFragment;
  26
+
  27
+import scala.tools.eclipse.contribution.weaving.jdt.ScalaJDTWeavingPlugin;
  28
+
  29
+/**
  30
+ * Captures all creations of {@link CompilationUnit}.  Uses a registry to determine 
  31
+ * what kind of CompilationUnit to create.  Clients can provide their own
  32
+ * CompilationUnit by using the cuprovider extension and associating a CompilationUnit
  33
+ * subclass with a file extension.
  34
+ * 
  35
+ * @author andrew
  36
+ * @created Dec 2, 2008
  37
+ */
  38
+public aspect CompilationUnitProviderAspect {
  39
+    
  40
+    /**
  41
+     * Captures creations of Compilation units
  42
+     */
  43
+    pointcut compilationUnitCreations(PackageFragment parent, String name, WorkingCopyOwner owner) : 
  44
+            call(public CompilationUnit.new(PackageFragment, String, WorkingCopyOwner)) &&
  45
+            (
  46
+                    within(org.eclipse.jdt..*) ||
  47
+                    within(org.codehaus.jdt.groovy.integration.internal.*) ||  // Captures GroovyLanguageSupport if groovy plugin is installed
  48
+                    within(org.codehaus.jdt.groovy.integration.*) // Captures DefaultLanguageSupport if groovy plugin is installed
  49
+            ) &&
  50
+            args(parent, name, owner);
  51
+
  52
+    CompilationUnit around(PackageFragment parent, String name, WorkingCopyOwner owner) : 
  53
+        compilationUnitCreations(parent, name, owner) {
  54
+        String newName = trimName(name);
  55
+        String extension = findExtension(newName);
  56
+        ICompilationUnitProvider provider = 
  57
+            CompilationUnitProviderRegistry.getInstance().getProvider(extension);
  58
+        if (provider != null) {
  59
+            try {
  60
+                return provider.create(parent, newName, owner);
  61
+            } catch (Throwable t) {
  62
+                ScalaJDTWeavingPlugin.logException(t);
  63
+            }
  64
+        }        
  65
+        return proceed(parent, name, owner);
  66
+    }
  67
+
  68
+    /**
  69
+     * hacks off any excess parts of the compilation unit name that indicate
  70
+     * extra characters were included in the name
  71
+     * 
  72
+     * @param original the original name of the compilation unit
  73
+     * @return new name trimmed to ensure that all trailing memento parts are removed
  74
+     */
  75
+    private String trimName(String original) {
  76
+        String noo = original;
  77
+        int extensionIndex = original.indexOf('.') + 1;
  78
+        if (extensionIndex >= 0) {
  79
+            int mementoIndex = extensionIndex;
  80
+            while (mementoIndex < original.length() && (Character.isJavaIdentifierPart(original.charAt(mementoIndex)) ||
  81
+                    // Bug 352871 - Scala files may have more than one dot in them
  82
+                    original.charAt(mementoIndex) == '.')) {
  83
+                mementoIndex++;
  84
+            }
  85
+            noo = original.substring(0, mementoIndex);
  86
+        }
  87
+        return noo;
  88
+    }
  89
+    
  90
+    private String findExtension(String name) {
  91
+        int extensionIndex = name.lastIndexOf('.') + 1;
  92
+        String extension;
  93
+        if (extensionIndex > 0) {
  94
+            extension = name.substring(extensionIndex);
  95
+        } else {
  96
+            extension = ""; //$NON-NLS-1$
  97
+        }
  98
+        return extension;
  99
+    }