Java Code Examples for com.intellij.openapi.util.io.FileUtil#setReadOnlyAttribute()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#setReadOnlyAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VMOptionsTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Test
public void testWritingReadOnlyFile() throws IOException {
  FileUtil.setReadOnlyAttribute(myFile.getPath(), true);

  VMOptions.writeOption(VMOptions.MemoryKind.HEAP, 1024);
  VMOptions.writeOption(VMOptions.MemoryKind.METASPACE, 256);

  assertThat(FileUtil.loadFile(myFile)).isEqualToIgnoringWhitespace("-Xmx1024m -XX:MaxMetaspaceSize=256m");
}
 
Example 2
Source File: VMOptions.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void writeGeneralOption(@Nonnull Pattern pattern, @Nonnull String value) {
  File file = getWriteFile();
  if (file == null) {
    LOG.warn("VM options file not configured");
    return;
  }

  try {
    String content = file.exists() ? FileUtil.loadFile(file) : read();

    if (!StringUtil.isEmptyOrSpaces(content)) {
      Matcher m = pattern.matcher(content);
      if (m.find()) {
        StringBuffer b = new StringBuffer();
        m.appendReplacement(b, Matcher.quoteReplacement(value));
        m.appendTail(b);
        content = b.toString();
      }
      else {
        content = StringUtil.trimTrailing(content) + SystemProperties.getLineSeparator() + value;
      }
    }
    else {
      content = value;
    }

    if (file.exists()) {
      FileUtil.setReadOnlyAttribute(file.getPath(), false);
    }
    else {
      FileUtil.ensureExists(file.getParentFile());
    }

    FileUtil.writeToFile(file, content);
  }
  catch (IOException e) {
    LOG.warn(e);
  }
}
 
Example 3
Source File: ReadOnlyAttributeUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void setReadOnlyAttribute(String path, boolean readOnlyStatus) throws IOException {
  FileUtil.setReadOnlyAttribute(path, readOnlyStatus);
}