コード例 #1
0
 /** 确保 Database 数据文件存在 */
 private void ensureRuleDatabase() {
   // copy database
   final String dbBundleFile = "data/" + RuleManager.RULE_DB_DEPLOY_PATH;
   String[] postfixes = new String[] {".mv.db", ".trace.db"};
   for (String pf : postfixes) {
     File file = TsmartStorageManager.getFile(ToolInfo.CC, RuleManager.RULE_DB_DEPLOY_PATH + pf);
     if (!file.exists()) {
       // copy from the bundle relative path to the target position
       try {
         URL srcUrl = getBundle().getEntry(dbBundleFile + pf);
         FileUtils.copyURLToFile(srcUrl, file);
       } catch (IOException e) {
       }
     }
   }
   // copy rule tree
   final String xmlBundleFile = "data/" + RuleTree.XML_TREE_DEPLOY_PATH;
   try {
     File file = TsmartStorageManager.getFile(ToolInfo.CC, RuleTree.XML_TREE_DEPLOY_PATH);
     if (!file.exists()) {
       FileUtils.copyURLToFile(
           getBundle().getEntry(xmlBundleFile),
           TsmartStorageManager.getFile(ToolInfo.CC, RuleTree.XML_TREE_DEPLOY_PATH));
     }
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #2
0
ファイル: PluginManagerTest.java プロジェクト: stisti/jenkins
 /**
  * Load "dependee" and then load "depender".
  * Asserts that "depender" can access to "dependee".
  * 
  * @throws Exception
  */
 public void testInstallDependingPluginWithoutRestart() throws Exception {
     // Load dependee.
     {
         String target = "dependee.hpi";
         URL src = getClass().getClassLoader().getResource(String.format("plugins/%s", target));
         File dest = new File(jenkins.getRootDir(), String.format("plugins/%s", target));
         FileUtils.copyURLToFile(src, dest);
         jenkins.pluginManager.dynamicLoad(dest);
     }
     
     // before load depender, of course failed to call Depender.getValue()
     try {
         callDependerValue();
         fail();
     } catch (ClassNotFoundException _) {
     }
     
     // No extensions exist.
     assertTrue(jenkins.getExtensionList("org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint").isEmpty());
     
     // Load depender.
     {
         String target = "depender.hpi";
         URL src = getClass().getClassLoader().getResource(String.format("plugins/%s", target));
         File dest = new File(jenkins.getRootDir(), String.format("plugins/%s", target));
         FileUtils.copyURLToFile(src, dest);
         jenkins.pluginManager.dynamicLoad(dest);
     }
     
     // depender successfully accesses to dependee.
     assertEquals("dependee", callDependerValue());
     
     // Extension in depender is loaded.
     assertFalse(jenkins.getExtensionList("org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint").isEmpty());
 }
コード例 #3
0
  /**
   * Downloads the given file specified via url to the given canonicalDestination.
   *
   * @param urlSource String
   * @param urlDestination String
   * @throws Exception
   */
  @Override
  public void downloadFile(String urlSource, String urlDestination) throws Exception {

    // sanity check
    if (urlSource == null
        || urlSource.length() == 0
        || urlDestination == null
        || urlDestination.length() == 0) {
      throw new IllegalArgumentException(
          "downloadFile(): urlSource or urlDestination argument is null...");
    }

    // URLs for given parameters
    URL source = new URL(urlSource);
    URL destination = new URL(urlDestination);

    // we have a compressed file
    if (GzipUtils.isCompressedFilename(urlSource)) {
      // downlod to temp destination
      File tempDestinationFile =
          org.apache.commons.io.FileUtils.getFile(
              org.apache.commons.io.FileUtils.getTempDirectory(),
              new File(source.getFile()).getName());
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), " + urlSource + ", this may take a while...");
      }
      org.apache.commons.io.FileUtils.copyURLToFile(source, tempDestinationFile);
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), gunzip: we have compressed file, decompressing...");
      }
      // decompress the file
      gunzip(tempDestinationFile.getCanonicalPath());
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), gunzip complete...");
      }
      // move temp/decompressed file to final destination
      File destinationFile = new File(destination.getFile());
      if (destinationFile.exists()) {
        org.apache.commons.io.FileUtils.forceDelete(destinationFile);
      }
      org.apache.commons.io.FileUtils.moveFile(
          org.apache.commons.io.FileUtils.getFile(
              GzipUtils.getUncompressedFilename(tempDestinationFile.getCanonicalPath())),
          destinationFile);

      // lets cleanup after ourselves - remove compressed file
      tempDestinationFile.delete();
    }
    // uncompressed file, download directry to urlDestination
    else {
      if (LOG.isInfoEnabled()) {
        LOG.info("downloadFile(), " + urlSource + ", this may take a while...");
      }
      org.apache.commons.io.FileUtils.copyURLToFile(
          source, org.apache.commons.io.FileUtils.getFile(destination.getFile()));
    }
  }
コード例 #4
0
  private void createWebStructure(List<VcmFileData> result) throws IOException {
    log.debug("Copying resource files");
    FileUtils.copyURLToFile(
        ClassLoader.getSystemResource("webpage/style.css"), new File(outputRootPath, "style.css"));
    FileUtils.copyURLToFile(
        ClassLoader.getSystemResource("webpage/up.jpg"), new File(outputRootPath, "up.jpg"));
    FileUtils.copyURLToFile(
        ClassLoader.getSystemResource("webpage/folder.jpg"),
        new File(outputRootPath, "folder.jpg"));

    walk(new File(componentRootPath), result);
  }
コード例 #5
0
  /**
   * Copy resources needed from plugin to project build directory. Resources include custom fonts
   * and XSL customization files.
   *
   * @throws MojoExecutionException Copy failed
   */
  final void copyResources() throws MojoExecutionException {
    // If you update this method, also see getBaseConfiguration().
    String[] resources = {
      "/fonts/DejaVuSans-Oblique.ttf",
      "/fonts/DejaVuSans.ttf",
      "/fonts/DejaVuSansCondensed-Bold.ttf",
      "/fonts/DejaVuSansCondensed-BoldOblique.ttf",
      "/fonts/DejaVuSansMono-Bold.ttf",
      "/fonts/DejaVuSansMono-BoldOblique.ttf",
      "/fonts/DejaVuSansMono-Oblique.ttf",
      "/fonts/DejaVuSansMono.ttf",
      "/fonts/DejaVuSerif-Italic.ttf",
      "/fonts/DejaVuSerif.ttf",
      "/fonts/DejaVuSerifCondensed-Bold.ttf",
      "/fonts/DejaVuSerifCondensed-BoldItalic.ttf",
      "/docbkx-stylesheets/epub/coredoc.xsl",
      "/docbkx-stylesheets/fo/coredoc.xsl",
      "/docbkx-stylesheets/fo/titlepages.xsl",
      "/docbkx-stylesheets/html/chunked.xsl",
      "/docbkx-stylesheets/html/coredoc.xsl",
      "/docbkx-stylesheets/man/coredoc.xsl"
    };

    for (String resource : resources) {
      URL src = getClass().getResource(resource);
      File dest = new File(getBuildDirectory() + resource.replaceAll("/", File.separator));
      try {
        FileUtils.copyURLToFile(src, dest);
      } catch (IOException e) {
        throw new MojoExecutionException(
            "Failed to copy file: " + resource + "\n" + e.getMessage());
      }
    }
  }
コード例 #6
0
  @Before
  public void setup() throws Exception {

    vfs = getVFS();

    folder1.create();
    folder2.create();

    FileUtils.copyURLToFile(
        this.getClass().getResource("/HelloWorld.jar"), folder1.newFile("HelloWorld.jar"));
    FileUtils.copyURLToFile(
        this.getClass().getResource("/HelloWorld.jar"), folder2.newFile("HelloWorld.jar"));

    uri1 = new File(folder1.getRoot(), "HelloWorld.jar").toURI();
    uri2 = folder2.getRoot().toURI();
  }
コード例 #7
0
  /**
   * Prepare single and chunked HTML for publication.
   *
   * <p>The HTML built by docbkx-tools does not currently include the following, which this method
   * adds.
   *
   * <ul>
   *   <li>A DOCTYPE declaration (needed to get Internet Explorer to interpret CSS correctly
   *   <li>JavaScript to workaround a long-standing Firefox issue, and the fold/unfold long lines in
   *       Screen elements
   *   <li>A favicon link
   *   <li>JavaScript used by Google Analytics
   *   <li>CSS to style the HTML
   * </ul>
   *
   * @param htmlDir Directory under which to find HTML output
   * @throws MojoExecutionException Something went wrong when updating HTML.
   */
  final void postProcessHTML(final String htmlDir) throws MojoExecutionException {
    try {
      getLog().info("Editing built HTML...");
      HashMap<String, String> replacements = new HashMap<String, String>();

      String doctype =
          IOUtils.toString(getClass().getResourceAsStream("/starthtml-doctype.txt"), "UTF-8");
      replacements.put("<html>", doctype);

      String javascript =
          IOUtils.toString(getClass().getResourceAsStream("/endhead-js-favicon.txt"), "UTF-8");
      replacements.put("</head>", javascript);

      String linkToJira = getLinkToJira();
      String gascript =
          IOUtils.toString(getClass().getResourceAsStream("/endbody-ga.txt"), "UTF-8");
      gascript = gascript.replace("ANALYTICS-ID", getGoogleAnalyticsId());
      replacements.put("</body>", linkToJira + "\n" + gascript);

      HTMLUtils.updateHTML(htmlDir, replacements);

      getLog().info("Adding CSS...");
      File css = new File(getBuildDirectory().getPath() + File.separator + "coredoc.css");
      FileUtils.deleteQuietly(css);
      FileUtils.copyURLToFile(getClass().getResource("/coredoc.css"), css);
      HTMLUtils.addCss(htmlDir, css, FilenameUtils.getBaseName(getDocumentSrcName()) + ".html");
    } catch (IOException e) {
      throw new MojoExecutionException("Failed to update output HTML correctly: " + e.getMessage());
    }
  }
コード例 #8
0
ファイル: TestFile.java プロジェクト: GeehomThor/shadow
 public void copyFrom(URL resource) {
   try {
     FileUtils.copyURLToFile(resource, this);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
コード例 #9
0
 public static void copyURLToFile(URL source, File destination) {
   try {
     FileUtils.copyURLToFile(source, destination);
   } catch (IOException e) {
     throw new UncheckedIOException(e);
   }
 }
コード例 #10
0
  @Test
  public void testViewDicomHeaderByIdPublicForPublicImage() throws Exception {
    PublicData publicDataMock = createMock(PublicData.class);

    URL testDicomUrl = this.getClass().getClassLoader().getResource("test.dcm");
    FileUtils.copyURLToFile(testDicomUrl, new File("/tmp/test.dcm"));

    expect(SpringApplicationContext.getBean("imageDAO")).andReturn(imageDAOMock);
    expect(imageDAOMock.findImagePath(591166)).andReturn("/tmp/test.dcm");
    expectNew(PublicData.class).andReturn(publicDataMock);
    expect(publicDataMock.checkPublicImage(591166)).andReturn(Boolean.TRUE);
    publicDataMock.setAuthorizationManager(authorizationManagerMock);

    replayMock();
    replay(PublicData.class, publicDataMock);

    LocalDicomTagViewer localDicomTagViewer = new LocalDicomTagViewer();
    localDicomTagViewer.setPublicData(true);
    localDicomTagViewer.setAuthorizationManager(authorizationManagerMock);

    List<DicomTagDTO> tags = localDicomTagViewer.viewDicomHeader(591166);
    Assert.assertTrue(tags.size() == 110);

    new File("/tmp/test.dcm").delete();

    verify(PublicData.class, publicDataMock);
  }
コード例 #11
0
 public void testCopyFileFromServerToRemoteClient() throws Exception {
   URL url = getClass().getResource("FTPRemoteClientTest.class");
   FileUtils.copyURLToFile(
       url, new File(ftpServer.getDefaultUserHomeDirectory(), "FTPRemoteClientTest.class"));
   ftpRemoteClient.copyFileFromLocalMachineToRemoteClient(
       "FTPRemoteClientTest.class", "./FTPRemoteClientTest2.class");
 }
コード例 #12
0
ファイル: AutoRefMap.java プロジェクト: arahpthos/AutoReferee
  /**
   * Gets map object associated with the zip file at the provided URL.
   *
   * @param url URL of map zip to be downloaded.
   * @return generated map object
   * @throws IOException if map cannot be unpackaged
   */
  public static AutoRefMap getMapFromURL(String url) throws IOException {
    String filename = url.substring(url.lastIndexOf('/') + 1, url.length());
    File zip = new File(AutoRefMap.getMapLibrary(), filename);

    FileUtils.copyURLToFile(new URL(url), zip);
    return AutoRefMap.getMapInfo(zip);
  }
コード例 #13
0
 public static void downloadToFile(final Proxy proxy, final URL url, final File file)
     throws IOException {
   if (proxy != Proxy.NO_PROXY && proxy.type() != Proxy.Type.DIRECT) {
     downloadUsingProxy(proxy, url, file);
   } else {
     FileUtils.copyURLToFile(url, file, 10000, 5000);
   }
 }
コード例 #14
0
ファイル: ShiwaBundleHelper.java プロジェクト: CSCSI/Triana
 /**
  * Download.
  *
  * @param urlSource the url source
  * @param downloadDir the download dir
  * @param localFile the local file
  * @return the file
  * @throws IOException Signals that an I/O exception has occurred.
  */
 public static File download(String urlSource, File downloadDir, File localFile)
     throws IOException {
   File remoteFile = new File(urlSource);
   if (localFile == null) {
     localFile = new File(downloadDir, remoteFile.getName());
   }
   org.apache.commons.io.FileUtils.copyURLToFile(new URL(urlSource), localFile);
   return localFile;
 }
コード例 #15
0
  /**
   * Downloads an Excel Spreadsheet XML and reads the substance values (name, ADI and ARfD)
   *
   * @throws Exception
   */
  private static void getAndParseFile() throws Exception {
    System.out.println("getAndParseFile");
    File file = File.createTempFile("substances", "tmp");

    String excelFileUrl =
        "http://ec.europa.eu/sanco_pesticides/public/?event=activesubstance.exportList";
    URL url = new URL(excelFileUrl);
    System.out.println("downloading file from " + excelFileUrl + " ...");
    FileUtils.copyURLToFile(url, file);
    System.out.println("downloading finished, parsing...");

    removeLineFromFile(file.getAbsolutePath(), 1, 2);

    String fileContent = IOUtils.toString(new FileInputStream(file));
    fileContent = fileContent.replaceAll("&ECCO", "&#38;ECCO");
    fileContent =
        "<?xml version=\"1.0\"?>\n"
            + "<!DOCTYPE some_name [ \n"
            + "<!ENTITY nbsp \"&#160;\"> \n"
            + "<!ENTITY acute \"&#180;\"> \n"
            + "]>"
            + fileContent;

    SAXParserFactory parserFactor = SAXParserFactory.newInstance();
    SAXParser parser = parserFactor.newSAXParser();
    SAXHandler handler = new SAXHandler();

    ByteArrayInputStream bis = new ByteArrayInputStream(fileContent.getBytes());

    parser.parse(bis, handler);

    // Parsing the substance list obtained from XML
    int count = 0;
    for (XmlRow subsRow : handler.xmlRowList) {
      if (subsRow.cellList.size() > 19) {
        String substance = subsRow.cellList.get(0);
        if (substance.equals("Substance")) {
          continue;
        }

        count++;
        String adi = subsRow.cellList.get(15); // column P
        String arfd = subsRow.cellList.get(18); // column S

        System.out.println(
            "Substance name='" + substance + "', ADI='" + adi + "', ARfD='" + arfd + "'");
      }
    }

    if (file.exists()) {
      System.out.println("delete file-> " + file.getAbsolutePath());
      if (!file.delete()) {
        System.out.println("file '" + file.getAbsolutePath() + "' was not deleted!");
      }
    }
    System.out.println("getAndParseFile finished, processed " + count + " substances!");
  }
コード例 #16
0
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    File function = scriptMgr.getFunctionRoot();
    File script = new File(function, "factorial." + getExtension());

    FileUtils.copyURLToFile(getClass().getResource(script.getName()), script);
  }
コード例 #17
0
ファイル: PluginManagerTest.java プロジェクト: stisti/jenkins
    public void testInstallWithoutRestart() throws Exception {
        URL res = getClass().getClassLoader().getResource("plugins/htmlpublisher.jpi");
        File f = new File(jenkins.getRootDir(), "plugins/htmlpublisher.jpi");
        FileUtils.copyURLToFile(res, f);
        jenkins.pluginManager.dynamicLoad(f);

        Class c = jenkins.getPluginManager().uberClassLoader.loadClass("htmlpublisher.HtmlPublisher$DescriptorImpl");
        assertNotNull(jenkins.getDescriptorByType(c));
    }
コード例 #18
0
ファイル: ClassPathUtils.java プロジェクト: rockgin/opoopress
  /**
   * @param jarFileURL
   * @param sourcePath
   * @param destination
   * @param overwrite
   * @throws Exception
   */
  protected static void copyJarPath(
      URL jarFileURL, String sourcePath, File destination, boolean overwrite) throws Exception {
    // URL jarFileURL = ResourceUtils.extractJarFileURL(url);
    if (!sourcePath.endsWith("/")) {
      sourcePath += "/";
    }
    String root = jarFileURL.toString() + "!/";
    if (!root.startsWith("jar:")) {
      root = "jar:" + root;
    }

    JarFile jarFile = new JarFile(new File(jarFileURL.toURI()));
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
      JarEntry jarEntry = entries.nextElement();
      String name = jarEntry.getName();
      // log.debug(name + "." + sourcePath + "." + name.startsWith(sourcePath));
      if (name.startsWith(sourcePath)) {
        String relativePath = name.substring(sourcePath.length());
        // log.debug("relativePath: " + relativePath);
        if (relativePath != null && relativePath.length() > 0) {
          File tmp = new File(destination, relativePath);
          // not exists or overwrite permitted
          if (overwrite || !tmp.exists()) {
            if (jarEntry.isDirectory()) {
              tmp.mkdirs();
              if (IS_DEBUG_ENABLED) {
                log.debug("Create directory: " + tmp);
              }
            } else {
              File parent = tmp.getParentFile();
              if (!parent.exists()) {
                parent.mkdirs();
              }
              // 1.FileCopyUtils.copy
              // InputStream is = jarFile.getInputStream(jarEntry);
              // FileCopyUtils.copy(is, new FileOutputStream(tmp));

              // 2. url copy
              URL u = new URL(root + name);
              // log.debug(u.toString());
              FileUtils.copyURLToFile(u, tmp);
              if (IS_DEBUG_ENABLED) {
                log.debug("Copyed file '" + u + "' to '" + tmp + "'.");
              }
            }
          }
        }
      }
    }

    try {
      jarFile.close();
    } catch (Exception ie) {
    }
  }
コード例 #19
0
 /** Oeps, duplication... */
 @Override
 public File copyTo(File target) throws MalformedURLException, IOException {
   File to = target;
   if (target.isDirectory()) {
     String[] pathElements = url.getFile().split("/");
     to = new File(target, pathElements[pathElements.length - 1]);
   }
   copyURLToFile(url, to);
   return to;
 }
コード例 #20
0
 public void downloadTest() {
   try {
     FileUtils.copyURLToFile(
         new URL(
             "http://www.openaip.net/system/files/airspaces/openaip_airspace_belgium_be.aip_1444791895"),
         new File("C:\\Downloads\\openaip\\openaip_airspace_belgium_be.aip"));
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
コード例 #21
0
ファイル: PluginManagerTest.java プロジェクト: stisti/jenkins
    /**
     * Manual submission form.
     */
    public void testUploadJpi() throws Exception {
        HtmlPage page = new WebClient().goTo("pluginManager/advanced");
        HtmlForm f = page.getFormByName("uploadPlugin");
        File dir = env.temporaryDirectoryAllocator.allocate();
        File plugin = new File(dir, "tasks.jpi");
        FileUtils.copyURLToFile(getClass().getClassLoader().getResource("plugins/tasks.jpi"),plugin);
        f.getInputByName("name").setValueAttribute(plugin.getAbsolutePath());
        submit(f);

        assertTrue( new File(jenkins.getRootDir(),"plugins/tasks.jpi").exists() );
    }
コード例 #22
0
  /** Download the chronicle page from the wiki. */
  public static Document downloadChroniclePageFromWiki(
      final URL chronicleUrl, final File chronicleDownloadFolder) throws IOException {
    // Calculate output filename.
    final File destination =
        new File(chronicleDownloadFolder, getImageFileName(chronicleUrl) + ".html");

    // Download chronicle page to output folder.
    FileUtils.copyURLToFile(chronicleUrl, destination);

    // Read downloaded chronicle with JSoup.
    return Jsoup.parse(destination, "UTF-8", chronicleUrl.toString());
  }
コード例 #23
0
ファイル: AssetManager.java プロジェクト: edwardcd/maptool
 /**
  * Create an asset from a file.
  *
  * @param file File to use for asset
  * @return Asset associated with the file
  * @throws IOException
  */
 public static Asset createAsset(URL url) throws IOException {
   // Create a temporary file from the downloaded URL
   File newFile = File.createTempFile("remote", null, null);
   try {
     FileUtils.copyURLToFile(url, newFile);
     if (!newFile.exists() || newFile.length() < 20) return null;
     Asset temp =
         new Asset(FileUtil.getNameWithoutExtension(url), FileUtils.readFileToByteArray(newFile));
     return temp;
   } finally {
     newFile.delete();
   }
 }
コード例 #24
0
  /**
   * Creates the summary file and the JavaScript file that will be updated for each received
   * response
   *
   * @throws IOException if a problem occurs writing the file
   */
  private void createOverview() throws IOException {
    FileUtils.writeStringToFile(javaScriptFile_, "var tab = [];\n", TextUtil.DEFAULT_CHARSET);

    final URL indexResource =
        DebuggingWebConnection.class.getResource("DebuggingWebConnection.index.html");
    if (indexResource == null) {
      throw new RuntimeException("Missing dependency DebuggingWebConnection.index.html");
    }
    final File summary = new File(reportFolder_, "index.html");
    FileUtils.copyURLToFile(indexResource, summary);

    LOG.info("Summary will be in " + summary.getAbsolutePath());
  }
コード例 #25
0
ファイル: PluginManagerTest.java プロジェクト: stisti/jenkins
 /**
  * Load "depender" and then load "dependee".
  * Asserts that "depender" can access to "dependee".
  * 
  * @throws Exception
  */
 @Bug(19976)
 public void testInstallDependedPluginWithoutRestart() throws Exception {
     // Load depender.
     {
         String target = "depender.hpi";
         URL src = getClass().getClassLoader().getResource(String.format("plugins/%s", target));
         File dest = new File(jenkins.getRootDir(), String.format("plugins/%s", target));
         FileUtils.copyURLToFile(src, dest);
         jenkins.pluginManager.dynamicLoad(dest);
     }
     
     // before load dependee, depender does not access to dependee.
     assertEquals("depender", callDependerValue());
     
     // before load dependee, of course failed to list extensions for dependee.
     try {
         jenkins.getExtensionList("org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint");
         fail();
     } catch( ClassNotFoundException _ ){
     }
     
     // Load dependee.
     {
         String target = "dependee.hpi";
         URL src = getClass().getClassLoader().getResource(String.format("plugins/%s", target));
         File dest = new File(jenkins.getRootDir(), String.format("plugins/%s", target));
         FileUtils.copyURLToFile(src, dest);
         jenkins.pluginManager.dynamicLoad(dest);
     }
     
     // (MUST) Not throws an exception
     // (SHOULD) depender successfully accesses to dependee.
     assertEquals("dependee", callDependerValue());
     
     // No extensions exist.
     // extensions in depender is not loaded.
     assertTrue(jenkins.getExtensionList("org.jenkinsci.plugins.dependencytest.dependee.DependeeExtensionPoint").isEmpty());
 }
コード例 #26
0
  /** Copies a well known style out to the data directory and adds a catalog entry for it. */
  void initializeStyle(Catalog catalog, String styleName, String sld) throws IOException {

    // copy the file out to the data directory if necessary
    if (resourceLoader.find("styles", sld) == null) {
      FileUtils.copyURLToFile(
          GeoServerLoader.class.getResource(sld),
          new File(resourceLoader.findOrCreateDirectory("styles"), sld));
    }

    // create a style for it
    StyleInfo s = catalog.getFactory().createStyle();
    s.setName(styleName);
    s.setFilename(sld);
    catalog.add(s);
  }
コード例 #27
0
  protected void includeEmptyDescriptor() throws MojoFailureException {

    final URL source = getClass().getResource(NULL_XML);

    final File target = new File(outputDirectorySCR(), NULL_XML);

    try {
      FileUtils.copyURLToFile(source, target);
    } catch (final Exception e) {
      throw new MojoFailureException("can not get " + NULL_XML, e);
    }

    getLog().info("");
    getLog().info("including empty descriptor = " + target);
  }
コード例 #28
0
 /** Скачивает архив с последней БД */
 private void downloadDB() {
   URL urlToDBExchange = null;
   File uploadedArchive = null;
   File oldUnzipedFile = null;
   try {
     uploadedArchive = new File(getClass().getResource(RES_PATH + DB_ARCHIVE_NAME).toURI());
     RES_ABS_PATH = uploadedArchive.getParent();
     urlToDBExchange = new URL(CATALOG_UPLOAD_URL + DB_ARCHIVE_NAME);
     FileUtils.copyURLToFile(urlToDBExchange, uploadedArchive);
     oldUnzipedFile = new File(uploadedArchive.getParent() + File.separator + DB_NAME);
     if (oldUnzipedFile.exists() && oldUnzipedFile.isFile()) {
       FileUtils.deleteQuietly(oldUnzipedFile);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #29
0
  @Test
  public void testViewDicomHeaderById() throws Exception {

    URL testDicomUrl = this.getClass().getClassLoader().getResource("test.dcm");
    FileUtils.copyURLToFile(testDicomUrl, new File("/tmp/test.dcm"));

    expect(SpringApplicationContext.getBean("imageDAO")).andReturn(imageDAOMock);
    expect(imageDAOMock.findImagePath(591166)).andReturn("/tmp/test.dcm");

    replayMock();

    LocalDicomTagViewer localDicomTagViewer = new LocalDicomTagViewer();
    List<DicomTagDTO> tags = localDicomTagViewer.viewDicomHeader(591166);
    Assert.assertTrue(tags.size() == 110);

    new File("/tmp/test.dcm").delete();
  }
コード例 #30
0
  /**
   * Submits a resourceJob installation job.
   *
   * @param session
   * @param resourceJob
   * @throws Exception
   */
  public void submitResourceInstall(JobArea jobArea, Session session, ResourceJob resourceJob)
      throws Exception {
    resourceJob.setTag(this.jobTag);

    jobArea.createTag(resourceJob.getTag());
    final File taskLocalDir = new File(jobArea.getBasename(resourceJob.getTag()));

    // get the wrapper script
    URL wrapperScriptURL = getClass().getClassLoader().getResource(this.wrapperScript);
    FileUtils.copyURLToFile(
        wrapperScriptURL, new File(jobArea.getBasename(resourceJob.getTag()), this.wrapperScript));

    FileUtils.writeStringToFile(
        new File(jobArea.getBasename(resourceJob.getTag()), constantsTemplate),
        writeConstants(jobArea, resourceJob));

    copyArtifactsPbRequests(
        resourceJob.getSourceConfig(), this.environmentScriptFilename, taskLocalDir);

    copyResourceFiles(
        registry.findByTypedId("GOBYWEB_SERVER_SIDE", ResourceConfig.class), taskLocalDir);

    copyResourceFiles(resourceJob.getSourceConfig(), taskLocalDir);
    AutoOptionsFileHelper helper = new AutoOptionsFileHelper(registry);

    File autoOptions =
        helper.generateAutoOptionsFile(new ResourceJobWrapper(resourceJob.getSourceConfig()));
    FileUtils.moveFile(
        autoOptions,
        new File(FilenameUtils.concat(taskLocalDir.getAbsolutePath(), "auto-options.sh")));
    // give execute permission to resourceJob scripts
    String[] binaryFiles =
        new String[] {"groovy", this.wrapperScript, "auto-options.sh", "constants.sh"};
    jobArea.grantExecutePermissions(resourceJob.getTag(), binaryFiles);

    // execute the resourceJob
    logger.info(
        String.format(
            "Resource %s: submitting to local cluster at %s...",
            resourceJob.getTag(), taskLocalDir.getAbsolutePath()));
    Map<String, String> env = new HashMap<String, String>();
    env.put("JOB_DIR", taskLocalDir.getAbsolutePath());
    env.put("PATH", System.getenv("PATH"));
    jobArea.execute(resourceJob.getTag(), this.wrapperScript, env);
  }