Revision 1050

View differences:

org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
        <fileSet>
24
            <directory>target/abeille</directory>
25
            <outputDirectory>.</outputDirectory>
26
        </fileSet>
27
  </fileSets>
28

  
29
  <dependencySets>
30

  
31
    <dependencySet>
32
      <useProjectArtifact>false</useProjectArtifact>
33
      <useTransitiveDependencies>false</useTransitiveDependencies>
34
      <outputDirectory>lib</outputDirectory>
35
      <includes>
36
        <!--
37
            Plugin libraries
38
        -->  
39
        <include>org.ini4j:ini4j</include>
40
        <include>net.sourceforge.thinlet:thinlet</include>
41
        <include>org.gvsig:org.gvsig.scripting.thing</include>
42
        <include>org.gvsig:org.gvsig.scripting.lib.api</include>
43
        <include>org.gvsig:org.gvsig.scripting.swing.api</include>
44
        <include>org.gvsig:org.gvsig.scripting.lib.impl</include>
45
        <include>org.gvsig:org.gvsig.scripting.swing.impl</include>
46
        <include>org.apache.tika:tika-core</include>        
47
        
48
        <!--
49
            Utility libraries
50
        -->
51
        <!-- JOpenDocument -->    
52
        <include>org.jopendocument:jOpenDocument</include>
53
        
54
        <!-- CSSBox webbrowser -->
55
        <include>net.sf.cssbox:cssbox</include>
56
        <include>net.sf.cssbox:swingbox</include>
57
        <include>net.sf.cssbox:jstyleparser</include>
58
        <include>net.sourceforge.nekohtml:nekohtml</include>
59
        <include>org.antlr:antlr-runtime</include>
60
                                
61
        <!--
62
            Script engines libraries
63
        -->
64

  
65
        <include>org.codehaus.groovy:groovy-all</include>
66

  
67
        <!--
68
        <include>org.renjin:renjin-script-engine:jar:jar-with-dependencies</include>
69
        -->
70
        
71
        <include>org.python:${jython.artifactId}</include>
72
        <include>com.github.tbekolay.jnumeric:jnumeric</include>
73
        
74
        <!--
75
        JRuby doesn't work by default on gvSIG, maybe the problems are
76
        related to the PluginClassLoader or to the way JRuby sets its
77
        internal classpath, so maybe setting the system property
78
        "org.jruby.embed.class.path" may solve the problem.
79
        See:
80
        http://kenai.com/projects/jruby/pages/RedBridge#Class_Path_%28Load_Path%29
81
        <include>org.jruby:jruby</include>
82
        -->
83

  
84
        <!--
85
            Scala doesn't work. When try to run a scala script show the message:
86
            Failed to initialize compiler: object scala in compiler mirror not found.
87
            ** Note that as of 2.8 scala does not assume use of the java classpath.
88
            ** For the old behavior pass -usejavacp to scala, or if using a Settings
89
            ** object programmatically, settings.usejavacp.value = true.
90
        
91
 
92
        <include>org.scala-lang:scala-dist</include>
93
        <include>org.scala-lang:scala-compiler</include>
94
        <include>org.scala-lang:scala-library</include>
95
        <include>org.scala-lang:scala-reflect</include>
96
        <include>org.scala-lang:scalap</include>
97
        -->
98
        <!--
99
        <include>jline:jline</include>
100
        -->
101

  
102
      </includes>
103
    </dependencySet>
104

  
105
    <dependencySet>
106
      <useProjectArtifact>false</useProjectArtifact>
107
      <useTransitiveDependencies>true</useTransitiveDependencies>
108
      <outputDirectory>lib</outputDirectory>
109
      <includes>
110
        <!--
111
            JGit support runtime libraries
112
        -->        
113
        <include>org.eclipse.jgit:org.eclipse.jgit</include>
114
        <include>com.jcraft:jsch</include>
115
        <include>com.googlecode.javaewah:JavaEWAH</include>
116
        <include>org.apache.httpcomponents:httpclient</include>
117
        <include>org.apache.httpcomponents:httpcore</include>
118
      </includes>
119
    </dependencySet>
120

  
121
    <dependencySet>
122
      <useProjectArtifact>false</useProjectArtifact>
123
      <useTransitiveDependencies>true</useTransitiveDependencies>
124
      <outputDirectory>lib</outputDirectory>
125
      <includes>
126
        <!--
127
            ICEPDF support runtime libraries
128
        -->        
129
        <include>org.icepdf.os:icepdf-viewer</include>
130
        <include>org.icepdf.os:icepdf-core</include>
131
      </includes>
132
    </dependencySet>
133

  
134
    <dependencySet>
135
      <useProjectArtifact>false</useProjectArtifact>
136
      <useTransitiveDependencies>true</useTransitiveDependencies>
137
      <outputDirectory>lib</outputDirectory>
138
      <includes>
139
        <!--
140
            flexmark-java, Markdown support libreries
141
        -->        
142
        <include>com.vladsch.flexmark:flexmark-all</include>
143
        <include>com.vladsch.flexmark:flexmark</include>
144
        <include>com.vladsch.flexmark:flexmark-ext-abbreviation</include>
145
        <include>com.vladsch.flexmark:flexmark-ext-anchorlink</include>
146
        <include>com.vladsch.flexmark:flexmark-ext-aside</include>
147
        <include>com.vladsch.flexmark:flexmark-ext-autolink</include>
148
        <include>org.nibor.autolink:autolink</include>
149
        <include>com.vladsch.flexmark:flexmark-ext-definition</include>
150
        <include>com.vladsch.flexmark:flexmark-ext-emoji</include>
151
        <include>com.vladsch.flexmark:flexmark-ext-escaped-character</include>
152
        <include>com.vladsch.flexmark:flexmark-ext-footnotes</include>
153
        <include>com.vladsch.flexmark:flexmark-ext-gfm-issues</include>
154
        <include>com.vladsch.flexmark:flexmark-ext-gfm-strikethrough</include>
155
        <include>com.vladsch.flexmark:flexmark-ext-gfm-tables</include>
156
        <include>com.vladsch.flexmark:flexmark-ext-gfm-tasklist</include>
157
        <include>com.vladsch.flexmark:flexmark-ext-gfm-users</include>
158
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-front-matter</include>
159
        <include>com.vladsch.flexmark:flexmark-ext-jekyll-tag</include>
160
        <include>com.vladsch.flexmark:flexmark-ext-ins</include>
161
        <include>com.vladsch.flexmark:flexmark-ext-xwiki-macros</include>
162
        <include>com.vladsch.flexmark:flexmark-ext-superscript</include>
163
        <include>com.vladsch.flexmark:flexmark-ext-tables</include>
164
        <include>com.vladsch.flexmark:flexmark-ext-toc</include>
165
        <include>com.vladsch.flexmark:flexmark-ext-typographic</include>
166
        <include>com.vladsch.flexmark:flexmark-ext-wikilink</include>
167
        <include>com.vladsch.flexmark:flexmark-ext-yaml-front-matter</include>
168
        <include>com.vladsch.flexmark:flexmark-formatter</include>
169
        <include>com.vladsch.flexmark:flexmark-html-parser</include>
170
        <include>org.jsoup:jsoup</include>
171
        <include>com.vladsch.flexmark:flexmark-jira-converter</include>
172
        <include>com.vladsch.flexmark:flexmark-pdf-converter</include>
173
        <include>com.openhtmltopdf:openhtmltopdf-core</include>
174
        <include>com.openhtmltopdf:openhtmltopdf-pdfbox</include>
175
        <include>org.apache.pdfbox:pdfbox</include>
176
        <include>org.apache.pdfbox:fontbox</include>
177
        <include>com.openhtmltopdf:openhtmltopdf-rtl-support</include>
178
        <include>com.ibm.icu:icu4j</include>
179
        <include>com.openhtmltopdf:openhtmltopdf-jsoup-dom-converter</include>
180
        <include>com.vladsch.flexmark:flexmark-profile-pegdown</include>
181
        <include>com.vladsch.flexmark:flexmark-util</include>
182
        <include>com.vladsch.flexmark:flexmark-youtrack-converter</include>        
183
      </includes>
184
    </dependencySet>
185
    
186
  </dependencySets>
187

  
188
</assembly>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptsInstallerInitializer.java
1
package org.gvsig.scripting.app.extension;
2

  
3
import java.io.File;
4
import org.apache.commons.io.FileUtils;
5
import org.gvsig.andami.PluginServices;
6
import org.gvsig.andami.PluginsLocator;
7
import org.gvsig.andami.PluginsManager;
8
import org.gvsig.installer.lib.api.InstallerLocator;
9
import org.gvsig.installer.lib.api.InstallerManager;
10
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
11
import org.gvsig.scripting.ScriptingLocator;
12
import org.gvsig.scripting.ScriptingManager;
13
import org.gvsig.tools.service.spi.ProviderFactory;
14
import org.gvsig.tools.service.spi.ProviderManager;
15
import org.gvsig.tools.util.Invocable;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

  
19
public class ScriptsInstallerInitializer implements Invocable {
20

  
21
    private static final Logger LOG = LoggerFactory.getLogger(ScriptsInstallerInitializer.class);
22
   
23
    @Override
24
    public Object call(Object... args) {
25
        // Cuando se hace la llamada a este metodo, aun no esta inicializado gvSIG.
26
        // Los servicios que ofrece el PluginsManager no son completos, solo algunos
27
        // de ellos estan disponibles. La lista de plugins aun no se ha cargado.
28
        try {
29
            String pluginName = (String) args[0];
30
            
31
            ProviderManager providerManager = InstallerProviderLocator.getProviderManager();            
32
            PluginsManager pluginManager = PluginsLocator.getManager();
33
            ScriptingManager manager = ScriptingLocator.getManager();
34
            InstallerManager installerManager = InstallerLocator.getInstallerManager();
35
            File pluginHomeFolder = pluginManager.getPluginHomeFolder(pluginName);
36
            
37
            String gvsigversion = pluginManager.getApplicationVersion().format("%M.%m.0") ;
38
            File home = FileUtils.getFile(pluginHomeFolder, gvsigversion) ;
39
            
40
            manager.setHomeFolder(home);
41
            manager.setPackagesFolder(pluginManager.getInstallFolder());
42
            
43
            File localAddonRepositoryFolder = new File(manager.getRootUserFolder(), "addons");
44
            
45
            ProviderFactory factory = manager.getInstallerFactory();
46
            providerManager.addProviderFactory(factory);
47
            
48
            installerManager.setDefaultLocalAddonRepository(
49
                    localAddonRepositoryFolder,
50
                    factory.getName()
51
            );
52
            
53
            return true;
54
            
55
        } catch (Exception ex) {
56
            LOG.warn("Problems initializing scripts installer.",ex);
57
            return false;
58
        }
59
    }
60

  
61
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/messagewait/MessageWaitView.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2

  
3
<object classname="com.jeta.forms.store.memento.FormPackage">
4
 <at name="fileversion">
5
  <object classname="com.jeta.forms.store.memento.FormsVersion2">
6
   <at name="major">2</at>
7
   <at name="minor">0</at>
8
   <at name="sub">0</at>
9
  </object>
10
 </at>
11
 <at name="form">
12
  <object classname="com.jeta.forms.store.memento.FormMemento">
13
   <super classname="com.jeta.forms.store.memento.ComponentMemento">
14
    <at name="cellconstraints">
15
     <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
16
      <at name="column">1</at>
17
      <at name="row">1</at>
18
      <at name="colspan">1</at>
19
      <at name="rowspan">1</at>
20
      <at name="halign">default</at>
21
      <at name="valign">default</at>
22
      <at name="insets" object="insets">0,0,0,0</at>
23
     </object>
24
    </at>
25
    <at name="componentclass">com.jeta.forms.gui.form.FormComponent</at>
26
   </super>
27
   <at name="id">/home/jjdelcerro/datos/devel/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/messagewait/MessageWaitView.xml</at>
28
   <at name="rowspecs">CENTER:4DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE</at>
29
   <at name="colspecs">FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE</at>
30
   <at name="components">
31
    <object classname="java.util.LinkedList">
32
     <item >
33
      <at name="value">
34
       <object classname="com.jeta.forms.store.memento.BeanMemento">
35
        <super classname="com.jeta.forms.store.memento.ComponentMemento">
36
         <at name="cellconstraints">
37
          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
38
           <at name="column">4</at>
39
           <at name="row">2</at>
40
           <at name="colspan">1</at>
41
           <at name="rowspan">1</at>
42
           <at name="halign">left</at>
43
           <at name="valign">top</at>
44
           <at name="insets" object="insets">0,0,0,0</at>
45
          </object>
46
         </at>
47
         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
48
        </super>
49
        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
50
        <at name="beanclass">com.jeta.forms.components.label.JETALabel</at>
51
        <at name="beanproperties">
52
         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
53
          <at name="classname">com.jeta.forms.components.label.JETALabel</at>
54
          <at name="properties">
55
           <object classname="com.jeta.forms.store.support.PropertyMap">
56
            <at name="border">
57
             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
58
              <super classname="com.jeta.forms.store.properties.BorderProperty">
59
               <at name="name">border</at>
60
              </super>
61
              <at name="borders">
62
               <object classname="java.util.LinkedList">
63
                <item >
64
                 <at name="value">
65
                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
66
                   <super classname="com.jeta.forms.store.properties.BorderProperty">
67
                    <at name="name">border</at>
68
                   </super>
69
                  </object>
70
                 </at>
71
                </item>
72
               </object>
73
              </at>
74
             </object>
75
            </at>
76
            <at name="name">lblMsg</at>
77
            <at name="width">12</at>
78
            <at name="fill">
79
             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
80
              <at name="name">fill</at>
81
             </object>
82
            </at>
83
            <at name="height">12</at>
84
           </object>
85
          </at>
86
         </object>
87
        </at>
88
       </object>
89
      </at>
90
     </item>
91
     <item >
92
      <at name="value">
93
       <object classname="com.jeta.forms.store.memento.BeanMemento">
94
        <super classname="com.jeta.forms.store.memento.ComponentMemento">
95
         <at name="cellconstraints">
96
          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
97
           <at name="column">4</at>
98
           <at name="row">4</at>
99
           <at name="colspan">1</at>
100
           <at name="rowspan">1</at>
101
           <at name="halign">right</at>
102
           <at name="valign">default</at>
103
           <at name="insets" object="insets">0,0,0,0</at>
104
          </object>
105
         </at>
106
         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
107
        </super>
108
        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
109
        <at name="beanclass">javax.swing.JButton</at>
110
        <at name="beanproperties">
111
         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
112
          <at name="classname">javax.swing.JButton</at>
113
          <at name="properties">
114
           <object classname="com.jeta.forms.store.support.PropertyMap">
115
            <at name="border">
116
             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
117
              <super classname="com.jeta.forms.store.properties.BorderProperty">
118
               <at name="name">border</at>
119
              </super>
120
              <at name="borders">
121
               <object classname="java.util.LinkedList">
122
                <item >
123
                 <at name="value">
124
                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
125
                   <super classname="com.jeta.forms.store.properties.BorderProperty">
126
                    <at name="name">border</at>
127
                   </super>
128
                  </object>
129
                 </at>
130
                </item>
131
               </object>
132
              </at>
133
             </object>
134
            </at>
135
            <at name="actionCommand">_Cancel</at>
136
            <at name="name">btnCancel</at>
137
            <at name="width">76</at>
138
            <at name="text">_Cancel</at>
139
            <at name="height">22</at>
140
           </object>
141
          </at>
142
         </object>
143
        </at>
144
       </object>
145
      </at>
146
     </item>
147
     <item >
148
      <at name="value">
149
       <object classname="com.jeta.forms.store.memento.BeanMemento">
150
        <super classname="com.jeta.forms.store.memento.ComponentMemento">
151
         <at name="cellconstraints">
152
          <object classname="com.jeta.forms.store.memento.CellConstraintsMemento">
153
           <at name="column">2</at>
154
           <at name="row">2</at>
155
           <at name="colspan">1</at>
156
           <at name="rowspan">1</at>
157
           <at name="halign">center</at>
158
           <at name="valign">top</at>
159
           <at name="insets" object="insets">0,0,0,0</at>
160
          </object>
161
         </at>
162
         <at name="componentclass">com.jeta.forms.gui.form.StandardComponent</at>
163
        </super>
164
        <at name="jetabeanclass">com.jeta.forms.gui.beans.JETABean</at>
165
        <at name="beanclass">com.jeta.forms.components.label.JETALabel</at>
166
        <at name="beanproperties">
167
         <object classname="com.jeta.forms.store.memento.PropertiesMemento">
168
          <at name="classname">com.jeta.forms.components.label.JETALabel</at>
169
          <at name="properties">
170
           <object classname="com.jeta.forms.store.support.PropertyMap">
171
            <at name="border">
172
             <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
173
              <super classname="com.jeta.forms.store.properties.BorderProperty">
174
               <at name="name">border</at>
175
              </super>
176
              <at name="borders">
177
               <object classname="java.util.LinkedList">
178
                <item >
179
                 <at name="value">
180
                  <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
181
                   <super classname="com.jeta.forms.store.properties.BorderProperty">
182
                    <at name="name">border</at>
183
                   </super>
184
                  </object>
185
                 </at>
186
                </item>
187
               </object>
188
              </at>
189
             </object>
190
            </at>
191
            <at name="name">lblIcon</at>
192
            <at name="width">12</at>
193
            <at name="fill">
194
             <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
195
              <at name="name">fill</at>
196
             </object>
197
            </at>
198
            <at name="height">12</at>
199
           </object>
200
          </at>
201
         </object>
202
        </at>
203
       </object>
204
      </at>
205
     </item>
206
    </object>
207
   </at>
208
   <at name="properties">
209
    <object classname="com.jeta.forms.store.memento.PropertiesMemento">
210
     <at name="classname">com.jeta.forms.gui.form.GridView</at>
211
     <at name="properties">
212
      <object classname="com.jeta.forms.store.support.PropertyMap">
213
       <at name="border">
214
        <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
215
         <super classname="com.jeta.forms.store.properties.BorderProperty">
216
          <at name="name">border</at>
217
         </super>
218
         <at name="borders">
219
          <object classname="java.util.LinkedList"/>
220
         </at>
221
        </object>
222
       </at>
223
       <at name="name"></at>
224
       <at name="fill">
225
        <object classname="com.jeta.forms.store.properties.effects.PaintProperty">
226
         <at name="name">fill</at>
227
        </object>
228
       </at>
229
       <at name="scollBars">
230
        <object classname="com.jeta.forms.store.properties.ScrollBarsProperty">
231
         <at name="name">scollBars</at>
232
         <at name="verticalpolicy">21</at>
233
         <at name="horizontalpolicy">31</at>
234
         <at name="border">
235
          <object classname="com.jeta.forms.store.properties.CompoundBorderProperty">
236
           <super classname="com.jeta.forms.store.properties.BorderProperty">
237
            <at name="name">border</at>
238
           </super>
239
           <at name="borders">
240
            <object classname="java.util.LinkedList">
241
             <item >
242
              <at name="value">
243
               <object classname="com.jeta.forms.store.properties.DefaultBorderProperty">
244
                <super classname="com.jeta.forms.store.properties.BorderProperty">
245
                 <at name="name">border</at>
246
                </super>
247
               </object>
248
              </at>
249
             </item>
250
            </object>
251
           </at>
252
          </object>
253
         </at>
254
        </object>
255
       </at>
256
      </object>
257
     </at>
258
    </object>
259
   </at>
260
   <at name="cellpainters">
261
    <object classname="com.jeta.forms.store.support.Matrix">
262
     <at name="rows">
263
      <object classname="[Ljava.lang.Object;" size="5">
264
       <at name="item" index="0">
265
        <object classname="[Ljava.lang.Object;" size="5"/>
266
       </at>
267
       <at name="item" index="1">
268
        <object classname="[Ljava.lang.Object;" size="5"/>
269
       </at>
270
       <at name="item" index="2">
271
        <object classname="[Ljava.lang.Object;" size="5"/>
272
       </at>
273
       <at name="item" index="3">
274
        <object classname="[Ljava.lang.Object;" size="5"/>
275
       </at>
276
       <at name="item" index="4">
277
        <object classname="[Ljava.lang.Object;" size="5"/>
278
       </at>
279
      </object>
280
     </at>
281
    </object>
282
   </at>
283
   <at name="rowgroups">
284
    <object classname="com.jeta.forms.store.memento.FormGroupSet">
285
     <at name="groups">
286
      <object classname="java.util.HashMap"/>
287
     </at>
288
    </object>
289
   </at>
290
   <at name="colgroups">
291
    <object classname="com.jeta.forms.store.memento.FormGroupSet">
292
     <at name="groups">
293
      <object classname="java.util.HashMap"/>
294
     </at>
295
    </object>
296
   </at>
297
  </object>
298
 </at>
299
</object>
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/messagewait/MessageWaitView.java
1
package org.gvsig.scripting.app.extension.messagewait;
2

  
3
import com.jeta.open.i18n.I18NUtils;
4
import com.jgoodies.forms.layout.CellConstraints;
5
import com.jgoodies.forms.layout.FormLayout;
6
import java.awt.BorderLayout;
7
import java.awt.ComponentOrientation;
8
import java.awt.Container;
9
import java.awt.Dimension;
10
import javax.swing.Box;
11
import javax.swing.ImageIcon;
12
import javax.swing.JButton;
13
import javax.swing.JFrame;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16

  
17

  
18
public class MessageWaitView extends JPanel
19
{
20
   JLabel lblMsg = new JLabel();
21
   JButton btnCancel = new JButton();
22
   JLabel lblIcon = new JLabel();
23

  
24
   /**
25
    * Default constructor
26
    */
27
   public MessageWaitView()
28
   {
29
      initializePanel();
30
   }
31

  
32
   /**
33
    * Adds fill components to empty cells in the first row and first column of the grid.
34
    * This ensures that the grid spacing will be the same as shown in the designer.
35
    * @param cols an array of column indices in the first row where fill components should be added.
36
    * @param rows an array of row indices in the first column where fill components should be added.
37
    */
38
   void addFillComponents( Container panel, int[] cols, int[] rows )
39
   {
40
      Dimension filler = new Dimension(10,10);
41

  
42
      boolean filled_cell_11 = false;
43
      CellConstraints cc = new CellConstraints();
44
      if ( cols.length > 0 && rows.length > 0 )
45
      {
46
         if ( cols[0] == 1 && rows[0] == 1 )
47
         {
48
            /** add a rigid area  */
49
            panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
50
            filled_cell_11 = true;
51
         }
52
      }
53

  
54
      for( int index = 0; index < cols.length; index++ )
55
      {
56
         if ( cols[index] == 1 && filled_cell_11 )
57
         {
58
            continue;
59
         }
60
         panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
61
      }
62

  
63
      for( int index = 0; index < rows.length; index++ )
64
      {
65
         if ( rows[index] == 1 && filled_cell_11 )
66
         {
67
            continue;
68
         }
69
         panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
70
      }
71

  
72
   }
73

  
74
   /**
75
    * Helper method to load an image file from the CLASSPATH
76
    * @param imageName the package and name of the file to load relative to the CLASSPATH
77
    * @return an ImageIcon instance with the specified image file
78
    * @throws IllegalArgumentException if the image resource cannot be loaded.
79
    */
80
   public ImageIcon loadImage( String imageName )
81
   {
82
      try
83
      {
84
         ClassLoader classloader = getClass().getClassLoader();
85
         java.net.URL url = classloader.getResource( imageName );
86
         if ( url != null )
87
         {
88
            ImageIcon icon = new ImageIcon( url );
89
            return icon;
90
         }
91
      }
92
      catch( Exception e )
93
      {
94
         e.printStackTrace();
95
      }
96
      throw new IllegalArgumentException( "Unable to load image: " + imageName );
97
   }
98

  
99
   /**
100
    * Method for recalculating the component orientation for 
101
    * right-to-left Locales.
102
    * @param orientation the component orientation to be applied
103
    */
104
   public void applyComponentOrientation( ComponentOrientation orientation )
105
   {
106
      // Not yet implemented...
107
      // I18NUtils.applyComponentOrientation(this, orientation);
108
      super.applyComponentOrientation(orientation);
109
   }
110

  
111
   public JPanel createPanel()
112
   {
113
      JPanel jpanel1 = new JPanel();
114
      FormLayout formlayout1 = new FormLayout("FILL:4DLU:NONE,FILL:DEFAULT:NONE,FILL:4DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:4DLU:NONE","CENTER:4DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:4DLU:NONE,CENTER:DEFAULT:NONE,CENTER:4DLU:NONE");
115
      CellConstraints cc = new CellConstraints();
116
      jpanel1.setLayout(formlayout1);
117

  
118
      lblMsg.setName("lblMsg");
119
      jpanel1.add(lblMsg,new CellConstraints(4,2,1,1,CellConstraints.LEFT,CellConstraints.TOP));
120

  
121
      btnCancel.setActionCommand("_Cancel");
122
      btnCancel.setName("btnCancel");
123
      btnCancel.setText("_Cancel");
124
      jpanel1.add(btnCancel,new CellConstraints(4,4,1,1,CellConstraints.RIGHT,CellConstraints.DEFAULT));
125

  
126
      lblIcon.setName("lblIcon");
127
      jpanel1.add(lblIcon,new CellConstraints(2,2,1,1,CellConstraints.CENTER,CellConstraints.TOP));
128

  
129
      addFillComponents(jpanel1,new int[]{ 1,2,3,4,5 },new int[]{ 1,2,3,4,5 });
130
      return jpanel1;
131
   }
132

  
133
   /**
134
    * Initializer
135
    */
136
   protected void initializePanel()
137
   {
138
      setLayout(new BorderLayout());
139
      add(createPanel(), BorderLayout.CENTER);
140
   }
141

  
142

  
143
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/messagewait/MessageWait.java
1
package org.gvsig.scripting.app.extension.messagewait;
2

  
3
import java.awt.Dimension;
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
import java.net.URL;
7
import javax.swing.ImageIcon;
8
import javax.swing.SwingUtilities;
9
import org.gvsig.tools.ToolsLocator;
10
import org.gvsig.tools.i18n.I18nManager;
11
import org.gvsig.tools.swing.api.ToolsSwingLocator;
12
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
13

  
14

  
15
public class MessageWait extends MessageWaitView {
16
    
17
    private static final long serialVersionUID = 6668980523307140920L;
18
    private WaitingCondition condition;
19
    private int seconds = 3;
20
    private boolean cancelled = false;
21
    private Runnable action;
22
    
23
    public interface WaitingCondition {
24
        
25
        public boolean stopWaiting();
26
    }
27
    
28
    public MessageWait() {
29
        this.btnCancel.addActionListener(new ActionListener() {
30
            @Override
31
            public void actionPerformed(ActionEvent e) {
32
                cancelled = true;
33
                setVisible(false);
34
            }
35
        });
36
        URL url = this.getClass().getResource("/images/spinner.gif");
37
        ImageIcon icon = new ImageIcon(url);
38
        this.lblIcon.setIcon(icon);
39
        I18nManager i18n = ToolsLocator.getI18nManager();
40
        this.btnCancel.setText(i18n.getTranslation("Cancel"));
41
    }
42
    
43
    public void showMessage(String title, String msg, WaitingCondition condition, Runnable action) {
44
        this.showMessage(title, msg, condition, action, 300, -1, 3);
45
    }
46

  
47
    public void showMessage(String title, String msg, WaitingCondition condition, Runnable action, int width, int height, int seconds) {
48
        if( condition.stopWaiting() ) {
49
            SwingUtilities.invokeLater(action);
50
            return;
51
        }
52
        this.setVisible(true);
53
        this.condition = condition;
54
        this.seconds = seconds;
55
        this.action = action;
56
        this.cancelled = false;
57
        this.lblMsg.setText("<html>"+msg.replace("\n", "<br>\n")+"</html>");
58
        Dimension d = this.getPreferredSize();
59
        if( height<d.height ) {
60
            height = d.height;
61
        }
62
        if( width<d.width ) {
63
            width = d.width;
64
        }
65
        this.setPreferredSize(new Dimension(width, height));
66
        WindowManager winmgr = ToolsSwingLocator.getWindowManager();
67
        winmgr.showWindow(this, title, WindowManager.MODE.TOOL);
68
        Thread th = new Thread(new Runnable() {
69
            @Override
70
            public void run() {
71
                doWait();
72
            }
73
        }, "MessageWait");
74
        th.start();
75
    }
76
    
77
    private void doWait() {
78
        while( true ) {
79
            if( this.condition.stopWaiting() ) {
80
                break;
81
            }
82
            try {
83
                Thread.sleep(this.seconds*1000);
84
            } catch (InterruptedException ex) {
85

  
86
            }
87
        }
88
        if( this.cancelled ) {
89
            return;
90
        }
91
        SwingUtilities.invokeLater(new Runnable() {
92
            @Override
93
            public void run() {
94
                setVisible(false);
95
                action.run();
96
            }
97
        });
98
    }
99
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptLaunchExtension.java
1
package org.gvsig.scripting.app.extension;
2

  
3
import java.io.File;
4
import java.util.ArrayList;
5
import java.util.Arrays;
6
import java.util.List;
7
import javax.swing.JOptionPane;
8
import org.gvsig.andami.PluginsLocator;
9
import org.gvsig.andami.PluginsManager;
10
import org.gvsig.andami.plugins.Extension;
11
import org.gvsig.app.ApplicationLocator;
12
import org.gvsig.app.ApplicationManager;
13
import org.gvsig.scripting.ScriptingLocator;
14
import org.gvsig.scripting.ScriptingManager;
15
import org.gvsig.scripting.ScriptingScript;
16
import org.slf4j.Logger;
17
import org.slf4j.LoggerFactory;
18

  
19
public class ScriptLaunchExtension extends Extension {
20

  
21
    private static final Logger logger = LoggerFactory.getLogger(ScriptLaunchExtension.class);
22

  
23
    @Override
24
    public void initialize() {
25
    }
26

  
27
    @Override
28
    public boolean isEnabled() {
29
        return true;
30
    }
31

  
32
    @Override
33
    public boolean isVisible() {
34
        return true;
35
    }
36

  
37
    @Override
38
    public boolean canQueryByAction() {
39
        return true;
40
    }
41

  
42
    @Override
43
    public void execute(String action) {
44
        ApplicationManager application = ApplicationLocator.getManager();
45
        ScriptingScript script = getScript(action);
46
        if( script == null ) {
47
            application.messageDialog(
48
                    "Can't locate script '"+action+"'", 
49
                    "Warning", 
50
                    JOptionPane.WARNING_MESSAGE
51
            );
52
            return;
53
        }
54
        try {
55
            script.runAsTask(null);
56
        } catch (Throwable th) {
57
            logger.warn("Can't execute '" + action + "' script.", th);
58
        }
59
    }
60

  
61
    @Override
62
    public void execute(String action, Object[] args) {
63
        ApplicationManager application = ApplicationLocator.getManager();
64
        ScriptingScript script = getScript(action);
65
        if( script == null ) {
66
            application.messageDialog(
67
                    "Can't locate script '"+action+"'", 
68
                    "Warning", 
69
                    JOptionPane.WARNING_MESSAGE
70
            );
71
            return;
72
        }
73
        try {
74
            script.runAsTask(args);
75
        } catch (Throwable th) {
76
            logger.warn("Can't execute '" + action + "' script.", th);
77
        }
78
    }
79

  
80
    @Override
81
    public boolean isVisible(String action) {
82
        ScriptingScript script = getScript(action);
83
        try {
84
            Boolean value = (Boolean) script.invokeFunction("isVisible", null);
85
            return value;
86
        } catch (Throwable th) {
87
            logger.warn("Can't execute isVisible in '" + action + "' script.", th);
88
        }
89
        return false;
90
    }
91

  
92
    @Override
93
    public boolean isEnabled(String action) {
94
        ScriptingScript script = getScript(action);
95
        try {
96
            Boolean value = (Boolean) script.invokeFunction("isEnabled", null);
97
            return value;
98
        } catch (Throwable th) {
99
            logger.warn("Can't execute isEnabled in '" + action + "' script.", th);
100
        }
101
        return false;
102
    }
103

  
104
    private ScriptingScript getScript(String scriptpathname) {
105
        final ScriptingManager manager = ScriptingLocator.getManager();
106
        final PluginsManager pluginManager = PluginsLocator.getManager();
107

  
108
        File scriptfile;
109
        ScriptingScript script;
110
        
111
        String s = manager.getRootUserFolder().getAbsolutePath().replace("\\", "/");
112
        scriptfile = new File(s+"/"+scriptpathname);
113
        if (scriptfile.exists()) {
114
            script = (ScriptingScript) manager.getScript(scriptfile);
115
            return script;
116
        }
117
                
118
        final List<File> pluginsFolders = new ArrayList<>();
119
        for (File f : pluginManager.getPluginsFolders()) {
120
            pluginsFolders.addAll(Arrays.asList(f.listFiles()));
121
        }
122

  
123
        for (File pluginFolder : pluginsFolders) {
124
            s = pluginFolder.getAbsolutePath().replace("\\", "/");
125
            scriptfile = new File(s+"/scripting/scripts/"+scriptpathname);
126
            if (scriptfile.exists()) {
127
                script = (ScriptingScript) manager.getScript(scriptfile);
128
                return script;
129
            }
130
        }
131
        return (ScriptingScript) manager.getScript(scriptpathname);
132
    }
133

  
134
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.65/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptingExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * 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
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.scripting.app.extension;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.nio.file.FileVisitOption;
28
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
29
import java.nio.file.FileVisitResult;
30
import java.nio.file.Files;
31
import java.nio.file.Path;
32
import java.nio.file.Paths;
33
import java.nio.file.SimpleFileVisitor;
34
import java.nio.file.attribute.BasicFileAttributes;
35
import java.text.MessageFormat;
36
import java.util.ArrayList;
37
import java.util.Arrays;
38
import java.util.Collections;
39
import java.util.Comparator;
40
import java.util.EnumSet;
41
import java.util.List;
42
import java.util.function.Predicate;
43

  
44
import javax.swing.JOptionPane;
45
import org.apache.commons.io.FileUtils;
46
import org.apache.commons.io.FilenameUtils;
47
import org.apache.commons.io.IOCase;
48
import org.apache.commons.io.IOUtils;
49
import org.apache.commons.lang3.BooleanUtils;
50
import org.apache.commons.lang3.StringUtils;
51

  
52
import org.gvsig.andami.IconThemeHelper;
53
import org.gvsig.andami.PluginServices;
54
import org.gvsig.andami.PluginsLocator;
55
import org.gvsig.andami.PluginsManager;
56
import org.gvsig.andami.plugins.Extension;
57
import org.gvsig.app.ApplicationLocator;
58
import org.gvsig.app.ApplicationManager;
59
import org.gvsig.scripting.ScriptingBaseScript;
60
import org.gvsig.scripting.ScriptingFolder;
61
import org.gvsig.scripting.ScriptingLocator;
62
import org.gvsig.scripting.ScriptingManager;
63
import org.gvsig.scripting.ScriptingScript;
64
import org.gvsig.scripting.ScriptingUnit;
65
import org.gvsig.scripting.app.extension.messagewait.MessageWait;
66
import org.gvsig.scripting.swing.api.JScriptingComposer;
67
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
68
import org.gvsig.scripting.swing.api.ScriptingUIManager;
69
import static org.gvsig.scripting.swing.api.ScriptingUIManager.SCRIPT_COMPOSER_AUTORUN;
70
import org.gvsig.tools.dynobject.DynObject;
71
import org.gvsig.tools.swing.api.ToolsSwingLocator;
72
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
73
import org.gvsig.tools.swing.impl.windowmanager.DefaultWindowManager;
74
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
76
import org.gvsig.tools.ToolsLocator;
77
import org.gvsig.tools.exception.BaseException;
78
import org.gvsig.tools.i18n.I18nManager;
79
import org.gvsig.tools.script.Script;
80
import org.gvsig.tools.task.SimpleTaskStatus;
81
import org.gvsig.tools.util.Invocable;
82
import org.gvsig.tools.visitor.VisitCanceledException;
83
import org.gvsig.tools.visitor.Visitor;
84

  
85
public class ScriptingExtension extends Extension {
86

  
87
    @SuppressWarnings("FieldNameHidesFieldInSuperclass")
88
    private static final Logger logger = LoggerFactory.getLogger(ScriptingExtension.class);
89

  
90
    private PluginServices plugin = null;
91

  
92
    private static final String SKIP_AUTORUNS = "skipAutoruns";
93
    
94
    /*
95
     * la funcion log y las constantes estan pensadas para usarlas desde los scripts.
96
     */
97
    public static final int INFO = 0;
98
    public static final int TRACE = 1;
99
    public static final int WARN = 2;
100
    public static final int ERROR = 3;
101
    private static boolean composer_initialized = false;
102
    private boolean executingAutorunScripts = true;
103
    private MessageWait message;
104

  
105
    public static void log(String message) {
106
        log(INFO, message, null);
107
    }
108

  
109
    public static void log(int level, String message) {
110
        log(level, message, null);
111
    }
112

  
113
    public static void log(int level, String message, Throwable th) {
114
        switch( level ) {
115
        case TRACE:
116
            logger.trace(message, th);
117
            break;
118
        case ERROR:
119
            logger.error(message, th);
120
            break;
121
        case WARN:
122
            logger.warn(message, th);
123
            break;
124
        default:
125
        case INFO:
126
            logger.info(message, th);
127
            break;
128
        }
129
    }
130

  
131
    @Override
132
    public PluginServices getPlugin() {
133
        if( this.plugin == null ) {
134
            this.plugin = PluginsLocator.getManager().getPlugin(ScriptingExtension.class);
135
        }
136
        return this.plugin;
137
    }
138

  
139
    @Override
140
    public void execute(String actionCommand) {
141
        this.execute(actionCommand, null);
142
    }
143

  
144
    @Override
145
    public void execute(String command, Object[] args) {
146
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
147
        WindowManager winmanager = ToolsSwingLocator.getWindowManager();
148

  
149
        if( "tools-scripting-launcher".equalsIgnoreCase(command) ) {
150
            winmanager.showWindow(uimanager.createLauncher().asJComponent(), uimanager.getTranslation("Scripting_Launcher"), WindowManager.MODE.TOOL);
151

  
152
        } else if( "tools-scripting-composer".equalsIgnoreCase(command) ) {
153
            I18nManager i18n = ToolsLocator.getI18nManager();
154
            message.showMessage(
155
                i18n.getTranslation("_notice"),
156
                i18n.getTranslation("_Initializing_the_scripting_plugin_Xhorizontal_ellipsisX") + "\n" + 
157
                    i18n.getTranslation("_Waiting_to_terminate"), 
158
                new MessageWait.WaitingCondition() {
159
                    private Thread th = null;
160
                    
161
                    @Override
162
                    public boolean stopWaiting() {
163
                        if( executingAutorunScripts ) {
164
                            return false;
165
                        }
166
                        if( composer_initialized ) {
167
                            return true;
168
                        }
169
                        if( th == null ) {
170
                            th = new Thread(new ExecuteScriptsFromScriptingFolders("scautorun",SCRIPT_COMPOSER_AUTORUN), "StartupScriptingComposer");
171
                            th.start();
172
                        }
173
                        return false;
174
                    }
175
                },
176
                new Runnable() {
177
                    @Override
178
                    public void run() {
179
                            showScriptingComposer();
180
                    }
181
                }
182
            );
183

  
184

  
185
        } else {
186
            ScriptingBaseScript script = uimanager.getManager().getScript(command);
187
            if( script != null ) {
188
                script.run(args);
189
            } else {
190
                ApplicationManager application = ApplicationLocator.getManager();
191
                application.messageDialog(
192
                        "Can't locate script '" + command + "'.", 
193
                        "ScriptLaunch", 
194
                        JOptionPane.OK_OPTION
195
                );
196
            }
197
        }
198
    }
199

  
200
    private void showScriptingComposer() {
201
        ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
202
 
203
        DynObject preferences = getPlugin().getPluginProperties();
204
        Boolean composerUseHisWindowManager = (Boolean) preferences.getDynValue("ComposerUseHisWindowManager");
205
        ScriptingUIManager uiManager = ScriptingSwingLocator.getUIManager();
206
        if( composerUseHisWindowManager ) {
207
            DefaultWindowManager winmanager = new DefaultWindowManager();
208
            uiManager.setWindowManager(winmanager);
209
        }
210
        JScriptingComposer composer = uimanager.createComposer();
211
        uiManager.showWindow(
212
            composer.asJComponent(),
213
            uimanager.getTranslation("Scripting_Composer")
214
        );
215
    }
216

  
217
    private class ExecuteScriptsFromScriptingFolders extends AbstractExecuteScripts {
218

  
219
        public ExecuteScriptsFromScriptingFolders(String title, String patternName) {
220
            super(title, patternName);
221
        }
222
        
223
        @Override
224
        public void run() {            
225
            SimpleTaskStatus status = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Scripts startup");
226
            status.setIndeterminate();
227
            status.setAutoremove(true);
228
            status.add();
229
            final ApplicationManager application = ApplicationLocator.getManager();
230
            final I18nManager i18nManager = ToolsLocator.getI18nManager();            
231
            try {
232
                logger.info("Searching "+title+" scripts...");
233
                application.message(
234
                    i18nManager.getTranslation("_Searching_autorun_scripts_Xhorizontal_ellipsisX"),
235
                    JOptionPane.INFORMATION_MESSAGE
236
                );
237
                ScriptingManager manager = ScriptingLocator.getManager();
238
                final List<ScriptingScript> scripts = new ArrayList<>();
239
                
240
                Visitor visitor = new Visitor() {
241
                    @Override
242
                    public void visit(Object o) throws VisitCanceledException, BaseException {
243
                        ScriptingUnit unit = (ScriptingUnit) o;
244
                        if( unit instanceof ScriptingScript && 
245
                            FilenameUtils.wildcardMatch(unit.getName(), patternName, IOCase.INSENSITIVE) ) {
246
                            ScriptingScript script = (ScriptingScript) unit;
247
                            if( script.isEnabled() ) {
248
                                scripts.add(script);
249
                            } else {
250
                                logger.info("Skip "+title+" script '" + script.getFile().getAbsolutePath() + "'.");
251
                            }
252
                        }
253
                    }
254
                };
255
                Predicate<ScriptingUnit> includeFilter = new Predicate<ScriptingUnit>() {
256
                    @Override
257
                    public boolean test(ScriptingUnit unit) {
258
                        if( unit instanceof ScriptingFolder ) {
259
                            return !BooleanUtils.toBoolean(unit.getProperty(SKIP_AUTORUNS));
260
                        }
261
                        return false;
262
                    }
263
                };
264
                manager.getSystemFolder().accept(visitor, includeFilter);
265
                manager.getUserFolder().accept(visitor, includeFilter);
266
                sortScripts(scripts);
267
                executeScripts(scripts, status);
268
            } catch(Throwable th) {
269
                
270
            } finally {
271
                logger.info("Running "+title+" scripts terminated.");
272
                application.message("", JOptionPane.INFORMATION_MESSAGE);
273
                status.terminate();
274
                composer_initialized = true;
275
            }
276
        }
277
    }
278
    
279
    @Override
280
    public void initialize() {
281
        IconThemeHelper.registerIcon("action", "tools-scripting-launcher", this);
282
        IconThemeHelper.registerIcon("action", "tools-scripting-composer", this);
283
        IconThemeHelper.registerIcon("action", "tools-scripting-console-jython", this);
284
        this.message = new MessageWait();
285

  
286
        initPaths();
287
        Thread th = new Thread(new Runnable() {
288
            @Override
289
            public void run() {
290
                preloadPythonEngine();
291
            }
292
        }, "ScriptEnginesInitializer");
293
        th.start();
294
        try {
295
            th.join(3000); // force change to other thread
296
        } catch (InterruptedException ex) {
297
            // Ignore.
298
        }
299
    }
300

  
301
    private void preloadPythonEngine() {
302
        ScriptingManager manager = (ScriptingManager) ScriptingLocator.getManager();
303
        synchronized (manager) {
304
            String respath = "/scripting/langs/python/preload.py";
305
            InputStream res = this.getClass().getResourceAsStream(respath);
306
            if( res != null ) {
307
                logger.info("Scan for script engines");
308
                List<String> lines;
309
                try {
310
                    lines = IOUtils.readLines(res);
311
                    String code = StringUtils.join(lines, "\n");
312
                    logger.info("Preload python script engine");
313
                    Script script = manager.createScript(
314
                        "preload",
315
                        code,
316
                        ScriptingManager.PYTHON_LANGUAGE_NAME
317
                    );
318
                    logger.info("Preload python modules");
319
                    script.invokeFunction("main", null);
320

  
321
                } catch (Exception ex) {
322
                    logger.warn("Can't run preload script for python.", ex);
323
                }
324
                logger.info("Preload of script engines finished");
325
            }
326
        }
327
    }
328

  
329
    private File getScriptsHomeFolder() {
330
        PluginsManager pluginManager = PluginsLocator.getManager();
331
        File pluginHomeFolder = this.getPlugin().getPluginHomeFolder();
332

  
333
        File scriptsHomeFolder;
334
        File f = FileUtils.getFile(pluginHomeFolder, "scripts-folder.txt");
335
        if( f.exists() ) {
336
            try {
337
                List<String> lines = FileUtils.readLines(f);
338
                for( String line : lines ) {
339
                    line = line.trim();
340
                    if( !line.startsWith("#") ) {
341
                        scriptsHomeFolder = new File(line);
342
                        if( !scriptsHomeFolder.isAbsolute() ) {
343
                            scriptsHomeFolder = new File(pluginHomeFolder, line);
344
                        }
345
                        scriptsHomeFolder = new File(
346
                            FilenameUtils.normalizeNoEndSeparator(
347
                                scriptsHomeFolder.getAbsolutePath(),
348
                                true
349
                            )
350
                        );
351
                        if( scriptsHomeFolder.exists() ) {
352
                            return scriptsHomeFolder;
353
                        }
354
                    }
355
                }
356
            } catch (IOException ex) {
357
            }
358
        } else {
359
            try {
360
                FileUtils.touch(f);
361
            } catch (IOException ex) {
362
            }
363
        }
364
        String gvsigversion = pluginManager.getApplicationVersion().format("%M.%m.%r") ;
365
        scriptsHomeFolder = FileUtils.getFile(pluginHomeFolder, gvsigversion) ;
366
        return scriptsHomeFolder;
367
    }
368
    
369
    private void initPaths() {
370
        PluginsManager pluginManager = PluginsLocator.getManager();
371

  
372
        ScriptingManager manager = ScriptingLocator.getManager();
373
        manager.setHomeFolder(getScriptsHomeFolder());
374

  
375
        ScriptingFolder folder = manager.createLink(
376
            "Common",
377
            manager.getUserFolder(), 
378
            "../../scripts"
379
        );
380
        folder.setProperty(SKIP_AUTORUNS, BooleanUtils.toStringTrueFalse(true));
381
        folder.save();
382
//        manager.createLink(
383
//            "Previous version",
384
//            manager.getUserFolder(), 
385
//            "../../../org.gvsig.scripting.app.extension/scripts"
386
//        );
387

  
388
        List<File> pluginsFolders = new ArrayList<>();
389
        for( File f : pluginManager.getPluginsFolders() ) {
390
            pluginsFolders.addAll(Arrays.asList(f.listFiles()));
391
        }
392

  
393
        for( File pluginFolder : pluginsFolders ) {
394
            File scriptsFolder = new File(pluginFolder, "scripting/scripts");
395
            if( scriptsFolder.exists() ) {
396
                manager.registerSystemFolder(pluginFolder.getName(), scriptsFolder);
397
            }
398
            File libFolder = new File(pluginFolder, "scripting/lib");
399
            if( libFolder.exists() ) {
400
                manager.addLibFolder(libFolder);
401
            }
402
        }
403
        manager.setPackagesFolder(pluginManager.getInstallFolder());
404

  
405
        File localAddonRepositoryFolder = new File(manager.getRootUserFolder(), "addons");
406
        if( !localAddonRepositoryFolder.exists() ) {
407
            try {
408
                FileUtils.forceMkdir(localAddonRepositoryFolder);
409
            } catch (IOException ex) {
410
                logger.info("Can't create addons folder in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
411
            }
412
        }
413
        File initAddonFile = new File(localAddonRepositoryFolder, "__init__.py");
414
        if( !initAddonFile.exists() ) {
415
            try {
416
                FileUtils.touch(initAddonFile);
417
            } catch (IOException ex) {
418
                logger.info("Can't create addons __init__ file in '" + localAddonRepositoryFolder.getAbsolutePath() + "'.", ex);
419
            }
420
        }
421
    }
422

  
423
    @Override
424
    public void postInitialize() {
425
        super.postInitialize();
426
        PluginsManager pluginManager = PluginsLocator.getManager();
427
        pluginManager.addStartupTask(
428
            "ExecuteAutorunScripts",
429
            new ExecuteAutorunScriptsOnStartup(),
430
            true,
431
            600
432
        );
433

  
434
        Invocable initializer = new ScriptsInstallerInitializer();
435
        initializer.call(this.getPlugin().getPluginName());
436
    }
437

  
438
    @Override
439
    public boolean isEnabled() {
440
        return true;
441
    }
442

  
443
    @Override
444
    public boolean isVisible() {
445
        return true;
446
    }
447

  
448
    private class ExecuteAutorunScriptsOnStartup implements Runnable {
449

  
450
        @Override
451
        public void run() {
452
            Thread th = new Thread(new ExecuteScriptsFromFilesystem("autotun","autorun.inf"));
453
            th.start();
454
        }
455
    }
456

  
457
    private abstract class AbstractExecuteScripts implements Runnable {
458
        protected String patternName;
459
        protected String title;
460

  
461
        public AbstractExecuteScripts(String title, String patternName) {
462
            this.patternName = patternName;
463
            this.title = title;
464
        }
465

  
466
        private String getScriptOrderKey(ScriptingBaseScript o) {
467
            int groupOrder = 500;
468
            String groupName = "default";
469
            int scriptOrder = 500;
470
            String s = o.getProperty("autorun.group.order");
471
            if( s != null ) {
472
                try {
473
                    groupOrder = Integer.parseInt(s);
474
                } catch (Exception ex) {
475
                    // Do nothing.
476
                }
477
            }
478
            s = o.getProperty("autorun.group.name");
479
            if( s != null ) {
480
                groupName = s;
481
            }
482
            s = o.getProperty("autorun.order");
483
            if( s != null ) {
484
                try {
485
                    scriptOrder = Integer.parseInt(s);
486
                } catch (Exception ex) {
487
                    // Do nothing.
488
                }
489
            }
490
            String key = MessageFormat.format(
491
                "{0,number,000000}.{1}.{2,number,000000}",
492
                groupOrder,
493
                groupName,
494
                scriptOrder
495
            );
496
            return key;
497
        }
498

  
499
        protected void sortScripts(List<ScriptingScript> scripts) {
500
            Collections.sort(scripts, new Comparator<ScriptingBaseScript>() {
501

  
502
                @Override
503
                public int compare(ScriptingBaseScript o1, ScriptingBaseScript o2) {
504
                    return getScriptOrderKey(o2).compareToIgnoreCase(getScriptOrderKey(o1));
505
                }
506
            });
507
        }
508
        
509
        protected void executeScripts(List<ScriptingScript> scripts, SimpleTaskStatus status) {
510
            final I18nManager i18nManager = ToolsLocator.getI18nManager();
511
            final ApplicationManager application = ApplicationLocator.getManager();
512
            if( scripts!=null && !scripts.isEmpty() ) {
513
                if( status!=null ) {
514
                    status.setRangeOfValues(0, scripts.size());
515
                }
516
                int n=0;
517
                for (ScriptingBaseScript script : scripts) {
518
                    if( status!=null ) {
519
                        status.setCurValue(n++);
520
                    }
521
                    try {
522
                        logger.info("running "+title+" script '" + script.getFile().getAbsolutePath() + "' (" + getScriptOrderKey(script) + ", " + script.getIsolationGroup() + ").");
523
                        application.message(
524
                            i18nManager.getTranslation(
525
                                "_Running_autorun_script_from_XnameX",
526
                                new String[]{
527
                                        script.getFile().getParentFile().getName()}
528
                            ),
529
                            JOptionPane.INFORMATION_MESSAGE
530
                        );
531
                    } catch (Exception ex) {
532
                        // Ignore it
533
                    }
534
                    try {
535
                        script.run();
536
                    } catch (Exception ex) {
537
                        logger.warn("Can't execute "+title+" from '" + script.getFile().getAbsolutePath() + "'.", ex);
538
                    }
539
                }
540
            }
541

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff