public SchemesManagerImpl(final String fileSpec, final SchemeProcessor<E> processor, final RoamingType roamingType, StreamProvider[] providers, File baseDir) { myFileSpec = fileSpec; myProcessor = processor; myRoamingType = roamingType; myProviders = providers; myBaseDir = baseDir; if (processor instanceof SchemeExtensionProvider) { mySchemeExtension = ((SchemeExtensionProvider)processor).getSchemeExtension(); myUpgradeExtension = ((SchemeExtensionProvider)processor).isUpgradeNeeded(); } myBaseDir.mkdirs(); if (ApplicationManager.getApplication().isUnitTestMode() || !ApplicationManager.getApplication().isCommandLine()) { addVFSListener(); } }
public void exportScheme(final E scheme, final String name, final String description) throws WriteExternalException, IOException { final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); if (providers != null) { Document document = myProcessor.writeScheme(scheme); if (document != null) { Document wrapped = wrap(document, name, description); for (StreamProvider provider : providers) { if (provider instanceof CurrentUserHolder) { wrapped = (Document)wrapped.clone(); String userName = ((CurrentUserHolder)provider).getCurrentUserName(); if (userName != null) { wrapped.getRootElement().setAttribute(USER, userName); } } StorageUtil.sendContent(provider, getFileFullPath(UniqueFileNamesProvider.convertName(scheme.getName())) + mySchemeExtension, wrapped, RoamingType.GLOBAL, false); } } } }
public EditorColorsManagerImpl(DefaultColorSchemesManager defaultColorSchemesManager, SchemesManagerFactory schemesManagerFactory) { myDefaultColorSchemesManager = defaultColorSchemesManager; mySchemesManager = schemesManagerFactory.createSchemesManager( FILE_SPEC, new MySchemeProcessor(), RoamingType.PER_USER); addDefaultSchemes(); // Load default schemes from providers if (!isUnitTestOrHeadlessMode()) { loadSchemesFromBeans(); } loadAllSchemes(); loadAdditionalTextAttributes(); setGlobalScheme(myDefaultColorSchemesManager.getAllSchemes()[0]); }
@NotNull @Override public <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(@NotNull String directoryName, @NotNull SchemeProcessor<E> processor, @NotNull RoamingType roamingType) { //noinspection unchecked return EMPTY; }
@Nullable private static Document loadGlobalScheme(final String schemePath) throws IOException { final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); for (StreamProvider provider : providers) { if (provider.isEnabled()) { Document document = StorageUtil.loadDocument(provider.loadContent(schemePath, RoamingType.GLOBAL)); if (document != null) return document; } } return null; }
public boolean isImportAvailable() { final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); if (providers == null) return false; for (StreamProvider provider : providers) { if (provider.isEnabled()) return true; } return false; }
public RoamingType getRoamingType(String name){ if (myRoamingTypeMap.containsKey(name)) { return myRoamingTypeMap.get(name); } return RoamingType.PER_USER; }
public static void sendContent(StreamProvider provider, String fileSpec, Document copy, RoamingType type, boolean async) throws IOException { byte[] content = printDocument(copy); ByteArrayInputStream in = new ByteArrayInputStream(content); try { if (provider.isEnabled()) { provider.saveContent(fileSpec, in, content.length, type, async); } } finally { in.close(); } }
public BaseToolManager(ActionManagerEx actionManagerEx, SchemesManagerFactory factory) { myActionManager = actionManagerEx; mySchemesManager = factory.createSchemesManager( getSchemesPath(), createProcessor(), RoamingType.PER_USER); mySchemesManager.loadSchemes(); registerActions(); }
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()); } }
public void saveContent(@Nonnull String fileSpec, @Nonnull RoamingType roamingType, byte[] content, int size) throws IOException { UnsyncByteArrayOutputStream out = new UnsyncByteArrayOutputStream(size); try (SnappyOutputStream snappyOutputStream = new SnappyOutputStream(out)) { snappyOutputStream.write(content, 0, size); } byte[] compressedContent = out.toByteArray(); myQueue.wantSave(myProxyDirectory, fileSpec, roamingType, compressedContent); }
@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(); }
@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()); } }
void wantSave(@Nonnull File proxyDirectory, @Nonnull String fileSpec, RoamingType roamingType, byte[] content) throws IOException { File file = new File(proxyDirectory, ExternalStorage.buildFileSpec(roamingType, fileSpec)); FileUtil.createParentDirs(file); FileUtil.writeToFile(file, content); try (CloseableHttpClient client = HttpClients.createDefault()) { URIBuilder urlBuilder = new URIBuilder(WebServiceApi.SYNCHRONIZE_API.buildUrl("pushFile")); urlBuilder.addParameter("filePath", ExternalStorage.buildFileSpec(roamingType, fileSpec)); HttpPost request = new HttpPost(urlBuilder.build()); request.setEntity(new ByteArrayEntity(content)); String authKey = WebServicesConfiguration.getInstance().getOAuthKey(WebServiceApi.SYNCHRONIZE_API); if (authKey != null) { request.addHeader("Authorization", authKey); } PushFile pushFile = client.execute(request, response -> { if (response.getStatusLine().getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { throw new AuthorizationFailedException(); } return new Gson().fromJson(EntityUtils.toString(response.getEntity()), PushFile.class); }); File modCountFile = ExternalStorageUtil.getModCountFile(file); FileUtil.writeToFile(modCountFile, String.valueOf(pushFile.modCount)); } catch (URISyntaxException e) { throw new IOException(e); } }
@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; }
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); } }
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; }
private void doSaveForProvider(@Nonnull Element element, @Nonnull RoamingType roamingType, @Nullable BufferExposingByteArrayOutputStream content) throws IOException { if (content == null) { StorageUtil.sendContent(myStreamProvider, myFileSpec, element, roamingType); } else { myStreamProvider.saveContent(myFileSpec, content.getInternalBuffer(), content.size(), myRoamingType); } }
/** * directoryName — like "keymaps". */ @NotNull public abstract <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> createSchemesManager(@NotNull String directoryName, @NotNull SchemeProcessor<E> processor, @NotNull RoamingType roamingType);
@NotNull public final <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T, E> create(@NotNull String directoryName, @NotNull SchemeProcessor<E> processor) { return createSchemesManager(directoryName, processor, RoamingType.DEFAULT); }
public InputStream loadContent(final String fileSpec, final RoamingType roamingType) throws IOException { return null; }
@Nullable InputStream loadContent(final String fileSpec, final RoamingType roamingType) throws IOException;
public abstract <T extends Scheme, E extends ExternalizableScheme> SchemesManager<T,E> createSchemesManager(String fileSpec, SchemeProcessor<E> processor, RoamingType roamingType);
@Override public <T extends Scheme,E extends ExternalizableScheme> SchemesManager<T,E> createSchemesManager(final String fileSpec, final SchemeProcessor<E> processor, final RoamingType roamingType) { return SchemesManager.EMPTY; }
@NotNull public Collection<SharedScheme<E>> loadSharedSchemes(Collection<T> currentSchemeList) { Collection<String> names = new HashSet<String>(getAllSchemeNames(currentSchemeList)); final StreamProvider[] providers = ((ApplicationImpl)ApplicationManager.getApplication()).getStateStore().getStateStorageManager() .getStreamProviders(RoamingType.GLOBAL); final HashMap<String, SharedScheme<E>> result = new HashMap<String, SharedScheme<E>>(); if (providers != null) { for (StreamProvider provider : providers) { if (provider.isEnabled()) { String[] paths = provider.listSubFiles(myFileSpec); for (String subpath : paths) { try { final Document subDocument = StorageUtil.loadDocument(provider.loadContent(getFileFullPath(subpath), RoamingType.GLOBAL)); if (subDocument != null) { SharedSchemeData original = unwrap(subDocument); final E scheme = myProcessor.readScheme(original.original); if (!alreadyShared(subpath, currentSchemeList)) { String schemeName = original.name; String uniqueName = UniqueNameGenerator.generateUniqueName("[shared] " + schemeName, names); renameScheme(scheme, uniqueName); schemeName = uniqueName; scheme.getExternalInfo().setOriginalPath(getFileFullPath(subpath)); scheme.getExternalInfo().setIsImported(true); result.put(schemeName, new SharedScheme<E>(original.user == null ? "unknown" : original.user, original.description, scheme)); } } } catch (Exception e) { LOG.debug("Cannot load data from IDEAServer: " + e.getLocalizedMessage()); } } } } } for (SharedScheme<E> t : result.values()) { myProcessor.initScheme(t.getScheme()); } return result.values(); }
public void setRoamingType(final String name, final RoamingType roamingType) { myRoamingTypeMap.put(name, roamingType); }
@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(); }
public void testCreateFileStateStorageMacroSubstituted() { StateStorage data = myStateStorageManager.getStateStorage("$MACRO1$/test.xml", RoamingType.PER_USER); assertThat(data, is(notNullValue())); }
public void testCreateFileStateStorageMacroSubstitutedWhenExpansionHas$() { myStateStorageManager.addMacro("$DOLLAR_MACRO$", "/temp/d$"); StateStorage data = myStateStorageManager.getStateStorage("$DOLLAR_MACRO$/test.xml", RoamingType.PER_USER); assertThat(data, is(notNullValue())); }
public MyXmlElementStorage(Element element) throws StateStorageException { super("", RoamingType.PER_USER, new MyPathMacroManager(), "root", null); myElement = element; }
public abstract <T extends Named, E extends ExternalizableScheme> SchemesManager<T,E> createSchemesManager(String fileSpec, SchemeProcessor<E> processor, RoamingType roamingType);
@Nonnull @Override public Collection<String> listSubFiles(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) { return myStorage.listSubFiles(fileSpec, roamingType); }
@Override public void saveContent(@Nonnull String fileSpec, @Nonnull byte[] content, int size, @Nonnull RoamingType roamingType) throws IOException { myStorage.saveContent(fileSpec, roamingType, content, size); }
@javax.annotation.Nullable @Override public InputStream loadContent(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) throws IOException { return myStorage.loadContent(fileSpec, roamingType, myStateStorageManager); }
@Override public void delete(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) { myStorage.delete(fileSpec, roamingType); }
public void delete(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) { fileSpec = buildFileSpec(roamingType, fileSpec); File file = new File(myProxyDirectory, fileSpec); file.delete(); }
LoadItem(String fileSpec, RoamingType roamingType, int modCount, StateStorageManager stateStorageManager) { myFileSpec = fileSpec; myRoamingType = roamingType; myModCount = modCount; myStateStorageManager = stateStorageManager; }
@Nullable public Ref<byte[]> getContent(String fileSpec, RoamingType roamingType) { return myLoadedBytes.remove(ExternalStorage.buildFileSpec(roamingType, fileSpec)); }
/** * fileSpec Only main fileSpec, not version */ public boolean isApplicable(@Nonnull String fileSpec, @Nonnull RoamingType roamingType) { return true; }