/** * This method is not meant for public use. Only for testing. use {@link * #removePluginDependency(IProject, IProject)} instead. If doMangle is true, then add an extra * space in the text to remove so that previously mangled plugin entries can be removed */ public static IStatus removePluginDependency( IProject dependent, IProject plugin, boolean doMangle) throws CoreException { Assert.isTrue( GrailsNature.isGrailsProject(dependent), dependent.getName() + " is not a grails project"); Assert.isTrue( GrailsNature.isGrailsPluginProject(plugin), plugin.getName() + " is not a grails plugin project"); IFile buildConfigFile = dependent.getFile(BUILD_CONFIG_LOCATION); String textToRemove = createDependencyText(dependent, plugin, doMangle); if (dependencyExists(buildConfigFile, textToRemove)) { char[] contents = ((CompilationUnit) JavaCore.create(buildConfigFile)).getContents(); String newText = String.valueOf(contents).replace(textToRemove, ""); InputStream stream = createInputStream(dependent, newText); buildConfigFile.setContents(stream, true, true, null); return Status.OK_STATUS; } else { return new Status( IStatus.WARNING, GrailsCoreActivator.PLUGIN_ID, "Could not remove a dependency from " + dependent.getName() + " to in place plugin " + plugin.getName() + ". Try manually editing the BuildConfig.groovy file."); } }
/** * This method is not meant for public use. Only for testing. use {@link * #addPluginDependency(IProject, IProject)} instead. If doMangle is true, then add an extra space * in the added text so that it cannot be removed. */ public static IStatus addPluginDependency(IProject dependent, IProject plugin, boolean doMangle) throws CoreException { Assert.isTrue( GrailsNature.isGrailsProject(dependent), dependent.getName() + " is not a grails project"); Assert.isTrue( GrailsNature.isGrailsPluginProject(plugin), plugin.getName() + " is not a grails plugin project"); IFile buildConfigFile = dependent.getFile(BUILD_CONFIG_LOCATION); // next create the text to add to BuildConfig.groovy String textToAdd = createDependencyText(dependent, plugin, doMangle); if (!dependencyExists(buildConfigFile, textToAdd)) { InputStream stream = createInputStream(dependent, textToAdd); buildConfigFile.appendContents(stream, true, true, null); return Status.OK_STATUS; } else { return new Status( IStatus.WARNING, GrailsCoreActivator.PLUGIN_ID, "Could not add a dependency from " + dependent.getName() + " to in place plugin " + plugin.getName() + ". Try manually editing the BuildConfig.groovy file."); } }