This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 196428
Collapse All | Expand All

(-)a/nbbuild/antsrc/org/netbeans/nbbuild/AutoUpdate.java (-5 / +51 lines)
Lines 52-57 Link Here
52
import java.io.InputStream;
52
import java.io.InputStream;
53
import java.io.InputStreamReader;
53
import java.io.InputStreamReader;
54
import java.io.OutputStream;
54
import java.io.OutputStream;
55
import java.net.MalformedURLException;
55
import java.net.URISyntaxException;
56
import java.net.URISyntaxException;
56
import java.net.URL;
57
import java.net.URL;
57
import java.net.URLConnection;
58
import java.net.URLConnection;
Lines 67-72 Link Here
67
import java.util.zip.ZipFile;
68
import java.util.zip.ZipFile;
68
import javax.xml.parsers.SAXParser;
69
import javax.xml.parsers.SAXParser;
69
import javax.xml.parsers.SAXParserFactory;
70
import javax.xml.parsers.SAXParserFactory;
71
import javax.xml.xpath.XPathExpressionException;
72
import javax.xml.xpath.XPathFactory;
70
import org.apache.tools.ant.BuildException;
73
import org.apache.tools.ant.BuildException;
71
import org.apache.tools.ant.DirectoryScanner;
74
import org.apache.tools.ant.DirectoryScanner;
72
import org.apache.tools.ant.Project;
75
import org.apache.tools.ant.Project;
Lines 88-93 Link Here
88
public class AutoUpdate extends Task {
91
public class AutoUpdate extends Task {
89
    private List<Modules> modules = new ArrayList<Modules>();
92
    private List<Modules> modules = new ArrayList<Modules>();
90
    private FileSet nbmSet;
93
    private FileSet nbmSet;
94
    private File download;
91
    private File dir;
95
    private File dir;
92
    private File cluster;
96
    private File cluster;
93
    private URL catalog;
97
    private URL catalog;
Lines 112-117 Link Here
112
    public void setToDir(File dir) {
116
    public void setToDir(File dir) {
113
        this.cluster = dir;
117
        this.cluster = dir;
114
    }
118
    }
119
    
120
    public void setDownloadDir(File dir) {
121
        this.download = dir;
122
    }
115
123
116
    /** Forces rewrite even the version of a module is not newer */
124
    /** Forces rewrite even the version of a module is not newer */
117
    public void setForce(boolean force) {
125
    public void setForce(boolean force) {
Lines 126-133 Link Here
126
134
127
    @Override
135
    @Override
128
    public void execute() throws BuildException {
136
    public void execute() throws BuildException {
137
        boolean downloadOnly = false;
129
        if ((dir != null) == (cluster != null)) {
138
        if ((dir != null) == (cluster != null)) {
130
            throw new BuildException("Specify either todir or installdir");
139
            if (dir == null && cluster == null && download != null) {
140
                log("Going to download NBMs only to " + download);
141
                downloadOnly = true;
142
            } else {
143
                throw new BuildException("Specify either todir or installdir");
144
            }
131
        }
145
        }
132
        Map<String, ModuleItem> units;
146
        Map<String, ModuleItem> units;
133
        if (catalog != null) {
147
        if (catalog != null) {
Lines 194-200 Link Here
194
            boolean delete = false;
208
            boolean delete = false;
195
            File lastM = null;
209
            File lastM = null;
196
            try {
210
            try {
197
                if (uu.getURL().getProtocol().equals("file")) {
211
                if (download == null && uu.getURL().getProtocol().equals("file")) {
198
                    try {
212
                    try {
199
                        tmp = new File(uu.getURL().toURI());
213
                        tmp = new File(uu.getURL().toURI());
200
                    } catch (URISyntaxException ex) {
214
                    } catch (URISyntaxException ex) {
Lines 206-214 Link Here
206
                }
220
                }
207
                final String dash = uu.getCodeName().replace('.', '-');
221
                final String dash = uu.getCodeName().replace('.', '-');
208
                if (tmp == null) {
222
                if (tmp == null) {
209
                    tmp = File.createTempFile(dash, ".nbm");
223
                    if (download != null) {
210
                    tmp.deleteOnExit();
224
                        tmp = new File(download, dash + ".nbm");
211
                    delete = true;
225
                        String v = readVersion(tmp);
226
                        if (v != null && !uu.isNewerThan(v)) {
227
                            log("Version " + v + " of " + tmp + " is up to date", Project.MSG_VERBOSE);
228
                            if (!force) {
229
                                continue;
230
                            }
231
                        }
232
                    } else {
233
                        tmp = File.createTempFile(dash, ".nbm");
234
                        tmp.deleteOnExit();
235
                        delete = true;
236
                    }
212
                    Get get = new Get();
237
                    Get get = new Get();
213
                    get.setProject(getProject());
238
                    get.setProject(getProject());
214
                    get.setTaskName("get:" + uu.getCodeName());
239
                    get.setTaskName("get:" + uu.getCodeName());
Lines 217-222 Link Here
217
                    get.setVerbose(true);
242
                    get.setVerbose(true);
218
                    get.execute();
243
                    get.execute();
219
                }
244
                }
245
                if (downloadOnly) {
246
                    continue;
247
                }
220
248
221
                File whereTo = dir != null ? new File(dir, uu.targetcluster) : cluster;
249
                File whereTo = dir != null ? new File(dir, uu.targetcluster) : cluster;
222
                whereTo.mkdirs();
250
                whereTo.mkdirs();
Lines 447-452 Link Here
447
        }
475
        }
448
        return all;
476
        return all;
449
    }
477
    }
478
    
479
    private String readVersion(File nbm) {
480
        try {
481
            URL u = new URL("jar:" + nbm.toURI() + "!/Info/info.xml");
482
            XPathFactory f = XPathFactory.newInstance();
483
            final InputStream s = u.openStream();
484
            InputSource is = new InputSource(s);
485
            String res = f.newXPath().evaluate("module/manifest/@OpenIDE-Module-Specification-Version", is);
486
            if (res.length() == 0) {
487
                throw new IOException("Not found tag OpenIDE-Module-Specification-Version!");
488
            }
489
            s.close();
490
            return res;
491
        } catch (Exception ex) {
492
            log("Cannot parse Info/info.xml from " + nbm, ex, Project.MSG_INFO);
493
            return null;
494
        }
495
    }
450
496
451
    private void parseVersion(final File config, final Map<String,List<String>> toAdd) throws Exception {
497
    private void parseVersion(final File config, final Map<String,List<String>> toAdd) throws Exception {
452
        class P extends DefaultHandler {
498
        class P extends DefaultHandler {
(-)a/nbbuild/test/unit/src/org/netbeans/nbbuild/AutoUpdateTest.java (+33 lines)
Lines 67-72 Link Here
67
        super(name);
67
        super(name);
68
    }
68
    }
69
69
70
    public void testJustDownloadNBMs() throws Exception {
71
        File nbm = generateNBM("org-netbeans-api-annotations-common.nbm",
72
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml",
73
            "netbeans/modules/org-netbeans-api-annotations-common.jar");
74
        assertTrue("NBM file created", nbm.isFile());
75
76
        File target = new File(getWorkDir(), "target");
77
        target.mkdirs();
78
79
        execute(
80
            "autoupdate.xml", "-verbose", "-Ddir=" + nbm.getParent(),
81
            "-Dincludes=org.netbeans.api.annotations.common",
82
            "-Dtarget=" + target,
83
            "mirror"
84
        );
85
        
86
        File[] arr = target.listFiles();
87
        assertEquals("One item in the array:\n" + getStdOut(), 1, arr.length);
88
        assertEquals("It is the NBM file", nbm.getName(), arr[0].getName());
89
        assertEquals("Length is the same", nbm.length(), arr[0].length());
90
        
91
        execute(
92
            "autoupdate.xml", "-verbose", "-Ddir=" + nbm.getParent(),
93
            "-Dincludes=org.netbeans.api.annotations.common",
94
            "-Dtarget=" + target,
95
            "mirror"
96
        );
97
98
        if (getStdOut().contains("get:org.netbeans.api.annotations.common")) {
99
            fail("No download when latest version present:\n" + getStdOut());
100
        }
101
        
102
    }
70
    public void testDirectlySpecifiedNBMs() throws Exception {
103
    public void testDirectlySpecifiedNBMs() throws Exception {
71
        File nbm = generateNBM("org-netbeans-api-annotations-common.nbm",
104
        File nbm = generateNBM("org-netbeans-api-annotations-common.nbm",
72
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml",
105
            "netbeans/config/Modules/org-netbeans-api-annotations-common.xml",
(-)a/nbbuild/test/unit/src/org/netbeans/nbbuild/autoupdate.xml (+13 lines)
Lines 59-62 Link Here
59
        </autoupdate>
59
        </autoupdate>
60
60
61
    </target>
61
    </target>
62
    
63
    <target name="mirror">
64
        <echo message="${root}"/>
65
66
        <taskdef classname="org.netbeans.nbbuild.AutoUpdate" name="autoupdate" classpath="${nb_all}/nbbuild/nbantext.jar"/>
67
68
        <autoupdate downloaddir="${target}">
69
            <nbms dir="${dir}">
70
                <include name="*.nbm"/>
71
            </nbms>
72
            <modules includes="${includes}"/>
73
        </autoupdate>
74
    </target>
62
</project>
75
</project>

Return to bug 196428