PageRenderTime 42ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/mercurial/src/org/netbeans/modules/mercurial/MercurialVCS.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 171 lines | 88 code | 19 blank | 64 comment | 13 complexity | ccae716283ae39808e6f0aad71229595 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. package org.netbeans.modules.mercurial;
  45. import java.io.File;
  46. import java.util.Set;
  47. import java.beans.PropertyChangeListener;
  48. import java.beans.PropertyChangeEvent;
  49. import java.util.prefs.PreferenceChangeEvent;
  50. import java.util.prefs.PreferenceChangeListener;
  51. import org.netbeans.spi.queries.CollocationQueryImplementation;
  52. import org.netbeans.modules.versioning.spi.VCSAnnotator;
  53. import org.netbeans.modules.versioning.spi.VCSHistoryProvider;
  54. import org.netbeans.modules.versioning.spi.VCSInterceptor;
  55. import org.netbeans.modules.versioning.spi.VersioningSystem;
  56. /**
  57. * Extends framework <code>VersioningSystem</code> to Mercurial module functionality.
  58. *
  59. * @author Maros Sandor
  60. */
  61. @VersioningSystem.Registration(
  62. displayName="#CTL_Mercurial_DisplayName",
  63. menuLabel="#CTL_Mercurial_MainMenu",
  64. actionsCategory="Mercurial",
  65. metadataFolderNames=".hg")
  66. public class MercurialVCS extends VersioningSystem implements PropertyChangeListener, PreferenceChangeListener {
  67. public MercurialVCS() {
  68. putProperty(PROP_DISPLAY_NAME, getDisplayName()); // NOI18N
  69. putProperty(PROP_MENU_LABEL, org.openide.util.NbBundle.getMessage(MercurialVCS.class, "CTL_Mercurial_MainMenu")); // NOI18N
  70. HgModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this);
  71. Mercurial.getInstance().register(this);
  72. }
  73. public static String getDisplayName() {
  74. return org.openide.util.NbBundle.getMessage(MercurialVCS.class, "CTL_Mercurial_DisplayName");
  75. }
  76. @Override
  77. public CollocationQueryImplementation getCollocationQueryImplementation() {
  78. return collocationQueryImplementation;
  79. }
  80. @Override
  81. public VCSHistoryProvider getVCSHistoryProvider() {
  82. return Mercurial.getInstance().getMercurialHistoryProvider();
  83. }
  84. private final CollocationQueryImplementation collocationQueryImplementation = new CollocationQueryImplementation() {
  85. @Override
  86. public boolean areCollocated(File a, File b) {
  87. File fra = getTopmostManagedAncestor(a);
  88. File frb = getTopmostManagedAncestor(b);
  89. if (fra == null || !fra.equals(frb)) return false;
  90. return true;
  91. }
  92. @Override
  93. public File findRoot(File file) {
  94. // TODO: we should probably return the closest common ancestor
  95. return getTopmostManagedAncestor(file);
  96. }
  97. };
  98. /**
  99. * Tests whether the file is managed by this versioning system. If it is,
  100. * the method should return the topmost
  101. * ancestor of the file that is still versioned.
  102. *
  103. * @param file a file
  104. * @return File the file itself or one of its ancestors or null if the
  105. * supplied file is NOT managed by this versioning system
  106. */
  107. @Override
  108. public File getTopmostManagedAncestor(File file) {
  109. return Mercurial.getInstance().getTopmostManagedAncestor(file);
  110. }
  111. /**
  112. * Coloring label, modifying icons, providing action on file
  113. */
  114. @Override
  115. public VCSAnnotator getVCSAnnotator() {
  116. return Mercurial.getInstance().getMercurialAnnotator();
  117. }
  118. /**
  119. * Handle file system events such as delete, create, remove etc.
  120. */
  121. @Override
  122. public VCSInterceptor getVCSInterceptor() {
  123. return Mercurial.getInstance().getMercurialInterceptor();
  124. }
  125. @Override
  126. public void getOriginalFile(File workingCopy, File originalFile) {
  127. Mercurial.getInstance().getOriginalFile(workingCopy, originalFile);
  128. }
  129. @SuppressWarnings("unchecked") // Property Change event.getNewValue returning Object
  130. @Override
  131. public void propertyChange(PropertyChangeEvent event) {
  132. if (event.getPropertyName().equals(FileStatusCache.PROP_FILE_STATUS_CHANGED)) {
  133. FileStatusCache.ChangedEvent changedEvent = (FileStatusCache.ChangedEvent) event.getNewValue();
  134. fireStatusChanged(changedEvent.getFile());
  135. } else if (event.getPropertyName().equals(Mercurial.PROP_HEAD_CHANGED)) {
  136. Set<File> files = (Set<File>) event.getNewValue();
  137. fireStatusChanged(files == null || files.isEmpty() ? null : files);
  138. } else if (event.getPropertyName().equals(Mercurial.PROP_ANNOTATIONS_CHANGED)) {
  139. fireAnnotationsChanged((Set<File>) event.getNewValue());
  140. } else if (event.getPropertyName().equals(Mercurial.PROP_VERSIONED_FILES_CHANGED)) {
  141. Mercurial.LOG.fine("cleaning unversioned parents cache"); //NOI18N
  142. Mercurial.getInstance().clearAncestorCaches();
  143. fireVersionedFilesChanged();
  144. }
  145. }
  146. @Override
  147. public void preferenceChange(PreferenceChangeEvent evt) {
  148. if (evt.getKey().startsWith(HgModuleConfig.PROP_COMMIT_EXCLUSIONS)) {
  149. fireStatusChanged((Set<File>) null);
  150. }
  151. }
  152. }