Revision 1071

View differences:

org.gvsig.scripting/tags/org.gvsig.scripting-2.3.67/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.67/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/InstallCert.java
1
package org.gvsig.scripting.app;
2

  
3
/*
4
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without
7
 * modification, are permitted provided that the following conditions
8
 * are met:
9
 *
10
 *   - Redistributions of source code must retain the above copyright
11
 *     notice, this list of conditions and the following disclaimer.
12
 *
13
 *   - Redistributions in binary form must reproduce the above copyright
14
 *     notice, this list of conditions and the following disclaimer in the
15
 *     documentation and/or other materials provided with the distribution.
16
 *
17
 *   - Neither the name of Sun Microsystems nor the names of its
18
 *     contributors may be used to endorse or promote products derived
19
 *     from this software without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22
 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
 */
33
/**
34
 * Originally from:
35
 * http://blogs.sun.com/andreas/resource/InstallCert.java
36
 * Use:
37
 * java InstallCert hostname
38
 * Example:
39
 *% java InstallCert ecc.fedora.redhat.com
40
 */
41

  
42
import java.io.BufferedReader;
43
import java.io.File;
44
import java.io.FileInputStream;
45
import java.io.FileOutputStream;
46
import java.io.InputStream;
47
import java.io.InputStreamReader;
48
import java.io.OutputStream;
49
import java.security.KeyStore;
50
import java.security.MessageDigest;
51
import java.security.cert.CertificateException;
52
import java.security.cert.X509Certificate;
53

  
54
import javax.net.ssl.SSLContext;
55
import javax.net.ssl.SSLException;
56
import javax.net.ssl.SSLSocket;
57
import javax.net.ssl.SSLSocketFactory;
58
import javax.net.ssl.TrustManager;
59
import javax.net.ssl.TrustManagerFactory;
60
import javax.net.ssl.X509TrustManager;
61

  
62
/**
63
 * Class used to add the server's certificate to the KeyStore
64
 * with your trusted certificates.
65
 * 
66
 * NOTE: modified to install the certificate always into the main cacerts
67
 * keystore.
68
 */
69
public class InstallCert {
70

  
71
    public static void install(String host, Integer port, String passphrase) throws Exception {
72
        if( passphrase==null ) {
73
            passphrase = "changeit";
74
        }
75
        if( port == null || port <1) {
76
            port = 443;
77
        }
78
        main(
79
            new String[] {
80
                host +":"+port,
81
                passphrase
82
            }
83
        );
84
    }
85
    
86
    public static void main(String[] args) throws Exception {
87
        String host;
88
        int port;
89
        char[] passphrase;
90
        if ((args.length == 1) || (args.length == 2)) {
91
            String[] c = args[0].split(":");
92
            host = c[0];
93
            port = (c.length == 1) ? 443 : Integer.parseInt(c[1]);
94
            String p = (args.length == 1) ? "changeit" : args[1];
95
            passphrase = p.toCharArray();
96
        } else {
97
            System.out.println("Usage: java InstallCert [:port] [passphrase]");
98
            return;
99
        }
100

  
101
        File file = null;
102
        // File file = new File("jssecacerts");
103
        // if (file.isFile() == false) {
104
        char SEP = File.separatorChar;
105
        File dir =
106
            new File(System.getProperty("java.home") + SEP + "lib" + SEP
107
                + "security");
108
        // file = new File(dir, "jssecacerts");
109
        // if (file.isFile() == false) {
110
                file = new File(dir, "cacerts");
111

  
112
        if (!file.canWrite()) {
113
            System.err
114
                .println("Unable to write in the file "
115
                    + file
116
                + ".\nRun InstallCert as an administrator or a user with "
117
                + "privileges to write in the cacerts file");
118

  
119
            System.exit(-1);
120
        }
121
        // }
122
        // }
123
        System.out.println("Loading KeyStore " + file + "...");
124
        InputStream in = new FileInputStream(file);
125
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
126
        ks.load(in, passphrase);
127
        in.close();
128

  
129
        SSLContext context = SSLContext.getInstance("TLS");
130
        TrustManagerFactory tmf =
131
            TrustManagerFactory.getInstance(TrustManagerFactory
132
                .getDefaultAlgorithm());
133
        tmf.init(ks);
134
        X509TrustManager defaultTrustManager =
135
            (X509TrustManager) tmf.getTrustManagers()[0];
136
        SavingTrustManager tm = new SavingTrustManager(defaultTrustManager);
137
        context.init(null, new TrustManager[] { tm }, null);
138
        SSLSocketFactory factory = context.getSocketFactory();
139

  
140
        System.out
141
            .println("Opening connection to " + host + ":" + port + "...");
142
        SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
143
        socket.setSoTimeout(10000);
144
        try {
145
            System.out.println("Starting SSL handshake...");
146
            socket.startHandshake();
147
            socket.close();
148
            System.out.println();
149
            System.out.println("No errors, certificate is already trusted");
150
        } catch (SSLException e) {
151
            System.out.println();
152
            e.printStackTrace(System.out);
153
        }
154

  
155
        X509Certificate[] chain = tm.chain;
156
        if (chain == null) {
157
            System.out.println("Could not obtain server certificate chain");
158
            return;
159
        }
160

  
161
        BufferedReader reader =
162
            new BufferedReader(new InputStreamReader(System.in));
163

  
164
        System.out.println();
165
        System.out.println("Server sent " + chain.length + " certificate(s):");
166
        System.out.println();
167
        MessageDigest sha1 = MessageDigest.getInstance("SHA1");
168
        MessageDigest md5 = MessageDigest.getInstance("MD5");
169
        for (int i = 0; i < chain.length; i++) {
170
            X509Certificate cert = chain[i];
171
            System.out.println(" " + (i + 1) + " Subject "
172
                + cert.getSubjectDN());
173
            System.out.println("   Issuer  " + cert.getIssuerDN());
174
            sha1.update(cert.getEncoded());
175
            System.out.println("   sha1    " + toHexString(sha1.digest()));
176
            md5.update(cert.getEncoded());
177
            System.out.println("   md5     " + toHexString(md5.digest()));
178
            System.out.println();
179
        }
180

  
181
//        int k=0;
182
//        System.out
183
//            .println("Enter certificate to add to trusted keystore or 'q' to quit: [1]");
184
//        String line = reader.readLine().trim();
185
//        try {
186
//            k = (line.length() == 0) ? 0 : Integer.parseInt(line) - 1;
187
//        } catch (NumberFormatException e) {
188
//            System.out.println("KeyStore not changed");
189
//            return;
190
//        }
191

  
192
        for( int k=0; k<chain.length; k++ ) {
193
            X509Certificate cert = chain[k];
194
            String alias = host + "-" + (k + 1);
195
            ks.setCertificateEntry(alias, cert);
196

  
197
            // OutputStream out = new FileOutputStream("jssecacerts");
198
            OutputStream out = new FileOutputStream(file);
199
            ks.store(out, passphrase);
200
            out.close();
201

  
202
            System.out.println();
203
            System.out.println(cert);
204
            System.out.println();
205
            System.out
206
                .println("Added certificate to keystore '" +
207
                        file + "' using alias '" + alias + "'");
208
        }
209
    }
210

  
211
    private static final char[] HEXDIGITS = "0123456789abcdef".toCharArray();
212

  
213
    private static String toHexString(byte[] bytes) {
214
        StringBuilder sb = new StringBuilder(bytes.length * 3);
215
        for (int b : bytes) {
216
            b &= 0xff;
217
            sb.append(HEXDIGITS[b >> 4]);
218
            sb.append(HEXDIGITS[b & 15]);
219
            sb.append(' ');
220
        }
221
        return sb.toString();
222
    }
223

  
224
    private static class SavingTrustManager implements X509TrustManager {
225

  
226
        private final X509TrustManager tm;
227
        private X509Certificate[] chain;
228

  
229
        SavingTrustManager(X509TrustManager tm) {
230
            this.tm = tm;
231
        }
232

  
233
        public X509Certificate[] getAcceptedIssuers() {
234
            throw new UnsupportedOperationException();
235
        }
236

  
237
        public void checkClientTrusted(X509Certificate[] chain, String authType)
238
            throws CertificateException {
239
            throw new UnsupportedOperationException();
240
        }
241

  
242
        public void checkServerTrusted(X509Certificate[] chain, String authType)
243
            throws CertificateException {
244
            this.chain = chain;
245
            tm.checkServerTrusted(chain, authType);
246
        }
247
    }
248
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.67/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
    public static final String VERSION_FORMAT = "%M.%m.%r";
22
    
23
    private static final Logger LOG = LoggerFactory.getLogger(ScriptsInstallerInitializer.class);
24
   
25
    @Override
26
    public Object call(Object... args) {
27
        // Cuando se hace la llamada a este metodo, aun no esta inicializado gvSIG.
28
        // Los servicios que ofrece el PluginsManager no son completos, solo algunos
29
        // de ellos estan disponibles. La lista de plugins aun no se ha cargado.
30
        try {
31
            String pluginName = (String) args[0];
32
            
33
            ProviderManager providerManager = InstallerProviderLocator.getProviderManager();            
34
            PluginsManager pluginManager = PluginsLocator.getManager();
35
            ScriptingManager manager = ScriptingLocator.getManager();
36
            InstallerManager installerManager = InstallerLocator.getInstallerManager();
37
            File pluginHomeFolder = pluginManager.getPluginHomeFolder(pluginName);
38
            
39
            String gvsigversion = pluginManager.getApplicationVersion().format(VERSION_FORMAT) ;
40
            File home = ScriptingUtils.getScriptsHomeFolder(pluginHomeFolder, gvsigversion);
41
            
42
            manager.setHomeFolder(home);
43
            manager.setPackagesFolder(pluginManager.getInstallFolder());
44
            
45
            File localAddonRepositoryFolder = new File(manager.getRootUserFolder(), "addons");
46
            
47
            ProviderFactory factory = manager.getInstallerFactory();
48
            providerManager.addProviderFactory(factory);
49
            
50
            installerManager.setDefaultLocalAddonRepository(
51
                    localAddonRepositoryFolder,
52
                    factory.getName()
53
            );
54
            
55
            return true;
56
            
57
        } catch (Exception ex) {
58
            LOG.warn("Problems initializing scripts installer.",ex);
59
            return false;
60
        }
61
    }
62

  
63
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.67/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.67/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.67/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.67/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.67/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.InputStream;
25
import java.util.List;
26
import org.apache.commons.io.IOUtils;
27
import org.apache.commons.lang3.StringUtils;
28

  
29
import org.gvsig.andami.IconThemeHelper;
30
import org.gvsig.andami.PluginsLocator;
31
import org.gvsig.andami.PluginsManager;
32
import org.gvsig.andami.plugins.Extension;
33
import org.gvsig.scripting.ScriptingLocator;
34
import org.gvsig.scripting.ScriptingManager;
35
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
36
import org.gvsig.scripting.swing.api.ScriptingUIManager;
37
import org.gvsig.tools.dynobject.DynObject;
38
import org.gvsig.tools.swing.impl.windowmanager.DefaultWindowManager;
39
import org.slf4j.Logger;
40
import org.slf4j.LoggerFactory;
41
import org.gvsig.tools.script.Script;
42
import org.gvsig.tools.util.Invocable;
43

  
44
public class ScriptingExtension extends Extension {
45

  
46
    @SuppressWarnings("FieldNameHidesFieldInSuperclass")
47
    private static final Logger logger = LoggerFactory.getLogger(ScriptingExtension.class);
48

  
49
    private ScriptingUtils utils;
50
    
51
    @Deprecated
52
    public static void log(String message) {
53
        ScriptingUtils.log(ScriptingUtils.INFO, message, null);
54
    }
55

  
56
    @Deprecated
57
    public static void log(int level, String message) {
58
        ScriptingUtils.log(level, message, null);
59
    }
60

  
61
    @Deprecated
62
    public static void log(int level, String message, Throwable th) {
63
        ScriptingUtils.log(level, message, th);
64
    }
65
    
66
    @Override
67
    public void initialize() {
68
        IconThemeHelper.registerIcon("action", "tools-scripting-launcher", this);
69
        IconThemeHelper.registerIcon("action", "tools-scripting-composer", this);
70
        IconThemeHelper.registerIcon("action", "tools-scripting-console-jython", this);
71

  
72
        Thread th = new Thread(new Runnable() {
73
            @Override
74
            public void run() {
75
                preloadPythonEngine();
76
            }
77
        }, "ScriptEnginesInitializer");
78
        th.start();
79
        try {
80
            th.join(1000); // force change to other thread
81
        } catch (InterruptedException ex) {
82
            // Ignore.
83
        }
84
    }
85

  
86
    @Override
87
    public void execute(String actionCommand) {
88
        this.execute(actionCommand, null);
89
    }
90

  
91
    @Override
92
    public void execute(String command, Object[] args) {
93

  
94

  
95
        if( "tools-scripting-launcher".equalsIgnoreCase(command) ) {
96
            utils.runLauncher();
97
            
98
        } else if( "tools-scripting-composer".equalsIgnoreCase(command) ) {
99

  
100
            DynObject preferences = getPlugin().getPluginProperties();
101
            Boolean composerUseHisWindowManager = (Boolean) preferences.getDynValue("ComposerUseHisWindowManager");
102
            if( composerUseHisWindowManager ) {
103
                DefaultWindowManager winmanager = new DefaultWindowManager();
104
                ScriptingUIManager uimanager = ScriptingSwingLocator.getUIManager();
105
                uimanager.setWindowManager(winmanager);
106
            }
107
            utils.runComposer();
108

  
109
        } else {
110
            utils.runScript(command, args);
111
        }
112
    }
113

  
114
    private void preloadPythonEngine() {
115
        ScriptingManager manager = (ScriptingManager) ScriptingLocator.getManager();
116
        synchronized (manager) {
117
            String respath = "/scripting/langs/python/preload.py";
118
            InputStream res = this.getClass().getResourceAsStream(respath);
119
            if( res != null ) {
120
                logger.info("Scan for script engines");
121
                List<String> lines;
122
                try {
123
                    lines = IOUtils.readLines(res);
124
                    String code = StringUtils.join(lines, "\n");
125
                    logger.info("Preload python script engine");
126
                    Script script = manager.createScript(
127
                        "preload",
128
                        code,
129
                        ScriptingManager.PYTHON_LANGUAGE_NAME
130
                    );
131
                    logger.info("Preload python modules");
132
                    script.invokeFunction("main", null);
133

  
134
                } catch (Exception ex) {
135
                    logger.warn("Can't run preload script for python.", ex);
136
                }
137
                logger.info("Preload of script engines finished");
138
            }
139
        }
140
    }
141

  
142
    
143
    @Override
144
    public void postInitialize() {
145
        super.postInitialize();
146
        
147
        PluginsManager pluginManager = PluginsLocator.getManager();
148
        this.utils = new ScriptingUtils();
149

  
150
        this.utils.initializaPaths(
151
                pluginManager.getPluginsFolders(), 
152
                pluginManager.getInstallFolder(), 
153
                this.getPlugin().getPluginHomeFolder(), 
154
                pluginManager.getApplicationVersion().format(ScriptsInstallerInitializer.VERSION_FORMAT)
155
        );
156
                
157
        pluginManager.addStartupTask(
158
            "ExecuteAutorunScripts",
159
            utils.getAutorunScriptsOnStartup(pluginManager.getPluginsFolders()),
160
            true,
161
            600
162
        );
163

  
164
        Invocable initializer = new ScriptsInstallerInitializer();
165
        initializer.call(this.getPlugin().getPluginName());
166
    }
167

  
168
    @Override
169
    public boolean isEnabled() {
170
        return true;
171
    }
172

  
173
    @Override
174
    public boolean isVisible() {
175
        return true;
176
    }
177

  
178
}
org.gvsig.scripting/tags/org.gvsig.scripting-2.3.67/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/java/org/gvsig/scripting/app/extension/ScriptingUtils.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.scripting.app.extension;
7

  
8
import java.io.File;
9
import java.io.IOException;
10
import java.nio.file.FileVisitOption;
11
import static java.nio.file.FileVisitOption.FOLLOW_LINKS;
12
import java.nio.file.FileVisitResult;
13
import java.nio.file.Files;
14
import java.nio.file.Path;
15
import java.nio.file.Paths;
16
import java.nio.file.SimpleFileVisitor;
17
import java.nio.file.attribute.BasicFileAttributes;
18
import java.text.MessageFormat;
19
import java.util.ArrayList;
20
import java.util.Arrays;
21
import java.util.Collections;
22
import java.util.Comparator;
23
import java.util.EnumSet;
24
import java.util.List;
25
import java.util.function.Predicate;
26
import javax.swing.JOptionPane;
27
import org.apache.commons.io.FileUtils;
28
import org.apache.commons.io.FilenameUtils;
29
import org.apache.commons.io.IOCase;
30
import org.apache.commons.lang3.BooleanUtils;
31
import org.gvsig.scripting.ScriptingBaseScript;
32
import org.gvsig.scripting.ScriptingFolder;
33
import org.gvsig.scripting.ScriptingLocator;
34
import org.gvsig.scripting.ScriptingManager;
35
import org.gvsig.scripting.ScriptingScript;
36
import org.gvsig.scripting.ScriptingUnit;
37
import org.gvsig.scripting.app.extension.messagewait.MessageWait;
38
import org.gvsig.scripting.swing.api.JScriptingComposer;
39
import org.gvsig.scripting.swing.api.ScriptingSwingLocator;
40
import org.gvsig.scripting.swing.api.ScriptingUIManager;
41
import static org.gvsig.scripting.swing.api.ScriptingUIManager.SCRIPT_COMPOSER_AUTORUN;
42
import org.gvsig.tools.ToolsLocator;
43
import org.gvsig.tools.exception.BaseException;
44
import org.gvsig.tools.i18n.I18nManager;
45
import org.gvsig.tools.swing.api.ToolsSwingLocator;
46
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager;
47
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
48
import org.gvsig.tools.task.SimpleTaskStatus;
49
import org.gvsig.tools.visitor.VisitCanceledException;
50
import org.gvsig.tools.visitor.Visitor;
51
import org.slf4j.Logger;
52
import org.slf4j.LoggerFactory;
53

  
54
/**
55
 *
56
 * @author jjdelcerro
57
 */
58
public class ScriptingUtils {
59
    
60
    public static final String SKIP_AUTORUNS = "skipAutoruns";
61
    
62
    private static final Logger logger = LoggerFactory.getLogger(ScriptingExtension.class);
63

  
64
    private boolean executingAutorunScripts = false;
65
    private static boolean composer_initialized = false;
66
    private final MessageWait message;
67

  
68
    /*
69
     * la funcion log y las constantes estan pensadas para usarlas desde los scripts.
70
     */
71
    public static final int INFO = 0;
72
    public static final int TRACE = 1;
73
    public static final int WARN = 2;
74
    public static final int ERROR = 3;
75

  
76
    public static void log(String message) {
77
        log(INFO, message, null);
78
    }
79

  
80
    public static void log(int level, String message) {
81
        log(level, message, null);
82
    }
83

  
84
    public static void log(int level, String message, Throwable th) {
85
        switch( level ) {
86
        case TRACE:
87
            logger.trace(message, th);
88
            break;
89
        case ERROR:
90
            logger.error(message, th);
91
            break;
92
        case WARN:
93
            logger.warn(message, th);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff