├── .gitignore
├── .travis.yml
├── README.md
├── libs
└── frmjdapi-10.0.jar
├── pom.xml
└── src
├── main
└── java
│ └── org
│ └── sonar
│ └── oracleforms
│ └── plsql
│ ├── Form.java
│ ├── JdapiAvailability.java
│ ├── JdapiProxy.java
│ ├── Node.java
│ ├── PlSqlExtractor.java
│ ├── Settings.java
│ ├── decorators
│ ├── CalculatedFieldDecorator.java
│ ├── CommentPathDecorator.java
│ ├── Decorator.java
│ ├── DecoratorFactory.java
│ ├── GuiBlockDecorator.java
│ ├── GuiItemDecorator.java
│ ├── ProgramUnitDecorator.java
│ └── package-info.java
│ └── package-info.java
└── test
├── java
└── org
│ └── sonar
│ └── oracleforms
│ └── plsql
│ ├── JdapiAvailabilityTest.java
│ ├── MediumTesting.java
│ ├── NodeTest.java
│ ├── PlSqlExtractorTest.java
│ ├── SettingsTest.java
│ └── decorators
│ ├── DecoratorsFactoryTest.java
│ ├── GuiBlockDecoratorTest.java
│ ├── GuiItemDecoratorTest.java
│ └── ProgramUnitDecoratorTest.java
└── resources
└── org
└── sonar
└── oracleforms
└── plsql
└── MediumTest
├── oracle-bigraph
├── graph.fmb
└── graph.fmx
├── oracle-demo
├── ffisamp.dll
├── webutil_demo.fmb
└── wu_fileupload_db_demo.sql
└── sample
└── ue_samp.fmb
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .DS_Store
3 | .classpath
4 | .project
5 | .idea/
6 | .settings/
7 | target/
8 | bin/
9 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | sudo: false
3 | install: true
4 |
5 | jdk:
6 | - oraclejdk7
7 |
8 | script:
9 | - mvn install:install-file -Dfile=libs/frmjdapi-10.0.jar -DgroupId=com.oracle -DartifactId=frmjdapi -Dversion=10.0 -Dpackaging=jar
10 | - mvn verify -B -e -V
11 |
12 | cache:
13 | directories:
14 | - '$HOME/.m2/repository'
15 |
16 | notifications:
17 | email: false
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Oracle Forms PL/SQL Extractor
2 | =============================
3 |
4 | Features
5 | --------
6 | This command-line gives the ability to extract PL/SQL source code from Oracle Forms. You can then feed SonarQube with the extracted PL/SQL source code.
7 |
8 | Download
9 | --------
10 |
11 | Latest version is 1.1, released on 14 May 2014
12 |
13 | http://downloads.sonarsource.com/plugins/org/codehaus/sonar-plugins/sonar-forms-plsql-extractor/1.1/sonar-forms-plsql-extractor-1.1-jar-with-dependencies.jar
14 |
15 | Prerequisites
16 | -------------
17 | This extractor uses the Oracle JDAPI library that is included in the [Oracle Developer Suite](http://www.oracle.com/technetwork/developer-tools/developer-suite/downloads/index.html). Therefore a full installation of the Oracle Developer Suite is required. Once installed, check that the environment is correctly set:
18 |
19 | The "PATH" environment variable must contain the Oracle Developer Suite paths, for example: ```PATH=C:/OracleDevSuite/jlib;C:/OracleDevSuite/bin;```
20 |
21 | Use Java 1.6 or higher to run Sonar Forms PLSQL Extractor.
22 |
23 | How to Execute
24 | --------------
25 | Download the JAR file then execute:
26 |
27 | ```
28 | set FORMS_PATH=C:\forms_project
29 | java -DinputDir=C:\forms_project -DoutputDir=C:\extracted_plsql -cp C:\path\to\sonar-forms-plsql-extractor-1.1-jar-with-dependencies.jar;C:\path\to\oracle\forms\java\frmjdapi.jar org.sonar.oracleforms.plsql.PlSqlExtractor
30 | ```
31 |
32 | Notes:
33 | * The optional property ```formsExtensions``` is a comma-separated list of extensions of Oracle Forms files to extract. Its default value is ```fmb,mmb,olb,pll```.
34 | * The output directory, as set by the outputDir property, must exist and is not cleaned up. Generated files override existing ones.
35 |
36 | FAQ
37 | ---
38 |
39 | Q : I'm getting "Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class oracle.forms.jdapi.Jdapi" whilst my env variables and paths are correctly configured, why ?
40 |
41 | A : Oracle Developer Suite used to perform the extraction is available only for x32 OS. As a consequence, the Oracle Forms PL/SQL Extractor will work only on x32 OS.
42 |
43 | How to Build Sources [](https://travis-ci.org/SonarQubeCommunity/sonar-forms-plsql-extractor)
44 | --------------------
45 |
46 | The Java library frmjdapi is provided by the Oracle Developer Suite (see forms/java/frmjdapi.jar) and must be installed into the Maven repository :
47 |
48 | ```
49 | mvn install:install-file -Dfile=/path/to/frmjdapi.jar -DgroupId=com.oracle -DartifactId=frmjdapi -Dversion=10.0 -Dpackaging=jar
50 | ```
51 |
52 | Then simply execute the following command. It does not require Oracle Developer Suite on the box:
53 |
54 | ```
55 | mvn clean install
56 | ```
57 |
58 | Medium tests are executed when enabling the profile "runMediumTests". Note that it requires the Oracle Dev Suite on the box:
59 |
60 | ```
61 | mvn clean install -PrunMediumTests
62 | ```
63 |
64 | License
65 | -------
66 |
67 | GNU LGPL v3
68 |
--------------------------------------------------------------------------------
/libs/frmjdapi-10.0.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/libs/frmjdapi-10.0.jar
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | org.codehaus.sonar-plugins
6 | parent
7 | 18
8 |
9 | sonar-forms-plsql-extractor
10 | 1.2-SNAPSHOT
11 | Forms PL/SQL Extractor
12 | Command-line that extracts PL/SQL code from Oracle Forms project
13 | 2014
14 |
15 |
16 | SonarSource
17 | http://www.sonarsource.com
18 |
19 |
20 |
21 |
22 | GNU LGPL 3
23 | http://www.gnu.org/licenses/lgpl.txt
24 | repo
25 |
26 |
27 |
28 |
29 | scm:git:https://github.com/SonarQubeCommunity/sonar-forms-plsql-extractor
30 | scm:git:https://github.com/SonarQubeCommunity/sonar-forms-plsql-extractor
31 | https://github.com/SonarQubeCommunity/sonar-forms-plsql-extractor
32 | HEAD
33 |
34 |
35 |
36 | GitHub Issues
37 | https://github.com/SonarQubeCommunity/sonar-forms-plsql-extractor/issues
38 |
39 |
40 |
41 |
42 | com.oracle
43 | frmjdapi
44 | 10.0
45 | provided
46 |
47 |
48 | com.google.code.findbugs
49 | jsr305
50 | 1.3.9
51 | provided
52 |
53 |
54 | org.slf4j
55 | slf4j-simple
56 | 1.7.6
57 |
58 |
59 | commons-io
60 | commons-io
61 | 2.4
62 |
63 |
64 | commons-lang
65 | commons-lang
66 | 2.6
67 |
68 |
69 |
70 |
71 | junit
72 | junit
73 | 4.11
74 | test
75 |
76 |
77 | org.easytesting
78 | fest-assert
79 | 1.4
80 | test
81 |
82 |
83 | org.mockito
84 | mockito-all
85 | 1.9.5
86 | test
87 |
88 |
89 |
90 |
91 |
92 |
93 | maven-assembly-plugin
94 | 2.2.2
95 |
96 |
97 |
98 | org.sonar.oracleforms.plsql.PlSqlExtractor
99 |
100 |
101 |
102 | jar-with-dependencies
103 |
104 |
105 |
106 |
107 | make-assembly
108 | package
109 |
110 | single
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 | runMediumTests
121 |
122 |
123 |
124 | org.apache.maven.plugins
125 | maven-surefire-plugin
126 |
127 |
128 | **/*Test.java
129 | **/MediumTesting.java
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/Form.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import oracle.forms.jdapi.*;
23 | import org.apache.commons.io.FileUtils;
24 | import org.apache.commons.io.IOUtils;
25 | import org.apache.commons.lang.StringUtils;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.sonar.oracleforms.plsql.decorators.DecoratorFactory;
29 |
30 | import javax.annotation.Nullable;
31 | import java.io.*;
32 |
33 | class Form {
34 |
35 | private static final Logger LOG = LoggerFactory.getLogger(Form.class);
36 |
37 | private final JdapiModule jdapiModule;
38 |
39 | Form(JdapiModule jdapiModule) {
40 | this.jdapiModule = jdapiModule;
41 | }
42 |
43 | void destroy() {
44 | jdapiModule.destroy();
45 | }
46 |
47 | void extractPlsql(File toDir) throws IOException {
48 | LOG.debug("Browse JDAPI nodes...");
49 | Node root = browse(jdapiModule, null);
50 | File targetDir = createTargetDir(root, toDir);
51 | LOG.debug("Extract program units...");
52 | writeProgramUnits(root, targetDir);
53 | LOG.debug("Extract GUI...");
54 | writeGui(root, targetDir);
55 |
56 | }
57 |
58 | private File createTargetDir(Node root, File toDir) throws IOException {
59 | File targetDir = new File(toDir, root.getName());
60 | FileUtils.forceMkdir(targetDir);
61 | return targetDir;
62 | }
63 |
64 | protected void writeGui(Node node, File targetDir) throws IOException {
65 | if (node != null && node.isModule()) {
66 | String plsql = DecoratorFactory.decorate(node);
67 | if (StringUtils.isNotBlank(plsql)) {
68 | File plsqlFile = createPlsqlFile(targetDir, node.getName() + "_GUI");
69 | Writer writer = new PrintWriter(new BufferedWriter(new FileWriter(plsqlFile)));
70 | try {
71 | writer.write(plsql);
72 | } finally {
73 | IOUtils.closeQuietly(writer);
74 | }
75 | }
76 | }
77 | }
78 |
79 | private void writeProgramUnits(Node node, File targetDir) throws IOException {
80 | if (node != null) {
81 | if (node.isProgramUnit() && !node.isAlias()) {
82 | String plsql = DecoratorFactory.decorate(node);
83 | if (StringUtils.isNotBlank(plsql)) {
84 | File plsqlFile = createPlsqlFile(targetDir, jdapiModule.getName() + "_" + node.getName());
85 | Writer writer = new PrintWriter(new BufferedWriter(new FileWriter(plsqlFile)));
86 | try {
87 | writer.write(plsql);
88 |
89 | } finally {
90 | IOUtils.closeQuietly(writer);
91 | }
92 | }
93 | }
94 | for (Node child : node.getChildren()) {
95 | writeProgramUnits(child, targetDir);
96 | }
97 | }
98 | }
99 |
100 | private Node browse(JdapiObject jdapiObject, @Nullable Node parent) throws IOException {
101 | Node node = new Node(parent, jdapiObject.getName());
102 | if (jdapiObject instanceof FormModule) {
103 | node.setType(Node.Type.FORM_MODULE);
104 | browse(((FormModule) jdapiObject).getBlocks(), node);
105 | browse(((FormModule) jdapiObject).getMenus(), node);
106 | browse(((FormModule) jdapiObject).getProgramUnits(), node);
107 | browse(((FormModule) jdapiObject).getTriggers(), node);
108 |
109 | } else if (jdapiObject instanceof MenuModule) {
110 | node.setType(Node.Type.MENU_MODULE);
111 | browse(((MenuModule) jdapiObject).getMenus(), node);
112 | browse(((MenuModule) jdapiObject).getProgramUnits(), node);
113 |
114 | } else if (jdapiObject instanceof PlsqlModule) {
115 | node.setType(Node.Type.PLSQL_MODULE);
116 | browse(((PlsqlModule) jdapiObject).getProgramUnits(), node);
117 |
118 | } else if (jdapiObject instanceof Block) {
119 | node.setType(Node.Type.BLOCK);
120 | browse(((Block) jdapiObject).getItems(), node);
121 | browse(((Block) jdapiObject).getTriggers(), node);
122 |
123 | } else if (jdapiObject instanceof Menu) {
124 | node.setType(Node.Type.MENU);
125 | browse(((Menu) jdapiObject).getMenuItems(), node);
126 |
127 | } else if (jdapiObject instanceof MenuItem) {
128 | node.setType(Node.Type.MENU_ITEM).setPlsql(((MenuItem) jdapiObject).getCommandText());
129 |
130 | } else if (jdapiObject instanceof ProgramUnit) {
131 | completeProgramUnit(jdapiObject, node);
132 |
133 | } else if (jdapiObject instanceof Trigger) {
134 | completeTrigger(jdapiObject, node);
135 |
136 | } else if (jdapiObject instanceof Item) {
137 | node.setType(Node.Type.ITEM);
138 | browse(((Item) jdapiObject).getTriggers(), node);
139 |
140 | } else {
141 | LOG.error("Not implemented type {}", jdapiObject.getClass());
142 | }
143 | if (node.isAlias()) {
144 | LOG.debug(node.getKey() + " is an alias of '" + node.getParentName() + "'");
145 | }
146 | return node;
147 | }
148 |
149 | private void completeProgramUnit(JdapiObject jdapiObject, Node node) {
150 | if (!isInherited(jdapiObject, JdapiTypes.PROGRAMUNIT_TEXT_PTID)) {
151 | node.setParentName(((ProgramUnit) jdapiObject).getParentName());
152 | node.setType(Node.Type.PROGRAM_UNIT).setPlsql(((ProgramUnit) jdapiObject).getProgramUnitText());
153 | } else {
154 | LOG.debug("Exclude inherited program unit: " + node.getKey());
155 | }
156 | }
157 |
158 | private void completeTrigger(JdapiObject jdapiObject, Node node) {
159 | if (!isInherited(jdapiObject, JdapiTypes.TRIGGER_TEXT_PTID)) {
160 | node.setParentName(((Trigger) jdapiObject).getParentName());
161 | node.setType(Node.Type.TRIGGER).setPlsql(((Trigger) jdapiObject).getTriggerText());
162 | } else {
163 | LOG.debug("Exclude inherited trigger: " + node.getKey());
164 | }
165 | }
166 |
167 | /**
168 | * Do not extract inherited PL/SQL code
169 | * See PLSQL-342
170 | */
171 | private boolean isInherited(JdapiObject jdapiObject, int type) {
172 | try {
173 | return jdapiObject.getPropertyState(type) == JdapiObject.PROPERTY_INHERITED_VALUE;
174 | } catch (Exception e) {
175 | // ignore, the property does not exist
176 | return false;
177 | }
178 | }
179 |
180 | private Node browse(JdapiIterator iterator, Node parent) throws IOException {
181 | while (iterator.hasNext()) {
182 | Object obj = iterator.next();
183 | if (obj instanceof JdapiObject) {
184 | browse((JdapiObject) obj, parent);
185 | }
186 | }
187 | return parent;
188 | }
189 |
190 | private File createPlsqlFile(File targetDir, String name) throws IOException {
191 | File plsqlFile = new File(targetDir, name + ".sql");
192 | plsqlFile.createNewFile();
193 | return plsqlFile;
194 | }
195 |
196 | }
197 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/JdapiAvailability.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | class JdapiAvailability {
23 | private static final String JDAPI_CLASSNAME = "oracle.forms.jdapi.Jdapi";
24 |
25 | void check() {
26 | check(JDAPI_CLASSNAME);
27 | }
28 |
29 | void check(String classname) {
30 | if (!isAvailableInClasspath(classname)) {
31 | throw new IllegalStateException("Oracle JDAPI file (usually named frmjdapi.jar) is not available in classpath");
32 | }
33 | }
34 |
35 | boolean isAvailableInClasspath(String classname) {
36 | try {
37 | JdapiAvailability.class.getClassLoader().loadClass(classname);
38 | return true;
39 |
40 | } catch (ClassNotFoundException e) {
41 | return false;
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/JdapiProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import oracle.forms.jdapi.Jdapi;
23 | import oracle.forms.jdapi.JdapiModule;
24 |
25 | import java.io.File;
26 | import java.io.IOException;
27 |
28 | class JdapiProxy {
29 |
30 | void init() throws IOException {
31 | Jdapi.setFailSubclassLoad(false);
32 | Jdapi.setFailLibraryLoad(true);
33 | }
34 |
35 | Form openModule(File formFile) {
36 | return new Form(JdapiModule.openModule(formFile));
37 | }
38 |
39 | void shutdown() {
40 | Jdapi.shutdown();
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/Node.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.apache.commons.lang.StringUtils;
23 | import org.apache.commons.lang.builder.ReflectionToStringBuilder;
24 | import org.apache.commons.lang.builder.ToStringStyle;
25 |
26 | import javax.annotation.Nullable;
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 | public class Node {
31 |
32 | private static final String SEPARATOR = "/";
33 |
34 | public enum Type {
35 | FORM_MODULE, MENU_MODULE, PLSQL_MODULE, BLOCK, MENU, MENU_ITEM, PROGRAM_UNIT, TRIGGER, ITEM
36 | }
37 |
38 | private String path;
39 | private String name;
40 | private String plsql;
41 | private Type type;
42 | private final List children;
43 | private String parentName = null;
44 |
45 | public Node(@Nullable Node parent, String name) {
46 | this.name = name;
47 | this.children = new ArrayList();
48 | if (parent != null) {
49 | path = parent.getKey();
50 | parent.addChild(this);
51 | }
52 | }
53 |
54 | public Node(String name) {
55 | this(null, name);
56 | }
57 |
58 | public boolean isAlias() {
59 | return parentName != null;
60 | }
61 |
62 | public void setParentName(String parentName) {
63 | if (StringUtils.isNotEmpty(parentName)) {
64 | this.parentName = parentName;
65 | }
66 | }
67 |
68 | public List getChildren() {
69 | return children;
70 | }
71 |
72 | public List getDescendents() {
73 | List descendents = new ArrayList();
74 | fillDescendents(descendents);
75 | return descendents;
76 | }
77 |
78 | private void fillDescendents(List descendents) {
79 | for (Node child : children) {
80 | descendents.add(child);
81 | child.fillDescendents(descendents);
82 | }
83 | }
84 |
85 | public Node addChild(Node child) {
86 | if (child != null) {
87 | children.add(child);
88 | }
89 | return this;
90 | }
91 |
92 | @Nullable
93 | public String getName() {
94 | return name;
95 | }
96 |
97 | public String getPlsqlName() {
98 | return StringUtils.replace(name, "-", "_");
99 | }
100 |
101 | public String getPlsql() {
102 | return plsql;
103 | }
104 |
105 | public Node setPath(String path) {
106 | this.path = path;
107 | return this;
108 | }
109 |
110 | public Node setName(String name) {
111 | this.name = name;
112 | return this;
113 | }
114 |
115 | public Node setPlsql(String plsql) {
116 | this.plsql = plsql;
117 | return this;
118 | }
119 |
120 | public boolean hasPlsql(boolean includeDescendents) {
121 | if (StringUtils.isNotBlank(plsql) && !isCalculatedField()) {
122 | return true;
123 | }
124 | if (includeDescendents) {
125 | for (Node descendent : getDescendents()) {
126 | if (descendent.hasPlsql(false)) {
127 | return true;
128 | }
129 | }
130 | }
131 | return false;
132 | }
133 |
134 | public boolean hasPlsql() {
135 | return hasPlsql(false);
136 | }
137 |
138 | public Type getType() {
139 | return type;
140 | }
141 |
142 | public Node setType(Type type) {
143 | this.type = type;
144 | return this;
145 | }
146 |
147 | public boolean isGuiBlock() {
148 | return isModule() || Type.MENU.equals(type) || Type.BLOCK.equals(type) || Type.ITEM.equals(type);
149 | }
150 |
151 | public boolean isGuiItem() {
152 | return Type.TRIGGER.equals(type) || Type.MENU_ITEM.equals(type);
153 | }
154 |
155 | public boolean isGui() {
156 | return isGuiBlock() || isGuiItem();
157 | }
158 |
159 | public boolean isModule() {
160 | return Type.FORM_MODULE.equals(type) || Type.MENU_MODULE.equals(type) || Type.PLSQL_MODULE.equals(type);
161 | }
162 |
163 | public boolean isCalculatedField() {
164 | return "FORMULA-CALCULATION".equals(getName());
165 | }
166 |
167 | public boolean isProgramUnit() {
168 | return Type.PROGRAM_UNIT.equals(type);
169 | }
170 |
171 | public String getKey() {
172 | return new StringBuilder().append(StringUtils.defaultString(path)).append(SEPARATOR).append(StringUtils.defaultString(name)).toString();
173 | }
174 |
175 | @Override
176 | public String toString() {
177 | return new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE).toString();
178 | }
179 |
180 | public String getParentName() {
181 | return parentName;
182 | }
183 |
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/PlSqlExtractor.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.slf4j.Logger;
23 | import org.slf4j.LoggerFactory;
24 |
25 | import java.io.File;
26 | import java.io.IOException;
27 | import java.util.Properties;
28 |
29 | public class PlSqlExtractor {
30 |
31 | private static final Logger LOG = LoggerFactory.getLogger(PlSqlExtractor.class);
32 |
33 | private final Settings settings;
34 | private final JdapiProxy jdapi;
35 | private final JdapiAvailability jdapiAvailability;
36 |
37 | PlSqlExtractor(Settings settings, JdapiAvailability jdapiAvailability, JdapiProxy jdapi) {
38 | this.settings = settings;
39 | this.jdapiAvailability = jdapiAvailability;
40 | this.jdapi = jdapi;
41 | }
42 |
43 | public void run() throws IOException {
44 | settings.logEnv();
45 | jdapiAvailability.check();
46 | try {
47 | jdapi.init();
48 | LOG.info("PL/SQL output directory is: " + settings.outputDir());
49 | for (File formFile : settings.formsFiles()) {
50 | extractForm(formFile, settings.outputDir());
51 | }
52 | } finally {
53 | jdapi.shutdown();
54 | }
55 | }
56 |
57 | void extractForm(File formFile, File toDir) throws IOException {
58 | long start = System.currentTimeMillis();
59 | LOG.info("Process file: " + formFile.getAbsolutePath());
60 | Form form = null;
61 | try {
62 | form = jdapi.openModule(formFile);
63 | form.extractPlsql(toDir);
64 | } finally {
65 | if (form != null) {
66 | try {
67 | form.destroy();
68 | } catch (Exception e) {
69 | // silent
70 | LOG.warn("Fai lto destroy form " + formFile, e);
71 | }
72 | }
73 | }
74 | LOG.info(String.format(" PL/SQL code extracted in %d ms", System.currentTimeMillis() - start));
75 | }
76 |
77 |
78 | public static void main(String[] args) throws IOException {
79 | create(System.getProperties()).run();
80 | }
81 |
82 | static PlSqlExtractor create(Properties props) {
83 | return new PlSqlExtractor(new Settings(props), new JdapiAvailability(), new JdapiProxy());
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/Settings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.apache.commons.io.FileUtils;
23 | import org.apache.commons.lang.StringUtils;
24 | import org.slf4j.Logger;
25 | import org.slf4j.LoggerFactory;
26 |
27 | import javax.annotation.Nullable;
28 | import java.io.File;
29 | import java.util.Collection;
30 | import java.util.Properties;
31 |
32 | class Settings {
33 |
34 | private static final Logger LOG = LoggerFactory.getLogger(Settings.class);
35 |
36 | static final String[] FORMS_EXTENSIONS = {"fmb", "mmb", "olb", "pll"};
37 |
38 | private final File inputDir;
39 | private final File outputDir;
40 | private final String[] formsExtensions;
41 |
42 | Settings(Properties props) {
43 | inputDir = initDir(props, "inputDir");
44 | outputDir = initDir(props, "outputDir");
45 | String extensions = props.getProperty("formsExtensions");
46 | if (extensions == null) {
47 | formsExtensions = FORMS_EXTENSIONS;
48 | } else {
49 | formsExtensions = StringUtils.split(extensions, ",");
50 | }
51 | }
52 |
53 | Collection formsFiles() {
54 | return FileUtils.listFiles(inputDir, formsExtensions, true);
55 | }
56 |
57 | File inputDir() {
58 | return inputDir;
59 | }
60 |
61 | File outputDir() {
62 | return outputDir;
63 | }
64 |
65 | void logEnv() {
66 | logEnvVariable("PATH");
67 | logEnvVariable("ORACLE_HOME");
68 | logEnvVariable("FORMS_PATH");
69 | log("CLASSPATH", System.getProperty("java.class.path"));
70 | }
71 |
72 | private void logEnvVariable(String key) {
73 | log(key, System.getenv(key));
74 | }
75 |
76 | private void log(String key, @Nullable String value) {
77 | LOG.info(String.format("%s: %s", key, value));
78 | }
79 |
80 | private static File initDir(Properties props, String propKey) {
81 | String path = props.getProperty(propKey);
82 | if (path == null) {
83 | throw new IllegalStateException(String.format("Property '%s' is required", propKey));
84 | }
85 | File dir = new File(path);
86 | if (!dir.exists() || !dir.isDirectory()) {
87 | throw new IllegalStateException(String.format("Value of property '%s' is not valid. Directory does not exist: %s", propKey, path));
88 | }
89 | return dir;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/CalculatedFieldDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.sonar.oracleforms.plsql.Node;
23 |
24 | public class CalculatedFieldDecorator implements Decorator {
25 |
26 | public String decorate(Node node, String text) {
27 | if (node.isCalculatedField()) {
28 | return "";
29 | }
30 | return text;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/CommentPathDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.apache.commons.io.IOUtils;
23 | import org.apache.commons.lang.StringUtils;
24 | import org.sonar.oracleforms.plsql.Node;
25 |
26 | public class CommentPathDecorator implements Decorator {
27 |
28 | public String decorate(Node node, String text) {
29 | if (node.isGuiItem() && StringUtils.isNotBlank(text)) {
30 | return new StringBuilder()
31 | .append("-- path: ")
32 | .append(node.getKey())
33 | .append(" (")
34 | .append(node.getType())
35 | .append(")")
36 | .append(IOUtils.LINE_SEPARATOR)
37 | .append(text)
38 | .toString();
39 | }
40 | return text;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/Decorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.sonar.oracleforms.plsql.Node;
23 |
24 | public interface Decorator {
25 | String decorate(Node node, String text);
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/DecoratorFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.apache.commons.lang.StringUtils;
23 | import org.sonar.oracleforms.plsql.Node;
24 |
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | public final class DecoratorFactory {
29 |
30 | private static final List DECORATORS = Arrays.asList(new CalculatedFieldDecorator(),
31 | new GuiBlockDecorator(), new GuiItemDecorator(),
32 | new CommentPathDecorator(), new ProgramUnitDecorator());
33 |
34 | private DecoratorFactory() {
35 | // only static methods
36 | }
37 |
38 | public static String decorate(Node node) {
39 | String plsql = StringUtils.defaultString(node.getPlsql());
40 | for (Decorator decorator : DECORATORS) {
41 | plsql = decorator.decorate(node, plsql);
42 | }
43 | return plsql;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/GuiBlockDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.apache.commons.io.IOUtils;
23 | import org.apache.commons.lang.StringUtils;
24 | import org.sonar.oracleforms.plsql.Node;
25 |
26 | public class GuiBlockDecorator implements Decorator {
27 |
28 | public String decorate(Node node, String text) {
29 | if ( !node.isGuiBlock()) {
30 | return text;
31 | }
32 |
33 | StringBuilder childrenBuilder = new StringBuilder();
34 | for (Node child : node.getChildren()) {
35 | if (child.isGui()) {
36 | String childPlsql = DecoratorFactory.decorate(child);
37 | if (StringUtils.isNotBlank(childPlsql)) {
38 | childrenBuilder.append(childPlsql).append(IOUtils.LINE_SEPARATOR);
39 | }
40 | }
41 | }
42 |
43 | if (StringUtils.isBlank(childrenBuilder.toString())) {
44 | return text;
45 | }
46 | return new StringBuilder()
47 | .append("Declare").append(IOUtils.LINE_SEPARATOR)
48 | .append("Procedure ").append(node.getPlsqlName()).append("_").append(" Is").append(IOUtils.LINE_SEPARATOR)
49 | .append("Begin").append(IOUtils.LINE_SEPARATOR)
50 | .append(childrenBuilder)
51 | .append("End ").append(node.getPlsqlName()).append("_").append(";").append(IOUtils.LINE_SEPARATOR)
52 | .append("Begin").append(IOUtils.LINE_SEPARATOR)
53 | .append(node.getPlsqlName()).append("_").append(";").append(IOUtils.LINE_SEPARATOR)
54 | .append("End;").append(IOUtils.LINE_SEPARATOR)
55 | .toString();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/GuiItemDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.apache.commons.io.IOUtils;
23 | import org.apache.commons.lang.StringUtils;
24 | import org.sonar.oracleforms.plsql.Node;
25 |
26 | public class GuiItemDecorator implements Decorator {
27 |
28 | public String decorate(Node node, String text) {
29 | if ( !node.isGuiItem() || StringUtils.isBlank(text) || node.isAlias()) {
30 | return text;
31 | }
32 |
33 | return new StringBuilder()
34 | .append("Declare").append(IOUtils.LINE_SEPARATOR)
35 | .append("Procedure ").append(node.getPlsqlName()).append("_").append(" Is").append(IOUtils.LINE_SEPARATOR)
36 | .append("Begin").append(IOUtils.LINE_SEPARATOR)
37 | .append(text).append(IOUtils.LINE_SEPARATOR)
38 | .append("End ").append(node.getPlsqlName()).append("_").append(";").append(IOUtils.LINE_SEPARATOR)
39 | .append("Begin").append(IOUtils.LINE_SEPARATOR)
40 | .append(node.getPlsqlName()).append("_").append(";").append(IOUtils.LINE_SEPARATOR)
41 | .append("End;").append(IOUtils.LINE_SEPARATOR)
42 | .toString();
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/ProgramUnitDecorator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.sonar.oracleforms.plsql.Node;
23 |
24 | public class ProgramUnitDecorator implements Decorator {
25 |
26 | public String decorate(Node node, String text) {
27 | if ( !node.isProgramUnit()) {
28 | return text;
29 | }
30 |
31 | return "CREATE " + text;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/decorators/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.oracleforms.plsql.decorators;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/src/main/java/org/sonar/oracleforms/plsql/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | @ParametersAreNonnullByDefault
21 | package org.sonar.oracleforms.plsql;
22 |
23 | import javax.annotation.ParametersAreNonnullByDefault;
24 |
25 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/JdapiAvailabilityTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.junit.Test;
23 |
24 | import static org.fest.assertions.Assertions.assertThat;
25 | import static org.fest.assertions.Fail.fail;
26 |
27 | public class JdapiAvailabilityTest {
28 | @Test
29 | public void check() throws Exception {
30 | new JdapiAvailability().check();
31 | // does not fail because frmjdapi is available in test classpath
32 | }
33 |
34 | @Test
35 | public void fail_if_class_not_found() throws Exception {
36 | try {
37 | new JdapiAvailability().check("does.not.Exist");
38 | fail();
39 | } catch (IllegalStateException e) {
40 | assertThat(e).hasMessage("Oracle JDAPI file (usually named frmjdapi.jar) is not available in classpath");
41 | }
42 | }
43 |
44 | @Test
45 | public void success_if_class_found() throws Exception {
46 | new JdapiAvailability().check(PlSqlExtractor.class.getName());
47 | // no failure
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/MediumTesting.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.apache.commons.io.FileUtils;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.TemporaryFolder;
26 |
27 | import java.io.File;
28 | import java.io.IOException;
29 | import java.util.ArrayList;
30 | import java.util.List;
31 | import java.util.Properties;
32 |
33 | import static org.fest.assertions.Assertions.assertThat;
34 |
35 | /**
36 | * This class requires Oracle Developer Suite and its Forms module to be installed
37 | * on the machine.
38 | *
39 | * Note that class name is suffixed by Testing but not Test in order to be excluded
40 | * by default build.
41 | */
42 | public class MediumTesting {
43 |
44 | @Rule
45 | public TemporaryFolder temp = new TemporaryFolder();
46 |
47 | @Test
48 | public void extract_plsql_code_from_oracle_forms() throws Exception {
49 | File outputDir = temp.newFolder();
50 | Properties props = new Properties();
51 | props.setProperty("inputDir", new File("src/test/resources/org/sonar/oracleforms/plsql/MediumTest/sample").getAbsolutePath());
52 | props.setProperty("outputDir", outputDir.getAbsolutePath());
53 |
54 | PlSqlExtractor.create(props).run();
55 |
56 | List generatedSqlFiles = new ArrayList(FileUtils.listFiles(outputDir, new String[]{"sql"}, true));
57 | assertThat(generatedSqlFiles).hasSize(1);
58 | File sqlFile = generatedSqlFiles.get(0);
59 | assertThat(sqlFile.getCanonicalPath()).isEqualTo(new File(outputDir, "UE_SAMP/UE_SAMP_GUI.sql").getCanonicalPath());
60 | String sql = FileUtils.readFileToString(sqlFile);
61 | assertThat(sql)
62 | .isNotEmpty()
63 | .contains("Procedure UE_SAMP_ Is")
64 | .contains("-- path: /UE_SAMP/BLOCK1/ITEM3/PRE-TEXT-ITEM (TRIGGER)");
65 | }
66 |
67 | @Test
68 | public void extract_oracle_demo() throws Exception {
69 | assertExtractionOk("oracle-demo");
70 | }
71 |
72 | @Test
73 | public void extract_oracle_bigraph() throws Exception {
74 | assertExtractionOk("oracle-bigraph");
75 | }
76 |
77 | private void assertExtractionOk(String project) throws IOException {
78 | File outputDir = temp.newFolder();
79 | Properties props = new Properties();
80 | props.setProperty("inputDir", new File("src/test/resources/org/sonar/oracleforms/plsql/MediumTest/" + project).getAbsolutePath());
81 | props.setProperty("outputDir", outputDir.getAbsolutePath());
82 |
83 | PlSqlExtractor.create(props).run();
84 |
85 | List generatedSqlFiles = new ArrayList(FileUtils.listFiles(outputDir, new String[]{"sql"}, true));
86 | assertThat(generatedSqlFiles.size()).isGreaterThan(0);
87 | }
88 |
89 | @Test
90 | public void forms_extensions_property() throws Exception {
91 | File outputDir = temp.newFolder();
92 | Properties props = new Properties();
93 | props.setProperty("inputDir", new File("src/test/resources/org/sonar/oracleforms/plsql/MediumTest/sample").getAbsolutePath());
94 | props.setProperty("outputDir", outputDir.getAbsolutePath());
95 |
96 | props.setProperty("formsExtensions", "forms,oracle");
97 | PlSqlExtractor.create(props).run();
98 | assertThat(FileUtils.listFiles(outputDir, new String[]{"sql"}, true)).isEmpty();
99 |
100 | props.setProperty("formsExtensions", "forms,fmb");
101 | PlSqlExtractor.create(props).run();
102 | assertThat(FileUtils.listFiles(outputDir, new String[]{"sql"}, true)).hasSize(1);
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/NodeTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.junit.Test;
23 |
24 | import static org.fest.assertions.Assertions.assertThat;
25 |
26 | public class NodeTest {
27 |
28 | @Test
29 | public void keyShouldNotContainNull() {
30 | assertThat(new Node(null, "foo").getKey()).doesNotContain("null");
31 | }
32 |
33 | @Test
34 | public void to_string() {
35 | assertThat(new Node("FORMULA-CALCULATION").toString()).isEqualTo("Node[path=,name=FORMULA-CALCULATION,plsql=,type=,children=[],parentName=]");
36 | }
37 |
38 | @Test
39 | public void keyShouldStartBySlash() {
40 | assertThat(new Node("foo").getKey()).isEqualTo("/foo");
41 | assertThat(new Node(new Node("parent"), "foo").getKey()).isEqualTo("/parent/foo");
42 | }
43 |
44 | @Test
45 | public void calculatedFields() {
46 | assertThat(new Node("FORMULA-CALCULATION").isCalculatedField()).isTrue();
47 | assertThat(new Node("foo").isCalculatedField()).isFalse();
48 | }
49 |
50 | @Test
51 | public void hasPlsql() {
52 | Node foo = new Node("foo");
53 | assertThat(foo.setPlsql(" ").hasPlsql()).isFalse();
54 | assertThat(foo.setPlsql("").hasPlsql()).isFalse();
55 | assertThat(foo.setPlsql(null).hasPlsql()).isFalse();
56 | assertThat(foo.setPlsql("some sql").hasPlsql()).isTrue();
57 | }
58 |
59 | @Test
60 | public void isAlias() {
61 | Node pUnit = new Node("program unit");
62 | assertThat(pUnit.isAlias()).isFalse();
63 | pUnit.setParentName(null);
64 | assertThat(pUnit.isAlias()).isFalse();
65 | pUnit.setParentName("Another Form");
66 | assertThat(pUnit.isAlias()).isTrue();
67 | }
68 |
69 | @Test
70 | public void plsqlNameDoesNotContainMinus() {
71 | assertThat(new Node("foo").getPlsqlName()).isEqualTo("foo");
72 | assertThat(new Node("foo-bar").getPlsqlName()).isEqualTo("foo_bar");
73 | assertThat(new Node("foo_bar").getPlsqlName()).isEqualTo("foo_bar");
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/PlSqlExtractorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.junit.Rule;
23 | import org.junit.Test;
24 | import org.junit.rules.TemporaryFolder;
25 | import org.mockito.InOrder;
26 | import org.mockito.Mockito;
27 |
28 | import java.io.File;
29 | import java.util.Arrays;
30 |
31 | import static org.mockito.Matchers.any;
32 | import static org.mockito.Mockito.mock;
33 | import static org.mockito.Mockito.when;
34 |
35 | public class PlSqlExtractorTest {
36 |
37 | @Rule
38 | public TemporaryFolder temp = new TemporaryFolder();
39 |
40 | @Test
41 | public void run() throws Exception {
42 | JdapiAvailability jdapiAvailability = mock(JdapiAvailability.class);
43 | JdapiProxy jdapi = mock(JdapiProxy.class);
44 | when(jdapi.openModule(any(File.class))).thenReturn(mock(Form.class));
45 | Settings settings = mock(Settings.class);
46 | File forms1 = temp.newFile();
47 | File forms2 = temp.newFile();
48 | when(settings.formsFiles()).thenReturn(Arrays.asList(forms1, forms2));
49 |
50 | PlSqlExtractor extractor = new PlSqlExtractor(settings, jdapiAvailability, jdapi);
51 | extractor.run();
52 |
53 | InOrder inOrder = Mockito.inOrder(jdapiAvailability, jdapi);
54 | inOrder.verify(jdapiAvailability).check();
55 | inOrder.verify(jdapi).init();
56 | inOrder.verify(jdapi).openModule(forms1);
57 | inOrder.verify(jdapi).openModule(forms2);
58 | inOrder.verify(jdapi).shutdown();
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/SettingsTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql;
21 |
22 | import org.apache.commons.io.FileUtils;
23 | import org.junit.Rule;
24 | import org.junit.Test;
25 | import org.junit.rules.TemporaryFolder;
26 |
27 | import java.io.File;
28 | import java.util.Properties;
29 |
30 | import static org.fest.assertions.Assertions.assertThat;
31 | import static org.fest.assertions.Fail.fail;
32 |
33 | public class SettingsTest {
34 |
35 | @Rule
36 | public TemporaryFolder temp = new TemporaryFolder();
37 |
38 | @Test
39 | public void dirs_must_exist() throws Exception {
40 | File input = temp.newFolder("forms-sources");
41 | File output = temp.newFolder("plsql-sources");
42 | Properties props = new Properties();
43 | props.setProperty("inputDir", input.getAbsolutePath());
44 | props.setProperty("outputDir", output.getAbsolutePath());
45 |
46 | Settings settings = new Settings(props);
47 |
48 | assertThat(settings.inputDir()).isEqualTo(input);
49 | assertThat(settings.outputDir()).isEqualTo(output);
50 | }
51 |
52 | @Test
53 | public void fail_if_input_dir_does_not_exist() throws Exception {
54 | File input = temp.newFolder("forms-sources");
55 | Properties props = new Properties();
56 | props.setProperty("inputDir", input.getAbsolutePath());
57 | props.setProperty("outputDir", "target/unknown");
58 |
59 | try {
60 | new Settings(props);
61 | fail();
62 | } catch (IllegalStateException e) {
63 | assertThat(e).hasMessage("Value of property 'outputDir' is not valid. Directory does not exist: target/unknown");
64 | }
65 | }
66 |
67 | @Test
68 | public void fail_if_mandatory_property_is_not_set() throws Exception {
69 | try {
70 | new Settings(new Properties());
71 | fail();
72 | } catch (IllegalStateException e) {
73 | assertThat(e).hasMessage("Property 'inputDir' is required");
74 | }
75 | }
76 |
77 | @Test
78 | public void default_forms_files() throws Exception {
79 | File input = temp.newFolder("forms-sources");
80 | File forms1 = new File(input, "foo.fmb");
81 | FileUtils.touch(forms1);
82 | File forms2 = new File(input, "bar.pll");
83 | FileUtils.touch(forms2);
84 | File other = new File(input, "other.forms");
85 | FileUtils.touch(other);
86 |
87 | File output = temp.newFolder("plsql-sources");
88 | Properties props = new Properties();
89 | props.setProperty("inputDir", input.getAbsolutePath());
90 | props.setProperty("outputDir", output.getAbsolutePath());
91 |
92 | Settings settings = new Settings(props);
93 |
94 | assertThat(settings.formsFiles()).containsOnly(forms1, forms2);
95 | }
96 |
97 | @Test
98 | public void customized_forms_files() throws Exception {
99 | File input = temp.newFolder("forms-sources");
100 | File forms1 = new File(input, "foo.fmb");
101 | FileUtils.touch(forms1);
102 | File forms2 = new File(input, "bar.forms");
103 | FileUtils.touch(forms2);
104 | File other = new File(input, "other.txt");
105 | FileUtils.touch(other);
106 |
107 | File output = temp.newFolder("plsql-sources");
108 | Properties props = new Properties();
109 | props.setProperty("inputDir", input.getAbsolutePath());
110 | props.setProperty("outputDir", output.getAbsolutePath());
111 | props.setProperty("formsExtensions", "fmb,pll,forms");
112 |
113 | Settings settings = new Settings(props);
114 |
115 | assertThat(settings.formsFiles()).containsOnly(forms1, forms2);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/decorators/DecoratorsFactoryTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.apache.commons.lang.StringUtils;
23 | import org.junit.Test;
24 | import org.sonar.oracleforms.plsql.Node;
25 |
26 | import java.util.regex.Matcher;
27 | import java.util.regex.Pattern;
28 |
29 | import static org.fest.assertions.Assertions.assertThat;
30 |
31 | public class DecoratorsFactoryTest {
32 |
33 | /**
34 | * Full integration test on all decorators
35 | */
36 | @Test
37 | public void decorateModule() {
38 | Node module = new Node("form1").setType(Node.Type.FORM_MODULE);
39 | Node trigger1 = new Node(module, "trigger1").setType(Node.Type.TRIGGER).setPlsql("content of trigger one");
40 | Node block = new Node(module, "block1").setType(Node.Type.BLOCK);
41 | Node trigger2 = new Node(block, "trigger2").setType(Node.Type.TRIGGER).setPlsql("content of trigger two");
42 |
43 | String plsql = DecoratorFactory.decorate(module);
44 |
45 | Pattern p = Pattern.compile(".*Procedure form1_.*content of trigger one.*content of trigger two.*", Pattern.DOTALL);
46 | Matcher m = p.matcher(plsql);
47 | assertThat(m.matches()).isTrue();
48 | }
49 |
50 | @Test
51 | public void appendPlsqlCodeOnItems() {
52 | Node trigger = new Node("foo").setType(Node.Type.TRIGGER).setPlsql("xxx").setPath("mypath");
53 | assertThat(DecoratorFactory.decorate(trigger)).startsWith("-- path: mypath");
54 | assertThat(DecoratorFactory.decorate(trigger)).contains("xxx");
55 | }
56 |
57 | @Test
58 | public void doNotAppendNull() {
59 | Node trigger = new Node("foo").setType(Node.Type.TRIGGER).setPlsql(null);
60 | assertThat(DecoratorFactory.decorate(trigger)).doesNotContain("null");
61 | }
62 |
63 | @Test
64 | public void calculatedFieldsAreNotExtracted() {
65 | Node block = new Node("block").setType(Node.Type.BLOCK);
66 | Node trigger = new Node(block, "FORMULA-CALCULATION").setType(Node.Type.TRIGGER).setPlsql("foo=bar;");
67 | assertThat(StringUtils.isBlank(DecoratorFactory.decorate(block))).isTrue();
68 |
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/decorators/GuiBlockDecoratorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 | import org.sonar.oracleforms.plsql.Node;
25 |
26 | import java.io.PrintWriter;
27 | import java.io.StringWriter;
28 |
29 | import static org.fest.assertions.Assertions.assertThat;
30 |
31 | public class GuiBlockDecoratorTest {
32 |
33 | GuiBlockDecorator decorator = new GuiBlockDecorator();
34 | Node node = new Node("FORM_BLOCK");
35 |
36 | @Before
37 | public void init() {
38 | node.setType(Node.Type.FORM_MODULE);
39 | }
40 |
41 | @Test
42 | public void shouldNotDecorateNodeWitoutChildren() {
43 | assertThat(decorator.decorate(node, "")).isEqualTo("");
44 | }
45 |
46 | @Test
47 | public void shouldDecorateBlockWithChildContainingPlsql() {
48 | Node child = new Node("MY_TRIGGER");
49 | child.setPlsql("PLSQL");
50 | child.setType(Node.Type.TRIGGER);
51 | node.addChild(child);
52 |
53 | StringWriter expectedResult = new StringWriter();
54 | PrintWriter writer = new PrintWriter(expectedResult);
55 | writer.println("Declare");
56 | writer.println("Procedure FORM_BLOCK_ Is");
57 | writer.println("Begin");
58 | writer.println("-- path: /MY_TRIGGER (TRIGGER)");
59 | writer.println("Declare");
60 | writer.println("Procedure MY_TRIGGER_ Is");
61 | writer.println("Begin");
62 | writer.println("PLSQL");
63 | writer.println("End MY_TRIGGER_;");
64 | writer.println("Begin");
65 | writer.println("MY_TRIGGER_;");
66 | writer.println("End;");
67 | writer.println("");
68 | writer.println("End FORM_BLOCK_;");
69 | writer.println("Begin");
70 | writer.println("FORM_BLOCK_;");
71 | writer.println("End;");
72 | writer.flush();
73 |
74 | assertThat(decorator.decorate(node, "")).isEqualTo(expectedResult.toString());
75 | }
76 |
77 | @Test
78 | public void shouldNotDecorateBlockWithChildWithoutPlsql() {
79 | Node child = new Node("MY_TRIGGER");
80 | child.setType(Node.Type.TRIGGER);
81 | node.addChild(child);
82 |
83 | assertThat(decorator.decorate(node, "")).isEqualTo("");
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/decorators/GuiItemDecoratorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.junit.Test;
23 | import org.sonar.oracleforms.plsql.Node;
24 |
25 | import java.io.PrintWriter;
26 | import java.io.StringWriter;
27 |
28 | import static org.fest.assertions.Assertions.assertThat;
29 |
30 | public class GuiItemDecoratorTest {
31 |
32 | GuiItemDecorator decorator = new GuiItemDecorator();
33 |
34 | @Test
35 | public void shouldNotDecorateBlankAndNoneAliasGuiItem() {
36 | Node node = new Node("MY_TRIGGER");
37 | node.setType(Node.Type.TRIGGER);
38 | assertThat(decorator.decorate(node, "")).isEqualTo("");
39 | }
40 |
41 | @Test
42 | public void shouldNotDecorateNoneBlankAndNoneAliasAndNoneGuiItem() {
43 | Node node = new Node("MY_TRIGGER");
44 | node.setType(Node.Type.PLSQL_MODULE);
45 | assertThat(decorator.decorate(node, "PLSQL")).isEqualTo("PLSQL");
46 | }
47 |
48 | @Test
49 | public void shouldNotDecorateNoneBlankButAliasGuiItem() {
50 | Node node = new Node("MY_TRIGGER");
51 | node.setType(Node.Type.TRIGGER);
52 | node.setParentName("parentName");
53 | assertThat(decorator.decorate(node, "PLSQL")).isEqualTo("PLSQL");
54 | }
55 |
56 | @Test
57 | public void shouldDecorateNoneBlankAndNoneAliasGuiItem() {
58 | Node node = new Node("MY_TRIGGER");
59 | node.setType(Node.Type.TRIGGER);
60 |
61 | StringWriter expectedResult = new StringWriter();
62 | PrintWriter writer = new PrintWriter(expectedResult);
63 | writer.println("Declare");
64 | writer.println("Procedure MY_TRIGGER_ Is");
65 | writer.println("Begin");
66 | writer.println("PLSQL");
67 | writer.println("End MY_TRIGGER_;");
68 | writer.println("Begin");
69 | writer.println("MY_TRIGGER_;");
70 | writer.println("End;");
71 | writer.flush();
72 |
73 | assertThat(decorator.decorate(node, "PLSQL")).isEqualTo(expectedResult.toString());
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/test/java/org/sonar/oracleforms/plsql/decorators/ProgramUnitDecoratorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Forms PL/SQL Extractor
3 | * Copyright (C) 2014 SonarSource
4 | * dev@sonar.codehaus.org
5 | *
6 | * This program is free software; you can redistribute it and/or
7 | * modify it under the terms of the GNU Lesser General Public
8 | * License as published by the Free Software Foundation; either
9 | * version 3 of the License, or (at your option) any later version.
10 | *
11 | * This program is distributed in the hope that it will be useful,
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | * Lesser General Public License for more details.
15 | *
16 | * You should have received a copy of the GNU Lesser General Public
17 | * License along with this program; if not, write to the Free Software
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
19 | */
20 | package org.sonar.oracleforms.plsql.decorators;
21 |
22 | import org.junit.Test;
23 | import org.sonar.oracleforms.plsql.Node;
24 |
25 | import static org.fest.assertions.Assertions.assertThat;
26 |
27 |
28 | public class ProgramUnitDecoratorTest {
29 | @Test
30 | public void should_prefix_program_unit() {
31 | Node node = new Node("MY_PU");
32 | node.setType(Node.Type.PROGRAM_UNIT);
33 | assertThat(new ProgramUnitDecorator().decorate(node, "plsql")).isEqualTo("CREATE plsql");
34 | }
35 |
36 | @Test
37 | public void should_not_prefix_other_nodes() {
38 | Node node = new Node("MY_PU");
39 | node.setType(Node.Type.TRIGGER);
40 | assertThat(new ProgramUnitDecorator().decorate(node, "plsql")).isEqualTo("plsql");
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-bigraph/graph.fmb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-bigraph/graph.fmb
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-bigraph/graph.fmx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-bigraph/graph.fmx
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-demo/ffisamp.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-demo/ffisamp.dll
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-demo/webutil_demo.fmb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-demo/webutil_demo.fmb
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/oracle-demo/wu_fileupload_db_demo.sql:
--------------------------------------------------------------------------------
1 | drop table wu_fileupdown_demo;
2 | create table wu_fileupdown_demo (blob blob, id number(2));
3 | insert into wu_fileupdown_demo values (NULL,1);
4 | commit;
--------------------------------------------------------------------------------
/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/sample/ue_samp.fmb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SonarQubeCommunity/sonar-forms-plsql-extractor/79d978768234557dc705f2e791e0a3c1ac4a5bc1/src/test/resources/org/sonar/oracleforms/plsql/MediumTest/sample/ue_samp.fmb
--------------------------------------------------------------------------------