Revision 91

View differences:

trunk/org.gvsig.customize.app/org.gvsig.customize.app.mainplugin/src/main/java/org/gvsig/customize/Installkit.java
1
package org.gvsig.customize;
2

  
3
import java.io.File;
4
import java.io.IOException;
5
import java.nio.file.Files;
6
import java.nio.file.Path;
7
import java.nio.file.Paths;
8
import java.nio.file.attribute.PosixFilePermission;
9
import java.util.HashSet;
10
import java.util.Set;
11
import org.gvsig.andami.PluginServices;
12
import org.gvsig.andami.PluginsLocator;
13
import org.gvsig.andami.PluginsManager;
14
import org.slf4j.Logger;
15
import org.slf4j.LoggerFactory;
16

  
17
public class Installkit {
18

  
19
    private static final Logger logger = LoggerFactory.getLogger(Installkit.class);
20
            
21
    File folder;
22

  
23
    public Installkit() {
24
        PluginsManager pluginsManager = PluginsLocator.getManager();
25
        PluginServices plugin = pluginsManager.getPlugin(CustomizeExtension.class);
26
        this.folder = new File(plugin.getPluginDirectory(), "installkit");
27
        setExecutePermission();
28
    }
29

  
30
    private File getInstallkitExefile() {
31
        File file = new File(folder.getAbsolutePath(), "installkit");
32
        return file;
33
    }
34

  
35
    public void addpks(String arg1, String arg2) throws IOException, InterruptedException {
36
        String cmd = getInstallkitExefile().getAbsolutePath()
37
                + " "
38
                + folder.getAbsolutePath()
39
                + "/main.tcl addpks "
40
                + arg1
41
                + " "
42
                + arg2;
43

  
44
        Process child = Runtime.getRuntime().exec(cmd);
45
        child.waitFor();
46
    }
47

  
48
    private void setExecutePermission() {
49
        Path path = Paths.get(getInstallkitExefile().toURI());
50
        Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>();
51
        //add owners permission
52
        perms.add(PosixFilePermission.OWNER_READ);
53
        perms.add(PosixFilePermission.OWNER_EXECUTE);
54
        //add group permissions
55
        perms.add(PosixFilePermission.GROUP_READ);
56
        perms.add(PosixFilePermission.GROUP_EXECUTE);
57
        //add others permissions
58
        perms.add(PosixFilePermission.OTHERS_READ);
59
        perms.add(PosixFilePermission.OTHERS_EXECUTE);
60

  
61
        try {
62
            Files.setPosixFilePermissions(path, perms);
63
        } catch (IOException ex) {
64
            logger.warn("Can't add execution permissions to '"+getInstallkitExefile()+"'.",ex);
65
        }
66
    }
67
}
trunk/org.gvsig.customize.app/org.gvsig.customize.app.mainplugin/src/main/java/org/gvsig/customize/CustomizeExtension.java
61 61
    }
62 62

  
63 63

  
64
    
64

  
65 65
    private void doCreateDistributionTask(final DistributionParametersPanel panel) {
66 66
        ApplicationManager application = ApplicationLocator.getManager();
67
                
67

  
68 68
        if( panel.getOnlineInstaller()==null ) {
69 69
            application.messageDialog(
70
                    "Shall specify the online installer to use", 
71
                    "Parameter required", 
70
                    "Shall specify the online installer to use",
71
                    "Parameter required",
72 72
                    JOptionPane.WARNING_MESSAGE);
73 73
            return;
74 74
        }
75 75
        if( panel.getWorkingFolder()==null ) {
76 76
            application.messageDialog(
77
                    "Shall specify the working folder to use", 
78
                    "Parameter required", 
77
                    "Shall specify the working folder to use",
78
                    "Parameter required",
79 79
                    JOptionPane.WARNING_MESSAGE);
80 80
            return;
81 81
        }
82 82
//        if( panel.getPackageSet()==null ) {
83 83
//            application.messageDialog(
84
//                    "Shall specify the package set to use", 
85
//                    "Parameter required", 
84
//                    "Shall specify the package set to use",
85
//                    "Parameter required",
86 86
//                    JOptionPane.WARNING_MESSAGE);
87 87
//            return;
88 88
//        }
89 89
        if( panel.getDistributionId()==null ) {
90 90
            application.messageDialog(
91
                    "Shall specify the identifier of the new distribution", 
92
                    "Parameter required", 
91
                    "Shall specify the identifier of the new distribution",
92
                    "Parameter required",
93 93
                    JOptionPane.WARNING_MESSAGE);
94 94
            return;
95 95
        }
96
        
96

  
97 97
        panel.setCloseAndCreateEnabled(false);
98
        
98

  
99 99
        final DistributionBuilder builder = new DistributionBuilder(panel);
100 100
        builder.setDistributionId(panel.getDistributionId());
101 101
        builder.setOnlineInstaller(panel.getOnlineInstaller());
102 102
        builder.setPackageSet(panel.getPackageSetFolder());
103 103
        builder.setWorkingFolder(panel.getWorkingFolder());
104 104
        builder.setIncludeCustomizePlugin(panel.getIncludeCustomizePlugin());
105
        
105

  
106 106
        Thread task = new Thread(new Runnable() {
107 107
            @Override
108 108
            public void run() {
......
121 121
    }
122 122

  
123 123
    public boolean isVisible() {
124
        PackageManager pkgmanager = ToolsLocator.getPackageManager();
125
        if( PackageManager.OS.LINUX.equalsIgnoreCase(pkgmanager.getOperatingSystem()) ) {
126
            return true;
127
        }
128
        return false;
124
        return true;
129 125
    }
130 126
}
trunk/org.gvsig.customize.app/org.gvsig.customize.app.mainplugin/src/main/java/org/gvsig/customize/DistributionBuilder.java
38 38
public class DistributionBuilder {
39 39

  
40 40
    private static final Logger logger = LoggerFactory.getLogger(DistributionBuilder.class);
41
    private static final String PCKGNAME= "package.gvspks";
41 42

  
42 43
    private String distributionId;
43 44
    private File onlineInstaller;
......
73 74

  
74 75
    public boolean build() {
75 76
        try {
76
            Installkit installkit = new Installkit();
77

  
78 77
            String target_name = this.onlineInstaller.getName().replace("online", this.distributionId);
79 78
            File target = new File(this.workingFolder, target_name);
80 79

  
......
94 93
            FileUtils.copyFile(this.onlineInstaller, target);
95 94

  
96 95
            message("Adding package set to the installer...");
97
            installkit.addpks(target.getAbsolutePath(), packageSet.getAbsolutePath());
96
            addPackagetoZip(target, packageSet);
98 97

  
99 98
            message("Installer created.");
100 99
        } catch (Exception ex) {
......
106 105
        }
107 106
        return true;
108 107
    }
109
    
108

  
109
    private void addPackagetoZip(File zipFile, File packageFile) throws IOException{
110
        FileSystem zipfs = null;
111
        try {
112
        Map<String, Object> env = new HashMap<>();
113
        env.put("create", "true");
114
        env.put("useTempFile", Boolean.TRUE);
115
        Path zipPath = Paths.get(zipFile.getAbsolutePath());
116
        URI uriZip = URI.create("jar:file:" + zipPath.toUri().getPath());
117
        zipfs = FileSystems.newFileSystem(uriZip,env);
118
        Path pathInZipfile = zipfs.getPath("/"+PCKGNAME);
119
        // copy a file into the zip file
120
        Files.copy( packageFile.toPath(),pathInZipfile,
121
                StandardCopyOption.REPLACE_EXISTING );
122
        message("Package set added to the installer.");
123
        } catch (Exception e) {
124
            logger.warn("Impossible to add ("+packageFile.getAbsolutePath()+") to ("+zipFile.getAbsolutePath()+")",e);
125
        } finally{
126
            if (zipfs != null) {
127
                try {
128
                    zipfs.close();
129
                } catch (IOException ex) {
130
                }
131
            }
132
        }
133
    }
134

  
110 135
    private void createPackageset(File zipfile) {
111 136
        Map<String, String> env = new HashMap<>();
112 137
        env.put("create", "true");
......
133 158
                }
134 159
            }
135 160
        }
136
        
161

  
137 162
    }
138 163

  
139 164
    private void buildCustomizePlugin() throws FileNotFoundException, MakePackageServiceException, IOException {
......
144 169
            InstallerManager installManager = InstallerLocator.getInstallerManager();
145 170

  
146 171
            FileUtils.copyFileToDirectory(
147
                    new File(packagesetFolder,"defaultPackages"), 
172
                    new File(packagesetFolder,"defaultPackages"),
148 173
                    plugin.getPluginDirectory()
149
            );   
150
            
174
            );
175

  
151 176
            PackageInfo pkginfo = pluginsManager.getPackageInfo(CustomizeExtension.class);
152 177
            String pkgfilename = installManager.getPackageFileName(pkginfo);
153 178
            customizePackagePath = new File(this.workingFolder, pkgfilename);

Also available in: Unified diff