com.intellij.openapi.components.RoamingType Java Examples

The following examples show how to use com.intellij.openapi.components.RoamingType. 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: BaseToolManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
public BaseToolManager(ActionManager actionManagerEx, SchemesManagerFactory factory) {
  myActionManager = actionManagerEx;

  mySchemesManager = factory.createSchemesManager(
    getSchemesPath(), createProcessor(), RoamingType.PER_USER);

  mySchemesManager.loadSchemes();
  registerActions();
}
 
Example #2
Source File: StateStorageManagerImplTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void testCreateStateStorageAssertionThrownWhenUnknownMacro() {
  try {
    myStateStorageManager.getStateStorage("$UNKNOWN_MACRO$/test.xml", RoamingType.PER_USER);
    fail("Exception expected");
  }
  catch (IllegalArgumentException e) {
    assertEquals("Unknown macro: $UNKNOWN_MACRO$ in storage file spec: $UNKNOWN_MACRO$/test.xml", e.getMessage());
  }
}
 
Example #3
Source File: SchemesManagerFactoryImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends Named, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(final String fileSpec,
                                                                                                    final SchemeProcessor<E> processor,
                                                                                                    final RoamingType roamingType) {
  final Application application = ApplicationManager.getApplication();
  if (!(application instanceof ApplicationEx2)) return null;
  String baseDirPath = ((ApplicationEx2)application).getStateStore().getStateStorageManager().expandMacros(fileSpec);

  StreamProvider
          provider = ((ApplicationEx2)ApplicationManager.getApplication()).getStateStore().getStateStorageManager().getStreamProvider();
  SchemesManagerImpl<T, E> manager = new SchemesManagerImpl<T, E>(fileSpec, processor, roamingType, provider, new File(baseDirPath));
  myRegisteredManagers.add(manager);
  return manager;
}
 
Example #4
Source File: VfsFileBasedStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void updatedFromStreamProvider(@Nonnull Set<String> changedComponentNames, boolean deleted) {
  if (myRoamingType == RoamingType.DISABLED) {
    // storage roaming was changed to DISABLED, but settings repository has old state
    return;
  }

  try {
    Element newElement = deleted ? null : loadDataFromStreamProvider();
    if (newElement == null) {
      StorageUtil.deleteFile(myFile, this, myCachedVirtualFile);
      // if data was loaded, mark as changed all loaded components
      if (myLoadedData != null) {
        changedComponentNames.addAll(myLoadedData.getComponentNames());
        myLoadedData = null;
      }
    }
    else if (myLoadedData != null) {
      StorageData newStorageData = createStorageData();
      loadState(newStorageData, newElement);
      changedComponentNames.addAll(myLoadedData.getChangedComponentNames(newStorageData, myPathMacroSubstitutor));
      myLoadedData = newStorageData;
    }
  }
  catch (Throwable e) {
    LOG.error(e);
  }
}
 
Example #5
Source File: XmlElementStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void doSaveForProvider(@Nonnull Element element, @Nonnull RoamingType roamingType, @Nullable byte[] content) throws IOException {
  if (content == null) {
    StorageUtil.sendContent(myStreamProvider, myFileSpec, element, roamingType);
  }
  else {
    myStreamProvider.saveContent(myFileSpec, content, myRoamingType);
  }
}
 
Example #6
Source File: XmlElementStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected XmlElementStorage(@Nonnull String fileSpec,
                            @Nullable RoamingType roamingType,
                            @Nullable TrackingPathMacroSubstitutor pathMacroSubstitutor,
                            @Nonnull String rootElementName,
                            @Nullable StreamProvider streamProvider) {
  super(pathMacroSubstitutor);

  myFileSpec = fileSpec;
  myRoamingType = roamingType == null ? RoamingType.PER_USER : roamingType;
  myRootElementName = rootElementName;
  myStreamProvider = myRoamingType == RoamingType.DISABLED ? null : streamProvider;
}
 
Example #7
Source File: IoFileBasedStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
public IoFileBasedStorage(@Nonnull String filePath,
                          @Nonnull String fileSpec,
                          @Nullable RoamingType roamingType,
                          @Nullable TrackingPathMacroSubstitutor pathMacroManager,
                          @Nonnull String rootElementName,
                          @Nonnull Disposable parentDisposable,
                          @Nullable final Listener listener,
                          @Nullable StreamProvider streamProvider,
                          boolean useXmlProlog) {
  super(fileSpec, roamingType, pathMacroManager, rootElementName, streamProvider);

  myFilePath = filePath;
  myUseXmlProlog = useXmlProlog;
  myFile = new File(filePath);
}
 
Example #8
Source File: ExternalStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public InputStream loadContent(String fileSpec, RoamingType roamingType, StateStorageManager stateStorageManager) throws IOException {
  Ref<byte[]> ref = myQueue.getContent(fileSpec, roamingType);
  if (ref != null) {
    byte[] bytes = ref.get();
    if (bytes == null) {
      return null;
    }
    else {
      Pair<byte[], Integer> pair = DataCompressor.uncompress(new UnsyncByteArrayInputStream(bytes));
      return new UnsyncByteArrayInputStream(pair.getFirst());
    }
  }

  InputStream stream = null;
  int mod = -1;
  File file = new File(myProxyDirectory, buildFileSpec(roamingType, fileSpec));
  if (file.exists()) {
    try (FileInputStream inputStream = new FileInputStream(file)) {
      Pair<byte[], Integer> compressedPair = DataCompressor.uncompress(inputStream);

      stream = new UnsyncByteArrayInputStream(compressedPair.getFirst());
      mod = compressedPair.getSecond();
    }
  }

  myQueue.wantLoad(fileSpec, roamingType, mod, stateStorageManager);
  return stream;
}
 
Example #9
Source File: ExternalStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public Collection<String> listSubFiles(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  fileSpec = buildFileSpec(roamingType, fileSpec);

  File proxy = new File(myProxyDirectory, fileSpec);
  if (proxy.isDirectory() && proxy.isDirectory()) {
    return Arrays.asList(proxy.list());
  }
  return Collections.emptyList();
}
 
Example #10
Source File: StorageUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static void sendContent(@Nonnull StreamProvider provider, @Nonnull String fileSpec, @Nonnull Parent element, @Nonnull RoamingType type) {
  if (!provider.isApplicable(fileSpec, type)) {
    return;
  }

  try {
    doSendContent(provider, fileSpec, element, type);
  }
  catch (IOException e) {
    LOG.warn(e);
  }
}
 
Example #11
Source File: ExternalStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean deleteWithoutServer(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  fileSpec = buildFileSpec(roamingType, fileSpec);

  File file = new File(myProxyDirectory, fileSpec);
  if (file.exists()) {
    return file.delete();
  }
  return false;
}
 
Example #12
Source File: ExternalStorage.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static String buildFileSpec(@Nonnull RoamingType roamingType, @Nonnull String fileSpec) {
  switch (roamingType) {
    case PER_PLATFORM:
      return "$OS$/" + getOsPrefix() + "/" + fileSpec;
    case PER_USER:
      return "$GLOBAL$/" + fileSpec;
    default:
      throw new UnsupportedOperationException(roamingType.name());
  }
}
 
Example #13
Source File: StreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * fileSpec Only main fileSpec, not version
 */
public boolean isApplicable(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  return true;
}
 
Example #14
Source File: ExternalStorageQueue.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public Ref<byte[]> getContent(String fileSpec, RoamingType roamingType) {
  return myLoadedBytes.remove(ExternalStorage.buildFileSpec(roamingType, fileSpec));
}
 
Example #15
Source File: StreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public abstract InputStream loadContent(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) throws IOException;
 
Example #16
Source File: StreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public Collection<String> listSubFiles(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  return Collections.emptyList();
}
 
Example #17
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static void delete(@Nonnull StreamProvider provider, @Nonnull String fileSpec, @Nonnull RoamingType type) {
  if (provider.isApplicable(fileSpec, type)) {
    provider.delete(fileSpec, type);
  }
}
 
Example #18
Source File: StorageUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
/**
 * You must call {@link StreamProvider#isApplicable(String, com.intellij.openapi.components.RoamingType)} before
 */
public static void doSendContent(@Nonnull StreamProvider provider, @Nonnull String fileSpec, @Nonnull Parent element, @Nonnull RoamingType type) throws IOException {
  // we should use standard line-separator (\n) - stream provider can share file content on any OS
  byte[] content = elementToBytes(element, false);
  provider.saveContent(fileSpec, content, type);
}
 
Example #19
Source File: ShelveChangesManager.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public ShelveChangesManager(Project project, ProjectPathMacroManager projectPathMacroManager, SchemesManagerFactory schemesManagerFactory, ChangeListManager changeListManager) {
  myProject = project;
  myPathMacroSubstitutor = projectPathMacroManager.createTrackingSubstitutor();
  myBus = project.getMessageBus();
  mySchemeManager = schemesManagerFactory.createSchemesManager(SHELVE_MANAGER_DIR_PATH, new BaseSchemeProcessor<ShelvedChangeList>() {
    @Nullable
    @Override
    public ShelvedChangeList readScheme(@Nonnull Element element, boolean duringLoad) throws InvalidDataException {
      return readOneShelvedChangeList(element);
    }

    @Nonnull
    @Override
    public Parent writeScheme(@Nonnull ShelvedChangeList scheme) throws WriteExternalException {
      Element child = new Element(ELEMENT_CHANGELIST);
      scheme.writeExternal(child);
      myPathMacroSubstitutor.collapsePaths(child);
      return child;
    }
  }, RoamingType.PER_USER);

  myCleaningFuture = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
    @Override
    public void run() {
      cleanSystemUnshelvedOlderOneWeek();
    }
  }, 1, 1, TimeUnit.DAYS);
  Disposer.register(project, new Disposable() {
    @Override
    public void dispose() {
      stopCleanScheduler();
    }
  });

  File shelfDirectory = mySchemeManager.getRootDirectory();
  myFileProcessor = new CompoundShelfFileProcessor(shelfDirectory);
  // do not try to ignore when new project created,
  // because it may lead to predefined ignore creation conflict; see ConvertExcludedToIgnoredTest etc
  if (shelfDirectory.exists()) {
    changeListManager.addDirectoryToIgnoreImplicitly(shelfDirectory.getAbsolutePath());
  }
}
 
Example #20
Source File: ExternalStorageQueue.java    From consulo with Apache License 2.0 4 votes vote down vote up
private File writeLocalFile(@Nonnull File proxyDirectory, @Nonnull String fileSpec, RoamingType roamingType, byte[] compressedData) throws IOException {
  File file = new File(proxyDirectory, ExternalStorage.buildFileSpec(roamingType, fileSpec));
  FileUtil.createParentDirs(file);
  FileUtil.writeToFile(file, compressedData);
  return file;
}
 
Example #21
Source File: MockSchemesManagerFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public <T extends Named,E extends ExternalizableScheme> SchemesManager<T,E> createSchemesManager(final String fileSpec,
                                                                 final SchemeProcessor<E> processor, final RoamingType roamingType) {
  return new EmptySchemesManager();
}
 
Example #22
Source File: ExternalStorageQueue.java    From consulo with Apache License 2.0 4 votes vote down vote up
LoadItem(String fileSpec, RoamingType roamingType, int modCount, StateStorageManager stateStorageManager) {
  myFileSpec = fileSpec;
  myRoamingType = roamingType;
  myModCount = modCount;
  myStateStorageManager = stateStorageManager;
}
 
Example #23
Source File: ExternalStorage.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void saveContent(@Nonnull String fileSpec, @Nonnull RoamingType roamingType, byte[] content) throws IOException {
  // compress data with -1 mod count - for local, server wull update it after pushing data
  byte[] compress = DataCompressor.compress(content, -1);

  myQueue.wantSaveToServer(myProxyDirectory, fileSpec, roamingType, compress);
}
 
Example #24
Source File: ExternalStorageStreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  myStorage.delete(fileSpec, roamingType);
}
 
Example #25
Source File: ExternalStorageStreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public InputStream loadContent(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) throws IOException {
  return myStorage.loadContent(fileSpec, roamingType, myStateStorageManager);
}
 
Example #26
Source File: ExternalStorageStreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void saveContent(@Nonnull String fileSpec, @Nonnull byte[] content, @Nonnull RoamingType roamingType) throws IOException {
  myStorage.saveContent(fileSpec, roamingType, content);
}
 
Example #27
Source File: ExternalStorageStreamProvider.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Collection<String> listSubFiles(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) {
  return myStorage.listSubFiles(fileSpec, roamingType);
}
 
Example #28
Source File: SchemesManagerFactory.java    From consulo with Apache License 2.0 4 votes vote down vote up
public abstract <T extends Named, E extends ExternalizableScheme> SchemesManager<T,E> createSchemesManager(String fileSpec, SchemeProcessor<E> processor,
RoamingType roamingType);
 
Example #29
Source File: XmlElementStorageTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
public MyXmlElementStorage(Element element) throws StateStorageException {
  super("", RoamingType.PER_USER, new MyPathMacroManager(), "root", null);
  myElement = element;
}
 
Example #30
Source File: StateStorageManagerImplTest.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void testCreateFileStateStorageMacroSubstitutedWhenExpansionHas$() {
  myStateStorageManager.addMacro("$DOLLAR_MACRO$", "/temp/d$");
  StateStorage data = myStateStorageManager.getStateStorage("$DOLLAR_MACRO$/test.xml", RoamingType.PER_USER);
  assertThat(data, is(notNullValue()));
}