Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

In this page you can find the example usage for java.net URL toExternalForm.

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:in.virit.vwscdn.VWSCDNMojo.java

@Override
public void execute() throws MojoExecutionException {

    try {/*from w w  w. j  av a 2s  .c o  m*/

        project.addCompileSourceRoot("target/generated-sources/vwscdn");

        String packageName = "in.virit";
        String className = "WidgetSet";

        String vaadinVersion = null;

        // Use same package as Maven plugin
        File packageDirectory = new File(outputDirectory, packageName.replace(".", "/"));
        packageDirectory.mkdirs();

        List cp = project.getCompileClasspathElements();
        Map<String, URL> urls = new HashMap<>();
        for (Object object : cp) {
            String path = (String) object;
            urls.put(path, new File(path).toURI().toURL());
        }
        Map<String, URL> availableWidgetSets = ClassPathExplorer.getAvailableWidgetSets(urls);
        Set<Artifact> artifacts = project.getArtifacts();
        for (Artifact artifact : artifacts) {
            // Store the vaadin version
            if (artifact.getArtifactId().equals("vaadin-server")) {
                vaadinVersion = artifact.getVersion();
                break;
            }
        }
        Set<Artifact> uniqueArtifacts = new HashSet<>();

        for (String name : availableWidgetSets.keySet()) {
            URL url = availableWidgetSets.get(name);
            for (Artifact a : artifacts) {
                String u = url.toExternalForm();
                if (u.contains(a.getArtifactId()) && u.contains(a.getBaseVersion())
                        && !u.contains("vaadin-client")) {
                    uniqueArtifacts.add(a);
                }
            }
        }

        WidgetSetRequest wsReq = new WidgetSetRequest();
        for (Artifact a : uniqueArtifacts) {
            wsReq.addon(a.getGroupId(), a.getArtifactId(), a.getBaseVersion());
        }
        System.out.println(
                (wsReq.getAddons() != null ? wsReq.getAddons().size() : 0) + " addons widget set found.");

        // Request compilation for the widgetset   
        wsReq.setCompileStyle(compileStyle);
        wsReq.setVaadinVersion(vaadinVersion);

        if (lastWidgetset.exists()
                && FileUtils.readFileToString(lastWidgetset).equals(wsReq.toWidgetsetString())) {
            System.out.println("No changes in widgetset: " + wsReq.toWidgetsetString());
            return;
        } else {
            FileUtils.writeStringToFile(lastWidgetset, wsReq.toWidgetsetString());
        }

        File outputFile = new File(packageDirectory, className + ".java");

        if (download) {
            serveLocally(wsReq, vaadinVersion, outputFile);
        } else {
            serveFromCDN(wsReq, vaadinVersion, outputFile);
        }
    } catch (IOException ex) {
        Logger.getLogger(VWSCDNMojo.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DependencyResolutionRequiredException ex) {
        Logger.getLogger(VWSCDNMojo.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:org.apache.jena.permissions.model.SecuredModelDetailTest.java

@Before
public void setup() {
    baseModel = ModelFactory.createDefaultModel();
    baseModel.removeAll();//from  w  w  w . j  a v a  2 s  .c om
    URL url = SecuredModelDetailTest.class.getClassLoader()
            .getResource("org/apache/jena/permissions/model/detail.ttl");
    baseModel.read(url.toExternalForm());
    secEval = new DetailEvaluator(baseModel);
    securedModel = Factory.getInstance(secEval, "http://example.com/detailModelTest", baseModel);
}

From source file:guru.qas.martini.jmeter.sampler.MartiniSampler.java

protected Exception getUnimplementedStepException(Martini martini, Step step) {
    Resource source = martini.getRecipe().getSource();

    String relative;/*from   www.j a va2  s. co m*/
    try {
        URL url = source.getURL();
        String externalForm = url.toExternalForm();
        int i = externalForm.lastIndexOf('!');
        relative = i > 0 && externalForm.length() > i + 1 ? externalForm.substring(i + 1) : externalForm;
    } catch (IOException e) {
        logger.warn("unable to obtain URL from Resource " + source, e);
        relative = source.toString();
    }

    int line = step.getLocation().getLine();
    String message = String.format("unimplemented step: %s line %s", relative, line);
    Exception exception = new Exception(message);
    exception.fillInStackTrace();
    return exception;
}

From source file:com.googlesource.gerrit.plugins.hooks.rtc.workitems.WorkItemsApiImpl.java

@Override
public synchronized RtcRelatedLink addRelated(long id, URL relatedUrl, String text) throws IOException {
    loginIfNeeded();//  ww  w . j av  a  2 s.  c om
    return transport.post(
            "/oslc/workitems/" + id + "/rtc_cm:com.ibm.team.workitem.linktype.relatedartifact.relatedArtifact",
            RtcRelatedLink.class, Transport.APP_JSON,
            new BasicNameValuePair("rdf:resource", relatedUrl.toExternalForm()),
            new BasicNameValuePair("oslc_cm:label", text));
}

From source file:hudson.lifecycle.WindowsSlaveInstaller.java

/**
 * Called when the install menu is selected
 *///from  ww w  .  j  a v a2 s  .  c  o  m
public void actionPerformed(ActionEvent e) {
    int r = JOptionPane.showConfirmDialog(dialog,
            "This will install a slave agent as a Windows service,\n"
                    + "so that this slave will connect to Hudson as soon as the machine boots.\n"
                    + "Do you want to proceed with installation?",
            Messages.WindowsInstallerLink_DisplayName(), JOptionPane.OK_CANCEL_OPTION);
    if (r != JOptionPane.OK_OPTION)
        return;

    if (!DotNet.isInstalled(2, 0)) {
        JOptionPane.showMessageDialog(dialog, ".NET Framework 2.0 or later is required for this feature",
                Messages.WindowsInstallerLink_DisplayName(), JOptionPane.ERROR_MESSAGE);
        return;
    }

    final File dir = new File(rootDir);

    try {
        final File slaveExe = new File(dir, "hudson-slave.exe");
        FileUtils.copyURLToFile(getClass().getResource("/windows-service/hudson.exe"), slaveExe);

        // write out the descriptor
        URL jnlp = new URL(engine.getHudsonUrl(), "computer/" + engine.slaveName + "/slave-agent.jnlp");
        String xml = generateSlaveXml(System.getProperty("java.home") + "\\bin\\java.exe",
                "-jnlpUrl " + jnlp.toExternalForm());
        FileUtils.writeStringToFile(new File(dir, "hudson-slave.xml"), xml, "UTF-8");

        // copy slave.jar
        URL slaveJar = new URL(engine.getHudsonUrl(), "jnlpJars/remoting.jar");
        File dstSlaveJar = new File(dir, "slave.jar").getCanonicalFile();
        if (!dstSlaveJar.exists()) // perhaps slave.jar is already there?
            FileUtils.copyURLToFile(slaveJar, dstSlaveJar);

        // install as a service
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        StreamTaskListener task = new StreamTaskListener(baos);
        r = new LocalLauncher(task).launch().cmds(slaveExe, "install").stdout(task).pwd(dir).join();
        if (r != 0) {
            JOptionPane.showMessageDialog(dialog, baos.toString(), "Error", JOptionPane.ERROR_MESSAGE);
            return;
        }

        r = JOptionPane.showConfirmDialog(dialog,
                "Installation was successful. Would you like to\n"
                        + "Stop this slave agent and start the newly installed service?",
                Messages.WindowsInstallerLink_DisplayName(), JOptionPane.OK_CANCEL_OPTION);
        if (r != JOptionPane.OK_OPTION)
            return;

        // let the service start after we close our connection, to avoid conflicts
        Runtime.getRuntime().addShutdownHook(new Thread("service starter") {
            public void run() {
                try {
                    StreamTaskListener task = new StreamTaskListener(System.out);
                    int r = new LocalLauncher(task).launch().cmds(slaveExe, "start").stdout(task).pwd(dir)
                            .join();
                    task.getLogger()
                            .println(r == 0 ? "Successfully started" : "start service failed. Exit code=" + r);
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        System.exit(0);
    } catch (Exception t) {
        StringWriter sw = new StringWriter();
        t.printStackTrace(new PrintWriter(sw));
        JOptionPane.showMessageDialog(dialog, sw.toString(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}

From source file:org.picketbox.http.test.config.ProtectedResourceManagerUnitTestCase.java

@Test
public void testUnprotectedResource() throws Exception {
    URL url = new URL(this.urlStr + "notProtected");

    DefaultHttpClient httpclient = null;

    try {/*from  w w  w  . jav a  2s . c o m*/
        httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(url.toExternalForm());
        HttpResponse response = httpclient.execute(httpget);
        assertEquals(404, response.getStatusLine().getStatusCode());
    } finally {
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:org.picketbox.http.test.config.ProtectedResourceManagerUnitTestCase.java

@Test
public void testProtectedResource() throws Exception {
    URL url = new URL(this.urlStr + "onlyManagers");

    DefaultHttpClient httpclient = null;

    try {/*from  ww  w  .  ja v  a  2 s  .  c  o m*/
        httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(url.toExternalForm());
        HttpResponse response = httpclient.execute(httpget);
        assertEquals(401, response.getStatusLine().getStatusCode());
    } finally {
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:javax.faces.webapp.ConfigFileTestCase.java

protected ConfigBase parseConfig(URL config) throws Exception {
    digester.clear();/*w w  w .  j a v  a 2  s.  co m*/
    digester.push(new ConfigBase());
    InputSource iso = new InputSource(config.toExternalForm());
    InputStream ist = config.openStream();
    iso.setByteStream(ist);
    ConfigBase base = (ConfigBase) digester.parse(iso);
    ist.close();
    return (base);
}

From source file:cz.cas.lib.proarc.common.config.AppConfiguration.java

private void copyConfigTemplateImpl(File configHome) throws IOException {
    File cfgFile = new File(configHome, CONFIG_FILE_NAME + ".template");
    if (!cfgFile.exists() || cfgFile.exists() && cfgFile.isFile() && cfgFile.canWrite()) {
        Enumeration<URL> resources = AppConfiguration.class.getClassLoader()
                .getResources(DEFAULT_PROPERTIES_RESOURCE);
        URL lastResource = null;/*from w  w  w. j a v a  2 s.  c o m*/
        while (resources.hasMoreElements()) {
            URL url = resources.nextElement();
            lastResource = url;
            System.out.println(url.toExternalForm());
        }

        if (lastResource == null) {
            throw new IllegalStateException(DEFAULT_PROPERTIES_RESOURCE);
        }
        InputStream resource = lastResource.openStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(resource, "ISO-8859-1"));
        try {
            // we need platform dependent line separator => PrintWriter
            PrintWriter writer = new PrintWriter(cfgFile, "UTF-8");
            try {
                for (String line; (line = reader.readLine()) != null;) {
                    writer.println(line);
                }
                writer.println();
            } finally {
                writer.close();
            }
        } finally {
            reader.close();
        }

    }
}

From source file:de.undercouch.gradle.tasks.download.DownloadTest.java

/**
 * Test if a file can be "downloaded" from a file:// url
 * @throws Exception if anything goes wrong
 *//*from  ww w . jav a2  s . c o  m*/
@Test
public void testFileDownloadURL() throws Exception {
    Download t = makeProjectAndTask();

    String testContent = "file content";
    File src = folder.newFile();
    FileUtils.writeStringToFile(src, testContent, "UTF-8");

    URL url = src.toURI().toURL();

    File dst = folder.newFile();
    assertTrue(dst.delete());

    t.src(new Object[] { url.toExternalForm() });
    t.dest(dst);
    t.execute();

    String content = FileUtils.readFileToString(dst, "UTF-8");
    assertEquals(testContent, content);
}