You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by li...@apache.org on 2007/10/08 20:50:56 UTC
svn commit: r582932 [1/3] - in
/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources:
./ META-INF/ schema/ src/ src/org/ src/org/apache/ src/org/apache/geronimo/
src/org/apache/geronimo/devtools/ src/org/apache/geronimo/devtools...
Author: linsun
Date: Mon Oct 8 11:50:53 2007
New Revision: 582932
URL: http://svn.apache.org/viewvc?rev=582932&view=rev
Log:
update the sources plugin for GERONIMODEVTOOLS-221
Added:
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/MANIFEST.MF
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/migrations.exsd
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/NodesVisitor.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/Anybody.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/DigestCallback.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/GeronimoLoginModule.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/GeronimoSimpleGroup.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/Nobody.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/compatibility/PasswordHasher.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/AbsoluteNameSolver.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/BlockVisitor.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/EjbEnvJavaMigration.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/MethodsVisitor.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/NameSolvingException.java (with props)
geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/environment/VarContext.java (with props)
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath Mon Oct 8 11:50:53 2007
@@ -0,0 +1,22 @@
+<classpath>
+ <classpathentry kind="src" path="." including="plugin.xml" excluding="**/*.java"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/tomcat/jasper-compiler/5.5.15/jasper-compiler-5.5.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.12/log4j-1.2.12.jar"/>
+ <classpathentry kind="src" path="/org.apache.geronimo.j2g.jasper"/>
+ <classpathentry kind="var" path="M2_REPO/commons-el/commons-el/1.0/commons-el-1.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-jsp_2.0_spec/1.1/geronimo-jsp_2.0_spec-1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/logkit/logkit/1.0.1/logkit-1.0.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/eclipse/jdt/core/3.2.0.666/core-3.2.0.666.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/apache/geronimo/specs/geronimo-servlet_2.4_spec/1.1.1/geronimo-servlet_2.4_spec-1.1.1.jar"/>
+ <classpathentry kind="var" path="M2_REPO/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar"/>
+ <classpathentry kind="src" path="/org.apache.geronimo.j2g.common"/>
+ <classpathentry kind="var" path="M2_REPO/tomcat/jasper-runtime/5.5.15/jasper-runtime-5.5.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.3/servlet-api-2.3.jar"/>
+ <classpathentry kind="var" path="M2_REPO/javax/servlet/jsp-api/2.0/jsp-api-2.0.jar"/>
+ <classpathentry kind="var" path="M2_REPO/tomcat/jasper-compiler-jdt/5.5.15/jasper-compiler-jdt-5.5.15.jar"/>
+ <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar"/>
+</classpath>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.classpath
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project Mon Oct 8 11:50:53 2007
@@ -0,0 +1,23 @@
+<projectDescription>
+ <name>org.apache.geronimo.j2g.sources</name>
+ <comment>JBoss to Geronimo Conversion Tool</comment>
+ <projects>
+ <project>org.apache.geronimo.j2g.jasper</project>
+ <project>org.apache.geronimo.j2g.common</project>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/.project
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/MANIFEST.MF?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/MANIFEST.MF (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/META-INF/MANIFEST.MF Mon Oct 8 11:50:53 2007
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: J2G Source Identification Plug-in
+Bundle-SymbolicName: org.apache.geronimo.devtools.j2g.sources;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Localization: plugin
+Require-Bundle: org.apache.geronimo.devtools.j2g.common,
+ org.apache.geronimo.devtools.j2g.jasper,
+ org.apache.geronimo.devtools.j2g.util,
+ org.eclipse.core.resources,
+ org.eclipse.core.runtime,
+ org.eclipse.jdt,
+ org.eclipse.jdt.core,
+ org.eclipse.jdt.launching,
+ org.eclipse.jface.text
+Bundle-Vendor: Apache.org
+Bundle-ClassPath: .,
+ lib/geronimo-security-1.1.jar,
+ lib/geronimo-util-1.1.jar
+Export-Package: org.apache.geronimo.devtools.j2g.sources,
+ org.apache.geronimo.devtools.j2g.sources.dependence,
+ org.apache.geronimo.devtools.j2g.sources.dependence.compatibility,
+ org.apache.geronimo.devtools.j2g.sources.environment
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties Mon Oct 8 11:50:53 2007
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+ output.. = bin/
+source.. = src/
+bin.includes = META-INF/,\
+ plugin.xml,\
+ .,\
+ lib/
+
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/build.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml Mon Oct 8 11:50:53 2007
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<!--
+ ~ 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.
+ -->
+<plugin>
+ <extension-point id="migrations" name="Java Sources Migration Extension Point" schema="schema/migrations.exsd"/>
+ <extension
+ id="tool"
+ name="Source Identification Tool"
+ point="org.eclipse.core.runtime.applications">
+ <application>
+ <run class="org.apache.geronimo.devtools.j2g.sources.SourceIdentificationTool"/>
+ </application>
+ </extension>
+ <extension
+ point="org.apache.geronimo.devtools.j2g.sources.migrations">
+ <migration
+ class="org.apache.geronimo.devtools.j2g.sources.dependence.DependenceJavaMigration">
+ </migration>
+ </extension>
+ <extension
+ point="org.apache.geronimo.devtools.j2g.sources.migrations">
+ <migration
+ class="org.apache.geronimo.devtools.j2g.sources.environment.EjbEnvJavaMigration">
+ </migration>
+ </extension>
+</plugin>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/plugin.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml Mon Oct 8 11:50:53 2007
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<!-- $Rev: 581360 $ $Date: 2007-10-02 15:32:28 -0400 (Tue, 02 Oct 2007) $ -->
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.geronimo.devtools.j2g</groupId>
+ <artifactId>plugins</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.geronimo.devtools.j2g.sources</artifactId>
+ <packaging>jar</packaging>
+ <name>${artifactId}</name>
+ <build>
+ <resources>
+ <resource>
+ <directory>.</directory>
+ <includes>
+ <include>plugin.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>lib</directory>
+ <targetPath>lib</targetPath>
+ <includes>
+ <include>*.jar</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>../../src/main/resources/properties/org.apache.geronimo.devtools.j2g.sources.dependence</directory>
+ <targetPath>.</targetPath>
+ <includes>
+ <include>class_analogies.properties</include>
+ <include>compatible_sources.properties</include>
+ <include>default_jars.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>../../src/main/resources/properties/org.apache.geronimo.devtools.j2g.sources.environment</directory>
+ <targetPath>.</targetPath>
+ <includes>
+ <include>beans-interfaces.properties</include>
+ <include>beans-references.properties</include>
+ <include>beans-types.properties</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ <configuration>
+ <artifactItems>
+ <artifactItem>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-security</artifactId>
+ </artifactItem>
+ <artifactItem>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-util</artifactId>
+ </artifactItem>
+ </artifactItems>
+ <outputDirectory>lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.geronimo.devtools</groupId>
+ <artifactId>maven-eclipsepde-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-security</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>geronimo</groupId>
+ <artifactId>geronimo-util</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.devtools.j2g</groupId>
+ <artifactId>org.apache.geronimo.devtools.j2g.util</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.devtools.j2g</groupId>
+ <artifactId>org.apache.geronimo.devtools.j2g.jasper</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.devtools.j2g</groupId>
+ <artifactId>org.apache.geronimo.devtools.j2g.common</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jdt</groupId>
+ <artifactId>core</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/migrations.exsd
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/migrations.exsd?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/migrations.exsd (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/schema/migrations.exsd Mon Oct 8 11:50:53 2007
@@ -0,0 +1,110 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.apache.geronimo.devtools.j2g.sources">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.apache.geronimo.devtools.j2g.sources" id="org.apache.geronimo.devtools.j2g.sources.migrations" name="Java Source Migration Point"/>
+ </appInfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="migration"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="migration">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ Source migration plug-in implementation class.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.apache.geronimo.devtools.j2g.common.IJavaMigration"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ <pre>
+ <extension
+ point="org.apache.geronimo.devtools.j2g.sources.migrations">
+ <migration class="org.apache.geronimo.devtools.j2g.sources.java.JavaSourceMigrator"/>
+ </extension>
+</pre>
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,65 @@
+/**
+ * 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.geronimo.devtools.j2g.sources;
+
+import java.io.File;
+import java.io.FileFilter;
+
+/**
+ * File filter for JSP files.
+ */
+public class FileFilterImpl implements FileFilter
+{
+ /**
+ * Files extensions.
+ */
+ private String[] extensions;
+
+ /**
+ * Creates file filter whith specifed extensions.
+ *
+ * @param extentions
+ */
+ public FileFilterImpl(String[] extentions)
+ {
+ this.extensions = extentions;
+ }
+
+ /**
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ public boolean accept(File file)
+ {
+ boolean isAllowed = false;
+ if (file.isDirectory())
+ {
+ return true;
+ }
+ else
+ {
+ for (int i = 0; i < extensions.length; i++)
+ {
+ if (file.getName().endsWith(extensions[i]))
+ {
+ isAllowed = true;
+ }
+ }
+ }
+ return isAllowed;
+ }
+}
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/FileFilterImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,455 @@
+/**
+ * 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.geronimo.devtools.j2g.sources;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.geronimo.devtools.j2g.common.FatalToolException;
+import org.apache.geronimo.devtools.j2g.common.ToolConstants;
+import org.apache.geronimo.devtools.j2g.jasper.JspCompiler;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IncrementalProjectBuilder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.launching.JavaRuntime;
+
+
+/**
+ * Parser for java sources. Compiles JSP files to template project and parses specifed sources and
+ * compiled JSPs.
+ */
+public class JavaParser {
+ /**
+ * List of sources dirs.
+ */
+ private String[] sources;
+
+ /**
+ * List of libraries.
+ */
+ private String[] libraries;
+
+ /**
+ * Web sources.
+ */
+ private String[] webContent;
+
+ /**
+ * JSP files extensions.
+ */
+ private String[] extensions = { "jsp" };
+
+ /**
+ * JSP files filter.
+ */
+ private FileFilter jspFilter;
+
+ /**
+ * Project which provides the environment (locations of sources including compiled JSP,
+ * libraries) to work.
+ */
+ private IProject project;
+
+ /**
+ * Java project representation.
+ */
+ private IJavaProject javaProject;
+
+ /**
+ * Source folder name.
+ */
+ private final String SRC_FOLDER_NAME = "src";
+
+ /**
+ * Binaries folder name.
+ */
+ private final String BIN_FOLDER_NAME = "bin";
+
+ /**
+ * Libraies folder name.
+ */
+ private final String LIB_FOLDER_NAME = "lib";
+
+ /**
+ * JSP folder name.
+ */
+ private final String JSP_FOLDER_NAME = "jsp";
+
+ /**
+ * AST Parser for java sources.
+ */
+ private ASTParser parser;
+
+ /**
+ * WEB-INF directory name.
+ */
+ private final String WEB_INF = "WEB-INF";
+
+ /**
+ * Classes directory name.
+ */
+ private final String CLASSES_CAT = "classes";
+
+ /**
+ * Libraries directory name.
+ */
+ private final String LIB_CAT = "lib";
+
+ /**
+ * Geronimo excluded lib.
+ */
+ private static final String GERONIMO_EXCLUDED_LIB = "geronimo-j2ee_1.4_spec-1.1.jar";
+
+ /**
+ * Java libraries file filter.
+ */
+ private FileFilter jarFilter;
+
+ /**
+ * For sources prepared for parsing.
+ */
+ private List units;
+
+ /**
+ * Creates java parser for specifed sources and libraries, compiles jsp files and save compiled
+ * in temporary project.
+ *
+ * @param sources not null list of source directories.
+ * @param libraries not null list of jar files or directories.
+ * @param webContent not null list of web content locations.
+ * @param jspExt not null list of jsp files extensions.
+ * @param created and opened project Eclipse project which will be provides sources and
+ * libraries.
+ * @throws FatalToolException if any problems occurs while parser preparing.
+ */
+
+ public JavaParser(String[] sources, String[] libraries, String[] webContent, String[] jspExt, File geronimoLib, File geronimoRep, IProject project) throws FatalToolException {
+ units = new ArrayList();
+ String[] exts = { "jar", "zip" };
+ jarFilter = new FileFilterImpl(exts);
+ this.sources = sources;
+ ArrayList libs = new ArrayList();
+ for (int i = 0; i < webContent.length; i++) {
+ File webinfCat = new File(webContent[i] + File.separator + WEB_INF);
+ if (webinfCat.exists()) {
+ File classes = new File(webinfCat, CLASSES_CAT);
+
+ if (classes.exists()) {
+ libs.add(classes.getAbsolutePath());
+ }
+
+ File lib = new File(webinfCat, LIB_CAT);
+ if (lib.exists() && lib.isDirectory()) {
+ File[] files = lib.listFiles(jarFilter);
+ for (int j = 0; j < files.length; j++) {
+ libs.add(files[j].getAbsolutePath());
+ }
+ }
+ }
+ else {
+ throw new FatalToolException("Path '" + webContent[i] + "' does not point to the web content directory. Could not find " + webinfCat.getAbsolutePath() + " directory.");
+ }
+ }
+
+ for (int i = 0; i < libraries.length; i++) {
+ libs.add(libraries[i]);
+ }
+ this.libraries = (String[]) libs.toArray(new String[libs.size()]);
+ this.webContent = webContent;
+ this.project = project;
+ this.javaProject = JavaCore.create(project);
+
+ try {
+ ArrayList classpathList = new ArrayList();
+ classpathList.addAll(linkSources());
+ classpathList.addAll(linkLibraries());
+ IClasspathEntry jreEntry = JavaCore.newContainerEntry(new Path(JavaRuntime.JRE_CONTAINER), false);
+ classpathList.add(jreEntry);
+ ArrayList repJars = new ArrayList();
+ getJarsRecursively(repJars, geronimoRep);
+ ArrayList libJars = new ArrayList();
+ getJarsRecursively(libJars, geronimoLib);
+ classpathList.addAll(linkGeronimo(repJars, ToolConstants.GERONIMO_REP));
+ classpathList.addAll(linkGeronimo(libJars, ToolConstants.GERONIMO_LIB));
+ IClasspathEntry[] entries = (IClasspathEntry[]) classpathList.toArray(new IClasspathEntry[classpathList.size()]);
+ javaProject.setRawClasspath(entries, null);
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ classpathList.addAll(compileAndLinkJsp(jspExt));
+ entries = (IClasspathEntry[]) classpathList.toArray(new IClasspathEntry[classpathList.size()]);
+ javaProject.setRawClasspath(entries, null);
+ parser = ASTParser.newParser(AST.JLS3);
+ } catch (CoreException ex) {
+ throw new FatalToolException("Cannot create template project classpath file.", ex);
+ }
+ }
+
+ /**
+ * Gets paths to the jar-files and puts it to list.
+ */
+ public void getJarsRecursively(List list, File file) {
+ if (file.isDirectory()) {
+ File[] files = file.listFiles(jarFilter);
+ for (int i = 0; i < files.length; i++) {
+ getJarsRecursively(list, files[i]);
+ }
+ }
+ else {
+ list.add(file);
+ }
+ }
+
+ /**
+ * Links Geronimo libraries to the temporary project.
+ * @throws FatalToolException
+ *
+ */
+ private List linkGeronimo(List jars, String baseName) throws FatalToolException {
+ ArrayList libs = new ArrayList();
+ for (int i = 0; i < jars.size(); i++) {
+ File jar = (File) jars.get(i);
+ String libName = jar.getName();
+ if (!libName.equals(GERONIMO_EXCLUDED_LIB)) {
+ String extension = libName.substring(libName.lastIndexOf("."), libName.length());
+ IFile sourceFolderEntry = project.getFile(generateName(baseName, i) + extension);
+ try {
+ sourceFolderEntry.createLink(Path.fromOSString(jar.getAbsolutePath()), IResource.NONE, null);
+ libs.add(JavaCore.newLibraryEntry(sourceFolderEntry.getFullPath(), null, null));
+ } catch (CoreException ex) {
+ throw new FatalToolException("Error occured while linking geronimo library: " + jar.getAbsolutePath(), ex);
+ }
+ }
+ }
+ return libs;
+ }
+
+ /**
+ * Compiles jsps to the jsp source folder to the project and returns List of a classpath
+ * entries.
+ * @see org.eclipse.jdt.core.IClasspathEntry
+ * @param webContent paths to a directories with jsps.
+ * @param jspExt jsp extensions.
+ * @return List of a classpath entries.
+ * @throws FatalToolException any errors occurs while jsp compiling.
+ */
+ private List compileAndLinkJsp(String[] jspExt) throws FatalToolException {
+ ArrayList compiledJsp = new ArrayList();
+ if (webContent != null && webContent.length > 0) {
+ if (jspExt != null && jspExt.length > 0) {
+ extensions = jspExt;
+ }
+ jspFilter = new FileFilterImpl(extensions);
+ ClassLoader savedContextClassLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[0]));
+ String classPath = "";
+ for (int i = 0; i < libraries.length; i++) {
+ classPath += File.pathSeparator + libraries[i];
+ }
+ IPath outputFodler = project.getFolder(BIN_FOLDER_NAME).getRawLocation();
+ classPath += File.pathSeparator + outputFodler.toOSString() + "/";
+ try {
+ for (int i = 0; i < webContent.length; i++) {
+ String jspFolderName = generateName(JSP_FOLDER_NAME, i);
+ IFolder compiledJspFolder = project.getFolder(jspFolderName);
+ compiledJspFolder.create(true, true, null);
+ compiledJspFolder.setDerived(true);
+ compiledJsp.add(JavaCore.newSourceEntry(compiledJspFolder.getFullPath()));
+ File jspSourceFolder = new File(webContent[i]);
+ JspCompiler jspCompiler = null;
+ jspCompiler = new JspCompiler(jspFilter);
+ compiledJspFolder.setDefaultCharset(jspCompiler.getEncoding(), null);
+ String jspOutputDir = compiledJspFolder.getLocation().toOSString();
+ String uriRoot = jspSourceFolder.getAbsolutePath();
+ jspCompiler.compileJsp(classPath, jspOutputDir, uriRoot);
+ }
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (CoreException ex) {
+ throw new FatalToolException("Cannot create jsp source folder in temporary project.", ex);
+ } finally {
+ Thread.currentThread().setContextClassLoader(savedContextClassLoader);
+ }
+ }
+ return compiledJsp;
+ }
+
+ /**
+ * Preapres java sources for parsing.
+ * @throws FatalToolException if any problems occurs while preparing sources.
+ */
+ public void prepareSources() throws FatalToolException {
+ for (int i = 0; i < sources.length; i++) {
+ File sourceFile = new File(sources[i]);
+ IFolder srcFolder = project.getFolder(generateName(SRC_FOLDER_NAME, i));
+ String basePackage = srcFolder.getFullPath().toPortableString();
+ prepareRecursively(basePackage, sourceFile);
+ }
+ }
+
+ /**
+ * Prepares compiled jsp sources for parsing.
+ * @throws FatalToolException if any problems occurs while preparing jsp sources.
+ */
+ public void prepareJspSources() throws FatalToolException {
+ for (int i = 0; i < webContent.length; i++) {
+ IFolder jspFolder = project.getFolder(generateName(JSP_FOLDER_NAME, i));
+ String basePackage = jspFolder.getFullPath().toPortableString();
+ prepareRecursively(basePackage, jspFolder.getLocation().toFile());
+ }
+ }
+
+ /**
+ * Recursively find and prepares sources provided by sourceFile variable and puts results into
+ * units list.
+ * @param packagePath path to processed package relative to workspace.
+ * @param sourceFile processed file.
+ * @throws FatalToolException if any problems occurs while preparing sources.
+ */
+ private void prepareRecursively(String packagePath, File sourceFile) throws FatalToolException {
+ if (sourceFile.isDirectory()) {
+ File[] files = sourceFile.listFiles(JavaSourceFilter.FILTER);
+ for (int i = 0; i < files.length; i++) {
+ if (files[i].isDirectory()) {
+ prepareRecursively(packagePath + IPath.SEPARATOR + files[i].getName(), files[i]);
+ }
+ else {
+ try {
+ IPath path = Path.fromPortableString(packagePath);
+ IPackageFragment fragment = javaProject.findPackageFragment(path);
+ ICompilationUnit compilationUnit = fragment.getCompilationUnit(files[i].getName());
+ units.add(new ParsedSource(compilationUnit, files[i]));
+ } catch (JavaModelException ex) {
+ throw new FatalToolException("Error occured while parsing sources.", ex);
+ }
+ }
+ }
+ }
+ else {
+ if (sourceFile.exists()) {
+ throw new FatalToolException("'" + sourceFile.getAbsolutePath() + "'; only source directories are allowed.");
+ }
+ else {
+ throw new FatalToolException("'" + sourceFile.getAbsolutePath() + "' directory does not exist.");
+ }
+ }
+ }
+
+ /**
+ * Parse next in the list of sources.
+ * @return parsed source or null if list is empty.
+ */
+ public ParsedSource parseNext() {
+ if (!units.isEmpty()) {
+ ParsedSource unit = (ParsedSource) units.get(0);
+ units.remove(unit);
+ parser.setResolveBindings(true);
+ parser.setSource(unit.getCompilationUnit());
+ ASTNode node = parser.createAST(null);
+ unit.setNode(node);
+ return unit;
+ }
+ return null;
+ }
+
+ /**
+ * Links sources paths to a temporary projects sources folder.
+ * @throws FatalToolException if any problems occurs while linking source folders.
+ */
+ private List linkSources() throws FatalToolException {
+ ArrayList srcList = new ArrayList();
+ for (int i = 0; i < sources.length; i++) {
+ File file = new File(sources[i]);
+ if (!file.exists()) {
+ throw new FatalToolException("Source directory '" + file.getAbsolutePath() + "' does not exist.");
+ }
+ IFolder sourceFolderEntry = project.getFolder(generateName(SRC_FOLDER_NAME, i));
+ try {
+ sourceFolderEntry.createLink(Path.fromOSString(file.getAbsolutePath()), IResource.NONE, null);
+ srcList.add(JavaCore.newSourceEntry(sourceFolderEntry.getFullPath()));
+ } catch (CoreException ex) {
+ throw new FatalToolException("Error occured while linking source directory: " + file.getAbsolutePath(), ex);
+ }
+ }
+ return srcList;
+ }
+
+ /**
+ * Links libraries paths to a temporary projects libraries folder.
+ * @throws FatalToolException if any problems occurs while linking libraries.
+ */
+ private List linkLibraries() throws FatalToolException {
+ ArrayList libList = new ArrayList();
+ if (libraries != null) {
+ for (int i = 0; i < libraries.length; i++) {
+ File file = new File(libraries[i]);
+ try {
+ if (file.isDirectory()) {
+ if (!file.exists()) {
+ throw new FatalToolException("Directory '" + file.getAbsolutePath() + "' does not exist.");
+ }
+ IFolder libFolderEntry = project.getFolder(generateName(LIB_FOLDER_NAME, i));
+ libFolderEntry.createLink(Path.fromOSString(file.getAbsolutePath()), IResource.NONE, null);
+ IClasspathEntry libDir = JavaCore.newLibraryEntry(libFolderEntry.getFullPath(), null, null);
+ libList.add(libDir);
+ }
+ else {
+ if (!file.exists()) {
+ throw new FatalToolException("File '" + file.getAbsolutePath() + "' does not exist.");
+ }
+ String libName = file.getName();
+ String extension = libName.substring(libName.lastIndexOf("."), libName.length());
+ IFile libJarEntry = project.getFile(generateName(LIB_FOLDER_NAME, i) + extension);
+ libJarEntry.createLink(Path.fromOSString(file.getAbsolutePath()), IResource.NONE, null);
+ IClasspathEntry libJar = JavaCore.newLibraryEntry(libJarEntry.getFullPath(), null, null);
+ libList.add(libJar);
+ }
+ } catch (CoreException ex) {
+ throw new FatalToolException("Error occured while linking library: " + file.getAbsolutePath(), ex);
+ }
+ }
+ }
+ return libList;
+ }
+
+ /**
+ * Generates folders names.
+ * @param base
+ * @param number
+ * @return generated folder name. (base_number)
+ */
+ private String generateName(String base, int number) {
+ return base + "_" + number;
+ }
+}
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaParser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,45 @@
+/**
+ * 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.geronimo.devtools.j2g.sources;
+
+import java.io.File;
+import java.io.FileFilter;
+
+/**
+ * Filter for .java files.
+ */
+public class JavaSourceFilter implements FileFilter
+{
+ /**
+ * Java sources suffix.
+ */
+ public static final String JAVA_SUFFIX = ".java";
+
+ /**
+ * Static filter.
+ */
+ public static final JavaSourceFilter FILTER = new JavaSourceFilter();
+
+ /**
+ * @see java.io.FileFilter#accept(java.io.File)
+ */
+ public boolean accept(File file)
+ {
+ return file.isDirectory() || file.getName().endsWith(JAVA_SUFFIX);
+ }
+}
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/JavaSourceFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,88 @@
+/**
+ * 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.geronimo.devtools.j2g.sources;
+
+import java.io.File;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.ASTNode;
+
+/**
+ * Class provides parsed source node and file.
+ */
+public class ParsedSource
+{
+ /**
+ * Syntax tree.
+ */
+ private ASTNode node;
+
+ /**
+ * Source unit.
+ */
+ private ICompilationUnit compilationUnit;
+
+ /**
+ * Source real file.
+ */
+ private File file;
+
+ /**
+ * Creates object with specifed source unit and syntax tree.
+ * @param node syntax tree.
+ * @param file source file.
+ */
+ public ParsedSource(ICompilationUnit compilationUnit, File file)
+ {
+ this.file = file;
+ this.compilationUnit = compilationUnit;
+ }
+
+ /**
+ * @return the syntax tree.
+ */
+ public ASTNode getNode()
+ {
+ return node;
+ }
+
+ /**
+ * @return the compilation unit.
+ */
+ public ICompilationUnit getCompilationUnit()
+ {
+ return compilationUnit;
+ }
+
+ /**
+ * @return the source file.
+ */
+ public File getFile()
+ {
+ return file;
+ }
+
+ /**
+ * Sets parsed AST node for current source.
+ * @param node
+ */
+ public void setNode(ASTNode node)
+ {
+ this.node = node;
+ }
+}
\ No newline at end of file
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/ParsedSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,371 @@
+/**
+ * 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.geronimo.devtools.j2g.sources;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.geronimo.devtools.j2g.common.FatalToolException;
+import org.apache.geronimo.devtools.j2g.common.IJavaMigration;
+import org.apache.geronimo.devtools.j2g.common.RollbackManager;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.common.ToolConstants;
+import org.eclipse.core.resources.ICommand;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.TextEdit;
+
+
+/**
+ * Class coordinates a work of plugins.
+ */
+public class SourceIdentificationTool extends Tool {
+ /**
+ * Sources parameter.
+ */
+ private final static String SRC_PARAM = "-src";
+
+ /**
+ * Libraries parameter.
+ */
+ private final static String LIB_PARAM = "-lib";
+
+ /**
+ * Web sources parameter.
+ */
+ private final static String WEB_PARAM = "-web";
+
+ /**
+ * Jsp extensions parameter.
+ */
+ private final static String JSPEXT_PARAM = "-jspext";
+
+ /**
+ * Geronimo home path parameter.
+ */
+ private final static String GERONIMO_PARAM = "-geronimo";
+
+ /**
+ * Allowed parameters.
+ */
+ private final static String[] ALLOWED_PARAMS = { SRC_PARAM, LIB_PARAM, WEB_PARAM, JSPEXT_PARAM, GERONIMO_PARAM };
+
+ /**
+ * Parameters delimeter.
+ */
+ private final static String DELIMETER = ",";
+
+ /**
+ * Temporary project.
+ */
+ private static IProject project;
+
+ /**
+ * Plug-in id
+ */
+ public final static String PLUGIN_ID = "org.apache.geronimo.devtools.j2g.sources";
+
+ /** Geronimo repository. */
+ private final static String REPOSITORY = "repository";
+
+ /** Geronimo common libraries. */
+ private final static String LIBRARIES = "lib";
+
+ /**
+ * Extension point id
+ */
+ public final static String EXTENSION_POINT_ID = PLUGIN_ID + ".migrations";
+
+ /**
+ * Geronimo home system environment variable name.
+ */
+ private final static String GERONIMO_HOME = "GERONIMO_HOME";
+
+ /**
+ * Geronimo home.
+ */
+ private String geronimoHomePath;
+
+ /**
+ * @see org.eclipse.core.runtime.IPlatformRunnable
+ */
+ public Object run(Object args) throws Exception {
+ try {
+ String[] arguments = (String[]) args;
+ if (arguments.length == 0) {
+ usage();
+ return new Integer(0);
+ }
+ project = createTemporaryProject();
+ Map params = parseArguments(arguments);
+ List geronimoHome = (List) params.get(GERONIMO_PARAM);
+ if (geronimoHome != null && geronimoHome.size() != 0) {
+ geronimoHomePath = (String) geronimoHome.get(0);
+ }
+ else {
+ geronimoHomePath = System.getProperty(GERONIMO_HOME);
+ if (geronimoHomePath == null) {
+ usage();
+ throw new FatalToolException("Missing mandatory parameter '-geronimo'");
+ }
+ }
+ File geronimo = new File(geronimoHomePath);
+ File geronimoRep = new File(geronimo, REPOSITORY);
+ File geronimoLib = new File(geronimo, LIBRARIES);
+ if (!geronimoRep.exists() || !geronimoLib.exists()) {
+ throw new FatalToolException("Invalid Geronimo installation. Cannot find libaries and repository directories.");
+ }
+
+ List src = (List) params.get(SRC_PARAM);
+ List lib = (List) params.get(LIB_PARAM);
+ List web = (List) params.get(WEB_PARAM);
+ List jspext = (List) params.get(JSPEXT_PARAM);
+ if (src != null) {
+ RollbackManager rollbackManager = new RollbackManager(JavaSourceFilter.FILTER);
+ Iterator sources = src.iterator();
+ while (sources.hasNext()) {
+ File file = new File((String) sources.next());
+ rollbackManager.restore(file);
+ }
+ }
+ JavaParser parser = null;
+ parser = new JavaParser(getStringArray(src), getStringArray(lib), getStringArray(web), getStringArray(jspext), geronimoLib, geronimoRep, project);
+ parser.prepareSources();
+
+ IJavaMigration[] plugs = loadPlugins();
+
+ ParsedSource unit;
+ while ((unit = parser.parseNext()) != null) {
+ migrate(plugs, unit, true);
+ }
+
+ parser.prepareJspSources();
+ while ((unit = parser.parseNext()) != null) {
+ migrate(plugs, unit, false);
+ }
+
+ } catch (FatalToolException ex) {
+ getOutput().fatal(SourceIdentificationTool.class.getSimpleName(), ex.getMessage());
+ return new Integer(1);
+ } finally {
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(ToolConstants.TEMPORARY_PROJECT_NAME);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ project.delete(true, null);
+ }
+ return new Integer(0);
+ }
+
+ /**
+ * Print tool usage text.
+ */
+ protected void usage() {
+ getOutput().fatal(SourceIdentificationTool.class.getSimpleName(), "Usage: jsrc2g.cmd {-src dir_name[,dir_nameN]}{-lib dir_or_jar_name[;dir_or_jar_nameN]}{-web dir_name[;dir_nameN]} -geronimo geronimo_home");
+ }
+
+ /**
+ * Converts List with Strings to String[] array.
+ * @param list list of strings.
+ * @return
+ */
+ private String[] getStringArray(List list) {
+ if (list != null) {
+ return (String[]) list.toArray(new String[list.size()]);
+ }
+ else {
+ return new String[0];
+ }
+ }
+
+ /**
+ * Parses arguments which was passed to the plugin.
+ * @param args arguments array.
+ * @return map of parameters where key - parameter names and values - lists of parameters.
+ * @throws FatalToolException if wrong parameter was found.
+ */
+ private Map parseArguments(String[] args) throws FatalToolException {
+ HashMap result = new HashMap();
+ int pointer = 0;
+ while (pointer < args.length) {
+ String key = args[pointer];
+ if (isCorrectParameter(key)) {
+ pointer++;
+ if (args.length > pointer) {
+ result.put(key, parseComplexPath(args[pointer]));
+ pointer++;
+ }
+ else {
+ throw new FatalToolException("Missing parameter for key:" + key);
+ }
+ }
+ else {
+ throw new FatalToolException("Wrong parameter:" + args[pointer]);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Checks correctness of parameters.
+ * @param arg paramter.
+ * @return true if parameter allowed.
+ */
+ private boolean isCorrectParameter(String arg) {
+ for (int i = 0; i < ALLOWED_PARAMS.length; i++) {
+ if (arg.equals(ALLOWED_PARAMS[i])) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Parses strings formated follows: some_string_1[;some_string_N]
+ * @param path string like this "some_string_1[;some_string_N]"
+ * @return list of parsed strings.
+ */
+ private List parseComplexPath(String path) {
+ ArrayList result = new ArrayList();
+ int index = path.indexOf(DELIMETER);
+ while (index > 0) {
+ result.add(path.substring(0, index));
+ path = path.substring(index + 1);
+ index = path.indexOf(DELIMETER);
+ }
+ result.add(path);
+ return result;
+ }
+
+ /**
+ * Creates opened temporary Eclipse project in current workspace.
+ * @return opened temporary Eclipse project.
+ * @throws FatalToolException
+ */
+ private IProject createTemporaryProject() throws FatalToolException {
+ IProject project;
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ try {
+ project = workspace.getRoot().getProject(ToolConstants.TEMPORARY_PROJECT_NAME);
+ IProjectDescription desc = workspace.newProjectDescription(project.getName());
+ desc.setNatureIds(new String[] { JavaCore.NATURE_ID });
+ ICommand command = desc.newCommand();
+ command.setBuilderName(JavaCore.BUILDER_ID);
+ desc.setBuildSpec(new ICommand[] { command });
+ project.create(desc, null);
+ project.open(null);
+ } catch (CoreException ex) {
+ throw new FatalToolException("Cannot create or open temporary project. Please try to clean workspace '" + workspace.getRoot().getLocation().toOSString() + "' manually.", ex);
+ }
+ return project;
+ }
+
+ /**
+ * Loads java source migration plug-ins from the extension registry.
+ * @return array of IJavaMigration instaces.
+ */
+ private IJavaMigration[] loadPlugins() {
+ List plugins = new ArrayList();
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(EXTENSION_POINT_ID);
+ IExtension[] exts = point.getExtensions();
+ for (int i = 0; i < exts.length; ++i) {
+ IConfigurationElement[] els = exts[i].getConfigurationElements();
+ for (int j = 0; j < els.length; ++j) {
+ try {
+ plugins.add(els[j].createExecutableExtension(ToolConstants.CLASS_PROPERTY));
+ } catch (CoreException ex) {
+ ILog log = Platform.getLog(Platform.getBundle(PLUGIN_ID));
+ log.log(new Status(Status.WARNING, PLUGIN_ID, Status.OK, "Failed to instantiate java source migration plug-in.", ex));
+ }
+ }
+ }
+ return (IJavaMigration[]) plugins.toArray(new IJavaMigration[plugins.size()]);
+ }
+
+ /**
+ * Migrates given source and execute saving if it's necessary.
+ *
+ * @param plugs available migration plug-ins.
+ * @param source source to migration.
+ * @param saveMigrated if true then migrated source will be saved.
+ * @throws FatalToolException
+ */
+ private void migrate(IJavaMigration[] plugs, ParsedSource source, boolean saveMigrated) throws FatalToolException {
+ boolean isModified = false;
+ CompilationUnit unit = (CompilationUnit) source.getNode();
+ unit.recordModifications();
+ for (int i = 0; i < plugs.length; ++i) {
+ isModified = plugs[i].migrate(source.getNode()) || isModified;
+ }
+ if (isModified && saveMigrated) {
+ saveSource(source);
+ }
+ }
+
+ /**
+ * Creates buckup copy and saves modified source.
+ * @param source
+ * @throws FatalToolException
+ * @throws IOException
+ */
+ private void saveSource(ParsedSource source) throws FatalToolException {
+ ICompilationUnit sourceUnit = source.getCompilationUnit();
+ CompilationUnit parsedUnit = (CompilationUnit) source.getNode();
+ try {
+ String contents = sourceUnit.getBuffer().getContents();
+ File file = new File(source.getFile().getAbsolutePath() + RollbackManager.BACKUP_SUFFIX);
+ file.createNewFile();
+ FileOutputStream out = new FileOutputStream(file);
+ out.write(contents.getBytes());
+ out.close();
+ Document document = new Document(contents);
+ TextEdit edits = parsedUnit.rewrite(document, sourceUnit.getJavaProject().getOptions(true));
+ edits.apply(document);
+ String newSource = document.get();
+ sourceUnit.getBuffer().setContents(newSource);
+ sourceUnit.save(null, true);
+ } catch (JavaModelException ex) {
+ getOutput().error(SourceIdentificationTool.class.getSimpleName(), "Java element does not exist or it is read-only: " + sourceUnit.getElementName());
+ } catch (IOException ex) {
+ getOutput().error(SourceIdentificationTool.class.getSimpleName(), "I/O error occured while creating backup copy of source file: " + source.getFile().getAbsolutePath());
+ } catch (BadLocationException ex) {
+ getOutput().error(SourceIdentificationTool.class.getSimpleName(), "Cannot edit source file: " + source.getFile().getAbsolutePath());
+ }
+ }
+}
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/SourceIdentificationTool.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,151 @@
+/**
+ * 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.geronimo.devtools.j2g.sources.dependence;
+
+import java.util.List;
+
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTMatcher;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
+
+
+/**
+ * Finds specified names and replaces its by new one.
+ */
+public class APIReplaceVisitor extends ASTVisitor {
+
+ /** Name to replace */
+ private QualifiedName targetName;
+
+ /** New name */
+ private QualifiedName newName;
+
+ /** Compilation unit */
+ private CompilationUnit unit;
+
+ /** Nodes matcher */
+ private ASTMatcher matcher;
+
+ /** Output */
+ private IOutput out;
+
+ /** Import changing flag */
+ private boolean isImportAffected;
+
+ /** Changes counter */
+ private int changes = 0;
+
+ /**
+ * Constructor. Creates new instance of APIReplaceVisitor.
+ * @param unit compilation unit.
+ * @param targetName target name.
+ * @param newName new name.
+ */
+ public APIReplaceVisitor(CompilationUnit unit, QualifiedName targetName, QualifiedName newName) {
+ super(false);
+ this.targetName = targetName;
+ this.newName = newName;
+ this.unit = unit;
+ matcher = new ASTMatcher(false);
+ out = Tool.getCurrent().getOutput();
+ isImportAffected = false;
+ }
+
+ /**
+ * Replaces qualified names in imports.
+ */
+ public boolean visit(ImportDeclaration importDeclaration) {
+ QualifiedName name = (QualifiedName) importDeclaration.getName();
+ if (!importDeclaration.isOnDemand()) {
+ int position = name.getStartPosition();
+ if (matcher.match(name, targetName)) {
+ isImportAffected = true;
+ AST ast = importDeclaration.getAST();
+ Name replacer = ast.newName(newName.getFullyQualifiedName());
+ printChanges(name, newName, unit.getLineNumber(position), unit.getColumnNumber(position));
+ importDeclaration.setName(replacer);
+ }
+ }
+ else {
+ if (matcher.match(name, targetName.getQualifier())) {
+ List imports = unit.imports();
+ AST ast = unit.getAST();
+ ImportDeclaration newImport = ast.newImportDeclaration();
+ newImport.setName(newName);
+ imports.add(newImport);
+ isImportAffected = true;
+ out.info(APIReplaceVisitor.class.getSimpleName(), "New import was added: '" + newName.getFullyQualifiedName()+"'.");
+ changes++;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Replaces qualified name.
+ */
+ public boolean visit(QualifiedName name) {
+ int position = name.getStartPosition();
+ if (matcher.match(name, targetName)) {
+ AST ast = name.getAST();
+ Name replacer = ast.newName(newName.getFullyQualifiedName());
+ StructuralPropertyDescriptor desc = name.getLocationInParent();
+ printChanges(name, newName, unit.getLineNumber(position), unit.getColumnNumber(position));
+ name.getParent().setStructuralProperty(desc, replacer);
+ }
+ return false;
+ }
+
+ /**
+ * Replaces simple name.
+ */
+ public boolean visit(SimpleName name) {
+ int position = name.getStartPosition();
+ if (matcher.match(name, targetName.getName()) && isImportAffected) {
+ printChanges(name, newName.getName(), unit.getLineNumber(position), unit.getColumnNumber(position));
+ name.setIdentifier(newName.getName().getIdentifier());
+ }
+ return false;
+ }
+
+ /**
+ * Prints out about changes in compilation unit.
+ * @param name replaced name.
+ * @param newName new name.
+ * @param row row in source unit.
+ * @param col column in source unit.
+ */
+ private void printChanges(Name name, Name newName, int row, int col) {
+ changes++;
+ out.info(APIReplaceVisitor.class.getSimpleName(), "Name '" + name.getFullyQualifiedName() + "' was replaced by '" + newName.getFullyQualifiedName() + "'.", row, col);
+ }
+
+ /**
+ * @return the changes count
+ */
+ public int getChanges() {
+ return changes;
+ }
+}
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/APIReplaceVisitor.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java?rev=582932&view=auto
==============================================================================
--- geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java (added)
+++ geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java Mon Oct 8 11:50:53 2007
@@ -0,0 +1,271 @@
+/**
+ * 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.geronimo.devtools.j2g.sources.dependence;
+
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.geronimo.devtools.j2g.common.FatalToolException;
+import org.apache.geronimo.devtools.j2g.common.IJavaMigration;
+import org.apache.geronimo.devtools.j2g.common.IOutput;
+import org.apache.geronimo.devtools.j2g.common.RollbackManager;
+import org.apache.geronimo.devtools.j2g.common.Tool;
+import org.apache.geronimo.devtools.j2g.common.ToolConstants;
+import org.apache.geronimo.devtools.j2g.sources.dependence.compatibility.Anybody;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.TextEdit;
+
+/**
+ * Determines all references of the source compilation unit to classes which are incompatible with
+ * Geronimo.
+ */
+public class DependenceJavaMigration implements IJavaMigration {
+ /**
+ * Plug-in name.
+ */
+ private final static String PLUGIN_NAME = "Dependence plug-in";
+
+ /**
+ * Tool output
+ */
+ private IOutput out;
+
+ /**
+ * Property file with default Geronimo libraries names.
+ */
+ private final String DEFAULT_LIBS_FILENAME = "default_jars.properties";
+ private final String DEFAULT_LIBS_DIRECTORY = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.sources.dependence/";
+
+ /**
+ * Set of default Geronimo libraries names.
+ */
+ private static Set defaultLibs;
+
+ /**
+ * Compatibility sources names.
+ */
+ private final String COMPATIBILITY_SOURCES_FILENAME = "compatible_sources.properties";
+ private final String COMPATIBILITY_SOURCES_DIRECTORY = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.sources.dependence/";
+
+ /**
+ * Set of default Geronimo libraries names.
+ */
+ private static Properties compatibilitySources;
+
+ /**
+ * Property file with class analogies.
+ */
+ private final String CLASS_ANALOGIES_FILENAME = "class_analogies.properties";
+ private final String CLASS_ANALOGIES_DIRECTORY = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.sources.dependence/";
+
+ /**
+ * Properties with class analogies.
+ */
+ private static Properties classAnalogies;
+
+ /**
+ * Compatibles package qualified name.
+ */
+ private static final String COMPATIBLES_PACKAGE = "org/apache/geronimo/devtools/j2g/sources/dependence/compatibility";
+
+ /**
+ * Location of Compatibles Files.
+ */
+ private static final String COMPATIBLES_LOCATION = System.getenv("ECLIPSE_HOME")+"/plugins/org.apache.geronimo.devtools.j2g.sources.dependence.compatibility";
+ /**
+ * Java resources extension.
+ */
+ private static final String JAVA_EXT = ".java";
+
+ /**
+ * Byte buffer size.
+ */
+ private static final int BUFFER_SIZE = 1024;
+
+ /**
+ * Constructor. Loads default libs names and class analogies names.
+ * @throws FatalToolException if cannot load properties file with default jars names.
+ */
+ public DependenceJavaMigration() throws FatalToolException {
+ super();
+ if (defaultLibs == null) {
+ try {
+ File propertyFile = new File(DEFAULT_LIBS_DIRECTORY + DEFAULT_LIBS_FILENAME);
+ Properties prop = new Properties();
+ prop.load(new FileInputStream(propertyFile));
+ defaultLibs = prop.keySet();
+ } catch (IOException e) {
+ throw new FatalToolException("Cannot load properties file with default jars names.");
+ }
+ }
+
+ if (classAnalogies == null) {
+ try {
+ File propertyFile = new File(CLASS_ANALOGIES_DIRECTORY + CLASS_ANALOGIES_FILENAME);
+ classAnalogies = new Properties();
+ classAnalogies.load(new FileInputStream(propertyFile));
+ } catch (IOException e) {
+ throw new FatalToolException("Cannot load properties file with class analogies.");
+ }
+ }
+ if (compatibilitySources == null) {
+ try {
+ File propertyFile = new File(COMPATIBILITY_SOURCES_DIRECTORY + COMPATIBILITY_SOURCES_FILENAME);
+ compatibilitySources = new Properties();
+ compatibilitySources.load(new FileInputStream(propertyFile));
+ } catch (IOException e) {
+ throw new FatalToolException("Cannot load properties file with compatibility classnames.");
+ }
+ }
+ }
+
+ /**
+ * Determines all references of the source compilation unit to classes which are incompatible
+ * with Geronimo.
+ * @param source compilation unit for migration.
+ */
+ public boolean migrate(ASTNode source) {
+ out = Tool.getCurrent().getOutput();
+ if (source instanceof CompilationUnit) {
+ CompilationUnit compilationUnit = (CompilationUnit) source;
+ String unitName = compilationUnit.getJavaElement().getElementName();
+ boolean isSourceChanged = false;
+ out.info(DependenceJavaMigration.class.getSimpleName(), "[" + PLUGIN_NAME + "] " + "Migration started: " + unitName);
+ Set replacedClasses = classAnalogies.keySet();
+ AST ast = compilationUnit.getAST();
+ Iterator classesIterator = replacedClasses.iterator();
+ while (classesIterator.hasNext()) {
+ String targetStr = (String) classesIterator.next();
+ String newStr = classAnalogies.getProperty(targetStr);
+ Name replaced = ast.newName(targetStr);
+ Name replacer = ast.newName(newStr);
+
+ if (replaced.isQualifiedName() && replacer.isQualifiedName()) {
+ QualifiedName targetName = (QualifiedName) replaced;
+ QualifiedName newName = (QualifiedName) replacer;
+ APIReplaceVisitor apiReplacer = new APIReplaceVisitor(compilationUnit, targetName, newName);
+ compilationUnit.accept(apiReplacer);
+ apiReplacer.visit(compilationUnit);
+ isSourceChanged = isSourceChanged || (apiReplacer.getChanges() > 0);
+ }
+ else {
+ out.error(DependenceJavaMigration.class.getSimpleName(), "Wrong class names for JBoss classes and it's Geronimo analogies in property file");
+ break;
+ }
+
+ }
+ try {
+ if (isSourceChanged) {
+ String path = compilationUnit.getJavaElement().getUnderlyingResource().getLocation().toPortableString();
+ String package_path = compilationUnit.getPackage().getName().getFullyQualifiedName().replace('.', IPath.SEPARATOR);
+ String src_path = path.substring(0, path.indexOf(package_path));
+ String compatible_dir = src_path + COMPATIBLES_PACKAGE;
+ File pack = new File(compatible_dir);
+ File sourceDir = new File(COMPATIBLES_LOCATION);
+ if (!pack.exists()) {
+ pack.mkdirs();
+ Set compatibleSources = compatibilitySources.keySet();
+ Iterator keys = compatibleSources.iterator();
+ while (keys.hasNext()) {
+ String classname = (String)keys.next();
+ String sourceName = classname.substring(classname.lastIndexOf('.') + 1) + JAVA_EXT;
+ File addedSource = new File(pack, sourceName);
+ addedSource.createNewFile();
+ PrintWriter writer = new PrintWriter(new FileOutputStream(addedSource));
+ InputStream inStream = null;
+ inStream = new FileInputStream(new File(sourceDir,sourceName));
+ byte[] buffer = new byte[BUFFER_SIZE];
+ int len = 0;
+ while ((len = inStream.read(buffer)) > 0) {
+ String outpt = new String(buffer, 0, len);
+ writer.print(outpt);
+ }
+ inStream.close();
+ writer.close();
+ }
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ IProject project = workspace.getRoot().getProject(ToolConstants.TEMPORARY_PROJECT_NAME);
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+ ICompilationUnit isource = (ICompilationUnit) compilationUnit.getJavaElement();
+ String contents = isource.getBuffer().getContents();
+ File file = new File(isource.getUnderlyingResource().getLocation().toOSString() + RollbackManager.BACKUP_SUFFIX);
+ file.createNewFile();
+ FileOutputStream fout = new FileOutputStream(file);
+ fout.write(contents.getBytes());
+ fout.close();
+ Document document = new Document(contents);
+ TextEdit edits = compilationUnit.rewrite(document, isource.getJavaProject().getOptions(true));
+ edits.apply(document);
+ String newSource = document.get();
+ isource.getBuffer().setContents(newSource);
+ isource.save(null, true);
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setSource(isource);
+ compilationUnit = (CompilationUnit) parser.createAST(null);
+ }
+ } catch (IOException ex) {
+ out.fatal(DependenceJavaMigration.class.getSimpleName(), "The plug-in cannot add compatible package or save backup because an I/O error occured. Make sure that the source directories are not under write protection.");
+ } catch (Exception e) {
+ out.fatal(DependenceJavaMigration.class.getSimpleName(), "The plug-in cannot get access to the resources. Make sure that the source files are not under write protection or have not been deleted by another process.");
+ }
+ NodesVisitor visitor = new NodesVisitor(compilationUnit);
+ compilationUnit.accept(visitor);
+ visitor.visit(compilationUnit);
+ boolean isSourceValid = visitor.isSourceValid();
+ if (isSourceChanged && !isSourceValid) {
+ out.warn(DependenceJavaMigration.class.getSimpleName(), "Errors were found in the source file! Changes were saved. The original file was saved with name " + unitName + RollbackManager.BACKUP_SUFFIX);
+ }
+ out.info(DependenceJavaMigration.class.getSimpleName(), "[" + PLUGIN_NAME + "] " + "Migration finished: " + unitName);
+ return false;
+ }
+ else {
+ out.error(DependenceJavaMigration.class.getSimpleName(), "[" + PLUGIN_NAME + "] " + "Wrong type of source node.");
+ }
+ return false;
+ }
+
+ /**
+ * @return set of default lib names.
+ */
+ public static Set getDefaultLibs() {
+ return defaultLibs;
+ }
+}
Propchange: geronimo/devtools/j2g/trunk/plugins/org.apache.geronimo.devtools.j2g.sources/src/org/apache/geronimo/devtools/j2g/sources/dependence/DependenceJavaMigration.java
------------------------------------------------------------------------------
svn:eol-style = native