diff options
Diffstat (limited to 'plugins/sonar-xoo-plugin/src/main/java/org')
3 files changed, 71 insertions, 2 deletions
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java index 8817e5575ec..8378ddd5ab4 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/XooPlugin.java @@ -74,6 +74,7 @@ import org.sonar.xoo.rule.XooFakeImporterWithMessages; import org.sonar.xoo.rule.XooRulesDefinition; import org.sonar.xoo.rule.XooSonarWayProfile; import org.sonar.xoo.scm.XooBlameCommand; +import org.sonar.xoo.scm.XooIgnoreCommand; import org.sonar.xoo.scm.XooScmProvider; import org.sonar.xoo.test.CoveragePerTestSensor; import org.sonar.xoo.test.TestExecutionSensor; @@ -174,7 +175,9 @@ public class XooPlugin implements Plugin { context.addExtension(DeprecatedGlobalSensor.class); } if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 6))) { - context.addExtension(GlobalProjectSensor.class); + context.addExtensions( + GlobalProjectSensor.class, + XooIgnoreCommand.class); } if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 2))) { context.addExtensions( diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooIgnoreCommand.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooIgnoreCommand.java new file mode 100644 index 00000000000..3ee3f9707ca --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooIgnoreCommand.java @@ -0,0 +1,59 @@ +/* + * SonarQube + * Copyright (C) 2009-2019 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.xoo.scm; + +import java.io.File; +import java.nio.file.Path; +import org.apache.commons.io.FilenameUtils; +import org.sonar.api.batch.scm.IgnoreCommand; +import org.sonar.api.utils.log.Logger; +import org.sonar.api.utils.log.Loggers; + +/** + * To ignore a file simply add an empty file with the same name as the file to ignore with a .ignore suffix. + * E.g. to ignore src/foo.xoo create the file src/foo.xoo.ignore + */ +public class XooIgnoreCommand implements IgnoreCommand { + + static final String IGNORE_FILE_EXTENSION = ".ignore"; + private static final Logger LOG = Loggers.get(XooIgnoreCommand.class); + private boolean isInit; + + @Override + public boolean isIgnored(Path path) { + if (!isInit) { + throw new IllegalStateException("Called init() first"); + } + String fullPath = FilenameUtils.getFullPath(path.toAbsolutePath().toString()); + File scmIgnoreFile = new File(fullPath, path.getFileName() + IGNORE_FILE_EXTENSION); + return scmIgnoreFile.exists(); + } + + @Override + public void init(Path baseDir) { + isInit = true; + LOG.debug("Init IgnoreCommand on dir '{}'"); + } + + @Override + public void clean() { + LOG.debug("Clean IgnoreCommand"); + } +} diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java index 3cf80922f97..856e6c829f9 100644 --- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java +++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/scm/XooScmProvider.java @@ -20,6 +20,7 @@ package org.sonar.xoo.scm; import org.sonar.api.batch.scm.BlameCommand; +import org.sonar.api.batch.scm.IgnoreCommand; import org.sonar.api.batch.scm.ScmProvider; import java.io.File; @@ -27,9 +28,11 @@ import java.io.File; public class XooScmProvider extends ScmProvider { private final XooBlameCommand blame; + private XooIgnoreCommand ignore; - public XooScmProvider(XooBlameCommand blame) { + public XooScmProvider(XooBlameCommand blame, XooIgnoreCommand ignore) { this.blame = blame; + this.ignore = ignore; } @Override @@ -47,4 +50,8 @@ public class XooScmProvider extends ScmProvider { return blame; } + @Override + public IgnoreCommand ignoreCommand() { + return ignore; + } } |