aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFileWithJar.java
blob: dd3ea8433e1b4501a087567b5a0a5ec6595f6fda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package net.sourceforge.jnlp.mock;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Locale;

import net.sourceforge.jnlp.InformationDesc;
import net.sourceforge.jnlp.JARDesc;
import net.sourceforge.jnlp.JNLPFile;
import net.sourceforge.jnlp.ResourcesDesc;
import net.sourceforge.jnlp.SecurityDesc;
import net.sourceforge.jnlp.Version;

/* A mocked dummy JNLP file with a single JAR. */
public class DummyJNLPFileWithJar extends JNLPFile {

    /* Create a JARDesc for the given URL location */
    static JARDesc makeJarDesc(URL jarLocation) {
        return new JARDesc(jarLocation, new Version("1"), null, false,false, false,false);
    }

    public URL codeBase, jarLocation;
    public JARDesc jarDesc;

    public DummyJNLPFileWithJar(File jarFile) throws MalformedURLException {
        codeBase = jarFile.getParentFile().toURI().toURL();
        jarLocation = jarFile.toURI().toURL();
        jarDesc = makeJarDesc(jarLocation); 
        info = new ArrayList<InformationDesc>();
    }

    @Override
    public ResourcesDesc getResources() {
        ResourcesDesc resources = new ResourcesDesc(null, new Locale[0], new String[0], new String[0]);
        resources.addResource(jarDesc);
        return resources;
    }
    @Override
    public ResourcesDesc[] getResourcesDescs(final Locale locale, final String os, final String arch) {
        return new ResourcesDesc[] { getResources() };
    }

    @Override
    public URL getCodeBase() {
        return codeBase;
    }

    @Override
    public SecurityDesc getSecurity() {
        return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null);
    }
}