Esempio n. 1
1
  /** @throws IOException */
  public void createJar() throws IOException {
    Manifest manifest = new Manifest();

    setDefaultAttributes(metaInfAttributes);

    for (String attrName : metaInfAttributes.keySet()) {
      manifest.getMainAttributes().putValue(attrName, metaInfAttributes.get(attrName));
    }

    removeOldJar();

    if (unpackaged) {
      for (File inputDir : inputDirectory) {
        FileUtils.copyFilesFromDir(inputDir, outputFile, getIncludes(), getExcludes());
      }
      File metaInfDir = new File(outputFile, "META-INF");
      metaInfDir.mkdirs();
      manifest.write(new FileOutputStream(new File(metaInfDir, "MANIFEST.MF")));
    } else {
      File parentFile = outputFile.getParentFile();
      if (parentFile != null && !parentFile.exists()) {
        parentFile.mkdirs();
      }

      JarOutputStream target = new JarOutputStream(new FileOutputStream(outputFile), manifest);

      if (inputDirectory != null) {
        Set<String> added = new HashSet<String>();
        for (File inputDir : inputDirectory) {
          addFile(inputDir, target, inputDir.getCanonicalPath().length(), added);
        }
      }
      target.close();
    }
  }
  @Before
  public void setUp() throws Exception {
    String zpath =
        System.getProperty("java.io.tmpdir") + "/ZeppelinTest_" + System.currentTimeMillis();
    zeppelinDir = new File(zpath);
    zeppelinDir.mkdirs();
    new File(zeppelinDir, "conf").mkdirs();

    notebooksDir = Joiner.on(File.separator).join(zpath, "notebook");
    File notebookDir = new File(notebooksDir);
    notebookDir.mkdirs();

    String testNoteDir = Joiner.on(File.separator).join(notebooksDir, TEST_NOTE_ID);
    FileUtils.copyDirectory(
        new File(Joiner.on(File.separator).join("src", "test", "resources", TEST_NOTE_ID)),
        new File(testNoteDir));

    System.setProperty(ConfVars.ZEPPELIN_HOME.getVarName(), zeppelinDir.getAbsolutePath());
    System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_DIR.getVarName(), notebookDir.getAbsolutePath());
    System.setProperty(
        ConfVars.ZEPPELIN_INTERPRETERS.getVarName(),
        "org.apache.zeppelin.interpreter.mock.MockInterpreter1,org.apache.zeppelin.interpreter.mock.MockInterpreter2");
    System.setProperty(
        ConfVars.ZEPPELIN_NOTEBOOK_STORAGE.getVarName(),
        "org.apache.zeppelin.notebook.repo.GitNotebookRepo");

    MockInterpreter1.register("mock1", "org.apache.zeppelin.interpreter.mock.MockInterpreter1");
    MockInterpreter2.register("mock2", "org.apache.zeppelin.interpreter.mock.MockInterpreter2");

    conf = ZeppelinConfiguration.create();
  }
Esempio n. 3
1
  @Test(expected = FileNotFoundException.class)
  public final void testNoSuchFile() throws Exception {
    QueryIdFactory.reset();
    SubQueryId schid = QueryIdFactory.newSubQueryId(QueryIdFactory.newQueryId());
    QueryUnitId qid1 = QueryIdFactory.newQueryUnitId(schid);
    QueryUnitId qid2 = QueryIdFactory.newQueryUnitId(schid);

    File qid1Dir = new File(TEST_DATA + "/" + qid1.toString() + "/out");
    qid1Dir.mkdirs();
    File qid2Dir = new File(TEST_DATA + "/" + qid2.toString() + "/out");
    qid2Dir.mkdirs();

    Random rnd = new Random();
    FileWriter writer = new FileWriter(qid1Dir + "/" + "testHttp");
    String watermark1 = "test_" + rnd.nextInt();
    writer.write(watermark1);
    writer.flush();
    writer.close();

    writer = new FileWriter(qid2Dir + "/" + "testHttp");
    String watermark2 = "test_" + rnd.nextInt();
    writer.write(watermark2);
    writer.flush();
    writer.close();

    InterDataRetriever ret = new InterDataRetriever();
    HttpDataServer server = new HttpDataServer(NetUtils.createSocketAddr("127.0.0.1:0"), ret);
    server.start();

    ret.register(qid1, qid1Dir.getPath());
    InetSocketAddress addr = server.getBindAddress();
    assertDataRetrival(qid1, addr.getPort(), watermark1);
    ret.unregister(qid1);
    assertDataRetrival(qid1, addr.getPort(), watermark1);
  }
    public Preparation invoke(String ndkArchitecture) {
      // This usually points to ${basedir}/obj/local
      nativeLibDirectory = new File(nativeLibrariesOutputDirectory, ndkArchitecture);
      libsDirectoryExists = nativeLibDirectory.exists();

      // Determine how much of the output directory structure (most likely obj/...) does not exist
      // and based on what we find, determine how much of it we delete after the build
      directoryToRemove = nativeLibDirectory;
      if (!libsDirectoryExists) {
        getLog().info("Creating native output directory " + nativeLibDirectory);

        // This simply checks how much of the structure already exists - nothing (e.g. we make all
        // the dirs)
        // or just a partial part (the architecture part)?
        if (!nativeLibrariesOutputDirectory.exists()) {
          if (nativeLibrariesOutputDirectory.getParentFile().exists()) {
            nativeLibDirectory.mkdir();
          } else {
            nativeLibDirectory.mkdirs();
            directoryToRemove = nativeLibrariesOutputDirectory.getParentFile();
          }
        } else {
          if (nativeLibDirectory.getParentFile().exists()) {
            nativeLibDirectory.mkdir();
          } else {
            nativeLibDirectory.mkdirs();
            directoryToRemove = nativeLibDirectory.getParentFile();
          }
        }
      }
      return this;
    }
Esempio n. 5
1
  public ImageCache(String filePath, String secondFilePath) {
    memoryCache = new HashMap<CachedImageKey, CachedImage>(60, 1.0f);
    if (StringUtil.isNotBlank(filePath)) {
      ImageCache.filePath = filePath;
    }
    if (StringUtil.isNotBlank(secondFilePath)) {
      ImageCache.secondaryFilePath = secondFilePath;
    }
    File cacheFile = new File(ImageCache.filePath);
    if (!cacheFile.exists()) {
      cacheFile.mkdir();
    }
    for (String folder : IMAGE_FOLDER) {
      File file = new File(ImageCache.filePath + File.separator + folder);
      if (!file.exists()) {
        file.mkdirs();
      }
      file = new File(ImageCache.secondaryFilePath + File.separator + folder);
      if (!file.exists()) {
        file.mkdirs();
      }
    }

    getCacheHeap();
  }
  public static void unzipIntoDirectory(InputStream inputStream, File directory) {
    if (directory.isFile()) return;
    directory.mkdirs();

    try {
      inputStream = new BufferedInputStream(inputStream);
      inputStream = new ZipInputStream(inputStream);

      for (ZipEntry entry = null;
          (entry = ((ZipInputStream) inputStream).getNextEntry()) != null; ) {
        StringBuilder pathBuilder =
            new StringBuilder(directory.getPath()).append('/').append(entry.getName());
        File file = new File(pathBuilder.toString());

        if (entry.isDirectory()) {
          file.mkdirs();
          continue;
        }

        StreamUtil.write(pathBuilder, inputStream, false);
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      StreamUtil.closeQuietly(inputStream);
    }
  }
  public List<Spawner> loadAllSpawnersFromWorld(World w) {
    List<Spawner> list = new ArrayList<Spawner>();

    String ch = File.separator;
    String worldDir = w.getWorldFolder() + ch + "cs_data" + ch;
    String entityDir = worldDir + ch + "entity";
    String spawnerDir = worldDir + ch + "spawner";

    File spawnerFiles = new File(spawnerDir);
    File entityFiles = new File(entityDir);

    if (!spawnerFiles.exists()) spawnerFiles.mkdirs();

    if (!entityFiles.exists()) entityFiles.mkdirs();

    for (File spawnerFile : spawnerFiles.listFiles()) {

      Spawner s = PLUGIN.getFileManager().loadSpawner(spawnerFile);
      List<Integer> sEntsAsIDs = s.getTypeData();
      List<SpawnableEntity> sEnts = new ArrayList<SpawnableEntity>();
      ArrayList<SpawnableEntity> containedEntities = new ArrayList<SpawnableEntity>();

      for (Integer i : sEntsAsIDs) {
        sEnts.add(CustomSpawners.getEntity(i.toString()));
      }

      for (File f : entityFiles.listFiles()) {
        containedEntities.add(PLUGIN.getFileManager().loadEntity(f));
      }

      if (containedEntities.containsAll(sEnts)) list.add(s);
    }

    return list;
  }
  @Test
  public void testContinueOnSomeDbDirectoriesMissing() throws Exception {
    File targetDir1 = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    File targetDir2 = new File(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());

    try {
      assertTrue(targetDir1.mkdirs());
      assertTrue(targetDir2.mkdirs());

      if (!targetDir1.setWritable(false, false)) {
        System.err.println(
            "Cannot execute 'testContinueOnSomeDbDirectoriesMissing' because cannot mark directory non-writable");
        return;
      }

      RocksDBStateBackend rocksDbBackend = new RocksDBStateBackend(TEMP_URI);
      rocksDbBackend.setDbStoragePaths(targetDir1.getAbsolutePath(), targetDir2.getAbsolutePath());

      try {
        rocksDbBackend.initializeForJob(getMockEnvironment(), "foobar", IntSerializer.INSTANCE);
      } catch (Exception e) {
        e.printStackTrace();
        fail("Backend initialization failed even though some paths were available");
      }
    } finally {
      //noinspection ResultOfMethodCallIgnored
      targetDir1.setWritable(true, false);
      FileUtils.deleteDirectory(targetDir1);
      FileUtils.deleteDirectory(targetDir2);
    }
  }
 public static void unZip(String unZipfileName, String mDestPath) {
   if (!mDestPath.endsWith("/")) {
     mDestPath = mDestPath + "/";
   }
   FileOutputStream fileOut = null;
   ZipInputStream zipIn = null;
   ZipEntry zipEntry = null;
   File file = null;
   int readedBytes = 0;
   byte buf[] = new byte[4096];
   try {
     zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(unZipfileName)));
     while ((zipEntry = zipIn.getNextEntry()) != null) {
       file = new File(mDestPath + zipEntry.getName());
       if (zipEntry.isDirectory()) {
         file.mkdirs();
       } else {
         // 如果指定文件的目录不存在,则创建之.
         File parent = file.getParentFile();
         if (!parent.exists()) {
           parent.mkdirs();
         }
         fileOut = new FileOutputStream(file);
         while ((readedBytes = zipIn.read(buf)) > 0) {
           fileOut.write(buf, 0, readedBytes);
         }
         fileOut.close();
       }
       zipIn.closeEntry();
     }
   } catch (IOException ioe) {
     ioe.printStackTrace();
   }
 }
Esempio n. 10
0
 private void save() {
   dir = new File(PATH);
   if (!dir.exists()) {
     dir.mkdirs();
     Log.e(PATH, dir.mkdirs() + "");
   }
 }
  public static void initApplicationDirs() throws IOException {
    createTrustStoreFileIfNotExists();
    File appDataRoot = new File(applicationDataDir());
    if (!appDataRoot.exists()) {
      appDataRoot.mkdirs();
    }
    if (!appDataRoot.canWrite()) {
      SEAGridDialogHelper.showExceptionDialogAndWait(
          new Exception("Cannot Write to Application Data Dir"),
          "Cannot Write to Application Data Dir",
          null,
          "Cannot Write to Application Data Dir " + applicationDataDir());
    }

    // Legacy editors use stdout and stderr instead of loggers. This is a workaround to append them
    // to a file
    System.setProperty("app.data.dir", applicationDataDir() + "logs");
    logger = LoggerFactory.getLogger(SEAGridDesktop.class);
    File logParent = new File(applicationDataDir() + "logs");
    if (!logParent.exists()) logParent.mkdirs();
    PrintStream outPs = new PrintStream(applicationDataDir() + "logs/seagrid.std.out");
    PrintStream errPs = new PrintStream(applicationDataDir() + "logs/seagrid.std.err");
    System.setOut(outPs);
    System.setErr(errPs);
    Runtime.getRuntime()
        .addShutdownHook(
            new Thread() {
              public void run() {
                outPs.close();
                errPs.close();
              }
            });

    extractLegacyEditorResources();
  }
Esempio n. 12
0
  public static void copyFile(String filePath, File targetLocation) throws Exception {
    File f = new File(filePath);
    if (f.isFile()) {

      targetLocation.mkdirs();
      String[] pathElements = filePath.split(File.separator);

      if (pathElements.length > 0) {
        System.out.println(filePath.substring(0, filePath.lastIndexOf(File.separator)));
        targetLocation =
            new File(
                targetLocation
                    + File.separator
                    + filePath.substring(0, filePath.lastIndexOf(File.separator)));
        targetLocation.mkdirs();
      }

      JEditorPane editor = mainFrame.editors.get(filePath);

      FileWriter fstream =
          new FileWriter(targetLocation + File.separator + pathElements[pathElements.length - 1]);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write(editor.getText());
      // Close the output stream
      out.close();
    }
  }
Esempio n. 13
0
  private void copyAssets() {

    InputStream in = null;
    OutputStream out = null;
    try {

      in = getAssets().open("tiles.zip");

      Log.i(TAG, ": " + Environment.getExternalStorageDirectory());
      File dir = new File(Environment.getExternalStorageDirectory(), "osmdroid");
      File wallpaperDirectory = new File("/osmdroid/tiles/");
      File folder =
          new File(Environment.getExternalStorageDirectory().toString() + "/osmdroid/tiles/");
      folder.mkdirs();
      Log.i(TAG, "isExist : " + folder.exists());
      if (!folder.exists()) folder.mkdirs();
      File fileZip = new File(folder, "tiles.zip");
      Log.i(TAG, "isExist : " + fileZip.exists());

      out = new FileOutputStream(fileZip);
      copyFile(in, out);
      in.close();
      unzip(fileZip, folder);
      in = null;
      out.flush();
      out.close();
      out = null;
    } catch (IOException e) {
      Log.e("tag", "Failed to copy asset file: " + e.getMessage());
    }
  }
Esempio n. 14
0
  /**
   * Creates a temporary folder.
   *
   * @return Temporary folder
   * @throws IOException Reporting a failure to create the folder
   */
  protected static File createTempDir() throws IOException {
    File targetDir = null;
    final String tmpDir = System.getProperty("java.io.tmpdir");
    if (tmpDir == null) {
      throw new IllegalStateException(
          "The java.io.tmpdir property is null. Can't create a temporary directory for service unpacking");
    }
    if (tmpDir.indexOf(' ') >= 0) {

      targetDir =
          new File(
              "Recipe_Test_Temp_Files" + File.separator + "Test_" + System.currentTimeMillis());
      if (!targetDir.mkdirs()) {
        throw new IllegalStateException(
            "Failed to create a directory where service will be unzipped. Target was: "
                + targetDir);
      }
      logger.warning(
          "The System temp directory name includes spaces. Using alternate directory: "
              + targetDir);
    }
    final File tempFile = File.createTempFile("GS_tmp_dir", ".service", targetDir);
    final String path = tempFile.getAbsolutePath();
    tempFile.delete();
    tempFile.mkdirs();
    final File baseDir = new File(path);
    return baseDir;
  }
Esempio n. 15
0
  public void initEnv() {
    Log.i("WBR", "enter initenv()");

    Log.i("WBR", "setting backup dir " + WIFIConfigurationManager.BACKUP_PATH);
    File backupDir = new File(WIFIConfigurationManager.BACKUP_PATH);
    if (backupDir == null) {
      Log.e(
          "WBR",
          "ERROR !!!! :: backupdir file (" + WIFIConfigurationManager.BACKUP_PATH + ") is null");
    }
    if (!backupDir.exists()) {
      if (backupDir.mkdirs()) {
        Log.i("WBR", WIFIConfigurationManager.BACKUP_PATH + " folder created");
      } else {
        Log.e("WBR", WIFIConfigurationManager.BACKUP_PATH + " folder creation failed");
      }
    }
    Log.i("WBR", "setting backup dir done ");

    Log.i("WBR", "setting backup histo dir");
    File backupHistoDir = new File(WIFIConfigurationManager.BACKUP_HISTORY_PATH);
    if (!backupHistoDir.exists()) {
      if (backupHistoDir.mkdirs()) {
        Log.i("WBR", WIFIConfigurationManager.BACKUP_HISTORY_PATH + " folder created");
      } else {
        Log.e("WBR", WIFIConfigurationManager.BACKUP_HISTORY_PATH + " folder creation failed");
      }
    }
    Log.i("WBR", "setting backup histo dir");

    new InitializerTask(this).execute();
  }
Esempio n. 16
0
  protected void unzip(String pathToFile, String outputFolder) {
    System.out.println("Start unzipping: " + pathToFile + " to " + outputFolder);
    String pathToUnzip;
    if (outputFolder.equals(pathManager.getPlatformFolderInAndroidSdk())) {
      pathToUnzip = outputFolder;
    } else {
      pathToUnzip = outputFolder + "/" + FileUtil.getNameWithoutExtension(new File(pathToFile));
    }
    if (new File(pathToUnzip).listFiles() != null) {
      System.out.println("File was already unzipped: " + pathToFile);
      return;
    }
    try {
      byte[] buf = new byte[1024];
      ZipInputStream zipinputstream = null;
      ZipEntry zipentry;
      zipinputstream = new ZipInputStream(new FileInputStream(pathToFile));

      zipentry = zipinputstream.getNextEntry();
      try {
        while (zipentry != null) {
          String entryName = zipentry.getName();
          int n;
          File outputFile = new File(outputFolder + "/" + entryName);

          if (zipentry.isDirectory()) {
            outputFile.mkdirs();
            zipinputstream.closeEntry();
            zipentry = zipinputstream.getNextEntry();
            continue;
          } else {
            File parentFile = outputFile.getParentFile();
            if (parentFile != null && !parentFile.exists()) {
              parentFile.mkdirs();
            }
            outputFile.createNewFile();
          }

          FileOutputStream fileoutputstream = new FileOutputStream(outputFile);
          try {
            while ((n = zipinputstream.read(buf, 0, 1024)) > -1) {
              fileoutputstream.write(buf, 0, n);
            }
          } finally {
            fileoutputstream.close();
          }
          zipinputstream.closeEntry();
          zipentry = zipinputstream.getNextEntry();
        }

        zipinputstream.close();
      } catch (IOException e) {
        System.err.println("Entry name: " + zipentry.getName());
        e.printStackTrace();
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("Finish unzipping: " + pathToFile + " to " + outputFolder);
  }
Esempio n. 17
0
  /**
   * Output the entries to the specified output folder on the file system.
   *
   * @param outputFolder The target output folder.
   * @throws java.io.IOException Write failure.
   */
  public void toFileSystem(File outputFolder) throws IOException {
    AssertArgument.isNotNull(outputFolder, "outputFolder");

    if (outputFolder.isFile()) {
      throw new IOException(
          "Cannot write Archive entries to '"
              + outputFolder.getAbsolutePath()
              + "'.  This is a normal file i.e. not a directory.");
    }
    if (!outputFolder.exists()) {
      outputFolder.mkdirs();
    }

    Set<Map.Entry<String, File>> entrySet = entries.entrySet();
    for (Map.Entry<String, File> entry : entrySet) {
      File archEntryFile = entry.getValue();
      byte[] fileBytes;
      File entryFile = new File(outputFolder, entry.getKey());

      if (archEntryFile != null) {
        fileBytes = FileUtils.readFile(archEntryFile);
        entryFile.getParentFile().mkdirs();
        FileUtils.writeFile(fileBytes, entryFile);
      } else {
        entryFile.mkdirs();
      }
    }
  }
Esempio n. 18
0
  public File getDirectory(String targetProject, String targetPackage) throws ShellException {
    // targetProject is interpreted as a directory that must exist
    //
    // targetPackage is interpreted as a sub directory, but in package
    // format (with dots instead of slashes). The sub directory will be
    // created
    // if it does not already exist

    File project = new File(targetProject);
    if (!project.isDirectory()) {
      //            throw new ShellException(getString("Warning.9", //$NON-NLS-1$
      //                    targetProject));
      project.mkdirs();
    }

    StringBuilder sb = new StringBuilder();
    StringTokenizer st = new StringTokenizer(targetPackage, "."); // $NON-NLS-1$
    while (st.hasMoreTokens()) {
      sb.append(st.nextToken());
      sb.append(File.separatorChar);
    }

    File directory = new File(project, sb.toString());
    if (!directory.isDirectory()) {
      boolean rc = directory.mkdirs();
      if (!rc) {
        throw new ShellException(
            getString(
                "Warning.10", //$NON-NLS-1$
                directory.getAbsolutePath()));
      }
    }

    return directory;
  }
Esempio n. 19
0
  public Sneakermesh(File f) {
    root = f;
    log("root: " + f);
    GiveCommand.root = f;

    Command.setLogger(this);

    if (!root.exists()) {
      root.mkdirs();
    }

    tmp = new File(root, "tmp");
    if (!tmp.exists()) {
      tmp.mkdirs();
    }
    Message.setTmp(tmp);

    texts = new File(root, "texts");
    if (!texts.exists()) {
      texts.mkdirs();
    }

    have = new HashSet<String>();
    want = new HashSet<String>();
    queue = new LinkedBlockingQueue<Command>();

    loadHashes();
  }
  @Override
  public void generateAngularGlobalEntity(GrailsDomainClass grailsDomainClass, String destDir)
      throws IOException {
    Assert.hasText(destDir, "Argument [destdir] not specified");

    /* Get global template list */
    File viewsDir = new File(destDir, "web-app/js/app");
    if (!viewsDir.exists()) {
      viewsDir.mkdirs();
    }

    for (String name : getTemplateNamesFromPath("js/entity")) {
      File viewsEntityDir =
          new File(viewsDir.getAbsolutePath() + "/" + grailsDomainClass.getPropertyName());
      if (!viewsEntityDir.exists()) {
        viewsEntityDir.mkdirs();
      }
      generateText(
          grailsDomainClass,
          name,
          viewsDir.getAbsolutePath() + "/" + grailsDomainClass.getPropertyName(),
          "js/entity",
          "js");
    }
  }
Esempio n. 21
0
  public static void setSettingUtility() {
    addSettings("actions");
    addSettings("settings");

    if (SdcardUtils.hasSdcardAndCanWrite()) {
      File rootFile = new File(GlobalContext.getInstance().getAppPath());
      if (!rootFile.exists()) rootFile.mkdirs();

      // 数据缓存目录设置
      File jsonFile =
          new File(
              rootFile.getAbsolutePath()
                  + File.separator
                  + getPermanentSettingAsStr("com_m_common_json", "files"));
      if (!jsonFile.exists()) jsonFile.mkdirs();

      // 缓存目录设置
      File imageFile =
          new File(
              rootFile.getAbsolutePath()
                  + File.separator
                  + getPermanentSettingAsStr("com_m_common_image", "images"));
      if (!imageFile.exists()) imageFile.mkdirs();
    }
  }
  protected File makeTestFile(File dir, String name, String relative, final InputStream contents)
      throws IOException {
    if (relative != null) {
      dir = new File(dir, relative);
      if (!dir.exists()) {
        boolean mkdir = dir.mkdirs();
        assertTrue(dir.getPath(), mkdir);
      }
    } else if (!dir.exists()) {
      boolean mkdir = dir.mkdirs();
      assertTrue(dir.getPath(), mkdir);
    }
    File tempFile = new File(dir, name);
    if (tempFile.exists()) {
      tempFile.delete();
    }

    Files.copy(
        new InputSupplier<InputStream>() {
          @Override
          public InputStream getInput() throws IOException {
            return contents;
          }
        },
        tempFile);

    return tempFile;
  }
Esempio n. 23
0
  @Before
  public void setUp() throws Exception {
    mojo = new CreateMojo();

    project = folder.newFolder("my-project");
    src = new File(project, "src");
    main = new File(src, "main");
    app = new File(main, "app");
    api = new File(main, "api");
    lala = new File(api, "lala");

    api.mkdirs();
    app.mkdirs();
    lala.mkdirs();

    // Do
    apiFile = new File(api, "hello.yaml");
    apiFile.createNewFile();
    new File(api, "bye.yml").createNewFile();
    new File(lala, "wow.yaml").createNewFile();

    // Don't
    new File(main, "dont-read.yaml").createNewFile();

    // TODO mock properties like this:
    setVariableValueToObject(mojo, "buildContext", new DefaultBuildContext());
    setVariableValueToObject(mojo, "log", mock(Log.class));
  }
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
   File minidfsDir = new File("target/minidfs-" + UUID.randomUUID()).getAbsoluteFile();
   minidfsDir.mkdirs();
   Assert.assertTrue(minidfsDir.exists());
   System.setProperty(MiniDFSCluster.PROP_TEST_BUILD_DATA, minidfsDir.getPath());
   Configuration conf = new HdfsConfiguration();
   conf.set("dfs.namenode.fs-limits.min-block-size", String.valueOf(32));
   EditLogFileOutputStream.setShouldSkipFsyncForTesting(true);
   miniDFS = new MiniDFSCluster.Builder(conf).numDataNodes(3).build();
   dir = new Path(miniDFS.getURI() + "/dir");
   FileSystem fs = miniDFS.getFileSystem();
   fs.mkdirs(dir);
   writeFile(fs, new Path(dir + "/forAllTests/" + "path"), 1000);
   dummyEtc = new File(minidfsDir, "dummy-etc");
   dummyEtc.mkdirs();
   Assert.assertTrue(dummyEtc.exists());
   Configuration dummyConf = new Configuration(false);
   for (String file : new String[] {"core", "hdfs", "mapred", "yarn"}) {
     File siteXml = new File(dummyEtc, file + "-site.xml");
     FileOutputStream out = new FileOutputStream(siteXml);
     dummyConf.writeXml(out);
     out.close();
   }
   resourcesDir = minidfsDir.getAbsolutePath();
   hadoopConfDir = dummyEtc.getName();
   System.setProperty("sdc.resources.dir", resourcesDir);
   ;
 }
Esempio n. 25
0
 public static synchronized void printPS(Origin o, String printerAlias, int copyCount)
     throws Exception {
   String command = Properties.get(Names.PS_PRINT_APP);
   Printer printer = find(printerAlias);
   File printTemp =
       new File(
           Properties.get(Names.TEMP_DIR) + Names.PATH_SEPARATOR + "print-queue",
           "print-" + getNextCount());
   if (printTemp.exists()) FileUtil.delete(printTemp);
   printTemp.mkdirs();
   InputStream in = Downloader.download(o);
   File print = new File(printTemp, o.getName());
   if (print.exists()) print.delete();
   FileUtil.save(in, print, true);
   File work =
       new File(
           Properties.get(Names.WORKING_DIR) + Names.PATH_SEPARATOR + "print",
           "work-" + getNextCount());
   if (!work.exists()) work.mkdirs();
   int i;
   for (i = 0; i < copyCount; i++) {
     ExecShell shell = new ExecShell();
     shell.setExecutable(command);
     shell.setWorkingDirectory(work);
     shell.addCommandLineArgument("/D:" + printer.getPath(), false);
     shell.addCommandLineArgument(print.getAbsolutePath(), true);
     {
     } // Logwriter.printOnConsole("sleeping for 2..");
     Thread.sleep(2000);
     {
     } // Logwriter.printOnConsole("waking up");
     shell.execute();
   }
 }
Esempio n. 26
0
  public static void copyDir(
      File from,
      File to,
      boolean includeSubdirs,
      boolean mkdirs,
      boolean overwriteOnlyOlderFiles,
      FileFilter filter) {
    if (filter != null && !filter.accept(from)) return;
    if (mkdirs) to.mkdirs();
    if (from == null || !from.isDirectory() || !to.isDirectory()) return;
    File[] fs = from.listFiles();
    if (fs == null) return;
    for (int i = 0; i < fs.length; i++) {
      String n = fs[i].getName();
      File c = new File(to, n);
      if (fs[i].isDirectory() && !includeSubdirs) continue;
      if (filter != null && !filter.accept(new File(from, n))) continue;

      if (fs[i].isDirectory()) {
        c.mkdirs();
        copyDir(fs[i], c, includeSubdirs, mkdirs, overwriteOnlyOlderFiles, filter);
      } else if (overwriteOnlyOlderFiles && fs[i].isFile() && c.isFile()) {
        copyFile(fs[i], c, false, c.lastModified() < fs[i].lastModified());
      } else {
        copyFile(fs[i], c);
      }
    }
  }
Esempio n. 27
0
  private void initializeWorkerStorage()
      throws IOException, FileDoesNotExistException, SuspectedFileSizeException, BlockInfoException,
          TException {
    LOG.info("Initializing the worker storage.");
    if (!mLocalDataFolder.exists()) {
      LOG.info("Local folder " + mLocalDataFolder + " does not exist. Creating a new one.");
      mLocalDataFolder.mkdirs();
      mLocalUserFolder.mkdirs();

      CommonUtils.changeLocalFilePermission(mLocalDataFolder.getPath(), "775");
      CommonUtils.changeLocalFilePermission(mLocalUserFolder.getPath(), "775");
      return;
    }

    if (!mLocalDataFolder.isDirectory()) {
      String tmp = "Data folder " + mLocalDataFolder + " is not a folder!";
      LOG.error(tmp);
      throw new IllegalArgumentException(tmp);
    }

    if (mLocalUserFolder.exists()) {
      try {
        FileUtils.deleteDirectory(mLocalUserFolder);
      } catch (IOException e) {
        LOG.error(e.getMessage(), e);
      }
    }
    mLocalUserFolder.mkdir();
    CommonUtils.changeLocalFilePermission(mLocalUserFolder.getPath(), "775");

    mUnderfsOrphansFolder = mUnderfsWorkerFolder + "/orphans";
    if (!mUnderFs.exists(mUnderfsOrphansFolder)) {
      mUnderFs.mkdirs(mUnderfsOrphansFolder, true);
    }

    int cnt = 0;
    for (File tFile : mLocalDataFolder.listFiles()) {
      if (tFile.isFile()) {
        cnt++;
        LOG.info("File " + cnt + ": " + tFile.getPath() + " with size " + tFile.length() + " Bs.");

        long blockId = CommonUtils.getBlockIdFromFileName(tFile.getName());
        boolean success = mWorkerSpaceCounter.requestSpaceBytes(tFile.length());
        try {
          addFoundBlock(blockId, tFile.length());
        } catch (FileDoesNotExistException e) {
          LOG.error("BlockId: " + blockId + " becomes orphan for: \"" + e.message + "\"");
          LOG.info(
              "Swapout File " + cnt + ": blockId: " + blockId + " to " + mUnderfsOrphansFolder);
          swapoutOrphanBlocks(blockId, tFile);
          freeBlock(blockId);
          continue;
        }
        mAddedBlockList.add(blockId);
        if (!success) {
          throw new RuntimeException("Pre-existing files exceed the local memory capacity.");
        }
      }
    }
  }
Esempio n. 28
0
 public static void unjar(File dest, InputStream is) throws IOException {
   dest.mkdirs();
   JarInputStream jis = new JarInputStream(is);
   try {
     while (true) {
       JarEntry je = jis.getNextJarEntry();
       if (je == null) break;
       String n = je.getName();
       File f = new File(dest, n);
       if (je.isDirectory()) {
         f.mkdirs();
       } else {
         if (f.exists()) {
           f.delete();
         } else {
           f.getParentFile().mkdirs();
         }
         FileOutputStream os = new FileOutputStream(f);
         try {
           copyStream(jis, os);
         } finally {
           os.close();
         }
       }
       long time = je.getTime();
       if (time != -1) f.setLastModified(time);
     }
   } finally {
     jis.close();
   }
 }
Esempio n. 29
0
 public static void unzip(File dest, String jar) throws IOException {
   dest.mkdirs();
   ZipFile zf = new ZipFile(jar);
   try {
     Enumeration es = zf.entries();
     while (es.hasMoreElements()) {
       ZipEntry je = (ZipEntry) es.nextElement();
       String n = je.getName();
       File f = new File(dest, n);
       if (je.isDirectory()) {
         f.mkdirs();
       } else {
         if (f.exists()) {
           f.delete();
         } else {
           f.getParentFile().mkdirs();
         }
         InputStream is = zf.getInputStream(je);
         FileOutputStream os = new FileOutputStream(f);
         try {
           copyStream(is, os);
         } finally {
           os.close();
         }
       }
       long time = je.getTime();
       if (time != -1) f.setLastModified(time);
     }
   } finally {
     zf.close();
   }
 }
Esempio n. 30
0
 public static void unZipFile(String targetPath, InputStream is) throws JDependException {
   try {
     ZipInputStream zis = new ZipInputStream(is);
     ZipEntry entry = null;
     while ((entry = zis.getNextEntry()) != null) {
       String zipPath = entry.getName();
       if (entry.isDirectory()) {
         File zipFolder = new File(targetPath + File.separator + zipPath);
         if (!zipFolder.exists()) {
           zipFolder.mkdirs();
         }
       } else {
         File file = new File(targetPath + File.separator + zipPath);
         if (!file.exists()) {
           File pathDir = file.getParentFile();
           pathDir.mkdirs();
           file.createNewFile();
           // copy data
           FileOutputStream fos = new FileOutputStream(file);
           int bread;
           while ((bread = zis.read()) != -1) {
             fos.write(bread);
           }
           fos.close();
         }
       }
     }
     zis.close();
     is.close();
   } catch (Exception e) {
     e.printStackTrace();
     throw new JDependException("解压失败", e);
   }
 }